Simplify realtime ZSL request/result processor logic
Only ZslSnapshotCaptureSession uses RealtimeZslRequestProcessor &
RealtimeZslResultProcessor. The only usage is YUV_420_888.
Bug: 342479309
Test: atest google_camera_hal_tests, cts
Change-Id: I4294e078321da6a20a86ad9a21de3fd48d58c796
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 2123f44..6ddc47c 100644
--- a/common/hal/google_camera_hal/realtime_zsl_request_processor.cc
+++ b/common/hal/google_camera_hal/realtime_zsl_request_processor.cc
@@ -126,9 +126,13 @@
ALOGE("%s: device_session_hwl is nullptr", __FUNCTION__);
return nullptr;
}
+ if (pixel_format != android_pixel_format_t::HAL_PIXEL_FORMAT_YCBCR_420_888) {
+ ALOGE("%s: only YCBCR_420_888 is supported for YUV ZSL", __FUNCTION__);
+ return nullptr;
+ }
auto request_processor = std::unique_ptr<RealtimeZslRequestProcessor>(
- new RealtimeZslRequestProcessor(pixel_format, device_session_hwl));
+ new RealtimeZslRequestProcessor(device_session_hwl));
if (request_processor == nullptr) {
ALOGE("%s: Creating RealtimeZslRequestProcessor failed.", __FUNCTION__);
return nullptr;
@@ -187,21 +191,19 @@
// For YUV ZSL, we will use the JPEG size for ZSL buffer size. We already
// checked the size is supported in capture session.
- if (pixel_format_ == android_pixel_format_t::HAL_PIXEL_FORMAT_YCBCR_420_888) {
- for (const auto& stream : stream_config.streams) {
- if (utils::IsSoftwareDenoiseEligibleSnapshotStream(stream)) {
- if (SelectWidthAndHeight(stream.width, stream.height,
- *device_session_hwl_, active_array_width_,
- active_array_height_) != OK) {
- ALOGE("%s: failed to select ZSL YUV buffer width and height",
- __FUNCTION__);
- return BAD_VALUE;
- }
- ALOGI("%s, Snapshot size is (%d x %d), selected size is (%d x %d)",
- __FUNCTION__, stream.width, stream.height, active_array_width_,
- active_array_height_);
- break;
+ for (const auto& stream : stream_config.streams) {
+ if (utils::IsSoftwareDenoiseEligibleSnapshotStream(stream)) {
+ if (SelectWidthAndHeight(stream.width, stream.height,
+ *device_session_hwl_, active_array_width_,
+ active_array_height_) != OK) {
+ ALOGE("%s: failed to select ZSL YUV buffer width and height",
+ __FUNCTION__);
+ return BAD_VALUE;
}
+ ALOGI("%s, Snapshot size is (%d x %d), selected size is (%d x %d)",
+ __FUNCTION__, stream.width, stream.height, active_array_width_,
+ active_array_height_);
+ break;
}
}
@@ -210,7 +212,7 @@
stream_to_add.stream_type = StreamType::kOutput;
stream_to_add.width = active_array_width_;
stream_to_add.height = active_array_height_;
- stream_to_add.format = pixel_format_;
+ stream_to_add.format = HAL_PIXEL_FORMAT_YCBCR_420_888;
stream_to_add.usage = 0;
stream_to_add.rotation = StreamRotation::kRotation0;
stream_to_add.data_space = HAL_DATASPACE_ARBITRARY;
@@ -218,8 +220,7 @@
// we will add the new stream as physical stream. As we support physical
// streams only or logical streams only combination. We can check the stream
// type of the first stream in the list.
- if (pixel_format_ == android_pixel_format_t::HAL_PIXEL_FORMAT_YCBCR_420_888 &&
- stream_config.streams[0].is_physical_camera_stream) {
+ if (stream_config.streams[0].is_physical_camera_stream) {
stream_to_add.is_physical_camera_stream = true;
stream_to_add.physical_camera_id =
stream_config.streams[0].physical_camera_id;
@@ -304,23 +305,21 @@
HalCameraMetadata::Clone(physical_metadata.get());
}
- if (pixel_format_ == android_pixel_format_t::HAL_PIXEL_FORMAT_YCBCR_420_888) {
- // Get one bffer from internal stream manager
- StreamBuffer buffer = {};
- status_t result;
- if (preview_intent_seen_) {
- result = internal_stream_manager_->GetStreamBuffer(stream_id_, &buffer);
- if (result != OK) {
- ALOGE("%s: frame:%d GetStreamBuffer failed.", __FUNCTION__,
- request.frame_number);
- return UNKNOWN_ERROR;
- }
+ // Get one buffer from internal stream manager
+ StreamBuffer buffer = {};
+ status_t result;
+ if (preview_intent_seen_) {
+ result = internal_stream_manager_->GetStreamBuffer(stream_id_, &buffer);
+ if (result != OK) {
+ ALOGE("%s: frame:%d GetStreamBuffer failed.", __FUNCTION__,
+ request.frame_number);
+ return UNKNOWN_ERROR;
}
+ }
- // Add output to capture request
- if (preview_intent_seen_) {
- block_request.output_buffers.push_back(buffer);
- }
+ // Add output to capture request
+ if (preview_intent_seen_) {
+ block_request.output_buffers.push_back(buffer);
}
std::vector<ProcessBlockRequest> block_requests(1);
diff --git a/common/hal/google_camera_hal/realtime_zsl_request_processor.h b/common/hal/google_camera_hal/realtime_zsl_request_processor.h
index 8f8f8ee..63a60d4 100644
--- a/common/hal/google_camera_hal/realtime_zsl_request_processor.h
+++ b/common/hal/google_camera_hal/realtime_zsl_request_processor.h
@@ -28,7 +28,7 @@
namespace google_camera_hal {
// RealtimeZslRequestProcessor implements a RequestProcessor that adds
-// internal raw stream to request and forwards the request to its ProcessBlock.
+// internal stream to request and forwards the request to its ProcessBlock.
class RealtimeZslRequestProcessor : public RequestProcessor {
public:
// device_session_hwl is owned by the caller and must be valid during the
@@ -41,7 +41,7 @@
// Override functions of RequestProcessor start.
// RealtimeZslRequestProcessor will configure all streams in stream_config.
- // And register one internal raw stream
+ // And register one internal stream
status_t ConfigureStreams(
InternalStreamManager* internal_stream_manager,
const StreamConfiguration& stream_config,
@@ -50,7 +50,7 @@
// Set the realtime process block for sending requests later.
status_t SetProcessBlock(std::unique_ptr<ProcessBlock> process_block) override;
- // Add one additional RAW output to capture request
+ // Add one additional output to capture request
// And forwards the capture request to realtime process
status_t ProcessRequest(const CaptureRequest& request) override;
@@ -61,9 +61,8 @@
// Override functions of RequestProcessor end.
protected:
- RealtimeZslRequestProcessor(android_pixel_format_t pixel_format,
- CameraDeviceSessionHwl* device_session_hwl)
- : pixel_format_(pixel_format), device_session_hwl_(device_session_hwl) {};
+ RealtimeZslRequestProcessor(CameraDeviceSessionHwl* device_session_hwl)
+ : device_session_hwl_(device_session_hwl) {};
private:
status_t Initialize(CameraDeviceSessionHwl* device_session_hwl);
@@ -73,7 +72,6 @@
std::unique_ptr<ProcessBlock> process_block_;
InternalStreamManager* internal_stream_manager_ = nullptr;
- android_pixel_format_t pixel_format_;
CameraDeviceSessionHwl* device_session_hwl_ = nullptr;
bool preview_intent_seen_ = false;
int32_t stream_id_ = -1;
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 2735920..9534b05 100644
--- a/common/hal/google_camera_hal/realtime_zsl_result_processor.cc
+++ b/common/hal/google_camera_hal/realtime_zsl_result_processor.cc
@@ -37,10 +37,14 @@
ALOGE("%s: internal_stream_manager is nullptr.", __FUNCTION__);
return nullptr;
}
+ if (pixel_format != android_pixel_format_t::HAL_PIXEL_FORMAT_YCBCR_420_888) {
+ ALOGE("%s: only YCBCR_420_888 is supported for YUV ZSL", __FUNCTION__);
+ 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<RealtimeZslResultProcessor>(new RealtimeZslResultProcessor(
+ internal_stream_manager, stream_id, partial_result_count));
if (result_processor == nullptr) {
ALOGE("%s: Creating RealtimeZslResultProcessor failed.", __FUNCTION__);
return nullptr;
@@ -51,10 +55,9 @@
RealtimeZslResultProcessor::RealtimeZslResultProcessor(
InternalStreamManager* internal_stream_manager, int32_t stream_id,
- android_pixel_format_t pixel_format, uint32_t partial_result_count) {
+ uint32_t partial_result_count) {
internal_stream_manager_ = internal_stream_manager;
stream_id_ = stream_id;
- pixel_format_ = pixel_format;
partial_result_count_ = partial_result_count;
}
@@ -66,88 +69,6 @@
notify_ = notify;
}
-void RealtimeZslResultProcessor::SaveLsForHdrplus(const CaptureRequest& request) {
- if (request.settings != nullptr) {
- uint8_t lens_shading_map_mode;
- status_t res =
- hal_utils::GetLensShadingMapMode(request, &lens_shading_map_mode);
- if (res == OK) {
- current_lens_shading_map_mode_ = lens_shading_map_mode;
- }
- }
-
- {
- std::lock_guard<std::mutex> lock(lens_shading_lock_);
- requested_lens_shading_map_modes_.emplace(request.frame_number,
- current_lens_shading_map_mode_);
- }
-}
-
-status_t RealtimeZslResultProcessor::HandleLsResultForHdrplus(
- uint32_t frameNumber, HalCameraMetadata* metadata) {
- if (metadata == nullptr) {
- ALOGE("%s: metadata is nullptr", __FUNCTION__);
- return BAD_VALUE;
- }
- std::lock_guard<std::mutex> lock(lens_shading_lock_);
- auto iter = requested_lens_shading_map_modes_.find(frameNumber);
- if (iter == requested_lens_shading_map_modes_.end()) {
- ALOGW("%s: can't find frame (%d)", __FUNCTION__, frameNumber);
- return OK;
- }
-
- if (iter->second == ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF) {
- status_t res = hal_utils::RemoveLsInfoFromResult(metadata);
- if (res != OK) {
- ALOGW("%s: RemoveLsInfoFromResult fail", __FUNCTION__);
- }
- }
- requested_lens_shading_map_modes_.erase(iter);
-
- return OK;
-}
-
-void RealtimeZslResultProcessor::SaveFdForHdrplus(const CaptureRequest& request) {
- // Enable face detect mode for internal use
- if (request.settings != nullptr) {
- uint8_t fd_mode;
- status_t res = hal_utils::GetFdMode(request, &fd_mode);
- if (res == OK) {
- current_face_detect_mode_ = fd_mode;
- }
- }
-
- {
- std::lock_guard<std::mutex> lock(face_detect_lock_);
- requested_face_detect_modes_.emplace(request.frame_number,
- current_face_detect_mode_);
- }
-}
-
-status_t RealtimeZslResultProcessor::HandleFdResultForHdrplus(
- uint32_t frameNumber, HalCameraMetadata* metadata) {
- if (metadata == nullptr) {
- ALOGE("%s: metadata is nullptr", __FUNCTION__);
- return BAD_VALUE;
- }
- std::lock_guard<std::mutex> lock(face_detect_lock_);
- auto iter = requested_face_detect_modes_.find(frameNumber);
- if (iter == requested_face_detect_modes_.end()) {
- ALOGW("%s: can't find frame (%d)", __FUNCTION__, frameNumber);
- return OK;
- }
-
- if (iter->second == ANDROID_STATISTICS_FACE_DETECT_MODE_OFF) {
- status_t res = hal_utils::RemoveFdInfoFromResult(metadata);
- if (res != OK) {
- ALOGW("%s: RestoreFdMetadataForHdrplus fail", __FUNCTION__);
- }
- }
- requested_face_detect_modes_.erase(iter);
-
- return OK;
-}
-
status_t RealtimeZslResultProcessor::AddPendingRequests(
const std::vector<ProcessBlockRequest>& process_block_requests,
const CaptureRequest& remaining_session_request) {
@@ -160,11 +81,6 @@
return BAD_VALUE;
}
- if (pixel_format_ == HAL_PIXEL_FORMAT_RAW10) {
- SaveFdForHdrplus(remaining_session_request);
- SaveLsForHdrplus(remaining_session_request);
- }
-
return OK;
}
@@ -183,8 +99,8 @@
return;
}
- // Return filled raw buffer to internal stream manager
- // And remove raw buffer from result
+ // Return filled buffer to internal stream manager
+ // And remove buffer from result
bool returned_output = false;
status_t res;
std::vector<StreamBuffer> modified_output_buffers;
@@ -224,28 +140,10 @@
ALOGW("%s: SetEnableZslMetadata (%d) fail", __FUNCTION__,
result->frame_number);
}
-
- if (pixel_format_ == HAL_PIXEL_FORMAT_RAW10) {
- res = HandleFdResultForHdrplus(result->frame_number,
- result->result_metadata.get());
- if (res != OK) {
- ALOGE("%s: HandleFdResultForHdrplus(%d) fail", __FUNCTION__,
- result->frame_number);
- return;
- }
-
- res = HandleLsResultForHdrplus(result->frame_number,
- result->result_metadata.get());
- if (res != OK) {
- ALOGE("%s: HandleLsResultForHdrplus(%d) fail", __FUNCTION__,
- result->frame_number);
- return;
- }
- }
}
}
- // Don't send result to framework if only internal raw callback
+ // Don't send result to framework if only internal callback
if (returned_output && result->result_metadata == nullptr &&
result->output_buffers.size() == 0) {
return;
@@ -279,4 +177,4 @@
}
} // namespace google_camera_hal
-} // namespace android
\ No newline at end of file
+} // namespace android
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 7ab5490..fd63ec9 100644
--- a/common/hal/google_camera_hal/realtime_zsl_result_processor.h
+++ b/common/hal/google_camera_hal/realtime_zsl_result_processor.h
@@ -26,7 +26,7 @@
namespace google_camera_hal {
// RealtimeZslResultProcessor implements a ResultProcessor that return
-// filled raw buffer and metadata to internal stream manager.
+// filled buffer and metadata to internal stream manager.
class RealtimeZslResultProcessor : public ResultProcessor {
public:
static std::unique_ptr<RealtimeZslResultProcessor> Create(
@@ -44,8 +44,8 @@
const std::vector<ProcessBlockRequest>& process_block_requests,
const CaptureRequest& remaining_session_request) override;
- // Return filled raw buffer and metadata to internal stream manager
- // and forwards the results without raw buffer to its callback functions.
+ // Return filled buffer and metadata to internal stream manager
+ // and forwards the results without buffer to its callback functions.
void ProcessResult(ProcessBlockResult block_result) override;
void Notify(const ProcessBlockNotifyMessage& block_message) override;
@@ -55,9 +55,7 @@
protected:
RealtimeZslResultProcessor(InternalStreamManager* internal_stream_manager,
- int32_t stream_id,
- android_pixel_format_t pixel_format,
- uint32_t partial_result_count);
+ int32_t stream_id, uint32_t partial_result_count);
InternalStreamManager* internal_stream_manager_;
int32_t stream_id_ = -1;
@@ -71,38 +69,6 @@
NotifyFunc notify_;
private:
- // Save face detect mode for HDR+
- void SaveFdForHdrplus(const CaptureRequest& request);
- // Handle face detect metadata from result for HDR+
- status_t HandleFdResultForHdrplus(uint32_t frameNumber,
- HalCameraMetadata* metadata);
- // Save lens shading map mode for HDR+
- void SaveLsForHdrplus(const CaptureRequest& request);
- // Handle Lens shading metadata from result for HDR+
- status_t HandleLsResultForHdrplus(uint32_t frameNumber,
- HalCameraMetadata* metadata);
-
- android_pixel_format_t pixel_format_;
-
- // Current face detect mode set by framework.
- uint8_t current_face_detect_mode_ = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF;
-
- std::mutex face_detect_lock_;
- // Map from frame number to face detect mode requested for that frame by
- // framework. And requested_face_detect_modes_ is protected by
- // face_detect_lock_
- std::unordered_map<uint32_t, uint8_t> requested_face_detect_modes_;
-
- // Current lens shading map mode set by framework.
- uint8_t current_lens_shading_map_mode_ =
- ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF;
-
- std::mutex lens_shading_lock_;
- // Map from frame number to lens shading map mode requested for that frame
- // by framework. And requested_lens_shading_map_modes_ is protected by
- // lens_shading_lock_
- std::unordered_map<uint32_t, uint8_t> requested_lens_shading_map_modes_;
-
std::shared_mutex process_block_shared_lock_;
};
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 b76bfa6..e6dc92b 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
@@ -51,10 +51,14 @@
ALOGE("%s: internal_stream_manager is nullptr.", __FUNCTION__);
return nullptr;
}
+ if (pixel_format != android_pixel_format_t::HAL_PIXEL_FORMAT_YCBCR_420_888) {
+ ALOGE("%s: only YCBCR_420_888 is supported for YUV ZSL", __FUNCTION__);
+ return nullptr;
+ }
auto result_processor = std::unique_ptr<RealtimeZslResultRequestProcessor>(
new RealtimeZslResultRequestProcessor(internal_stream_manager, stream_id,
- pixel_format, partial_result_count));
+ partial_result_count));
if (result_processor == nullptr) {
ALOGE("%s: Creating RealtimeZslResultRequestProcessor failed.",
__FUNCTION__);
@@ -66,9 +70,9 @@
RealtimeZslResultRequestProcessor::RealtimeZslResultRequestProcessor(
InternalStreamManager* internal_stream_manager, int32_t stream_id,
- android_pixel_format_t pixel_format, uint32_t partial_result_count)
+ uint32_t partial_result_count)
: RealtimeZslResultProcessor(internal_stream_manager, stream_id,
- pixel_format, partial_result_count) {
+ partial_result_count) {
}
void RealtimeZslResultRequestProcessor::UpdateOutputBufferCount(
@@ -117,8 +121,8 @@
pending_request.capture_request->frame_number = result->frame_number;
}
- // Return filled raw buffer to internal stream manager
- // And remove raw buffer from result
+ // Return filled buffer to internal stream manager
+ // And remove buffer from result
status_t res;
std::vector<StreamBuffer> modified_output_buffers;
for (uint32_t i = 0; i < result->output_buffers.size(); i++) {
@@ -424,7 +428,7 @@
pending_frame_number_to_requests_.erase(result->frame_number);
}
- // Don't send result to framework if only internal raw callback
+ // Don't send result to framework if only internal callback
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/realtime_zsl_result_request_processor.h b/common/hal/google_camera_hal/realtime_zsl_result_request_processor.h
index 2ae631e..33436b9 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
@@ -31,7 +31,7 @@
namespace google_camera_hal {
// RealtimeZslResultRequestProcessor implements a RealtimeZslResultProcessor
-// that return filled raw buffer and metadata to internal stream manager. It
+// that return filled buffer and metadata to internal stream manager. It
// also implements a RequestProcess to forward the results.
class RealtimeZslResultRequestProcessor : public RealtimeZslResultProcessor,
RequestProcessor {
@@ -70,7 +70,7 @@
protected:
RealtimeZslResultRequestProcessor(
InternalStreamManager* internal_stream_manager, int32_t stream_id,
- android_pixel_format_t pixel_format, uint32_t partial_result_count);
+ uint32_t partial_result_count);
private:
std::shared_mutex process_block_shared_lock_;
@@ -84,7 +84,7 @@
uint32_t partial_results_received = 0;
bool zsl_buffer_received = false;
int framework_buffer_count = INT_MAX;
- // Whether there were filled raw buffers that have been returned to internal
+ // Whether there were filled buffers that have been returned to internal
// stream manager.
bool has_returned_output_to_internal_stream_manager = false;
};