1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! Sans-IO server-side ad insertion (SSAI) session core for SCTE 35 cues:
//! where a break splices, which break each viewer session is in, and what
//! that viewer's HLS playlist says about it.
//!
//! A cue's nominal splice time is conditioned against the real segment or
//! keyframe boundaries, with the drift reported rather than hidden; an
//! [`AdDecisionProvider`] the caller implements chooses the interstitial
//! content; a bounded [`SessionStore`] keeps one small [`BreakState`] per
//! viewer; and the playlist layer renders an HLS Interstitial
//! (`EXT-X-DATERANGE` with `CLASS="com.apple.hls.interstitial"`, Appendix D
//! of the HLS draft-pantos-hls-rfc8216bis dated 1 May 2026) into each
//! viewer's media playlist. Cue semantics follow ANSI/SCTE 35 2023r1, but the
//! core takes plain 90 kHz ticks; decoding the cue is `scte35-splice`.
//!
//! It builds on `broadcast-core`, `broadcast-common` (the 33-bit clock) and
//! `broadcast-hls` (the playlist and `EXT-X-DATERANGE` model); a live origin
//! such as `multimux` drives it, and `playout-runtime` reuses its splice-point
//! conditioning. There is no HTTP client, no VAST or VMAP, no clock read and
//! no media splicing (that is `transmux`). `no_std` + `alloc` without `std`.
//!
//! # Quickstart
//!
//! Condition a cue, track the break for one viewer, and render the
//! interstitial tag for their playlist:
//!
//! ```rust
//! use broadcast_common::clock33::Clock33;
//! use ssai_runtime::{
//! AdBreakDecision, BreakState, InterstitialDateRange, SessionLimits, SessionStore,
//! condition_splice_point,
//! };
//! use std::time::Duration;
//!
//! let clock = |ticks| Clock33::try_new(ticks).unwrap();
//! let boundaries = [clock(810_000), clock(897_000), clock(904_500)];
//! let point =
//! condition_splice_point(clock(900_000), &boundaries, Duration::from_millis(60)).unwrap();
//! assert_eq!(point.snapped_pts, clock(897_000));
//! assert_eq!(point.delta_ticks, 3_000);
//!
//! let decision = AdBreakDecision::single_asset("ad-1", "https://ads.example/ad-1.m3u8");
//! let mut store = SessionStore::new(SessionLimits {
//! max_sessions: 1024,
//! max_decision_items: 16,
//! max_decision_text_bytes: 4096,
//! });
//! store
//! .begin_break("viewer-42", BreakState::new(decision.clone(), point))
//! .unwrap();
//!
//! let tag = InterstitialDateRange::from_decision(&decision, "2026-01-01T00:00:10.000Z", Some(30.0))
//! .to_tag_line()
//! .unwrap();
//! assert!(tag.contains("CLASS=\"com.apple.hls.interstitial\""));
//! ```
//!
//! # How do I...
//!
//! - Snap a cue's splice time to a real boundary and see the drift:
//! [`condition_splice_point`], [`ConditionedSplicePoint::delta_ticks`],
//! `examples/condition_real_cue.rs`.
//! - Plug in my ad decision service: [`AdDecisionProvider`],
//! [`BreakContext`], [`AdBreakDecision`], `examples/session_playlist.rs`.
//! - Track which break a viewer session is in: [`SessionStore`],
//! [`BreakState`], [`SessionLimits`], `examples/session_playlist.rs`.
//! - Render one viewer's playlist with the interstitial tag:
//! [`render_session_playlist`], [`InterstitialDateRange`],
//! `examples/session_playlist.rs`.
//! - Render the shared playlist once and splice each viewer's tag in:
//! [`SessionPlaylistBase`], `examples/many_viewers.rs`.
//! - Point a break at an asset list instead of one asset, and set snap
//! rules: [`AssetSource`], [`SnapMode`], `examples/many_viewers.rs`.
//! - Resume, end and expire breaks on my own clock:
//! [`SessionStore::resume`], [`SessionStore::end`],
//! [`SessionStore::advance`], [`SessionStore::expire_idle`],
//! `examples/many_viewers.rs`.
//! - Read an interstitial tag back: [`InterstitialDateRange::parse_tag_line`],
//! `examples/many_viewers.rs`.
//!
//! # Modules
//!
//! - [`splice`]: splice-point conditioning on the 33-bit PTS circle.
//! - [`decision`]: the ad-decision extension point and the decision model.
//! - [`session`]: the bounded per-session break store.
//! - [`playlist`]: the Interstitial `EXT-X-DATERANGE` and per-viewer
//! playlist rendering.
//! - [`error`]: [`Error`] and [`Result`].
//!
//! # Feature flags
//!
//! - `std` (default): link the standard library; without it the crate is
//! `no_std` + `alloc`.
//! - `serde`: serde derives on the decision and break-state types.
//!
//! # Spec citations
//!
//! draft-pantos-hls-rfc8216bis Appendix D §D.2 and §4.4.5.1
//! (`private/specs-verified/hls/ietf/rfc8216bis-interstitials.md`); ANSI/SCTE
//! 35 2023r1 `splice_insert()` and `break_duration()`
//! (`private/specs-verified/scte/scte35-splice/`).
extern crate alloc;
;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;