[2/6] pipeline: rpi: Add queue of wallclock timestamps
diff mbox series

Message ID 20241004115558.9166-3-david.plowman@raspberrypi.com
State New
Headers show
Series
  • Raspberry Pi software camera sync algorithm
Related show

Commit Message

David Plowman Oct. 4, 2024, 11:55 a.m. UTC
From: Naushir Patuck <naush@raspberrypi.com>

Subsequent commits will add actual values to this queue, which we can
then use for sending wallclock timestamps over to the IPAs, where a
future "synchonisation algorithm" can use them.

Also add code to return the wallclock time to the application through
the frame metadata.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
---
 src/libcamera/pipeline/rpi/common/pipeline_base.cpp | 9 +++++++++
 src/libcamera/pipeline/rpi/common/pipeline_base.h   | 2 ++
 2 files changed, 11 insertions(+)

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
index 3041fd1e..253fac96 100644
--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
@@ -676,6 +676,7 @@  int PipelineHandlerBase::start(Camera *camera, const ControlList *controls)
 	 */
 	data->delayedCtrls_->reset(0);
 	data->state_ = CameraData::State::Idle;
+	data->frameWallClock_ = {};
 
 	/* Enable SOF event generation. */
 	data->frontendDevice()->setFrameStartEnabled(true);
@@ -1353,6 +1354,11 @@  void CameraData::cameraTimeout()
 
 void CameraData::frameStarted(uint32_t sequence)
 {
+	/* Get frame wall clock. */
+	auto now = std::chrono::system_clock::now();
+	auto durNow = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch());
+	frameWallClock_.emplace(sequence, durNow);
+
 	LOG(RPI, Debug) << "Frame start " << sequence;
 
 	/* Write any controls for the next frame as soon as we can. */
@@ -1483,6 +1489,9 @@  void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request
 	request->metadata().set(controls::SensorTimestamp,
 				bufferControls.get(controls::SensorTimestamp).value_or(0));
 
+	request->metadata().set(controls::rpi::FrameWallClock,
+				bufferControls.get(controls::rpi::FrameWallClock).value_or(0));
+
 	request->metadata().set(controls::ScalerCrop, scalerCrop_);
 }
 
diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h
index f9cecf70..b7f5470f 100644
--- a/src/libcamera/pipeline/rpi/common/pipeline_base.h
+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h
@@ -163,6 +163,8 @@  public:
 
 	Config config_;
 
+	std::queue<std::pair<uint64_t, utils::Duration>> frameWallClock_;
+
 protected:
 	void fillRequestMetadata(const ControlList &bufferControls,
 				 Request *request);