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 InputCodec inputCodec); 38 39 // Implementation of the media::VideoDecodeAccelerator::Client interface. 40 void ProvidePictureBuffers(uint32_t requested_num_of_buffers, 41 media::VideoPixelFormat output_format, 42 const media::Size& dimensions) override; 43 void DismissPictureBuffer(int32_t picture_buffer_id) override; 44 void PictureReady(const media::Picture& picture) override; 45 void NotifyEndOfBitstreamBuffer(int32_t bitstream_buffer_id) override; 46 void NotifyFlushDone() override; 47 void NotifyResetDone() override; 48 void NotifyError(media::VideoDecodeAccelerator::Error error) override; 49 50 private: 51 std::unique_ptr<media::VideoDecodeAccelerator> mVDA; 52 VideoDecodeAcceleratorAdaptor::Client* mClient; 53 54 // The number of allocated output buffers. This is obtained from assignPictureBuffers call from 55 // client, and used to check validity of picture id in importBufferForPicture and 56 // reusePictureBuffer. 57 uint32_t mNumOutputBuffers; 58 // The picture size for creating picture buffers. This is obtained while VDA calls 59 // ProvidePictureBuffers. 60 media::Size mPictureSize; 61 62 DISALLOW_COPY_AND_ASSIGN(C2VDAAdaptor); 63 }; 64 65 } // namespace android 66 67 #endif // ANDROID_C2_VDA_ADAPTOR_H 68