use super::Producer;
use super::hang::CatalogExt;
pub struct VideoTrack<E: CatalogExt = ()> {
catalog: Producer<E>,
name: String,
present: bool,
}
impl<E: CatalogExt> VideoTrack<E> {
pub(super) fn new(catalog: Producer<E>, name: impl Into<String>) -> Self {
Self {
catalog,
name: name.into(),
present: false,
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn timestamp(&self, hint: Option<crate::container::Timestamp>) -> crate::Result<crate::container::Timestamp> {
self.catalog.timestamp(hint)
}
pub fn set(&mut self, mut config: hang::catalog::VideoConfig) {
config.timeline = Some(self.catalog.timeline_section(&self.name));
self.catalog.lock().video.renditions.insert(self.name.clone(), config);
self.present = true;
}
pub fn update(&mut self, f: impl FnOnce(&mut hang::catalog::VideoConfig)) {
if !self.present {
return;
}
let mut guard = self.catalog.lock();
if let Some(config) = guard.video.renditions.get_mut(&self.name) {
f(config);
}
}
}
impl<E: CatalogExt> Drop for VideoTrack<E> {
fn drop(&mut self) {
if self.present {
self.catalog.lock().video.renditions.remove(&self.name);
}
}
}
pub struct AudioTrack<E: CatalogExt = ()> {
catalog: Producer<E>,
name: String,
present: bool,
}
impl<E: CatalogExt> AudioTrack<E> {
pub(super) fn new(catalog: Producer<E>, name: impl Into<String>) -> Self {
Self {
catalog,
name: name.into(),
present: false,
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn timestamp(&self, hint: Option<crate::container::Timestamp>) -> crate::Result<crate::container::Timestamp> {
self.catalog.timestamp(hint)
}
pub fn set(&mut self, mut config: hang::catalog::AudioConfig) {
config.timeline = Some(self.catalog.timeline_section(&self.name));
self.catalog.lock().audio.renditions.insert(self.name.clone(), config);
self.present = true;
}
pub fn update(&mut self, f: impl FnOnce(&mut hang::catalog::AudioConfig)) {
if !self.present {
return;
}
let mut guard = self.catalog.lock();
if let Some(config) = guard.audio.renditions.get_mut(&self.name) {
f(config);
}
}
}
impl<E: CatalogExt> Drop for AudioTrack<E> {
fn drop(&mut self) {
if self.present {
self.catalog.lock().audio.renditions.remove(&self.name);
}
}
}