[v2,2/5] ipa: simple: softisp: Extend to pass metadata
diff mbox series

Message ID 20241219211010.103310-3-mzamazal@redhat.com
State New
Headers show
Series
  • ipa: simple: Introduce metadata reporting
Related show

Commit Message

Milan Zamazal Dec. 19, 2024, 9:10 p.m. UTC
From: Kieran Bingham <kieran.bingham@ideasonboard.com>

Extend the Simple IPA IPC to support returning a metadata ControlList
when the process call has completed.

A new signal from the IPA is introduced to report the metadata,
similarly to what the hardware pipelines do.

Merge the metadata reported by the ISP into any completing request to
provide to the application.  Completion of a request is delayed until
this is done; this doesn't apply to canceled requests.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 .../internal/software_isp/software_isp.h      |  2 ++
 include/libcamera/ipa/soft.mojom              |  1 +
 src/ipa/simple/soft_simple.cpp                |  7 +---
 src/libcamera/pipeline/simple/simple.cpp      | 35 +++++++++++++++----
 src/libcamera/software_isp/software_isp.cpp   | 11 ++++++
 5 files changed, 43 insertions(+), 13 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h
index d51b03fd..3d248aba 100644
--- a/include/libcamera/internal/software_isp/software_isp.h
+++ b/include/libcamera/internal/software_isp/software_isp.h
@@ -83,12 +83,14 @@  public:
 	Signal<FrameBuffer *> inputBufferReady;
 	Signal<FrameBuffer *> outputBufferReady;
 	Signal<uint32_t, uint32_t> ispStatsReady;
+	Signal<uint32_t, const ControlList &> metadataReady;
 	Signal<const ControlList &> setSensorControls;
 
 private:
 	void saveIspParams();
 	void setSensorCtrls(const ControlList &sensorControls);
 	void statsReady(uint32_t frame, uint32_t bufferId);
+	void saveMetadata(uint32_t frame, const ControlList &metadata);
 	void inputReady(FrameBuffer *input);
 	void outputReady(FrameBuffer *output);
 
diff --git a/include/libcamera/ipa/soft.mojom b/include/libcamera/ipa/soft.mojom
index d52e6f1a..934a6fd1 100644
--- a/include/libcamera/ipa/soft.mojom
+++ b/include/libcamera/ipa/soft.mojom
@@ -33,4 +33,5 @@  interface IPASoftInterface {
 interface IPASoftEventInterface {
 	setSensorControls(libcamera.ControlList sensorControls);
 	setIspParams();
+	metadataReady(uint32 frame, libcamera.ControlList metadata);
 };
diff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp
index b26e4e15..944c644e 100644
--- a/src/ipa/simple/soft_simple.cpp
+++ b/src/ipa/simple/soft_simple.cpp
@@ -295,15 +295,10 @@  void IPASoftSimple::processStats(const uint32_t frame,
 	int32_t again = sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>();
 	frameContext.sensor.gain = camHelper_ ? camHelper_->gain(again) : again;
 
-	/*
-	 * Software ISP currently does not produce any metadata. Use an empty
-	 * ControlList for now.
-	 *
-	 * \todo Implement proper metadata handling
-	 */
 	ControlList metadata(controls::controls);
 	for (auto const &algo : algorithms())
 		algo->process(context_, frame, frameContext, stats_, metadata);
+	metadataReady.emit(frame, metadata);
 
 	/* Sanity check */
 	if (!sensorControls.contains(V4L2_CID_EXPOSURE) ||
diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index 07c1cf1f..1438bb22 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -184,6 +184,7 @@  class SimplePipelineHandler;
 struct SimpleFrameInfo {
 	uint32_t frame;
 	Request *request;
+	bool metadataProcessed;
 };
 
 class SimpleFrames
@@ -206,6 +207,7 @@  void SimpleFrames::create(Request *request)
 	SimpleFrameInfo *info = new SimpleFrameInfo;
 	info->frame = frame;
 	info->request = request;
+	info->metadataProcessed = false;
 	frameInfo_[frame] = info;
 }
 
@@ -363,11 +365,12 @@  private:
 	void tryPipeline(unsigned int code, const Size &size);
 	static std::vector<const MediaPad *> routedSourcePads(MediaPad *sink);
 
-	void completeRequest(Request *request);
+	void completeRequest(Request *request, bool checkCompleted);
 	void conversionInputDone(FrameBuffer *buffer);
 	void conversionOutputDone(FrameBuffer *buffer);
 
 	void ispStatsReady(uint32_t frame, uint32_t bufferId);
+	void metadataReady(uint32_t frame, const ControlList &metadata);
 	void setSensorControls(const ControlList &sensorControls);
 };
 
@@ -620,6 +623,7 @@  int SimpleCameraData::init()
 			});
 			swIsp_->outputBufferReady.connect(this, &SimpleCameraData::conversionOutputDone);
 			swIsp_->ispStatsReady.connect(this, &SimpleCameraData::ispStatsReady);
