1use broadcast_common::impl_spec_display;
4use thiserror::Error;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum Limit {
10 InputBytes,
12 Depth,
14 Elements,
16 AttributeBytes,
18 Attributes,
20 Periods,
22 AdaptationSets,
24 Representations,
26 TimelineEntries,
28 BaseUrls,
30 SegmentUrls,
32}
33
34impl Limit {
35 #[must_use]
37 pub fn name(&self) -> &'static str {
38 match self {
39 Self::InputBytes => "input_bytes",
40 Self::Depth => "depth",
41 Self::Elements => "elements",
42 Self::AttributeBytes => "attribute_bytes",
43 Self::Attributes => "attributes",
44 Self::Periods => "periods",
45 Self::AdaptationSets => "adaptation_sets",
46 Self::Representations => "representations",
47 Self::TimelineEntries => "timeline_entries",
48 Self::BaseUrls => "base_urls",
49 Self::SegmentUrls => "segment_urls",
50 }
51 }
52}
53impl_spec_display!(Limit);
54
55impl From<broadcast_common::xml_chars::XmlLimit> for Limit {
56 fn from(limit: broadcast_common::xml_chars::XmlLimit) -> Self {
57 use broadcast_common::xml_chars::XmlLimit;
58 match limit {
59 XmlLimit::Depth => Self::Depth,
60 XmlLimit::Elements => Self::Elements,
61 XmlLimit::AttributeBytes => Self::AttributeBytes,
62 XmlLimit::Attributes => Self::Attributes,
63 _ => Self::InputBytes,
64 }
65 }
66}
67
68impl From<broadcast_common::xml::XmlError> for MpdError {
69 fn from(e: broadcast_common::xml::XmlError) -> Self {
70 use broadcast_common::xml::XmlError;
71 match e {
72 XmlError::InvalidUtf8 { valid_up_to } => Self::InvalidUtf8 { valid_up_to },
73 XmlError::NotWellFormed { position, message } => Self::Xml {
74 pos: position,
75 message,
76 },
77 XmlError::WrongRoot { found } => Self::NotMpd { found },
78 XmlError::Limit(exceeded) => Self::TooLarge {
79 limit: exceeded.limit.into(),
80 max: exceeded.max,
81 },
82 _ => Self::Invalid {
83 what: "document",
84 detail: "unrecognised XML reader failure".to_string(),
85 },
86 }
87 }
88}
89
90#[derive(Debug, Clone, Copy, PartialEq, Eq)]
92#[non_exhaustive]
93pub enum Unsupported {
94 PresentationTypeList,
96 SegmentSequence,
98 DataUrl,
100 OpenEndedRange,
102 HierarchicalSidx,
104 EventXmlPayload,
106 RepresentationBaseChild,
109}
110
111impl Unsupported {
112 #[must_use]
114 pub fn name(&self) -> &'static str {
115 match self {
116 Self::PresentationTypeList => "presentation_type_list",
117 Self::SegmentSequence => "segment_sequence",
118 Self::DataUrl => "data_url",
119 Self::OpenEndedRange => "open_ended_range",
120 Self::HierarchicalSidx => "hierarchical_sidx",
121 Self::EventXmlPayload => "event_xml_payload",
122 Self::RepresentationBaseChild => "representation_base_child",
123 }
124 }
125}
126impl_spec_display!(Unsupported);
127
128#[derive(Debug, Clone, PartialEq, Eq, Error)]
130#[non_exhaustive]
131pub enum MpdError {
132 #[error("MPD is not valid UTF-8 (valid up to byte {valid_up_to})")]
134 InvalidUtf8 {
135 valid_up_to: usize,
137 },
138 #[error("XML error at byte {pos}: {message}")]
141 Xml {
142 pos: usize,
144 message: String,
146 },
147 #[error("document root is not an MPD in the MPD namespace (found `{found}`)")]
149 NotMpd {
150 found: String,
152 },
153 #[error("MPD write failed: {message}")]
155 Write {
156 message: String,
158 },
159 #[error("invalid MPD: {what}: {detail}")]
161 Invalid {
162 what: &'static str,
164 detail: String,
166 },
167 #[error("MPD exceeds the {limit} limit of {max}")]
169 TooLarge {
170 limit: Limit,
172 max: usize,
174 },
175 #[error("unsupported: {0}")]
177 Unsupported(Unsupported),
178}