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