diff options
author | Donghui Han <donghuihan@google.com> | 2020-05-12 14:42:07 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-05-12 14:42:07 +0000 |
commit | 3461691d650edd433c8050935b51577b70b4a0a2 (patch) | |
tree | cc538a3fe37715f6efbf3b71d66c8c00866a0144 | |
parent | 1a9e9c34c220edf1c2c2171db89f375fe05a054a (diff) | |
parent | 0985992b7203d7a075e1b7b010008cca72d49ccd (diff) | |
download | camera-3461691d650edd433c8050935b51577b70b4a0a2.tar.gz |
camera: Add FlushPendingRequests to result processor am: 0985992b72
Change-Id: I176ffad1a05093e306be85a49afdbfa120884e12
18 files changed, 150 insertions, 9 deletions
diff --git a/common/hal/google_camera_hal/basic_result_processor.cc b/common/hal/google_camera_hal/basic_result_processor.cc index 06fa5a7..41a112b 100644 --- a/common/hal/google_camera_hal/basic_result_processor.cc +++ b/common/hal/google_camera_hal/basic_result_processor.cc @@ -104,5 +104,10 @@ void BasicResultProcessor::Notify(const ProcessBlockNotifyMessage& block_message notify_(block_message.message); } +status_t BasicResultProcessor::FlushPendingRequests() { + ATRACE_CALL(); + return INVALID_OPERATION; +} + } // namespace google_camera_hal } // namespace android diff --git a/common/hal/google_camera_hal/basic_result_processor.h b/common/hal/google_camera_hal/basic_result_processor.h index 0071208..f263807 100644 --- a/common/hal/google_camera_hal/basic_result_processor.h +++ b/common/hal/google_camera_hal/basic_result_processor.h @@ -41,6 +41,8 @@ class BasicResultProcessor : public ResultProcessor { void ProcessResult(ProcessBlockResult block_result) override; void Notify(const ProcessBlockNotifyMessage& block_message) override; + + status_t FlushPendingRequests() override; // Override functions of ResultProcessor end. protected: diff --git a/common/hal/google_camera_hal/dual_ir_depth_result_processor.cc b/common/hal/google_camera_hal/dual_ir_depth_result_processor.cc index 9397c85..ee30451 100644 --- a/common/hal/google_camera_hal/dual_ir_depth_result_processor.cc +++ b/common/hal/google_camera_hal/dual_ir_depth_result_processor.cc @@ -133,5 +133,10 @@ void DualIrDepthResultProcessor::Notify( notify_(message); } +status_t DualIrDepthResultProcessor::FlushPendingRequests() { + ATRACE_CALL(); + return INVALID_OPERATION; +} + } // namespace google_camera_hal } // namespace android diff --git a/common/hal/google_camera_hal/dual_ir_depth_result_processor.h b/common/hal/google_camera_hal/dual_ir_depth_result_processor.h index 1338609..4e9af84 100644 --- a/common/hal/google_camera_hal/dual_ir_depth_result_processor.h +++ b/common/hal/google_camera_hal/dual_ir_depth_result_processor.h @@ -41,6 +41,8 @@ class DualIrDepthResultProcessor : public ResultProcessor { void ProcessResult(ProcessBlockResult block_result) override; void Notify(const ProcessBlockNotifyMessage& block_message) override; + + status_t FlushPendingRequests() override; // Override functions of ResultProcessor end. protected: diff --git a/common/hal/google_camera_hal/dual_ir_result_request_processor.cc b/common/hal/google_camera_hal/dual_ir_result_request_processor.cc index fcebc13..3511886 100644 --- a/common/hal/google_camera_hal/dual_ir_result_request_processor.cc +++ b/common/hal/google_camera_hal/dual_ir_result_request_processor.cc @@ -346,5 +346,10 @@ status_t DualIrResultRequestProcessor::Flush() { return INVALID_OPERATION; } +status_t DualIrResultRequestProcessor::FlushPendingRequests() { + ATRACE_CALL(); + return OK; +} + } // namespace google_camera_hal } // namespace android
\ No newline at end of file diff --git a/common/hal/google_camera_hal/dual_ir_result_request_processor.h b/common/hal/google_camera_hal/dual_ir_result_request_processor.h index 78c9510..39bde53 100644 --- a/common/hal/google_camera_hal/dual_ir_result_request_processor.h +++ b/common/hal/google_camera_hal/dual_ir_result_request_processor.h @@ -54,6 +54,8 @@ class DualIrResultRequestProcessor : public ResultProcessor, void ProcessResult(ProcessBlockResult block_result) override; void Notify(const ProcessBlockNotifyMessage& block_message) override; + + status_t FlushPendingRequests() override; // Override functions of ResultProcessor end. // Override functions of RequestProcessor start. diff --git a/common/hal/google_camera_hal/hdrplus_result_processor.cc b/common/hal/google_camera_hal/hdrplus_result_processor.cc index 6728353..b1747ef 100644 --- a/common/hal/google_camera_hal/hdrplus_result_processor.cc +++ b/common/hal/google_camera_hal/hdrplus_result_processor.cc @@ -130,5 +130,10 @@ void HdrplusResultProcessor::Notify( notify_(block_message.message); } +status_t HdrplusResultProcessor::FlushPendingRequests() { + ATRACE_CALL(); + return INVALID_OPERATION; +} + } // namespace google_camera_hal } // namespace android
\ No newline at end of file diff --git a/common/hal/google_camera_hal/hdrplus_result_processor.h b/common/hal/google_camera_hal/hdrplus_result_processor.h index 46456a3..e6062a5 100644 --- a/common/hal/google_camera_hal/hdrplus_result_processor.h +++ b/common/hal/google_camera_hal/hdrplus_result_processor.h @@ -46,6 +46,8 @@ class HdrplusResultProcessor : public ResultProcessor { void ProcessResult(ProcessBlockResult block_result) override; void Notify(const ProcessBlockNotifyMessage& block_message) override; + + status_t FlushPendingRequests() override; // Override functions of ResultProcessor end. protected: diff --git a/common/hal/google_camera_hal/multicam_realtime_process_block.cc b/common/hal/google_camera_hal/multicam_realtime_process_block.cc index 485b95c..5f412e7 100644 --- a/common/hal/google_camera_hal/multicam_realtime_process_block.cc +++ b/common/hal/google_camera_hal/multicam_realtime_process_block.cc @@ -416,7 +416,13 @@ status_t MultiCameraRtProcessBlock::Flush() { return OK; } - return device_session_hwl_->Flush(); + status_t res = device_session_hwl_->Flush(); + if (res != OK) { + ALOGE("%s: Flushing hwl device session failed.", __FUNCTION__); + return res; + } + + return result_processor_->FlushPendingRequests(); } void MultiCameraRtProcessBlock::NotifyHwlPipelineResult( 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 f9e4687..92fe396 100644 --- a/common/hal/google_camera_hal/realtime_zsl_result_processor.cc +++ b/common/hal/google_camera_hal/realtime_zsl_result_processor.cc @@ -249,5 +249,10 @@ void RealtimeZslResultProcessor::Notify( notify_(message); } +status_t RealtimeZslResultProcessor::FlushPendingRequests() { + ATRACE_CALL(); + return INVALID_OPERATION; +} + } // 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_processor.h index 138b064..41ad622 100644 --- a/common/hal/google_camera_hal/realtime_zsl_result_processor.h +++ b/common/hal/google_camera_hal/realtime_zsl_result_processor.h @@ -46,6 +46,8 @@ class RealtimeZslResultProcessor : public ResultProcessor { void ProcessResult(ProcessBlockResult block_result) override; void Notify(const ProcessBlockNotifyMessage& block_message) override; + + status_t FlushPendingRequests() override; // Override functions of ResultProcessor end. protected: diff --git a/common/hal/google_camera_hal/result_processor.h b/common/hal/google_camera_hal/result_processor.h index 947078a..28eef51 100644 --- a/common/hal/google_camera_hal/result_processor.h +++ b/common/hal/google_camera_hal/result_processor.h @@ -59,6 +59,9 @@ class ResultProcessor { // Called by a ProcessBlock to notify a message. virtual void Notify(const ProcessBlockNotifyMessage& block_message) = 0; + + // Flush all pending workload. + virtual status_t FlushPendingRequests() = 0; }; } // namespace google_camera_hal diff --git a/common/hal/google_camera_hal/rgbird_capture_session.cc b/common/hal/google_camera_hal/rgbird_capture_session.cc index 38eedba..41ec461 100644 --- a/common/hal/google_camera_hal/rgbird_capture_session.cc +++ b/common/hal/google_camera_hal/rgbird_capture_session.cc @@ -1102,6 +1102,17 @@ void RgbirdCaptureSession::NotifyHalMessage(const NotifyMessage& message) { return; } } else if (message.type == MessageType::kError) { + // drop the error notifications for the internal streams + auto error_stream_id = message.message.error.error_stream_id; + if (has_depth_stream_ && + message.message.error.error_code == ErrorCode::kErrorBuffer && + error_stream_id != kInvalidStreamId && + (error_stream_id == rgb_internal_yuv_stream_id_ || + error_stream_id == ir1_internal_raw_stream_id_ || + error_stream_id == ir2_internal_raw_stream_id_)) { + return; + } + status_t res = result_dispatcher_->AddError(message.message.error); if (res != OK) { ALOGE("%s: AddError for frame %u failed: %s (%d).", __FUNCTION__, diff --git a/common/hal/google_camera_hal/rgbird_depth_result_processor.cc b/common/hal/google_camera_hal/rgbird_depth_result_processor.cc index 93ea30e..83d92e2 100644 --- a/common/hal/google_camera_hal/rgbird_depth_result_processor.cc +++ b/common/hal/google_camera_hal/rgbird_depth_result_processor.cc @@ -142,5 +142,10 @@ void RgbirdDepthResultProcessor::Notify( notify_(message); } +status_t RgbirdDepthResultProcessor::FlushPendingRequests() { + ATRACE_CALL(); + return INVALID_OPERATION; +} + } // namespace google_camera_hal } // namespace android
\ No newline at end of file diff --git a/common/hal/google_camera_hal/rgbird_depth_result_processor.h b/common/hal/google_camera_hal/rgbird_depth_result_processor.h index e2dbe7d..88f9fd2 100644 --- a/common/hal/google_camera_hal/rgbird_depth_result_processor.h +++ b/common/hal/google_camera_hal/rgbird_depth_result_processor.h @@ -49,6 +49,8 @@ class RgbirdDepthResultProcessor : public ResultProcessor { void ProcessResult(ProcessBlockResult block_result) override; void Notify(const ProcessBlockNotifyMessage& block_message) override; + + status_t FlushPendingRequests() override; // Override functions of ResultProcessor end. protected: 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 d6bc2ec..28e8376 100644 --- a/common/hal/google_camera_hal/rgbird_result_request_processor.cc +++ b/common/hal/google_camera_hal/rgbird_result_request_processor.cc @@ -398,9 +398,9 @@ status_t RgbirdResultRequestProcessor::VerifyAndSubmitDepthRequest( uint32_t frame_number) { std::lock_guard<std::mutex> lock(depth_requests_mutex_); if (depth_requests_.find(frame_number) == depth_requests_.end()) { - ALOGE("%s: Can not find depth request with frame number %u", __FUNCTION__, + ALOGW("%s: Can not find depth request with frame number %u", __FUNCTION__, frame_number); - return UNKNOWN_ERROR; + return NAME_NOT_FOUND; } uint32_t valid_input_buffer_num = 0; @@ -414,6 +414,8 @@ status_t RgbirdResultRequestProcessor::VerifyAndSubmitDepthRequest( if (IsAutocalRequest(frame_number)) { if (valid_input_buffer_num != /*rgb+ir1+ir2*/ 3) { // not all input buffers are ready, early return properly + ALOGV("%s: Not all input buffers are ready for frame %u", __FUNCTION__, + frame_number); return OK; } } else { @@ -421,12 +423,16 @@ status_t RgbirdResultRequestProcessor::VerifyAndSubmitDepthRequest( // consistent with the input buffer metadata. if (valid_input_buffer_num != /*ir1+ir2*/ 2) { // not all input buffers are ready, early return properly + ALOGV("%s: Not all input buffers are ready for frame %u", __FUNCTION__, + frame_number); return OK; } } if (depth_request->input_buffer_metadata.empty()) { // input buffer metadata is not ready(cloned) yet, early return properly + ALOGV("%s: Input buffer metadata is not ready for frame %u", __FUNCTION__, + frame_number); return OK; } @@ -441,7 +447,8 @@ status_t RgbirdResultRequestProcessor::VerifyAndSubmitDepthRequest( } } if (!is_ready) { - ALOGV("%s: Not all AutoCal Metadata is ready.", __FUNCTION__); + ALOGV("%s: Not all AutoCal Metadata is ready for frame %u.", __FUNCTION__, + frame_number); return OK; } } @@ -458,6 +465,7 @@ status_t RgbirdResultRequestProcessor::VerifyAndSubmitDepthRequest( __FUNCTION__); return UNKNOWN_ERROR; } + depth_requests_.erase(frame_number); return OK; } @@ -477,10 +485,19 @@ status_t RgbirdResultRequestProcessor::TrySubmitDepthProcessBlockRequest( IsAutocalRequest(frame_number))) { std::lock_guard<std::mutex> lock(depth_requests_mutex_); + // In case depth request is flushed if (depth_requests_.find(frame_number) == depth_requests_.end()) { - ALOGE("%s: Can not find depth request with frame number %u", + ALOGV("%s: Can not find depth request with frame number %u", __FUNCTION__, frame_number); - return UNKNOWN_ERROR; + status_t res = + internal_stream_manager_->ReturnStreamBuffer(output_buffer); + if (res != OK) { + ALOGW( + "%s: Failed to return internal buffer for flushed depth request" + " %u", + __FUNCTION__, frame_number); + } + continue; } // If input_buffer_metadata is not empty, the RGB pipeline result metadata @@ -537,6 +554,7 @@ status_t RgbirdResultRequestProcessor::TrySubmitDepthProcessBlockRequest( if (result->result_metadata != nullptr && request_id == kRgbCameraId) { std::lock_guard<std::mutex> lock(depth_requests_mutex_); + // In case a depth request is flushed if (depth_requests_.find(frame_number) == depth_requests_.end()) { ALOGV("%s No depth request for Autocal", __FUNCTION__); return OK; @@ -786,15 +804,72 @@ status_t RgbirdResultRequestProcessor::ProcessRequest( status_t RgbirdResultRequestProcessor::Flush() { ATRACE_CALL(); - // TODO(b/127322570): Implement this method. + std::lock_guard<std::mutex> lock(depth_process_block_lock_); if (depth_process_block_ == nullptr) { - ALOGE("%s: depth_process_block_ is null.", __FUNCTION__); - return BAD_VALUE; + ALOGW("%s: depth_process_block_ is null.", __FUNCTION__); + return OK; } return depth_process_block_->Flush(); } +status_t RgbirdResultRequestProcessor::FlushPendingRequests() { + ATRACE_CALL(); + + std::lock_guard<std::mutex> lock(callback_lock_); + if (notify_ == nullptr) { + ALOGE("%s: notify_ is nullptr. Dropping a message.", __FUNCTION__); + return OK; + } + + if (process_capture_result_ == nullptr) { + ALOGE("%s: process_capture_result_ is nullptr. Dropping a result.", + __FUNCTION__); + return OK; + } + + std::lock_guard<std::mutex> requests_lock(depth_requests_mutex_); + for (auto& [frame_number, capture_request] : depth_requests_) { + // Returns all internal stream buffers + for (auto& input_buffer : capture_request->input_buffers) { + if (input_buffer.stream_id != kInvalidStreamId) { + status_t res = + internal_stream_manager_->ReturnStreamBuffer(input_buffer); + if (res != OK) { + ALOGW("%s: Failed to return internal buffer for depth request %d", + __FUNCTION__, frame_number); + } + } + } + + // Notify buffer error for the depth stream output buffer + const NotifyMessage message = { + .type = MessageType::kError, + .message.error = {.frame_number = frame_number, + .error_stream_id = depth_stream_id_, + .error_code = ErrorCode::kErrorBuffer}}; + notify_(message); + + // Return output buffer for the depth stream + auto result = std::make_unique<CaptureResult>(); + result->frame_number = frame_number; + for (auto& output_buffer : capture_request->output_buffers) { + if (output_buffer.stream_id == depth_stream_id_) { + result->output_buffers.push_back(output_buffer); + auto& buffer = result->output_buffers.back(); + buffer.status = BufferStatus::kError; + buffer.acquire_fence = nullptr; + buffer.release_fence = nullptr; + break; + } + } + process_capture_result_(std::move(result)); + } + depth_requests_.clear(); + ALOGI("%s: Flushing depth requests done. ", __FUNCTION__); + return OK; +} + } // namespace google_camera_hal } // namespace android diff --git a/common/hal/google_camera_hal/rgbird_result_request_processor.h b/common/hal/google_camera_hal/rgbird_result_request_processor.h index b494fef..0c35d28 100644 --- a/common/hal/google_camera_hal/rgbird_result_request_processor.h +++ b/common/hal/google_camera_hal/rgbird_result_request_processor.h @@ -63,6 +63,8 @@ class RgbirdResultRequestProcessor : public ResultProcessor, void ProcessResult(ProcessBlockResult block_result) override; void Notify(const ProcessBlockNotifyMessage& block_message) override; + + status_t FlushPendingRequests() override; // Override functions of ResultProcessor end. // Override functions of RequestProcessor start. diff --git a/common/hal/tests/mock_result_processor.h b/common/hal/tests/mock_result_processor.h index 1dba1e3..fdf36cf 100644 --- a/common/hal/tests/mock_result_processor.h +++ b/common/hal/tests/mock_result_processor.h @@ -38,6 +38,8 @@ class MockResultProcessor : public ResultProcessor { MOCK_METHOD1(ProcessResult, void(ProcessBlockResult result)); MOCK_METHOD1(Notify, void(const ProcessBlockNotifyMessage& message)); + + MOCK_METHOD0(FlushPendingRequests, status_t()); }; } // namespace google_camera_hal |