14869017679542b70443d5a306845be1291744400Johny Lin// Copyright 2017 The Chromium Authors. All rights reserved.
24869017679542b70443d5a306845be1291744400Johny Lin// Use of this source code is governed by a BSD-style license that can be
34869017679542b70443d5a306845be1291744400Johny Lin// found in the LICENSE file.
44869017679542b70443d5a306845be1291744400Johny Lin
5c6d0b6f730a74e2d10a414ba5b368fb7cd87f78dJohny Lin#ifndef ANDROID_C2_VDA_ADAPTOR_H
6c6d0b6f730a74e2d10a414ba5b368fb7cd87f78dJohny Lin#define ANDROID_C2_VDA_ADAPTOR_H
74869017679542b70443d5a306845be1291744400Johny Lin
8c6d0b6f730a74e2d10a414ba5b368fb7cd87f78dJohny Lin#include <VideoDecodeAcceleratorAdaptor.h>
9c6d0b6f730a74e2d10a414ba5b368fb7cd87f78dJohny Lin
10c6d0b6f730a74e2d10a414ba5b368fb7cd87f78dJohny Lin#include <video_decode_accelerator.h>
11c6d0b6f730a74e2d10a414ba5b368fb7cd87f78dJohny Lin
12c6d0b6f730a74e2d10a414ba5b368fb7cd87f78dJohny Lin#include <base/macros.h>
134869017679542b70443d5a306845be1291744400Johny Lin
144869017679542b70443d5a306845be1291744400Johny Linnamespace android {
154869017679542b70443d5a306845be1291744400Johny Lin
164869017679542b70443d5a306845be1291744400Johny Lin// This class translates adaptor API to media::VideoDecodeAccelerator API to make communication
174869017679542b70443d5a306845be1291744400Johny Lin// between Codec 2.0 VDA component and VDA.
184869017679542b70443d5a306845be1291744400Johny Linclass C2VDAAdaptor : public VideoDecodeAcceleratorAdaptor,
194869017679542b70443d5a306845be1291744400Johny Lin                     public media::VideoDecodeAccelerator::Client {
204869017679542b70443d5a306845be1291744400Johny Linpublic:
214869017679542b70443d5a306845be1291744400Johny Lin    C2VDAAdaptor();
224869017679542b70443d5a306845be1291744400Johny Lin    ~C2VDAAdaptor() override;
234869017679542b70443d5a306845be1291744400Johny Lin
244869017679542b70443d5a306845be1291744400Johny Lin    // Implementation of the VideoDecodeAcceleratorAdaptor interface.
25a891f0ea984eb1175467ebe1c0ec086977464a07Johny Lin    Result initialize(media::VideoCodecProfile profile, bool secureMode,
264869017679542b70443d5a306845be1291744400Johny Lin                      VideoDecodeAcceleratorAdaptor::Client* client) override;
27ce275069838da4e120c7e54bbfb8e202d3a13997Hirokazu Honda    void decode(int32_t bitstreamId, int handleFd, off_t offset, uint32_t bytesUsed) override;
284869017679542b70443d5a306845be1291744400Johny Lin    void assignPictureBuffers(uint32_t numOutputBuffers) override;
29ac6e2703a612a0d1431e412d022712c988177a7cJohny Lin    void importBufferForPicture(int32_t pictureBufferId, HalPixelFormat format, int handleFd,
304869017679542b70443d5a306845be1291744400Johny Lin                                const std::vector<VideoFramePlane>& planes) override;
314869017679542b70443d5a306845be1291744400Johny Lin    void reusePictureBuffer(int32_t pictureBufferId) override;
324869017679542b70443d5a306845be1291744400Johny Lin    void flush() override;
334869017679542b70443d5a306845be1291744400Johny Lin    void reset() override;
344869017679542b70443d5a306845be1291744400Johny Lin    void destroy() override;
354869017679542b70443d5a306845be1291744400Johny Lin
367c4cb52a0cc4035582797eed726fe04d60703478Johny Lin    static media::VideoDecodeAccelerator::SupportedProfiles GetSupportedProfiles(
377c4cb52a0cc4035582797eed726fe04d60703478Johny Lin            uint32_t inputFormatFourcc);
387c4cb52a0cc4035582797eed726fe04d60703478Johny Lin
39ac6e2703a612a0d1431e412d022712c988177a7cJohny Lin    static HalPixelFormat ResolveBufferFormat(bool crcb, bool semiplanar);
40ac6e2703a612a0d1431e412d022712c988177a7cJohny Lin
414869017679542b70443d5a306845be1291744400Johny Lin    // Implementation of the media::VideoDecodeAccelerator::Client interface.
424869017679542b70443d5a306845be1291744400Johny Lin    void ProvidePictureBuffers(uint32_t requested_num_of_buffers,
434869017679542b70443d5a306845be1291744400Johny Lin                               media::VideoPixelFormat output_format,
444869017679542b70443d5a306845be1291744400Johny Lin                               const media::Size& dimensions) override;
454869017679542b70443d5a306845be1291744400Johny Lin    void DismissPictureBuffer(int32_t picture_buffer_id) override;
464869017679542b70443d5a306845be1291744400Johny Lin    void PictureReady(const media::Picture& picture) override;
474869017679542b70443d5a306845be1291744400Johny Lin    void NotifyEndOfBitstreamBuffer(int32_t bitstream_buffer_id) override;
484869017679542b70443d5a306845be1291744400Johny Lin    void NotifyFlushDone() override;
494869017679542b70443d5a306845be1291744400Johny Lin    void NotifyResetDone() override;
504869017679542b70443d5a306845be1291744400Johny Lin    void NotifyError(media::VideoDecodeAccelerator::Error error) override;
514869017679542b70443d5a306845be1291744400Johny Lin
524869017679542b70443d5a306845be1291744400Johny Linprivate:
534869017679542b70443d5a306845be1291744400Johny Lin    std::unique_ptr<media::VideoDecodeAccelerator> mVDA;
544869017679542b70443d5a306845be1291744400Johny Lin    VideoDecodeAcceleratorAdaptor::Client* mClient;
554869017679542b70443d5a306845be1291744400Johny Lin
564869017679542b70443d5a306845be1291744400Johny Lin    // The number of allocated output buffers. This is obtained from assignPictureBuffers call from
574869017679542b70443d5a306845be1291744400Johny Lin    // client, and used to check validity of picture id in importBufferForPicture and
584869017679542b70443d5a306845be1291744400Johny Lin    // reusePictureBuffer.
594869017679542b70443d5a306845be1291744400Johny Lin    uint32_t mNumOutputBuffers;
604869017679542b70443d5a306845be1291744400Johny Lin    // The picture size for creating picture buffers. This is obtained while VDA calls
614869017679542b70443d5a306845be1291744400Johny Lin    // ProvidePictureBuffers.
624869017679542b70443d5a306845be1291744400Johny Lin    media::Size mPictureSize;
634869017679542b70443d5a306845be1291744400Johny Lin
644869017679542b70443d5a306845be1291744400Johny Lin    DISALLOW_COPY_AND_ASSIGN(C2VDAAdaptor);
654869017679542b70443d5a306845be1291744400Johny Lin};
664869017679542b70443d5a306845be1291744400Johny Lin
674869017679542b70443d5a306845be1291744400Johny Lin}  // namespace android
684869017679542b70443d5a306845be1291744400Johny Lin
69c6d0b6f730a74e2d10a414ba5b368fb7cd87f78dJohny Lin#endif  // ANDROID_C2_VDA_ADAPTOR_H
70