[libcamera-devel] [PATCH v4 2/7] android: camera_stream: Plumb process() with Camera3RequestDescriptor

Umang Jain umang.jain at ideasonboard.com
Mon Oct 11 09:35:00 CEST 2021


Data (or broader context) required for post processing of a camera request
is saved via Camera3RequestDescriptor. Instead of passing individual
arguments to CameraStream::process(), pass the Camera3RequestDescriptor
pointer to it. All the arguments necessary to run the post-processor can
be accessed from the descriptor.

In subsequent commits, we will prepare the post-processor to run
asynchronously. Hence, it will require the Camera3RequestDescriptor
pointer to be emitted back in the post-processing completion handler
to finally complete the request (i.e. sending the capture results back
to the framework).

Store result metadata which is sent as capture results into the
Camera3RequestDescriptor. This is will remove the need to send the
result metadata pointer separately to CameraStream::process().
In the subsequent commit, a Camera3RequestDescriptor pointer
will be passed to CameraStream::process() and the result metadata
can be directly accessed from there.

Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Reviewed-by: Hirokazu Honda <hiroh at chromium.org>
---
 src/android/camera_device.cpp            | 9 +++++----
 src/android/camera_device.h              | 1 +
 src/android/camera_stream.cpp            | 5 ++---
 src/android/camera_stream.h              | 5 +++--
 src/android/jpeg/post_processor_jpeg.cpp | 5 +++--
 src/android/jpeg/post_processor_jpeg.h   | 3 +--
 src/android/post_processor.h             | 5 +++--
 src/android/yuv/post_processor_yuv.cpp   | 3 +--
 src/android/yuv/post_processor_yuv.h     | 3 +--
 9 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 48a96d0c..b52bdc8f 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -1207,6 +1207,8 @@ void CameraDevice::requestComplete(Request *request)
 		resultMetadata = std::make_unique<CameraMetadata>(0, 0);
 	}
 
+	descriptor->resultMetadata_ = std::move(resultMetadata);
+
 	/* Handle post-processing. */
 	for (camera3_stream_buffer_t &buffer : descriptor->buffers_) {
 		CameraStream *cameraStream =
@@ -1224,9 +1226,8 @@ void CameraDevice::requestComplete(Request *request)
 			continue;
 		}
 
-		int ret = cameraStream->process(*src, buffer,
-						descriptor->settings_,
-						resultMetadata.get());
+		int ret = cameraStream->process(*src, buffer, descriptor);
+
 		/*
 		 * Return the FrameBuffer to the CameraStream now that we're
 		 * done processing it.
@@ -1241,7 +1242,7 @@ void CameraDevice::requestComplete(Request *request)
 		}
 	}
 
-	captureResult.result = resultMetadata->get();
+	captureResult.result = descriptor->resultMetadata_->get();
 	descriptor->status_ = Camera3RequestDescriptor::Status::Success;
 	sendCaptureResults();
 }
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index 26d1c6de..3da8dffa 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -55,6 +55,7 @@ struct Camera3RequestDescriptor {
 	std::vector<std::unique_ptr<libcamera::FrameBuffer>> frameBuffers_;
 	CameraMetadata settings_;
 	std::unique_ptr<CaptureRequest> request_;
+	std::unique_ptr<CameraMetadata> resultMetadata_;
 
 	camera3_capture_result_t captureResult_ = {};
 	Status status_ = Status::Pending;
diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp
index 3b96d2e9..8f47e4d8 100644
--- a/src/android/camera_stream.cpp
+++ b/src/android/camera_stream.cpp
@@ -144,8 +144,7 @@ int CameraStream::waitFence(int fence)
 
 int CameraStream::process(const FrameBuffer &source,
 			  camera3_stream_buffer_t &camera3Dest,
-			  const CameraMetadata &requestMetadata,
-			  CameraMetadata *resultMetadata)
+			  Camera3RequestDescriptor *request)
 {
 	/* Handle waiting on fences on the destination buffer. */
 	int fence = camera3Dest.acquire_fence;
@@ -175,7 +174,7 @@ int CameraStream::process(const FrameBuffer &source,
 		return -EINVAL;
 	}
 
-	return postProcessor_->process(source, &dest, requestMetadata, resultMetadata);
+	return postProcessor_->process(source, &dest, request);
 }
 
 FrameBuffer *CameraStream::getBuffer()
diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h
index 03ecfa94..04cfd111 100644
--- a/src/android/camera_stream.h
+++ b/src/android/camera_stream.h
@@ -23,6 +23,8 @@ class CameraDevice;
 class CameraMetadata;
 class PostProcessor;
 
