pub struct ClockNormalizer { /* private fields */ }Expand description
Normalizes device PTS to the shared monotonic clock.
Records the device PTS origin and monotonic clock origin on the first sample.
Later calls return device_pts - device_origin + monotonic_origin, shifting the
device clock onto the monotonic timeline while preserving its rate.
For sources without device PTS, such as microphones, pass each sample’s arrival
time (monotonic_now_ns) as device_pts.
Implementations§
Source§impl ClockNormalizer
impl ClockNormalizer
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a normalizer with unset origins, which are fixed by the first normalize.
Sourcepub fn is_unset(&self) -> bool
pub fn is_unset(&self) -> bool
Returns whether the origins are still unset (the first sample has not arrived).
Sourcepub fn normalize(&mut self, device_pts_ns: i64) -> i64
pub fn normalize(&mut self, device_pts_ns: i64) -> i64
Maps device PTS (ns) to normalized monotonic PTS (ns).
The first call fixes the origins and uses the current monotonic_now_ns as
the monotonic origin. Later calls preserve device-clock deltas.
Device rollover uses wrapping subtraction; a translated value outside i64
saturates at the nearest boundary rather than panicking or wrapping the timeline.