Skip to main content

dash_runtime/address/
mod.rs

1//! Representation to Segment plan (ISO/IEC 23009-1 5.3.9.2-5.3.9.6).
2//!
3//! [`plan::SegmentPlan`] is a lazy, ordered view of a Representation's Media
4//! Segments: number, media time, duration, URL reference, byte range and, for
5//! dynamic MPDs, availability window. Nothing is materialised per segment
6//! except where the MPD itself lists them (`SegmentList`, `sidx`).
7
8use thiserror::Error;
9
10use crate::error::Unsupported;
11
12pub mod base_index;
13pub mod list;
14pub mod plan;
15pub mod representation;
16pub mod template;
17pub mod timeline;
18
19pub use plan::{DynamicContext, PlanInput, ResourceRef, SegmentPlan, SegmentRef};
20pub use representation::{PlanError, PlanOptions, PlannedRepresentation, plan_representation};
21
22/// Why a Representation's segments cannot be addressed.
23#[derive(Debug, Clone, PartialEq, Eq, Error)]
24#[non_exhaustive]
25pub enum AddressError {
26    /// A template string is invalid (5.3.9.4.4); the Representation is
27    /// dropped.
28    #[error("invalid template `{template}`: {fault}")]
29    InvalidTemplate {
30        /// The template text.
31        template: String,
32        /// What is wrong with it.
33        fault: template::TemplateFault,
34    },
35    /// A feature outside the 0.1 scope.
36    #[error("unsupported: {0}")]
37    Unsupported(Unsupported),
38    /// A template Representation with no `@media`.
39    #[error("SegmentTemplate has no @media")]
40    MissingMediaTemplate,
41    /// A multi-segment list with neither `@duration` nor a timeline.
42    #[error("no @duration or SegmentTimeline to time the segments")]
43    MissingDuration,
44    /// `S@t` smaller than the end of the previous run.
45    #[error("S@t {t} is before the end of the previous run ({floor})")]
46    TimelineNotIncreasing {
47        /// The offending `@t`.
48        t: u64,
49        /// The previous end.
50        floor: u64,
51    },
52    /// `S@n` smaller than the next expected number.
53    #[error("S@n {n} is below the expected next number {expected}")]
54    NumberNotIncreasing {
55        /// The offending `@n`.
56        n: u64,
57        /// The expected number.
58        expected: u64,
59    },
60    /// An `S` with `@d` of zero cannot time a segment (5.3.9.6.1).
61    #[error("S@d is zero")]
62    ZeroSegmentDuration,
63    /// The timeline describes more segments than the bound allows.
64    #[error("timeline describes at least {count_hint} segments")]
65    TimelineTooLong {
66        /// Count reached.
67        count_hint: u64,
68    },
69    /// A `SegmentList` whose URL count and timeline disagree.
70    #[error("SegmentList has {urls} SegmentURL entries but its timeline describes {segments}")]
71    ListTimelineMismatch {
72        /// `SegmentURL` entries.
73        urls: usize,
74        /// Timeline segments.
75        segments: u64,
76    },
77    /// The index bytes are not a usable `sidx`.
78    #[error("sidx: {0}")]
79    Sidx(String),
80    /// Arithmetic overflow on hostile values.
81    #[error("segment arithmetic overflow")]
82    Overflow,
83    /// A SegmentBase Representation whose `sidx` has not been supplied yet.
84    #[error("the Representation index (sidx) is required before its segments can be addressed")]
85    IndexRequired,
86    /// A `SegmentList` entry with no `@media` and no `@mediaRange`.
87    #[error("SegmentURL has neither @media nor @mediaRange")]
88    EmptySegmentUrl,
89}