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