[6/8] libcamera: pipelines: Use the metadataAvailable() function
diff mbox series

Message ID 20241206160747.97176-7-jacopo.mondi@ideasonboard.com
State New
Headers show
Series
  • libcamera: Support partial metadata completion
Related show

Commit Message

Jacopo Mondi Dec. 6, 2024, 4:07 p.m. UTC
In order to prepare to restrict access to the Request::metadata_
list, use the new PipelineHandler::metadataAvailable() function
to notify the availability of metadata and accumulate them in
the Request::metadata_ list.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/libcamera/pipeline/imx8-isi/imx8-isi.cpp       |  6 ++----
 src/libcamera/pipeline/ipu3/ipu3.cpp               | 14 +++++++-------
 src/libcamera/pipeline/rkisp1/rkisp1.cpp           |  8 ++++----
 .../pipeline/rpi/common/pipeline_base.cpp          | 12 ++++++------
 src/libcamera/pipeline/simple/simple.cpp           |  4 ++--
 src/libcamera/pipeline/uvcvideo/uvcvideo.cpp       |  4 ++--
 src/libcamera/pipeline/vimc/vimc.cpp               |  4 ++--
 src/libcamera/pipeline/virtual/virtual.cpp         |  3 ++-
 8 files changed, 27 insertions(+), 28 deletions(-)

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp
index 4e66b3368d5a..5588f4a05446 100644
--- a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp
+++ b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp
@@ -1099,10 +1099,8 @@  void PipelineHandlerISI::bufferReady(FrameBuffer *buffer)
 	Request *request = buffer->request();
 
 	/* Record the sensor's timestamp in the request metadata. */
-	ControlList &metadata = request->metadata();
-	if (!metadata.contains(controls::SensorTimestamp.id()))
-		metadata.set(controls::SensorTimestamp,
-			     buffer->metadata().timestamp);
+	metadataAvailable(request, controls::SensorTimestamp,
+			  static_cast<int64_t>(buffer->metadata().timestamp));
 
 	completeBuffer(request, buffer);
 	if (request->hasPendingBuffers())
diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index e31e3879dcc9..bf1119bea567 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -1245,7 +1245,7 @@  void IPU3CameraData::metadataReady(unsigned int id, const ControlList &metadata)
 		return;
 
 	Request *request = info->request;
-	request->metadata().merge(metadata);
+	pipe()->metadataAvailable(request, metadata);
 
 	info->metadataProcessed = true;
 	if (frameInfos_.tryComplete(info))
@@ -1272,12 +1272,12 @@  void IPU3CameraData::imguOutputBufferReady(FrameBuffer *buffer)
 
 	pipe()->completeBuffer(request, buffer);
 
-	request->metadata().set(controls::draft::PipelineDepth, 3);
+	pipe()->metadataAvailable(request, controls::draft::PipelineDepth, 3);
 	/* \todo Actually apply the scaler crop region to the ImgU. */
 	const auto &scalerCrop = request->controls().get(controls::ScalerCrop);
 	if (scalerCrop)
 		cropRegion_ = *scalerCrop;
-	request->metadata().set(controls::ScalerCrop, cropRegion_);
+	pipe()->metadataAvailable(request, controls::ScalerCrop, cropRegion_);
 
 	if (frameInfos_.tryComplete(info))
 		pipe()->completeRequest(request);
@@ -1317,8 +1317,8 @@  void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer)
 	 * \todo The sensor timestamp should be better estimated by connecting
 	 * to the V4L2Device::frameStart signal.
 	 */
-	request->metadata().set(controls::SensorTimestamp,
-				buffer->metadata().timestamp);
+	pipe()->metadataAvailable(request, controls::SensorTimestamp,
+				  static_cast<int64_t>(buffer->metadata().timestamp));
 
 	info->effectiveSensorControls = delayedCtrls_->get(buffer->metadata().sequence);
 
@@ -1412,8 +1412,8 @@  void IPU3CameraData::frameStart(uint32_t sequence)
 		return;
 	}
 
