ffmpeg_the_third/codec/decoder/
audio.rs1use std::ops::{Deref, DerefMut};
2
3use super::Opened;
4use crate::codec::Context;
5use crate::util::format;
6use crate::AudioService;
7
8use crate::ChannelLayout;
9
10#[cfg(not(feature = "ffmpeg_7_0"))]
11use crate::ChannelLayoutMask;
12
13pub struct Audio(pub Opened);
14
15impl Audio {
16 pub fn rate(&self) -> u32 {
17 unsafe { (*self.as_ptr()).sample_rate as u32 }
18 }
19
20 #[cfg(not(feature = "ffmpeg_7_0"))]
21 pub fn channels(&self) -> u16 {
22 unsafe { (*self.as_ptr()).channels as u16 }
23 }
24
25 pub fn format(&self) -> format::Sample {
26 unsafe { format::Sample::from((*self.as_ptr()).sample_fmt) }
27 }
28
29 pub fn request_format(&mut self, value: format::Sample) {
30 unsafe {
31 (*self.as_mut_ptr()).request_sample_fmt = value.into();
32 }
33 }
34
35 #[cfg(not(feature = "ffmpeg_7_0"))]
36 pub fn frames(&self) -> usize {
37 unsafe { (*self.as_ptr()).frame_number as usize }
38 }
39
40 pub fn align(&self) -> usize {
41 unsafe { (*self.as_ptr()).block_align as usize }
42 }
43
44 #[cfg(not(feature = "ffmpeg_7_0"))]
45 pub fn channel_layout(&self) -> ChannelLayoutMask {
46 unsafe { ChannelLayoutMask::from_bits_truncate((*self.as_ptr()).channel_layout) }
47 }
48
49 #[cfg(not(feature = "ffmpeg_7_0"))]
50 pub fn set_channel_layout(&mut self, value: ChannelLayoutMask) {
51 unsafe {
52 (*self.as_mut_ptr()).channel_layout = value.bits();
53 }
54 }
55
56 #[cfg(not(feature = "ffmpeg_7_0"))]
57 pub fn request_channel_layout(&mut self, value: ChannelLayoutMask) {
58 unsafe {
59 (*self.as_mut_ptr()).request_channel_layout = value.bits();
60 }
61 }
62
63 pub fn ch_layout(&self) -> ChannelLayout<'_> {
64 unsafe { ChannelLayout::from(&self.as_ptr().as_ref().unwrap().ch_layout) }
65 }
66
67 pub fn set_ch_layout(&mut self, value: ChannelLayout) {
68 unsafe {
69 self.as_mut_ptr().as_mut().unwrap().ch_layout = value.into_owned();
70 }
71 }
72
73 pub fn audio_service(&mut self) -> AudioService {
74 unsafe { AudioService::from((*self.as_mut_ptr()).audio_service_type) }
75 }
76
77 pub fn max_bit_rate(&self) -> usize {
78 unsafe { (*self.as_ptr()).rc_max_rate as usize }
79 }
80
81 pub fn frame_size(&self) -> u32 {
82 unsafe { (*self.as_ptr()).frame_size as u32 }
83 }
84}
85
86impl Deref for Audio {
87 type Target = Opened;
88
89 fn deref(&self) -> &<Self as Deref>::Target {
90 &self.0
91 }
92}
93
94impl DerefMut for Audio {
95 fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
96 &mut self.0
97 }
98}
99
100impl AsRef<Context> for Audio {
101 fn as_ref(&self) -> &Context {
102 self
103 }
104}
105
106impl AsMut<Context> for Audio {
107 fn as_mut(&mut self) -> &mut Context {
108 &mut self.0
109 }
110}