From 88b0a47eb44e3f091adcd4897fd4ad3059b30bdb Mon Sep 17 00:00:00 2001 From: Cheng Gu Date: Sat, 4 Mar 2023 17:38:15 -0800 Subject: multicam_realtime_process_block: Allow input streams No longer blocks input streams when configuring streams. Bug: 267751832 Test: build Change-Id: I72eb06d06e55c298f0c8bf1ec8fcc88adfc09e20 --- common/hal/utils/multicam_realtime_process_block.cc | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/common/hal/utils/multicam_realtime_process_block.cc b/common/hal/utils/multicam_realtime_process_block.cc index fea8f7f..da624d4 100644 --- a/common/hal/utils/multicam_realtime_process_block.cc +++ b/common/hal/utils/multicam_realtime_process_block.cc @@ -111,9 +111,8 @@ status_t MultiCameraRtProcessBlock::GetCameraStreamConfigurationMap( // Create one stream configuration for each camera. camera_stream_config_map->clear(); for (auto& stream : stream_config.streams) { - if (stream.stream_type != StreamType::kOutput || - !stream.is_physical_camera_stream) { - ALOGE("%s: Only physical output streams are supported.", __FUNCTION__); + if (!stream.is_physical_camera_stream) { + ALOGE("%s: Only physical streams are supported.", __FUNCTION__); return BAD_VALUE; } @@ -271,11 +270,6 @@ bool MultiCameraRtProcessBlock::AreRequestsValidLocked( std::unordered_set request_camera_ids; uint32_t frame_number = block_requests[0].request.frame_number; for (auto& block_request : block_requests) { - if (!block_request.request.input_buffers.empty()) { - ALOGE("%s: Input buffers are not supported.", __FUNCTION__); - return false; - } - if (block_request.request.output_buffers.size() == 0) { ALOGE("%s: request %u doesn't contain any output streams.", __FUNCTION__, block_request.request.frame_number); -- cgit v1.2.3 From acc803c9540c70d1bffa7e7bf808ce132601301a Mon Sep 17 00:00:00 2001 From: Tianyu Jiang Date: Sun, 5 Mar 2023 18:17:37 -0800 Subject: Correct the SCALER_CROP_REGION for maximum_resolution streams in GCH Without this change, crop region is always computed to active array dimension. In MAX_RES streams, crop region should have been on active array maximum resolution dimension. Bug: 268237897 Bug: 267654643 Test: manual Change-Id: I9777acc4ceca559ea918ac3c8ac3d6a3d04f41c8 --- .../hal/google_camera_hal/camera_device_session.cc | 33 +++++- common/hal/utils/zoom_ratio_mapper.cc | 125 +++++++++++++-------- common/hal/utils/zoom_ratio_mapper.h | 14 +++ 3 files changed, 124 insertions(+), 48 deletions(-) diff --git a/common/hal/google_camera_hal/camera_device_session.cc b/common/hal/google_camera_hal/camera_device_session.cc index f0fb273..1574b9d 100644 --- a/common/hal/google_camera_hal/camera_device_session.cc +++ b/common/hal/google_camera_hal/camera_device_session.cc @@ -26,9 +26,11 @@ #include "basic_capture_session.h" #include "capture_session_utils.h" #include "dual_ir_capture_session.h" +#include "hal_types.h" #include "hal_utils.h" #include "hdrplus_capture_session.h" #include "rgbird_capture_session.h" +#include "system/camera_metadata.h" #include "vendor_tag_defs.h" #include "vendor_tag_types.h" #include "vendor_tags.h" @@ -457,6 +459,21 @@ status_t CameraDeviceSession::Initialize( return OK; } +status_t GetMaxResDimension(const HalCameraMetadata* characteristics, + Dimension& max_res_dimension) { + Rect active_array_maximum_resolution_size; + status_t max_res_status = utils::GetSensorActiveArraySize( + characteristics, &active_array_maximum_resolution_size, + /*maximum_resolution*/ true); + if (max_res_status == OK) { + max_res_dimension = {active_array_maximum_resolution_size.right - + active_array_maximum_resolution_size.left + 1, + active_array_maximum_resolution_size.bottom - + active_array_maximum_resolution_size.top + 1}; + } + return max_res_status; +} + void CameraDeviceSession::InitializeZoomRatioMapper( HalCameraMetadata* characteristics) { if (characteristics == nullptr) { @@ -466,7 +483,8 @@ void CameraDeviceSession::InitializeZoomRatioMapper( Rect active_array_size; status_t res = - utils::GetSensorActiveArraySize(characteristics, &active_array_size); + utils::GetSensorActiveArraySize(characteristics, &active_array_size, + /*maximum_resolution*/ false); if (res != OK) { ALOGE("%s: Failed to get the active array size: %s(%d)", __FUNCTION__, strerror(-res), res); @@ -479,6 +497,10 @@ void CameraDeviceSession::InitializeZoomRatioMapper( active_array_size.right - active_array_size.left + 1, active_array_size.bottom - active_array_size.top + 1}; + // Populate max-res dimension only if the logical camera have max-res resolution + (void)GetMaxResDimension(characteristics, + params.active_array_maximum_resolution_dimension); + std::vector physical_camera_ids = device_session_hwl_->GetPhysicalCameraIds(); for (uint32_t id : physical_camera_ids) { @@ -493,7 +515,8 @@ void CameraDeviceSession::InitializeZoomRatioMapper( } res = utils::GetSensorActiveArraySize(physical_cam_characteristics.get(), - &active_array_size); + &active_array_size, + /*maximum_resolution*/ false); if (res != OK) { ALOGE("%s: Failed to get cam: %u, active array size: %s(%d)", __FUNCTION__, id, strerror(-res), res); @@ -504,6 +527,12 @@ void CameraDeviceSession::InitializeZoomRatioMapper( active_array_size.bottom - active_array_size.top + 1}; params.physical_cam_active_array_dimension.emplace(id, active_array_dimension); + Dimension max_res_dimension; + if (GetMaxResDimension(physical_cam_characteristics.get(), + max_res_dimension) == OK) { + params.physical_cam_active_array_maximum_resolution_dimension.emplace( + id, max_res_dimension); + } } res = utils::GetZoomRatioRange(characteristics, ¶ms.zoom_ratio_range); diff --git a/common/hal/utils/zoom_ratio_mapper.cc b/common/hal/utils/zoom_ratio_mapper.cc index 6e74bc1..47030d8 100644 --- a/common/hal/utils/zoom_ratio_mapper.cc +++ b/common/hal/utils/zoom_ratio_mapper.cc @@ -16,11 +16,13 @@ #define LOG_TAG "GCH_ZoomRatioMapper" +#include "zoom_ratio_mapper.h" + #include + #include #include "utils.h" -#include "zoom_ratio_mapper.h" namespace android { namespace google_camera_hal { @@ -34,6 +36,19 @@ int32_t kRectToConvert[] = {ANDROID_SCALER_CROP_REGION}; int32_t kResultPointsToConvert[] = {ANDROID_STATISTICS_FACE_LANDMARKS, ANDROID_STATISTICS_FACE_RECTANGLES}; +camera_metadata_enum_android_sensor_pixel_mode GetSensorPixelMode( + const HalCameraMetadata& metadata) { + camera_metadata_ro_entry sensor_pixel_mode_metadata = {}; + auto res = + metadata.Get(ANDROID_SENSOR_PIXEL_MODE, &sensor_pixel_mode_metadata); + if (res == OK && sensor_pixel_mode_metadata.data.u8 != nullptr && + sensor_pixel_mode_metadata.data.u8[0] == + ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) { + return ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION; + } + return ANDROID_SENSOR_PIXEL_MODE_DEFAULT; +} + void ZoomRatioMapper::Initialize(InitParams* params) { if (params == nullptr) { ALOGE("%s: invalid param", __FUNCTION__); @@ -41,8 +56,13 @@ void ZoomRatioMapper::Initialize(InitParams* params) { } memcpy(&active_array_dimension_, ¶ms->active_array_dimension, sizeof(active_array_dimension_)); + memcpy(&active_array_maximum_resolution_dimension_, + ¶ms->active_array_maximum_resolution_dimension, + sizeof(active_array_maximum_resolution_dimension_)); physical_cam_active_array_dimension_ = params->physical_cam_active_array_dimension; + physical_cam_active_array_maximum_resolution_dimension_ = + params->physical_cam_active_array_maximum_resolution_dimension; memcpy(&zoom_ratio_range_, ¶ms->zoom_ratio_range, sizeof(zoom_ratio_range_)); zoom_ratio_mapper_hwl_ = std::move(params->zoom_ratio_mapper_hwl); @@ -50,6 +70,54 @@ void ZoomRatioMapper::Initialize(InitParams* params) { camera_id_ = params->camera_id; } +Dimension ZoomRatioMapper::GetActiveArrayDimension( + const HalCameraMetadata& metadata, bool is_physical, + uint32_t camera_id) const { + Dimension active_array_dimension = active_array_dimension_; + + // Overwrite based on zoom_ratio_mapper_hwl_ + Dimension override_dimension; + if (zoom_ratio_mapper_hwl_ && + zoom_ratio_mapper_hwl_->GetActiveArrayDimensionToBeUsed( + camera_id, &metadata, &override_dimension)) { + active_array_dimension = override_dimension; + } + + // Overwrite based on sensor pixel mode + if (is_physical) { + if (GetSensorPixelMode(metadata) == + ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) { + auto physical_cam_iter = + physical_cam_active_array_maximum_resolution_dimension_.find( + camera_id); + LOG_ALWAYS_FATAL_IF( + physical_cam_iter == + physical_cam_active_array_maximum_resolution_dimension_.end(), + "%s: cannot process a max-res request or result on the physical " + "camera %d because it does not have max-res dimension", + __FUNCTION__, camera_id); + return physical_cam_iter->second; + } else { + auto physical_cam_iter = + physical_cam_active_array_dimension_.find(camera_id); + LOG_ALWAYS_FATAL_IF( + physical_cam_iter == physical_cam_active_array_dimension_.end(), + "%s: cannot process a request or result on the physical " + "camera %d because it does not have active array dimension", + __FUNCTION__, camera_id); + return physical_cam_iter->second; + } + } else { + if (GetSensorPixelMode(metadata) == + ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) { + return active_array_maximum_resolution_dimension_; + } else { + return active_array_dimension; + } + } + return active_array_dimension; +} + void ZoomRatioMapper::UpdateCaptureRequest(CaptureRequest* request) { if (request == nullptr) { ALOGE("%s: request is nullptr", __FUNCTION__); @@ -62,32 +130,15 @@ void ZoomRatioMapper::UpdateCaptureRequest(CaptureRequest* request) { } if (request->settings != nullptr) { - Dimension override_dimension; - Dimension active_array_dimension_chosen = active_array_dimension_; - if (zoom_ratio_mapper_hwl_ && - zoom_ratio_mapper_hwl_->GetActiveArrayDimensionToBeUsed( - camera_id_, request->settings.get(), &override_dimension)) { - active_array_dimension_chosen = override_dimension; - } - ApplyZoomRatio(active_array_dimension_chosen, true, request->settings.get()); + Dimension active_array_dimension = GetActiveArrayDimension( + *request->settings, /*is_physical*/ false, camera_id_); + ApplyZoomRatio(active_array_dimension, true, request->settings.get()); } for (auto& [camera_id, metadata] : request->physical_camera_settings) { if (metadata != nullptr) { - auto physical_cam_iter = - physical_cam_active_array_dimension_.find(camera_id); - if (physical_cam_iter == physical_cam_active_array_dimension_.end()) { - ALOGE("%s: Physical camera id %d is not found!", __FUNCTION__, - camera_id); - continue; - } - Dimension override_dimension; - Dimension physical_active_array_dimension = physical_cam_iter->second; - if (zoom_ratio_mapper_hwl_ && - zoom_ratio_mapper_hwl_->GetActiveArrayDimensionToBeUsed( - camera_id, metadata.get(), &override_dimension)) { - physical_active_array_dimension = override_dimension; - } + Dimension physical_active_array_dimension = + GetActiveArrayDimension(*metadata, /*is_physical*/ true, camera_id); ApplyZoomRatio(physical_active_array_dimension, true, metadata.get()); } } @@ -108,33 +159,15 @@ void ZoomRatioMapper::UpdateCaptureResult(CaptureResult* result) { } if (result->result_metadata != nullptr) { - Dimension override_dimension; - Dimension active_array_dimension_chosen = active_array_dimension_; - if (zoom_ratio_mapper_hwl_ && - zoom_ratio_mapper_hwl_->GetActiveArrayDimensionToBeUsed( - camera_id_, result->result_metadata.get(), &override_dimension)) { - active_array_dimension_chosen = override_dimension; - } - ApplyZoomRatio(active_array_dimension_chosen, false, - result->result_metadata.get()); + Dimension active_array_dimension = GetActiveArrayDimension( + *result->result_metadata, /*is_physical*/ false, camera_id_); + ApplyZoomRatio(active_array_dimension, false, result->result_metadata.get()); } for (auto& [camera_id, metadata] : result->physical_metadata) { if (metadata != nullptr) { - auto physical_cam_iter = - physical_cam_active_array_dimension_.find(camera_id); - if (physical_cam_iter == physical_cam_active_array_dimension_.end()) { - ALOGE("%s: Physical camera id %d is not found!", __FUNCTION__, - camera_id); - continue; - } - Dimension override_dimension; - Dimension physical_active_array_dimension = physical_cam_iter->second; - if (zoom_ratio_mapper_hwl_ && - zoom_ratio_mapper_hwl_->GetActiveArrayDimensionToBeUsed( - camera_id, metadata.get(), &override_dimension)) { - physical_active_array_dimension = override_dimension; - } + Dimension physical_active_array_dimension = + GetActiveArrayDimension(*metadata, /*is_physical*/ true, camera_id); ApplyZoomRatio(physical_active_array_dimension, false, metadata.get()); } } diff --git a/common/hal/utils/zoom_ratio_mapper.h b/common/hal/utils/zoom_ratio_mapper.h index 4fbee2f..1282ab7 100644 --- a/common/hal/utils/zoom_ratio_mapper.h +++ b/common/hal/utils/zoom_ratio_mapper.h @@ -27,7 +27,10 @@ class ZoomRatioMapper { public: struct InitParams { Dimension active_array_dimension; + Dimension active_array_maximum_resolution_dimension; std::unordered_map physical_cam_active_array_dimension; + std::unordered_map + physical_cam_active_array_maximum_resolution_dimension; ZoomRatioRange zoom_ratio_range; std::unique_ptr zoom_ratio_mapper_hwl; uint32_t camera_id; @@ -42,6 +45,10 @@ class ZoomRatioMapper { void UpdateCaptureResult(CaptureResult* result); private: + // Gets active array dimension + Dimension GetActiveArrayDimension(const HalCameraMetadata& metadata, + bool is_physical, uint32_t camera_id) const; + // Apply zoom ratio to the capture request or result. void ApplyZoomRatio(const Dimension& active_array_dimension, const bool is_request, HalCameraMetadata* metadata); @@ -67,9 +74,16 @@ class ZoomRatioMapper { // Active array dimension of logical camera. Dimension active_array_dimension_; + // Active array maximum resolution dimension of logical camera. + Dimension active_array_maximum_resolution_dimension_; + // Active array dimension of physical camera. std::unordered_map physical_cam_active_array_dimension_; + // Active array maximum resolution dimension of physical camera. + std::unordered_map + physical_cam_active_array_maximum_resolution_dimension_; + // Zoom ratio range. ZoomRatioRange zoom_ratio_range_; -- cgit v1.2.3 From 319f417cb787108da1dca1a7dedfec79520b599d Mon Sep 17 00:00:00 2001 From: Devin Cody Date: Wed, 15 Mar 2023 00:05:50 +0000 Subject: adding log_id to StreamConfiguration log_id lets us join CameraFramework metrics to Lyric metrics. BUG: 267668584 Test: Unit Change-Id: Ifb1e171dce74ab6f69d41f176a00a9bc8fa38a1a --- common/hal/aidl_service/aidl_utils.cc | 1 + common/hal/common/hal_types.h | 1 + common/hal/google_camera_hal/basic_request_processor.cc | 1 + common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc | 1 + 4 files changed, 4 insertions(+) diff --git a/common/hal/aidl_service/aidl_utils.cc b/common/hal/aidl_service/aidl_utils.cc index a7250fc..bae6dfe 100644 --- a/common/hal/aidl_service/aidl_utils.cc +++ b/common/hal/aidl_service/aidl_utils.cc @@ -935,6 +935,7 @@ status_t ConvertToHalStreamConfig( aidl_stream_config.streamConfigCounter; hal_stream_config->multi_resolution_input_image = aidl_stream_config.multiResolutionInputImage; + hal_stream_config->log_id = aidl_stream_config.logId; return OK; } diff --git a/common/hal/common/hal_types.h b/common/hal/common/hal_types.h index e27f78e..0f7f9da 100644 --- a/common/hal/common/hal_types.h +++ b/common/hal/common/hal_types.h @@ -151,6 +151,7 @@ struct StreamConfiguration { std::unique_ptr session_params; uint32_t stream_config_counter = 0; bool multi_resolution_input_image = false; + long log_id = 0; }; struct CameraIdAndStreamConfiguration { diff --git a/common/hal/google_camera_hal/basic_request_processor.cc b/common/hal/google_camera_hal/basic_request_processor.cc index c38d9e0..06beb5d 100644 --- a/common/hal/google_camera_hal/basic_request_processor.cc +++ b/common/hal/google_camera_hal/basic_request_processor.cc @@ -61,6 +61,7 @@ status_t BasicRequestProcessor::ConfigureStreams( stream_config.stream_config_counter; process_block_stream_config->multi_resolution_input_image = stream_config.multi_resolution_input_image; + process_block_stream_config->log_id = stream_config.log_id; return OK; } diff --git a/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc b/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc index be455eb..472b5bc 100644 --- a/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc +++ b/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc @@ -233,6 +233,7 @@ status_t RealtimeZslResultRequestProcessor::ConfigureStreams( stream_config.stream_config_counter; process_block_stream_config->multi_resolution_input_image = stream_config.multi_resolution_input_image; + process_block_stream_config->log_id = stream_config.log_id; return OK; } -- cgit v1.2.3 From 6142d98c97ca1e61f4eddc70c30063380fc0a070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kosi=C5=84ski?= Date: Tue, 11 Apr 2023 00:51:10 +0000 Subject: Fix libgooglecamerahal_headers. Enable on host and add libcamera_metadata as a dependency, since the headers include . Bug: 277650648 Test: presubmit Change-Id: I132c1657ef7d934817f330bfbe2ea5dac4483112 --- common/hal/Android.bp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/hal/Android.bp b/common/hal/Android.bp index f953dc8..6b9d31c 100644 --- a/common/hal/Android.bp +++ b/common/hal/Android.bp @@ -22,11 +22,14 @@ package { cc_library_headers { name: "libgooglecamerahal_headers", vendor: true, + host_supported: true, export_include_dirs: [ "common", "hwl_interface", "utils", ], + shared_libs: ["libcamera_metadata"], + export_shared_lib_headers: ["libcamera_metadata"], } cc_defaults { -- cgit v1.2.3 From 542a6e28961c3c1aed3999af7cd085a862968282 Mon Sep 17 00:00:00 2001 From: Speth Chang Date: Thu, 27 Apr 2023 19:15:42 +0800 Subject: ZslSnapshotCaptureSession: reduce log level for non-error case Change log level to information if the stream configuration is not compatible. Bug: 251044817 Test: GCA Change-Id: I59d5e7137acc9d229f7367e61b5bac0fb7d9194a --- .../google_camera_hal/zsl_snapshot_capture_session.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/hal/google_camera_hal/zsl_snapshot_capture_session.cc b/common/hal/google_camera_hal/zsl_snapshot_capture_session.cc index 8d9e6d7..f6e658a 100644 --- a/common/hal/google_camera_hal/zsl_snapshot_capture_session.cc +++ b/common/hal/google_camera_hal/zsl_snapshot_capture_session.cc @@ -211,7 +211,7 @@ bool ZslSnapshotCaptureSession::IsStreamConfigurationSupported( camera_metadata_ro_entry entry; res = characteristics->Get(VendorTagIds::kSwDenoiseEnabled, &entry); if (res != OK || entry.data.u8[0] != 1) { - ALOGE("%s: Software denoised not enabled", __FUNCTION__); + ALOGI("%s: Software denoised not enabled", __FUNCTION__); return false; } @@ -220,11 +220,11 @@ bool ZslSnapshotCaptureSession::IsStreamConfigurationSupported( bool has_hdr_preview_stream = false; for (const auto& stream : stream_config.streams) { if (stream.is_physical_camera_stream) { - ALOGE("%s: support logical stream only", __FUNCTION__); + ALOGI("%s: support logical stream only", __FUNCTION__); return false; } if (utils::IsSecuredStream(stream)) { - ALOGE("%s: don't support secured stream", __FUNCTION__); + ALOGI("%s: don't support secured stream", __FUNCTION__); return false; } if (utils::IsJPEGSnapshotStream(stream) || @@ -238,27 +238,27 @@ bool ZslSnapshotCaptureSession::IsStreamConfigurationSupported( has_hdr_preview_stream = true; } } else { - ALOGE("%s: only support preview + (snapshot and/or YUV) streams", + ALOGI("%s: only support preview + (snapshot and/or YUV) streams", __FUNCTION__); return false; } } if (!has_eligible_snapshot_stream) { - ALOGE("%s: no eligible JPEG or YUV stream", __FUNCTION__); + ALOGI("%s: no eligible JPEG or YUV stream", __FUNCTION__); return false; } if (!has_preview_stream) { - ALOGE("%s: no preview stream", __FUNCTION__); + ALOGI("%s: no preview stream", __FUNCTION__); return false; } if (has_hdr_preview_stream) { - ALOGE("%s: 10-bit HDR preview stream does not support ZSL snapshot", + ALOGI("%s: 10-bit HDR preview stream does not support ZSL snapshot", __FUNCTION__); return false; } - ALOGD("%s: ZslSnapshotCaptureSession supports the stream config", + ALOGI("%s: ZslSnapshotCaptureSession supports the stream config", __FUNCTION__); return true; } -- cgit v1.2.3 From 9aa67d3323da140abc065b9959e7ae9029484110 Mon Sep 17 00:00:00 2001 From: Speth Chang Date: Wed, 17 May 2023 06:57:24 +0000 Subject: Deliver physical camera settings to HWL Bug: 281489971 Test: GCA, CTS Change-Id: I75a2f48df2c98230ed6427ee57061738efb4d497 --- common/hal/hwl_interface/hwl_types.h | 4 ++++ common/hal/utils/hal_utils.cc | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/common/hal/hwl_interface/hwl_types.h b/common/hal/hwl_interface/hwl_types.h index cfe4622..8168a7d 100644 --- a/common/hal/hwl_interface/hwl_types.h +++ b/common/hal/hwl_interface/hwl_types.h @@ -46,6 +46,10 @@ struct HwlPipelineRequest { std::vector output_buffers; + // Maps from physical camera ID to physical camera settings. + std::unordered_map> + physical_camera_settings; + int32_t input_width; int32_t input_height; }; diff --git a/common/hal/utils/hal_utils.cc b/common/hal/utils/hal_utils.cc index 58febe7..3412542 100644 --- a/common/hal/utils/hal_utils.cc +++ b/common/hal/utils/hal_utils.cc @@ -50,6 +50,11 @@ status_t CreateHwlPipelineRequest(HwlPipelineRequest* hwl_request, HalCameraMetadata::Clone(metadata.get())); } + for (auto& [camera_id, physical_metadata] : request.physical_camera_settings) { + hwl_request->physical_camera_settings.emplace( + camera_id, HalCameraMetadata::Clone(physical_metadata.get())); + } + return OK; } -- cgit v1.2.3 From d168b8f60c04661a3a0f19672560d527be1618b2 Mon Sep 17 00:00:00 2001 From: Cherry Ng Date: Wed, 17 May 2023 16:21:21 +0800 Subject: Remove //hardware/google/camera soong namespace. This allows all packages auto-enroll to the generic build & prebuilt unit tests supported by build team. Bug: 260807850 Test: build, presubmit Change-Id: I48f1c1613a69e13a48816772121bdbb518e8d854 --- Android.bp | 3 --- common/hal/aidl_service/Android.bp | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Android.bp b/Android.bp index c199173..57e147b 100644 --- a/Android.bp +++ b/Android.bp @@ -1,6 +1,3 @@ -soong_namespace { -} - package { // See: http://go/android-license-faq default_applicable_licenses: ["Android-Apache-2.0"], diff --git a/common/hal/aidl_service/Android.bp b/common/hal/aidl_service/Android.bp index 179a826..4fc1158 100644 --- a/common/hal/aidl_service/Android.bp +++ b/common/hal/aidl_service/Android.bp @@ -122,7 +122,7 @@ cc_defaults { } cc_defaults { - name: "camera_service_defaults", + name: "hardware_camera_service_defaults", defaults: [ "camera_service_defaults_common", ], @@ -135,7 +135,7 @@ cc_defaults { cc_binary { name: "android.hardware.camera.provider@2.7-service-google", defaults: [ - "camera_service_defaults", + "hardware_camera_service_defaults", "camera_service_eager_hal_defaults", ], init_rc: ["android.hardware.camera.provider@2.7-service-google.rc"], @@ -144,7 +144,7 @@ cc_binary { cc_binary { name: "android.hardware.camera.provider@2.7-service-google-lazy", defaults: [ - "camera_service_defaults", + "hardware_camera_service_defaults", "camera_service_lazy_hal_defaults", ], init_rc: ["android.hardware.camera.provider@2.7-service-google-lazy.rc"], -- cgit v1.2.3 From eb479b935169cd60ce4ebcd13231ce27a9627696 Mon Sep 17 00:00:00 2001 From: Cherry Ng Date: Fri, 19 May 2023 08:06:27 +0800 Subject: Add test-only static library of lib_profiler. Test: build & presubmit Bug: 260807850 Change-Id: I50e90c8ca6fee3dfd0a024f54f390e69370b30fd --- common/profiler/Android.bp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/common/profiler/Android.bp b/common/profiler/Android.bp index 990d148..4a5a0dd 100644 --- a/common/profiler/Android.bp +++ b/common/profiler/Android.bp @@ -36,9 +36,8 @@ cc_library_static { host_supported: true, } -cc_library_shared { - name: - "lib_profiler", +cc_defaults { + name: "lib_profiler_defaults", srcs: [ "profiler.cc", @@ -71,3 +70,16 @@ cc_library_shared { host_supported: true, rtti: true, } + +cc_library_shared { + name: "lib_profiler", + defaults: ["lib_profiler_defaults"], +} + +cc_test_library { + name: "lib_profiler_for_test", + defaults: ["lib_profiler_defaults"], + shared: { + enabled: false, + }, +} -- cgit v1.2.3 From 507b8a4fc42727d8dbdb7b356ae125985462a123 Mon Sep 17 00:00:00 2001 From: Tianyu Jiang Date: Tue, 23 May 2023 16:30:15 -0700 Subject: Add status to the log when error happens Bug: 270214632 Test: build Change-Id: I9829800d638b6feb145ee6e45cae7c028be36ac5 --- common/hal/google_camera_hal/camera_device_session.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/common/hal/google_camera_hal/camera_device_session.cc b/common/hal/google_camera_hal/camera_device_session.cc index 1574b9d..621fd6f 100644 --- a/common/hal/google_camera_hal/camera_device_session.cc +++ b/common/hal/google_camera_hal/camera_device_session.cc @@ -1183,7 +1183,8 @@ status_t CameraDeviceSession::HandleInactiveStreams(const CaptureRequest& reques status_t res = stream_buffer_cache_manager_->IsStreamActive( stream_buffer.stream_id, &is_active); if (res != OK) { - ALOGE("%s: Failed to check if stream is active.", __FUNCTION__); + ALOGE("%s: Failed to check if stream is active, error status: %s(%d)", + __FUNCTION__, strerror(-res), res); return UNKNOWN_ERROR; } if (!is_active) { @@ -1749,8 +1750,10 @@ status_t CameraDeviceSession::RegisterStreamsIntoCacheManagerLocked( status_t res = stream_buffer_cache_manager_->RegisterStream(reg_info); if (res != OK) { - ALOGE("%s: Failed to register stream into stream buffer cache manager.", - __FUNCTION__); + ALOGE( + "%s: Failed to register stream into stream buffer cache manager, " + "error status: %s(%d)", + __FUNCTION__, strerror(-res), res); return UNKNOWN_ERROR; } ALOGI("%s: [sbc] Registered stream %d into SBC manager.", __FUNCTION__, @@ -1777,7 +1780,10 @@ status_t CameraDeviceSession::RequestBuffersFromStreamBufferCacheManager( status_t res = this->stream_buffer_cache_manager_->GetStreamBuffer( stream_id, &buffer_request_result); if (res != OK) { - ALOGE("%s: Failed to get stream buffer from SBC manager.", __FUNCTION__); + ALOGE( + "%s: Failed to get stream buffer from SBC manager, error status: " + "%s(%d).", + __FUNCTION__, strerror(-res), res); return UNKNOWN_ERROR; } @@ -1881,8 +1887,8 @@ status_t CameraDeviceSession::RequestStreamBuffers( if (status != BufferRequestStatus::kOk || buffer_returns.size() != 1) { ALOGW( "%s: Requesting stream buffer failed. (buffer_returns has %zu " - "entries)", - __FUNCTION__, buffer_returns.size()); + "entries; status is %s(%d)).", + __FUNCTION__, buffer_returns.size(), strerror(-res), status); for (auto& buffer_return : buffer_returns) { ALOGI("%s: stream %d, buffer request error %d", __FUNCTION__, buffer_return.stream_id, buffer_return.val.error); -- cgit v1.2.3 From a476527aa8942b3bd82c9393eb0a88359400c4ee Mon Sep 17 00:00:00 2001 From: Minghui Tan Date: Tue, 23 May 2023 21:13:39 -0700 Subject: Do not notify error for internal streams. Bug: 284062202 Fix: 284062202 Test: the error log is gone Test: CTS Change-Id: Ifc49e15db916c50d0b7edf542d3b60823d687b5f --- common/hal/google_camera_hal/realtime_zsl_result_processor.cc | 8 +++++++- .../google_camera_hal/realtime_zsl_result_request_processor.cc | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/common/hal/google_camera_hal/realtime_zsl_result_processor.cc b/common/hal/google_camera_hal/realtime_zsl_result_processor.cc index 0475c46..6580167 100644 --- a/common/hal/google_camera_hal/realtime_zsl_result_processor.cc +++ b/common/hal/google_camera_hal/realtime_zsl_result_processor.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -//#define LOG_NDEBUG 0 +// #define LOG_NDEBUG 0 #include "hal_types.h" #define LOG_TAG "GCH_RealtimeZslResultProcessor" #define ATRACE_TAG ATRACE_TAG_CAMERA @@ -263,6 +263,12 @@ void RealtimeZslResultProcessor::Notify( return; } + // Do not notify errors for internal streams + if (message.type == MessageType::kError && + message.message.error.error_stream_id == stream_id_) { + return; + } + notify_(message); } diff --git a/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc b/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc index 472b5bc..d9a851a 100644 --- a/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc +++ b/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc @@ -351,6 +351,13 @@ void RealtimeZslResultRequestProcessor::Notify( message.message.shutter.timestamp_ns, message.message.shutter.readout_timestamp_ns); } + + // Do not notify errors for internal streams + if (message.type == MessageType::kError && + message.message.error.error_stream_id == stream_id_) { + return; + } + notify_(message); } -- cgit v1.2.3 From 214c08a5c396c1353b4ad46a3ab4c45e65306b72 Mon Sep 17 00:00:00 2001 From: Michelle Ho Date: Thu, 25 May 2023 10:57:21 +0000 Subject: Add max device state enum for validation Device state is a bit field data, and we need to define a max value for data validation. Bug: 284098431 Test: build pass, basic functionality tests Change-Id: I54e97d087b6b899d87a75d4fb2841c5d52f5801c --- common/hal/common/hal_types.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/hal/common/hal_types.h b/common/hal/common/hal_types.h index 0f7f9da..8695418 100644 --- a/common/hal/common/hal_types.h +++ b/common/hal/common/hal_types.h @@ -386,9 +386,10 @@ struct BufferReturn { // ::android::hardware::camera::provider::V2_5::DeviceState enum class DeviceState : uint64_t { kNormal = 0ull, - kBackCovered = 1ull, - kFrontCovered = 2ull, - kFolded = 4ull + kBackCovered = 1 << 0, + kFrontCovered = 1 << 1, + kFolded = 1 << 2, + kMaxDeviceState = 1 << 3 // for data validation }; // Callback function invoked to process capture results. -- cgit v1.2.3 From b1bcb49cff838a5ff1fe3558b83c600ddbf0f52f Mon Sep 17 00:00:00 2001 From: Devin Cody Date: Fri, 2 Jun 2023 01:45:15 +0000 Subject: Add log_id to all other processors Previously framework ID was only passed in basic_request_processor and zsl_result_request_processor. Bug:285444361 Test: m Change-Id: Id23d77804dd2527784d0a86acb3685561e749efb --- common/hal/google_camera_hal/dual_ir_request_processor.cc | 1 + common/hal/google_camera_hal/realtime_zsl_request_processor.cc | 1 + common/hal/google_camera_hal/rgbird_result_request_processor.cc | 1 + common/hal/google_camera_hal/rgbird_rt_request_processor.cc | 1 + common/hal/google_camera_hal/snapshot_request_processor.cc | 1 + common/hal/utils/hdrplus_request_processor.cc | 1 + 6 files changed, 6 insertions(+) diff --git a/common/hal/google_camera_hal/dual_ir_request_processor.cc b/common/hal/google_camera_hal/dual_ir_request_processor.cc index c4fca0b..b8aa769 100644 --- a/common/hal/google_camera_hal/dual_ir_request_processor.cc +++ b/common/hal/google_camera_hal/dual_ir_request_processor.cc @@ -73,6 +73,7 @@ status_t DualIrRequestProcessor::ConfigureStreams( HalCameraMetadata::Clone(stream_config.session_params.get()); process_block_stream_config->stream_config_counter = stream_config.stream_config_counter; + process_block_stream_config->log_id = stream_config.log_id; for (auto& stream : process_block_stream_config->streams) { // Assign all logical streams to the lead camera. diff --git a/common/hal/google_camera_hal/realtime_zsl_request_processor.cc b/common/hal/google_camera_hal/realtime_zsl_request_processor.cc index c5db47d..8232456 100644 --- a/common/hal/google_camera_hal/realtime_zsl_request_processor.cc +++ b/common/hal/google_camera_hal/realtime_zsl_request_processor.cc @@ -250,6 +250,7 @@ status_t RealtimeZslRequestProcessor::ConfigureStreams( HalCameraMetadata::Clone(stream_config.session_params.get()); process_block_stream_config->stream_config_counter = stream_config.stream_config_counter; + process_block_stream_config->log_id = stream_config.log_id; return OK; } diff --git a/common/hal/google_camera_hal/rgbird_result_request_processor.cc b/common/hal/google_camera_hal/rgbird_result_request_processor.cc index ee41697..e48e3d1 100644 --- a/common/hal/google_camera_hal/rgbird_result_request_processor.cc +++ b/common/hal/google_camera_hal/rgbird_result_request_processor.cc @@ -754,6 +754,7 @@ status_t RgbirdResultRequestProcessor::ConfigureStreams( process_block_stream_config->stream_config_counter = stream_config.stream_config_counter; } + process_block_stream_config->log_id = stream_config.log_id; return OK; } diff --git a/common/hal/google_camera_hal/rgbird_rt_request_processor.cc b/common/hal/google_camera_hal/rgbird_rt_request_processor.cc index cf2c6a3..1e752c4 100644 --- a/common/hal/google_camera_hal/rgbird_rt_request_processor.cc +++ b/common/hal/google_camera_hal/rgbird_rt_request_processor.cc @@ -447,6 +447,7 @@ status_t RgbirdRtRequestProcessor::ConfigureStreams( HalCameraMetadata::Clone(stream_config.session_params.get()); process_block_stream_config->stream_config_counter = stream_config.stream_config_counter; + process_block_stream_config->log_id = stream_config.log_id; bool has_depth_stream = false; for (auto& stream : stream_config.streams) { diff --git a/common/hal/google_camera_hal/snapshot_request_processor.cc b/common/hal/google_camera_hal/snapshot_request_processor.cc index bd07b55..3c66860 100644 --- a/common/hal/google_camera_hal/snapshot_request_processor.cc +++ b/common/hal/google_camera_hal/snapshot_request_processor.cc @@ -119,6 +119,7 @@ status_t SnapshotRequestProcessor::ConfigureStreams( HalCameraMetadata::Clone(stream_config.session_params.get()); process_block_stream_config->stream_config_counter = stream_config.stream_config_counter; + process_block_stream_config->log_id = stream_config.log_id; return OK; } diff --git a/common/hal/utils/hdrplus_request_processor.cc b/common/hal/utils/hdrplus_request_processor.cc index 36d2f83..9ca39fb 100644 --- a/common/hal/utils/hdrplus_request_processor.cc +++ b/common/hal/utils/hdrplus_request_processor.cc @@ -138,6 +138,7 @@ status_t HdrplusRequestProcessor::ConfigureStreams( HalCameraMetadata::Clone(stream_config.session_params.get()); process_block_stream_config->stream_config_counter = stream_config.stream_config_counter; + process_block_stream_config->log_id = stream_config.log_id; return OK; } -- cgit v1.2.3 From dfa0473dfc96bf6ac29a98bacc11c23841926e9b Mon Sep 17 00:00:00 2001 From: Cheng Gu Date: Fri, 9 Jun 2023 16:46:36 -0700 Subject: realtime_zsl: Avoid reading pending_request after erasure The entry erased by: pending_frame_number_to_requests_.erase(result->frame_number); is actually the `pending_request`. So after the erasure it must not be accessed again. This commit fixes a use-after-free bug introduced by commit 31fa05e. Fix: 279845929 Test: CTS Change-Id: I91197513377b5e3f7972c3f521cfbd94614ae36f --- .../hal/google_camera_hal/realtime_zsl_result_request_processor.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc b/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc index d9a851a..93e5844 100644 --- a/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc +++ b/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc @@ -407,13 +407,16 @@ void RealtimeZslResultRequestProcessor::ReturnResultDirectlyForFramesWithErrorsL // the callback directly. Otherwise wait until the missing pieces arrive. CombineErrorAndPendingEntriesToResult(error_entry, pending_request, result); + const bool has_returned_output_to_internal_stream_manager = + pending_request.has_returned_output_to_internal_stream_manager; + if (AllDataCollected(error_entry)) { pending_error_frames_.erase(result->frame_number); pending_frame_number_to_requests_.erase(result->frame_number); } // Don't send result to framework if only internal raw callback - if (pending_request.has_returned_output_to_internal_stream_manager && + if (has_returned_output_to_internal_stream_manager && result->result_metadata == nullptr && result->output_buffers.size() == 0) { return; } -- cgit v1.2.3 From 576da27e5ad43bae21960576d8900c1fe8e86030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kosi=C5=84ski?= Date: Sat, 22 Jul 2023 03:51:05 +0000 Subject: Replace GCH use of thermal HIDL with AIDL. Fix: 292292737 Test: run the HAL and check GCH logs Change-Id: Ib4f28bb7c1eed36e066dbf12bad3593bf546ed15 --- common/hal/aidl_service/Android.bp | 5 +- .../hal/aidl_service/aidl_camera_device_session.cc | 192 ++++++++--------- .../hal/aidl_service/aidl_camera_device_session.h | 127 +++++------ common/hal/aidl_service/aidl_thermal_utils.cc | 230 ++++++++++++++++++++ common/hal/aidl_service/aidl_thermal_utils.h | 70 ++++++ common/hal/aidl_service/hidl_thermal_utils.cc | 236 --------------------- common/hal/aidl_service/hidl_thermal_utils.h | 79 ------- 7 files changed, 466 insertions(+), 473 deletions(-) create mode 100644 common/hal/aidl_service/aidl_thermal_utils.cc create mode 100644 common/hal/aidl_service/aidl_thermal_utils.h delete mode 100644 common/hal/aidl_service/hidl_thermal_utils.cc delete mode 100644 common/hal/aidl_service/hidl_thermal_utils.h diff --git a/common/hal/aidl_service/Android.bp b/common/hal/aidl_service/Android.bp index 4fc1158..26556fd 100644 --- a/common/hal/aidl_service/Android.bp +++ b/common/hal/aidl_service/Android.bp @@ -81,7 +81,7 @@ cc_defaults { "aidl_camera_device_session.cc", "aidl_camera_provider.cc", "aidl_profiler.cc", - "hidl_thermal_utils.cc", + "aidl_thermal_utils.cc", "aidl_utils.cc", "libc_wrappers.cc", ], @@ -96,8 +96,6 @@ cc_defaults { "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@3.0", "android.hardware.graphics.mapper@4.0", - "android.hardware.thermal@1.0", - "android.hardware.thermal@2.0", "android.hardware.thermal-V1-ndk", "libbinder", "libbinder_ndk", @@ -117,7 +115,6 @@ cc_defaults { ], static_libs: [ "libaidlcommonsupport", - "libthermalutils", ], } diff --git a/common/hal/aidl_service/aidl_camera_device_session.cc b/common/hal/aidl_service/aidl_camera_device_session.cc index 9a69d74..64acd2f 100644 --- a/common/hal/aidl_service/aidl_camera_device_session.cc +++ b/common/hal/aidl_service/aidl_camera_device_session.cc @@ -16,7 +16,7 @@ #define LOG_TAG "GCH_AidlCameraDeviceSession" #define ATRACE_TAG ATRACE_TAG_CAMERA -//#define LOG_NDEBUG 0 +// #define LOG_NDEBUG 0 #include "aidl_camera_device_session.h" #include @@ -26,7 +26,6 @@ #include #include #include -#include #include #include "aidl_profiler.h" @@ -39,20 +38,28 @@ namespace implementation { namespace aidl_utils = ::android::hardware::camera::implementation::aidl_utils; -using aidl::android::hardware::camera::common::Status; -using aidl::android::hardware::camera::device::BufferRequest; -using aidl::android::hardware::camera::device::BufferRequestStatus; -using aidl::android::hardware::camera::device::CaptureResult; -using aidl::android::hardware::camera::device::HalStream; -using aidl::android::hardware::camera::device::NotifyMsg; -using aidl::android::hardware::camera::device::StreamBuffer; -using aidl::android::hardware::camera::device::StreamBufferRet; -using aidl::android::hardware::camera::device::StreamBuffersVal; -using aidl_utils::ConvertToAidlReturn; -using ::android::hardware::thermal::V1_0::ThermalStatus; -using ::android::hardware::thermal::V1_0::ThermalStatusCode; -using ::android::hardware::thermal::V2_0::Temperature; -using ::android::hardware::thermal::V2_0::TemperatureType; +using ::aidl::android::hardware::camera::common::Status; +using ::aidl::android::hardware::camera::device::BufferCache; +using ::aidl::android::hardware::camera::device::BufferRequest; +using ::aidl::android::hardware::camera::device::BufferRequestStatus; +using ::aidl::android::hardware::camera::device::CameraMetadata; +using ::aidl::android::hardware::camera::device::CameraOfflineSessionInfo; +using ::aidl::android::hardware::camera::device::CaptureRequest; +using ::aidl::android::hardware::camera::device::CaptureResult; +using ::aidl::android::hardware::camera::device::HalStream; +using ::aidl::android::hardware::camera::device::ICameraDeviceCallback; +using ::aidl::android::hardware::camera::device::ICameraDeviceSession; +using ::aidl::android::hardware::camera::device::ICameraOfflineSession; +using ::aidl::android::hardware::camera::device::NotifyMsg; +using ::aidl::android::hardware::camera::device::RequestTemplate; +using ::aidl::android::hardware::camera::device::StreamBuffer; +using ::aidl::android::hardware::camera::device::StreamBufferRet; +using ::aidl::android::hardware::camera::device::StreamBuffersVal; +using ::aidl::android::hardware::camera::device::StreamConfiguration; +using ::aidl::android::hardware::thermal::Temperature; +using ::aidl::android::hardware::thermal::TemperatureType; +using ::android::hardware::camera::implementation::AidlProfiler; +using ::android::hardware::camera::implementation::aidl_utils::ConvertToAidlReturn; std::shared_ptr AidlCameraDeviceSession::Create( const std::shared_ptr& callback, @@ -389,29 +396,17 @@ status_t AidlCameraDeviceSession::Initialize( } const std::string thermal_instance_name = - std::string(::aidl::android::hardware::thermal::IThermal::descriptor) + + std::string(aidl::android::hardware::thermal::IThermal::descriptor) + "/default"; if (AServiceManager_isDeclared(thermal_instance_name.c_str())) { - auto thermal_aidl_service = - ::aidl::android::hardware::thermal::IThermal::fromBinder(ndk::SpAIBinder( + auto thermal_ = + aidl::android::hardware::thermal::IThermal::fromBinder(ndk::SpAIBinder( AServiceManager_waitForService(thermal_instance_name.c_str()))); - if (thermal_aidl_service) { - thermal_ = - sp<::aidl::android::hardware::thermal::ThermalHidlWrapper>::make( - thermal_aidl_service); - } else { - ALOGW("Unable to get Thermal AIDL service; trying Thermal HIDL service"); + if (!thermal_) { + ALOGW("Unable to get Thermal AIDL service"); } } else { - ALOGW("Thermal AIDL service is not declared; trying Thermal HIDL service"); - } - - if (!thermal_) { - thermal_ = android::hardware::thermal::V2_0::IThermal::getService(); - } - if (thermal_ == nullptr) { - ALOGE("%s: Getting thermal failed.", __FUNCTION__); - // Continue without getting thermal information. + ALOGW("Thermal AIDL service is not declared"); } aidl_device_callback_ = callback; @@ -465,7 +460,7 @@ void AidlCameraDeviceSession::SetSessionCallbacks() { status_t AidlCameraDeviceSession::RegisterThermalChangedCallback( google_camera_hal::NotifyThrottlingFunc notify_throttling, bool filter_type, google_camera_hal::TemperatureType type) { - std::lock_guard lock(hidl_thermal_mutex_); + std::lock_guard lock(aidl_thermal_mutex_); if (thermal_ == nullptr) { ALOGE("%s: thermal was not initialized.", __FUNCTION__); return NO_INIT; @@ -476,24 +471,31 @@ status_t AidlCameraDeviceSession::RegisterThermalChangedCallback( return ALREADY_EXISTS; } - TemperatureType hidl_type; - status_t res = - hidl_thermal_utils::ConvertToHidlTemperatureType(type, &hidl_type); - if (res != OK) { - ALOGE("%s: Converting to HIDL type failed: %s(%d)", __FUNCTION__, - strerror(-res), res); - return res; + TemperatureType aidl_type = TemperatureType::UNKNOWN; + if (filter_type) { + status_t res = + aidl_thermal_utils::ConvertToAidlTemperatureType(type, &aidl_type); + if (res != OK) { + ALOGE("%s: Converting to AIDL type failed: %s(%d)", __FUNCTION__, + strerror(-res), res); + return res; + } } - std::unique_ptr callback = - hidl_thermal_utils::HidlThermalChangedCallback::Create(notify_throttling); - thermal_changed_callback_ = callback.release(); - ThermalStatus thermal_status; - auto hidl_res = thermal_->registerThermalChangedCallback( - thermal_changed_callback_, filter_type, hidl_type, - [&](ThermalStatus status) { thermal_status = status; }); - if (!hidl_res.isOk() || thermal_status.code != ThermalStatusCode::SUCCESS) { + thermal_changed_callback_ = + ndk::SharedRefBase::make( + notify_throttling); + ndk::ScopedAStatus status; + if (filter_type) { + status = thermal_->registerThermalChangedCallbackWithType( + thermal_changed_callback_, aidl_type); + } else { + status = thermal_->registerThermalChangedCallback(thermal_changed_callback_); + } + if (!status.isOk()) { thermal_changed_callback_ = nullptr; + ALOGE("%s: Error when registering thermal changed callback: %s", + __FUNCTION__, status.getMessage()); return UNKNOWN_ERROR; } @@ -501,7 +503,7 @@ status_t AidlCameraDeviceSession::RegisterThermalChangedCallback( } void AidlCameraDeviceSession::UnregisterThermalChangedCallback() { - std::lock_guard lock(hidl_thermal_mutex_); + std::lock_guard lock(aidl_thermal_mutex_); if (thermal_changed_callback_ == nullptr) { // no-op if no thermal changed callback is registered. return; @@ -512,13 +514,11 @@ void AidlCameraDeviceSession::UnregisterThermalChangedCallback() { return; } - ThermalStatus thermal_status; - auto hidl_res = thermal_->unregisterThermalChangedCallback( - thermal_changed_callback_, - [&](ThermalStatus status) { thermal_status = status; }); - if (!hidl_res.isOk() || thermal_status.code != ThermalStatusCode::SUCCESS) { + auto status = + thermal_->unregisterThermalChangedCallback(thermal_changed_callback_); + if (!status.isOk()) { ALOGW("%s: Unregstering thermal callback failed: %s", __FUNCTION__, - thermal_status.debugMessage.c_str()); + status.getMessage()); } thermal_changed_callback_ = nullptr; @@ -551,23 +551,23 @@ status_t AidlCameraDeviceSession::CreateMetadataQueue( return OK; } -ScopedAStatus AidlCameraDeviceSession::constructDefaultRequestSettings( +ndk::ScopedAStatus AidlCameraDeviceSession::constructDefaultRequestSettings( RequestTemplate type, CameraMetadata* aidl_return) { ATRACE_NAME("AidlCameraDeviceSession::constructDefaultRequestSettings"); if (aidl_return == nullptr) { - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::ILLEGAL_ARGUMENT)); } aidl_return->metadata.clear(); if (device_session_ == nullptr) { - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::INTERNAL_ERROR)); } google_camera_hal::RequestTemplate hal_type; status_t res = aidl_utils::ConvertToHalTemplateType(type, &hal_type); if (res != OK) { - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::ILLEGAL_ARGUMENT)); } @@ -580,20 +580,20 @@ ScopedAStatus AidlCameraDeviceSession::constructDefaultRequestSettings( uint32_t metadata_size = settings->GetCameraMetadataSize(); uint8_t* settings_p = (uint8_t*)settings->ReleaseCameraMetadata(); aidl_return->metadata.assign(settings_p, settings_p + metadata_size); - return ScopedAStatus::ok(); + return ndk::ScopedAStatus::ok(); } -ScopedAStatus AidlCameraDeviceSession::configureStreams( +ndk::ScopedAStatus AidlCameraDeviceSession::configureStreams( const StreamConfiguration& requestedConfiguration, std::vector* aidl_return) { ATRACE_NAME("AidlCameraDeviceSession::configureStreams"); if (aidl_return == nullptr) { - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::ILLEGAL_ARGUMENT)); } aidl_return->clear(); if (device_session_ == nullptr) { - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::ILLEGAL_ARGUMENT)); } @@ -615,7 +615,7 @@ ScopedAStatus AidlCameraDeviceSession::configureStreams( status_t res = aidl_utils::ConvertToHalStreamConfig( requestedConfigurationOverriddenSensorPixelModes, &hal_stream_config); if (res != OK) { - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::ILLEGAL_ARGUMENT)); } @@ -633,28 +633,30 @@ ScopedAStatus AidlCameraDeviceSession::configureStreams( if (res != OK) { return aidl_utils::ConvertToAidlReturn(res); } - return ScopedAStatus::ok(); + return ndk::ScopedAStatus::ok(); } -ScopedAStatus AidlCameraDeviceSession::getCaptureRequestMetadataQueue( - ::aidl::android::hardware::common::fmq::MQDescriptor< - int8_t, SynchronizedReadWrite>* aidl_return) { +ndk::ScopedAStatus AidlCameraDeviceSession::getCaptureRequestMetadataQueue( + aidl::android::hardware::common::fmq::MQDescriptor< + int8_t, aidl::android::hardware::common::fmq::SynchronizedReadWrite>* + aidl_return) { *aidl_return = request_metadata_queue_->dupeDesc(); - return ScopedAStatus::ok(); + return ndk::ScopedAStatus::ok(); } -ScopedAStatus AidlCameraDeviceSession::getCaptureResultMetadataQueue( - ::aidl::android::hardware::common::fmq::MQDescriptor< - int8_t, SynchronizedReadWrite>* aidl_return) { +ndk::ScopedAStatus AidlCameraDeviceSession::getCaptureResultMetadataQueue( + aidl::android::hardware::common::fmq::MQDescriptor< + int8_t, aidl::android::hardware::common::fmq::SynchronizedReadWrite>* + aidl_return) { *aidl_return = result_metadata_queue_->dupeDesc(); - return ScopedAStatus::ok(); + return ndk::ScopedAStatus::ok(); } -ScopedAStatus AidlCameraDeviceSession::processCaptureRequest( +ndk::ScopedAStatus AidlCameraDeviceSession::processCaptureRequest( const std::vector& requests, const std::vector& cachesToRemove, int32_t* aidl_return) { if (aidl_return == nullptr || device_session_ == nullptr) { - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::ILLEGAL_ARGUMENT)); } *aidl_return = 0; @@ -677,7 +679,7 @@ ScopedAStatus AidlCameraDeviceSession::processCaptureRequest( if (profile_first_request) { ATRACE_END(); } - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::ILLEGAL_ARGUMENT)); } @@ -716,7 +718,7 @@ ScopedAStatus AidlCameraDeviceSession::processCaptureRequest( } if (num_processed_requests > INT_MAX) { cleanupHandles(handles_to_delete); - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::ILLEGAL_ARGUMENT)); } *aidl_return = (int32_t)num_processed_requests; @@ -727,17 +729,17 @@ ScopedAStatus AidlCameraDeviceSession::processCaptureRequest( return aidl_utils::ConvertToAidlReturn(res); } -ScopedAStatus AidlCameraDeviceSession::signalStreamFlush( +ndk::ScopedAStatus AidlCameraDeviceSession::signalStreamFlush( const std::vector&, int32_t) { // TODO(b/143902312): Implement this. - return ScopedAStatus::ok(); + return ndk::ScopedAStatus::ok(); } -ScopedAStatus AidlCameraDeviceSession::flush() { +ndk::ScopedAStatus AidlCameraDeviceSession::flush() { ATRACE_NAME("AidlCameraDeviceSession::flush"); ATRACE_ASYNC_BEGIN("switch_mode", 0); if (device_session_ == nullptr) { - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::INTERNAL_ERROR)); } @@ -752,14 +754,14 @@ ScopedAStatus AidlCameraDeviceSession::flush() { if (res != OK) { ALOGE("%s: Flushing device failed: %s(%d).", __FUNCTION__, strerror(-res), res); - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::INTERNAL_ERROR)); } - return ScopedAStatus::ok(); + return ndk::ScopedAStatus::ok(); } -ScopedAStatus AidlCameraDeviceSession::close() { +ndk::ScopedAStatus AidlCameraDeviceSession::close() { ATRACE_NAME("AidlCameraDeviceSession::close"); if (device_session_ != nullptr) { auto profiler = aidl_profiler_->MakeScopedProfiler( @@ -770,25 +772,25 @@ ScopedAStatus AidlCameraDeviceSession::close() { aidl_profiler_->GetFpsFlag())); device_session_ = nullptr; } - return ScopedAStatus::ok(); + return ndk::ScopedAStatus::ok(); } -ScopedAStatus AidlCameraDeviceSession::switchToOffline( +ndk::ScopedAStatus AidlCameraDeviceSession::switchToOffline( const std::vector&, CameraOfflineSessionInfo* out_offlineSessionInfo, std::shared_ptr* aidl_return) { *out_offlineSessionInfo = CameraOfflineSessionInfo(); *aidl_return = nullptr; - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::INTERNAL_ERROR)); } -ScopedAStatus AidlCameraDeviceSession::isReconfigurationRequired( +ndk::ScopedAStatus AidlCameraDeviceSession::isReconfigurationRequired( const CameraMetadata& oldSessionParams, const CameraMetadata& newSessionParams, bool* reconfiguration_required) { ATRACE_NAME("AidlCameraDeviceSession::isReconfigurationRequired"); if (reconfiguration_required == nullptr) { - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::ILLEGAL_ARGUMENT)); } *reconfiguration_required = true; @@ -798,7 +800,7 @@ ScopedAStatus AidlCameraDeviceSession::isReconfigurationRequired( if (res != OK) { ALOGE("%s: Converting to old session metadata failed: %s(%d)", __FUNCTION__, strerror(-res), res); - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::INTERNAL_ERROR)); } @@ -808,7 +810,7 @@ ScopedAStatus AidlCameraDeviceSession::isReconfigurationRequired( if (res != OK) { ALOGE("%s: Converting to new session metadata failed: %s(%d)", __FUNCTION__, strerror(-res), res); - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::INTERNAL_ERROR)); } @@ -819,11 +821,11 @@ ScopedAStatus AidlCameraDeviceSession::isReconfigurationRequired( if (res != OK) { ALOGE("%s: IsReconfigurationRequired failed: %s(%d)", __FUNCTION__, strerror(-res), res); - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Status::INTERNAL_ERROR)); } - return ScopedAStatus::ok(); + return ndk::ScopedAStatus::ok(); } ::ndk::SpAIBinder AidlCameraDeviceSession::createBinder() { diff --git a/common/hal/aidl_service/aidl_camera_device_session.h b/common/hal/aidl_service/aidl_camera_device_session.h index 3423d8f..6480b05 100644 --- a/common/hal/aidl_service/aidl_camera_device_session.h +++ b/common/hal/aidl_service/aidl_camera_device_session.h @@ -20,14 +20,16 @@ #include #include #include -#include +#include +#include #include +#include #include #include "aidl_profiler.h" +#include "aidl_thermal_utils.h" #include "camera_device_session.h" -#include "hidl_thermal_utils.h" namespace android { namespace hardware { @@ -35,26 +37,11 @@ namespace camera { namespace device { namespace implementation { -using ::aidl::android::hardware::camera::device::BnCameraDeviceSession; -using ::aidl::android::hardware::camera::device::BufferCache; -using ::aidl::android::hardware::camera::device::CameraMetadata; -using ::aidl::android::hardware::camera::device::CameraOfflineSessionInfo; -using ::aidl::android::hardware::camera::device::CaptureRequest; -using ::aidl::android::hardware::camera::device::HalStream; -using ::aidl::android::hardware::camera::device::ICameraDeviceCallback; -using ::aidl::android::hardware::camera::device::ICameraOfflineSession; -using ::aidl::android::hardware::camera::device::RequestTemplate; -using ::aidl::android::hardware::camera::device::StreamConfiguration; -using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite; -using ::android::hardware::camera::implementation::AidlProfiler; -using ndk::ScopedAStatus; - -using MetadataQueue = AidlMessageQueue; - // AidlCameraDeviceSession implements the AIDL camera device session interface, // ICameraDeviceSession, that contains the methods to configure and request // captures from an active camera device. -class AidlCameraDeviceSession : public BnCameraDeviceSession { +class AidlCameraDeviceSession + : public aidl::android::hardware::camera::device::BnCameraDeviceSession { public: // Create a AidlCameraDeviceSession. // device_session is a google camera device session that @@ -62,61 +49,79 @@ class AidlCameraDeviceSession : public BnCameraDeviceSession { // AidlCameraDeviceSession will fail if device_session is // nullptr. static std::shared_ptr Create( - const std::shared_ptr& callback, + const std::shared_ptr< + aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback, std::unique_ptr device_session, - std::shared_ptr aidl_profiler); + std::shared_ptr + aidl_profiler); virtual ~AidlCameraDeviceSession(); // functions in ICameraDeviceSession - ScopedAStatus close() override; + ndk::ScopedAStatus close() override; - ScopedAStatus configureStreams(const StreamConfiguration&, - std::vector*) override; + ndk::ScopedAStatus configureStreams( + const aidl::android::hardware::camera::device::StreamConfiguration&, + std::vector*) override; - ScopedAStatus constructDefaultRequestSettings( - RequestTemplate in_type, CameraMetadata* _aidl_return) override; + ndk::ScopedAStatus constructDefaultRequestSettings( + aidl::android::hardware::camera::device::RequestTemplate in_type, + aidl::android::hardware::camera::device::CameraMetadata* aidl_return) + override; - ScopedAStatus flush() override; + ndk::ScopedAStatus flush() override; - ScopedAStatus getCaptureRequestMetadataQueue( - ::aidl::android::hardware::common::fmq::MQDescriptor< - int8_t, SynchronizedReadWrite>* _aidl_return) override; + ndk::ScopedAStatus getCaptureRequestMetadataQueue( + aidl::android::hardware::common::fmq::MQDescriptor< + int8_t, aidl::android::hardware::common::fmq::SynchronizedReadWrite>* + aidl_return) override; - ScopedAStatus getCaptureResultMetadataQueue( - ::aidl::android::hardware::common::fmq::MQDescriptor< - int8_t, SynchronizedReadWrite>* _aidl_return) override; + ndk::ScopedAStatus getCaptureResultMetadataQueue( + aidl::android::hardware::common::fmq::MQDescriptor< + int8_t, aidl::android::hardware::common::fmq::SynchronizedReadWrite>* + aidl_return) override; - ScopedAStatus isReconfigurationRequired( - const CameraMetadata& in_oldSessionParams, - const CameraMetadata& in_newSessionParams, bool* _aidl_return) override; + ndk::ScopedAStatus isReconfigurationRequired( + const aidl::android::hardware::camera::device::CameraMetadata& + in_oldSessionParams, + const aidl::android::hardware::camera::device::CameraMetadata& + in_newSessionParams, + bool* aidl_return) override; - ScopedAStatus processCaptureRequest( - const std::vector& in_requests, - const std::vector& in_cachesToRemove, - int32_t* _aidl_return) override; + ndk::ScopedAStatus processCaptureRequest( + const std::vector& + in_requests, + const std::vector& + in_cachesToRemove, + int32_t* aidl_return) override; - ScopedAStatus signalStreamFlush(const std::vector& in_streamIds, - int32_t in_streamConfigCounter) override; + ndk::ScopedAStatus signalStreamFlush(const std::vector& in_streamIds, + int32_t in_streamConfigCounter) override; - ScopedAStatus switchToOffline( + ndk::ScopedAStatus switchToOffline( const std::vector& in_streamsToKeep, - CameraOfflineSessionInfo* out_offlineSessionInfo, - std::shared_ptr* _aidl_return) override; + aidl::android::hardware::camera::device::CameraOfflineSessionInfo* + out_offlineSessionInfo, + std::shared_ptr< + aidl::android::hardware::camera::device::ICameraOfflineSession>* + aidl_return) override; - ScopedAStatus repeatingRequestEnd( + ndk::ScopedAStatus repeatingRequestEnd( int32_t /*in_frameNumber*/, const std::vector& /*in_streamIds*/) override { - return ScopedAStatus::ok(); + return ndk::ScopedAStatus::ok(); }; AidlCameraDeviceSession() = default; protected: - ::ndk::SpAIBinder createBinder() override; + ndk::SpAIBinder createBinder() override; private: + using MetadataQueue = AidlMessageQueue< + int8_t, aidl::android::hardware::common::fmq::SynchronizedReadWrite>; + static constexpr uint32_t kRequestMetadataQueueSizeBytes = 1 << 20; // 1MB static constexpr uint32_t kResultMetadataQueueSizeBytes = 1 << 20; // 1MB @@ -125,9 +130,11 @@ class AidlCameraDeviceSession : public BnCameraDeviceSession { // Initialize AidlCameraDeviceSession with a CameraDeviceSession. status_t Initialize( - const std::shared_ptr& callback, + const std::shared_ptr< + aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback, std::unique_ptr device_session, - std::shared_ptr aidl_profiler); + std::shared_ptr + aidl_profiler); // Create a metadata queue. // If override_size_property contains a valid size, it will create a metadata @@ -188,18 +195,19 @@ class AidlCameraDeviceSession : public BnCameraDeviceSession { // used to protect member variable writing and reading. std::shared_mutex aidl_device_callback_lock_; // Protected by aidl_device_callback_lock_ - std::shared_ptr aidl_device_callback_; + std::shared_ptr + aidl_device_callback_; - sp buffer_mapper_v2_; - sp buffer_mapper_v3_; - sp buffer_mapper_v4_; + android::sp buffer_mapper_v2_; + android::sp buffer_mapper_v3_; + android::sp buffer_mapper_v4_; - std::mutex hidl_thermal_mutex_; - sp thermal_; + std::mutex aidl_thermal_mutex_; + std::shared_ptr thermal_; // Must be protected by hidl_thermal_mutex_. - sp - thermal_changed_callback_; + std::shared_ptr + thermal_changed_callback_ GUARDED_BY(aidl_thermal_mutex_); // Flag for profiling first frame processing time. bool first_frame_requested_ = false; @@ -212,7 +220,8 @@ class AidlCameraDeviceSession : public BnCameraDeviceSession { // Must be protected by pending_first_frame_buffers_mutex_ size_t num_pending_first_frame_buffers_ = 0; - std::shared_ptr aidl_profiler_; + std::shared_ptr + aidl_profiler_; }; } // namespace implementation diff --git a/common/hal/aidl_service/aidl_thermal_utils.cc b/common/hal/aidl_service/aidl_thermal_utils.cc new file mode 100644 index 0000000..3104d23 --- /dev/null +++ b/common/hal/aidl_service/aidl_thermal_utils.cc @@ -0,0 +1,230 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "GCH_AidlThermalUtils" +// #define LOG_NDEBUG 0 +#include "aidl_thermal_utils.h" + +#include + +namespace android { +namespace hardware { +namespace aidl_thermal_utils { +namespace { + +using ::aidl::android::hardware::thermal::Temperature; +using ::aidl::android::hardware::thermal::TemperatureType; +using ::aidl::android::hardware::thermal::ThrottlingSeverity; + +} // namespace + +ThermalChangedCallback::ThermalChangedCallback( + google_camera_hal::NotifyThrottlingFunc notify_throttling) + : notify_throttling_(std::move(notify_throttling)) { +} + +status_t ConvertToAidlTemperatureType( + const google_camera_hal::TemperatureType& hal_temperature_type, + TemperatureType* aidl_temperature_type) { + if (aidl_temperature_type == nullptr) { + ALOGE("%s: aidl_temperature_type is nullptr", __FUNCTION__); + return BAD_VALUE; + } + + switch (hal_temperature_type) { + case google_camera_hal::TemperatureType::kUnknown: + *aidl_temperature_type = TemperatureType::UNKNOWN; + break; + case google_camera_hal::TemperatureType::kCpu: + *aidl_temperature_type = TemperatureType::CPU; + break; + case google_camera_hal::TemperatureType::kGpu: + *aidl_temperature_type = TemperatureType::GPU; + break; + case google_camera_hal::TemperatureType::kBattery: + *aidl_temperature_type = TemperatureType::BATTERY; + break; + case google_camera_hal::TemperatureType::kSkin: + *aidl_temperature_type = TemperatureType::SKIN; + break; + case google_camera_hal::TemperatureType::kUsbPort: + *aidl_temperature_type = TemperatureType::USB_PORT; + break; + case google_camera_hal::TemperatureType::kPowerAmplifier: + *aidl_temperature_type = TemperatureType::POWER_AMPLIFIER; + break; + case google_camera_hal::TemperatureType::kBclVoltage: + *aidl_temperature_type = TemperatureType::BCL_VOLTAGE; + break; + case google_camera_hal::TemperatureType::kBclCurrent: + *aidl_temperature_type = TemperatureType::BCL_CURRENT; + break; + case google_camera_hal::TemperatureType::kBclPercentage: + *aidl_temperature_type = TemperatureType::BCL_PERCENTAGE; + break; + case google_camera_hal::TemperatureType::kNpu: + *aidl_temperature_type = TemperatureType::NPU; + break; + default: + ALOGE("%s: Unknown temperature type: %d", __FUNCTION__, + hal_temperature_type); + return BAD_VALUE; + } + + return OK; +} + +status_t ThermalChangedCallback::ConvertToHalTemperatureType( + const TemperatureType& aidl_temperature_type, + google_camera_hal::TemperatureType* hal_temperature_type) { + if (hal_temperature_type == nullptr) { + ALOGE("%s: hal_temperature_type is nullptr", __FUNCTION__); + return BAD_VALUE; + } + + switch (aidl_temperature_type) { + case TemperatureType::UNKNOWN: + *hal_temperature_type = google_camera_hal::TemperatureType::kUnknown; + break; + case TemperatureType::CPU: + *hal_temperature_type = google_camera_hal::TemperatureType::kCpu; + break; + case TemperatureType::GPU: + *hal_temperature_type = google_camera_hal::TemperatureType::kGpu; + break; + case TemperatureType::BATTERY: + *hal_temperature_type = google_camera_hal::TemperatureType::kBattery; + break; + case TemperatureType::SKIN: + *hal_temperature_type = google_camera_hal::TemperatureType::kSkin; + break; + case TemperatureType::USB_PORT: + *hal_temperature_type = google_camera_hal::TemperatureType::kUsbPort; + break; + case TemperatureType::POWER_AMPLIFIER: + *hal_temperature_type = + google_camera_hal::TemperatureType::kPowerAmplifier; + break; + case TemperatureType::BCL_VOLTAGE: + *hal_temperature_type = google_camera_hal::TemperatureType::kBclVoltage; + break; + case TemperatureType::BCL_CURRENT: + *hal_temperature_type = google_camera_hal::TemperatureType::kBclCurrent; + break; + case TemperatureType::BCL_PERCENTAGE: + *hal_temperature_type = google_camera_hal::TemperatureType::kBclPercentage; + break; + case TemperatureType::NPU: + *hal_temperature_type = google_camera_hal::TemperatureType::kNpu; + break; + default: + ALOGE("%s: Unknown temperature type: %d", __FUNCTION__, + aidl_temperature_type); + return BAD_VALUE; + } + + return OK; +} + +status_t ThermalChangedCallback::ConvertToHalThrottlingSeverity( + const ThrottlingSeverity& aidl_throttling_severity, + google_camera_hal::ThrottlingSeverity* hal_throttling_severity) { + if (hal_throttling_severity == nullptr) { + ALOGE("%s: hal_throttling_severity is nullptr", __FUNCTION__); + return BAD_VALUE; + } + + switch (aidl_throttling_severity) { + case ThrottlingSeverity::NONE: + *hal_throttling_severity = google_camera_hal::ThrottlingSeverity::kNone; + break; + case ThrottlingSeverity::LIGHT: + *hal_throttling_severity = google_camera_hal::ThrottlingSeverity::kLight; + break; + case ThrottlingSeverity::MODERATE: + *hal_throttling_severity = + google_camera_hal::ThrottlingSeverity::kModerate; + break; + case ThrottlingSeverity::SEVERE: + *hal_throttling_severity = google_camera_hal::ThrottlingSeverity::kSevere; + break; + case ThrottlingSeverity::CRITICAL: + *hal_throttling_severity = + google_camera_hal::ThrottlingSeverity::kCritical; + break; + case ThrottlingSeverity::EMERGENCY: + *hal_throttling_severity = + google_camera_hal::ThrottlingSeverity::kEmergency; + break; + case ThrottlingSeverity::SHUTDOWN: + *hal_throttling_severity = + google_camera_hal::ThrottlingSeverity::kShutdown; + break; + default: + ALOGE("%s: Unknown temperature severity: %d", __FUNCTION__, + aidl_throttling_severity); + return BAD_VALUE; + } + + return OK; +} + +status_t ThermalChangedCallback::ConvertToHalTemperature( + const Temperature& aidl_temperature, + google_camera_hal::Temperature* hal_temperature) { + if (hal_temperature == nullptr) { + ALOGE("%s: hal_temperature is nullptr", __FUNCTION__); + return BAD_VALUE; + } + + status_t res = ConvertToHalTemperatureType(aidl_temperature.type, + &hal_temperature->type); + if (res != OK) { + ALOGE("%s: Converting to hal temperature type failed: %s(%d)", __FUNCTION__, + strerror(-res), res); + return res; + } + + hal_temperature->name = aidl_temperature.name; + hal_temperature->value = aidl_temperature.value; + + res = ConvertToHalThrottlingSeverity(aidl_temperature.throttlingStatus, + &hal_temperature->throttling_status); + if (res != OK) { + ALOGE("%s: Converting to hal throttling severity type failed: %s(%d)", + __FUNCTION__, strerror(-res), res); + return res; + } + + return OK; +} + +ndk::ScopedAStatus ThermalChangedCallback::notifyThrottling( + const Temperature& temperature) { + google_camera_hal::Temperature hal_temperature; + status_t res = ConvertToHalTemperature(temperature, &hal_temperature); + if (res == OK) { + notify_throttling_(hal_temperature); + } else { + ALOGE("%s: Converting to hal temperature failed: %s(%d)", __FUNCTION__, + strerror(-res), res); + } + return ndk::ScopedAStatus(AStatus_newOk()); +} + +} // namespace aidl_thermal_utils +} // namespace hardware +} // namespace android diff --git a/common/hal/aidl_service/aidl_thermal_utils.h b/common/hal/aidl_service/aidl_thermal_utils.h new file mode 100644 index 0000000..98a06e5 --- /dev/null +++ b/common/hal/aidl_service/aidl_thermal_utils.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_THERMAL_UTILS_H_ +#define HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_THERMAL_UTILS_H_ + +#include +#include + +#include "thermal_types.h" + +namespace android { +namespace hardware { +namespace aidl_thermal_utils { + +// ThermalChangedCallback implements the AIDL thermal changed callback +// interface, IThermalChangedCallback, to be registered for thermal status +// change. +class ThermalChangedCallback + : public aidl::android::hardware::thermal::BnThermalChangedCallback { + public: + explicit ThermalChangedCallback( + google_camera_hal::NotifyThrottlingFunc notify_throttling); + virtual ~ThermalChangedCallback() = default; + + // Override functions in HidlThermalChangedCallback. + ndk::ScopedAStatus notifyThrottling( + const aidl::android::hardware::thermal::Temperature& temperature) override; + // End of override functions in HidlThermalChangedCallback. + + private: + const google_camera_hal::NotifyThrottlingFunc notify_throttling_; + + status_t ConvertToHalTemperatureType( + const aidl::android::hardware::thermal::TemperatureType& + aidl_temperature_type, + google_camera_hal::TemperatureType* hal_temperature_type); + + status_t ConvertToHalThrottlingSeverity( + const aidl::android::hardware::thermal::ThrottlingSeverity& + aidl_throttling_severity, + google_camera_hal::ThrottlingSeverity* hal_throttling_severity); + + status_t ConvertToHalTemperature( + const aidl::android::hardware::thermal::Temperature& aidl_temperature, + google_camera_hal::Temperature* hal_temperature); +}; + +status_t ConvertToAidlTemperatureType( + const google_camera_hal::TemperatureType& hal_temperature_type, + aidl::android::hardware::thermal::TemperatureType* aidl_temperature_type); + +} // namespace aidl_thermal_utils +} // namespace hardware +} // namespace android + +#endif // HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_THERMAL_UTILS_H_ \ No newline at end of file diff --git a/common/hal/aidl_service/hidl_thermal_utils.cc b/common/hal/aidl_service/hidl_thermal_utils.cc deleted file mode 100644 index cb2c915..0000000 --- a/common/hal/aidl_service/hidl_thermal_utils.cc +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "GCH_HidlThermalUtils" -//#define LOG_NDEBUG 0 -#include "hidl_thermal_utils.h" - -#include - -namespace android { -namespace hardware { -namespace hidl_thermal_utils { - -std::unique_ptr HidlThermalChangedCallback::Create( - google_camera_hal::NotifyThrottlingFunc notify_throttling) { - auto thermal_changed_callback = std::unique_ptr( - new HidlThermalChangedCallback(notify_throttling)); - if (thermal_changed_callback == nullptr) { - ALOGE("%s: Failed to create a thermal changed callback", __FUNCTION__); - return nullptr; - } - - return thermal_changed_callback; -} - -HidlThermalChangedCallback::HidlThermalChangedCallback( - google_camera_hal::NotifyThrottlingFunc notify_throttling) - : kNotifyThrottling(notify_throttling) { -} - -status_t ConvertToHidlTemperatureType( - const google_camera_hal::TemperatureType& hal_temperature_type, - TemperatureType* hidl_temperature_type) { - if (hidl_temperature_type == nullptr) { - ALOGE("%s: hidl_temperature_type is nullptr", __FUNCTION__); - return BAD_VALUE; - } - - switch (hal_temperature_type) { - case google_camera_hal::TemperatureType::kUnknown: - *hidl_temperature_type = TemperatureType::UNKNOWN; - break; - case google_camera_hal::TemperatureType::kCpu: - *hidl_temperature_type = TemperatureType::CPU; - break; - case google_camera_hal::TemperatureType::kGpu: - *hidl_temperature_type = TemperatureType::GPU; - break; - case google_camera_hal::TemperatureType::kBattery: - *hidl_temperature_type = TemperatureType::BATTERY; - break; - case google_camera_hal::TemperatureType::kSkin: - *hidl_temperature_type = TemperatureType::SKIN; - break; - case google_camera_hal::TemperatureType::kUsbPort: - *hidl_temperature_type = TemperatureType::USB_PORT; - break; - case google_camera_hal::TemperatureType::kPowerAmplifier: - *hidl_temperature_type = TemperatureType::POWER_AMPLIFIER; - break; - case google_camera_hal::TemperatureType::kBclVoltage: - *hidl_temperature_type = TemperatureType::BCL_VOLTAGE; - break; - case google_camera_hal::TemperatureType::kBclCurrent: - *hidl_temperature_type = TemperatureType::BCL_CURRENT; - break; - case google_camera_hal::TemperatureType::kBclPercentage: - *hidl_temperature_type = TemperatureType::BCL_PERCENTAGE; - break; - case google_camera_hal::TemperatureType::kNpu: - *hidl_temperature_type = TemperatureType::NPU; - break; - default: - ALOGE("%s: Unknown temperature type: %d", __FUNCTION__, - hal_temperature_type); - return BAD_VALUE; - } - - return OK; -} - -status_t HidlThermalChangedCallback::ConvertToHalTemperatureType( - const TemperatureType& hidl_temperature_type, - google_camera_hal::TemperatureType* hal_temperature_type) { - if (hal_temperature_type == nullptr) { - ALOGE("%s: hal_temperature_type is nullptr", __FUNCTION__); - return BAD_VALUE; - } - - switch (hidl_temperature_type) { - case TemperatureType::UNKNOWN: - *hal_temperature_type = google_camera_hal::TemperatureType::kUnknown; - break; - case TemperatureType::CPU: - *hal_temperature_type = google_camera_hal::TemperatureType::kCpu; - break; - case TemperatureType::GPU: - *hal_temperature_type = google_camera_hal::TemperatureType::kGpu; - break; - case TemperatureType::BATTERY: - *hal_temperature_type = google_camera_hal::TemperatureType::kBattery; - break; - case TemperatureType::SKIN: - *hal_temperature_type = google_camera_hal::TemperatureType::kSkin; - break; - case TemperatureType::USB_PORT: - *hal_temperature_type = google_camera_hal::TemperatureType::kUsbPort; - break; - case TemperatureType::POWER_AMPLIFIER: - *hal_temperature_type = - google_camera_hal::TemperatureType::kPowerAmplifier; - break; - case TemperatureType::BCL_VOLTAGE: - *hal_temperature_type = google_camera_hal::TemperatureType::kBclVoltage; - break; - case TemperatureType::BCL_CURRENT: - *hal_temperature_type = google_camera_hal::TemperatureType::kBclCurrent; - break; - case TemperatureType::BCL_PERCENTAGE: - *hal_temperature_type = google_camera_hal::TemperatureType::kBclPercentage; - break; - case TemperatureType::NPU: - *hal_temperature_type = google_camera_hal::TemperatureType::kNpu; - break; - default: - ALOGE("%s: Unknown temperature type: %d", __FUNCTION__, - hidl_temperature_type); - return BAD_VALUE; - } - - return OK; -} - -status_t HidlThermalChangedCallback::ConvertToHalThrottlingSeverity( - const ThrottlingSeverity& hidl_throttling_severity, - google_camera_hal::ThrottlingSeverity* hal_throttling_severity) { - if (hal_throttling_severity == nullptr) { - ALOGE("%s: hal_throttling_severity is nullptr", __FUNCTION__); - return BAD_VALUE; - } - - switch (hidl_throttling_severity) { - case ThrottlingSeverity::NONE: - *hal_throttling_severity = google_camera_hal::ThrottlingSeverity::kNone; - break; - case ThrottlingSeverity::LIGHT: - *hal_throttling_severity = google_camera_hal::ThrottlingSeverity::kLight; - break; - case ThrottlingSeverity::MODERATE: - *hal_throttling_severity = - google_camera_hal::ThrottlingSeverity::kModerate; - break; - case ThrottlingSeverity::SEVERE: - *hal_throttling_severity = google_camera_hal::ThrottlingSeverity::kSevere; - break; - case ThrottlingSeverity::CRITICAL: - *hal_throttling_severity = - google_camera_hal::ThrottlingSeverity::kCritical; - break; - case ThrottlingSeverity::EMERGENCY: - *hal_throttling_severity = - google_camera_hal::ThrottlingSeverity::kEmergency; - break; - case ThrottlingSeverity::SHUTDOWN: - *hal_throttling_severity = - google_camera_hal::ThrottlingSeverity::kShutdown; - break; - default: - ALOGE("%s: Unknown temperature severity: %d", __FUNCTION__, - hidl_throttling_severity); - return BAD_VALUE; - } - - return OK; -} - -status_t HidlThermalChangedCallback::ConvertToHalTemperature( - const Temperature& hidl_temperature, - google_camera_hal::Temperature* hal_temperature) { - if (hal_temperature == nullptr) { - ALOGE("%s: hal_temperature is nullptr", __FUNCTION__); - return BAD_VALUE; - } - - status_t res = ConvertToHalTemperatureType(hidl_temperature.type, - &hal_temperature->type); - if (res != OK) { - ALOGE("%s: Converting to hal temperature type failed: %s(%d)", __FUNCTION__, - strerror(-res), res); - return res; - } - - hal_temperature->name = hidl_temperature.name; - hal_temperature->value = hidl_temperature.value; - - res = ConvertToHalThrottlingSeverity(hidl_temperature.throttlingStatus, - &hal_temperature->throttling_status); - if (res != OK) { - ALOGE("%s: Converting to hal throttling severity type failed: %s(%d)", - __FUNCTION__, strerror(-res), res); - return res; - } - - return OK; -} - -Return HidlThermalChangedCallback::notifyThrottling( - const Temperature& temperature) { - google_camera_hal::Temperature hal_temperature; - status_t res = ConvertToHalTemperature(temperature, &hal_temperature); - if (res != OK) { - ALOGE("%s: Converting to hal temperature failed: %s(%d)", __FUNCTION__, - strerror(-res), res); - return Void(); - } - - kNotifyThrottling(hal_temperature); - return Void(); -} - -} // namespace hidl_thermal_utils -} // namespace hardware -} // namespace android diff --git a/common/hal/aidl_service/hidl_thermal_utils.h b/common/hal/aidl_service/hidl_thermal_utils.h deleted file mode 100644 index d815ab2..0000000 --- a/common/hal/aidl_service/hidl_thermal_utils.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_THERMAL_UTILS_H_ -#define HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_THERMAL_UTILS_H_ - -#include - -#include "thermal_types.h" - -namespace android { -namespace hardware { -namespace hidl_thermal_utils { - -using ::android::sp; -using ::android::hardware::hidl_string; -using ::android::hardware::hidl_vec; -using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::hardware::thermal::V2_0::IThermalChangedCallback; -using ::android::hardware::thermal::V2_0::Temperature; -using ::android::hardware::thermal::V2_0::TemperatureType; -using ::android::hardware::thermal::V2_0::ThrottlingSeverity; - -// HidlThermalChangedCallback implements the HIDL thermal changed callback -// interface, IThermalChangedCallback, to be registered for thermal status -// change. -class HidlThermalChangedCallback : public IThermalChangedCallback { - public: - static std::unique_ptr Create( - google_camera_hal::NotifyThrottlingFunc notify_throttling); - virtual ~HidlThermalChangedCallback() = default; - - // Override functions in HidlThermalChangedCallback. - Return notifyThrottling(const Temperature& temperature) override; - // End of override functions in HidlThermalChangedCallback. - - protected: - HidlThermalChangedCallback( - google_camera_hal::NotifyThrottlingFunc notify_throttling); - - private: - const google_camera_hal::NotifyThrottlingFunc kNotifyThrottling; - - status_t ConvertToHalTemperatureType( - const TemperatureType& hidl_temperature_type, - google_camera_hal::TemperatureType* hal_temperature_type); - - status_t ConvertToHalThrottlingSeverity( - const ThrottlingSeverity& hidl_throttling_severity, - google_camera_hal::ThrottlingSeverity* hal_throttling_severity); - - status_t ConvertToHalTemperature( - const Temperature& hidl_temperature, - google_camera_hal::Temperature* hal_temperature); -}; - -status_t ConvertToHidlTemperatureType( - const google_camera_hal::TemperatureType& hal_temperature_type, - TemperatureType* hidl_temperature_type); - -} // namespace hidl_thermal_utils -} // namespace hardware -} // namespace android - -#endif // HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_THERMAL_UTILS_H_ \ No newline at end of file -- cgit v1.2.3 From 3d8c1eb88df8f554020daf02a241bde3951b8f5b Mon Sep 17 00:00:00 2001 From: Tianyu Jiang Date: Wed, 26 Jul 2023 09:38:54 -0700 Subject: Remove log spew Fix: 293299661 Test: log Change-Id: I30fecb33f20b77b2d07379fe9df59c39193ab7b2 --- common/hal/utils/utils.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/common/hal/utils/utils.cc b/common/hal/utils/utils.cc index 6bc5867..f8023a3 100644 --- a/common/hal/utils/utils.cc +++ b/common/hal/utils/utils.cc @@ -185,11 +185,6 @@ status_t GetSensorActiveArraySize(const HalCameraMetadata* characteristics, camera_metadata_ro_entry entry; status_t res = characteristics->Get(active_array_tag, &entry); if (res != OK || entry.count != 4) { - ALOGE( - "%s: Getting ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE failed: %s(%d) " - "count: %zu max resolution ? %s", - __FUNCTION__, strerror(-res), res, entry.count, - maximum_resolution ? "true" : "false"); return res; } -- cgit v1.2.3 From fac8478b0e69e5154cce9377a9f6b7a1732f68db Mon Sep 17 00:00:00 2001 From: Mia Manalastas Date: Wed, 9 Aug 2023 18:57:15 +0000 Subject: Bump up udc-qpr-dev major version to N+2 Bug: 295109284 Change-Id: I764e9f4e665bede7e2b1eaa5a957d4aaabdb6e52 --- common/hal/aidl_service/version_script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/hal/aidl_service/version_script.py b/common/hal/aidl_service/version_script.py index bdfe922..02bf97a 100644 --- a/common/hal/aidl_service/version_script.py +++ b/common/hal/aidl_service/version_script.py @@ -20,7 +20,7 @@ import os import re import sys -BRANCH_SPECIFIC_VERSION_IDENTIFIER = 10 # main +BRANCH_SPECIFIC_VERSION_IDENTIFIER = 12 # main DEFAULT_ENG_BUILD_NUMBER = 2147480000 DEFAULT_BAD_BUILD_NUMBER = DEFAULT_ENG_BUILD_NUMBER - 1 -- cgit v1.2.3 From 40f15e09bb2a2d94504b3b3dc68cf9274b896491 Mon Sep 17 00:00:00 2001 From: Kiyoung Kim Date: Tue, 25 Jul 2023 17:11:54 +0900 Subject: Remove dependency with libbinder As part of VNDK deprecation, vendor APEXes will no longer be able to link with VNDK namespace over 'use_vndk_as_stable' flag. To achieve this, vendor APEXes should only use stable interface or include all libraries within the APEX. Since libbinder is not available to locate within the APEX, it should be removed from the dependency. This change removes dependency with libbinder from camera provider service. Bug: 290318998 Test: aosp_cf_x86_64_phone boot succeeded Change-Id: Ia5e1b976cf4504a81376a1587d0689b806c0551c Merged-In: Ia5e1b976cf4504a81376a1587d0689b806c0551c (cherry picked from commit 0c93a1906395b45cd0eb3a7b202bca3e89906221) --- common/hal/aidl_service/Android.bp | 1 - common/hal/aidl_service/aidl_service.cc | 4 ---- 2 files changed, 5 deletions(-) diff --git a/common/hal/aidl_service/Android.bp b/common/hal/aidl_service/Android.bp index 179a826..3493961 100644 --- a/common/hal/aidl_service/Android.bp +++ b/common/hal/aidl_service/Android.bp @@ -99,7 +99,6 @@ cc_defaults { "android.hardware.thermal@1.0", "android.hardware.thermal@2.0", "android.hardware.thermal-V1-ndk", - "libbinder", "libbinder_ndk", "libbase", "libcamera_metadata", diff --git a/common/hal/aidl_service/aidl_service.cc b/common/hal/aidl_service/aidl_service.cc index a98753a..2739f46 100644 --- a/common/hal/aidl_service/aidl_service.cc +++ b/common/hal/aidl_service/aidl_service.cc @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -49,10 +48,7 @@ const std::string kProviderInstance = "/internal/0"; int main() { ALOGI("Google camera provider service is starting."); - // The camera HAL may communicate to other vendor components via - // /dev/vndbinder mallopt(M_DECAY_TIME, 1); - android::ProcessState::initWithDriver("/dev/vndbinder"); android::hardware::configureRpcThreadpool(/*maxThreads=*/6, /*callerWillJoin=*/true); -- cgit v1.2.3 From 7fc592f1c05364882ae6b1356a148f54173eaf61 Mon Sep 17 00:00:00 2001 From: Speth Chang Date: Fri, 25 Aug 2023 07:33:38 +0000 Subject: Fix thermal service and callback race 1. Fix lost thermal service in camera AIDL. 2. Add lock to prevent race between callback and destructor. Bug: 291986991 Test: thermal notification Test: CTS, GCA Change-Id: I5431b2313993942542fefea9f522e04bd7f3457b --- common/hal/aidl_service/aidl_camera_device_session.cc | 2 +- common/hal/google_camera_hal/camera_device_session.cc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/common/hal/aidl_service/aidl_camera_device_session.cc b/common/hal/aidl_service/aidl_camera_device_session.cc index 64acd2f..ed4978e 100644 --- a/common/hal/aidl_service/aidl_camera_device_session.cc +++ b/common/hal/aidl_service/aidl_camera_device_session.cc @@ -399,7 +399,7 @@ status_t AidlCameraDeviceSession::Initialize( std::string(aidl::android::hardware::thermal::IThermal::descriptor) + "/default"; if (AServiceManager_isDeclared(thermal_instance_name.c_str())) { - auto thermal_ = + thermal_ = aidl::android::hardware::thermal::IThermal::fromBinder(ndk::SpAIBinder( AServiceManager_waitForService(thermal_instance_name.c_str()))); if (!thermal_) { diff --git a/common/hal/google_camera_hal/camera_device_session.cc b/common/hal/google_camera_hal/camera_device_session.cc index 621fd6f..31b2721 100644 --- a/common/hal/google_camera_hal/camera_device_session.cc +++ b/common/hal/google_camera_hal/camera_device_session.cc @@ -640,6 +640,7 @@ void CameraDeviceSession::SetSessionCallback( } void CameraDeviceSession::NotifyThrottling(const Temperature& temperature) { + std::lock_guard lock(session_callback_lock_); switch (temperature.throttling_status) { case ThrottlingSeverity::kNone: case ThrottlingSeverity::kLight: -- cgit v1.2.3 From 4337e908c95aab939cd479736544aa7410483135 Mon Sep 17 00:00:00 2001 From: timmyli Date: Sun, 6 Aug 2023 07:12:23 +0000 Subject: Add new vendor tag for [24,24] and [24,30] transition. Added new vendor tag to signal hal to not reconfigure graph when switch between [24,24] and [24,30]. This tag is more generic and allows for more fps configurations in the future. Bug: 290796203 Test: mm, manual test for smooth transition Change-Id: I5a877bebc4d3ab7fc48ef75c486efde18ac7139b --- common/hal/common/vendor_tag_defs.h | 12 ++++++++ common/hal/google_camera_hal/vendor_tags.cc | 3 ++ common/hal/utils/utils.cc | 48 ++++++++++++++++++++++++----- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/common/hal/common/vendor_tag_defs.h b/common/hal/common/vendor_tag_defs.h index bce1b13..e9b8cd0 100644 --- a/common/hal/common/vendor_tag_defs.h +++ b/common/hal/common/vendor_tag_defs.h @@ -49,6 +49,7 @@ enum VendorTagIds : uint32_t { kSwDenoiseEnabled, kVideoSwDenoiseEnabled, kVideo60to30FPSThermalThrottle, + kVideoFpsThrottle, // This should not be used as a vendor tag ID on its own, but as a placeholder // to indicate the end of currently defined vendor tag IDs kEndMarker @@ -242,6 +243,17 @@ static const std::vector kInternalVendorTags = { {.tag_id = VendorTagIds::kVideo60to30FPSThermalThrottle, .tag_name = "Video60to30FPSThermalThrottle", .tag_type = CameraMetadataType::kByte}, + // Video Fps Throttle Enabled + // + // Indicates whether hal should accept changes in + // fps range without reconfiguring graph. This allows for + // smooth transitions. + // + // Present in: request and session keys + // Payload: VideoFpsThrottle + {.tag_id = VendorTagIds::kVideoFpsThrottle, + .tag_name = "VideoFpsThrottle", + .tag_type = CameraMetadataType::kByte}, }; // Google Camera HAL vendor tag sections diff --git a/common/hal/google_camera_hal/vendor_tags.cc b/common/hal/google_camera_hal/vendor_tags.cc index f1f0641..7d84c28 100644 --- a/common/hal/google_camera_hal/vendor_tags.cc +++ b/common/hal/google_camera_hal/vendor_tags.cc @@ -108,6 +108,9 @@ status_t ModifyCharacteristicsKeys(HalCameraMetadata* metadata) { // VendorTagIds::kVideo60to30FPSThermalThrottle session_keys.push_back(VendorTagIds::kVideo60to30FPSThermalThrottle); request_keys.push_back(VendorTagIds::kVideo60to30FPSThermalThrottle); + // VendorTagIds::kVideoFpsThrottle + session_keys.push_back(VendorTagIds::kVideoFpsThrottle); + request_keys.push_back(VendorTagIds::kVideoFpsThrottle); // Update the static metadata with the new set of keys if (metadata->Set(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS, request_keys.data(), diff --git a/common/hal/utils/utils.cc b/common/hal/utils/utils.cc index f8023a3..897e2c8 100644 --- a/common/hal/utils/utils.cc +++ b/common/hal/utils/utils.cc @@ -24,6 +24,8 @@ #include #include +#include + #include "utils.h" #include "vendor_tag_defs.h" @@ -31,6 +33,31 @@ namespace android { namespace google_camera_hal { namespace utils { +namespace { + +using FpsRange = std::pair; + +bool IsAcceptableThrottledFpsChange(const FpsRange& old_fps, + const FpsRange& new_fps) { + // We allow smooth transitions between [30,30] to [60,60] and [24,24] and [24,30]. + constexpr std::array, 3> kAcceptableTransitions = { + std::make_pair({30, 30}, {60, 60}), + std::make_pair({24, 24}, {24, 30}), + std::make_pair({24, 24}, {30, 30}), + }; + + for (const std::pair& range : kAcceptableTransitions) { + // We don't care about the direction of the transition. + if ((old_fps == range.first && new_fps == range.second) || + (new_fps == range.first && old_fps == range.second)) { + return true; + } + } + + return false; +} +} // namespace + constexpr char kRealtimeThreadSetProp[] = "persist.vendor.camera.realtimethread"; @@ -374,6 +401,10 @@ bool IsSessionParameterCompatible(const HalCameraMetadata* old_session, // the special case that AE FPS is throttling [60, 60] to [30, 30] or // restored from [30, 30] to [60, 60] from GCA side when session parameter // kVideo60to30FPSThermalThrottle is enabled. + // Added kVideoFpsThrottle more generic transitions such + // as between [24,24] and [24,30]. kVideoFpsThrottle should be used + // over kVideo60to30FPSThermalThrottle going forth. They are functionally + // the same, but kVideoFpsThrottle is more generically named. uint8_t video_60_to_30fps_thermal_throttle = 0; camera_metadata_ro_entry_t video_60_to_30fps_throttle_entry; if (new_session->Get(kVideo60to30FPSThermalThrottle, @@ -382,14 +413,17 @@ bool IsSessionParameterCompatible(const HalCameraMetadata* old_session, video_60_to_30fps_throttle_entry.data.u8[0]; } + uint8_t video_fps_throttle = 0; + camera_metadata_ro_entry_t video_fps_throttle_entry; + if (new_session->Get(kVideoFpsThrottle, &video_fps_throttle_entry) == OK) { + video_fps_throttle = video_fps_throttle_entry.data.u8[0]; + } + bool ignore_fps_range_diff = false; - if (video_60_to_30fps_thermal_throttle) { - if (((old_min_fps == 60) && (old_max_fps == 60) && - (new_min_fps == 30) && (new_max_fps == 30)) || - ((old_min_fps == 30) && (old_max_fps == 30) && - (new_min_fps == 60) && (new_max_fps == 60))) { - ignore_fps_range_diff = true; - } + if (video_60_to_30fps_thermal_throttle || video_fps_throttle) { + ignore_fps_range_diff = IsAcceptableThrottledFpsChange( + /*old_fps=*/{old_min_fps, old_max_fps}, + /*new_fps=*/{new_min_fps, new_max_fps}); } if (old_max_fps == new_max_fps || ignore_fps_range_diff) { -- cgit v1.2.3 From dfbc1208bad48287de8ab8a72eac10a9044da28b Mon Sep 17 00:00:00 2001 From: Xin Qi Date: Tue, 29 Aug 2023 12:49:05 -0700 Subject: Set result dispatcher thread to be realtime by default This will make the ResultDispatch thread to run in realtime, so that by priority inheritance CameraServer will be in realtime priority too. Bug: b/295977499 Test: manual tested with systrace, manual CTS run Change-Id: I3bf32875eaddf617837da83a918478a7cb3a2818 --- common/hal/utils/result_dispatcher.cc | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/common/hal/utils/result_dispatcher.cc b/common/hal/utils/result_dispatcher.cc index b539bc2..e7c6c17 100644 --- a/common/hal/utils/result_dispatcher.cc +++ b/common/hal/utils/result_dispatcher.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -//#define LOG_NDEBUG 0 +// #define LOG_NDEBUG 0 #define LOG_TAG "GCH_ResultDispatcher" #define ATRACE_TAG ATRACE_TAG_CAMERA #include "result_dispatcher.h" @@ -61,23 +61,16 @@ ResultDispatcher::ResultDispatcher( notify_callback_thread_ = std::thread([this] { this->NotifyCallbackThreadLoop(); }); - if (utils::SupportRealtimeThread()) { - status_t res = - utils::SetRealtimeThread(notify_callback_thread_.native_handle()); - if (res != OK) { - ALOGE("[%s] %s: SetRealtimeThread fail", name_.c_str(), __FUNCTION__); - } else { - ALOGI("[%s] %s: SetRealtimeThread OK", name_.c_str(), __FUNCTION__); - } + // Assign higher priority to reduce the preemption when CPU usage is high + // + // As from b/295977499, we need to make it realtime for priority inheritance + // to avoid CameraServer thread being the bottleneck + status_t res = + utils::SetRealtimeThread(notify_callback_thread_.native_handle()); + if (res != OK) { + ALOGE("[%s] %s: SetRealtimeThread fail", name_.c_str(), __FUNCTION__); } else { - // Assign higher priority to reduce the preemption when CPU usage is high - int32_t res = setpriority( - PRIO_PROCESS, - pthread_gettid_np(notify_callback_thread_.native_handle()), -20); - if (res != 0) { - ALOGE("[%s] %s: Set thread priority fail with error: %s", name_.c_str(), - __FUNCTION__, strerror(errno)); - } + ALOGI("[%s] %s: SetRealtimeThread OK", name_.c_str(), __FUNCTION__); } InitializeGroupStreamIdsMap(stream_config); } -- cgit v1.2.3 From 017f5677eaf5b02cee154ffe8bffd5c72371a95d Mon Sep 17 00:00:00 2001 From: Speth Chang Date: Thu, 31 Aug 2023 02:19:35 +0000 Subject: Revert "Fix thermal service and callback race" This reverts commit 7fc592f1c05364882ae6b1356a148f54173eaf61. Reason for revert: issue not fix and suspecting cause a regression Change-Id: Ib234a87ea5bebcaddcb8d062d19b408cac23e826 Bug: 298132153 --- common/hal/aidl_service/aidl_camera_device_session.cc | 2 +- common/hal/google_camera_hal/camera_device_session.cc | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/common/hal/aidl_service/aidl_camera_device_session.cc b/common/hal/aidl_service/aidl_camera_device_session.cc index ed4978e..64acd2f 100644 --- a/common/hal/aidl_service/aidl_camera_device_session.cc +++ b/common/hal/aidl_service/aidl_camera_device_session.cc @@ -399,7 +399,7 @@ status_t AidlCameraDeviceSession::Initialize( std::string(aidl::android::hardware::thermal::IThermal::descriptor) + "/default"; if (AServiceManager_isDeclared(thermal_instance_name.c_str())) { - thermal_ = + auto thermal_ = aidl::android::hardware::thermal::IThermal::fromBinder(ndk::SpAIBinder( AServiceManager_waitForService(thermal_instance_name.c_str()))); if (!thermal_) { diff --git a/common/hal/google_camera_hal/camera_device_session.cc b/common/hal/google_camera_hal/camera_device_session.cc index 31b2721..621fd6f 100644 --- a/common/hal/google_camera_hal/camera_device_session.cc +++ b/common/hal/google_camera_hal/camera_device_session.cc @@ -640,7 +640,6 @@ void CameraDeviceSession::SetSessionCallback( } void CameraDeviceSession::NotifyThrottling(const Temperature& temperature) { - std::lock_guard lock(session_callback_lock_); switch (temperature.throttling_status) { case ThrottlingSeverity::kNone: case ThrottlingSeverity::kLight: -- cgit v1.2.3 From 0ea79e00cdffbc205e5af441695c268d6083b52c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kosi=C5=84ski?= Date: Fri, 1 Sep 2023 00:15:02 +0000 Subject: Fix typo that causes thermal service to always be null. This could be detected with -Wshadow, but turning that on currently causes other breakage. Bug: 298299323 Test: presubmit, check logs Change-Id: I4515f14ec0218debdb3aba6c642885c42d8ba3ed --- common/hal/aidl_service/aidl_camera_device_session.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/hal/aidl_service/aidl_camera_device_session.cc b/common/hal/aidl_service/aidl_camera_device_session.cc index 64acd2f..ed4978e 100644 --- a/common/hal/aidl_service/aidl_camera_device_session.cc +++ b/common/hal/aidl_service/aidl_camera_device_session.cc @@ -399,7 +399,7 @@ status_t AidlCameraDeviceSession::Initialize( std::string(aidl::android::hardware::thermal::IThermal::descriptor) + "/default"; if (AServiceManager_isDeclared(thermal_instance_name.c_str())) { - auto thermal_ = + thermal_ = aidl::android::hardware::thermal::IThermal::fromBinder(ndk::SpAIBinder( AServiceManager_waitForService(thermal_instance_name.c_str()))); if (!thermal_) { -- cgit v1.2.3 From c026a1ddb69b573a5990da57db291473ef303688 Mon Sep 17 00:00:00 2001 From: Michelle Ho Date: Mon, 4 Sep 2023 10:33:43 +0000 Subject: Lower the log level to avoid log spew Currently there's a per-frame log spew, so we lower the log level as a WAR. Plan to resume the log level once the issue fixed. Bug: 298643274 Test: build pass, basic functionality tests Test: GCA Pro manual lens zoom Change-Id: I98f2028833f7cc5a099d81fc903d2e194341f9c5 --- common/hal/utils/zoom_ratio_mapper.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/hal/utils/zoom_ratio_mapper.cc b/common/hal/utils/zoom_ratio_mapper.cc index 47030d8..5f5bbd8 100644 --- a/common/hal/utils/zoom_ratio_mapper.cc +++ b/common/hal/utils/zoom_ratio_mapper.cc @@ -192,12 +192,14 @@ void ZoomRatioMapper::ApplyZoomRatio(const Dimension& active_array_dimension, } float zoom_ratio = entry.data.f[0]; + // TODO(b/298643274) Restore the log level to ERROR once the log spew + // issue is fixed. if (zoom_ratio < zoom_ratio_range_.min) { - ALOGE("%s, zoom_ratio(%f) is smaller than lower bound(%f)", __FUNCTION__, + ALOGV("%s, zoom_ratio(%f) is smaller than lower bound(%f)", __FUNCTION__, zoom_ratio, zoom_ratio_range_.min); zoom_ratio = zoom_ratio_range_.min; } else if (zoom_ratio > zoom_ratio_range_.max) { - ALOGE("%s, zoom_ratio(%f) is larger than upper bound(%f)", __FUNCTION__, + ALOGV("%s, zoom_ratio(%f) is larger than upper bound(%f)", __FUNCTION__, zoom_ratio, zoom_ratio_range_.max); zoom_ratio = zoom_ratio_range_.max; } -- cgit v1.2.3 From b680e1994d98757286c8cf150a4fd7cb20c02e61 Mon Sep 17 00:00:00 2001 From: Michelle Ho Date: Mon, 4 Sep 2023 10:38:42 +0000 Subject: Restore log levels Restore the log levels after the log spew fixed Bug: 299569176 Test: build pass, basic functionality tests Test: GCA Pro manual lens zoom Change-Id: I65b081b0c8ac4802245400877431befad6e3d0d8 --- common/hal/utils/zoom_ratio_mapper.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/common/hal/utils/zoom_ratio_mapper.cc b/common/hal/utils/zoom_ratio_mapper.cc index 5f5bbd8..47030d8 100644 --- a/common/hal/utils/zoom_ratio_mapper.cc +++ b/common/hal/utils/zoom_ratio_mapper.cc @@ -192,14 +192,12 @@ void ZoomRatioMapper::ApplyZoomRatio(const Dimension& active_array_dimension, } float zoom_ratio = entry.data.f[0]; - // TODO(b/298643274) Restore the log level to ERROR once the log spew - // issue is fixed. if (zoom_ratio < zoom_ratio_range_.min) { - ALOGV("%s, zoom_ratio(%f) is smaller than lower bound(%f)", __FUNCTION__, + ALOGE("%s, zoom_ratio(%f) is smaller than lower bound(%f)", __FUNCTION__, zoom_ratio, zoom_ratio_range_.min); zoom_ratio = zoom_ratio_range_.min; } else if (zoom_ratio > zoom_ratio_range_.max) { - ALOGV("%s, zoom_ratio(%f) is larger than upper bound(%f)", __FUNCTION__, + ALOGE("%s, zoom_ratio(%f) is larger than upper bound(%f)", __FUNCTION__, zoom_ratio, zoom_ratio_range_.max); zoom_ratio = zoom_ratio_range_.max; } -- cgit v1.2.3 From 1852410987c2210a2fcb4018193f730e22500f2e Mon Sep 17 00:00:00 2001 From: Owen Kim Date: Tue, 3 Oct 2023 16:34:18 +0000 Subject: [GCH] Fix the memory leak when writing metdata to AIDL buffer Bug: 301771574 Test: GCA Change-Id: I93fb755def32671705c0874052d917e38ac1a1a1 --- common/hal/aidl_service/aidl_utils.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/hal/aidl_service/aidl_utils.cc b/common/hal/aidl_service/aidl_utils.cc index 332d1a1..ed84c50 100644 --- a/common/hal/aidl_service/aidl_utils.cc +++ b/common/hal/aidl_service/aidl_utils.cc @@ -308,8 +308,8 @@ status_t ConvertToAidlResultMetadata( } uint32_t metadata_size = hal_metadata->GetCameraMetadataSize(); - uint8_t* metadata_p = - reinterpret_cast(hal_metadata->ReleaseCameraMetadata()); + const auto* metadata_p = + reinterpret_cast(hal_metadata->GetRawCameraMetadata()); // TODO: Do we reallly need to copy here ? aidl_metadata->assign(metadata_p, metadata_p + metadata_size); -- cgit v1.2.3