av_format/stream.rs
1use crate::data::params::CodecParams;
2use crate::rational::Rational64;
3use std::any::Any;
4use std::sync::Arc;
5
6/// Stream data.
7#[derive(Debug, Clone)]
8pub struct Stream {
9 /// Format-specific track identifier.
10 ///
11 /// If negative, either the stream is not supported by the
12 /// underlying format or the default progression should be used.
13 ///
14 /// Must be unique for each stream.
15 pub id: isize,
16 /// Stream position within the source file.
17 pub index: usize,
18 /// Codec parameters of the stream.
19 pub params: CodecParams,
20 /// Start position of the stream.
21 ///
22 /// If `None`, start position of the stream is not considered.
23 pub start: Option<u64>,
24 /// Stream duration.
25 ///
26 /// If `None`, stream duration is not considered.
27 pub duration: Option<u64>,
28 /// Timebase numerator/denominator.
29 pub timebase: Rational64,
30 /// User private data.
31 ///
32 /// This data cannot be cloned.
33 pub user_private: Option<Arc<dyn Any + Send + Sync>>,
34}
35
36impl Stream {
37 /// Creates a new `Stream` instance from codec parameters.
38 pub fn from_params(params: &CodecParams, timebase: Rational64) -> Self {
39 Stream {
40 id: -1,
41 index: 0,
42 params: params.clone(),
43 start: None,
44 duration: None,
45 timebase,
46 user_private: None,
47 }
48 }
49 /// Returns extradata associated to the codec parameters of a stream.
50 pub fn get_extradata(&self) -> Option<&[u8]> {
51 self.params.extradata.as_deref()
52 }
53}
54
55/// Group of streams.
56pub struct StreamGroup<'a> {
57 /// Stream group ID.
58 ///
59 /// Must be unique for each group of stream.
60 pub id: usize,
61 /// Start position of the stream group.
62 pub start: u64,
63 /// End position of the stream group.
64 pub end: u64,
65 /// Streams of the group.
66 pub streams: &'a [Stream],
67}