lin
2025-08-21 57113df3a0e2be01232281fad9a5f2c060567981
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// 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_PROXY_H
#define ANDROID_C2_VDA_ADAPTOR_PROXY_H
 
#include <memory>
 
#include <VideoDecodeAcceleratorAdaptor.h>
 
#include <video_decode_accelerator.h>
 
#include <arc/Future.h>
#include <mojo/public/cpp/bindings/binding.h>
 
#include <components/arc/common/video.mojom.h>
#include <components/arc/common/video_decode_accelerator.mojom.h>
 
namespace arc {
class MojoProcessSupport;
}  // namespace arc
 
namespace android {
namespace arc {
class C2VDAAdaptorProxy : public VideoDecodeAcceleratorAdaptor,
                          public ::arc::mojom::VideoDecodeClient {
public:
    C2VDAAdaptorProxy();
    explicit C2VDAAdaptorProxy(::arc::MojoProcessSupport* MojomProcessSupport);
    ~C2VDAAdaptorProxy() override;
 
    // Establishes ipc channel for video acceleration. Returns true if channel
    // connected successfully.
    // This must be called before all other methods.
    bool establishChannel();
 
    // 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 size) 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;
 
    // ::arc::mojom::VideoDecodeClient implementations.
    void ProvidePictureBuffers(::arc::mojom::PictureBufferFormatPtr format) override;
    void PictureReady(::arc::mojom::PicturePtr picture) override;
    void NotifyEndOfBitstreamBuffer(int32_t bitstream_id) override;
    void NotifyError(::arc::mojom::VideoDecodeAccelerator::Result error) override;
 
    // The following functions are called as callbacks.
    void NotifyResetDone(::arc::mojom::VideoDecodeAccelerator::Result result);
    void NotifyFlushDone(::arc::mojom::VideoDecodeAccelerator::Result result);
 
    static media::VideoDecodeAccelerator::SupportedProfiles GetSupportedProfiles(
            InputCodec inputCodec);
 
private:
    void onConnectionError(const std::string& pipeName);
    void establishChannelOnMojoThread(std::shared_ptr<::arc::Future<bool>> future);
    void onVersionReady(std::shared_ptr<::arc::Future<bool>> future, uint32_t version);
 
    // Closes ipc channel for video acceleration.
    // This must be called before deleting this object.
    void closeChannelOnMojoThread();
 
    // mojo thread corresponding part of C2VDAAdaptorProxy implementations.
    void initializeOnMojoThread(const media::VideoCodecProfile profile, const bool mSecureMode,
                                const ::arc::mojom::VideoDecodeAccelerator::InitializeCallback& cb);
    void decodeOnMojoThread(int32_t bitstreamId, int ashmemFd, off_t offset, uint32_t bytesUsed);
    void assignPictureBuffersOnMojoThread(uint32_t numOutputBuffers);
 
    void importBufferForPictureOnMojoThread(int32_t pictureBufferId, HalPixelFormat format,
                                            int handleFd,
                                            const std::vector<VideoFramePlane>& planes);
    void reusePictureBufferOnMojoThread(int32_t pictureBufferId);
    void flushOnMojoThread();
    void resetOnMojoThread();
 
    VideoDecodeAcceleratorAdaptor::Client* mClient;
 
    // Task runner for mojom functions.
    const scoped_refptr<::base::SingleThreadTaskRunner> mMojoTaskRunner;
 
    // |mVDAPtr| and |mBinding| should only be called on |mMojoTaskRunner| after bound.
    ::arc::mojom::VideoDecodeAcceleratorPtr mVDAPtr;
    mojo::Binding<::arc::mojom::VideoDecodeClient> mBinding;
 
    // Used to cancel the wait on arc::Future.
    sp<::arc::CancellationRelay> mRelay;
 
    DISALLOW_COPY_AND_ASSIGN(C2VDAAdaptorProxy);
};
}  // namespace arc
}  // namespace android
 
#endif  // ANDROID_C2_VDA_ADAPTOR_PROXY_H