libcamera v0.5.0
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
Public Member Functions | List of all members
libcamera::ClockRecovery Class Reference

Recover an output clock from an input clock. More...

Public Member Functions

 ClockRecovery ()
 Construct a ClockRecovery.
 
void configure (unsigned int numSamples=100, unsigned int maxJitter=2000, unsigned int minSamples=10, unsigned int errorThreshold=50000)
 Set configuration parameters.
 
void reset ()
 Reset the clock recovery model and start again from scratch.
 
void addSample ()
 Add a sample point to the clock recovery model, for recovering a wall clock value from the internal system time since boot.
 
void addSample (uint64_t input, uint64_t output)
 Add a sample point to the clock recovery model, specifying the exact input and output clock values.
 
uint64_t getOutput (uint64_t input)
 Calculate the output clock value according to the model from an input clock value.
 

Detailed Description

Recover an output clock from an input clock.

The ClockRecovery class derives an output clock from an input clock, modelling the output clock as being linearly related to the input clock. For example, we may use it to derive wall clock timestamps from timestamps measured by the internal system clock which counts local time since boot.

When pairs of corresponding input and output timestamps are available, they should be submitted to the model with addSample(). The model will update, and output clock values for known input clock values can be obtained using getOutput().

As a convenience, if the input clock is indeed the time since boot, and the output clock represents a real wallclock time, then addSample() can be called with no arguments, and a pair of timestamps will be captured at that moment.

The configure() function accepts some configuration parameters to control the linear fitting process.

Member Function Documentation

◆ addSample() [1/2]

void libcamera::ClockRecovery::addSample ( )

Add a sample point to the clock recovery model, for recovering a wall clock value from the internal system time since boot.

This is a convenience function to make it easy to derive a wall clock value (using the Linux CLOCK_REALTIME) from the time since the system started (measured by CLOCK_BOOTTIME).

◆ addSample() [2/2]

void libcamera::ClockRecovery::addSample ( uint64_t  input,
uint64_t  output 
)

Add a sample point to the clock recovery model, specifying the exact input and output clock values.

Parameters
[in]inputThe input clock value
[in]outputThe value of the output clock at the same moment, as far as possible, that the input clock was sampled

This function should be used for corresponding clocks other than the Linux BOOTTIME and REALTIME clocks.

◆ configure()

void libcamera::ClockRecovery::configure ( unsigned int  numSamples = 100,
unsigned int  maxJitter = 2000,
unsigned int  minSamples = 10,
unsigned int  errorThreshold = 50000 
)

Set configuration parameters.

Parameters
[in]numSamplesThe approximate duration for which the state of the model is persistent
[in]maxJitterNew output samples are clamped to no more than this amount of jitter, to prevent sudden swings from having a large effect
[in]minSamplesThe fitted clock model is not used to generate outputs until this many samples have been received
[in]errorThresholdIf the accumulated differences between input and output clocks reaches this amount over a few frames, the model is reset

◆ getOutput()

uint64_t libcamera::ClockRecovery::getOutput ( uint64_t  input)

Calculate the output clock value according to the model from an input clock value.

Parameters
[in]inputThe input clock value
Returns
Output clock value

The documentation for this class was generated from the following files: