[v4,4/7] android: Add CameraDevice::sendCaptureResult()
diff mbox series

Message ID 20241210142557.2886315-5-chenghaoyang@chromium.org
State New
Headers show
Series
  • Refactor Android HAL before supporting partial result
Related show

Commit Message

Cheng-Hao Yang Dec. 10, 2024, 2:23 p.m. UTC
The new function is separated from sendCaptureResults(), which allows
other functions to send a result out of order, like aborting. It'll be
updated in the upcoming patch, when the usage of error result is
separated.

This function also allows the upcoming partial results to be sent back
to the application without waiting for the requests.

Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>
Co-developed-by: Harvey Yang <chenghaoyang@chromium.org>
Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/android/camera_device.cpp | 57 ++++++++++++++++++-----------------
 src/android/camera_device.h   |  1 +
 2 files changed, 31 insertions(+), 27 deletions(-)

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 6bc19a74a..f3f570544 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -1323,42 +1323,45 @@  void CameraDevice::sendCaptureResults()
 		auto descriptor = std::move(descriptors_.front());
 		descriptors_.pop();
 
-		camera3_capture_result_t captureResult = {};
+		sendCaptureResult(descriptor.get());
+	}
+}
 
-		captureResult.frame_number = descriptor->frameNumber_;
+void CameraDevice::sendCaptureResult(Camera3RequestDescriptor *request) const
+{
+	std::vector<camera3_stream_buffer_t> resultBuffers;
+	resultBuffers.reserve(request->buffers_.size());
 
-		if (descriptor->resultMetadata_)
-			captureResult.result =
-				descriptor->resultMetadata_->getMetadata();
+	for (auto &buffer : request->buffers_) {
+		camera3_buffer_status status = CAMERA3_BUFFER_STATUS_ERROR;
 
-		std::vector<camera3_stream_buffer_t> resultBuffers;
-		resultBuffers.reserve(descriptor->buffers_.size());
+		if (buffer.status == StreamBuffer::Status::Success)
+			status = CAMERA3_BUFFER_STATUS_OK;
 
-		for (auto &buffer : descriptor->buffers_) {
-			camera3_buffer_status status = CAMERA3_BUFFER_STATUS_ERROR;
+		/*
+		 * Pass the buffer fence back to the camera framework as
+		 * a release fence. This instructs the framework to wait
+		 * on the acquire fence in case we haven't done so
+		 * ourselves for any reason.
+		 */
+		resultBuffers.push_back({ buffer.stream->camera3Stream(),
+					  buffer.camera3Buffer, status,
+					  -1, buffer.fence.release() });
+	}
 
-			if (buffer.status == StreamBuffer::Status::Success)
-				status = CAMERA3_BUFFER_STATUS_OK;
+	camera3_capture_result_t captureResult = {};
 
-			/*
-			 * Pass the buffer fence back to the camera framework as
-			 * a release fence. This instructs the framework to wait
-			 * on the acquire fence in case we haven't done so
-			 * ourselves for any reason.
-			 */
-			resultBuffers.push_back({ buffer.stream->camera3Stream(),
-						  buffer.camera3Buffer, status,
-						  -1, buffer.fence.release() });
-		}
+	captureResult.frame_number = request->frameNumber_;
+	captureResult.num_output_buffers = resultBuffers.size();
+	captureResult.output_buffers = resultBuffers.data();
 
-		captureResult.num_output_buffers = resultBuffers.size();
-		captureResult.output_buffers = resultBuffers.data();
+	if (request->status_ == Camera3RequestDescriptor::Status::Success)
+		captureResult.partial_result = 1;
 
-		if (descriptor->status_ == Camera3RequestDescriptor::Status::Success)
-			captureResult.partial_result = 1;
+	if (request->resultMetadata_)
+		captureResult.result = request->resultMetadata_->getMetadata();
 
-		callbacks_->process_capture_result(callbacks_, &captureResult);
-	}
+	callbacks_->process_capture_result(callbacks_, &captureResult);
 }
 
 void CameraDevice::setBufferStatus(StreamBuffer &streamBuffer,
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index c92ee1aa4..699aa8f17 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -97,6 +97,7 @@  private:
 	void completeDescriptor(Camera3RequestDescriptor *descriptor)
 		LIBCAMERA_TSA_EXCLUDES(descriptorsMutex_);
 	void sendCaptureResults() LIBCAMERA_TSA_REQUIRES(descriptorsMutex_);
+	void sendCaptureResult(Camera3RequestDescriptor *request) const;
 	void setBufferStatus(StreamBuffer &buffer,
 			     StreamBuffer::Status status);
 	std::unique_ptr<CameraMetadata> getResultMetadata(