diff options
author | Minghui Tan <mhtan@google.com> | 2022-02-14 14:13:28 -0800 |
---|---|---|
committer | Minghui Tan <mhtan@google.com> | 2022-02-16 13:29:54 -0800 |
commit | e1e580df9bf0df20f9a4c2b566fb4ef2659ad999 (patch) | |
tree | 836a4b2527048fddd0270adacc438d3b3ded4db8 | |
parent | 5fad5994967f8c04fcf9ed413f0cdebff74aec22 (diff) | |
download | camera-e1e580df9bf0df20f9a4c2b566fb4ef2659ad999.tar.gz |
Modify RealtimeZslResultProcessor to be a request processor.
Bug: 218907758
Fix: 218907758
Test: compile
Change-Id: If4467d5d0f7f414f9a360c04f1efcfa264ad0fc9
-rw-r--r-- | common/hal/google_camera_hal/Android.bp | 2 | ||||
-rw-r--r-- | common/hal/google_camera_hal/hdrplus_capture_session.cc | 7 | ||||
-rw-r--r-- | common/hal/google_camera_hal/hdrplus_capture_session.h | 2 | ||||
-rw-r--r-- | common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc (renamed from common/hal/google_camera_hal/realtime_zsl_result_processor.cc) | 122 | ||||
-rw-r--r-- | common/hal/google_camera_hal/realtime_zsl_result_request_processor.h (renamed from common/hal/google_camera_hal/realtime_zsl_result_processor.h) | 47 | ||||
-rw-r--r-- | common/hal/google_camera_hal/zsl_snapshot_capture_session.cc | 23 | ||||
-rw-r--r-- | common/hal/google_camera_hal/zsl_snapshot_capture_session.h | 9 |
7 files changed, 163 insertions, 49 deletions
diff --git a/common/hal/google_camera_hal/Android.bp b/common/hal/google_camera_hal/Android.bp index 15048a8..6f0e6da 100644 --- a/common/hal/google_camera_hal/Android.bp +++ b/common/hal/google_camera_hal/Android.bp @@ -69,7 +69,7 @@ cc_library_shared { "pending_requests_tracker.cc", "realtime_process_block.cc", "realtime_zsl_request_processor.cc", - "realtime_zsl_result_processor.cc", + "realtime_zsl_result_request_processor.cc", "rgbird_capture_session.cc", "rgbird_depth_result_processor.cc", "rgbird_result_request_processor.cc", diff --git a/common/hal/google_camera_hal/hdrplus_capture_session.cc b/common/hal/google_camera_hal/hdrplus_capture_session.cc index c7b676a..98fdf99 100644 --- a/common/hal/google_camera_hal/hdrplus_capture_session.cc +++ b/common/hal/google_camera_hal/hdrplus_capture_session.cc @@ -32,7 +32,7 @@ #include "hdrplus_result_processor.h" #include "realtime_process_block.h" #include "realtime_zsl_request_processor.h" -#include "realtime_zsl_result_processor.h" +#include "realtime_zsl_result_request_processor.h" #include "vendor_tag_defs.h" namespace android { @@ -374,10 +374,11 @@ status_t HdrplusCaptureSession::SetupRealtimeProcessChain( } // Create realtime result processor. - auto result_processor = RealtimeZslResultProcessor::Create( + auto result_processor = RealtimeZslResultRequestProcessor::Create( internal_stream_manager_.get(), *raw_stream_id, HAL_PIXEL_FORMAT_RAW10); if (result_processor == nullptr) { - ALOGE("%s: Creating RealtimeZslResultProcessor failed.", __FUNCTION__); + ALOGE("%s: Creating RealtimeZslResultRequestProcessor failed.", + __FUNCTION__); return UNKNOWN_ERROR; } result_processor->SetResultCallback(process_capture_result, notify); diff --git a/common/hal/google_camera_hal/hdrplus_capture_session.h b/common/hal/google_camera_hal/hdrplus_capture_session.h index 2519541..8369196 100644 --- a/common/hal/google_camera_hal/hdrplus_capture_session.h +++ b/common/hal/google_camera_hal/hdrplus_capture_session.h @@ -33,7 +33,7 @@ namespace google_camera_hal { // process chains (realtime and HDR+) // // 1. RealtimeZslRequestProcessor -> RealtimeProcessBlock -> -// RealtimeZslResultProcessor +// RealtimeZslResultRequestProcessor // 2. HdrplusRequestProcessor -> HdrplusProcessBlock -> HdrplusResultProcessor // // It only supports a single physical camera device session. diff --git a/common/hal/google_camera_hal/realtime_zsl_result_processor.cc b/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc index d337f88..fae83ff 100644 --- a/common/hal/google_camera_hal/realtime_zsl_result_processor.cc +++ b/common/hal/google_camera_hal/realtime_zsl_result_request_processor.cc @@ -15,10 +15,10 @@ */ //#define LOG_NDEBUG 0 -#define LOG_TAG "GCH_RealtimeZslResultProcessor" +#define LOG_TAG "GCH_RealtimeZslResultRequestProcessor" #define ATRACE_TAG ATRACE_TAG_CAMERA -#include "realtime_zsl_result_processor.h" +#include "realtime_zsl_result_request_processor.h" #include <inttypes.h> #include <log/log.h> @@ -29,7 +29,8 @@ namespace android { namespace google_camera_hal { -std::unique_ptr<RealtimeZslResultProcessor> RealtimeZslResultProcessor::Create( +std::unique_ptr<RealtimeZslResultRequestProcessor> +RealtimeZslResultRequestProcessor::Create( InternalStreamManager* internal_stream_manager, int32_t stream_id, android_pixel_format_t pixel_format, uint32_t partial_result_count) { ATRACE_CALL(); @@ -38,18 +39,19 @@ std::unique_ptr<RealtimeZslResultProcessor> RealtimeZslResultProcessor::Create( return nullptr; } - auto result_processor = std::unique_ptr<RealtimeZslResultProcessor>( - new RealtimeZslResultProcessor(internal_stream_manager, stream_id, - pixel_format, partial_result_count)); + auto result_processor = std::unique_ptr<RealtimeZslResultRequestProcessor>( + new RealtimeZslResultRequestProcessor(internal_stream_manager, stream_id, + pixel_format, partial_result_count)); if (result_processor == nullptr) { - ALOGE("%s: Creating RealtimeZslResultProcessor failed.", __FUNCTION__); + ALOGE("%s: Creating RealtimeZslResultRequestProcessor failed.", + __FUNCTION__); return nullptr; } return result_processor; } -RealtimeZslResultProcessor::RealtimeZslResultProcessor( +RealtimeZslResultRequestProcessor::RealtimeZslResultRequestProcessor( InternalStreamManager* internal_stream_manager, int32_t stream_id, android_pixel_format_t pixel_format, uint32_t partial_result_count) { internal_stream_manager_ = internal_stream_manager; @@ -58,14 +60,15 @@ RealtimeZslResultProcessor::RealtimeZslResultProcessor( partial_result_count_ = partial_result_count; } -void RealtimeZslResultProcessor::SetResultCallback( +void RealtimeZslResultRequestProcessor::SetResultCallback( ProcessCaptureResultFunc process_capture_result, NotifyFunc notify) { std::lock_guard<std::mutex> lock(callback_lock_); process_capture_result_ = process_capture_result; notify_ = notify; } -void RealtimeZslResultProcessor::SaveLsForHdrplus(const CaptureRequest& request) { +void RealtimeZslResultRequestProcessor::SaveLsForHdrplus( + const CaptureRequest& request) { if (request.settings != nullptr) { uint8_t lens_shading_map_mode; status_t res = @@ -82,7 +85,7 @@ void RealtimeZslResultProcessor::SaveLsForHdrplus(const CaptureRequest& request) } } -status_t RealtimeZslResultProcessor::HandleLsResultForHdrplus( +status_t RealtimeZslResultRequestProcessor::HandleLsResultForHdrplus( uint32_t frameNumber, HalCameraMetadata* metadata) { if (metadata == nullptr) { ALOGE("%s: metadata is nullptr", __FUNCTION__); @@ -106,7 +109,8 @@ status_t RealtimeZslResultProcessor::HandleLsResultForHdrplus( return OK; } -void RealtimeZslResultProcessor::SaveFdForHdrplus(const CaptureRequest& request) { +void RealtimeZslResultRequestProcessor::SaveFdForHdrplus( + const CaptureRequest& request) { // Enable face detect mode for internal use if (request.settings != nullptr) { uint8_t fd_mode; @@ -123,7 +127,7 @@ void RealtimeZslResultProcessor::SaveFdForHdrplus(const CaptureRequest& request) } } -status_t RealtimeZslResultProcessor::HandleFdResultForHdrplus( +status_t RealtimeZslResultRequestProcessor::HandleFdResultForHdrplus( uint32_t frameNumber, HalCameraMetadata* metadata) { if (metadata == nullptr) { ALOGE("%s: metadata is nullptr", __FUNCTION__); @@ -147,7 +151,7 @@ status_t RealtimeZslResultProcessor::HandleFdResultForHdrplus( return OK; } -status_t RealtimeZslResultProcessor::AddPendingRequests( +status_t RealtimeZslResultRequestProcessor::AddPendingRequests( const std::vector<ProcessBlockRequest>& process_block_requests, const CaptureRequest& remaining_session_request) { ATRACE_CALL(); @@ -167,7 +171,8 @@ status_t RealtimeZslResultProcessor::AddPendingRequests( return OK; } -void RealtimeZslResultProcessor::ProcessResult(ProcessBlockResult block_result) { +void RealtimeZslResultRequestProcessor::ProcessResult( + ProcessBlockResult block_result) { ATRACE_CALL(); std::lock_guard<std::mutex> lock(callback_lock_); std::unique_ptr<CaptureResult> result = std::move(block_result.result); @@ -252,7 +257,7 @@ void RealtimeZslResultProcessor::ProcessResult(ProcessBlockResult block_result) process_capture_result_(std::move(result)); } -void RealtimeZslResultProcessor::Notify( +void RealtimeZslResultRequestProcessor::Notify( const ProcessBlockNotifyMessage& block_message) { ATRACE_CALL(); std::lock_guard<std::mutex> lock(callback_lock_); @@ -265,10 +270,93 @@ void RealtimeZslResultProcessor::Notify( notify_(message); } -status_t RealtimeZslResultProcessor::FlushPendingRequests() { +status_t RealtimeZslResultRequestProcessor::FlushPendingRequests() { ATRACE_CALL(); return INVALID_OPERATION; } +status_t RealtimeZslResultRequestProcessor::ConfigureStreams( + InternalStreamManager* /*internal_stream_manager*/, + const StreamConfiguration& stream_config, + StreamConfiguration* process_block_stream_config) { + ATRACE_CALL(); + if (process_block_stream_config == nullptr) { + ALOGE("%s: process_block_stream_config is nullptr", __FUNCTION__); + return BAD_VALUE; + } + + process_block_stream_config->streams = stream_config.streams; + process_block_stream_config->operation_mode = stream_config.operation_mode; + process_block_stream_config->session_params = + HalCameraMetadata::Clone(stream_config.session_params.get()); + process_block_stream_config->stream_config_counter = + stream_config.stream_config_counter; + process_block_stream_config->multi_resolution_input_image = + stream_config.multi_resolution_input_image; + + return OK; +} + +status_t RealtimeZslResultRequestProcessor::SetProcessBlock( + std::unique_ptr<ProcessBlock> process_block) { + ATRACE_CALL(); + if (process_block == nullptr) { + ALOGE("%s: process_block is nullptr", __FUNCTION__); + return BAD_VALUE; + } + + std::lock_guard lock(process_block_shared_lock_); + if (process_block_ != nullptr) { + ALOGE("%s: Already configured.", __FUNCTION__); + return ALREADY_EXISTS; + } + + process_block_ = std::move(process_block); + return OK; +} + +status_t RealtimeZslResultRequestProcessor::ProcessRequest( + const CaptureRequest& request) { + ATRACE_CALL(); + std::shared_lock lock(process_block_shared_lock_); + if (process_block_ == nullptr) { + ALOGE("%s: Not configured yet.", __FUNCTION__); + return NO_INIT; + } + + CaptureRequest block_request; + block_request.frame_number = request.frame_number; + block_request.settings = HalCameraMetadata::Clone(request.settings.get()); + block_request.input_buffers = request.input_buffers; + block_request.input_width = request.input_width; + block_request.input_height = request.input_height; + + for (auto& metadata : request.input_buffer_metadata) { + block_request.input_buffer_metadata.push_back( + HalCameraMetadata::Clone(metadata.get())); + } + + block_request.output_buffers = request.output_buffers; + for (auto& [camera_id, physical_metadata] : request.physical_camera_settings) { + block_request.physical_camera_settings[camera_id] = + HalCameraMetadata::Clone(physical_metadata.get()); + } + + std::vector<ProcessBlockRequest> block_requests(1); + block_requests[0].request = std::move(block_request); + + return process_block_->ProcessRequests(block_requests, request); +} + +status_t RealtimeZslResultRequestProcessor::Flush() { + ATRACE_CALL(); + std::shared_lock lock(process_block_shared_lock_); + if (process_block_ == nullptr) { + return OK; + } + + return process_block_->Flush(); +} + } // namespace google_camera_hal } // namespace android
\ No newline at end of file diff --git a/common/hal/google_camera_hal/realtime_zsl_result_processor.h b/common/hal/google_camera_hal/realtime_zsl_result_request_processor.h index 3a59df2..6ee1675 100644 --- a/common/hal/google_camera_hal/realtime_zsl_result_processor.h +++ b/common/hal/google_camera_hal/realtime_zsl_result_request_processor.h @@ -14,25 +14,29 @@ * limitations under the License. */ -#ifndef HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_REALTIME_ZSL_RESULT_PROCESSOR_H_ -#define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_REALTIME_ZSL_RESULT_PROCESSOR_H_ +#ifndef HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_REALTIME_ZSL_RESULT_REQUEST_PROCESSOR_H_ +#define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_REALTIME_ZSL_RESULT_REQUEST_PROCESSOR_H_ + +#include <shared_mutex> #include "internal_stream_manager.h" +#include "request_processor.h" #include "result_processor.h" namespace android { namespace google_camera_hal { -// RealtimeZslResultProcessor implements a ResultProcessor that return filled -// raw buffer and matedata to internal stream manager and forwards the results -// without raw buffer to its callback functions. -class RealtimeZslResultProcessor : public ResultProcessor { +// RealtimeZslResultRequestProcessor implements a ResultProcessor that return +// filled raw buffer and metadata to internal stream manager. It also implements +// a RequestProcess to forward the results. +class RealtimeZslResultRequestProcessor : public ResultProcessor, + RequestProcessor { public: - static std::unique_ptr<RealtimeZslResultProcessor> Create( + static std::unique_ptr<RealtimeZslResultRequestProcessor> Create( InternalStreamManager* internal_stream_manager, int32_t stream_id, android_pixel_format_t pixel_format, uint32_t partial_result_count = 1); - virtual ~RealtimeZslResultProcessor() = default; + virtual ~RealtimeZslResultRequestProcessor() = default; // Override functions of ResultProcessor start. void SetResultCallback(ProcessCaptureResultFunc process_capture_result, @@ -51,11 +55,23 @@ class RealtimeZslResultProcessor : public ResultProcessor { status_t FlushPendingRequests() override; // Override functions of ResultProcessor end. + // Override functions of RequestProcessor start. + status_t ConfigureStreams( + InternalStreamManager* internal_stream_manager, + const StreamConfiguration& stream_config, + StreamConfiguration* process_block_stream_config) override; + + status_t SetProcessBlock(std::unique_ptr<ProcessBlock> process_block) override; + + status_t ProcessRequest(const CaptureRequest& request) override; + + status_t Flush() override; + // Override functions of RequestProcessor end. + protected: - RealtimeZslResultProcessor(InternalStreamManager* internal_stream_manager, - int32_t stream_id, - android_pixel_format_t pixel_format, - uint32_t partial_result_count); + RealtimeZslResultRequestProcessor( + InternalStreamManager* internal_stream_manager, int32_t stream_id, + android_pixel_format_t pixel_format, uint32_t partial_result_count); private: // Save face detect mode for HDR+ @@ -99,9 +115,14 @@ class RealtimeZslResultProcessor : public ResultProcessor { // Partial result count reported by HAL uint32_t partial_result_count_; + + std::shared_mutex process_block_shared_lock_; + + // Protected by process_block_shared_lock_. + std::unique_ptr<ProcessBlock> process_block_; }; } // namespace google_camera_hal } // namespace android -#endif // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_REALTIME_ZSL_RESULT_PROCESSOR_H_ +#endif // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_REALTIME_ZSL_RESULT_REQUEST_PROCESSOR_H_ 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 77d5660..f6afbed 100644 --- a/common/hal/google_camera_hal/zsl_snapshot_capture_session.cc +++ b/common/hal/google_camera_hal/zsl_snapshot_capture_session.cc @@ -405,17 +405,20 @@ status_t ZslSnapshotCaptureSession::ConfigureStreams( } // Create preview result processor. Stream ID is not set at this stage. - auto realtime_result_processor = RealtimeZslResultProcessor::Create( - internal_stream_manager_.get(), additional_stream_id, - HAL_PIXEL_FORMAT_YCBCR_420_888, partial_result_count_); - if (realtime_result_processor == nullptr) { + auto realtime_result_request_processor = + RealtimeZslResultRequestProcessor::Create( + internal_stream_manager_.get(), additional_stream_id, + HAL_PIXEL_FORMAT_YCBCR_420_888, partial_result_count_); + if (realtime_result_request_processor == nullptr) { ALOGE("%s: Creating RealtimeZslResultProcessor failed.", __FUNCTION__); return UNKNOWN_ERROR; } - realtime_result_processor_ = realtime_result_processor.get(); - realtime_result_processor->SetResultCallback(process_capture_result, notify); + realtime_result_request_processor_ = realtime_result_request_processor.get(); + realtime_result_request_processor->SetResultCallback(process_capture_result, + notify); - res = process_block->SetResultProcessor(std::move(realtime_result_processor)); + res = process_block->SetResultProcessor( + std::move(realtime_result_request_processor)); if (res != OK) { ALOGE("%s: Setting result process in process block failed.", __FUNCTION__); return res; @@ -539,14 +542,14 @@ status_t ZslSnapshotCaptureSession::SetupRealtimeProcessChain( ProcessCaptureResultFunc process_capture_result, NotifyFunc notify) { ATRACE_CALL(); if (realtime_process_block_ != nullptr || - realtime_result_processor_ != nullptr || + realtime_result_request_processor_ != nullptr || realtime_request_processor_ != nullptr) { ALOGE( "%s: realtime_process_block_(%p) or realtime_result_processor_(%p) or " "realtime_request_processor_(%p) is/are " "already set", - __FUNCTION__, realtime_process_block_, realtime_result_processor_, - realtime_request_processor_.get()); + __FUNCTION__, realtime_process_block_, + realtime_result_request_processor_, realtime_request_processor_.get()); return BAD_VALUE; } diff --git a/common/hal/google_camera_hal/zsl_snapshot_capture_session.h b/common/hal/google_camera_hal/zsl_snapshot_capture_session.h index 09adbb9..7e34cba 100644 --- a/common/hal/google_camera_hal/zsl_snapshot_capture_session.h +++ b/common/hal/google_camera_hal/zsl_snapshot_capture_session.h @@ -25,7 +25,7 @@ #include "hwl_types.h" #include "process_block.h" #include "realtime_zsl_request_processor.h" -#include "realtime_zsl_result_processor.h" +#include "realtime_zsl_result_request_processor.h" #include "request_processor.h" #include "result_processor.h" #include "snapshot_request_processor.h" @@ -42,7 +42,7 @@ class CameraDeviceSession; // // 1.SnapshotRequestProcessor->SnapshotProcessBlock->SnapshotResultProcessor // -// 2.RealtimeZslRequestProcessor->CaptureSessionWrapperProcessBlock->RealtimeZslResultProcessor +// 2.RealtimeZslRequestProcessor->CaptureSessionWrapperProcessBlock->RealtimeZslResultRequestProcessor->DenoiseProcessBlock->BasicResultProcessor // || /\ // \/ || // embedded capture session @@ -142,9 +142,10 @@ class ZslSnapshotCaptureSession : public CaptureSession { // CaptureSessionWrapperProcessBlock will be owned and released by // RealtimeZslRequestProcessor. CaptureSessionWrapperProcessBlock* realtime_process_block_ = nullptr; - // RealtimeZslResultProcessor will be owned and released by + // RealtimeZslResultRequestProcessor will be owned and released by // CaptureSessionWrapperProcessBlock. - RealtimeZslResultProcessor* realtime_result_processor_ = nullptr; + RealtimeZslResultRequestProcessor* realtime_result_request_processor_ = + nullptr; std::unique_ptr<SnapshotRequestProcessor> snapshot_request_processor_; // SnapshotProcessBlock will be owned and released by |