Skip to main content

Timeline

Struct Timeline 

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

A stateful conversion session.

Implementations§

Source§

impl Timeline

Source

pub fn new() -> Self

New session with no anchor.

Source

pub fn with_anchor(anchor: TimeAnchor) -> Self

New session with a wall-clock anchor.

Examples found in repository?
examples/scte35_to_hls.rs (line 26)
14fn main() {
15    // Real Unified Streaming splice: ID 2002, out-of-network, break_duration 24 s.
16    let hex = "FC302100000000000000FFF01005000007D27FEF7F7E0020F580C0000000000088B9661D";
17    let raw = 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::with_anchor(anchor);
27
28    // Parse the SCTE-35 section and unroll PTS wrap.
29    let event = timeline.push_scte35(&raw).expect("valid splice");
30
31    // Convert to a DATERANGE.
32    let daterange = timeline.to_daterange(&event).expect("anchor is set");
33
34    println!("Event kind  : {}", event.kind);
35    println!("Event id    : {:?}", event.id);
36    println!(
37        "Duration    : {:?}s",
38        event.duration.map(|d| d.as_seconds_f64())
39    );
40    println!();
41    println!(
42        "{}",
43        daterange.to_tag_line().expect("valid DATERANGE attributes")
44    );
45}
More examples
Hide additional examples
examples/scte35_to_dash.rs (line 24)
15fn main() {
16    // Real Unified Streaming splice: ID 2002, out-of-network, break_duration 24 s.
17    let hex = "FC302100000000000000FFF01005000007D27FEF7F7E0020F580C0000000000088B9661D";
18    let raw = hex::decode(hex).unwrap();
19
20    let anchor = TimeAnchor {
21        pts_90k: 0,
22        utc_epoch_ms: 1_705_320_000_000,
23    };
24    let mut timeline = Timeline::with_anchor(anchor);
25    let event = timeline.push_scte35(&raw).expect("valid splice");
26
27    // Build emsg config: 90 kHz timescale, segment-relative delta 0, 24 s duration.
28    let cfg = EmsgConfig {
29        timescale: 90_000,
30        presentation: PresentationTime::Delta(0),
31        event_duration: 2_160_000, // 24s * 90000
32        value: "34".to_string(),   // segmentation_type_id for Provider Ad Start
33        id: event.id.unwrap_or(0),
34    };
35
36    let emsg_bytes = timeline
37        .to_emsg(&event, &cfg)
38        .expect("SCTE-35-sourced event");
39
40    println!("Event kind  : {}", event.kind);
41    println!("Event id    : {:?}", event.id);
42    println!("emsg length : {} bytes", emsg_bytes.len());
43    println!();
44    println!(
45        "emsg hex: {}",
46        emsg_bytes
47            .iter()
48            .map(|b| format!("{b:02X}"))
49            .collect::<Vec<_>>()
50            .join("")
51    );
52
53    // Verify round-trip: extract the splice from the emsg and compare.
54    use timed_metadata::convert::emsg_to_scte35;
55    let extracted = emsg_to_scte35(&emsg_bytes).expect("round-trip");
56    assert_eq!(extracted, raw, "splice bytes must survive verbatim");
57    println!();
58    println!("Round-trip verified: splice bytes survive verbatim in emsg message_data.");
59}
Source

pub fn set_anchor(&mut self, anchor: TimeAnchor)

Set or replace the wall-clock anchor, keeping the PTS unroll state of the events already pushed.

Source

pub fn push_scte35(&mut self, bytes: &[u8]) -> Result<TimedEvent>

Parse a SCTE-35 section; unroll its PTS into an absolute MediaTime.

