1 /*
2 * Copyright (C) 2019 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_NDEBUG 0
18 #define LOG_TAG "GCH_HalUtils"
19 #include "hal_utils.h"
20
21 #include <cutils/properties.h>
22 #include <inttypes.h>
23 #include <log/log.h>
24
25 #include <string>
26
27 #include "vendor_tag_defs.h"
28
29 namespace android {
30 namespace google_camera_hal {
31 namespace hal_utils {
32
CreateHwlPipelineRequest(HwlPipelineRequest * hwl_request,uint32_t pipeline_id,const CaptureRequest & request)33 status_t CreateHwlPipelineRequest(HwlPipelineRequest* hwl_request,
34 uint32_t pipeline_id,
35 const CaptureRequest& request) {
36 if (hwl_request == nullptr) {
37 ALOGE("%s: hwl_request is nullptr", __FUNCTION__);
38 return BAD_VALUE;
39 }
40
41 hwl_request->pipeline_id = pipeline_id;
42 hwl_request->settings = HalCameraMetadata::Clone(request.settings.get());
43 hwl_request->input_buffers = request.input_buffers;
44 hwl_request->output_buffers = request.output_buffers;
45 hwl_request->input_width = request.input_width;
46 hwl_request->input_height = request.input_height;
47
48 for (auto& metadata : request.input_buffer_metadata) {
49 hwl_request->input_buffer_metadata.push_back(
50 HalCameraMetadata::Clone(metadata.get()));
51 }
52
53 return OK;
54 }
55
CreateHwlPipelineRequests(std::vector<HwlPipelineRequest> * hwl_requests,const std::vector<uint32_t> & pipeline_ids,const std::vector<ProcessBlockRequest> & requests)56 status_t CreateHwlPipelineRequests(
57 std::vector<HwlPipelineRequest>* hwl_requests,
58 const std::vector<uint32_t>& pipeline_ids,
59 const std::vector<ProcessBlockRequest>& requests) {
60 if (hwl_requests == nullptr) {
61 ALOGE("%s: hwl_requests is nullptr", __FUNCTION__);
62 return BAD_VALUE;
63 }
64
65 if (pipeline_ids.size() != requests.size()) {
66 ALOGE("%s: There are %zu pipeline IDs but %zu requests", __FUNCTION__,
67 pipeline_ids.size(), requests.size());
68 return BAD_VALUE;
69 }
70
71 status_t res;
72 for (size_t i = 0; i < pipeline_ids.size(); i++) {
73 HwlPipelineRequest hwl_request;
74 res = CreateHwlPipelineRequest(&hwl_request, pipeline_ids[i],
75 requests[i].request);
76 if (res != OK) {
77 ALOGE("%s: Creating a HWL pipeline request failed: %s(%d)", __FUNCTION__,
78 strerror(-res), res);
79 return res;
80 }
81
82 hwl_requests->push_back(std::move(hwl_request));
83 }
84
85 return OK;
86 }
87
ConvertToCaptureResult(std::unique_ptr<HwlPipelineResult> hwl_result)88 std::unique_ptr<CaptureResult> ConvertToCaptureResult(
89 std::unique_ptr<HwlPipelineResult> hwl_result) {
90 if (hwl_result == nullptr) {
91 ALOGE("%s: hwl_result is nullptr", __FUNCTION__);
92 return nullptr;
93 }
94
95 auto capture_result = std::make_unique<CaptureResult>();
96 if (capture_result == nullptr) {
97 ALOGE("%s: Creating capture_result failed.", __FUNCTION__);
98 return nullptr;
99 }
100
101 capture_result->frame_number = hwl_result->frame_number;
102 capture_result->result_metadata = std::move(hwl_result->result_metadata);
103 capture_result->output_buffers = std::move(hwl_result->output_buffers);
104 capture_result->input_buffers = std::move(hwl_result->input_buffers);
105 capture_result->partial_result = hwl_result->partial_result;
106
107 capture_result->physical_metadata.reserve(
108 hwl_result->physical_camera_results.size());
109 for (const auto& [camera_id, metadata] : hwl_result->physical_camera_results) {
110 capture_result->physical_metadata.push_back(PhysicalCameraMetadata(
111 {camera_id, HalCameraMetadata::Clone(metadata.get())}));
112 }
113
114 return capture_result;
115 }
116
ContainsOutputBuffer(const CaptureRequest & request,const StreamBuffer & buffer)117 bool ContainsOutputBuffer(const CaptureRequest& request,
118 const StreamBuffer& buffer) {
119 for (auto& request_buffer : request.output_buffers) {
120 if (request_buffer.buffer == buffer.buffer) {
121 return true;
122 } else if (buffer.buffer == nullptr &&
123 request_buffer.stream_id == buffer.stream_id) {
124 // Framework passed in an empty buffer and HAL allocated the buffer.
125 return true;
126 }
127 }
128
129 return false;
130 }
131
AreAllRemainingBuffersRequested(const std::vector<ProcessBlockRequest> & process_block_requests,const CaptureRequest & remaining_session_request)132 bool AreAllRemainingBuffersRequested(
133 const std::vector<ProcessBlockRequest>& process_block_requests,
134 const CaptureRequest& remaining_session_request) {
135 for (auto& buffer : remaining_session_request.output_buffers) {
136 bool found = false;
137
138 for (auto& block_request : process_block_requests) {
139 if (ContainsOutputBuffer(block_request.request, buffer)) {
140 found = true;
141 break;
142 }
143 }
144
145 if (!found) {
146 ALOGE("%s: A buffer %" PRIu64 " of stream %d is not requested.",
147 __FUNCTION__, buffer.buffer_id, buffer.stream_id);
148 return false;
149 }
150 }
151
152 return true;
153 }
154
GetColorFilterArrangement(const HalCameraMetadata * characteristics,uint8_t * cfa)155 static status_t GetColorFilterArrangement(
156 const HalCameraMetadata* characteristics, uint8_t* cfa) {
157 if (characteristics == nullptr || cfa == nullptr) {
158 ALOGE("%s: characteristics (%p) or cfa (%p) is nullptr", __FUNCTION__,
159 characteristics, cfa);
160 return BAD_VALUE;
161 }
162
163 camera_metadata_ro_entry entry;
164 status_t res = characteristics->Get(
165 ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, &entry);
166 if (res != OK || entry.count != 1) {
167 ALOGE("%s: Getting COLOR_FILTER_ARRANGEMENT failed: %s(%d) count: %zu",
168 __FUNCTION__, strerror(-res), res, entry.count);
169 return res;
170 }
171
172 *cfa = entry.data.u8[0];
173 return OK;
174 }
175
IsIrCamera(const HalCameraMetadata * characteristics)176 bool IsIrCamera(const HalCameraMetadata* characteristics) {
177 uint8_t cfa;
178 status_t res = GetColorFilterArrangement(characteristics, &cfa);
179 if (res != OK) {
180 ALOGE("%s: Getting color filter arrangement failed: %s(%d)", __FUNCTION__,
181 strerror(-res), res);
182 return false;
183 }
184
185 return cfa == ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_NIR;
186 }
187
IsMonoCamera(const HalCameraMetadata * characteristics)188 bool IsMonoCamera(const HalCameraMetadata* characteristics) {
189 uint8_t cfa;
190 status_t res = GetColorFilterArrangement(characteristics, &cfa);
191 if (res != OK) {
192 ALOGE("%s: Getting color filter arrangement failed: %s(%d)", __FUNCTION__,
193 strerror(-res), res);
194 return false;
195 }
196
197 return cfa == ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_MONO;
198 }
199
IsBayerCamera(const HalCameraMetadata * characteristics)200 bool IsBayerCamera(const HalCameraMetadata* characteristics) {
201 uint8_t cfa;
202 status_t res = GetColorFilterArrangement(characteristics, &cfa);
203 if (res != OK) {
204 ALOGE("%s: Getting color filter arrangement failed: %s(%d)", __FUNCTION__,
205 strerror(-res), res);
206 return false;
207 }
208
209 if (cfa == ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_RGGB ||
210 cfa == ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_GRBG ||
211 cfa == ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_GBRG ||
212 cfa == ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_BGGR) {
213 return true;
214 }
215
216 return false;
217 }
218
IsFixedFocusCamera(const HalCameraMetadata * characteristics)219 bool IsFixedFocusCamera(const HalCameraMetadata* characteristics) {
220 if (characteristics == nullptr) {
221 ALOGE("%s: characteristics (%p) is nullptr", __FUNCTION__, characteristics);
222 return false;
223 }
224
225 camera_metadata_ro_entry entry = {};
226 status_t res =
227 characteristics->Get(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, &entry);
228 if (res != OK || entry.count != 1) {
229 ALOGE("%s: Getting ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE failed: %s(%d)",
230 __FUNCTION__, strerror(-res), res);
231 return false;
232 }
233
234 return entry.data.f[0] == 0.0f;
235 }
236
IsRequestHdrplusCompatible(const CaptureRequest & request,int32_t preview_stream_id)237 bool IsRequestHdrplusCompatible(const CaptureRequest& request,
238 int32_t preview_stream_id) {
239 if (request.settings == nullptr) {
240 return false;
241 }
242
243 camera_metadata_ro_entry entry;
244 if (request.settings->Get(ANDROID_CONTROL_CAPTURE_INTENT, &entry) != OK ||
245 *entry.data.u8 != ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE) {
246 ALOGV("%s: ANDROID_CONTROL_CAPTURE_INTENT is not STILL_CAPTURE",
247 __FUNCTION__);
248 return false;
249 }
250
251 if (request.settings->Get(ANDROID_CONTROL_ENABLE_ZSL_TRUE, &entry) != OK ||
252 *entry.data.u8 != ANDROID_CONTROL_ENABLE_ZSL_TRUE) {
253 ALOGV("%s: ANDROID_CONTROL_ENABLE_ZSL is not true", __FUNCTION__);
254 return false;
255 }
256
257 if (request.settings->Get(ANDROID_NOISE_REDUCTION_MODE, &entry) != OK ||
258 *entry.data.u8 != ANDROID_NOISE_REDUCTION_MODE_HIGH_QUALITY) {
259 ALOGV("%s: ANDROID_NOISE_REDUCTION_MODE is not HQ", __FUNCTION__);
260 return false;
261 }
262
263 if (request.settings->Get(ANDROID_EDGE_MODE, &entry) != OK ||
264 *entry.data.u8 != ANDROID_EDGE_MODE_HIGH_QUALITY) {
265 ALOGV("%s: ANDROID_EDGE_MODE is not HQ", __FUNCTION__);
266 return false;
267 }
268
269 if (request.settings->Get(ANDROID_COLOR_CORRECTION_ABERRATION_MODE, &entry) !=
270 OK ||
271 *entry.data.u8 != ANDROID_COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY) {
272 ALOGV("%s: ANDROID_COLOR_CORRECTION_ABERRATION_MODE is not HQ",
273 __FUNCTION__);
274 return false;
275 }
276
277 if (request.settings->Get(ANDROID_CONTROL_AE_MODE, &entry) != OK ||
278 (*entry.data.u8 != ANDROID_CONTROL_AE_MODE_ON &&
279 *entry.data.u8 != ANDROID_CONTROL_AE_MODE_ON_AUTO_FLASH)) {
280 ALOGV("%s: ANDROID_CONTROL_AE_MODE is not ON or ON_AUTO_FLASH",
281 __FUNCTION__);
282 return false;
283 }
284
285 if (request.settings->Get(ANDROID_CONTROL_AWB_MODE, &entry) != OK ||
286 *entry.data.u8 != ANDROID_CONTROL_AWB_MODE_AUTO) {
287 ALOGV("%s: ANDROID_CONTROL_AWB_MODE is not HQ", __FUNCTION__);
288 return false;
289 }
290
291 if (request.settings->Get(ANDROID_CONTROL_EFFECT_MODE, &entry) != OK ||
292 *entry.data.u8 != ANDROID_CONTROL_EFFECT_MODE_OFF) {
293 ALOGV("%s: ANDROID_CONTROL_EFFECT_MODE is not HQ", __FUNCTION__);
294 return false;
295 }
296
297 if (request.settings->Get(ANDROID_CONTROL_MODE, &entry) != OK ||
298 (*entry.data.u8 != ANDROID_CONTROL_MODE_AUTO &&
299 *entry.data.u8 != ANDROID_CONTROL_MODE_USE_SCENE_MODE)) {
300 ALOGV("%s: ANDROID_CONTROL_MODE is not AUTO or USE_SCENE_MODE",
301 __FUNCTION__);
302 return false;
303 }
304
305 if (request.settings->Get(ANDROID_FLASH_MODE, &entry) != OK ||
306 *entry.data.u8 != ANDROID_FLASH_MODE_OFF) {
307 ALOGV("%s: ANDROID_FLASH_MODE is not OFF", __FUNCTION__);
308 return false;
309 }
310
311 if (request.settings->Get(ANDROID_TONEMAP_MODE, &entry) != OK ||
312 *entry.data.u8 != ANDROID_TONEMAP_MODE_HIGH_QUALITY) {
313 ALOGV("%s: ANDROID_TONEMAP_MODE is not HQ", __FUNCTION__);
314 return false;
315 }
316
317 // For b/129798167 - AOSP camera AP can't trigger the snapshot
318 if (request.settings->Get(ANDROID_CONTROL_AF_TRIGGER, &entry) != OK ||
319 *entry.data.u8 != ANDROID_CONTROL_AF_TRIGGER_IDLE) {
320 ALOGI("%s: (%d)ANDROID_CONTROL_AF_TRIGGER is not IDLE", __FUNCTION__,
321 request.frame_number);
322 return false;
323 }
324
325 // For b/130768200, treat the request as non-HDR+ request
326 // if only request one preview frame output.
327 if (preview_stream_id != -1 && request.output_buffers.size() == 1 &&
328 request.output_buffers[0].stream_id == preview_stream_id) {
329 ALOGI("%s: (%d)Only request preview frame", __FUNCTION__,
330 request.frame_number);
331 return false;
332 }
333
334 return true;
335 }
336
IsStreamHdrplusCompatible(const StreamConfiguration & stream_config,const HalCameraMetadata * characteristics)337 bool IsStreamHdrplusCompatible(const StreamConfiguration& stream_config,
338 const HalCameraMetadata* characteristics) {
339 static const uint32_t kHdrplusSensorMaxFps = 30;
340 if (characteristics == nullptr) {
341 ALOGE("%s: characteristics is nullptr", __FUNCTION__);
342 return false;
343 }
344
345 if (property_get_bool("persist.vendor.camera.hdrplus.disable", false)) {
346 ALOGI("%s: HDR+ is disabled by property", __FUNCTION__);
347 return false;
348 }
349
350 camera_metadata_ro_entry entry;
351 status_t res =
352 characteristics->Get(VendorTagIds::kHdrplusPayloadFrames, &entry);
353 if (res != OK || entry.data.i32[0] <= 0) {
354 ALOGW("%s: Getting kHdrplusPayloadFrames failed or number <= 0",
355 __FUNCTION__);
356 return false;
357 }
358
359 if (stream_config.operation_mode != StreamConfigurationMode::kNormal) {
360 ALOGI("%s: Only support normal mode. operation_mode = %d", __FUNCTION__,
361 stream_config.operation_mode);
362 return false;
363 }
364
365 if (property_get_bool("persist.vendor.camera.fatp.enable", false)) {
366 ALOGI("%s: Do not use HDR+ for FATP mode", __FUNCTION__);
367 return false;
368 }
369
370 if (stream_config.session_params != nullptr &&
371 stream_config.session_params->Get(ANDROID_CONTROL_AE_TARGET_FPS_RANGE,
372 &entry) == OK) {
373 uint32_t max_fps = entry.data.i32[1];
374 if (max_fps > kHdrplusSensorMaxFps) {
375 ALOGI("%s: the fps (%d) is over HDR+ support.", __FUNCTION__, max_fps);
376 return false;
377 }
378 }
379
380 if (stream_config.session_params != nullptr) {
381 camera_metadata_ro_entry entry;
382 status_t result = stream_config.session_params->Get(
383 VendorTagIds::kHdrPlusDisabled, &entry);
384
385 if ((result == OK) && (entry.data.u8[0] == 1)) {
386 ALOGI("%s: request.disable_hdrplus true", __FUNCTION__);
387 return false;
388 }
389 }
390
391 bool preview_stream = false;
392 bool jpeg_stream = false;
393 bool has_logical_stream = false;
394 bool has_physical_stream = false;
395 uint32_t yuv_num = 0;
396 uint32_t last_physical_cam_id = 0;
397
398 for (auto stream : stream_config.streams) {
399 if (utils::IsPreviewStream(stream)) {
400 preview_stream = true;
401 } else if (utils::IsJPEGSnapshotStream(stream)) {
402 jpeg_stream = true;
403 } else if (utils::IsDepthStream(stream)) {
404 ALOGI("%s: Don't support depth stream", __FUNCTION__);
405 return false;
406 } else if (utils::IsVideoStream(stream)) {
407 ALOGI("%s: Don't support video stream", __FUNCTION__);
408 return false;
409 } else if (utils::IsArbitraryDataSpaceRawStream(stream)) {
410 ALOGI("%s: Don't support raw stream", __FUNCTION__);
411 return false;
412 } else if (utils::IsYUVSnapshotStream(stream)) {
413 yuv_num++;
414 } else {
415 ALOGE("%s: Unknown stream type %d, res %ux%u, format %d, usage %" PRIu64,
416 __FUNCTION__, stream.stream_type, stream.width, stream.height,
417 stream.format, stream.usage);
418 return false;
419 }
420
421 if (stream.is_physical_camera_stream) {
422 if (has_physical_stream &&
423 stream.physical_camera_id != last_physical_cam_id) {
424 // b/137721824, we don't support HDR+ if stream configuration contains
425 // different physical camera id streams.
426 ALOGI("%s: Don't support different physical camera id streams",
427 __FUNCTION__);
428 return false;
429 }
430 has_physical_stream = true;
431 last_physical_cam_id = stream.physical_camera_id;
432 } else {
433 has_logical_stream = true;
434 }
435 }
436
437 // Only preview is configured.
438 if (preview_stream == true && jpeg_stream == false && yuv_num == 0) {
439 ALOGI("%s: Only preview is configured.", __FUNCTION__);
440 return false;
441 }
442
443 // No preview is configured.
444 if (preview_stream == false) {
445 ALOGI("%s: no preview is configured.", __FUNCTION__);
446 return false;
447 }
448
449 // b/137721824, we don't support HDR+ if stream configuration contains
450 // logical and physical streams.
451 if (has_logical_stream == true && has_physical_stream == true) {
452 ALOGI("%s: Don't support logical and physical combination", __FUNCTION__);
453 return false;
454 }
455
456 // TODO(b/128633958): remove this after depth block is in place
457 if (property_get_bool("persist.vendor.camera.rgbird.forceinternal", false)) {
458 return false;
459 }
460
461 return true;
462 }
463
SetEnableZslMetadata(HalCameraMetadata * metadata,bool enable)464 status_t SetEnableZslMetadata(HalCameraMetadata* metadata, bool enable) {
465 if (metadata == nullptr) {
466 ALOGE("%s: metadata is nullptr", __FUNCTION__);
467 return BAD_VALUE;
468 }
469
470 uint8_t enable_zsl = enable ? 1 : 0;
471 status_t res = metadata->Set(ANDROID_CONTROL_ENABLE_ZSL, &enable_zsl, 1);
472 if (res != OK) {
473 ALOGE("%s: set %d fail", __FUNCTION__, enable_zsl);
474 return res;
475 }
476
477 return OK;
478 }
479
SetHybridAeMetadata(HalCameraMetadata * metadata,bool enable)480 status_t SetHybridAeMetadata(HalCameraMetadata* metadata, bool enable) {
481 if (metadata == nullptr) {
482 ALOGE("%s: metadata is nullptr", __FUNCTION__);
483 return BAD_VALUE;
484 }
485
486 status_t res;
487 int32_t enable_hybrid_ae = enable ? 1 : 0;
488 res = metadata->Set(VendorTagIds::kHybridAeEnabled, &enable_hybrid_ae,
489 /*data_count=*/1);
490 if (res != OK) {
491 ALOGE("%s: enable_hybrid_ae(%d) fail", __FUNCTION__, enable_hybrid_ae);
492 return res;
493 }
494
495 return OK;
496 }
497
ForceLensShadingMapModeOn(HalCameraMetadata * metadata)498 status_t ForceLensShadingMapModeOn(HalCameraMetadata* metadata) {
499 if (metadata == nullptr) {
500 ALOGE("%s: metadata is nullptr", __FUNCTION__);
501 return BAD_VALUE;
502 }
503
504 camera_metadata_ro_entry entry;
505 if (metadata->Get(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, &entry) == OK &&
506 *entry.data.u8 == ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF) {
507 // Force enabling LENS_SHADING_MAP_MODE_ON.
508 uint8_t mode = ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_ON;
509 status_t result =
510 metadata->Set(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, &mode, 1);
511 if (result != OK) {
512 ALOGE("%s: Set LENS_SHADING_MAP_MODE on fail", __FUNCTION__);
513 return result;
514 }
515 }
516
517 return OK;
518 }
519
ModifyRealtimeRequestForHdrplus(HalCameraMetadata * metadata,const bool hybrid_ae_enable)520 status_t ModifyRealtimeRequestForHdrplus(HalCameraMetadata* metadata,
521 const bool hybrid_ae_enable) {
522 if (metadata == nullptr) {
523 ALOGE("%s: metadata is nullptr", __FUNCTION__);
524 return BAD_VALUE;
525 }
526
527 // Update hybrid AE
528 status_t result = SetHybridAeMetadata(metadata, hybrid_ae_enable);
529 if (result != OK) {
530 ALOGE("%s: SetHybridAeMetadata fail", __FUNCTION__);
531 return result;
532 }
533
534 // Update FD mode
535 camera_metadata_ro_entry entry;
536 if (metadata->Get(ANDROID_STATISTICS_FACE_DETECT_MODE, &entry) == OK &&
537 *entry.data.u8 == ANDROID_STATISTICS_FACE_DETECT_MODE_OFF) {
538 // Force enabling face detect mode to simple.
539 uint8_t mode = ANDROID_STATISTICS_FACE_DETECT_MODE_SIMPLE;
540 result = metadata->Set(ANDROID_STATISTICS_FACE_DETECT_MODE, &mode, 1);
541 if (result != OK) {
542 ALOGE("%s: update FD simple mode fail", __FUNCTION__);
543 return result;
544 }
545 }
546
547 // Force lens shading mode to on
548 result = ForceLensShadingMapModeOn(metadata);
549 if (result != OK) {
550 ALOGE("%s: ForceLensShadingMapModeOn fail", __FUNCTION__);
551 return result;
552 }
553
554 return OK;
555 }
556
GetLensShadingMapMode(const CaptureRequest & request,uint8_t * lens_shading_mode)557 status_t GetLensShadingMapMode(const CaptureRequest& request,
558 uint8_t* lens_shading_mode) {
559 if (request.settings == nullptr || lens_shading_mode == nullptr) {
560 ALOGE("%s: request.settings or lens_shading_mode is nullptr", __FUNCTION__);
561 return BAD_VALUE;
562 }
563
564 camera_metadata_ro_entry entry;
565 status_t result =
566 request.settings->Get(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, &entry);
567 if (result != OK) {
568 ALOGV("%s: Get LENS_SHADING_MAP_MODE fail", __FUNCTION__);
569 return result;
570 }
571 *lens_shading_mode = *entry.data.u8;
572
573 return OK;
574 }
575
RemoveLsInfoFromResult(HalCameraMetadata * metadata)576 status_t RemoveLsInfoFromResult(HalCameraMetadata* metadata) {
577 if (metadata == nullptr) {
578 ALOGE("%s: metadata is nullptr", __FUNCTION__);
579 return BAD_VALUE;
580 }
581
582 camera_metadata_ro_entry entry;
583 status_t res;
584 if (metadata->Get(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, &entry) == OK) {
585 // Change lens shading map mode to OFF.
586 uint8_t mode = ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF;
587 res = metadata->Set(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, &mode, 1);
588 if (res != OK) {
589 ALOGE("%s: Set LENS_SHADING_MAP_MODE off fail", __FUNCTION__);
590 return res;
591 }
592 }
593
594 // Erase lens shading map.
595 res = metadata->Erase(ANDROID_STATISTICS_LENS_SHADING_MAP);
596 if (res != OK) {
597 ALOGE("%s: erase LENS_SHADING_MAP fail", __FUNCTION__);
598 return res;
599 }
600
601 return OK;
602 }
603
GetFdMode(const CaptureRequest & request,uint8_t * face_detect_mode)604 status_t GetFdMode(const CaptureRequest& request, uint8_t* face_detect_mode) {
605 if (request.settings == nullptr || face_detect_mode == nullptr) {
606 ALOGE("%s: request.settings or face_detect_mode is nullptr", __FUNCTION__);
607 return BAD_VALUE;
608 }
609
610 camera_metadata_ro_entry entry;
611 status_t result =
612 request.settings->Get(ANDROID_STATISTICS_FACE_DETECT_MODE, &entry);
613 if (result != OK) {
614 ALOGV("%s: Get FACE_DETECT_MODE fail", __FUNCTION__);
615 return result;
616 }
617 *face_detect_mode = *entry.data.u8;
618
619 return OK;
620 }
621
RemoveFdInfoFromResult(HalCameraMetadata * metadata)622 status_t RemoveFdInfoFromResult(HalCameraMetadata* metadata) {
623 if (metadata == nullptr) {
624 ALOGE("%s: metadata is nullptr", __FUNCTION__);
625 return BAD_VALUE;
626 }
627
628 camera_metadata_ro_entry entry;
629 status_t res;
630 if (metadata->Get(ANDROID_STATISTICS_FACE_DETECT_MODE, &entry) == OK) {
631 uint8_t mode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF;
632 res = metadata->Set(ANDROID_STATISTICS_FACE_DETECT_MODE, &mode, 1);
633 if (res != OK) {
634 ALOGE("%s: update FD off mode fail", __FUNCTION__);
635 return res;
636 }
637 }
638
639 res = metadata->Erase(ANDROID_STATISTICS_FACE_RECTANGLES);
640 if (res != OK) {
641 ALOGE("%s: erase face rectangles fail", __FUNCTION__);
642 return res;
643 }
644
645 res = metadata->Erase(ANDROID_STATISTICS_FACE_SCORES);
646 if (res != OK) {
647 ALOGE("%s: erase face scores fail", __FUNCTION__);
648 return res;
649 }
650
651 return OK;
652 }
653
DumpStreamConfiguration(const StreamConfiguration & stream_configuration,const std::string & title)654 void DumpStreamConfiguration(const StreamConfiguration& stream_configuration,
655 const std::string& title) {
656 std::string str = "======== " + title + " ========";
657 ALOGI("%s", str.c_str());
658 ALOGI("== stream num: %zu, operation_mode:%d",
659 stream_configuration.streams.size(),
660 stream_configuration.operation_mode);
661 for (uint32_t i = 0; i < stream_configuration.streams.size(); i++) {
662 auto& stream = stream_configuration.streams[i];
663 ALOGI("==== [%u]stream_id %d, type %d, format %d, res %ux%u, usage %" PRIu64
664 ", is_phy %d, phy_cam_id %u, group_id %d",
665 i, stream.id, stream.stream_type, stream.format, stream.width,
666 stream.height, stream.usage, stream.is_physical_camera_stream,
667 stream.physical_camera_id, stream.group_id);
668 }
669 ALOGI("%s", str.c_str());
670 }
671
DumpHalConfiguredStreams(const std::vector<HalStream> & hal_configured_streams,const std::string & title)672 void DumpHalConfiguredStreams(
673 const std::vector<HalStream>& hal_configured_streams,
674 const std::string& title) {
675 std::string str = "======== " + title + " ========";
676 ALOGI("%s", str.c_str());
677 ALOGI("== stream num: %zu", hal_configured_streams.size());
678 for (uint32_t i = 0; i < hal_configured_streams.size(); i++) {
679 auto& stream = hal_configured_streams[i];
680 ALOGI("==== [%u]stream_id:%5d override_format:%8x p_usage:%" PRIu64
681 " c_usage:%" PRIu64 " max_buf:%u is_phy:%d",
682 i, stream.id, stream.override_format, stream.producer_usage,
683 stream.consumer_usage, stream.max_buffers,
684 stream.is_physical_camera_stream);
685 }
686 ALOGI("%s", str.c_str());
687 }
688
DumpCaptureRequest(const CaptureRequest & request,const std::string & title)689 void DumpCaptureRequest(const CaptureRequest& request,
690 const std::string& title) {
691 std::string str = "======== " + title + " ========";
692 ALOGI("%s", str.c_str());
693 ALOGI("== frame_number:%u", request.frame_number);
694 ALOGI("== settings:%p", request.settings.get());
695 ALOGI("== num_output_buffers:%zu", request.output_buffers.size());
696 for (uint32_t i = 0; i < request.output_buffers.size(); i++) {
697 ALOGI("==== buf[%d] stream_id:%d buf:%p", i,
698 request.output_buffers[i].stream_id, request.output_buffers[i].buffer);
699 }
700 ALOGI("== num_input_buffers:%zu", request.input_buffers.size());
701 for (uint32_t i = 0; i < request.input_buffers.size(); i++) {
702 ALOGI("==== buf[%d] stream_id:%d buf:%p", i,
703 request.input_buffers[i].stream_id, request.input_buffers[i].buffer);
704 }
705 ALOGI("%s", str.c_str());
706 }
707
DumpCaptureResult(const ProcessBlockResult & result,const std::string & title)708 void DumpCaptureResult(const ProcessBlockResult& result,
709 const std::string& title) {
710 std::string str = "======== " + title + " ========";
711 ALOGI("%s", str.c_str());
712 ALOGI("== frame_number:%u", result.result->frame_number);
713 ALOGI("== num_output_buffers:%zu", result.result->output_buffers.size());
714 for (uint32_t i = 0; i < result.result->output_buffers.size(); i++) {
715 ALOGI("==== buf[%d] stream_id:%d bud:%" PRIu64 " handle: %p status: %d", i,
716 result.result->output_buffers[i].stream_id,
717 result.result->output_buffers[i].buffer_id,
718 result.result->output_buffers[i].buffer,
719 result.result->output_buffers[i].status);
720 }
721 ALOGI("== has_metadata:%d", result.result->result_metadata != nullptr);
722 ALOGI("== request_id:%d", result.request_id);
723 ALOGI("%s", str.c_str());
724 }
725
DumpCaptureResult(const CaptureResult & result,const std::string & title)726 void DumpCaptureResult(const CaptureResult& result, const std::string& title) {
727 std::string str = "======== " + title + " ========";
728 ALOGI("%s", str.c_str());
729 ALOGI("== frame_number:%u", result.frame_number);
730 ALOGI("== num_output_buffers:%zu", result.output_buffers.size());
731 for (uint32_t i = 0; i < result.output_buffers.size(); i++) {
732 ALOGI("==== buf[%d] stream_id:%d bud:%" PRIu64 " handle: %p status: %d", i,
733 result.output_buffers[i].stream_id, result.output_buffers[i].buffer_id,
734 result.output_buffers[i].buffer, result.output_buffers[i].status);
735 }
736 ALOGI("== has_metadata:%d", result.result_metadata != nullptr);
737 ALOGI("%s", str.c_str());
738 }
739
DumpNotify(const NotifyMessage & message,const std::string & title)740 void DumpNotify(const NotifyMessage& message, const std::string& title) {
741 std::string str = "======== " + title + " ========";
742 ALOGI("%s", str.c_str());
743 if (message.type == MessageType::kShutter) {
744 ALOGI("== frame_number:%u", message.message.shutter.frame_number);
745 ALOGI("== time_stamp:%" PRIu64, message.message.shutter.timestamp_ns);
746 } else if (message.type == MessageType::kError) {
747 ALOGI("== frame_number:%u", message.message.error.frame_number);
748 ALOGI("== error_code:%u", message.message.error.error_code);
749 }
750 ALOGI("%s", str.c_str());
751 }
752
DumpStream(const Stream & stream,const std::string & title)753 void DumpStream(const Stream& stream, const std::string& title) {
754 std::string str = "======== " + title + " ========";
755 ALOGI("%s", str.c_str());
756 ALOGI("== stream_id %d, format %d, res %ux%u, usage %" PRIu64
757 ", is_phy %d, phy_cam_id %u",
758 stream.id, stream.format, stream.width, stream.height, stream.usage,
759 stream.is_physical_camera_stream, stream.physical_camera_id);
760 ALOGI("%s", str.c_str());
761 }
762
763 // Dump HalStream
DumpHalStream(const HalStream & hal_stream,const std::string & title)764 void DumpHalStream(const HalStream& hal_stream, const std::string& title) {
765 std::string str = "======== " + title + " ========";
766 ALOGI("%s", str.c_str());
767 ALOGI("== id %d, override_format %d, producer_usage %" PRIu64 ", %" PRIu64
768 ", max_buffers %u, override_data_space %u, is_phy %u, phy_cam_id %d",
769 hal_stream.id, hal_stream.override_format, hal_stream.producer_usage,
770 hal_stream.consumer_usage, hal_stream.max_buffers,
771 hal_stream.override_data_space, hal_stream.is_physical_camera_stream,
772 hal_stream.physical_camera_id);
773 ALOGI("%s", str.c_str());
774 }
775
DumpBufferReturn(const std::vector<StreamBuffer> & stream_buffers,const std::string & title)776 void DumpBufferReturn(const std::vector<StreamBuffer>& stream_buffers,
777 const std::string& title) {
778 std::string str = "======== " + title + " ========";
779 ALOGI("%s", str.c_str());
780 for (auto stream_buffer : stream_buffers) {
781 ALOGI("== Strm id:%d, buf id:%" PRIu64, stream_buffer.stream_id,
782 stream_buffer.buffer_id);
783 }
784 ALOGI("%s", str.c_str());
785 }
786
DumpBufferRequest(const std::vector<BufferRequest> & hal_buffer_requests,const std::vector<BufferReturn> * hal_buffer_returns,const std::string & title)787 void DumpBufferRequest(const std::vector<BufferRequest>& hal_buffer_requests,
788 const std::vector<BufferReturn>* hal_buffer_returns,
789 const std::string& title) {
790 std::string str = "======== " + title + " ========";
791 ALOGI("%s", str.c_str());
792 for (const auto& buffer_request : hal_buffer_requests) {
793 ALOGI("== Strm id:%d", buffer_request.stream_id);
794 }
795 ALOGI("===");
796 for (const auto& buffer_return : *hal_buffer_returns) {
797 for (const auto& stream_buffer : buffer_return.val.buffers) {
798 ALOGI("== buf id:%" PRIu64 " stm id:%d buf:%p", stream_buffer.buffer_id,
799 stream_buffer.stream_id, stream_buffer.buffer);
800 }
801 }
802 ALOGI("%s", str.c_str());
803 }
804
805 } // namespace hal_utils
806 } // namespace google_camera_hal
807 } // namespace android
808