Skip to main content

hang/catalog/
reference.rs

1use super::{AudioConfig, BinaryConfig, JsonConfig, TextConfig, VideoConfig};
2
3/// Where a catalog entry's track lives: the broadcast that publishes it and its name there.
4///
5/// An entry's key in the catalog is its ID. The track it names is `track` when set and the ID
6/// otherwise, in `broadcast` when set and the catalog's own broadcast otherwise. Every reader
7/// subscribes through [`track`](Self::track) so the two never diverge.
8pub trait Reference {
9	/// The broadcast publishing the track, relative to the catalog's; `None` is the catalog's own.
10	fn broadcast(&self) -> Option<&moq_net::path::Relative>;
11
12	/// The track's name in its broadcast, given this entry's ID.
13	fn track<'a>(&'a self, id: &'a str) -> &'a str;
14}
15
16macro_rules! reference {
17	($($config:ty),*) => {$(
18		impl Reference for $config {
19			fn broadcast(&self) -> Option<&moq_net::path::Relative> {
20				self.broadcast.as_ref()
21			}
22
23			fn track<'a>(&'a self, id: &'a str) -> &'a str {
24				self.track.as_deref().unwrap_or(id)
25			}
26		}
27	)*};
28}
29
30reference!(VideoConfig, AudioConfig, TextConfig, JsonConfig, BinaryConfig);
31
32/// moq-hang-04 for a `track` other than the ID: a reader that ignores it subscribes to the ID, a
33/// different track.
34pub(crate) fn renamed_version(config: &impl Reference, id: &str) -> Option<u64> {
35	(config.track(id) != id).then_some(4)
36}