Skip to content

Commit 17f3d0f

Browse files
committed
pipeline: rpi: Add wallclock timestamp support
A ClockRecovery object is added for derived classes to use, and wallclock timestamps are copied into the request metadata for applications. Wallclock timestamps are derived corresponding to the sensor timestamp, and made available to the base pipeline handler class and to IPAs, for both vc4 and pisp platforms. Signed-off-by: David Plowman <[email protected]> Reviewed-by: Kieran Bingham <[email protected]> Reviewed-by: Naushir Patuck <[email protected]>
1 parent 4c1d9a4 commit 17f3d0f

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

src/libcamera/pipeline/rpi/common/pipeline_base.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,9 @@ int PipelineHandlerBase::start(Camera *camera, const ControlList *controls)
686686
return ret;
687687
}
688688

689+
/* A good moment to add an initial clock sample. */
690+
data->wallClockRecovery_.addSample();
691+
689692
/*
690693
* Reset the delayed controls with the gain and exposure values set by
691694
* the IPA.
@@ -1510,6 +1513,8 @@ void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request
15101513
{
15111514
request->metadata().set(controls::SensorTimestamp,
15121515
bufferControls.get(controls::SensorTimestamp).value_or(0));
1516+
request->metadata().set(controls::FrameWallClock,
1517+
bufferControls.get(controls::FrameWallClock).value_or(0));
15131518

15141519
if (cropParams_.size()) {
15151520
std::vector<Rectangle> crops;

src/libcamera/pipeline/rpi/common/pipeline_base.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "libcamera/internal/bayer_format.h"
2121
#include "libcamera/internal/camera.h"
2222
#include "libcamera/internal/camera_sensor.h"
23+
#include "libcamera/internal/clock_recovery.h"
2324
#include "libcamera/internal/framebuffer.h"
2425
#include "libcamera/internal/media_device.h"
2526
#include "libcamera/internal/media_object.h"
@@ -177,6 +178,8 @@ class CameraData : public Camera::Private
177178

178179
Config config_;
179180

181+
ClockRecovery wallClockRecovery_;
182+
180183
protected:
181184
void fillRequestMetadata(const ControlList &bufferControls,
182185
Request *request);

src/libcamera/pipeline/rpi/pisp/pisp.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,9 +1744,15 @@ void PiSPCameraData::cfeBufferDequeue(FrameBuffer *buffer)
17441744
auto [ctrl, delayContext] = delayedCtrls_->get(buffer->metadata().sequence);
17451745
/*
17461746
* Add the frame timestamp to the ControlList for the IPA to use
1747-
* as it does not receive the FrameBuffer object.
1747+
* as it does not receive the FrameBuffer object. Also derive a
1748+
* corresponding wallclock value.
17481749
*/
1749-
ctrl.set(controls::SensorTimestamp, buffer->metadata().timestamp);
1750+
wallClockRecovery_.addSample();
1751+
uint64_t sensorTimestamp = buffer->metadata().timestamp;
1752+
uint64_t wallClockTimestamp = wallClockRecovery_.getOutput(sensorTimestamp / 1000);
1753+
1754+
ctrl.set(controls::SensorTimestamp, sensorTimestamp);
1755+
ctrl.set(controls::FrameWallClock, wallClockTimestamp);
17501756
job.sensorControls = std::move(ctrl);
17511757
job.delayContext = delayContext;
17521758
} else if (stream == &cfe_[Cfe::Config]) {

src/libcamera/pipeline/rpi/vc4/vc4.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,9 +833,15 @@ void Vc4CameraData::unicamBufferDequeue(FrameBuffer *buffer)
833833
auto [ctrl, delayContext] = delayedCtrls_->get(buffer->metadata().sequence);
834834
/*
835835
* Add the frame timestamp to the ControlList for the IPA to use
836-
* as it does not receive the FrameBuffer object.
836+
* as it does not receive the FrameBuffer object. Also derive a
837+
* corresponding wallclock value.
837838
*/
838-
ctrl.set(controls::SensorTimestamp, buffer->metadata().timestamp);
839+
wallClockRecovery_.addSample();
840+
uint64_t sensorTimestamp = buffer->metadata().timestamp;
841+
uint64_t wallClockTimestamp = wallClockRecovery_.getOutput(sensorTimestamp / 1000);
842+
843+
ctrl.set(controls::SensorTimestamp, sensorTimestamp);
844+
ctrl.set(controls::FrameWallClock, wallClockTimestamp);
839845
bayerQueue_.push({ buffer, std::move(ctrl), delayContext });
840846
} else {
841847
embeddedQueue_.push(buffer);

0 commit comments

Comments
 (0)