use broadcast_common::impl_spec_display;
use crate::timing::utc_timing::UtcScheme;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RepId(pub(crate) u32);
impl RepId {
#[must_use]
pub fn get(self) -> u32 {
self.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
pub enum ResourceId {
Init {
rep: RepId,
},
Index {
rep: RepId,
},
Segment {
rep: RepId,
number: u64,
},
}
impl ResourceId {
#[must_use]
pub fn rep(&self) -> RepId {
match self {
Self::Init { rep } | Self::Index { rep } | Self::Segment { rep, .. } => *rep,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct UtcId(pub(crate) u32);
impl UtcId {
#[must_use]
pub fn get(self) -> u32 {
self.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum UtcMethod {
Get,
Head,
}
impl UtcMethod {
#[must_use]
pub fn name(&self) -> &'static str {
match self {
Self::Get => "GET",
Self::Head => "HEAD",
}
}
}
impl_spec_display!(UtcMethod);
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[non_exhaustive]
pub struct MpdValidators {
pub etag: Option<String>,
pub last_modified: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Action {
FetchMpd {
url: String,
validators: MpdValidators,
},
FetchUtcTiming {
id: UtcId,
scheme: UtcScheme,
url: String,
method: UtcMethod,
},
FetchInit {
id: ResourceId,
url: String,
byte_range: Option<(u64, u64)>,
},
FetchIndex {
id: ResourceId,
url: String,
byte_range: Option<(u64, u64)>,
},
FetchSegment {
id: ResourceId,
url: String,
byte_range: Option<(u64, u64)>,
},
}
impl Action {
#[must_use]
pub fn id(&self) -> Option<ResourceId> {
match self {
Self::FetchMpd { .. } | Self::FetchUtcTiming { .. } => None,
Self::FetchInit { id, .. }
| Self::FetchIndex { id, .. }
| Self::FetchSegment { id, .. } => Some(*id),
}
}
#[must_use]
pub fn url(&self) -> &str {
match self {
Self::FetchMpd { url, .. }
| Self::FetchUtcTiming { url, .. }
| Self::FetchInit { url, .. }
| Self::FetchIndex { url, .. }
| Self::FetchSegment { url, .. } => url,
}
}
#[must_use]
pub fn byte_range(&self) -> Option<(u64, u64)> {
match self {
Self::FetchMpd { .. } | Self::FetchUtcTiming { .. } => None,
Self::FetchInit { byte_range, .. }
| Self::FetchIndex { byte_range, .. }
| Self::FetchSegment { byte_range, .. } => *byte_range,
}
}
}