ffmpeg_the_third/codec/parameters/
common.rs

1use crate::macros::impl_for_many;
2
3use super::{Parameters, ParametersMut, ParametersRef};
4use crate::chroma::Location;
5use crate::codec::Id;
6use crate::color;
7use crate::media;
8use crate::{FieldOrder, Rational};
9
10#[cfg(feature = "ffmpeg_5_1")]
11use crate::ChannelLayout;
12
13impl_for_many! {
14    impl for Parameters, ParametersRef<'p>, ParametersMut<'p> {
15        pub fn medium(&self) -> media::Type {
16            unsafe { (*self.as_ptr()).codec_type.into() }
17        }
18
19        pub fn id(&self) -> Id {
20            unsafe { (*self.as_ptr()).codec_id.into() }
21        }
22
23        // TODO: codec_tag
24        // TODO: extradata
25        // TODO: coded_side_data
26        // TODO: format (needs From<c_int> for format::Pixel and format::Sample)
27
28        pub fn bit_rate(&self) -> i64 {
29            unsafe { (*self.as_ptr()).bit_rate }
30        }
31
32        pub fn bits_per_coded_sample(&self) -> u32 {
33            unsafe { (*self.as_ptr()).bits_per_coded_sample as u32 }
34        }
35
36        pub fn bits_per_raw_sample(&self) -> u32 {
37            unsafe { (*self.as_ptr()).bits_per_raw_sample as u32 }
38        }
39
40        pub fn profile(&self) -> i32 {
41            unsafe { (*self.as_ptr()).profile as i32 }
42        }
43
44        pub fn level(&self) -> i32 {
45            unsafe { (*self.as_ptr()).level as i32 }
46        }
47
48        /// Video only
49        pub fn width(&self) -> u32 {
50            unsafe { (*self.as_ptr()).width as u32 }
51        }
52
53        /// Video only
54        pub fn height(&self) -> u32 {
55            unsafe { (*self.as_ptr()).height as u32 }
56        }
57
58        /// Video only
59        pub fn sample_aspect_ratio(&self) -> Rational {
60            unsafe { (*self.as_ptr()).sample_aspect_ratio.into() }
61        }
62
63        /// Video only
64        #[cfg(feature = "ffmpeg_6_1")]
65        pub fn framerate(&self) -> Rational {
66            unsafe { (*self.as_ptr()).framerate.into() }
67        }
68
69        /// Video only
70        pub fn field_order(&self) -> FieldOrder {
71            unsafe { (*self.as_ptr()).field_order.into() }
72        }
73
74        /// Video only
75        pub fn color_range(&self) -> color::Range {
76            unsafe { (*self.as_ptr()).color_range.into() }
77        }
78
79        /// Video only
80        pub fn color_primaries(&self) -> color::Primaries {
81            unsafe { (*self.as_ptr()).color_primaries.into() }
82        }
83
84        /// Video only
85        pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic {
86            unsafe { (*self.as_ptr()).color_trc.into() }
87        }
88
89        /// Video only
90        pub fn color_space(&self) -> color::Space {
91            unsafe { (*self.as_ptr()).color_space.into() }
92        }
93
94        /// Video only
95        pub fn chroma_location(&self) -> Location {
96            unsafe { (*self.as_ptr()).chroma_location.into() }
97        }
98
99        /// Video only
100        pub fn video_delay(&self) -> i32 {
101            unsafe { (*self.as_ptr()).video_delay as i32 }
102        }
103
104        /// Audio only
105        #[cfg(feature = "ffmpeg_5_1")]
106        pub fn ch_layout(&self) -> ChannelLayout {
107            unsafe { ChannelLayout::from(&(*self.as_ptr()).ch_layout) }
108        }
109
110        /// Audio only
111        pub fn sample_rate(&self) -> u32 {
112            unsafe { (*self.as_ptr()).sample_rate as u32 }
113        }
114
115        /// Audio only
116        pub fn block_align(&self) -> u32 {
117            unsafe { (*self.as_ptr()).block_align as u32 }
118        }
119
120        /// Audio only
121        pub fn frame_size(&self) -> u32 {
122            unsafe { (*self.as_ptr()).frame_size as u32 }
123        }
124
125        /// Audio only
126        pub fn initial_padding(&self) -> u32 {
127            unsafe { (*self.as_ptr()).initial_padding as u32 }
128        }
129
130        /// Audio only
131        pub fn trailing_padding(&self) -> u32 {
132            unsafe { (*self.as_ptr()).trailing_padding as u32 }
133        }
134
135        /// Audio only
136        pub fn seek_preroll(&self) -> u32 {
137            unsafe { (*self.as_ptr()).seek_preroll as u32 }
138        }
139    }
140}