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