blob: d2fdf024574b879146c7fdac349a3f0de4c3794e [file] [log] [blame]
Yin-Chia Yeh248ed702017-01-23 17:27:26 -08001/*
2 * Copyright (C) 2017 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
17#define LOG_TAG "HandleImporter"
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080018#include "HandleImporter.h"
Jason Macnakeda6dca2020-04-15 15:20:59 -070019
20#include <gralloctypes/Gralloc4.h>
Emilian Peevdda1eb72022-07-28 16:37:40 -070021#include "aidl/android/hardware/graphics/common/Smpte2086.h"
Steven Moreland4e7a3072017-04-06 12:15:23 -070022#include <log/log.h>
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080023
24namespace android {
25namespace hardware {
26namespace camera {
27namespace common {
28namespace V1_0 {
29namespace helper {
30
Jason Macnakeda6dca2020-04-15 15:20:59 -070031using aidl::android::hardware::graphics::common::PlaneLayout;
32using aidl::android::hardware::graphics::common::PlaneLayoutComponent;
33using aidl::android::hardware::graphics::common::PlaneLayoutComponentType;
Emilian Peevdda1eb72022-07-28 16:37:40 -070034using aidl::android::hardware::graphics::common::Smpte2086;
Emilian Peevb5f634f2021-12-13 15:13:46 -080035using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType;
Shuzhen Wang915115e2019-05-10 12:07:14 -070036using MapperErrorV2 = android::hardware::graphics::mapper::V2_0::Error;
37using MapperErrorV3 = android::hardware::graphics::mapper::V3_0::Error;
Marissa Walla51eb932019-06-21 09:13:35 -070038using MapperErrorV4 = android::hardware::graphics::mapper::V4_0::Error;
Shuzhen Wang915115e2019-05-10 12:07:14 -070039using IMapperV3 = android::hardware::graphics::mapper::V3_0::IMapper;
Marissa Walla51eb932019-06-21 09:13:35 -070040using IMapperV4 = android::hardware::graphics::mapper::V4_0::IMapper;
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080041
Yin-Chia Yeh519c1672017-04-21 14:59:31 -070042HandleImporter::HandleImporter() : mInitialized(false) {}
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080043
Yin-Chia Yeh519c1672017-04-21 14:59:31 -070044void HandleImporter::initializeLocked() {
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080045 if (mInitialized) {
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080046 return;
47 }
48
Marissa Walla51eb932019-06-21 09:13:35 -070049 mMapperV4 = IMapperV4::getService();
50 if (mMapperV4 != nullptr) {
51 mInitialized = true;
52 return;
53 }
54
Shuzhen Wang915115e2019-05-10 12:07:14 -070055 mMapperV3 = IMapperV3::getService();
56 if (mMapperV3 != nullptr) {
57 mInitialized = true;
58 return;
59 }
60
61 mMapperV2 = IMapper::getService();
62 if (mMapperV2 == nullptr) {
Yin-Chia Yeh519c1672017-04-21 14:59:31 -070063 ALOGE("%s: cannnot acccess graphics mapper HAL!", __FUNCTION__);
64 return;
65 }
66
67 mInitialized = true;
68 return;
69}
70
71void HandleImporter::cleanup() {
Marissa Walla51eb932019-06-21 09:13:35 -070072 mMapperV4.clear();
Shuzhen Wang915115e2019-05-10 12:07:14 -070073 mMapperV3.clear();
74 mMapperV2.clear();
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080075 mInitialized = false;
76}
77
Shuzhen Wang915115e2019-05-10 12:07:14 -070078template<class M, class E>
79bool HandleImporter::importBufferInternal(const sp<M> mapper, buffer_handle_t& handle) {
80 E error;
81 buffer_handle_t importedHandle;
82 auto ret = mapper->importBuffer(
83 hidl_handle(handle),
84 [&](const auto& tmpError, const auto& tmpBufferHandle) {
85 error = tmpError;
86 importedHandle = static_cast<buffer_handle_t>(tmpBufferHandle);
87 });
88
89 if (!ret.isOk()) {
90 ALOGE("%s: mapper importBuffer failed: %s",
91 __FUNCTION__, ret.description().c_str());
92 return false;
93 }
94
95 if (error != E::NONE) {
96 return false;
97 }
98
99 handle = importedHandle;
100 return true;
101}
102
103template<class M, class E>
104YCbCrLayout HandleImporter::lockYCbCrInternal(const sp<M> mapper, buffer_handle_t& buf,
105 uint64_t cpuUsage, const IMapper::Rect& accessRegion) {
106 hidl_handle acquireFenceHandle;
107 auto buffer = const_cast<native_handle_t*>(buf);
108 YCbCrLayout layout = {};
109
110 typename M::Rect accessRegionCopy = {accessRegion.left, accessRegion.top,
111 accessRegion.width, accessRegion.height};
112 mapper->lockYCbCr(buffer, cpuUsage, accessRegionCopy, acquireFenceHandle,
113 [&](const auto& tmpError, const auto& tmpLayout) {
114 if (tmpError == E::NONE) {
115 // Member by member copy from different versions of YCbCrLayout.
116 layout.y = tmpLayout.y;
117 layout.cb = tmpLayout.cb;
118 layout.cr = tmpLayout.cr;
119 layout.yStride = tmpLayout.yStride;
120 layout.cStride = tmpLayout.cStride;
121 layout.chromaStep = tmpLayout.chromaStep;
122 } else {
123 ALOGE("%s: failed to lockYCbCr error %d!", __FUNCTION__, tmpError);
124 }
125 });
126 return layout;
127}
128
Emilian Peevb5f634f2021-12-13 15:13:46 -0800129bool isMetadataPesent(const sp<IMapperV4> mapper, const buffer_handle_t& buf,
130 MetadataType metadataType) {
131 auto buffer = const_cast<native_handle_t*>(buf);
Emilian Peevdda1eb72022-07-28 16:37:40 -0700132 bool ret = false;
133 hidl_vec<uint8_t> vec;
134 mapper->get(buffer, metadataType, [&] (const auto& tmpError,
Emilian Peevb5f634f2021-12-13 15:13:46 -0800135 const auto& tmpMetadata) {
136 if (tmpError == MapperErrorV4::NONE) {
Emilian Peevdda1eb72022-07-28 16:37:40 -0700137 vec = tmpMetadata;
Emilian Peevb5f634f2021-12-13 15:13:46 -0800138 } else {
139 ALOGE("%s: failed to get metadata %d!", __FUNCTION__, tmpError);
Emilian Peevb5f634f2021-12-13 15:13:46 -0800140 }});
141
Emilian Peevdda1eb72022-07-28 16:37:40 -0700142 if (vec.size() > 0) {
143 if (metadataType == gralloc4::MetadataType_Smpte2086){
144 std::optional<Smpte2086> realSmpte2086;
145 gralloc4::decodeSmpte2086(vec, &realSmpte2086);
146 ret = realSmpte2086.has_value();
147 } else if (metadataType == gralloc4::MetadataType_Smpte2094_10) {
148 std::optional<std::vector<uint8_t>> realSmpte2094_10;
149 gralloc4::decodeSmpte2094_10(vec, &realSmpte2094_10);
150 ret = realSmpte2094_10.has_value();
151 } else if (metadataType == gralloc4::MetadataType_Smpte2094_40) {
152 std::optional<std::vector<uint8_t>> realSmpte2094_40;
153 gralloc4::decodeSmpte2094_40(vec, &realSmpte2094_40);
154 ret = realSmpte2094_40.has_value();
155 } else {
156 ALOGE("%s: Unknown metadata type!", __FUNCTION__);
157 }
158 }
159
160 return ret;
Emilian Peevb5f634f2021-12-13 15:13:46 -0800161}
162
Emilian Peev6a2572b2021-05-24 16:51:17 -0700163std::vector<PlaneLayout> getPlaneLayouts(const sp<IMapperV4> mapper, buffer_handle_t& buf) {
164 auto buffer = const_cast<native_handle_t*>(buf);
165 std::vector<PlaneLayout> planeLayouts;
166 hidl_vec<uint8_t> encodedPlaneLayouts;
167 mapper->get(buffer, gralloc4::MetadataType_PlaneLayouts,
168 [&](const auto& tmpError, const auto& tmpEncodedPlaneLayouts) {
169 if (tmpError == MapperErrorV4::NONE) {
170 encodedPlaneLayouts = tmpEncodedPlaneLayouts;
171 } else {
172 ALOGE("%s: failed to get plane layouts %d!", __FUNCTION__, tmpError);
173 }
174 });
175
176 gralloc4::decodePlaneLayouts(encodedPlaneLayouts, &planeLayouts);
177
178 return planeLayouts;
179}
180
Jason Macnakeda6dca2020-04-15 15:20:59 -0700181template <>
182YCbCrLayout HandleImporter::lockYCbCrInternal<IMapperV4, MapperErrorV4>(
183 const sp<IMapperV4> mapper, buffer_handle_t& buf, uint64_t cpuUsage,
184 const IMapper::Rect& accessRegion) {
185 hidl_handle acquireFenceHandle;
186 auto buffer = const_cast<native_handle_t*>(buf);
187 YCbCrLayout layout = {};
188 void* mapped = nullptr;
189
190 typename IMapperV4::Rect accessRegionV4 = {accessRegion.left, accessRegion.top,
191 accessRegion.width, accessRegion.height};
192 mapper->lock(buffer, cpuUsage, accessRegionV4, acquireFenceHandle,
193 [&](const auto& tmpError, const auto& tmpPtr) {
194 if (tmpError == MapperErrorV4::NONE) {
195 mapped = tmpPtr;
196 } else {
197 ALOGE("%s: failed to lock error %d!", __FUNCTION__, tmpError);
198 }
199 });
200
201 if (mapped == nullptr) {
202 return layout;
203 }
204
Emilian Peev6a2572b2021-05-24 16:51:17 -0700205 std::vector<PlaneLayout> planeLayouts = getPlaneLayouts(mapper, buf);
Jason Macnakeda6dca2020-04-15 15:20:59 -0700206 for (const auto& planeLayout : planeLayouts) {
207 for (const auto& planeLayoutComponent : planeLayout.components) {
208 const auto& type = planeLayoutComponent.type;
209
210 if (!gralloc4::isStandardPlaneLayoutComponentType(type)) {
211 continue;
212 }
213
214 uint8_t* data = reinterpret_cast<uint8_t*>(mapped);
215 data += planeLayout.offsetInBytes;
216 data += planeLayoutComponent.offsetInBits / 8;
217
218 switch (static_cast<PlaneLayoutComponentType>(type.value)) {
219 case PlaneLayoutComponentType::Y:
220 layout.y = data;
221 layout.yStride = planeLayout.strideInBytes;
222 break;
223 case PlaneLayoutComponentType::CB:
224 layout.cb = data;
225 layout.cStride = planeLayout.strideInBytes;
226 layout.chromaStep = planeLayout.sampleIncrementInBits / 8;
227 break;
228 case PlaneLayoutComponentType::CR:
229 layout.cr = data;
230 layout.cStride = planeLayout.strideInBytes;
231 layout.chromaStep = planeLayout.sampleIncrementInBits / 8;
232 break;
233 default:
234 break;
235 }
236 }
237 }
238
239 return layout;
240}
241
Shuzhen Wang915115e2019-05-10 12:07:14 -0700242template<class M, class E>
243int HandleImporter::unlockInternal(const sp<M> mapper, buffer_handle_t& buf) {
244 int releaseFence = -1;
245 auto buffer = const_cast<native_handle_t*>(buf);
246
247 mapper->unlock(
248 buffer, [&](const auto& tmpError, const auto& tmpReleaseFence) {
249 if (tmpError == E::NONE) {
250 auto fenceHandle = tmpReleaseFence.getNativeHandle();
251 if (fenceHandle) {
252 if (fenceHandle->numInts != 0 || fenceHandle->numFds != 1) {
253 ALOGE("%s: bad release fence numInts %d numFds %d",
254 __FUNCTION__, fenceHandle->numInts, fenceHandle->numFds);
255 return;
256 }
257 releaseFence = dup(fenceHandle->data[0]);
258 if (releaseFence < 0) {
259 ALOGE("%s: bad release fence FD %d",
260 __FUNCTION__, releaseFence);
261 }
262 }
263 } else {
264 ALOGE("%s: failed to unlock error %d!", __FUNCTION__, tmpError);
265 }
266 });
267 return releaseFence;
268}
269
Yin-Chia Yeh248ed702017-01-23 17:27:26 -0800270// In IComposer, any buffer_handle_t is owned by the caller and we need to
271// make a clone for hwcomposer2. We also need to translate empty handle
272// to nullptr. This function does that, in-place.
273bool HandleImporter::importBuffer(buffer_handle_t& handle) {
274 if (!handle->numFds && !handle->numInts) {
275 handle = nullptr;
276 return true;
277 }
278
Yin-Chia Yeh519c1672017-04-21 14:59:31 -0700279 Mutex::Autolock lock(mLock);
280 if (!mInitialized) {
281 initializeLocked();
282 }
283
Marissa Walla51eb932019-06-21 09:13:35 -0700284 if (mMapperV4 != nullptr) {
285 return importBufferInternal<IMapperV4, MapperErrorV4>(mMapperV4, handle);
286 }
287
Shuzhen Wang915115e2019-05-10 12:07:14 -0700288 if (mMapperV3 != nullptr) {
289 return importBufferInternal<IMapperV3, MapperErrorV3>(mMapperV3, handle);
Yin-Chia Yeh248ed702017-01-23 17:27:26 -0800290 }
291
Shuzhen Wang915115e2019-05-10 12:07:14 -0700292 if (mMapperV2 != nullptr) {
293 return importBufferInternal<IMapper, MapperErrorV2>(mMapperV2, handle);
Yin-Chia Yeh519c1672017-04-21 14:59:31 -0700294 }
295
Marissa Walla51eb932019-06-21 09:13:35 -0700296 ALOGE("%s: mMapperV4, mMapperV3 and mMapperV2 are all null!", __FUNCTION__);
Shuzhen Wang915115e2019-05-10 12:07:14 -0700297 return false;
Yin-Chia Yeh248ed702017-01-23 17:27:26 -0800298}
299
300void HandleImporter::freeBuffer(buffer_handle_t handle) {
301 if (!handle) {
302 return;
303 }
304
Yin-Chia Yeh519c1672017-04-21 14:59:31 -0700305 Mutex::Autolock lock(mLock);
Yin-Chia Yeh97978fb2020-01-25 18:15:00 -0800306 if (!mInitialized) {
307 initializeLocked();
Yin-Chia Yeh519c1672017-04-21 14:59:31 -0700308 }
309
Marissa Walla51eb932019-06-21 09:13:35 -0700310 if (mMapperV4 != nullptr) {
311 auto ret = mMapperV4->freeBuffer(const_cast<native_handle_t*>(handle));
312 if (!ret.isOk()) {
313 ALOGE("%s: mapper freeBuffer failed: %s", __FUNCTION__, ret.description().c_str());
314 }
315 } else if (mMapperV3 != nullptr) {
Shuzhen Wang915115e2019-05-10 12:07:14 -0700316 auto ret = mMapperV3->freeBuffer(const_cast<native_handle_t*>(handle));
317 if (!ret.isOk()) {
318 ALOGE("%s: mapper freeBuffer failed: %s",
319 __FUNCTION__, ret.description().c_str());
320 }
321 } else {
322 auto ret = mMapperV2->freeBuffer(const_cast<native_handle_t*>(handle));
323 if (!ret.isOk()) {
324 ALOGE("%s: mapper freeBuffer failed: %s",
325 __FUNCTION__, ret.description().c_str());
326 }
Yin-Chia Yeh519c1672017-04-21 14:59:31 -0700327 }
Yin-Chia Yeh248ed702017-01-23 17:27:26 -0800328}
329
Yin-Chia Yeh519c1672017-04-21 14:59:31 -0700330bool HandleImporter::importFence(const native_handle_t* handle, int& fd) const {
Yin-Chia Yeh248ed702017-01-23 17:27:26 -0800331 if (handle == nullptr || handle->numFds == 0) {
332 fd = -1;
333 } else if (handle->numFds == 1) {
334 fd = dup(handle->data[0]);
335 if (fd < 0) {
336 ALOGE("failed to dup fence fd %d", handle->data[0]);
337 return false;
338 }
339 } else {
340 ALOGE("invalid fence handle with %d file descriptors",
341 handle->numFds);
342 return false;
343 }
344
345 return true;
346}
347
Yin-Chia Yeh519c1672017-04-21 14:59:31 -0700348void HandleImporter::closeFence(int fd) const {
Yin-Chia Yeh248ed702017-01-23 17:27:26 -0800349 if (fd >= 0) {
350 close(fd);
351 }
352}
353
Yuriy Romanenkod0bd4f12018-01-19 16:00:00 -0800354void* HandleImporter::lock(
355 buffer_handle_t& buf, uint64_t cpuUsage, size_t size) {
Jason Macnakf2c9ed12020-04-20 14:43:58 -0700356 IMapper::Rect accessRegion{0, 0, static_cast<int>(size), 1};
357 return lock(buf, cpuUsage, accessRegion);
358}
359
360void* HandleImporter::lock(buffer_handle_t& buf, uint64_t cpuUsage,
361 const IMapper::Rect& accessRegion) {
Yuriy Romanenkod0bd4f12018-01-19 16:00:00 -0800362 Mutex::Autolock lock(mLock);
Yuriy Romanenkod0bd4f12018-01-19 16:00:00 -0800363
364 if (!mInitialized) {
365 initializeLocked();
366 }
367
Jason Macnakf2c9ed12020-04-20 14:43:58 -0700368 void* ret = nullptr;
369
Marissa Walla51eb932019-06-21 09:13:35 -0700370 if (mMapperV4 == nullptr && mMapperV3 == nullptr && mMapperV2 == nullptr) {
371 ALOGE("%s: mMapperV4, mMapperV3 and mMapperV2 are all null!", __FUNCTION__);
Yuriy Romanenkod0bd4f12018-01-19 16:00:00 -0800372 return ret;
373 }
374
375 hidl_handle acquireFenceHandle;
376 auto buffer = const_cast<native_handle_t*>(buf);
Marissa Walla51eb932019-06-21 09:13:35 -0700377 if (mMapperV4 != nullptr) {
Jason Macnakf2c9ed12020-04-20 14:43:58 -0700378 IMapperV4::Rect accessRegionV4{accessRegion.left, accessRegion.top, accessRegion.width,
379 accessRegion.height};
380
381 mMapperV4->lock(buffer, cpuUsage, accessRegionV4, acquireFenceHandle,
Marissa Wall9c5ebfc2019-11-05 14:59:27 -0800382 [&](const auto& tmpError, const auto& tmpPtr) {
Marissa Walla51eb932019-06-21 09:13:35 -0700383 if (tmpError == MapperErrorV4::NONE) {
384 ret = tmpPtr;
385 } else {
386 ALOGE("%s: failed to lock error %d!", __FUNCTION__, tmpError);
387 }
388 });
389 } else if (mMapperV3 != nullptr) {
Jason Macnakf2c9ed12020-04-20 14:43:58 -0700390 IMapperV3::Rect accessRegionV3{accessRegion.left, accessRegion.top, accessRegion.width,
391 accessRegion.height};
392
393 mMapperV3->lock(buffer, cpuUsage, accessRegionV3, acquireFenceHandle,
394 [&](const auto& tmpError, const auto& tmpPtr, const auto& /*bytesPerPixel*/,
395 const auto& /*bytesPerStride*/) {
396 if (tmpError == MapperErrorV3::NONE) {
397 ret = tmpPtr;
398 } else {
399 ALOGE("%s: failed to lock error %d!", __FUNCTION__, tmpError);
400 }
401 });
Shuzhen Wang915115e2019-05-10 12:07:14 -0700402 } else {
Shuzhen Wang915115e2019-05-10 12:07:14 -0700403 mMapperV2->lock(buffer, cpuUsage, accessRegion, acquireFenceHandle,
404 [&](const auto& tmpError, const auto& tmpPtr) {
405 if (tmpError == MapperErrorV2::NONE) {
406 ret = tmpPtr;
407 } else {
Jason Macnakf2c9ed12020-04-20 14:43:58 -0700408 ALOGE("%s: failed to lock error %d!", __FUNCTION__, tmpError);
Shuzhen Wang915115e2019-05-10 12:07:14 -0700409 }
410 });
411 }
Yuriy Romanenkod0bd4f12018-01-19 16:00:00 -0800412
Jason Macnakf2c9ed12020-04-20 14:43:58 -0700413 ALOGV("%s: ptr %p accessRegion.top: %d accessRegion.left: %d accessRegion.width: %d "
414 "accessRegion.height: %d",
415 __FUNCTION__, ret, accessRegion.top, accessRegion.left, accessRegion.width,
416 accessRegion.height);
Yuriy Romanenkod0bd4f12018-01-19 16:00:00 -0800417 return ret;
418}
419
Yin-Chia Yeh19030592017-10-19 17:30:11 -0700420YCbCrLayout HandleImporter::lockYCbCr(
421 buffer_handle_t& buf, uint64_t cpuUsage,
422 const IMapper::Rect& accessRegion) {
423 Mutex::Autolock lock(mLock);
Yin-Chia Yeh19030592017-10-19 17:30:11 -0700424
425 if (!mInitialized) {
426 initializeLocked();
427 }
428
Marissa Walla51eb932019-06-21 09:13:35 -0700429 if (mMapperV4 != nullptr) {
Jason Macnakeda6dca2020-04-15 15:20:59 -0700430 return lockYCbCrInternal<IMapperV4, MapperErrorV4>(mMapperV4, buf, cpuUsage, accessRegion);
Marissa Walla51eb932019-06-21 09:13:35 -0700431 }
432
Shuzhen Wang915115e2019-05-10 12:07:14 -0700433 if (mMapperV3 != nullptr) {
434 return lockYCbCrInternal<IMapperV3, MapperErrorV3>(
435 mMapperV3, buf, cpuUsage, accessRegion);
Yin-Chia Yeh19030592017-10-19 17:30:11 -0700436 }
437
Shuzhen Wang915115e2019-05-10 12:07:14 -0700438 if (mMapperV2 != nullptr) {
439 return lockYCbCrInternal<IMapper, MapperErrorV2>(
440 mMapperV2, buf, cpuUsage, accessRegion);
441 }
Yin-Chia Yeh19030592017-10-19 17:30:11 -0700442
Marissa Walla51eb932019-06-21 09:13:35 -0700443 ALOGE("%s: mMapperV4, mMapperV3 and mMapperV2 are all null!", __FUNCTION__);
Shuzhen Wang915115e2019-05-10 12:07:14 -0700444 return {};
Yin-Chia Yeh19030592017-10-19 17:30:11 -0700445}
446
Emilian Peev6a2572b2021-05-24 16:51:17 -0700447status_t HandleImporter::getMonoPlanarStrideBytes(buffer_handle_t &buf, uint32_t *stride /*out*/) {
448 if (stride == nullptr) {
449 return BAD_VALUE;
450 }
451
452 Mutex::Autolock lock(mLock);
453
454 if (!mInitialized) {
455 initializeLocked();
456 }
457
458 if (mMapperV4 != nullptr) {
459 std::vector<PlaneLayout> planeLayouts = getPlaneLayouts(mMapperV4, buf);
460 if (planeLayouts.size() != 1) {
461 ALOGE("%s: Unexpected number of planes %zu!", __FUNCTION__, planeLayouts.size());
462 return BAD_VALUE;
463 }
464
465 *stride = planeLayouts[0].strideInBytes;
466 } else {
467 ALOGE("%s: mMapperV4 is null! Query not supported!", __FUNCTION__);
468 return NO_INIT;
469 }
470
471 return OK;
472}
473
Yin-Chia Yeh19030592017-10-19 17:30:11 -0700474int HandleImporter::unlock(buffer_handle_t& buf) {
Marissa Walla51eb932019-06-21 09:13:35 -0700475 if (mMapperV4 != nullptr) {
476 return unlockInternal<IMapperV4, MapperErrorV4>(mMapperV4, buf);
477 }
Shuzhen Wang915115e2019-05-10 12:07:14 -0700478 if (mMapperV3 != nullptr) {
479 return unlockInternal<IMapperV3, MapperErrorV3>(mMapperV3, buf);
480 }
481 if (mMapperV2 != nullptr) {
482 return unlockInternal<IMapper, MapperErrorV2>(mMapperV2, buf);
483 }
Yin-Chia Yeh19030592017-10-19 17:30:11 -0700484
Marissa Walla51eb932019-06-21 09:13:35 -0700485 ALOGE("%s: mMapperV4, mMapperV3 and mMapperV2 are all null!", __FUNCTION__);
Shuzhen Wang915115e2019-05-10 12:07:14 -0700486 return -1;
Yin-Chia Yeh19030592017-10-19 17:30:11 -0700487}
488
Emilian Peevb5f634f2021-12-13 15:13:46 -0800489bool HandleImporter::isSmpte2086Present(const buffer_handle_t& buf) {
490 Mutex::Autolock lock(mLock);
491
492 if (!mInitialized) {
493 initializeLocked();
494 }
495
496 if (mMapperV4 != nullptr) {
497 return isMetadataPesent(mMapperV4, buf, gralloc4::MetadataType_Smpte2086);
498 } else {
499 ALOGE("%s: mMapperV4 is null! Query not supported!", __FUNCTION__);
500 }
501
502 return false;
503}
504
505bool HandleImporter::isSmpte2094_10Present(const buffer_handle_t& buf) {
506 Mutex::Autolock lock(mLock);
507
508 if (!mInitialized) {
509 initializeLocked();
510 }
511
512 if (mMapperV4 != nullptr) {
513 return isMetadataPesent(mMapperV4, buf, gralloc4::MetadataType_Smpte2094_10);
514 } else {
515 ALOGE("%s: mMapperV4 is null! Query not supported!", __FUNCTION__);
516 }
517
518 return false;
519}
520
521bool HandleImporter::isSmpte2094_40Present(const buffer_handle_t& buf) {
522 Mutex::Autolock lock(mLock);
523
524 if (!mInitialized) {
525 initializeLocked();
526 }
527
528 if (mMapperV4 != nullptr) {
529 return isMetadataPesent(mMapperV4, buf, gralloc4::MetadataType_Smpte2094_40);
530 } else {
531 ALOGE("%s: mMapperV4 is null! Query not supported!", __FUNCTION__);
532 }
533
534 return false;
535}
536
537
Yin-Chia Yeh248ed702017-01-23 17:27:26 -0800538} // namespace helper
539} // namespace V1_0
540} // namespace common
541} // namespace camera
542} // namespace hardware
543} // namespace android