[libcamera-devel] [RFC PATCH 3/6] android: camera_stream: Pass post processor in configure()

Hirokazu Honda hiroh at chromium.org
Thu Feb 4 11:05:38 CET 2021


CameraStream creates PostProcessor in its constructor and
configures the PostProcessor() in its configure(). The
existing code hard-codes them for PostProcessorJpeg. It is
difficult to generalize the code for other PostProcessor.
A client of CameraStream should know what post processor
is needed and how to configure it. Therefore, this changes
CameraStream::configure() interface to take a post processor.
A client of CameraStream creates and configures a post
processor before calling configure().

Signed-off-by: Hirokazu Honda <hiroh at chromium.org>
---
 src/android/camera_device.cpp | 21 ++++++++++++++++++++-
 src/android/camera_stream.cpp | 31 ++++++++-----------------------
 src/android/camera_stream.h   |  2 +-
 3 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index a50b0ebf..752e17ba 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -8,6 +8,7 @@
 #include "camera_device.h"
 #include "camera_ops.h"
 #include "post_processor.h"
+#include "jpeg/post_processor_jpeg.h"

 #include <fstream>
 #include <sys/mman.h>
@@ -1613,7 +1614,25 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
 	 * the Android camera3_stream_t.
 	 */
 	for (CameraStream &cameraStream : streams_) {
-		ret = cameraStream.configure();
+		std::unique_ptr<PostProcessor> postProcessor;
+
+		if (cameraStream.type() == CameraStream::Type::Internal ||
+		    cameraStream.type() == CameraStream::Type::Mapped) {
+			postProcessor =
+				std::make_unique<PostProcessorJpeg>(this);
+
+			auto output = cameraStream.configuration();
+			output.pixelFormat = formats::MJPEG;
+			postProcessor->configure(cameraStream.configuration(),
+						 output);
+			if (ret) {
+				LOG(HAL, Error) << "Failed to configure "
+						<< "PostProcessorJpeg";
+				return ret;
+			}
+		}
+
+		ret = cameraStream.configure(std::move(postProcessor));
 		if (ret) {
 			LOG(HAL, Error) << "Failed to configure camera stream";
 			return ret;
diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp
index 611ec0d1..ed6c5265 100644
--- a/src/android/camera_stream.cpp
+++ b/src/android/camera_stream.cpp
@@ -9,7 +9,7 @@

 #include "camera_device.h"
 #include "camera_metadata.h"
-#include "jpeg/post_processor_jpeg.h"
+#include "post_processor.h"

 #include <libcamera/formats.h>

@@ -38,22 +38,13 @@ LOG_DECLARE_CATEGORY(HAL)
  * and buffer allocation.
  */

-CameraStream::CameraStream(CameraDevice *const cameraDevice, Type type,
-			   camera3_stream_t *camera3Stream, unsigned int index)
+CameraStream::CameraStream(CameraDevice *const cameraDevice,
+			   Type type, camera3_stream_t *camera3Stream,
+			   unsigned int index)
 	: cameraDevice_(cameraDevice),
-	  config_(cameraDevice->cameraConfiguration()), type_(type),
-	  camera3Stream_(camera3Stream), index_(index)
+	  config_(cameraDevice->cameraConfiguration()),
+ 	  type_(type), camera3Stream_(camera3Stream), index_(index)
 {
-	if (type_ == Type::Internal || type_ == Type::Mapped) {
-		/*
-		 * \todo There might be multiple post-processors. The logic
-		 * which should be instantiated here, is deferred for the
-		 * future. For now, we only have PostProcessorJpeg and that
-		 * is what we instantiate here.
-		 */
-		postProcessor_ = std::make_unique<PostProcessorJpeg>(cameraDevice_);
-	}
-
 	if (type == Type::Internal) {
 		allocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());
 		mutex_ = std::make_unique<std::mutex>();
@@ -70,15 +61,9 @@ Stream *CameraStream::stream() const
 	return configuration().stream();
 }

-int CameraStream::configure()
+int CameraStream::configure(std::unique_ptr<PostProcessor> postProcessor)
 {
-	if (postProcessor_) {
-		StreamConfiguration output = configuration();
-		output.pixelFormat = formats::MJPEG;
-		int ret = postProcessor_->configure(configuration(), output);
-		if (ret)
-			return ret;
-	}
+	postProcessor_ = std::move(postProcessor);

 	if (allocator_) {
 		int ret = allocator_->allocate(stream());
diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h
index fc242b2a..faafc934 100644
--- a/src/android/camera_stream.h
+++ b/src/android/camera_stream.h
@@ -118,7 +118,7 @@ public:
 	const libcamera::StreamConfiguration &configuration() const;
 	libcamera::Stream *stream() const;

-	int configure();
+	int configure(std::unique_ptr<PostProcessor> postProcessor);
 	int process(const libcamera::FrameBuffer &source,
 		    libcamera::MappedBuffer *destination,
 		    const CameraMetadata &requestMetadata,
--
2.30.0.365.g02bc693789-goog


More information about the libcamera-devel mailing list