xref: /aosp_15_r20/frameworks/av/media/codec2/sfplugin/C2AidlNode.cpp (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1*ec779b8eSAndroid Build Coastguard Worker /*
2*ec779b8eSAndroid Build Coastguard Worker  * Copyright 2024, The Android Open Source Project
3*ec779b8eSAndroid Build Coastguard Worker  *
4*ec779b8eSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*ec779b8eSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*ec779b8eSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*ec779b8eSAndroid Build Coastguard Worker  *
8*ec779b8eSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*ec779b8eSAndroid Build Coastguard Worker  *
10*ec779b8eSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*ec779b8eSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*ec779b8eSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*ec779b8eSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*ec779b8eSAndroid Build Coastguard Worker  * limitations under the License.
15*ec779b8eSAndroid Build Coastguard Worker  */
16*ec779b8eSAndroid Build Coastguard Worker //#define LOG_NDEBUG 0
17*ec779b8eSAndroid Build Coastguard Worker #define LOG_TAG "C2AidlNode"
18*ec779b8eSAndroid Build Coastguard Worker #include <log/log.h>
19*ec779b8eSAndroid Build Coastguard Worker #include <private/android/AHardwareBufferHelpers.h>
20*ec779b8eSAndroid Build Coastguard Worker 
21*ec779b8eSAndroid Build Coastguard Worker #include <media/stagefright/MediaErrors.h>
22*ec779b8eSAndroid Build Coastguard Worker #include <media/stagefright/aidlpersistentsurface/wrapper/Conversion.h>
23*ec779b8eSAndroid Build Coastguard Worker 
24*ec779b8eSAndroid Build Coastguard Worker #include "C2NodeImpl.h"
25*ec779b8eSAndroid Build Coastguard Worker #include "C2AidlNode.h"
26*ec779b8eSAndroid Build Coastguard Worker 
27*ec779b8eSAndroid Build Coastguard Worker namespace android {
28*ec779b8eSAndroid Build Coastguard Worker 
29*ec779b8eSAndroid Build Coastguard Worker using ::aidl::android::media::IAidlBufferSource;
30*ec779b8eSAndroid Build Coastguard Worker using ::aidl::android::media::IAidlNode;
31*ec779b8eSAndroid Build Coastguard Worker 
32*ec779b8eSAndroid Build Coastguard Worker // Conversion
33*ec779b8eSAndroid Build Coastguard Worker using ::android::media::aidl_conversion::toAidlStatus;
34*ec779b8eSAndroid Build Coastguard Worker 
C2AidlNode(const std::shared_ptr<Codec2Client::Component> & comp)35*ec779b8eSAndroid Build Coastguard Worker C2AidlNode::C2AidlNode(const std::shared_ptr<Codec2Client::Component> &comp)
36*ec779b8eSAndroid Build Coastguard Worker     : mImpl(new C2NodeImpl(comp, true)) {}
37*ec779b8eSAndroid Build Coastguard Worker 
38*ec779b8eSAndroid Build Coastguard Worker // aidl ndk interfaces
freeNode()39*ec779b8eSAndroid Build Coastguard Worker ::ndk::ScopedAStatus C2AidlNode::freeNode() {
40*ec779b8eSAndroid Build Coastguard Worker     return toAidlStatus(mImpl->freeNode());
41*ec779b8eSAndroid Build Coastguard Worker }
42*ec779b8eSAndroid Build Coastguard Worker 
getConsumerUsage(int64_t * _aidl_return)43*ec779b8eSAndroid Build Coastguard Worker ::ndk::ScopedAStatus C2AidlNode::getConsumerUsage(int64_t* _aidl_return) {
44*ec779b8eSAndroid Build Coastguard Worker     uint64_t usage;
45*ec779b8eSAndroid Build Coastguard Worker     mImpl->getConsumerUsageBits(&usage);
46*ec779b8eSAndroid Build Coastguard Worker     *_aidl_return = usage;
47*ec779b8eSAndroid Build Coastguard Worker     return ::ndk::ScopedAStatus::ok();
48*ec779b8eSAndroid Build Coastguard Worker }
49*ec779b8eSAndroid Build Coastguard Worker 
getInputBufferParams(IAidlNode::InputBufferParams * _aidl_return)50*ec779b8eSAndroid Build Coastguard Worker ::ndk::ScopedAStatus C2AidlNode::getInputBufferParams(IAidlNode::InputBufferParams* _aidl_return) {
51*ec779b8eSAndroid Build Coastguard Worker     mImpl->getInputBufferParams(_aidl_return);
52*ec779b8eSAndroid Build Coastguard Worker     return ::ndk::ScopedAStatus::ok();
53*ec779b8eSAndroid Build Coastguard Worker }
54*ec779b8eSAndroid Build Coastguard Worker 
setConsumerUsage(int64_t usage)55*ec779b8eSAndroid Build Coastguard Worker ::ndk::ScopedAStatus C2AidlNode::setConsumerUsage(int64_t usage) {
56*ec779b8eSAndroid Build Coastguard Worker     mImpl->setConsumerUsageBits(static_cast<uint64_t>(usage));
57*ec779b8eSAndroid Build Coastguard Worker     return ::ndk::ScopedAStatus::ok();
58*ec779b8eSAndroid Build Coastguard Worker }
59*ec779b8eSAndroid Build Coastguard Worker 
setAdjustTimestampGapUs(int32_t gapUs)60*ec779b8eSAndroid Build Coastguard Worker ::ndk::ScopedAStatus C2AidlNode::setAdjustTimestampGapUs(int32_t gapUs) {
61*ec779b8eSAndroid Build Coastguard Worker     mImpl->setAdjustTimestampGapUs(gapUs);
62*ec779b8eSAndroid Build Coastguard Worker     return ::ndk::ScopedAStatus::ok();
63*ec779b8eSAndroid Build Coastguard Worker }
64*ec779b8eSAndroid Build Coastguard Worker 
setInputSurface(const std::shared_ptr<IAidlBufferSource> & bufferSource)65*ec779b8eSAndroid Build Coastguard Worker ::ndk::ScopedAStatus C2AidlNode::setInputSurface(
66*ec779b8eSAndroid Build Coastguard Worker         const std::shared_ptr<IAidlBufferSource>& bufferSource) {
67*ec779b8eSAndroid Build Coastguard Worker     return toAidlStatus(mImpl->setAidlInputSurface(bufferSource));
68*ec779b8eSAndroid Build Coastguard Worker }
69*ec779b8eSAndroid Build Coastguard Worker 
submitBuffer(int32_t buffer,const std::optional<::aidl::android::hardware::HardwareBuffer> & hBuffer,int32_t flags,int64_t timestamp,const::ndk::ScopedFileDescriptor & fence)70*ec779b8eSAndroid Build Coastguard Worker ::ndk::ScopedAStatus C2AidlNode::submitBuffer(
71*ec779b8eSAndroid Build Coastguard Worker         int32_t buffer,
72*ec779b8eSAndroid Build Coastguard Worker         const std::optional<::aidl::android::hardware::HardwareBuffer>& hBuffer,
73*ec779b8eSAndroid Build Coastguard Worker         int32_t flags, int64_t timestamp, const ::ndk::ScopedFileDescriptor& fence) {
74*ec779b8eSAndroid Build Coastguard Worker     sp<GraphicBuffer> gBuf;
75*ec779b8eSAndroid Build Coastguard Worker     AHardwareBuffer *ahwb = nullptr;
76*ec779b8eSAndroid Build Coastguard Worker     if (hBuffer.has_value()) {
77*ec779b8eSAndroid Build Coastguard Worker         ahwb = hBuffer.value().get();
78*ec779b8eSAndroid Build Coastguard Worker     }
79*ec779b8eSAndroid Build Coastguard Worker 
80*ec779b8eSAndroid Build Coastguard Worker     if (ahwb) {
81*ec779b8eSAndroid Build Coastguard Worker         gBuf = AHardwareBuffer_to_GraphicBuffer(ahwb);
82*ec779b8eSAndroid Build Coastguard Worker     }
83*ec779b8eSAndroid Build Coastguard Worker     return toAidlStatus(mImpl->submitBuffer(
84*ec779b8eSAndroid Build Coastguard Worker             buffer, gBuf, flags, timestamp, ::dup(fence.get())));
85*ec779b8eSAndroid Build Coastguard Worker }
86*ec779b8eSAndroid Build Coastguard Worker 
onDataSpaceChanged(int32_t dataSpace,int32_t aspects,int32_t pixelFormat)87*ec779b8eSAndroid Build Coastguard Worker ::ndk::ScopedAStatus C2AidlNode::onDataSpaceChanged(
88*ec779b8eSAndroid Build Coastguard Worker         int32_t dataSpace,
89*ec779b8eSAndroid Build Coastguard Worker         int32_t aspects,
90*ec779b8eSAndroid Build Coastguard Worker         int32_t pixelFormat) {
91*ec779b8eSAndroid Build Coastguard Worker     // NOTE: legacy codes passed aspects, but they didn't used.
92*ec779b8eSAndroid Build Coastguard Worker     (void)aspects;
93*ec779b8eSAndroid Build Coastguard Worker 
94*ec779b8eSAndroid Build Coastguard Worker     return toAidlStatus(mImpl->onDataspaceChanged(
95*ec779b8eSAndroid Build Coastguard Worker             static_cast<uint32_t>(dataSpace),
96*ec779b8eSAndroid Build Coastguard Worker             static_cast<uint32_t>(pixelFormat)));
97*ec779b8eSAndroid Build Coastguard Worker }
98*ec779b8eSAndroid Build Coastguard Worker 
99*ec779b8eSAndroid Build Coastguard Worker // cpp interface
100*ec779b8eSAndroid Build Coastguard Worker 
getSource()101*ec779b8eSAndroid Build Coastguard Worker std::shared_ptr<IAidlBufferSource> C2AidlNode::getSource() {
102*ec779b8eSAndroid Build Coastguard Worker     return mImpl->getAidlSource();
103*ec779b8eSAndroid Build Coastguard Worker }
104*ec779b8eSAndroid Build Coastguard Worker 
setFrameSize(uint32_t width,uint32_t height)105*ec779b8eSAndroid Build Coastguard Worker void C2AidlNode::setFrameSize(uint32_t width, uint32_t height) {
106*ec779b8eSAndroid Build Coastguard Worker     return mImpl->setFrameSize(width, height);
107*ec779b8eSAndroid Build Coastguard Worker }
108*ec779b8eSAndroid Build Coastguard Worker 
onInputBufferDone(c2_cntr64_t index)109*ec779b8eSAndroid Build Coastguard Worker void C2AidlNode::onInputBufferDone(c2_cntr64_t index) {
110*ec779b8eSAndroid Build Coastguard Worker     return mImpl->onInputBufferDone(index);
111*ec779b8eSAndroid Build Coastguard Worker }
112*ec779b8eSAndroid Build Coastguard Worker 
onInputBufferEmptied()113*ec779b8eSAndroid Build Coastguard Worker void C2AidlNode::onInputBufferEmptied() {
114*ec779b8eSAndroid Build Coastguard Worker     return mImpl->onInputBufferEmptied();
115*ec779b8eSAndroid Build Coastguard Worker }
116*ec779b8eSAndroid Build Coastguard Worker 
getDataspace()117*ec779b8eSAndroid Build Coastguard Worker android_dataspace C2AidlNode::getDataspace() {
118*ec779b8eSAndroid Build Coastguard Worker     return mImpl->getDataspace();
119*ec779b8eSAndroid Build Coastguard Worker }
120*ec779b8eSAndroid Build Coastguard Worker 
getPixelFormat()121*ec779b8eSAndroid Build Coastguard Worker uint32_t C2AidlNode::getPixelFormat() {
122*ec779b8eSAndroid Build Coastguard Worker     return mImpl->getPixelFormat();
123*ec779b8eSAndroid Build Coastguard Worker }
124*ec779b8eSAndroid Build Coastguard Worker 
setPriority(int priority)125*ec779b8eSAndroid Build Coastguard Worker void C2AidlNode::setPriority(int priority) {
126*ec779b8eSAndroid Build Coastguard Worker     return mImpl->setPriority(priority);
127*ec779b8eSAndroid Build Coastguard Worker }
128*ec779b8eSAndroid Build Coastguard Worker 
129*ec779b8eSAndroid Build Coastguard Worker }  // namespace android
130