Skip to main content

mp4_edit/atom/container/
edts.rs

1use std::fmt;
2
3use crate::{
4    atom::{
5        atom_ref::{unwrap_atom_data, AtomRef, AtomRefMut},
6        elst::ELST,
7        EditListAtom,
8    },
9    Atom, AtomData, FourCC,
10};
11
12pub const EDTS: FourCC = FourCC::new(b"edts");
13
14#[derive(Clone, Copy)]
15pub struct EdtsAtomRef<'a>(pub(crate) AtomRef<'a>);
16
17impl fmt::Debug for EdtsAtomRef<'_> {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        f.debug_struct("EdtsAtomRef").finish()
20    }
21}
22
23impl<'a> EdtsAtomRef<'a> {
24    pub fn children(&self) -> impl Iterator<Item = &'a Atom> {
25        self.0.children()
26    }
27
28    pub fn edit_list(&self) -> Option<&'a EditListAtom> {
29        let atom = self.0.find_child(ELST)?;
30        match atom.data.as_ref()? {
31            AtomData::EditList(data) => Some(data),
32            _ => None,
33        }
34    }
35}
36
37#[derive(Debug)]
38pub struct EdtsAtomRefMut<'a>(pub(crate) AtomRefMut<'a>);
39
40impl EdtsAtomRefMut<'_> {
41    /// Finds or creates the ELST atom
42    pub fn edit_list(&mut self) -> &mut EditListAtom {
43        unwrap_atom_data!(
44            self.0
45                .find_or_insert_child(ELST)
46                .insert_data(AtomData::EditList(EditListAtom::default()))
47                .call(),
48            AtomData::EditList,
49        )
50    }
51}