playout-runtime 0.9.0

Sans-IO linear channel playout: a schedule model (programme/ad/slate), transition planning across a join (PTS-rebase offset + discontinuity detection), and SCTE-35 splice_insert() emission points built with scte35-splice. No HTTP, no tokio, no transcoding.
Documentation
//! Sans-IO linear channel playout: a schedule of programmes, ads and slates,
//! the plan for each join between two sources, and the SCTE 35
//! `splice_insert()` each break edge implies.
//!
//! A channel is an ordered [`Schedule`]; [`next_transition`] finds the next
//! join and plans it: the channel-timeline instant, the PTS-rebase offset
//! that lands the incoming source's clock continuously on the channel
//! timeline (unwrapping a 33-bit source PTS when asked), and whether a codec
//! configuration change must be signalled as a discontinuity.
//! [`build_splice_insert`] turns a break edge into an ANSI/SCTE 35 2023r1
//! `splice_insert()` (§9.7.3, Table 10) whose splice time is conditioned
//! against real boundaries by `ssai-runtime`, and [`to_section`] wraps it in
//! a clear `splice_info_section` built by `scte35-splice`.
//!
//! The schedule is an in-memory model of this crate (no wire format, and
//! SCTE 224 is deliberately not adopted). The crate computes numbers and
//! cues only: `transmux` applies a rebase to samples, a playlist writer acts
//! on a discontinuity, and the caller owns the clock and the media. No HTTP,
//! no async runtime, no transcoding; `no_std` + `alloc` without `std`.
//!
//! # Quickstart
//!
//! Schedule a programme and a 30 s ad, plan the join, and build the cue that
//! enters the break:
//!
//! ```rust
//! use broadcast_common::clock33::Clock33;
//! use broadcast_core::timescale::Timescale;
//! use playout_runtime::{
//!     BreakEdge, CodecConfigId, EntryKind, Playhead, Schedule, ScheduleEntry,
//!     build_splice_insert, next_transition,
//! };
//! use std::time::Duration;
//!
//! let mut schedule = Schedule::new();
//! schedule
//!     .push(ScheduleEntry {
//!         id: "news".into(),
//!         kind: EntryKind::Programme,
//!         planned_start: 0,
//!         source_start_pts: 0,
//!         codec_config: CodecConfigId(1),
//!     })
//!     .unwrap();
//! schedule
//!     .push(ScheduleEntry {
//!         id: "ad".into(),
//!         kind: EntryKind::Ad,
//!         planned_start: 54_000_000,
//!         source_start_pts: 5_000,
//!         codec_config: CodecConfigId(2),
//!     })
//!     .unwrap();
//!
//! let t = next_transition(&schedule, Playhead::new(0, Timescale::MICROS)).unwrap();
//! assert_eq!(t.plan.at_pts, 54_000_000);
//! assert!(t.plan.discontinuity);
//! assert_eq!(t.plan.rebase(5_000), Some(54_000_000));
//!
//! let clock = |ticks| Clock33::try_new(ticks).unwrap();
//! let (point, insert) = build_splice_insert(
//!     BreakEdge::Enter,
//!     1,
//!     clock(t.plan.at_pts),
//!     &[clock(53_998_000), clock(54_003_000)],
//!     Duration::from_millis(60),
//!     Some(Duration::from_secs(30)),
//! )
//! .unwrap();
//! assert_eq!(point.snapped_pts, clock(53_998_000));
//! assert!(insert.out_of_network_indicator);
//! ```
//!
//! # How do I...
//!
//! - Build a channel schedule of programmes, ads and slates: [`Schedule`],
//!   [`ScheduleEntry`], [`EntryKind`], `examples/schedule_and_transition.rs`.
//! - Walk every join the schedule implies, with its rebase offset and
//!   discontinuity: [`next_transition`], [`Playhead`],
//!   `examples/schedule_and_transition.rs`.
//! - Plan the join between two given entries: [`TransitionPlan::plan`],
//!   `examples/rebase_and_return.rs`.
//! - Put an incoming source's timestamps on the channel timeline, including a
//!   33-bit PTS that wraps: [`TransitionPlan::rebase`],
//!   [`TransitionPlan::rebase_wrapped`], `examples/rebase_and_return.rs`.
//! - Ask which entry is on air at an instant: [`Schedule::active_at`],
//!   `examples/rebase_and_return.rs`.
//! - Emit the `splice_insert()` that enters a break, snapped to a real
//!   keyframe, and serialise it: [`build_splice_insert`], [`BreakEdge`],
//!   [`to_section`], `examples/emit_splice_from_real_cue.rs`.
//! - Emit the `splice_insert()` that returns to the network:
//!   [`build_splice_insert`] with [`BreakEdge::Return`],
//!   `examples/rebase_and_return.rs`.
//!
//! # Modules
//!
//! - [`schedule`]: the schedule model and the playhead.
//! - [`transition`]: join planning and PTS rebasing.
//! - [`scte35`]: the `splice_insert()` a break edge implies.
//! - [`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 schedule, transition and decision types.
//!
//! # Spec citations
//!
//! ANSI/SCTE 35 2023r1 §9.7.3 Table 10 (`splice_insert()`) and §9.8
//! (`splice_time()`, `break_duration()`), transcribed in
//! `private/specs-verified/scte/scte35-splice/`.
#![no_std]
#![forbid(unsafe_code)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![deny(missing_docs)]

extern crate alloc;

#[cfg(doctest)]
#[doc = include_str!("../README.md")]
struct ReadmeDoctests;

pub mod error;
pub mod schedule;
pub mod scte35;
pub mod transition;

pub use error::{Error, Result};
pub use schedule::{CodecConfigId, EntryKind, Playhead, Schedule, ScheduleEntry};
pub use scte35::{BreakEdge, build_splice_insert, to_section};
pub use transition::{PlannedTransition, TransitionPlan, next_transition};