1 | // Take a look at the license at the top of the repository in the LICENSE file. |
2 | |
3 | use std::{mem, ptr}; |
4 | |
5 | use glib::{prelude::*, translate::*}; |
6 | |
7 | use crate::{AudioDecoder, AudioInfo}; |
8 | |
9 | extern "C" { |
10 | fn _gst_audio_decoder_error( |
11 | dec: *mut ffi::GstAudioDecoder, |
12 | weight: i32, |
13 | domain: glib::ffi::GQuark, |
14 | code: i32, |
15 | txt: *mut libc::c_char, |
16 | debug: *mut libc::c_char, |
17 | file: *const libc::c_char, |
18 | function: *const libc::c_char, |
19 | line: i32, |
20 | ) -> gst::ffi::GstFlowReturn; |
21 | } |
22 | |
23 | mod sealed { |
24 | pub trait Sealed {} |
25 | impl<T: super::IsA<super::AudioDecoder>> Sealed for T {} |
26 | } |
27 | |
28 | pub trait AudioDecoderExtManual: sealed::Sealed + IsA<AudioDecoder> + 'static { |
29 | #[doc (alias = "gst_audio_decoder_negotiate" )] |
30 | fn negotiate(&self) -> Result<(), gst::FlowError> { |
31 | unsafe { |
32 | let ret = from_glib(ffi::gst_audio_decoder_negotiate( |
33 | self.as_ref().to_glib_none().0, |
34 | )); |
35 | if ret { |
36 | Ok(()) |
37 | } else { |
38 | Err(gst::FlowError::NotNegotiated) |
39 | } |
40 | } |
41 | } |
42 | |
43 | #[cfg (feature = "v1_16" )] |
44 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_16" )))] |
45 | #[doc (alias = "gst_audio_decoder_set_output_caps" )] |
46 | fn set_output_caps(&self, caps: &gst::Caps) -> Result<(), gst::FlowError> { |
47 | unsafe { |
48 | let ret = from_glib(ffi::gst_audio_decoder_set_output_caps( |
49 | self.as_ref().to_glib_none().0, |
50 | caps.to_glib_none().0, |
51 | )); |
52 | if ret { |
53 | Ok(()) |
54 | } else { |
55 | Err(gst::FlowError::NotNegotiated) |
56 | } |
57 | } |
58 | } |
59 | |
60 | #[doc (alias = "gst_audio_decoder_set_output_format" )] |
61 | fn set_output_format(&self, info: &AudioInfo) -> Result<(), gst::FlowError> { |
62 | unsafe { |
63 | let ret = from_glib(ffi::gst_audio_decoder_set_output_format( |
64 | self.as_ref().to_glib_none().0, |
65 | info.to_glib_none().0, |
66 | )); |
67 | if ret { |
68 | Ok(()) |
69 | } else { |
70 | Err(gst::FlowError::NotNegotiated) |
71 | } |
72 | } |
73 | } |
74 | |
75 | #[doc (alias = "get_allocator" )] |
76 | #[doc (alias = "gst_audio_decoder_get_allocator" )] |
77 | fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) { |
78 | unsafe { |
79 | let mut allocator = ptr::null_mut(); |
80 | let mut params = mem::MaybeUninit::uninit(); |
81 | ffi::gst_audio_decoder_get_allocator( |
82 | self.as_ref().to_glib_none().0, |
83 | &mut allocator, |
84 | params.as_mut_ptr(), |
85 | ); |
86 | (from_glib_full(allocator), params.assume_init().into()) |
87 | } |
88 | } |
89 | |
90 | #[allow (clippy::too_many_arguments)] |
91 | fn error<T: gst::MessageErrorDomain>( |
92 | &self, |
93 | weight: i32, |
94 | code: T, |
95 | message: Option<&str>, |
96 | debug: Option<&str>, |
97 | file: &str, |
98 | function: &str, |
99 | line: u32, |
100 | ) -> Result<gst::FlowSuccess, gst::FlowError> { |
101 | unsafe { |
102 | try_from_glib(_gst_audio_decoder_error( |
103 | self.as_ref().to_glib_none().0, |
104 | weight, |
105 | T::domain().into_glib(), |
106 | code.code(), |
107 | message.to_glib_full(), |
108 | debug.to_glib_full(), |
109 | file.to_glib_none().0, |
110 | function.to_glib_none().0, |
111 | line as i32, |
112 | )) |
113 | } |
114 | } |
115 | |
116 | fn sink_pad(&self) -> &gst::Pad { |
117 | unsafe { |
118 | let elt = &*(self.as_ptr() as *const ffi::GstAudioDecoder); |
119 | &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad) |
120 | } |
121 | } |
122 | |
123 | fn src_pad(&self) -> &gst::Pad { |
124 | unsafe { |
125 | let elt = &*(self.as_ptr() as *const ffi::GstAudioDecoder); |
126 | &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad) |
127 | } |
128 | } |
129 | } |
130 | |
131 | impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {} |
132 | |
133 | #[macro_export ] |
134 | macro_rules! audio_decoder_error( |
135 | ($obj:expr, $weight:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { { |
136 | use $crate::prelude::AudioDecoderExtManual; |
137 | $obj.error( |
138 | $weight, |
139 | $err, |
140 | Some(&format!($($msg)*)), |
141 | Some(&format!($($debug)*)), |
142 | file!(), |
143 | $crate::glib::function_name!(), |
144 | line!(), |
145 | ) |
146 | }}; |
147 | ($obj:expr, $weight:expr, $err:expr, ($($msg:tt)*)) => { { |
148 | use $crate::prelude::AudioDecoderExtManual; |
149 | $obj.error( |
150 | $weight, |
151 | $err, |
152 | Some(&format!($($msg)*)), |
153 | None, |
154 | file!(), |
155 | $crate::glib::function_name!(), |
156 | line!(), |
157 | ) |
158 | }}; |
159 | ($obj:expr, $weight:expr, $err:expr, [$($debug:tt)*]) => { { |
160 | use $crate::prelude::AudioDecoderExtManual; |
161 | $obj.error( |
162 | $weight, |
163 | $err, |
164 | None, |
165 | Some(&format!($($debug)*)), |
166 | file!(), |
167 | $crate::glib::function_name!(), |
168 | line!(), |
169 | ) |
170 | }}; |
171 | ); |
172 | |