[PATCH v2 3/9] android: Set StreamBuffer::srcBuffer in CameraDevice::processCaptureRequest

Harvey Yang chenghaoyang at chromium.org
Wed Nov 27 10:25:53 CET 2024


StreamBuffer::srcBuffer was set right before being processed, while it
was already determined when being constructed. This patch sets the value
in CameraDevice::processCaptureRequest.

Signed-off-by: Han-Lin Chen <hanlinchen at chromium.org>
Co-developed-by: Harvey Yang <chenghaoyang at chromium.org>
Signed-off-by: Harvey Yang <chenghaoyang at chromium.org>
---
 src/android/camera_device.cpp | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 4e3bdc9cc..11613fac9 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -967,9 +967,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
 	 * to a libcamera stream. Streams of type Mapped will be handled later.
 	 *
 	 * Collect the CameraStream associated to each requested capture stream.
-	 * Since requestedStreams is an std:set<>, no duplications can happen.
+	 * Since requestedStreams is an std:map<>, no duplications can happen.
 	 */
-	std::set<CameraStream *> requestedStreams;
+	std::map<CameraStream *, libcamera::FrameBuffer *> requestedBuffers;
 	for (const auto &[i, buffer] : utils::enumerate(descriptor->buffers_)) {
 		CameraStream *cameraStream = buffer.stream;
 		camera3_stream_t *camera3Stream = cameraStream->camera3Stream();
@@ -1008,6 +1008,8 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
 						  cameraStream->configuration().size);
 			frameBuffer = buffer.frameBuffer.get();
 			acquireFence = std::move(buffer.fence);
+
+			requestedBuffers[cameraStream] = frameBuffer;
 			LOG(HAL, Debug) << ss.str() << " (direct)";
 			break;
 
@@ -1021,6 +1023,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
 			 */
 			frameBuffer = cameraStream->getBuffer();
 			buffer.internalBuffer = frameBuffer;
+			buffer.srcBuffer = frameBuffer;
+
+			requestedBuffers[cameraStream] = frameBuffer;
 			LOG(HAL, Debug) << ss.str() << " (internal)";
 
 			descriptor->pendingStreamsToProcess_.insert(
@@ -1036,8 +1041,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
 		auto fence = std::make_unique<Fence>(std::move(acquireFence));
 		descriptor->request_->addBuffer(cameraStream->stream(),
 						frameBuffer, std::move(fence));
-
-		requestedStreams.insert(cameraStream);
 	}
 
 	/*
@@ -1068,8 +1071,19 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
 		 */
 		CameraStream *sourceStream = cameraStream->sourceStream();
 		ASSERT(sourceStream);
-		if (requestedStreams.find(sourceStream) != requestedStreams.end())
+		ASSERT(sourceStream->type() == CameraStream::Type::Direct);
+
+		/*
+		 * If the buffer for the source stream has been requested as
+		 * Direct, use its framebuffer as the source buffer for
+		 * post-processing. No need to recycle the buffer since it's
+		 * owned by Android.
+		 */
+		auto iterDirectBuffer = requestedBuffers.find(sourceStream);
+		if (iterDirectBuffer != requestedBuffers.end()) {
+			buffer.srcBuffer = iterDirectBuffer->second;
 			continue;
+		}
 
 		/*
 		 * If that's not the case, we need to add a buffer to the request
@@ -1077,11 +1091,12 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
 		 */
 		FrameBuffer *frameBuffer = cameraStream->getBuffer();
 		buffer.internalBuffer = frameBuffer;
+		buffer.srcBuffer = frameBuffer;
 
 		descriptor->request_->addBuffer(sourceStream->stream(),
 						frameBuffer, nullptr);
 
-		requestedStreams.insert(sourceStream);
+		requestedBuffers[sourceStream] = frameBuffer;
 	}
 
 	/*
@@ -1236,8 +1251,6 @@ void CameraDevice::requestComplete(Request *request)
 			continue;
 		}
 
-		buffer->srcBuffer = src;
-
 		++iter;
 		int ret = stream->process(buffer);
 		if (ret) {
-- 
2.47.0.338.g60cca15819-goog



More information about the libcamera-devel mailing list