ffmpeg_the_third/software/resampling/
extensions.rs

1use super::Context;
2use crate::util::format;
3use crate::{decoder, frame, Error};
4
5#[cfg(feature = "ffmpeg_5_1")]
6use crate::ChannelLayout;
7
8#[cfg(not(feature = "ffmpeg_7_0"))]
9use crate::ChannelLayoutMask;
10
11impl frame::Audio {
12    #[cfg(not(feature = "ffmpeg_7_0"))]
13    #[inline]
14    pub fn resampler(
15        &self,
16        format: format::Sample,
17        channel_layout: ChannelLayoutMask,
18        rate: u32,
19    ) -> Result<Context, Error> {
20        Context::get(
21            self.format(),
22            self.channel_layout(),
23            unsafe { (*self.as_ptr()).sample_rate as u32 },
24            format,
25            channel_layout,
26            rate,
27        )
28    }
29
30    #[cfg(feature = "ffmpeg_5_1")]
31    #[inline]
32    pub fn resampler2(
33        &self,
34        format: format::Sample,
35        ch_layout: ChannelLayout,
36        rate: u32,
37    ) -> Result<Context, Error> {
38        Context::get2(
39            self.format(),
40            self.ch_layout(),
41            unsafe { (*self.as_ptr()).sample_rate as u32 },
42            format,
43            ch_layout,
44            rate,
45        )
46    }
47}
48
49impl decoder::Audio {
50    #[cfg(not(feature = "ffmpeg_7_0"))]
51    #[inline]
52    pub fn resampler(
53        &self,
54        format: format::Sample,
55        channel_layout: ChannelLayoutMask,
56        rate: u32,
57    ) -> Result<Context, Error> {
58        Context::get(
59            self.format(),
60            self.channel_layout(),
61            self.rate(),
62            format,
63            channel_layout,
64            rate,
65        )
66    }
67
68    #[cfg(feature = "ffmpeg_5_1")]
69    #[inline]
70    pub fn resampler2(
71        &self,
72        format: format::Sample,
73        ch_layout: ChannelLayout,
74        rate: u32,
75    ) -> Result<Context, Error> {
76        Context::get2(
77            self.format(),
78            self.ch_layout(),
79            self.rate(),
80            format,
81            ch_layout,
82            rate,
83        )
84    }
85}