+struct Camera3RequestDescriptor;
+
 class CameraStream
 {
 public:
@@ -120,8 +122,7 @@ public:
 	int configure();
 	int process(const libcamera::FrameBuffer &source,
 		    camera3_stream_buffer_t &camera3Buffer,
-		    const CameraMetadata &requestMetadata,
-		    CameraMetadata *resultMetadata);
+		    Camera3RequestDescriptor *request);
 	libcamera::FrameBuffer *getBuffer();
 	void putBuffer(libcamera::FrameBuffer *buffer);
 
diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp
index f6d47f63..656c48b2 100644
--- a/src/android/jpeg/post_processor_jpeg.cpp
+++ b/src/android/jpeg/post_processor_jpeg.cpp
@@ -99,14 +99,15 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,
 
 int PostProcessorJpeg::process(const FrameBuffer &source,
 			       CameraBuffer *destination,
-			       const CameraMetadata &requestMetadata,
-			       CameraMetadata *resultMetadata)
+			       Camera3RequestDescriptor *request)
 {
 	if (!encoder_)
 		return 0;
 
 	ASSERT(destination->numPlanes() == 1);
 
+	const CameraMetadata &requestMetadata = request->settings_;
+	CameraMetadata *resultMetadata = request->resultMetadata_.get();
 	camera_metadata_ro_entry_t entry;
 	int ret;
 
diff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h
index 6fd31022..0184d77e 100644
--- a/src/android/jpeg/post_processor_jpeg.h
+++ b/src/android/jpeg/post_processor_jpeg.h
@@ -24,8 +24,7 @@ public:
 		      const libcamera::StreamConfiguration &outcfg) override;
 	int process(const libcamera::FrameBuffer &source,
 		    CameraBuffer *destination,
-		    const CameraMetadata &requestMetadata,
-		    CameraMetadata *resultMetadata) override;
+		    Camera3RequestDescriptor *request) override;
 
 private:
 	void generateThumbnail(const libcamera::FrameBuffer &source,
diff --git a/src/android/post_processor.h b/src/android/post_processor.h
index ab2b2c60..fa13c7e0 100644
--- a/src/android/post_processor.h
+++ b/src/android/post_processor.h
@@ -14,6 +14,8 @@
 
 class CameraMetadata;
 
+struct Camera3RequestDescriptor;
+
 class PostProcessor
 {
 public:
@@ -23,8 +25,7 @@ public:
 			      const libcamera::StreamConfiguration &outCfg) = 0;
 	virtual int process(const libcamera::FrameBuffer &source,
 			    CameraBuffer *destination,
-			    const CameraMetadata &requestMetadata,
-			    CameraMetadata *resultMetadata) = 0;
+			    Camera3RequestDescriptor *request) = 0;
 };
 
 #endif /* __ANDROID_POST_PROCESSOR_H__ */
diff --git a/src/android/yuv/post_processor_yuv.cpp b/src/android/yuv/post_processor_yuv.cpp
index 7b3b4960..8110a1f1 100644
--- a/src/android/yuv/post_processor_yuv.cpp
+++ b/src/android/yuv/post_processor_yuv.cpp
@@ -51,8 +51,7 @@ int PostProcessorYuv::configure(const StreamConfiguration &inCfg,
 
 int PostProcessorYuv::process(const FrameBuffer &source,
 			      CameraBuffer *destination,
-			      [[maybe_unused]] const CameraMetadata &requestMetadata,
-			      [[maybe_unused]] CameraMetadata *metadata)
+			      [[maybe_unused]] Camera3RequestDescriptor *request)
 {
 	if (!isValidBuffers(source, *destination))
 		return -EINVAL;
diff --git a/src/android/yuv/post_processor_yuv.h b/src/android/yuv/post_processor_yuv.h
index 12f7af07..a4e0ff5d 100644
--- a/src/android/yuv/post_processor_yuv.h
+++ b/src/android/yuv/post_processor_yuv.h
@@ -20,8 +20,7 @@ public:
 		      const libcamera::StreamConfiguration &outcfg) override;
 	int process(const libcamera::FrameBuffer &source,
 		    CameraBuffer *destination,
-		    const CameraMetadata &requestMetadata,
-		    CameraMetadata *metadata) override;
+		    Camera3RequestDescriptor *request) override;
 
 private:
 	bool isValidBuffers(const libcamera::FrameBuffer &source,
-- 
2.31.1



More information about the libcamera-devel mailing list