pub struct Timeline { /* private fields */ }Expand description
A stateful conversion session.
Implementations§
Source§impl Timeline
impl Timeline
Sourcepub fn new(anchor: TimeAnchor) -> Self
pub fn new(anchor: TimeAnchor) -> Self
New session with a wall-clock anchor (the one constructor; start from
Timeline::default for a session that is anchored later with
Timeline::set_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 = 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
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
examples/scte35_to_dash.rs (line 29)
20fn main() {
21 // Real Unified Streaming splice: ID 2002, out-of-network, break_duration 24 s.
22 let hex = "FC302100000000000000FFF01005000007D27FEF7F7E0020F580C0000000000088B9661D";
23 let raw = broadcast_common::hex::hex_decode(hex).unwrap();
24
25 let anchor = TimeAnchor {
26 pts_90k: 0,
27 utc_epoch_ms: 1_705_320_000_000,
28 };
29 let mut timeline = Timeline::new(anchor);
30 let event = timeline.push_scte35(&raw).expect("valid splice");
31
32 // Build emsg config: 90 kHz timescale, segment-relative delta 0, 24 s duration.
33 let cfg = EmsgConfig::new(
34 timescale(90_000),
35 PresentationTime::Delta(0),
36 2_160_000, // 24s * 90000
37 "34".to_string(), // segmentation_type_id for Provider Ad Start
38 event.id.unwrap_or(0),
39 );
40
41 let emsg_bytes = timeline
42 .to_emsg(&event, &cfg)
43 .expect("SCTE-35-sourced event");
44
45 println!("Event kind : {}", event.kind);
46 println!("Event id : {:?}", event.id);
47 println!("emsg length : {} bytes", emsg_bytes.len());
48 println!();
49 println!(
50 "emsg hex: {}",
51 emsg_bytes
52 .iter()
53 .map(|b| format!("{b:02X}"))
54 .collect::<Vec<_>>()
55 .join("")
56 );
57
58 // Verify round-trip: extract the splice from the emsg and compare.
59 use timed_metadata::convert::emsg_to_scte35;
60 let extracted = emsg_to_scte35(&emsg_bytes).expect("round-trip");
61 assert_eq!(extracted, raw, "splice bytes must survive verbatim");
62 println!();
63 println!("Round-trip verified: splice bytes survive verbatim in emsg message_data.");
64}Sourcepub fn set_anchor(&mut self, anchor: TimeAnchor)
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.
Sourcepub fn push_scte35(&mut self, bytes: &[u8]) -> Result<TimedEvent>
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 = 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
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
examples/scte35_to_dash.rs (line 30)
20fn main() {
21 // Real Unified Streaming splice: ID 2002, out-of-network, break_duration 24 s.
22 let hex = "FC302100000000000000FFF01005000007D27FEF7F7E0020F580C0000000000088B9661D";
23 let raw = broadcast_common::hex::hex_decode(hex).unwrap();
24
25 let anchor = TimeAnchor {
26 pts_90k: 0,
27 utc_epoch_ms: 1_705_320_000_000,
28 };
29 let mut timeline = Timeline::new(anchor);
30 let event = timeline.push_scte35(&raw).expect("valid splice");
31
32 // Build emsg config: 90 kHz timescale, segment-relative delta 0, 24 s duration.
33 let cfg = EmsgConfig::new(
34 timescale(90_000),
35 PresentationTime::Delta(0),
36 2_160_000, // 24s * 90000
37 "34".to_string(), // segmentation_type_id for Provider Ad Start
38 event.id.unwrap_or(0),
39 );
40
41 let emsg_bytes = timeline
42 .to_emsg(&event, &cfg)
43 .expect("SCTE-35-sourced event");
44
45 println!("Event kind : {}", event.kind);
46 println!("Event id : {:?}", event.id);
47 println!("emsg length : {} bytes", emsg_bytes.len());
48 println!();
49 println!(
50 "emsg hex: {}",
51 emsg_bytes
52 .iter()
53 .map(|b| format!("{b:02X}"))
54 .collect::<Vec<_>>()
55 .join("")
56 );
57
58 // Verify round-trip: extract the splice from the emsg and compare.
59 use timed_metadata::convert::emsg_to_scte35;
60 let extracted = emsg_to_scte35(&emsg_bytes).expect("round-trip");
61 assert_eq!(extracted, raw, "splice bytes must survive verbatim");
62 println!();
63 println!("Round-trip verified: splice bytes survive verbatim in emsg message_data.");
64}Sourcepub fn to_daterange(&self, ev: &TimedEvent) -> Result<DateRange>
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 = 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
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}Sourcepub fn to_emsg(&self, ev: &TimedEvent, cfg: &EmsgConfig) -> Result<Vec<u8>>
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 42)
20fn main() {
21 // Real Unified Streaming splice: ID 2002, out-of-network, break_duration 24 s.
22 let hex = "FC302100000000000000FFF01005000007D27FEF7F7E0020F580C0000000000088B9661D";
23 let raw = broadcast_common::hex::hex_decode(hex).unwrap();
24
25 let anchor = TimeAnchor {
26 pts_90k: 0,
27 utc_epoch_ms: 1_705_320_000_000,
28 };
29 let mut timeline = Timeline::new(anchor);
30 let event = timeline.push_scte35(&raw).expect("valid splice");
31
32 // Build emsg config: 90 kHz timescale, segment-relative delta 0, 24 s duration.
33 let cfg = EmsgConfig::new(
34 timescale(90_000),
35 PresentationTime::Delta(0),
36 2_160_000, // 24s * 90000
37 "34".to_string(), // segmentation_type_id for Provider Ad Start
38 event.id.unwrap_or(0),
39 );
40
41 let emsg_bytes = timeline
42 .to_emsg(&event, &cfg)
43 .expect("SCTE-35-sourced event");
44
45 println!("Event kind : {}", event.kind);
46 println!("Event id : {:?}", event.id);
47 println!("emsg length : {} bytes", emsg_bytes.len());
48 println!();
49 println!(
50 "emsg hex: {}",
51 emsg_bytes
52 .iter()
53 .map(|b| format!("{b:02X}"))
54 .collect::<Vec<_>>()
55 .join("")
56 );
57
58 // Verify round-trip: extract the splice from the emsg and compare.
59 use timed_metadata::convert::emsg_to_scte35;
60 let extracted = emsg_to_scte35(&emsg_bytes).expect("round-trip");
61 assert_eq!(extracted, raw, "splice bytes must survive verbatim");
62 println!();
63 println!("Round-trip verified: splice bytes survive verbatim in emsg message_data.");
64}Trait Implementations§
Auto Trait Implementations§
impl Forget for Timeline
impl Freeze for Timeline
impl Move for Timeline
impl RefUnwindSafe for Timeline
impl Send for Timeline
impl Sync for Timeline
impl Unpin for Timeline
impl UnsafeUnpin for Timeline
impl UnwindSafe for Timeline
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more