use alloc::format;
use alloc::string::String;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum ResourceId {
Init,
Part {
msn: u64,
part: u64,
},
Segment {
msn: u64,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BlockingReload {
pub msn: u64,
pub part: Option<u64>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum Action {
FetchPlaylist {
url: String,
blocking: Option<BlockingReload>,
skip: bool,
},
FetchResource {
id: ResourceId,
url: String,
byte_range: Option<(u64, u64)>,
},
WaitMs(u64),
}
impl Action {
pub fn playlist_request_url(&self) -> Option<String> {
match self {
Action::FetchPlaylist {
url,
blocking,
skip,
} => {
let mut u = url.clone();
if let Some(b) = blocking {
u = super::url::append_query(&u, &format!("_HLS_msn={}", b.msn));
if let Some(part) = b.part {
u = super::url::append_query(&u, &format!("_HLS_part={part}"));
}
}
if *skip {
u = super::url::append_query(&u, "_HLS_skip=YES");
}
Some(u)
}
Action::FetchResource { .. } | Action::WaitMs(_) => None,
}
}
}