use std::task::Poll;
use crate::container::{Container as ContainerTrait, Frame, fmp4, legacy, loc};
pub enum Container {
Legacy,
Cmaf(fmp4::Wire),
Loc,
}
impl TryFrom<&hang::catalog::Container> for Container {
type Error = crate::Error;
fn try_from(container: &hang::catalog::Container) -> Result<Self, Self::Error> {
match container {
hang::catalog::Container::Legacy => Ok(Self::Legacy),
hang::catalog::Container::Cmaf { init, .. } => Ok(Self::Cmaf(fmp4::Wire::from_init(init)?)),
hang::catalog::Container::Loc => Ok(Self::Loc),
}
}
}
impl ContainerTrait for Container {
type Error = crate::Error;
fn write(&self, group: &mut moq_net::GroupProducer, frames: &[Frame]) -> Result<(), Self::Error> {
match self {
Self::Legacy => legacy::Wire.write(group, frames),
Self::Cmaf(cmaf) => cmaf.write(group, frames).map_err(Into::into),
Self::Loc => loc::Wire.write(group, frames),
}
}
fn poll_read(
&self,
group: &mut moq_net::GroupConsumer,
waiter: &kio::Waiter,
) -> Poll<Result<Option<Vec<Frame>>, Self::Error>> {
match self {
Self::Legacy => legacy::Wire.poll_read(group, waiter),
Self::Cmaf(cmaf) => cmaf.poll_read(group, waiter).map(|r| r.map_err(Into::into)),
Self::Loc => loc::Wire.poll_read(group, waiter),
}
}
}