[libcamera-devel,v2,4/7] android: Move StreamBuffer out of Camera3RequestDescriptor
diff mbox series

Message ID 20220812090838.1784703-5-hanlinchen@chromium.org
State New
Headers show
Series
  • Implement Android Partial Result Featrue
Related show

Commit Message

Hanlin Chen Aug. 12, 2022, 9:08 a.m. UTC
Move StreamBuffer out of Camera3RequestDescriptor as a refactory before
applying partial result to Android adaptor. For easier adding
Camera3ResultDescriptor which references both StreamBuffer and
Camera3RequestDescriptor.

Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>
---
 src/android/camera_device.cpp            | 22 +++++-----
 src/android/camera_device.h              |  7 ++--
 src/android/camera_request.cpp           | 29 +++++++------
 src/android/camera_request.h             | 52 ++++++++++++++----------
 src/android/camera_stream.cpp            | 17 ++++----
 src/android/camera_stream.h              |  6 +--
 src/android/jpeg/post_processor_jpeg.cpp |  2 +-
 src/android/jpeg/post_processor_jpeg.h   |  2 +-
 src/android/post_processor.h             |  4 +-
 src/android/yuv/post_processor_yuv.cpp   |  2 +-
 src/android/yuv/post_processor_yuv.h     |  2 +-
 11 files changed, 75 insertions(+), 70 deletions(-)

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index b20e389b..0248f146 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -860,7 +860,7 @@  void CameraDevice::abortRequest(Camera3RequestDescriptor *descriptor) const
 	notifyError(descriptor->frameNumber_, nullptr, CAMERA3_MSG_ERROR_REQUEST);
 
 	for (auto &buffer : descriptor->buffers_)
-		buffer.status = Camera3RequestDescriptor::Status::Error;
+		buffer.status = StreamBuffer::Status::Error;
 
 	descriptor->status_ = Camera3RequestDescriptor::Status::Error;
 }
@@ -1156,7 +1156,7 @@  void CameraDevice::requestComplete(Request *request)
 			if (fence)
 				buffer.fence = fence->release();
 		}
-		buffer.status = Camera3RequestDescriptor::Status::Success;
+		buffer.status = StreamBuffer::Status::Success;
 	}
 
 	/*
@@ -1219,12 +1219,12 @@  void CameraDevice::requestComplete(Request *request)
 	auto iter = descriptor->pendingStreamsToProcess_.begin();
 	while (iter != descriptor->pendingStreamsToProcess_.end()) {
 		CameraStream *stream = iter->first;
-		Camera3RequestDescriptor::StreamBuffer *buffer = iter->second;
+		StreamBuffer *buffer = iter->second;
 
 		FrameBuffer *src = request->findBuffer(stream->stream());
 		if (!src) {
 			LOG(HAL, Error) << "Failed to find a source stream buffer";
-			setBufferStatus(*buffer, Camera3RequestDescriptor::Status::Error);
+			setBufferStatus(*buffer, StreamBuffer::Status::Error);
 			iter = descriptor->pendingStreamsToProcess_.erase(iter);
 			continue;
 		}
@@ -1234,7 +1234,7 @@  void CameraDevice::requestComplete(Request *request)
 		++iter;
 		int ret = stream->process(buffer);
 		if (ret) {
-			setBufferStatus(*buffer, Camera3RequestDescriptor::Status::Error);
+			setBufferStatus(*buffer, StreamBuffer::Status::Error);
 			descriptor->pendingStreamsToProcess_.erase(stream);
 
 			/*
@@ -1304,7 +1304,7 @@  void CameraDevice::sendCaptureResults()
 		for (auto &buffer : descriptor->buffers_) {
 			camera3_buffer_status status = CAMERA3_BUFFER_STATUS_ERROR;
 
-			if (buffer.status == Camera3RequestDescriptor::Status::Success)
+			if (buffer.status == StreamBuffer::Status::Success)
 				status = CAMERA3_BUFFER_STATUS_OK;
 
 			/*
@@ -1328,11 +1328,11 @@  void CameraDevice::sendCaptureResults()
 	}
 }
 
-void CameraDevice::setBufferStatus(Camera3RequestDescriptor::StreamBuffer &streamBuffer,
-				   Camera3RequestDescriptor::Status status)
+void CameraDevice::setBufferStatus(StreamBuffer &streamBuffer,
+				   StreamBuffer::Status status)
 {
 	streamBuffer.status = status;
-	if (status != Camera3RequestDescriptor::Status::Success) {
+	if (status != StreamBuffer::Status::Success) {
 		notifyError(streamBuffer.request->frameNumber_,
 			    streamBuffer.stream->camera3Stream(),
 			    CAMERA3_MSG_ERROR_BUFFER);
@@ -1356,8 +1356,8 @@  void CameraDevice::setBufferStatus(Camera3RequestDescriptor::StreamBuffer &strea
  * be generated from post-processing have been completed. Mark the descriptor as
  * complete using completeDescriptor() in that case.
  */
