Skip to main content

moq_ext_adaptive/
lib.rs

1//! Rendition choice and decoder handover for adaptive video playback.
2//!
3//! This crate is pure logic. It does no I/O, spawns nothing, and depends on
4//! neither tokio nor any media or transport type. Every method that depends on
5//! time takes a [`std::time::Instant`] argument, so the tests drive the state
6//! machines with a fake clock and run in microseconds.
7//!
8//! There are two state machines, which a player wires together:
9//!
10//! - [`Bound`] decides which rendition of a ladder should play. Each pass it
11//!   gets the ranked ladder ([`Rung`]s, best first), the caller's
12//!   [`Constraints`] and a [`NetworkSample`], and returns the best rung the
13//!   link carries. Time enters only as hysteresis, tuned by [`Adaptation`].
14//!   [`choose`] wraps it with the [`RenditionMode`] (automatic, pinned or off),
15//!   and [`Backoffs`] tracks renditions whose decoders failed. [`step_down`]
16//!   tells whether a switch moves down the ladder.
17//! - [`Switcher`] hands the picture from one decoder to the next. It tracks one
18//!   incumbent and at most one replacement, and takes over once the replacement
19//!   has decoded a picture close to the incumbent's playhead, or has run out of
20//!   patience. The decoders themselves are opaque type parameters.
21//!
22//! The async loops that feed these machines, with their channels and timers,
23//! live in the player.
24
25#![forbid(unsafe_code)]
26
27mod bound;
28mod network;
29mod select;
30mod switch;
31
32pub use self::{
33    bound::{Adaptation, Bound, Constraints, Rung},
34    network::NetworkSample,
35    select::{Backoffs, Choice, PinProblem, RenditionMode, best, choose, step_down},
36    switch::{Abandoned, CATCH_UP_PATIENCE, CATCH_UP_SLACK, Outcome, Switcher, Target, Verdict},
37};