Skip to main content

Crate ssai_runtime

Crate ssai_runtime 

Source
Expand description

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:

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…

§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/).

Re-exports§

pub use decision::AdBreakDecision;
pub use decision::AdDecisionProvider;
pub use decision::AssetSource;
pub use decision::BreakContext;
pub use decision::RestrictMode;
pub use decision::SnapMode;
pub use error::Error;
pub use error::Result;
pub use playlist::INTERSTITIAL_CLASS;
pub use playlist::InterstitialDateRange;
pub use playlist::SessionPlaylistBase;
pub use playlist::render_session_playlist;
pub use session::BreakState;
pub use session::SessionLimits;
pub use session::SessionStore;
pub use splice::ConditionedSplicePoint;
pub use splice::SnapDirection;
pub use splice::condition_splice_point;

Modules§

decision
Ad-break decision types.
error
Crate error type.
playlist
Per-session HLS Interstitial playlist rendering.
session
Per-session ad-break state.
splice
Splice-point conditioning: aligning a SCTE-35 cue’s target presentation time (splice_time().pts_time, ANSI/SCTE 35 2023r1 §9.8.1, or a DASH emsg’s presentation_time) against the primary content’s actual segment/keyframe boundaries.