-	request->metadata().set(controls::draft::TestPatternMode,
-				*testPatternMode);
+	pipe()->metadataAvailable(request, controls::draft::TestPatternMode,
+				  *testPatternMode);
 }
 
 REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3, "ipu3")
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
index 908724e20975..8c66f0fc11b4 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
@@ -431,7 +431,7 @@  void RkISP1CameraData::metadataReady(unsigned int frame, const ControlList &meta
 	if (!info)
 		return;
 
-	info->request->metadata().merge(metadata);
+	pipe()->metadataAvailable(info->request, metadata);
 	info->metadataProcessed = true;
 
 	pipe()->tryCompleteRequest(info);
@@ -1414,8 +1414,8 @@  void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
 		 * \todo The sensor timestamp should be better estimated by connecting
 		 * to the V4L2Device::frameStart signal.
 		 */
-		request->metadata().set(controls::SensorTimestamp,
-					metadata.timestamp);
+		metadataAvailable(request, controls::SensorTimestamp,
+				  static_cast<int64_t>(metadata.timestamp));
 
 		if (isRaw_) {
 			const ControlList &ctrls =
@@ -1487,7 +1487,7 @@  void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
 		LOG(RkISP1, Error) << "Cannot queue buffers to dewarper: "
 				   << strerror(-ret);
 
-	request->metadata().set(controls::ScalerCrop, activeCrop_.value());
+	metadataAvailable(request, controls::ScalerCrop, activeCrop_.value());
 }
 
 void PipelineHandlerRkISP1::dewarpBufferReady(FrameBuffer *buffer)
diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
index 6f278b29331a..8bfca6d2890d 100644
--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
@@ -1234,7 +1234,7 @@  void CameraData::metadataReady(const ControlList &metadata)
 	/* Add to the Request metadata buffer what the IPA has provided. */
 	/* Last thing to do is to fill up the request metadata. */
 	Request *request = requestQueue_.front();
-	request->metadata().merge(metadata);
+	pipe()->metadataAvailable(request, metadata);
 
 	/*
 	 * Inform the sensor of the latest colour gains if it has the
@@ -1507,8 +1507,8 @@  void CameraData::checkRequestCompleted()
 
 void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request *request)
 {
-	request->metadata().set(controls::SensorTimestamp,
-				bufferControls.get(controls::SensorTimestamp).value_or(0));
+	pipe()->metadataAvailable(request, controls::SensorTimestamp,
+		  static_cast<int64_t>(bufferControls.get(controls::SensorTimestamp).value_or(0)));
 
 	if (cropParams_.size()) {
 		std::vector<Rectangle> crops;
@@ -1516,10 +1516,10 @@  void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request
 		for (auto const &[k, v] : cropParams_)
 			crops.push_back(scaleIspCrop(v.ispCrop));
 
-		request->metadata().set(controls::ScalerCrop, crops[0]);
+		pipe()->metadataAvailable(request, controls::ScalerCrop, crops[0]);
 		if (crops.size() > 1) {
-			request->metadata().set(controls::rpi::ScalerCrops,
-						Span<const Rectangle>(crops.data(), crops.size()));
+			pipe()->metadataAvailable(request, controls::rpi::ScalerCrops,
+						  Span<const Rectangle>(crops.data(), crops.size()));
 		}
 	}
 }
diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index 8ac24e6e3423..0a68e454b3e4 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -844,8 +844,8 @@  void SimpleCameraData::imageBufferReady(FrameBuffer *buffer)
 	}
 
 	if (request)
-		request->metadata().set(controls::SensorTimestamp,
-					buffer->metadata().timestamp);
+		pipe->metadataAvailable(request, controls::SensorTimestamp,
+					static_cast<int64_t>(buffer->metadata().timestamp));
 
 	/*
 	 * Queue the captured and the request buffer to the converter or Software
diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
index 8c2c6baf3575..7fe607972a73 100644
--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
@@ -752,8 +752,8 @@  void UVCCameraData::imageBufferReady(FrameBuffer *buffer)
 	Request *request = buffer->request();
 
 	/* \todo Use the UVC metadata to calculate a more precise timestamp */
-	request->metadata().set(controls::SensorTimestamp,
-				buffer->metadata().timestamp);
+	pipe()->metadataAvailable(request, controls::SensorTimestamp,
+				  static_cast<int64_t>(buffer->metadata().timestamp));
 
 	pipe()->completeBuffer(request, buffer);
 	pipe()->completeRequest(request);
diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp
index 07273bd2b6c3..56b9d3c1ed69 100644
--- a/src/libcamera/pipeline/vimc/vimc.cpp
+++ b/src/libcamera/pipeline/vimc/vimc.cpp
@@ -615,8 +615,8 @@  void VimcCameraData::imageBufferReady(FrameBuffer *buffer)
 	}
 
 	/* Record the sensor's timestamp in the request metadata. */
-	request->metadata().set(controls::SensorTimestamp,
-				buffer->metadata().timestamp);
+	pipe->metadataAvailable(request, controls::SensorTimestamp,
+				static_cast<int64_t>(buffer->metadata().timestamp));
 
 	pipe->completeBuffer(request, buffer);
 	pipe->completeRequest(request);
diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp
index cec8a85bf22c..695e2650e10f 100644
--- a/src/libcamera/pipeline/virtual/virtual.cpp
+++ b/src/libcamera/pipeline/virtual/virtual.cpp
@@ -317,7 +317,8 @@  int PipelineHandlerVirtual::queueRequestDevice([[maybe_unused]] Camera *camera,
 		ASSERT(found);
 	}
 
-	request->metadata().set(controls::SensorTimestamp, currentTimestamp());
+	metadataAvailable(request, controls::SensorTimestamp,
+			  static_cast<int64_t>(currentTimestamp()));
 	completeRequest(request);
 
 	return 0;