+			swIsp_->metadataReady.connect(this, &SimpleCameraData::metadataReady);
 			swIsp_->setSensorControls.connect(this, &SimpleCameraData::setSensorControls);
 		}
 	}
@@ -865,7 +869,7 @@  void SimpleCameraData::imageBufferReady(FrameBuffer *buffer)
 			/* No conversion, just complete the request. */
 			Request *request = buffer->request();
 			pipe->completeBuffer(request, buffer);
-			completeRequest(request);
+			completeRequest(request, false);
 			return;
 		}
 
@@ -883,7 +887,7 @@  void SimpleCameraData::imageBufferReady(FrameBuffer *buffer)
 		const RequestOutputs &outputs = conversionQueue_.front();
 		for (auto &[stream, buf] : outputs.outputs)
 			pipe->completeBuffer(outputs.request, buf);
-		completeRequest(outputs.request);
+		completeRequest(outputs.request, false);
 		conversionQueue_.pop();
 
 		return;
@@ -941,7 +945,7 @@  void SimpleCameraData::imageBufferReady(FrameBuffer *buffer)
 
 	/* Otherwise simply complete the request. */
 	pipe->completeBuffer(request, buffer);
-	completeRequest(request);
+	completeRequest(request, false);
 }
 
 void SimpleCameraData::clearIncompleteRequests()
@@ -952,11 +956,17 @@  void SimpleCameraData::clearIncompleteRequests()
 	}
 }
 
-void SimpleCameraData::completeRequest(Request *request)
+void SimpleCameraData::completeRequest(Request *request, bool checkCompleted)
 {
+	if (checkCompleted && request->hasPendingBuffers())
+		return;
+
 	SimpleFrameInfo *info = frameInfo_.find(request);
-	if (info)
+	if (info) {
+		if (checkCompleted && !info->metadataProcessed)
+			return;
 		frameInfo_.destroy(info->frame);
+	}
 	pipe()->completeRequest(request);
 }
 
@@ -973,7 +983,7 @@  void SimpleCameraData::conversionOutputDone(FrameBuffer *buffer)
 	/* Complete the buffer and the request. */
 	Request *request = buffer->request();
 	if (pipe->completeBuffer(request, buffer))
-		completeRequest(request);
+		completeRequest(request, true);
 }
 
 void SimpleCameraData::ispStatsReady(uint32_t frame, uint32_t bufferId)
@@ -982,6 +992,17 @@  void SimpleCameraData::ispStatsReady(uint32_t frame, uint32_t bufferId)
 			     delayedCtrls_->get(frame));
 }
 
+void SimpleCameraData::metadataReady(uint32_t frame, const ControlList &metadata)
+{
+	SimpleFrameInfo *info = frameInfo_.find(frame);
+	if (!info)
+		return;
+
+	info->request->metadata().merge(metadata);
+	info->metadataProcessed = true;
+	completeRequest(info->request, true);
+}
+
 void SimpleCameraData::setSensorControls(const ControlList &sensorControls)
 {
 	delayedCtrls_->push(sensorControls);
diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp
index 2bea64d9..bd4c25cc 100644
--- a/src/libcamera/software_isp/software_isp.cpp
+++ b/src/libcamera/software_isp/software_isp.cpp
@@ -51,6 +51,11 @@  LOG_DEFINE_CATEGORY(SoftwareIsp)
  * \brief A signal emitted when the statistics for IPA are ready
  */
 
+/**
+ * \var SoftwareIsp::metadataReady
+ * \brief A signal emitted when the metadata for IPA are ready
+ */
+
 /**
  * \var SoftwareIsp::setSensorControls
  * \brief A signal emitted when the values to write to the sensor controls are
@@ -136,6 +141,7 @@  SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,
 	}
 
 	ipa_->setIspParams.connect(this, &SoftwareIsp::saveIspParams);
+	ipa_->metadataReady.connect(this, &SoftwareIsp::saveMetadata);
 	ipa_->setSensorControls.connect(this, &SoftwareIsp::setSensorCtrls);
 
 	debayer_->moveToThread(&ispWorkerThread_);
@@ -357,6 +363,11 @@  void SoftwareIsp::statsReady(uint32_t frame, uint32_t bufferId)
 	ispStatsReady.emit(frame, bufferId);
 }
 
+void SoftwareIsp::saveMetadata(uint32_t frame, const ControlList &metadata)
+{
+	metadataReady.emit(frame, metadata);
+}
+
 void SoftwareIsp::inputReady(FrameBuffer *input)
 {
 	inputBufferReady.emit(input);