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 timeline;
17
18pub use broadcast_dash::template;
19
20pub use plan::{DynamicContext, PlanInput, ResourceRef, SegmentPlan, SegmentRef};
21pub use representation::{PlanError, PlanOptions, PlannedRepresentation, plan_representation};
22
23/// Why a Representation's segments cannot be addressed.
24#[derive(Debug, Clone, PartialEq, Eq, Error)]
25#[non_exhaustive]
26pub enum AddressError {
27    /// A template string is invalid (5.3.9.4.4); the Representation is
28    /// dropped.
29    #[error("invalid template `{template}`: {fault}")]
30    InvalidTemplate {
31        /// The template text.
32        template: String,
33        /// What is wrong with it.
34        fault: template::TemplateFault,
35    },
36    /// A template names a `$Number$` or `$Time$` the Representation has no
37    /// value for; rendering it would address the wrong segment.
38    #[error("template `{template}` names {which} but there is no value for it")]
39    MissingTemplateValue {
40        /// The template text.
41        template: String,
42        /// Which identifier (`number`, `time`).
43        which: &'static str,
44    },
45    /// A feature outside the 0.1 scope.
46    #[error("unsupported: {0}")]
47    Unsupported(Unsupported),
48    /// A template Representation with no `@media`.
49    #[error("SegmentTemplate has no @media")]
50    MissingMediaTemplate,
51    /// A multi-segment list with neither `@duration` nor a timeline.
52    #[error("no @duration or SegmentTimeline to time the segments")]
53    MissingDuration,
54    /// `S@t` smaller than the end of the previous run.
55    #[error("S@t {t} is before the end of the previous run ({floor})")]
56    TimelineNotIncreasing {
57        /// The offending `@t`.
58        t: u64,
59        /// The previous end.
60        floor: u64,
61    },
62    /// `S@n` smaller than the next expected number.
63    #[error("S@n {n} is below the expected next number {expected}")]
64    NumberNotIncreasing {
65        /// The offending `@n`.
66        n: u64,
67        /// The expected number.
68        expected: u64,
69    },
70    /// An `S` with `@d` of zero cannot time a segment (5.3.9.6.1).
71    #[error("S@d is zero")]
72    ZeroSegmentDuration,
73    /// The timeline describes more segments than the bound allows.
74    #[error("timeline describes at least {count_hint} segments")]
75    TimelineTooLong {
76        /// Count reached.
77        count_hint: u64,
78    },
79    /// A `SegmentList` whose URL count and timeline disagree.
80    #[error("SegmentList has {urls} SegmentURL entries but its timeline describes {segments}")]
81    ListTimelineMismatch {
82        /// `SegmentURL` entries.
83        urls: usize,
84        /// Timeline segments.
85        segments: u64,
86    },
87    /// The index bytes are not a usable `sidx`.
88    #[error("sidx: {0}")]
89    Sidx(String),
90    /// Arithmetic overflow on hostile values.
91    #[error("segment arithmetic overflow")]
92    Overflow,
93    /// A SegmentBase Representation whose `sidx` has not been supplied yet.
94    #[error("the Representation index (sidx) is required before its segments can be addressed")]
95    IndexRequired,
96    /// A `SegmentList` entry with no `@media` and no `@mediaRange`.
97    #[error("SegmentURL has neither @media nor @mediaRange")]
98    EmptySegmentUrl,
99    /// A Segment addressing kind this core does not plan (a future
100    /// `broadcast-dash` variant), or a template fault it does not classify.
101    #[error("unsupported segment addressing")]
102    UnsupportedFeature,
103}