Skip to main content

PtsUnroller

Struct PtsUnroller 

Source
pub struct PtsUnroller { /* private fields */ }
Expand description

Per-signal 33-bit PTS unroller: turns a repeating 90 kHz wire counter into an absolute, ever-growing tick value.

Thin stateful wrapper around broadcast_common::clock33::unwrap_delta — the actual wrap-correction math lives there (shared with transmux’s demux-edge unroller and media-doctor/compliance-probe’s wrap-aware comparisons), so a fix there reaches every 33-bit clock consumer in the workspace instead of just this one.

SCTE-35 cues and caption commit events never legitimately reorder across the 33-bit origin before any sample has been observed (there is no prior sample to wrap from), so unroll never sees a negative accumulator in practice; the max(0) below is a defensive clamp against malformed input rather than a real code path.

Implementations§

Source§

impl PtsUnroller

Source

pub fn seeded(origin: u64) -> Self

An unroller seeded at origin (wrap-unrolled 90 kHz ticks).

Examples found in repository?
examples/scte35_to_hls.rs (line 45)
14fn main() -> Result<(), Box<dyn std::error::Error>> {
15    // Real Unified Streaming splice: ID 2002, out-of-network, break_duration 24 s.
16    let hex = "FC302100000000000000FFF01005000007D27FEF7F7E0020F580C0000000000088B9661D";
17    let raw = broadcast_common::hex::hex_decode(hex).unwrap();
18
19    // Wall-clock anchor: assume PTS 0 == 2024-01-15T12:00:00.000Z (ms since epoch).
20    let utc_epoch_ms: i64 = 1_705_320_000_000; // 2024-01-15 12:00:00 UTC
21    let anchor = TimeAnchor {
22        pts_90k: 0,
23        utc_epoch_ms,
24    };
25
26    let mut timeline = Timeline::new(anchor);
27
28    // Parse the SCTE-35 section and unroll PTS wrap.
29    let event = timeline.push_scte35(&raw).expect("valid splice");
30    let _: &TimedEvent = &event;
31    match &event.source {
32        SourcePayload::Scte35 { raw: original } => {
33            assert_eq!(original, &raw, "the source section is carried verbatim");
34        }
35        other => println!("source payload: {other:?}"),
36    }
37
38    // Convert to a DATERANGE.
39    let daterange = timeline.to_daterange(&event).expect("anchor is set");
40    let pure: Result<_, Error> = timed_metadata::convert::scte35_to_daterange(&event, &anchor);
41    assert_eq!(
42        pure.expect("SCTE-35-sourced event").to_tag_line()?,
43        daterange.to_tag_line()?
44    );
45    let mut unroller = PtsUnroller::seeded(0);
46    println!("unrolled PTS: {}", unroller.unroll(90_000));
47
48    println!("Event kind  : {}", event.kind);
49    println!("Event id    : {:?}", event.id);
50    println!(
51        "Duration    : {:?}s",
52        event.duration.map(|d| d.as_seconds_f64())
53    );
54    println!();
55    println!(
56        "{}",
57        daterange.to_tag_line().expect("valid DATERANGE attributes")
58    );
59    Ok(())
60}
Source

pub fn unroll(&mut self, raw33: u64) -> u64

Unroll one raw 33-bit PTS onto this unroller’s ever-growing timeline.

Examples found in repository?
examples/scte35_to_hls.rs (line 46)
14fn main() -> Result<(), Box<dyn std::error::Error>> {
15    // Real Unified Streaming splice: ID 2002, out-of-network, break_duration 24 s.
16    let hex = "FC302100000000000000FFF01005000007D27FEF7F7E0020F580C0000000000088B9661D";
17    let raw = broadcast_common::hex::hex_decode(hex).unwrap();
18
19    // Wall-clock anchor: assume PTS 0 == 2024-01-15T12:00:00.000Z (ms since epoch).
20    let utc_epoch_ms: i64 = 1_705_320_000_000; // 2024-01-15 12:00:00 UTC
21    let anchor = TimeAnchor {
22        pts_90k: 0,
23        utc_epoch_ms,
24    };
25
26    let mut timeline = Timeline::new(anchor);
27
28    // Parse the SCTE-35 section and unroll PTS wrap.
29    let event = timeline.push_scte35(&raw).expect("valid splice");
30    let _: &TimedEvent = &event;
31    match &event.source {
32        SourcePayload::Scte35 { raw: original } => {
33            assert_eq!(original, &raw, "the source section is carried verbatim");
34        }
35        other => println!("source payload: {other:?}"),
36    }
37
38    // Convert to a DATERANGE.
39    let daterange = timeline.to_daterange(&event).expect("anchor is set");
40    let pure: Result<_, Error> = timed_metadata::convert::scte35_to_daterange(&event, &anchor);
41    assert_eq!(
42        pure.expect("SCTE-35-sourced event").to_tag_line()?,
43        daterange.to_tag_line()?
44    );
45    let mut unroller = PtsUnroller::seeded(0);
46    println!("unrolled PTS: {}", unroller.unroll(90_000));
47
48    println!("Event kind  : {}", event.kind);
49    println!("Event id    : {:?}", event.id);
50    println!(
51        "Duration    : {:?}s",
52        event.duration.map(|d| d.as_seconds_f64())
53    );
54    println!();
55    println!(
56        "{}",
57        daterange.to_tag_line().expect("valid DATERANGE attributes")
58    );
59    Ok(())
60}

Trait Implementations§

Source§

impl Debug for PtsUnroller

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PtsUnroller

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.