Home | History | Annotate | Download | only in include
      1 // Copyright 2017 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef ANDROID_VIDEO_DECODE_ACCELERATOR_ADAPTOR_H
      6 #define ANDROID_VIDEO_DECODE_ACCELERATOR_ADAPTOR_H
      7 
      8 #include <C2VDACommon.h>
      9 
     10 #include <rect.h>
     11 #include <size.h>
     12 #include <video_codecs.h>
     13 #include <video_pixel_format.h>
     14 
     15 #include <vector>
     16 
     17 namespace android {
     18 
     19 // The offset and stride of a video frame plane.
     20 struct VideoFramePlane {
     21     uint32_t mOffset;
     22     uint32_t mStride;
     23 };
     24 
     25 // Video decoder accelerator adaptor interface.
     26 // The adaptor plays the role of providing unified adaptor API functions and client callback to
     27 // codec component side.
     28 // The adaptor API and client callback are modeled after media::VideoDecodeAccelerator which is
     29 // ported from Chrome and are 1:1 mapped with its API functions.
     30 class VideoDecodeAcceleratorAdaptor {
     31 public:
     32     enum Result {
     33         SUCCESS = 0,
     34         ILLEGAL_STATE = 1,
     35         INVALID_ARGUMENT = 2,
     36         UNREADABLE_INPUT = 3,
     37         PLATFORM_FAILURE = 4,
     38         INSUFFICIENT_RESOURCES = 5,
     39     };
     40 
     41     // The adaptor client interface. This interface should be implemented in the component side.
     42     class Client {
     43     public:
     44         virtual ~Client() {}
     45 
     46         // Callback to tell client how many and what size of buffers to provide.
     47         virtual void providePictureBuffers(uint32_t minNumBuffers,
     48                                            const media::Size& codedSize) = 0;
     49 
     50         // Callback to dismiss picture buffer that was assigned earlier.
     51         virtual void dismissPictureBuffer(int32_t pictureBufferId) = 0;
     52 
     53         // Callback to deliver decoded pictures ready to be displayed.
     54         virtual void pictureReady(int32_t pictureBufferId, int32_t bitstreamId,
     55                                   const media::Rect& cropRect) = 0;
     56 
     57         // Callback to notify that decoder has decoded the end of the bitstream buffer with
     58         // specified ID.
     59         virtual void notifyEndOfBitstreamBuffer(int32_t bitstreamId) = 0;
     60 
     61         // Flush completion callback.
     62         virtual void notifyFlushDone() = 0;
     63 
     64         // Reset completion callback.
     65         virtual void notifyResetDone() = 0;
     66 
     67         // Callback to notify about errors. Note that errors in initialize() will not be reported
     68         // here, instead of by its returned value.
     69         virtual void notifyError(Result error) = 0;
     70     };
     71 
     72     // Initializes the video decoder with specific profile. This call is synchronous and returns
     73     // SUCCESS iff initialization is successful.
     74     virtual Result initialize(media::VideoCodecProfile profile, bool secureMode,
     75                               Client* client) = 0;
     76 
     77     // Decodes given buffer handle with bitstream ID.
     78     virtual void decode(int32_t bitstreamId, int handleFd, off_t offset, uint32_t bytesUsed) = 0;
     79 
     80     // Assigns a specified number of picture buffer set to the video decoder.
     81     virtual void assignPictureBuffers(uint32_t numOutputBuffers) = 0;
     82 
     83     // Imports planes as backing memory for picture buffer with specified ID.
     84     virtual void importBufferForPicture(int32_t pictureBufferId, HalPixelFormat format,
     85                                         int handleFd,
     86                                         const std::vector<VideoFramePlane>& planes) = 0;
     87 
     88     // Sends picture buffer to be reused by the decoder by its piture ID.
     89     virtual void reusePictureBuffer(int32_t pictureBufferId) = 0;
     90 
     91     // Flushes the decoder.
     92     virtual void flush() = 0;
     93 
     94     // Resets the decoder.
     95     virtual void reset() = 0;
     96 
     97     // Destroys the decoder.
     98     virtual void destroy() = 0;
     99 
    100     virtual ~VideoDecodeAcceleratorAdaptor() {}
    101 };
    102 
    103 }  // namespace android
    104 
    105 #endif  // ANDROID_VIDEO_DECODE_ACCELERATOR_ADAPTOR_H
    106