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 // The HAL pixel format information supported by Android flexible YUV format.
     26 struct SupportedPixelFormat {
     27     bool mCrcb;
     28     bool mSemiplanar;
     29     HalPixelFormat mPixelFormat;
     30 };
     31 
     32 // Video decoder accelerator adaptor interface.
     33 // The adaptor plays the role of providing unified adaptor API functions and client callback to
     34 // codec component side.
     35 // The adaptor API and client callback are modeled after media::VideoDecodeAccelerator which is
     36 // ported from Chrome and are 1:1 mapped with its API functions.
     37 class VideoDecodeAcceleratorAdaptor {
     38 public:
     39     enum Result {
     40         SUCCESS = 0,
     41         ILLEGAL_STATE = 1,
     42         INVALID_ARGUMENT = 2,
     43         UNREADABLE_INPUT = 3,
     44         PLATFORM_FAILURE = 4,
     45         INSUFFICIENT_RESOURCES = 5,
     46     };
     47 
     48     // The adaptor client interface. This interface should be implemented in the component side.
     49     class Client {
     50     public:
     51         virtual ~Client() {}
     52 
     53         // Callback to tell client how many and what size of buffers to provide.
     54         virtual void providePictureBuffers(uint32_t minNumBuffers,
     55                                            const media::Size& codedSize) = 0;
     56 
     57         // Callback to dismiss picture buffer that was assigned earlier.
     58         virtual void dismissPictureBuffer(int32_t pictureBufferId) = 0;
     59 
     60         // Callback to deliver decoded pictures ready to be displayed.
     61         virtual void pictureReady(int32_t pictureBufferId, int32_t bitstreamId,
     62                                   const media::Rect& cropRect) = 0;
     63 
     64         // Callback to notify that decoder has decoded the end of the bitstream buffer with
     65         // specified ID.
     66         virtual void notifyEndOfBitstreamBuffer(int32_t bitstreamId) = 0;
     67 
     68         // Flush completion callback.
     69         virtual void notifyFlushDone() = 0;
     70 
     71         // Reset completion callback.
     72         virtual void notifyResetDone() = 0;
     73 
     74         // Callback to notify about errors. Note that errors in initialize() will not be reported
     75         // here, instead of by its returned value.
     76         virtual void notifyError(Result error) = 0;
     77     };
     78 
     79     // Initializes the video decoder with specific profile. This call is synchronous and returns
     80     // SUCCESS iff initialization is successful.
     81     virtual Result initialize(media::VideoCodecProfile profile, bool secureMode,
     82                               Client* client) = 0;
     83 
     84     // Decodes given buffer handle with bitstream ID.
     85     virtual void decode(int32_t bitstreamId, int handleFd, off_t offset, uint32_t bytesUsed) = 0;
     86 
     87     // Assigns a specified number of picture buffer set to the video decoder.
     88     virtual void assignPictureBuffers(uint32_t numOutputBuffers) = 0;
     89 
     90     // Imports planes as backing memory for picture buffer with specified ID.
     91     virtual void importBufferForPicture(int32_t pictureBufferId, HalPixelFormat format,
     92                                         int handleFd,
     93                                         const std::vector<VideoFramePlane>& planes) = 0;
     94 
     95     // Sends picture buffer to be reused by the decoder by its piture ID.
     96     virtual void reusePictureBuffer(int32_t pictureBufferId) = 0;
     97 
     98     // Flushes the decoder.
     99     virtual void flush() = 0;
    100 
    101     // Resets the decoder.
    102     virtual void reset() = 0;
    103 
    104     // Destroys the decoder.
    105     virtual void destroy() = 0;
    106 
    107     virtual ~VideoDecodeAcceleratorAdaptor() {}
    108 };
    109 
    110 }  // namespace android
    111 
    112 #endif  // ANDROID_VIDEO_DECODE_ACCELERATOR_ADAPTOR_H
    113