blob: 6f53e0fbee97346952052289db0eaf27ee1ba0b0 [file] [log] [blame]
Pawin Vongmasa36653902018-11-15 00:10:25 -08001/*
Sungtak Lee64c9d932024-03-26 03:46:53 +00002 * Copyright 2024, The Android Open Source Project
Pawin Vongmasa36653902018-11-15 00:10:25 -08003 *
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
Pawin Vongmasa36653902018-11-15 00:10:25 -080017//#define LOG_NDEBUG 0
Sungtak Lee64c9d932024-03-26 03:46:53 +000018#define LOG_TAG "C2NodeImpl"
Pawin Vongmasa36653902018-11-15 00:10:25 -080019#include <log/log.h>
20
21#include <C2AllocatorGralloc.h>
22#include <C2BlockInternal.h>
23#include <C2Component.h>
Wonsik Kim414eb152020-11-12 11:14:42 -080024#include <C2Config.h>
Sungtak Lee64c9d932024-03-26 03:46:53 +000025#include <C2Debug.h>
Pawin Vongmasa36653902018-11-15 00:10:25 -080026#include <C2PlatformSupport.h>
27
Chong Zhang442be452019-06-18 10:20:54 -070028#include <android/fdsan.h>
Wonsik Kim673dd192021-01-29 14:58:12 -080029#include <media/stagefright/foundation/ColorUtils.h>
Pawin Vongmasa36653902018-11-15 00:10:25 -080030#include <ui/Fence.h>
31#include <ui/GraphicBuffer.h>
Sungtak Lee64c9d932024-03-26 03:46:53 +000032#include <utils/Errors.h>
Wonsik Kim831b8d72019-06-11 17:52:56 -070033#include <utils/Thread.h>
Pawin Vongmasa36653902018-11-15 00:10:25 -080034
Wonsik Kim673dd192021-01-29 14:58:12 -080035#include "utils/Codec2Mapper.h"
Sungtak Lee10f3f5a2024-03-26 03:36:50 +000036#include "C2NodeImpl.h"
Wonsik Kima79c5522022-01-18 16:29:24 -080037#include "Codec2Buffer.h"
Pawin Vongmasa36653902018-11-15 00:10:25 -080038
39namespace android {
40
Sungtak Lee64c9d932024-03-26 03:46:53 +000041using ::aidl::android::media::IAidlBufferSource;
42using ::aidl::android::media::IAidlNode;
Pawin Vongmasa36653902018-11-15 00:10:25 -080043
Sungtak Lee64c9d932024-03-26 03:46:53 +000044using ::android::media::BUFFERFLAG_EOS;
45
46namespace {
Wonsik Kim414eb152020-11-12 11:14:42 -080047
Pawin Vongmasa36653902018-11-15 00:10:25 -080048class Buffer2D : public C2Buffer {
49public:
50 explicit Buffer2D(C2ConstGraphicBlock block) : C2Buffer({ block }) {}
51};
52
53} // namespace
54
Sungtak Lee64c9d932024-03-26 03:46:53 +000055class C2NodeImpl::QueueThread : public Thread {
Wonsik Kim831b8d72019-06-11 17:52:56 -070056public:
57 QueueThread() : Thread(false) {}
58 ~QueueThread() override = default;
59 void queue(
60 const std::shared_ptr<Codec2Client::Component> &comp,
61 int fenceFd,
62 std::unique_ptr<C2Work> &&work,
63 android::base::unique_fd &&fd0,
64 android::base::unique_fd &&fd1) {
65 Mutexed<Jobs>::Locked jobs(mJobs);
Sungtak Lee45d80592020-02-25 13:54:14 -080066 auto it = jobs->queues.try_emplace(comp, comp).first;
Wonsik Kim831b8d72019-06-11 17:52:56 -070067 it->second.workList.emplace_back(
68 std::move(work), fenceFd, std::move(fd0), std::move(fd1));
69 jobs->cond.broadcast();
70 }
71
Wonsik Kim673dd192021-01-29 14:58:12 -080072 void setDataspace(android_dataspace dataspace) {
73 Mutexed<Jobs>::Locked jobs(mJobs);
74 ColorUtils::convertDataSpaceToV0(dataspace);
75 jobs->configUpdate.emplace_back(new C2StreamDataSpaceInfo::input(0u, dataspace));
76 int32_t standard;
77 int32_t transfer;
78 int32_t range;
79 ColorUtils::getColorConfigFromDataSpace(dataspace, &range, &standard, &transfer);
80 std::unique_ptr<C2StreamColorAspectsInfo::input> colorAspects =
81 std::make_unique<C2StreamColorAspectsInfo::input>(0u);
82 if (C2Mapper::map(standard, &colorAspects->primaries, &colorAspects->matrix)
83 && C2Mapper::map(transfer, &colorAspects->transfer)
84 && C2Mapper::map(range, &colorAspects->range)) {
85 jobs->configUpdate.push_back(std::move(colorAspects));
86 }
87 }
88
Wonsik Kima1335e12021-04-22 16:28:29 -070089 void setPriority(int priority) {
90 androidSetThreadPriority(getTid(), priority);
91 }
92
Wonsik Kim831b8d72019-06-11 17:52:56 -070093protected:
94 bool threadLoop() override {
95 constexpr nsecs_t kIntervalNs = nsecs_t(10) * 1000 * 1000; // 10ms
96 constexpr nsecs_t kWaitNs = kIntervalNs * 2;
97 for (int i = 0; i < 2; ++i) {
98 Mutexed<Jobs>::Locked jobs(mJobs);
99 nsecs_t nowNs = systemTime();
100 bool queued = false;
Wonsik Kim0ca30c32019-06-28 14:15:02 -0700101 for (auto it = jobs->queues.begin(); it != jobs->queues.end(); ) {
Wonsik Kim831b8d72019-06-11 17:52:56 -0700102 Queue &queue = it->second;
103 if (queue.workList.empty()
Sungtak Lee45d80592020-02-25 13:54:14 -0800104 || (queue.lastQueuedTimestampNs != 0 &&
105 nowNs - queue.lastQueuedTimestampNs < kIntervalNs)) {
Wonsik Kim0ca30c32019-06-28 14:15:02 -0700106 ++it;
Wonsik Kim831b8d72019-06-11 17:52:56 -0700107 continue;
108 }
109 std::shared_ptr<Codec2Client::Component> comp = queue.component.lock();
110 if (!comp) {
111 it = jobs->queues.erase(it);
112 continue;
113 }
114 std::list<std::unique_ptr<C2Work>> items;
115 std::vector<int> fenceFds;
116 std::vector<android::base::unique_fd> uniqueFds;
117 while (!queue.workList.empty()) {
118 items.push_back(std::move(queue.workList.front().work));
119 fenceFds.push_back(queue.workList.front().fenceFd);
120 uniqueFds.push_back(std::move(queue.workList.front().fd0));
121 uniqueFds.push_back(std::move(queue.workList.front().fd1));
122 queue.workList.pop_front();
123 }
Wonsik Kim673dd192021-01-29 14:58:12 -0800124 for (const std::unique_ptr<C2Param> &param : jobs->configUpdate) {
125 items.front()->input.configUpdate.emplace_back(C2Param::Copy(*param));
126 }
Wonsik Kim831b8d72019-06-11 17:52:56 -0700127
128 jobs.unlock();
129 for (int fenceFd : fenceFds) {
130 sp<Fence> fence(new Fence(fenceFd));
131 fence->waitForever(LOG_TAG);
132 }
Sungtak Lee45d80592020-02-25 13:54:14 -0800133 queue.lastQueuedTimestampNs = nowNs;
Wonsik Kim831b8d72019-06-11 17:52:56 -0700134 comp->queue(&items);
135 for (android::base::unique_fd &ufd : uniqueFds) {
136 (void)ufd.release();
137 }
138 jobs.lock();
139
Wonsik Kim0ca30c32019-06-28 14:15:02 -0700140 it = jobs->queues.upper_bound(comp);
Wonsik Kim831b8d72019-06-11 17:52:56 -0700141 queued = true;
142 }
143 if (queued) {
Wonsik Kim673dd192021-01-29 14:58:12 -0800144 jobs->configUpdate.clear();
Wonsik Kim831b8d72019-06-11 17:52:56 -0700145 return true;
146 }
147 if (i == 0) {
148 jobs.waitForConditionRelative(jobs->cond, kWaitNs);
149 }
150 }
151 return true;
152 }
153
154private:
155 struct WorkFence {
156 WorkFence(std::unique_ptr<C2Work> &&w, int fd) : work(std::move(w)), fenceFd(fd) {}
157
158 WorkFence(
159 std::unique_ptr<C2Work> &&w,
160 int fd,
161 android::base::unique_fd &&uniqueFd0,
162 android::base::unique_fd &&uniqueFd1)
163 : work(std::move(w)),
164 fenceFd(fd),
165 fd0(std::move(uniqueFd0)),
166 fd1(std::move(uniqueFd1)) {}
167
168 std::unique_ptr<C2Work> work;
169 int fenceFd;
170 android::base::unique_fd fd0;
171 android::base::unique_fd fd1;
172 };
173 struct Queue {
Sungtak Lee45d80592020-02-25 13:54:14 -0800174 Queue(const std::shared_ptr<Codec2Client::Component> &comp)
175 : component(comp), lastQueuedTimestampNs(0) {}
Wonsik Kim831b8d72019-06-11 17:52:56 -0700176 Queue(const Queue &) = delete;
177 Queue &operator =(const Queue &) = delete;
178
179 std::weak_ptr<Codec2Client::Component> component;
180 std::list<WorkFence> workList;
181 nsecs_t lastQueuedTimestampNs;
182 };
183 struct Jobs {
184 std::map<std::weak_ptr<Codec2Client::Component>,
185 Queue,
186 std::owner_less<std::weak_ptr<Codec2Client::Component>>> queues;
Wonsik Kim673dd192021-01-29 14:58:12 -0800187 std::vector<std::unique_ptr<C2Param>> configUpdate;
Wonsik Kim831b8d72019-06-11 17:52:56 -0700188 Condition cond;
189 };
190 Mutexed<Jobs> mJobs;
191};
192
Sungtak Lee64c9d932024-03-26 03:46:53 +0000193C2NodeImpl::C2NodeImpl(const std::shared_ptr<Codec2Client::Component> &comp, bool aidl)
Wonsik Kim9eac4d12019-05-23 12:58:48 -0700194 : mComp(comp), mFrameIndex(0), mWidth(0), mHeight(0), mUsage(0),
Wonsik Kim831b8d72019-06-11 17:52:56 -0700195 mAdjustTimestampGapUs(0), mFirstInputFrame(true),
Sungtak Lee64c9d932024-03-26 03:46:53 +0000196 mQueueThread(new QueueThread), mAidlHal(aidl) {
Chong Zhang442be452019-06-18 10:20:54 -0700197 android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_WARN_ALWAYS);
Sungtak Lee64c9d932024-03-26 03:46:53 +0000198 mQueueThread->run("C2NodeImpl", PRIORITY_AUDIO);
Wonsik Kim673dd192021-01-29 14:58:12 -0800199
Songyue Hanad01f6a2023-08-17 05:45:35 +0000200 android_dataspace ds = HAL_DATASPACE_UNKNOWN;
201 mDataspace.lock().set(ds);
202 uint32_t pf = PIXEL_FORMAT_UNKNOWN;
203 mPixelFormat.lock().set(pf);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800204}
205
Sungtak Lee64c9d932024-03-26 03:46:53 +0000206C2NodeImpl::~C2NodeImpl() {
207}
208
209status_t C2NodeImpl::freeNode() {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800210 mComp.reset();
Chong Zhang442be452019-06-18 10:20:54 -0700211 android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_WARN_ONCE);
Wonsik Kim831b8d72019-06-11 17:52:56 -0700212 return mQueueThread->requestExitAndWait();
Pawin Vongmasa36653902018-11-15 00:10:25 -0800213}
214
Sungtak Lee64c9d932024-03-26 03:46:53 +0000215void C2NodeImpl::onFirstInputFrame() {
216 mFirstInputFrame = true;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800217}
218
Sungtak Lee64c9d932024-03-26 03:46:53 +0000219void C2NodeImpl::getConsumerUsageBits(uint64_t *usage) {
220 *usage = mUsage;
221}
222
223void C2NodeImpl::getInputBufferParams(IAidlNode::InputBufferParams *params) {
224 params->bufferCountActual = 16;
225
226 // WORKAROUND: having more slots improve performance while consuming
227 // more memory. This is a temporary workaround to reduce memory for
228 // larger-than-4K scenario.
229 if (mWidth * mHeight > 4096 * 2340) {
230 std::shared_ptr<Codec2Client::Component> comp = mComp.lock();
231 C2PortActualDelayTuning::input inputDelay(0);
232 C2ActualPipelineDelayTuning pipelineDelay(0);
233 c2_status_t c2err = C2_NOT_FOUND;
234 if (comp) {
235 c2err = comp->query(
236 {&inputDelay, &pipelineDelay}, {}, C2_DONT_BLOCK, nullptr);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800237 }
Sungtak Lee64c9d932024-03-26 03:46:53 +0000238 if (c2err == C2_OK || c2err == C2_BAD_INDEX) {
239 params->bufferCountActual = 4;
240 params->bufferCountActual += (inputDelay ? inputDelay.value : 0u);
241 params->bufferCountActual += (pipelineDelay ? pipelineDelay.value : 0u);
Sungtak Lee0cd4fbc2023-02-02 00:59:01 +0000242 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800243 }
Sungtak Lee64c9d932024-03-26 03:46:53 +0000244
245 params->frameWidth = mWidth;
246 params->frameHeight = mHeight;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800247}
248
Sungtak Lee64c9d932024-03-26 03:46:53 +0000249void C2NodeImpl::setConsumerUsageBits(uint64_t usage) {
250 mUsage = usage;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800251}
252
Sungtak Lee64c9d932024-03-26 03:46:53 +0000253void C2NodeImpl::setAdjustTimestampGapUs(int32_t gapUs) {
254 mAdjustTimestampGapUs = gapUs;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800255}
256
Sungtak Lee64c9d932024-03-26 03:46:53 +0000257status_t C2NodeImpl::setInputSurface(const sp<IOMXBufferSource> &bufferSource) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800258 c2_status_t err = GetCodec2PlatformAllocatorStore()->fetchAllocator(
259 C2PlatformAllocatorStore::GRALLOC,
260 &mAllocator);
261 if (err != OK) {
262 return UNKNOWN_ERROR;
263 }
Sungtak Lee64c9d932024-03-26 03:46:53 +0000264 CHECK(!mAidlHal);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800265 mBufferSource = bufferSource;
266 return OK;
267}
268
Sungtak Lee64c9d932024-03-26 03:46:53 +0000269status_t C2NodeImpl::setAidlInputSurface(
270 const std::shared_ptr<IAidlBufferSource> &aidlBufferSource) {
271 c2_status_t err = GetCodec2PlatformAllocatorStore()->fetchAllocator(
272 C2PlatformAllocatorStore::GRALLOC,
273 &mAllocator);
274 if (err != OK) {
275 return UNKNOWN_ERROR;
276 }
277 CHECK(mAidlHal);
278 mAidlBufferSource = aidlBufferSource;
279 return OK;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800280}
281
Sungtak Lee64c9d932024-03-26 03:46:53 +0000282status_t C2NodeImpl::submitBuffer(
283 uint32_t buffer, const sp<GraphicBuffer> &graphicBuffer,
284 uint32_t flags, int64_t timestamp, int fenceFd) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800285 std::shared_ptr<Codec2Client::Component> comp = mComp.lock();
286 if (!comp) {
287 return NO_INIT;
288 }
289
Sungtak Lee64c9d932024-03-26 03:46:53 +0000290 uint32_t c2Flags = (flags & BUFFERFLAG_EOS)
Pawin Vongmasa36653902018-11-15 00:10:25 -0800291 ? C2FrameData::FLAG_END_OF_STREAM : 0;
292 std::shared_ptr<C2GraphicBlock> block;
293
Chong Zhang442be452019-06-18 10:20:54 -0700294 android::base::unique_fd fd0, fd1;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800295 C2Handle *handle = nullptr;
Sungtak Lee64c9d932024-03-26 03:46:53 +0000296 if (graphicBuffer) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800297 std::shared_ptr<C2GraphicAllocation> alloc;
298 handle = WrapNativeCodec2GrallocHandle(
Sungtak Lee64c9d932024-03-26 03:46:53 +0000299 graphicBuffer->handle,
300 graphicBuffer->width,
301 graphicBuffer->height,
302 graphicBuffer->format,
303 graphicBuffer->usage,
304 graphicBuffer->stride);
Chong Zhang442be452019-06-18 10:20:54 -0700305 if (handle != nullptr) {
306 // unique_fd takes ownership of the fds, we'll get warning if these
307 // fds get closed by somebody else. Onwership will be released before
308 // we return, so that the fds get closed as usually when this function
309 // goes out of scope (when both items and block are gone).
310 native_handle_t *nativeHandle = reinterpret_cast<native_handle_t*>(handle);
311 fd0.reset(nativeHandle->numFds > 0 ? nativeHandle->data[0] : -1);
312 fd1.reset(nativeHandle->numFds > 1 ? nativeHandle->data[1] : -1);
313 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800314 c2_status_t err = mAllocator->priorGraphicAllocation(handle, &alloc);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800315 if (err != OK) {
Chong Zhang442be452019-06-18 10:20:54 -0700316 (void)fd0.release();
317 (void)fd1.release();
Chih-Yu Huangc0ac3552021-03-11 14:37:10 +0900318 native_handle_close(handle);
319 native_handle_delete(handle);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800320 return UNKNOWN_ERROR;
321 }
322 block = _C2BlockFactory::CreateGraphicBlock(alloc);
Sungtak Lee64c9d932024-03-26 03:46:53 +0000323 } else if (!(flags & BUFFERFLAG_EOS)) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800324 return BAD_VALUE;
325 }
326
327 std::unique_ptr<C2Work> work(new C2Work);
328 work->input.flags = (C2FrameData::flags_t)c2Flags;
329 work->input.ordinal.timestamp = timestamp;
330
331 // WORKAROUND: adjust timestamp based on gapUs
332 {
333 work->input.ordinal.customOrdinal = timestamp; // save input timestamp
334 if (mFirstInputFrame) {
335 // grab timestamps on first frame
336 mPrevInputTimestamp = timestamp;
337 mPrevCodecTimestamp = timestamp;
338 mFirstInputFrame = false;
339 } else if (mAdjustTimestampGapUs > 0) {
340 work->input.ordinal.timestamp =
341 mPrevCodecTimestamp
342 + c2_min((timestamp - mPrevInputTimestamp).peek(), mAdjustTimestampGapUs);
343 } else if (mAdjustTimestampGapUs < 0) {
344 work->input.ordinal.timestamp = mPrevCodecTimestamp - mAdjustTimestampGapUs;
345 }
346 mPrevInputTimestamp = work->input.ordinal.customOrdinal;
347 mPrevCodecTimestamp = work->input.ordinal.timestamp;
348 ALOGV("adjusting %lld to %lld (gap=%lld)",
349 work->input.ordinal.customOrdinal.peekll(),
350 work->input.ordinal.timestamp.peekll(),
351 (long long)mAdjustTimestampGapUs);
352 }
353
354 work->input.ordinal.frameIndex = mFrameIndex++;
355 work->input.buffers.clear();
356 if (block) {
357 std::shared_ptr<C2Buffer> c2Buffer(
Pawin Vongmasa36653902018-11-15 00:10:25 -0800358 new Buffer2D(block->share(
Wonsik Kim4f3314d2019-03-26 17:00:34 -0700359 C2Rect(block->width(), block->height()), ::C2Fence())));
Pawin Vongmasa36653902018-11-15 00:10:25 -0800360 work->input.buffers.push_back(c2Buffer);
Wonsik Kima79c5522022-01-18 16:29:24 -0800361 std::shared_ptr<C2StreamHdrStaticInfo::input> staticInfo;
362 std::shared_ptr<C2StreamHdrDynamicMetadataInfo::input> dynamicInfo;
363 GetHdrMetadataFromGralloc4Handle(
364 block->handle(),
365 &staticInfo,
366 &dynamicInfo);
367 if (staticInfo && *staticInfo) {
368 c2Buffer->setInfo(staticInfo);
369 }
370 if (dynamicInfo && *dynamicInfo) {
371 c2Buffer->setInfo(dynamicInfo);
372 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800373 }
374 work->worklets.clear();
375 work->worklets.emplace_back(new C2Worklet);
Wonsik Kim831b8d72019-06-11 17:52:56 -0700376 mBufferIdsInUse.lock()->emplace(work->input.ordinal.frameIndex.peeku(), buffer);
377 mQueueThread->queue(comp, fenceFd, std::move(work), std::move(fd0), std::move(fd1));
Chong Zhang442be452019-06-18 10:20:54 -0700378
Pawin Vongmasa36653902018-11-15 00:10:25 -0800379 return OK;
380}
381
Sungtak Lee64c9d932024-03-26 03:46:53 +0000382status_t C2NodeImpl::onDataspaceChanged(uint32_t dataSpace, uint32_t pixelFormat) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800383 ALOGD("dataspace changed to %#x pixel format: %#x", dataSpace, pixelFormat);
Sungtak Lee64c9d932024-03-26 03:46:53 +0000384 android_dataspace d = (android_dataspace)dataSpace;
385 mQueueThread->setDataspace(d);
Wonsik Kim673dd192021-01-29 14:58:12 -0800386
Sungtak Lee64c9d932024-03-26 03:46:53 +0000387 mDataspace.lock().set(d);
Songyue Hanad01f6a2023-08-17 05:45:35 +0000388 mPixelFormat.lock().set(pixelFormat);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800389 return OK;
390}
391
Sungtak Lee64c9d932024-03-26 03:46:53 +0000392sp<IOMXBufferSource> C2NodeImpl::getSource() {
393 CHECK(!mAidlHal);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800394 return mBufferSource;
395}
396
Sungtak Lee64c9d932024-03-26 03:46:53 +0000397std::shared_ptr<IAidlBufferSource> C2NodeImpl::getAidlSource() {
398 CHECK(mAidlHal);
399 return mAidlBufferSource;
400}
401
402void C2NodeImpl::setFrameSize(uint32_t width, uint32_t height) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800403 mWidth = width;
404 mHeight = height;
405}
406
Sungtak Lee64c9d932024-03-26 03:46:53 +0000407void C2NodeImpl::onInputBufferDone(c2_cntr64_t index) {
408 if (mAidlHal) {
409 if (!mAidlBufferSource) {
410 ALOGD("Buffer source not set (index=%llu)", index.peekull());
411 return;
412 }
413 } else {
414 if (!mBufferSource) {
415 ALOGD("Buffer source not set (index=%llu)", index.peekull());
416 return;
417 }
Wonsik Kim4f3314d2019-03-26 17:00:34 -0700418 }
Wonsik Kima261e382019-04-10 11:37:50 -0700419
420 int32_t bufferId = 0;
421 {
422 decltype(mBufferIdsInUse)::Locked bufferIds(mBufferIdsInUse);
423 auto it = bufferIds->find(index.peeku());
424 if (it == bufferIds->end()) {
425 ALOGV("Untracked input index %llu (maybe already removed)", index.peekull());
426 return;
427 }
428 bufferId = it->second;
429 (void)bufferIds->erase(it);
Wonsik Kim4f3314d2019-03-26 17:00:34 -0700430 }
Sungtak Lee64c9d932024-03-26 03:46:53 +0000431 if (mAidlHal) {
432 ::ndk::ScopedFileDescriptor nullFence;
433 (void)mAidlBufferSource->onInputBufferEmptied(bufferId, nullFence);
434 } else {
435 (void)mBufferSource->onInputBufferEmptied(bufferId, -1);
436 }
Wonsik Kim4f3314d2019-03-26 17:00:34 -0700437}
438
Sungtak Lee64c9d932024-03-26 03:46:53 +0000439android_dataspace C2NodeImpl::getDataspace() {
Wonsik Kim673dd192021-01-29 14:58:12 -0800440 return *mDataspace.lock();
441}
442
Sungtak Lee64c9d932024-03-26 03:46:53 +0000443uint32_t C2NodeImpl::getPixelFormat() {
Songyue Hanad01f6a2023-08-17 05:45:35 +0000444 return *mPixelFormat.lock();
445}
446
Sungtak Lee64c9d932024-03-26 03:46:53 +0000447void C2NodeImpl::setPriority(int priority) {
Wonsik Kima1335e12021-04-22 16:28:29 -0700448 mQueueThread->setPriority(priority);
449}
450
Pawin Vongmasa36653902018-11-15 00:10:25 -0800451} // namespace android