1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::data::rational::Rational64;
use crate::stream::Stream;

/// Global media file information.
#[derive(Debug, Clone)]
pub struct GlobalInfo {
    /// Duration of a media file.
    ///
    /// If `None`, the duration of a media file is not considered.
    pub duration: Option<u64>,
    /// Timebase associated to a media file.
    ///
    /// If `None`, the timebase of a media file is not considered.
    pub timebase: Option<Rational64>,
    /// List of streams present in a media file.
    pub streams: Vec<Stream>,
}

impl GlobalInfo {
    /// Adds a stream to the list of streams present in a media file.
    pub fn add_stream(&mut self, mut st: Stream) -> usize {
        let idx = self.streams.len();

        if st.id < 0 {
            st.id = st.index as isize;
        }
        st.index = idx;

        self.streams.push(st);

        idx
    }
}