use broadcast_common::impl_spec_display;
use super::model::Descriptor;
pub const SCHEME_ROLE: &str = "urn:mpeg:dash:role:2011";
pub const SCHEME_PERIOD_CONTINUITY: &str = "urn:mpeg:dash:period-continuity:2015";
pub const SCHEME_PERIOD_CONNECTIVITY: &str = "urn:mpeg:dash:period-connectivity:2015";
pub const SCHEME_RESET: &str = "urn:mpeg:dash:reset:2016";
pub const SCHEME_URLPARAM: &str = "urn:mpeg:dash:urlparam:2014";
pub const SCHEME_URLPARAM_2016: &str = "urn:mpeg:dash:urlparam:2016";
pub const SCHEME_LAST_SEGMENT_NUMBER: &str = "http://dashif.org/guidelines/last-segment-number";
pub const XLINK_RESOLVE_TO_ZERO: &str = "urn:mpeg:dash:resolve-to-zero:2013";
pub const SCHEME_MP4_PROTECTION: &str = "urn:mpeg:dash:mp4protection:2011";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Role {
Caption,
Subtitle,
Main,
Alternate,
Supplementary,
Commentary,
Dub,
Description,
Sign,
Metadata,
EnhancedAudioIntelligibility,
Emergency,
ForcedSubtitle,
EasyReader,
Karaoke,
Other,
}
impl Role {
#[must_use]
pub fn from_value(value: &str) -> Self {
match value {
"caption" => Self::Caption,
"subtitle" => Self::Subtitle,
"main" => Self::Main,
"alternate" => Self::Alternate,
"supplementary" => Self::Supplementary,
"commentary" => Self::Commentary,
"dub" => Self::Dub,
"description" => Self::Description,
"sign" => Self::Sign,
"metadata" => Self::Metadata,
"enhanced-audio-intelligibility" => Self::EnhancedAudioIntelligibility,
"emergency" => Self::Emergency,
"forced-subtitle" => Self::ForcedSubtitle,
"easyreader" => Self::EasyReader,
"karaoke" => Self::Karaoke,
_ => Self::Other,
}
}
#[must_use]
pub fn name(&self) -> &'static str {
match self {
Self::Caption => "caption",
Self::Subtitle => "subtitle",
Self::Main => "main",
Self::Alternate => "alternate",
Self::Supplementary => "supplementary",
Self::Commentary => "commentary",
Self::Dub => "dub",
Self::Description => "description",
Self::Sign => "sign",
Self::Metadata => "metadata",
Self::EnhancedAudioIntelligibility => "enhanced-audio-intelligibility",
Self::Emergency => "emergency",
Self::ForcedSubtitle => "forced-subtitle",
Self::EasyReader => "easyreader",
Self::Karaoke => "karaoke",
Self::Other => "other",
}
}
}
impl_spec_display!(Role);
pub fn roles(descriptors: &[Descriptor]) -> impl Iterator<Item = Role> + '_ {
descriptors
.iter()
.filter(|d| d.scheme_id_uri == SCHEME_ROLE)
.filter_map(|d| d.value.as_deref())
.map(Role::from_value)
}
#[must_use]
pub fn find<'a>(descriptors: &'a [Descriptor], scheme: &str) -> Option<&'a Descriptor> {
descriptors.iter().find(|d| d.scheme_id_uri == scheme)
}
pub const UNDERSTOOD_ESSENTIAL: &[&str] = &[
SCHEME_PERIOD_CONTINUITY,
SCHEME_PERIOD_CONNECTIVITY,
SCHEME_RESET,
SCHEME_URLPARAM,
SCHEME_LAST_SEGMENT_NUMBER,
];
#[must_use]
pub fn essential_understood(descriptor: &Descriptor) -> bool {
UNDERSTOOD_ESSENTIAL.contains(&descriptor.scheme_id_uri.as_str())
}
#[cfg(test)]
mod scheme_tests {
use super::*;
#[test]
fn scheme_constants_are_the_registered_uris() {
assert_eq!(SCHEME_URLPARAM_2016, "urn:mpeg:dash:urlparam:2016");
assert_eq!(SCHEME_MP4_PROTECTION, "urn:mpeg:dash:mp4protection:2011");
assert_ne!(SCHEME_URLPARAM_2016, SCHEME_URLPARAM);
}
#[test]
fn the_2016_urlparam_scheme_is_not_an_understood_essential_property() {
let d = Descriptor {
scheme_id_uri: SCHEME_URLPARAM_2016.into(),
..Descriptor::default()
};
assert!(!essential_understood(&d));
let known = Descriptor {
scheme_id_uri: SCHEME_URLPARAM.into(),
..Descriptor::default()
};
assert!(essential_understood(&known));
}
}