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_C2_VDA_ADAPTOR_H
      6 #define ANDROID_C2_VDA_ADAPTOR_H
      7 
      8 #include <VideoDecodeAcceleratorAdaptor.h>
      9 
     10 #include <video_decode_accelerator.h>
     11 
     12 #include <base/macros.h>
     13 
     14 namespace android {
     15 
     16 // This class translates adaptor API to media::VideoDecodeAccelerator API to make communication
     17 // between Codec 2.0 VDA component and VDA.
     18 class C2VDAAdaptor : public VideoDecodeAcceleratorAdaptor,
     19                      public media::VideoDecodeAccelerator::Client {
     20 public:
     21     C2VDAAdaptor();
     22     ~C2VDAAdaptor() override;
     23 
     24     // Implementation of the VideoDecodeAcceleratorAdaptor interface.
     25     Result initialize(media::VideoCodecProfile profile, bool secureMode,
     26                       VideoDecodeAcceleratorAdaptor::Client* client) override;
     27     void decode(int32_t bitstreamId, int handleFd, off_t offset, uint32_t bytesUsed) override;
     28     void assignPictureBuffers(uint32_t numOutputBuffers) override;
     29     void importBufferForPicture(int32_t pictureBufferId, HalPixelFormat format, int handleFd,
     30                                 const std::vector<VideoFramePlane>& planes) override;
     31     void reusePictureBuffer(int32_t pictureBufferId) override;
     32     void flush() override;
     33     void reset() override;
     34     void destroy() override;
     35 
     36     static media::VideoDecodeAccelerator::SupportedProfiles GetSupportedProfiles(
     37             uint32_t inputFormatFourcc);
     38 
     39     static HalPixelFormat ResolveBufferFormat(bool crcb, bool semiplanar);
     40 
     41     // Implementation of the media::VideoDecodeAccelerator::Client interface.
     42     void ProvidePictureBuffers(uint32_t requested_num_of_buffers,
     43                                media::VideoPixelFormat output_format,
     44                                const media::Size& dimensions) override;
     45     void DismissPictureBuffer(int32_t picture_buffer_id) override;
     46     void PictureReady(const media::Picture& picture) override;
     47     void NotifyEndOfBitstreamBuffer(int32_t bitstream_buffer_id) override;
     48     void NotifyFlushDone() override;
     49     void NotifyResetDone() override;
     50     void NotifyError(media::VideoDecodeAccelerator::Error error) override;
     51 
     52 private:
     53     std::unique_ptr<media::VideoDecodeAccelerator> mVDA;
     54     VideoDecodeAcceleratorAdaptor::Client* mClient;
     55 
     56     // The number of allocated output buffers. This is obtained from assignPictureBuffers call from
     57     // client, and used to check validity of picture id in importBufferForPicture and
     58     // reusePictureBuffer.
     59     uint32_t mNumOutputBuffers;
     60     // The picture size for creating picture buffers. This is obtained while VDA calls
     61     // ProvidePictureBuffers.
     62     media::Size mPictureSize;
     63 
     64     DISALLOW_COPY_AND_ASSIGN(C2VDAAdaptor);
     65 };
     66 
     67 }  // namespace android
     68 
     69 #endif  // ANDROID_C2_VDA_ADAPTOR_H
     70