Skip to main content

buffering_runtime/
lib.rs

1#![no_std]
2#![forbid(unsafe_code)]
3#![doc = include_str!("../README.md")]
4// The README is the single text for crates.io and docs.rs (docs/DOC-STANDARD.md rule 1).
5
6extern crate alloc;
7
8pub mod config;
9pub mod controller;
10pub mod error;
11pub mod events;
12pub mod histogram;
13pub mod input_log;
14pub mod jitter;
15pub mod policy;
16pub mod stall_memory;
17pub mod time;
18pub mod tracks;
19pub mod window;
20
21pub use config::{ControllerConfig, JitterConfig, PolicyConfig, US_PER_S};
22pub use controller::BufferController;
23pub use error::{ConfigField, Error};
24pub use events::{Event, EventRecord, Hint, Reason, State, Stats, kind};
25pub use jitter::{DeliveryJitter, JitterEstimate, SampleOutcome};
26pub use stall_memory::StallMemorySnapshot;
27pub use time::{
28    Clock27, MAX_DIFFERENCE_ERROR, duration_add, duration_between, instant_micros,
29    micros_as_duration, window_micros,
30};
31pub use tracks::{COALESCE, DEFAULT_TRACK, MAX_TRACKS};
32
33use broadcast_common::clock33::{PCR_EXT_MODULUS, WRAP_33BIT};
34
35/// C-ABI revision of the plain-data surface ([`EventRecord`], the `u32`
36/// codes of [`State`]/[`Reason`]/[`Hint`], the event [`kind`] codes). Bumped
37/// when any of them changes shape or meaning. Version 2 added the
38/// `track` / `track_valid` pair to [`EventRecord`] (40 bytes, was 32).
39pub const ABI_VERSION: u32 = 2;
40
41/// A 90 kHz PTS (33-bit, wrapped) as a playback-domain position: `PTS x 300`,
42/// exact and wrap-consistent (one PTS wrap is one `PCR_WRAP_27MHZ`).
43///
44/// # Errors
45/// [`broadcast_common::clock33::ClockOutOfRange`] when the product leaves the
46/// 27 MHz clock: `PTS x 300` is always below `2^33 x 300`, so only a caller's
47/// own value at the top of the 33-bit range can be over.
48pub fn pts90k_to_clock27(pts: u64) -> Result<Clock27, broadcast_common::clock33::ClockOutOfRange> {
49    let ticks = (pts % WRAP_33BIT) * PCR_EXT_MODULUS;
50    Clock27::from_27mhz(ticks)
51}