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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::data::params::CodecParams;
use crate::rational::Rational64;
use std::any::Any;
use std::sync::Arc;

/// Stream data.
#[derive(Debug, Clone)]
pub struct Stream {
    /// Format-specific track identifier.
    ///
    /// If negative, either the stream is not supported by the
    /// underlying format or the default progression should be used.
    ///
    /// Must be unique for each stream.
    pub id: isize,
    /// Stream position within the source file.
    pub index: usize,
    /// Codec parameters of the stream.
    pub params: CodecParams,
    /// Start position of the stream.
    ///
    /// If `None`, start position of the stream is not considered.
    pub start: Option<u64>,
    /// Stream duration.
    ///
    /// If `None`, stream duration is not considered.
    pub duration: Option<u64>,
    /// Timebase numerator/denominator.
    pub timebase: Rational64,
    /// User private data.
    ///
    /// This data cannot be cloned.
    pub user_private: Option<Arc<dyn Any + Send + Sync>>,
}

impl Stream {
    /// Creates a new `Stream` instance from codec parameters.
    pub fn from_params(params: &CodecParams, timebase: Rational64) -> Self {
        Stream {
            id: -1,
            index: 0,
            params: params.clone(),
            start: None,
            duration: None,
            timebase,
            user_private: None,
        }
    }
    /// Returns extradata associated to the codec parameters of a stream.
    pub fn get_extradata(&self) -> Option<&[u8]> {
        self.params.extradata.as_deref()
    }
}

/// Group of streams.
pub struct StreamGroup<'a> {
    /// Stream group ID.
    ///
    /// Must be unique for each group of stream.
    pub id: usize,
    /// Start position of the stream group.
    pub start: u64,
    /// End position of the stream group.
    pub end: u64,
    /// Streams of the group.
    pub streams: &'a [Stream],
}