diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-02 23:58:30 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-02 23:58:30 +0000 |
commit | 458e1d164d6a276a79cae71567abbe2fc39234ad (patch) | |
tree | af7b6f643c654f5e4c83586ccd4fc9d10f00e385 | |
parent | 0b86dbcbad3bb8b38d68e6dc72229a17bc70c202 (diff) | |
parent | 9a0a4df0a78d3ffe7b6b4f08b0090b3bb35d4687 (diff) | |
download | camera-simpleperf-release.tar.gz |
Snap for 11400057 from 9a0a4df0a78d3ffe7b6b4f08b0090b3bb35d4687 to simpleperf-releasesimpleperf-release
Change-Id: I81ff08bb67d06de12c7e0a8f3a53da1ed5dc87d8
30 files changed, 552 insertions, 403 deletions
@@ -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/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 { diff --git a/common/hal/aidl_service/Android.bp b/common/hal/aidl_service/Android.bp index 3493961..722d3fd 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_ndk", "libbase", @@ -116,12 +114,11 @@ cc_defaults { ], static_libs: [ "libaidlcommonsupport", - "libthermalutils", ], } cc_defaults { - name: "camera_service_defaults", + name: "hardware_camera_service_defaults", defaults: [ "camera_service_defaults_common", ], @@ -134,7 +131,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"], @@ -143,7 +140,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"], diff --git a/common/hal/aidl_service/aidl_camera_device_session.cc b/common/hal/aidl_service/aidl_camera_device_session.cc index 9a69d74..ed4978e 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 <aidl/android/hardware/thermal/IThermal.h> @@ -26,7 +26,6 @@ #include <cutils/trace.h> #include <log/log.h> #include <malloc.h> -#include <thermalutils/ThermalHidlWrapper.h> #include <utils/Trace.h> #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> AidlCameraDeviceSession::Create( const std::shared_ptr<ICameraDeviceCallback>& 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( + 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<std::mutex> lock(hidl_thermal_mutex_); + std::lock_guard<std::mutex> 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<hidl_thermal_utils::HidlThermalChangedCallback> 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<aidl_thermal_utils::ThermalChangedCallback>( + 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<std::mutex> lock(hidl_thermal_mutex_); + std::lock_guard<std::mutex> 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<int32_t>(Status::ILLEGAL_ARGUMENT)); } aidl_return->metadata.clear(); if (device_session_ == nullptr) { - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast<int32_t>(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<int32_t>(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<HalStream>* aidl_return) { ATRACE_NAME("AidlCameraDeviceSession::configureStreams"); if (aidl_return == nullptr) { - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast<int32_t>(Status::ILLEGAL_ARGUMENT)); } aidl_return->clear(); if (device_session_ == nullptr) { - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast<int32_t>(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<int32_t>(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<CaptureRequest>& requests, const std::vector<BufferCache>& cachesToRemove, int32_t* aidl_return) { if (aidl_return == nullptr || device_session_ == nullptr) { - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast<int32_t>(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<int32_t>(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<int32_t>(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>&, 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<int32_t>(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<int32_t>(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<int32_t>&, CameraOfflineSessionInfo* out_offlineSessionInfo, std::shared_ptr<ICameraOfflineSession>* aidl_return) { *out_offlineSessionInfo = CameraOfflineSessionInfo(); *aidl_return = nullptr; - return ScopedAStatus::fromServiceSpecificError( + return ndk::ScopedAStatus::fromServiceSpecificError( static_cast<int32_t>(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<int32_t>(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<int32_t>(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<int32_t>(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<int32_t>(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 <aidl/android/hardware/camera/device/BnCameraDeviceSession.h> #include <aidl/android/hardware/camera/device/ICameraDevice.h> #include <aidl/android/hardware/camera/device/ICameraDeviceCallback.h> -#include <android/hardware/thermal/2.0/IThermal.h> +#include <aidl/android/hardware/thermal/IThermal.h> +#include <android-base/thread_annotations.h> #include <fmq/AidlMessageQueue.h> +#include <utils/StrongPointer.h> #include <shared_mutex> #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<int8_t, SynchronizedReadWrite>; - // 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<AidlCameraDeviceSession> Create( - const std::shared_ptr<ICameraDeviceCallback>& callback, + const std::shared_ptr< + aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback, std::unique_ptr<google_camera_hal::CameraDeviceSession> device_session, - std::shared_ptr<AidlProfiler> aidl_profiler); + std::shared_ptr<android::hardware::camera::implementation::AidlProfiler> + aidl_profiler); virtual ~AidlCameraDeviceSession(); // functions in ICameraDeviceSession - ScopedAStatus close() override; + ndk::ScopedAStatus close() override; - ScopedAStatus configureStreams(const StreamConfiguration&, - std::vector<HalStream>*) override; + ndk::ScopedAStatus configureStreams( + const aidl::android::hardware::camera::device::StreamConfiguration&, + std::vector<aidl::android::hardware::camera::device::HalStream>*) 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<CaptureRequest>& in_requests, - const std::vector<BufferCache>& in_cachesToRemove, - int32_t* _aidl_return) override; + ndk::ScopedAStatus processCaptureRequest( + const std::vector<aidl::android::hardware::camera::device::CaptureRequest>& + in_requests, + const std::vector<aidl::android::hardware::camera::device::BufferCache>& + in_cachesToRemove, + int32_t* aidl_return) override; - ScopedAStatus signalStreamFlush(const std::vector<int32_t>& in_streamIds, - int32_t in_streamConfigCounter) override; + ndk::ScopedAStatus signalStreamFlush(const std::vector<int32_t>& in_streamIds, + int32_t in_streamConfigCounter) override; - ScopedAStatus switchToOffline( + ndk::ScopedAStatus switchToOffline( const std::vector<int32_t>& in_streamsToKeep, - CameraOfflineSessionInfo* out_offlineSessionInfo, - std::shared_ptr<ICameraOfflineSession>* _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<int32_t>& /*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<ICameraDeviceCallback>& callback, + const std::shared_ptr< + aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback, std::unique_ptr<google_camera_hal::CameraDeviceSession> device_session, - std::shared_ptr<AidlProfiler> aidl_profiler); + std::shared_ptr<android::hardware::camera::implementation::AidlProfiler> + 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<ICameraDeviceCallback> aidl_device_callback_; + std::shared_ptr<aidl::android::hardware::camera::device::ICameraDeviceCallback> + aidl_device_callback_; - sp<android::hardware::graphics::mapper::V2_0::IMapper> buffer_mapper_v2_; - sp<android::hardware::graphics::mapper::V3_0::IMapper> buffer_mapper_v3_; - sp<android::hardware::graphics::mapper::V4_0::IMapper> buffer_mapper_v4_; + android::sp<android::hardware::graphics::mapper::V2_0::IMapper> buffer_mapper_v2_; + android::sp<android::hardware::graphics::mapper::V3_0::IMapper> buffer_mapper_v3_; + android::sp<android::hardware::graphics::mapper::V4_0::IMapper> buffer_mapper_v4_; - std::mutex hidl_thermal_mutex_; - sp<android::hardware::thermal::V2_0::IThermal> thermal_; + std::mutex aidl_thermal_mutex_; + std::shared_ptr<aidl::android::hardware::thermal::IThermal> thermal_; // Must be protected by hidl_thermal_mutex_. - sp<android::hardware::thermal::V2_0::IThermalChangedCallback> - thermal_changed_callback_; + std::shared_ptr<aidl::android::hardware::thermal::IThermalChangedCallback> + 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<AidlProfiler> aidl_profiler_; + std::shared_ptr<android::hardware::camera::implementation::AidlProfiler> + aidl_profiler_; }; } // namespace implementation diff --git a/common/hal/aidl_service/hidl_thermal_utils.cc b/common/hal/aidl_service/aidl_thermal_utils.cc index cb2c915..3104d23 100644 --- a/common/hal/aidl_service/hidl_thermal_utils.cc +++ b/common/hal/aidl_service/aidl_thermal_utils.cc @@ -14,74 +14,69 @@ * limitations under the License. */ -#define LOG_TAG "GCH_HidlThermalUtils" -//#define LOG_NDEBUG 0 -#include "hidl_thermal_utils.h" +#define LOG_TAG "GCH_AidlThermalUtils" +// #define LOG_NDEBUG 0 +#include "aidl_thermal_utils.h" #include <log/log.h> namespace android { namespace hardware { -namespace hidl_thermal_utils { - -std::unique_ptr<HidlThermalChangedCallback> HidlThermalChangedCallback::Create( - google_camera_hal::NotifyThrottlingFunc notify_throttling) { - auto thermal_changed_callback = std::unique_ptr<HidlThermalChangedCallback>( - new HidlThermalChangedCallback(notify_throttling)); - if (thermal_changed_callback == nullptr) { - ALOGE("%s: Failed to create a thermal changed callback", __FUNCTION__); - return nullptr; - } +namespace aidl_thermal_utils { +namespace { - return thermal_changed_callback; -} +using ::aidl::android::hardware::thermal::Temperature; +using ::aidl::android::hardware::thermal::TemperatureType; +using ::aidl::android::hardware::thermal::ThrottlingSeverity; + +} // namespace -HidlThermalChangedCallback::HidlThermalChangedCallback( +ThermalChangedCallback::ThermalChangedCallback( google_camera_hal::NotifyThrottlingFunc notify_throttling) - : kNotifyThrottling(notify_throttling) { + : notify_throttling_(std::move(notify_throttling)) { } -status_t ConvertToHidlTemperatureType( +status_t ConvertToAidlTemperatureType( 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__); + 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: - *hidl_temperature_type = TemperatureType::UNKNOWN; + *aidl_temperature_type = TemperatureType::UNKNOWN; break; case google_camera_hal::TemperatureType::kCpu: - *hidl_temperature_type = TemperatureType::CPU; + *aidl_temperature_type = TemperatureType::CPU; break; case google_camera_hal::TemperatureType::kGpu: - *hidl_temperature_type = TemperatureType::GPU; + *aidl_temperature_type = TemperatureType::GPU; break; case google_camera_hal::TemperatureType::kBattery: - *hidl_temperature_type = TemperatureType::BATTERY; + *aidl_temperature_type = TemperatureType::BATTERY; break; case google_camera_hal::TemperatureType::kSkin: - *hidl_temperature_type = TemperatureType::SKIN; + *aidl_temperature_type = TemperatureType::SKIN; break; case google_camera_hal::TemperatureType::kUsbPort: - *hidl_temperature_type = TemperatureType::USB_PORT; + *aidl_temperature_type = TemperatureType::USB_PORT; break; case google_camera_hal::TemperatureType::kPowerAmplifier: - *hidl_temperature_type = TemperatureType::POWER_AMPLIFIER; + *aidl_temperature_type = TemperatureType::POWER_AMPLIFIER; break; case google_camera_hal::TemperatureType::kBclVoltage: - *hidl_temperature_type = TemperatureType::BCL_VOLTAGE; + *aidl_temperature_type = TemperatureType::BCL_VOLTAGE; break; case google_camera_hal::TemperatureType::kBclCurrent: - *hidl_temperature_type = TemperatureType::BCL_CURRENT; + *aidl_temperature_type = TemperatureType::BCL_CURRENT; break; case google_camera_hal::TemperatureType::kBclPercentage: - *hidl_temperature_type = TemperatureType::BCL_PERCENTAGE; + *aidl_temperature_type = TemperatureType::BCL_PERCENTAGE; break; case google_camera_hal::TemperatureType::kNpu: - *hidl_temperature_type = TemperatureType::NPU; + *aidl_temperature_type = TemperatureType::NPU; break; default: ALOGE("%s: Unknown temperature type: %d", __FUNCTION__, @@ -92,15 +87,15 @@ status_t ConvertToHidlTemperatureType( return OK; } -status_t HidlThermalChangedCallback::ConvertToHalTemperatureType( - const TemperatureType& hidl_temperature_type, +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 (hidl_temperature_type) { + switch (aidl_temperature_type) { case TemperatureType::UNKNOWN: *hal_temperature_type = google_camera_hal::TemperatureType::kUnknown; break; @@ -137,22 +132,22 @@ status_t HidlThermalChangedCallback::ConvertToHalTemperatureType( break; default: ALOGE("%s: Unknown temperature type: %d", __FUNCTION__, - hidl_temperature_type); + aidl_temperature_type); return BAD_VALUE; } return OK; } -status_t HidlThermalChangedCallback::ConvertToHalThrottlingSeverity( - const ThrottlingSeverity& hidl_throttling_severity, +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 (hidl_throttling_severity) { + switch (aidl_throttling_severity) { case ThrottlingSeverity::NONE: *hal_throttling_severity = google_camera_hal::ThrottlingSeverity::kNone; break; @@ -180,22 +175,22 @@ status_t HidlThermalChangedCallback::ConvertToHalThrottlingSeverity( break; default: ALOGE("%s: Unknown temperature severity: %d", __FUNCTION__, - hidl_throttling_severity); + aidl_throttling_severity); return BAD_VALUE; } return OK; } -status_t HidlThermalChangedCallback::ConvertToHalTemperature( - const Temperature& hidl_temperature, +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(hidl_temperature.type, + status_t res = ConvertToHalTemperatureType(aidl_temperature.type, &hal_temperature->type); if (res != OK) { ALOGE("%s: Converting to hal temperature type failed: %s(%d)", __FUNCTION__, @@ -203,10 +198,10 @@ status_t HidlThermalChangedCallback::ConvertToHalTemperature( return res; } - hal_temperature->name = hidl_temperature.name; - hal_temperature->value = hidl_temperature.value; + hal_temperature->name = aidl_temperature.name; + hal_temperature->value = aidl_temperature.value; - res = ConvertToHalThrottlingSeverity(hidl_temperature.throttlingStatus, + res = ConvertToHalThrottlingSeverity(aidl_temperature.throttlingStatus, &hal_temperature->throttling_status); if (res != OK) { ALOGE("%s: Converting to hal throttling severity type failed: %s(%d)", @@ -217,20 +212,19 @@ status_t HidlThermalChangedCallback::ConvertToHalTemperature( return OK; } -Return<void> HidlThermalChangedCallback::notifyThrottling( +ndk::ScopedAStatus ThermalChangedCallback::notifyThrottling( const Temperature& temperature) { google_camera_hal::Temperature hal_temperature; status_t res = ConvertToHalTemperature(temperature, &hal_temperature); - if (res != OK) { + if (res == OK) { + notify_throttling_(hal_temperature); + } else { ALOGE("%s: Converting to hal temperature failed: %s(%d)", __FUNCTION__, strerror(-res), res); - return Void(); } - - kNotifyThrottling(hal_temperature); - return Void(); + return ndk::ScopedAStatus(AStatus_newOk()); } -} // namespace hidl_thermal_utils +} // 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 <aidl/android/hardware/thermal/BnThermalChangedCallback.h> +#include <aidl/android/hardware/thermal/IThermal.h> + +#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/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<uint8_t*>(hal_metadata->ReleaseCameraMetadata()); + const auto* metadata_p = + reinterpret_cast<const uint8_t*>(hal_metadata->GetRawCameraMetadata()); // TODO: Do we reallly need to copy here ? aidl_metadata->assign(metadata_p, metadata_p + metadata_size); 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 <android/hardware/thermal/2.0/IThermalChangedCallback.h> - -#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<HidlThermalChangedCallback> Create( - google_camera_hal::NotifyThrottlingFunc notify_throttling); - virtual ~HidlThermalChangedCallback() = default; - - // Override functions in HidlThermalChangedCallback. - Return<void> 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 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 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<VendorTag> 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/camera_device_session.cc b/common/hal/google_camera_hal/camera_device_session.cc index f0fb273..621fd6f 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<uint32_t> 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); @@ -1154,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) { @@ -1720,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__, @@ -1748,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; } @@ -1852,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); 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/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..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 @@ -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); } @@ -400,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; } 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/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/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; } 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<StreamBuffer> output_buffers; + // Maps from physical camera ID to physical camera settings. + std::unordered_map<uint32_t, std::unique_ptr<HalCameraMetadata>> + 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; } 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; } 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<int32_t> 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); 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); } diff --git a/common/hal/utils/utils.cc b/common/hal/utils/utils.cc index c8f7b64..b9efc80 100644 --- a/common/hal/utils/utils.cc +++ b/common/hal/utils/utils.cc @@ -25,6 +25,8 @@ #include <hardware/gralloc.h> #include <sys/stat.h> +#include <array> + #include "utils.h" #include "vendor_tag_defs.h" @@ -32,6 +34,31 @@ namespace android { namespace google_camera_hal { namespace utils { +namespace { + +using FpsRange = std::pair<int32_t, int32_t>; + +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<std::pair<FpsRange, FpsRange>, 3> kAcceptableTransitions = { + std::make_pair<FpsRange, FpsRange>({30, 30}, {60, 60}), + std::make_pair<FpsRange, FpsRange>({24, 24}, {24, 30}), + std::make_pair<FpsRange, FpsRange>({24, 24}, {30, 30}), + }; + + for (const std::pair<FpsRange, FpsRange>& 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"; @@ -186,11 +213,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; } @@ -380,6 +402,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, @@ -388,14 +414,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) { 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 <log/log.h> + #include <cmath> #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<uint32_t, Dimension> physical_cam_active_array_dimension; + std::unordered_map<uint32_t, Dimension> + physical_cam_active_array_maximum_resolution_dimension; ZoomRatioRange zoom_ratio_range; std::unique_ptr<ZoomRatioMapperHwl> 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<uint32_t, Dimension> physical_cam_active_array_dimension_; + // Active array maximum resolution dimension of physical camera. + std::unordered_map<uint32_t, Dimension> + physical_cam_active_array_maximum_resolution_dimension_; + // Zoom ratio range. ZoomRatioRange zoom_ratio_range_; 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, + }, +} |