Examples found in repository?
examples/scte35_to_hls.rs (line 29)
14fn main() {
15    // Real Unified Streaming splice: ID 2002, out-of-network, break_duration 24 s.
16    let hex = "FC302100000000000000FFF01005000007D27FEF7F7E0020F580C0000000000088B9661D";
17    let raw = 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::with_anchor(anchor);
27
28    // Parse the SCTE-35 section and unroll PTS wrap.
29    let event = timeline.push_scte35(&raw).expect("valid splice");
30
31    // Convert to a DATERANGE.
32    let daterange = timeline.to_daterange(&event).expect("anchor is set");
33
34    println!("Event kind  : {}", event.kind);
35    println!("Event id    : {:?}", event.id);
36    println!(
37        "Duration    : {:?}s",
38        event.duration.map(|d| d.as_seconds_f64())
39    );
40    println!();
41    println!(
42        "{}",
43        daterange.to_tag_line().expect("valid DATERANGE attributes")
44    );
45}
More examples
Hide additional examples
examples/scte35_to_dash.rs (line 25)
15fn main() {
16    // Real Unified Streaming splice: ID 2002, out-of-network, break_duration 24 s.
17    let hex = "FC302100000000000000FFF01005000007D27FEF7F7E0020F580C0000000000088B9661D";
18    let raw = hex::decode(hex).unwrap();
19
20    let anchor = TimeAnchor {
21        pts_90k: 0,
22        utc_epoch_ms: 1_705_320_000_000,
23    };
24    let mut timeline = Timeline::with_anchor(anchor);
25    let event = timeline.push_scte35(&raw).expect("valid splice");
26
27    // Build emsg config: 90 kHz timescale, segment-relative delta 0, 24 s duration.
28    let cfg = EmsgConfig {
29        timescale: 90_000,
30        presentation: PresentationTime::Delta(0),
31        event_duration: 2_160_000, // 24s * 90000
32        value: "34".to_string(),   // segmentation_type_id for Provider Ad Start
33        id: event.id.unwrap_or(0),
34    };
35
36    let emsg_bytes = timeline
37        .to_emsg(&event, &cfg)
38        .expect("SCTE-35-sourced event");
39
40    println!("Event kind  : {}", event.kind);
41    println!("Event id    : {:?}", event.id);
42    println!("emsg length : {} bytes", emsg_bytes.len());
43    println!();
44    println!(
45        "emsg hex: {}",
46        emsg_bytes
47            .iter()
48            .map(|b| format!("{b:02X}"))
49            .collect::<Vec<_>>()
50            .join("")
51    );
52
53    // Verify round-trip: extract the splice from the emsg and compare.
54    use timed_metadata::convert::emsg_to_scte35;
55    let extracted = emsg_to_scte35(&emsg_bytes).expect("round-trip");
56    assert_eq!(extracted, raw, "splice bytes must survive verbatim");
57    println!();
58    println!("Round-trip verified: splice bytes survive verbatim in emsg message_data.");
59}
Source

pub fn to_daterange(&self, ev: &TimedEvent) -> Result<DateRange>

Convert to a DATERANGE (requires an anchor).

Examples found in repository?
examples/scte35_to_hls.rs (line 32)
14fn main() {
15    // Real Unified Streaming splice: ID 2002, out-of-network, break_duration 24 s.
16    let hex = "FC302100000000000000FFF01005000007D27FEF7F7E0020F580C0000000000088B9661D";
17    let raw = 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::with_anchor(anchor);
27
28    // Parse the SCTE-35 section and unroll PTS wrap.
29    let event = timeline.push_scte35(&raw).expect("valid splice");
30
31    // Convert to a DATERANGE.
32    let daterange = timeline.to_daterange(&event).expect("anchor is set");
33
34    println!("Event kind  : {}", event.kind);
35    println!("Event id    : {:?}", event.id);
36    println!(
37        "Duration    : {:?}s",
38        event.duration.map(|d| d.as_seconds_f64())
39    );
40    println!();
41    println!(
42        "{}",
43        daterange.to_tag_line().expect("valid DATERANGE attributes")
44    );
45}
Source

pub fn to_emsg(&self, ev: &TimedEvent, cfg: &EmsgConfig) -> Result<Vec<u8>>

Convert to a serialized SCTE-35 emsg box.

Examples found in repository?
examples/scte35_to_dash.rs (line 37)
15fn main() {
16    // Real Unified Streaming splice: ID 2002, out-of-network, break_duration 24 s.
17    let hex = "FC302100000000000000FFF01005000007D27FEF7F7E0020F580C0000000000088B9661D";
18    let raw = hex::decode(hex).unwrap();
19
20    let anchor = TimeAnchor {
21        pts_90k: 0,
22        utc_epoch_ms: 1_705_320_000_000,
23    };
24    let mut timeline = Timeline::with_anchor(anchor);
25    let event = timeline.push_scte35(&raw).expect("valid splice");
26
27    // Build emsg config: 90 kHz timescale, segment-relative delta 0, 24 s duration.
28    let cfg = EmsgConfig {
29        timescale: 90_000,
30        presentation: PresentationTime::Delta(0),
31        event_duration: 2_160_000, // 24s * 90000
32        value: "34".to_string(),   // segmentation_type_id for Provider Ad Start
33        id: event.id.unwrap_or(0),
34    };
35
36    let emsg_bytes = timeline
37        .to_emsg(&event, &cfg)
38        .expect("SCTE-35-sourced event");
39
40    println!("Event kind  : {}", event.kind);
41    println!("Event id    : {:?}", event.id);
42    println!("emsg length : {} bytes", emsg_bytes.len());
43    println!();
44    println!(
45        "emsg hex: {}",
46        emsg_bytes
47            .iter()
48            .map(|b| format!("{b:02X}"))
49            .collect::<Vec<_>>()
50            .join("")
51    );
52
53    // Verify round-trip: extract the splice from the emsg and compare.
54    use timed_metadata::convert::emsg_to_scte35;
55    let extracted = emsg_to_scte35(&emsg_bytes).expect("round-trip");
56    assert_eq!(extracted, raw, "splice bytes must survive verbatim");
57    println!();
58    println!("Round-trip verified: splice bytes survive verbatim in emsg message_data.");
59}

Trait Implementations§

Source§

impl Debug for Timeline

Source§

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

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

impl Default for Timeline

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.