blob: 0f2320549029c2482908f8aeeada32cd5a3a438f [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(
71 int32_t buffer, const ::aidl::android::hardware::HardwareBuffer& hBuffer,
72 int32_t flags, int64_t timestamp, const ::ndk::ScopedFileDescriptor& fence) {
73 sp<GraphicBuffer> gBuf;
74 AHardwareBuffer *ahwb = hBuffer.get();
75 if (ahwb) {
76 gBuf = AHardwareBuffer_to_GraphicBuffer(ahwb);
77 }
78 return toAidlStatus(mImpl->submitBuffer(
79 buffer, gBuf, flags, timestamp, ::dup(fence.get())));
80}
81
82::ndk::ScopedAStatus C2AidlNode::onDataSpaceChanged(
83 int32_t dataSpace,
84 int32_t aspects,
85 int32_t pixelFormat) {
86 // NOTE: legacy codes passed aspects, but they didn't used.
87 (void)aspects;
88
89 return toAidlStatus(mImpl->onDataspaceChanged(
90 static_cast<uint32_t>(dataSpace),
91 static_cast<uint32_t>(pixelFormat)));
92}
93
94// cpp interface
95
96std::shared_ptr<IAidlBufferSource> C2AidlNode::getSource() {
97 return mImpl->getAidlSource();
98}
99
100void C2AidlNode::setFrameSize(uint32_t width, uint32_t height) {
101 return mImpl->setFrameSize(width, height);
102}
103
104void C2AidlNode::onInputBufferDone(c2_cntr64_t index) {
105 return mImpl->onInputBufferDone(index);
106}
107
Wonsik Kim1951d932024-05-23 22:59:00 +0000108void C2AidlNode::onInputBufferEmptied() {
109 return mImpl->onInputBufferEmptied();
110}
111
Sungtak Lee64c9d932024-03-26 03:46:53 +0000112android_dataspace C2AidlNode::getDataspace() {
113 return mImpl->getDataspace();
114}
115
116uint32_t C2AidlNode::getPixelFormat() {
117 return mImpl->getPixelFormat();
118}
119
120void C2AidlNode::setPriority(int priority) {
121 return mImpl->setPriority(priority);
122}
123
124} // namespace android