Skip to main content

moq_mux/catalog/msf/
mod.rs

1//! MSF catalog.
2//!
3//! The IETF MoQT Streaming Format catalog, served on the `catalog`
4//! track. moq-mux subscribes here but doesn't publish; [`Consumer`]
5//! reads MSF and converts it to a [`Catalog<E>`](crate::catalog::hang::Catalog)
6//! on the fly so the rest of the pipeline only sees one shape. Publishing is
7//! the hang producer's job (it writes both tracks).
8
9mod consumer;
10
11pub use consumer::Consumer;
12
13#[cfg(test)]
14pub(crate) use consumer::from_msf;
15
16/// Whether an MSF `namespace` names the catalog's own broadcast at `base`.
17///
18/// MSF namespaces are absolute, but each side sees paths under its own connection root. Draft
19/// catalogs repeat the publisher's full namespace on every track, so a namespace that matches
20/// the catalog's path on whole trailing segments is the catalog seen from a different root.
21pub(crate) fn names_catalog(namespace: &moq_net::Path, base: &moq_net::Path) -> bool {
22	if namespace == base {
23		return true;
24	}
25	let namespace: Vec<_> = namespace.parts().collect();
26	let base: Vec<_> = base.parts().collect();
27	!namespace.is_empty() && !base.is_empty() && (namespace.ends_with(&base) || base.ends_with(&namespace))
28}
29
30/// MSF catalog decoding errors.
31#[derive(Debug, Clone, thiserror::Error)]
32#[non_exhaustive]
33pub enum Error {
34	/// The namespace cannot be represented by a relative broadcast reference.
35	#[error("MSF track {name:?} namespace {namespace:?} cannot be referenced from the catalog")]
36	UnresolvableNamespace {
37		/// The track name.
38		name: String,
39		/// The namespace that cannot be resolved.
40		namespace: String,
41	},
42
43	/// The catalog frame is not valid UTF-8.
44	#[error("MSF catalog frame is not valid UTF-8")]
45	InvalidUtf8,
46
47	/// The catalog frame cannot be decoded as an MSF catalog.
48	#[error("failed to parse MSF catalog frame")]
49	ParseFrame,
50
51	/// The named CMAF track has no initialization data.
52	#[error("MSF CMAF track {0:?} missing init_data")]
53	MissingCmafInit(String),
54
55	/// The named track has malformed initialization data.
56	#[error("MSF track {0:?} has malformed init_data")]
57	MalformedInitData(String),
58
59	/// The named video track has no codec identifier.
60	#[error("MSF video track {0:?} missing codec")]
61	MissingVideoCodec(String),
62
63	/// The named audio track has no codec identifier.
64	#[error("MSF audio track {0:?} missing codec")]
65	MissingAudioCodec(String),
66
67	/// The track's packaging cannot be converted without discarding it.
68	#[error("MSF track {name:?} has unsupported packaging {packaging:?}")]
69	UnsupportedPackaging {
70		/// The track name.
71		name: String,
72		/// The unsupported packaging identifier.
73		packaging: String,
74	},
75
76	/// The named text track has no codec identifier.
77	#[error("MSF text track {0:?} missing codec")]
78	MissingTextCodec(String),
79
80	/// The named video track has an invalid codec identifier.
81	#[error("MSF video track {name:?} has invalid codec {codec:?}")]
82	InvalidVideoCodec {
83		/// The video track name.
84		name: String,
85		/// The invalid codec identifier.
86		codec: String,
87	},
88
89	/// The named audio track has an invalid codec identifier.
90	#[error("MSF audio track {name:?} has invalid codec {codec:?}")]
91	InvalidAudioCodec {
92		/// The audio track name.
93		name: String,
94		/// The invalid codec identifier.
95		codec: String,
96	},
97
98	/// The named audio track has neither explicit audio parameters nor initialization data.
99	#[error("MSF audio track {0:?} omits samplerate/channelConfig and has no init_data to derive from")]
100	MissingAudioParams(String),
101
102	/// The track packaging cannot supply the missing audio parameters.
103	#[error("MSF audio track {name:?} packaging {packaging:?} is unsupported for parameter derivation")]
104	UnsupportedDerivationPackaging {
105		/// The audio track name.
106		name: String,
107		/// The packaging identifier that cannot supply audio parameters.
108		packaging: String,
109	},
110
111	/// The named audio track has a malformed AudioSpecificConfig.
112	#[error("MSF audio track {0:?} has malformed AudioSpecificConfig")]
113	MalformedAac(String),
114
115	/// The named audio track has a malformed OpusHead.
116	#[error("MSF audio track {0:?} has malformed OpusHead")]
117	MalformedOpus(String),
118
119	/// The named audio track has malformed FLAC STREAMINFO.
120	#[error("MSF audio track {0:?} has malformed FLAC STREAMINFO")]
121	MalformedFlac(String),
122
123	/// The named audio track has bytes after its OpusHead.
124	#[error("MSF audio track {0:?} OpusHead has trailing bytes")]
125	OpusTrailingBytes(String),
126
127	/// The named audio track uses a codec with no initialization data parser.
128	#[error("MSF audio track {0:?} omits samplerate/channelConfig; codec has no init_data parser")]
129	UnsupportedDerivationCodec(String),
130
131	/// The named track has a malformed initialization segment.
132	#[error("MSF track {0:?} init segment is malformed")]
133	MalformedInitSegment(String),
134
135	/// The named track has no moov box in its initialization segment.
136	#[error("MSF track {0:?} init segment missing moov")]
137	MissingInitMoov(String),
138
139	/// The named audio track has no audio sample entry to supply its audio parameters.
140	#[error("MSF audio track {0:?} CMAF init has no audio sample entry to derive samplerate/channelConfig from")]
141	MissingAudioSampleEntry(String),
142}
143
144/// A result using this module's error type.
145pub type Result<T> = std::result::Result<T, Error>;