diff options
author | Minghui Tan <mhtan@google.com> | 2022-02-18 14:47:40 -0800 |
---|---|---|
committer | Minghui Tan <mhtan@google.com> | 2022-03-01 22:41:10 +0000 |
commit | 0c5c17057a285d2b00a0756dcc6ef921e03dccd3 (patch) | |
tree | 90c55744ae501537bc04d9183a6a3d7cfc64787b /common | |
parent | 18e5d7e67c5a6a1446ca1f6c1cdd3a45e650cb1d (diff) | |
download | camera-0c5c17057a285d2b00a0756dcc6ef921e03dccd3.tar.gz |
Chain denoise processor to the capture session
Bug: 220022111
Test: snapchat video denoise enabled/disabled
Change-Id: I1ac3d69b45c06e08a41b88450a51283526ed42e8
Diffstat (limited to 'common')
4 files changed, 136 insertions, 15 deletions
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 04f428d..2f14217 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 @@ -15,16 +15,17 @@ */ //#define LOG_NDEBUG 0 -#include "realtime_zsl_result_processor.h" #define LOG_TAG "GCH_RealtimeZslResultRequestProcessor" #define ATRACE_TAG ATRACE_TAG_CAMERA +#include "realtime_zsl_result_request_processor.h" + #include <inttypes.h> #include <log/log.h> #include <utils/Trace.h> #include "hal_utils.h" -#include "realtime_zsl_result_request_processor.h" +#include "realtime_zsl_result_processor.h" namespace android { namespace google_camera_hal { @@ -117,6 +118,45 @@ void RealtimeZslResultRequestProcessor::ProcessResult( result->output_buffers.size() == 0) { return; } + + // Cache the CaptureRequest in a queue as the metadata and buffers may not + // come together. + if (pending_frame_number_to_requests_.find(result->frame_number) == + pending_frame_number_to_requests_.end()) { + pending_frame_number_to_requests_[result->frame_number] = + std::make_unique<CaptureRequest>(); + pending_frame_number_to_requests_[result->frame_number]->frame_number = + result->frame_number; + } + + // Fill in final result metadata + if (result->result_metadata != nullptr && + result->partial_result == partial_result_count_) { + pending_frame_number_to_requests_[result->frame_number]->settings = + HalCameraMetadata::Clone(result->result_metadata.get()); + } + + // Fill in output buffer + if (!result->output_buffers.empty()) { + pending_frame_number_to_requests_[result->frame_number]->input_buffers = + result->input_buffers; + pending_frame_number_to_requests_[result->frame_number]->output_buffers = + result->output_buffers; + } + + // Submit the request and remove the request from the cache when all data is collected. + if (!pending_frame_number_to_requests_[result->frame_number] + ->output_buffers.empty() && + pending_frame_number_to_requests_[result->frame_number]->settings != + nullptr) { + res = + ProcessRequest(*pending_frame_number_to_requests_[result->frame_number]); + pending_frame_number_to_requests_.erase(result->frame_number); + if (res != OK) { + ALOGE("%s: ProcessRequest fail", __FUNCTION__); + return; + } + } } status_t RealtimeZslResultRequestProcessor::ConfigureStreams( diff --git a/common/hal/google_camera_hal/realtime_zsl_result_request_processor.h b/common/hal/google_camera_hal/realtime_zsl_result_request_processor.h index 84a1ba1..71f156c 100644 --- a/common/hal/google_camera_hal/realtime_zsl_result_request_processor.h +++ b/common/hal/google_camera_hal/realtime_zsl_result_request_processor.h @@ -17,8 +17,10 @@ #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 <cstdint> #include <shared_mutex> +#include "hal_types.h" #include "internal_stream_manager.h" #include "realtime_zsl_result_processor.h" #include "request_processor.h" @@ -66,6 +68,9 @@ class RealtimeZslResultRequestProcessor : public RealtimeZslResultProcessor, // Protected by process_block_shared_lock_. std::unique_ptr<ProcessBlock> process_block_; + + std::unordered_map<uint32_t, std::unique_ptr<CaptureRequest>> + pending_frame_number_to_requests_; }; } // namespace google_camera_hal 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..068a2fb 100644 --- a/common/hal/google_camera_hal/zsl_snapshot_capture_session.cc +++ b/common/hal/google_camera_hal/zsl_snapshot_capture_session.cc @@ -27,6 +27,7 @@ #include <utils/Trace.h> #include "hal_utils.h" +#include "realtime_zsl_result_request_processor.h" #include "snapshot_request_processor.h" #include "snapshot_result_processor.h" #include "system/graphics-base-v1.0.h" @@ -405,14 +406,28 @@ 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_); + + std::unique_ptr<ResultProcessor> realtime_result_processor; + RealtimeZslResultRequestProcessor* realtime_result_request_processor; + if (video_sw_denoise_enabled_) { + auto processor = RealtimeZslResultRequestProcessor::Create( + internal_stream_manager_.get(), additional_stream_id, + HAL_PIXEL_FORMAT_YCBCR_420_888, partial_result_count_); + realtime_result_request_processor = processor.get(); + realtime_result_processor = std::move(processor); + } else { + 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) { - ALOGE("%s: Creating RealtimeZslResultProcessor failed.", __FUNCTION__); + ALOGE( + "%s: Creating " + "RealtimeZslResultProcessor/RealtimeZslResultRequestProcessor failed.", + __FUNCTION__); return UNKNOWN_ERROR; } - realtime_result_processor_ = realtime_result_processor.get(); realtime_result_processor->SetResultCallback(process_capture_result, notify); res = process_block->SetResultProcessor(std::move(realtime_result_processor)); @@ -437,6 +452,56 @@ status_t ZslSnapshotCaptureSession::ConfigureStreams( } } + if (video_sw_denoise_enabled_) { + StreamConfiguration denoise_process_block_stream_config; + // Configure streams for request processor + res = realtime_result_request_processor->ConfigureStreams( + internal_stream_manager_.get(), stream_config, + &denoise_process_block_stream_config); + + if (res != OK) { + ALOGE( + "%s: Configuring stream for process block " + "(RealtimeZslResultRequestProcessor) failed.", + __FUNCTION__); + return res; + } + + std::unique_ptr<ProcessBlock> denoise_processor = + CreateDenoiseProcessBlock(); + // Create preview result processor. Stream ID is not set at this stage. + auto basic_result_processor = BasicResultProcessor::Create(); + if (basic_result_processor == nullptr) { + ALOGE("%s: Creating BasicResultProcessor failed.", __FUNCTION__); + return UNKNOWN_ERROR; + } + basic_result_processor_ = basic_result_processor.get(); + basic_result_processor->SetResultCallback(process_capture_result, notify); + + res = + denoise_processor->SetResultProcessor(std::move(basic_result_processor)); + if (res != OK) { + ALOGE("%s: Setting result process in process block failed.", __FUNCTION__); + return res; + } + + // Configure streams for process block. + res = denoise_processor->ConfigureStreams( + denoise_process_block_stream_config, stream_config); + if (res != OK) { + ALOGE("%s: Configuring stream for process block failed.", __FUNCTION__); + return res; + } + + res = realtime_result_request_processor->SetProcessBlock( + std::move(denoise_processor)); + if (res != OK) { + ALOGE("%s: Setting process block for RequestProcessor failed: %s(%d)", + __FUNCTION__, strerror(-res), res); + return res; + } + } + return OK; } @@ -539,13 +604,11 @@ status_t ZslSnapshotCaptureSession::SetupRealtimeProcessChain( ProcessCaptureResultFunc process_capture_result, NotifyFunc notify) { ATRACE_CALL(); if (realtime_process_block_ != nullptr || - realtime_result_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_, + "%s: realtime_process_block_(%p) or realtime_request_processor_(%p) " + "is/are already set", + __FUNCTION__, realtime_process_block_, realtime_request_processor_.get()); return BAD_VALUE; } @@ -648,6 +711,16 @@ status_t ZslSnapshotCaptureSession::Initialize( return BAD_VALUE; } + camera_metadata_ro_entry video_sw_denoise_entry; + res = characteristics->Get(VendorTagIds::kVideoSwDenoiseEnabled, + &video_sw_denoise_entry); + if (res == OK && video_sw_denoise_entry.data.u8[0] == 1) { + video_sw_denoise_enabled_ = true; + ALOGI("%s: video sw denoise is enabled.", __FUNCTION__); + } else { + ALOGI("%s: video sw denoise is disabled.", __FUNCTION__); + } + for (auto stream : stream_config.streams) { if (utils::IsPreviewStream(stream)) { hal_preview_stream_id_ = stream.id; 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 04cc63d..2a66592 100644 --- a/common/hal/google_camera_hal/zsl_snapshot_capture_session.h +++ b/common/hal/google_camera_hal/zsl_snapshot_capture_session.h @@ -17,6 +17,7 @@ #ifndef HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_ZSL_SNAPSHOT_CAPTURE_SESSION_H_ #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_ZSL_SNAPSHOT_CAPTURE_SESSION_H_ +#include "basic_result_processor.h" #include "camera_buffer_allocator_hwl.h" #include "camera_device_session_hwl.h" #include "capture_session.h" @@ -142,9 +143,6 @@ class ZslSnapshotCaptureSession : public CaptureSession { // CaptureSessionWrapperProcessBlock will be owned and released by // RealtimeZslRequestProcessor. CaptureSessionWrapperProcessBlock* realtime_process_block_ = nullptr; - // RealtimeZslResultRequestProcessor will be owned and released by - // CaptureSessionWrapperProcessBlock. - RealtimeZslResultProcessor* realtime_result_processor_ = nullptr; std::unique_ptr<SnapshotRequestProcessor> snapshot_request_processor_; // SnapshotProcessBlock will be owned and released by @@ -153,6 +151,8 @@ class ZslSnapshotCaptureSession : public CaptureSession { // SnapshotResultProcessor will be owned and released by SnapshotProcessBlock. SnapshotResultProcessor* snapshot_result_processor_ = nullptr; + BasicResultProcessor* basic_result_processor_ = nullptr; + // Use this stream id to check the request is ZSL compatible int32_t hal_preview_stream_id_ = -1; @@ -188,6 +188,9 @@ class ZslSnapshotCaptureSession : public CaptureSession { // Partial result count reported by HAL uint32_t partial_result_count_ = 1; + + // Whether video software denoise is enabled + bool video_sw_denoise_enabled_ = false; }; } // namespace google_camera_hal |