-void CameraDevice::streamProcessingComplete(Camera3RequestDescriptor::StreamBuffer *streamBuffer,
-					    Camera3RequestDescriptor::Status status)
+void CameraDevice::streamProcessingComplete(StreamBuffer *streamBuffer,
+					    StreamBuffer::Status status)
 {
 	setBufferStatus(*streamBuffer, status);
 
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index 64050416..9eb7221b 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -64,8 +64,8 @@  public:
 	int configureStreams(camera3_stream_configuration_t *stream_list);
 	int processCaptureRequest(camera3_capture_request_t *request);
 	void requestComplete(libcamera::Request *request);
-	void streamProcessingComplete(Camera3RequestDescriptor::StreamBuffer *bufferStream,
-				      Camera3RequestDescriptor::Status status);
+	void streamProcessingComplete(StreamBuffer *bufferStream,
+				      StreamBuffer::Status status);
 
 protected:
 	std::string logPrefix() const override;
@@ -96,8 +96,7 @@  private:
 	void completeDescriptor(Camera3RequestDescriptor *descriptor)
 		LIBCAMERA_TSA_EXCLUDES(descriptorsMutex_);
 	void sendCaptureResults() LIBCAMERA_TSA_REQUIRES(descriptorsMutex_);
-	void setBufferStatus(Camera3RequestDescriptor::StreamBuffer &buffer,
-			     Camera3RequestDescriptor::Status status);
+	void setBufferStatus(StreamBuffer &buffer, StreamBuffer::Status status);
 	std::unique_ptr<CameraMetadata> getResultMetadata(
 		const Camera3RequestDescriptor &descriptor) const;
 
diff --git a/src/android/camera_request.cpp b/src/android/camera_request.cpp
index 6c87adba..f5d4d314 100644
--- a/src/android/camera_request.cpp
+++ b/src/android/camera_request.cpp
@@ -141,7 +141,7 @@  Camera3RequestDescriptor::Camera3RequestDescriptor(
 Camera3RequestDescriptor::~Camera3RequestDescriptor() = default;
 
 /**
- * \struct Camera3RequestDescriptor::StreamBuffer
+ * \class StreamBuffer
  * \brief Group information for per-stream buffer of Camera3RequestDescriptor
  *
  * A capture request placed to the libcamera HAL can contain multiple streams.
@@ -150,35 +150,35 @@  Camera3RequestDescriptor::~Camera3RequestDescriptor() = default;
  * generation. The generation of the stream will depend on its type (refer to
  * the CameraStream::Type documentation).
  *
- * \var Camera3RequestDescriptor::StreamBuffer::stream
+ * \var StreamBuffer::stream
  * \brief Pointer to the corresponding CameraStream
  *
- * \var Camera3RequestDescriptor::StreamBuffer::camera3Buffer
+ * \var StreamBuffer::camera3Buffer
  * \brief Native handle to the buffer
  *
- * \var Camera3RequestDescriptor::StreamBuffer::frameBuffer
+ * \var StreamBuffer::frameBuffer
  * \brief Encapsulate the dmabuf handle inside a libcamera::FrameBuffer for
  * direct streams
  *
- * \var Camera3RequestDescriptor::StreamBuffer::fence
+ * \var StreamBuffer::fence
  * \brief Acquire fence of the buffer
  *
- * \var Camera3RequestDescriptor::StreamBuffer::status
+ * \var StreamBuffer::status
  * \brief Track the status of the buffer
  *
- * \var Camera3RequestDescriptor::StreamBuffer::internalBuffer
+ * \var StreamBuffer::internalBuffer
  * \brief Pointer to a buffer internally handled by CameraStream (if any)
  *
- * \var Camera3RequestDescriptor::StreamBuffer::srcBuffer
+ * \var StreamBuffer::srcBuffer
  * \brief Pointer to the source frame buffer used for post-processing
  *
- * \var Camera3RequestDescriptor::StreamBuffer::dstBuffer
+ * \var StreamBuffer::dstBuffer
  * \brief Pointer to the destination frame buffer used for post-processing
  *
- * \var Camera3RequestDescriptor::StreamBuffer::request
+ * \var StreamBuffer::request
  * \brief Back pointer to the Camera3RequestDescriptor to which the StreamBuffer belongs
  */
-Camera3RequestDescriptor::StreamBuffer::StreamBuffer(
+StreamBuffer::StreamBuffer(
 	CameraStream *cameraStream, const camera3_stream_buffer_t &buffer,
 	Camera3RequestDescriptor *requestDescriptor)
 	: stream(cameraStream), camera3Buffer(buffer.buffer),
@@ -186,9 +186,8 @@  Camera3RequestDescriptor::StreamBuffer::StreamBuffer(
 {
 }
 
-Camera3RequestDescriptor::StreamBuffer::~StreamBuffer() = default;
+StreamBuffer::~StreamBuffer() = default;
 
-Camera3RequestDescriptor::StreamBuffer::StreamBuffer(StreamBuffer &&) = default;
+StreamBuffer::StreamBuffer(StreamBuffer &&) = default;
 
-Camera3RequestDescriptor::StreamBuffer &
-Camera3RequestDescriptor::StreamBuffer::operator=(Camera3RequestDescriptor::StreamBuffer &&) = default;
+StreamBuffer &StreamBuffer::operator=(StreamBuffer &&) = default;
diff --git a/src/android/camera_request.h b/src/android/camera_request.h
index 37b6ae32..5aa4eea8 100644
--- a/src/android/camera_request.h
+++ b/src/android/camera_request.h
@@ -24,8 +24,9 @@ 
 
 class CameraBuffer;
 class CameraStream;
+class Camera3RequestDescriptor;
 
-class Camera3RequestDescriptor
+class StreamBuffer
 {
 public:
 	enum class Status {
@@ -33,27 +34,34 @@  public:
 		Error,
 	};
 
-	struct StreamBuffer {
-		StreamBuffer(CameraStream *stream,
-			     const camera3_stream_buffer_t &buffer,
-			     Camera3RequestDescriptor *request);
-		~StreamBuffer();
-
-		StreamBuffer(StreamBuffer &&);
-		StreamBuffer &operator=(StreamBuffer &&);
-
-		CameraStream *stream;
-		buffer_handle_t *camera3Buffer;
-		std::unique_ptr<libcamera::FrameBuffer> frameBuffer;
-		libcamera::UniqueFD fence;
-		Status status = Status::Success;
-		libcamera::FrameBuffer *internalBuffer = nullptr;
-		const libcamera::FrameBuffer *srcBuffer = nullptr;
-		std::unique_ptr<CameraBuffer> dstBuffer;
-		Camera3RequestDescriptor *request;
-
-	private:
-		LIBCAMERA_DISABLE_COPY(StreamBuffer)
+	StreamBuffer(CameraStream *stream,
+		     const camera3_stream_buffer_t &buffer,
+		     Camera3RequestDescriptor *request);
+	~StreamBuffer();
+
+	StreamBuffer(StreamBuffer &&);
+	StreamBuffer &operator=(StreamBuffer &&);
+
+	CameraStream *stream;
+	buffer_handle_t *camera3Buffer;
+	std::unique_ptr<libcamera::FrameBuffer> frameBuffer;
+	libcamera::UniqueFD fence;
+	Status status = Status::Success;
+	libcamera::FrameBuffer *internalBuffer = nullptr;
+	const libcamera::FrameBuffer *srcBuffer = nullptr;
+	std::unique_ptr<CameraBuffer> dstBuffer;
+	Camera3RequestDescriptor *request;
+
+private:
+	LIBCAMERA_DISABLE_COPY(StreamBuffer)
+};
+
+class Camera3RequestDescriptor
+{
+public:
+	enum class Status {
+		Success,
+		Error,
 	};
 
 	/* Keeps track of streams requiring post-processing. */
diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp
index 045e6006..02dc8922 100644
--- a/src/android/camera_stream.cpp
+++ b/src/android/camera_stream.cpp
@@ -112,14 +112,14 @@  int CameraStream::configure()
 
 		worker_ = std::make_unique<PostProcessorWorker>(postProcessor_.get());
 		postProcessor_->processComplete.connect(
-			this, [&](Camera3RequestDescriptor::StreamBuffer *streamBuffer,
+			this, [&](StreamBuffer *streamBuffer,
 				  PostProcessor::Status status) {
-				Camera3RequestDescriptor::Status bufferStatus;
+				StreamBuffer::Status bufferStatus;
 
 				if (status == PostProcessor::Status::Success)
-					bufferStatus = Camera3RequestDescriptor::Status::Success;
+					bufferStatus = StreamBuffer::Status::Success;
 				else
-					bufferStatus = Camera3RequestDescriptor::Status::Error;
+					bufferStatus = StreamBuffer::Status::Error;
 
 				cameraDevice_->streamProcessingComplete(streamBuffer,
 									bufferStatus);
@@ -165,7 +165,7 @@  int CameraStream::waitFence(int fence)
 	return -errno;
 }
 
-int CameraStream::process(Camera3RequestDescriptor::StreamBuffer *streamBuffer)
+int CameraStream::process(StreamBuffer *streamBuffer)
 {
 	ASSERT(type_ != Type::Direct);
 
@@ -283,7 +283,7 @@  void CameraStream::PostProcessorWorker::start()
 	Thread::start();
 }
 
-void CameraStream::PostProcessorWorker::queueRequest(Camera3RequestDescriptor::StreamBuffer *dest)
+void CameraStream::PostProcessorWorker::queueRequest(StreamBuffer *dest)
 {
 	{
 		MutexLocker lock(mutex_);
@@ -306,7 +306,7 @@  void CameraStream::PostProcessorWorker::run()
 		if (state_ != State::Running)
 			break;
 
-		Camera3RequestDescriptor::StreamBuffer *streamBuffer = requests_.front();
+		StreamBuffer *streamBuffer = requests_.front();
 		requests_.pop();
 		locker.unlock();
 
@@ -316,8 +316,7 @@  void CameraStream::PostProcessorWorker::run()
 	}
 
 	if (state_ == State::Flushing) {
-		std::queue<Camera3RequestDescriptor::StreamBuffer *> requests =
-			std::move(requests_);
+		std::queue<StreamBuffer *> requests = std::move(requests_);
 		locker.unlock();
 
 		while (!requests.empty()) {
diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h
index 4c5078b2..c3b2e325 100644
--- a/src/android/camera_stream.h
+++ b/src/android/camera_stream.h
@@ -127,7 +127,7 @@  public:
 	CameraStream *sourceStream() const { return sourceStream_; }
 
 	int configure();
-	int process(Camera3RequestDescriptor::StreamBuffer *streamBuffer);
+	int process(StreamBuffer *streamBuffer);
 	libcamera::FrameBuffer *getBuffer();
 	void putBuffer(libcamera::FrameBuffer *buffer);
 	void flush();
@@ -146,7 +146,7 @@  private:
 		~PostProcessorWorker();
 
 		void start();
-		void queueRequest(Camera3RequestDescriptor::StreamBuffer *request);
+		void queueRequest(StreamBuffer *request);
 		void flush();
 
 	protected:
@@ -158,7 +158,7 @@  private:
 		libcamera::Mutex mutex_;
 		libcamera::ConditionVariable cv_;
 
-		std::queue<Camera3RequestDescriptor::StreamBuffer *> requests_
+		std::queue<StreamBuffer *> requests_
 			LIBCAMERA_TSA_GUARDED_BY(mutex_);
 
 		State state_ LIBCAMERA_TSA_GUARDED_BY(mutex_) = State::Stopped;
diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp
index d72ebc3c..b9ba38ce 100644
--- a/src/android/jpeg/post_processor_jpeg.cpp
+++ b/src/android/jpeg/post_processor_jpeg.cpp
@@ -98,7 +98,7 @@  void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,
 	}
 }
 
-void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBuffer)
+void PostProcessorJpeg::process(StreamBuffer *streamBuffer)
 {
 	ASSERT(encoder_);
 
diff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h
index 98309b01..0ba3e01b 100644
--- a/src/android/jpeg/post_processor_jpeg.h
+++ b/src/android/jpeg/post_processor_jpeg.h
@@ -22,7 +22,7 @@  public:
 
 	int configure(const libcamera::StreamConfiguration &incfg,
 		      const libcamera::StreamConfiguration &outcfg) override;
-	void process(Camera3RequestDescriptor::StreamBuffer *streamBuffer) override;
+	void process(StreamBuffer *streamBuffer) override;
 
 private:
 	void generateThumbnail(const libcamera::FrameBuffer &source,
diff --git a/src/android/post_processor.h b/src/android/post_processor.h
index 1a205b05..ac0182cd 100644
--- a/src/android/post_processor.h
+++ b/src/android/post_processor.h
@@ -27,7 +27,7 @@  public:
 
 	virtual int configure(const libcamera::StreamConfiguration &inCfg,
 			      const libcamera::StreamConfiguration &outCfg) = 0;
-	virtual void process(Camera3RequestDescriptor::StreamBuffer *streamBuffer) = 0;
+	virtual void process(StreamBuffer *streamBuffer) = 0;
 
-	libcamera::Signal<Camera3RequestDescriptor::StreamBuffer *, Status> processComplete;
+	libcamera::Signal<StreamBuffer *, Status> processComplete;
 };
diff --git a/src/android/yuv/post_processor_yuv.cpp b/src/android/yuv/post_processor_yuv.cpp
index ed44e6fe..de49b378 100644
--- a/src/android/yuv/post_processor_yuv.cpp
+++ b/src/android/yuv/post_processor_yuv.cpp
@@ -49,7 +49,7 @@  int PostProcessorYuv::configure(const StreamConfiguration &inCfg,
 	return 0;
 }
 
-void PostProcessorYuv::process(Camera3RequestDescriptor::StreamBuffer *streamBuffer)
+void PostProcessorYuv::process(StreamBuffer *streamBuffer)
 {
 	const FrameBuffer &source = *streamBuffer->srcBuffer;
 	CameraBuffer *destination = streamBuffer->dstBuffer.get();
diff --git a/src/android/yuv/post_processor_yuv.h b/src/android/yuv/post_processor_yuv.h
index a7ac17c5..27cf4bbc 100644
--- a/src/android/yuv/post_processor_yuv.h
+++ b/src/android/yuv/post_processor_yuv.h
@@ -18,7 +18,7 @@  public:
 
 	int configure(const libcamera::StreamConfiguration &incfg,
 		      const libcamera::StreamConfiguration &outcfg) override;
-	void process(Camera3RequestDescriptor::StreamBuffer *streamBuffer) override;
+	void process(StreamBuffer *streamBuffer) override;
 
 private:
 	bool isValidBuffers(const libcamera::FrameBuffer &source,