1use crate::{ffi, AudioInfo};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GstAudioDecoder")]
16 pub struct AudioDecoder(Object<ffi::GstAudioDecoder, ffi::GstAudioDecoderClass>) @extends gst::Element, gst::Object;
17
18 match fn {
19 type_ => || ffi::gst_audio_decoder_get_type(),
20 }
21}
22
23impl AudioDecoder {
24 pub const NONE: Option<&'static AudioDecoder> = None;
25}
26
27unsafe impl Send for AudioDecoder {}
28unsafe impl Sync for AudioDecoder {}
29
30pub trait AudioDecoderExt: IsA<AudioDecoder> + 'static {
31 #[doc(alias = "gst_audio_decoder_allocate_output_buffer")]
32 fn allocate_output_buffer(&self, size: usize) -> gst::Buffer {
33 unsafe {
34 from_glib_full(ffi::gst_audio_decoder_allocate_output_buffer(
35 self.as_ref().to_glib_none().0,
36 size,
37 ))
38 }
39 }
40
41 #[doc(alias = "gst_audio_decoder_finish_frame")]
42 fn finish_frame(
43 &self,
44 buf: Option<gst::Buffer>,
45 frames: i32,
46 ) -> Result<gst::FlowSuccess, gst::FlowError> {
47 unsafe {
48 try_from_glib(ffi::gst_audio_decoder_finish_frame(
49 self.as_ref().to_glib_none().0,
50 buf.into_glib_ptr(),
51 frames,
52 ))
53 }
54 }
55
56 #[cfg(feature = "v1_16")]
57 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
58 #[doc(alias = "gst_audio_decoder_finish_subframe")]
59 fn finish_subframe(
60 &self,
61 buf: Option<gst::Buffer>,
62 ) -> Result<gst::FlowSuccess, gst::FlowError> {
63 unsafe {
64 try_from_glib(ffi::gst_audio_decoder_finish_subframe(
65 self.as_ref().to_glib_none().0,
66 buf.into_glib_ptr(),
67 ))
68 }
69 }
70
71 #[doc(alias = "gst_audio_decoder_get_audio_info")]
72 #[doc(alias = "get_audio_info")]
73 fn audio_info(&self) -> AudioInfo {
74 unsafe {
75 from_glib_none(ffi::gst_audio_decoder_get_audio_info(
76 self.as_ref().to_glib_none().0,
77 ))
78 }
79 }
80
81 #[doc(alias = "gst_audio_decoder_get_delay")]
82 #[doc(alias = "get_delay")]
83 fn delay(&self) -> i32 {
84 unsafe { ffi::gst_audio_decoder_get_delay(self.as_ref().to_glib_none().0) }
85 }
86
87 #[doc(alias = "gst_audio_decoder_get_drainable")]
88 #[doc(alias = "get_drainable")]
89 fn is_drainable(&self) -> bool {
90 unsafe {
91 from_glib(ffi::gst_audio_decoder_get_drainable(
92 self.as_ref().to_glib_none().0,
93 ))
94 }
95 }
96
97 #[doc(alias = "gst_audio_decoder_get_estimate_rate")]
98 #[doc(alias = "get_estimate_rate")]
99 fn estimate_rate(&self) -> i32 {
100 unsafe { ffi::gst_audio_decoder_get_estimate_rate(self.as_ref().to_glib_none().0) }
101 }
102
103 #[doc(alias = "gst_audio_decoder_get_latency")]
104 #[doc(alias = "get_latency")]
105 fn latency(&self) -> (gst::ClockTime, Option<gst::ClockTime>) {
106 unsafe {
107 let mut min = std::mem::MaybeUninit::uninit();
108 let mut max = std::mem::MaybeUninit::uninit();
109 ffi::gst_audio_decoder_get_latency(
110 self.as_ref().to_glib_none().0,
111 min.as_mut_ptr(),
112 max.as_mut_ptr(),
113 );
114 (
115 try_from_glib(min.assume_init()).expect("mandatory glib value is None"),
116 from_glib(max.assume_init()),
117 )
118 }
119 }
120
121 #[doc(alias = "gst_audio_decoder_get_max_errors")]
122 #[doc(alias = "get_max_errors")]
123 #[doc(alias = "max-errors")]
124 fn max_errors(&self) -> i32 {
125 unsafe { ffi::gst_audio_decoder_get_max_errors(self.as_ref().to_glib_none().0) }
126 }
127
128 #[doc(alias = "gst_audio_decoder_get_min_latency")]
129 #[doc(alias = "get_min_latency")]
130 #[doc(alias = "min-latency")]
131 fn min_latency(&self) -> gst::ClockTime {
132 unsafe {
133 try_from_glib(ffi::gst_audio_decoder_get_min_latency(
134 self.as_ref().to_glib_none().0,
135 ))
136 .expect("mandatory glib value is None")
137 }
138 }
139
140 #[doc(alias = "gst_audio_decoder_get_needs_format")]
141 #[doc(alias = "get_needs_format")]
142 fn needs_format(&self) -> bool {
143 unsafe {
144 from_glib(ffi::gst_audio_decoder_get_needs_format(
145 self.as_ref().to_glib_none().0,
146 ))
147 }
148 }
149
150 #[doc(alias = "gst_audio_decoder_get_parse_state")]
151 #[doc(alias = "get_parse_state")]
152 fn parse_state(&self) -> (bool, bool) {
153 unsafe {
154 let mut sync = std::mem::MaybeUninit::uninit();
155 let mut eos = std::mem::MaybeUninit::uninit();
156 ffi::gst_audio_decoder_get_parse_state(
157 self.as_ref().to_glib_none().0,
158 sync.as_mut_ptr(),
159 eos.as_mut_ptr(),
160 );
161 (from_glib(sync.assume_init()), from_glib(eos.assume_init()))
162 }
163 }
164
165 #[doc(alias = "gst_audio_decoder_get_plc")]
166 #[doc(alias = "get_plc")]
167 #[doc(alias = "plc")]
168 fn is_plc(&self) -> bool {
169 unsafe {
170 from_glib(ffi::gst_audio_decoder_get_plc(
171 self.as_ref().to_glib_none().0,
172 ))
173 }
174 }
175
176 #[doc(alias = "gst_audio_decoder_get_plc_aware")]
177 #[doc(alias = "get_plc_aware")]
178 fn plc_aware(&self) -> i32 {
179 unsafe { ffi::gst_audio_decoder_get_plc_aware(self.as_ref().to_glib_none().0) }
180 }
181
182 #[doc(alias = "gst_audio_decoder_get_tolerance")]
183 #[doc(alias = "get_tolerance")]
184 fn tolerance(&self) -> gst::ClockTime {
185 unsafe {
186 try_from_glib(ffi::gst_audio_decoder_get_tolerance(
187 self.as_ref().to_glib_none().0,
188 ))
189 .expect("mandatory glib value is None")
190 }
191 }
192
193 #[doc(alias = "gst_audio_decoder_merge_tags")]
194 fn merge_tags(&self, tags: Option<&gst::TagList>, mode: gst::TagMergeMode) {
195 unsafe {
196 ffi::gst_audio_decoder_merge_tags(
197 self.as_ref().to_glib_none().0,
198 tags.to_glib_none().0,
199 mode.into_glib(),
200 );
201 }
202 }
203
204 #[doc(alias = "gst_audio_decoder_proxy_getcaps")]
205 fn proxy_getcaps(&self, caps: Option<&gst::Caps>, filter: Option<&gst::Caps>) -> gst::Caps {
206 unsafe {
207 from_glib_full(ffi::gst_audio_decoder_proxy_getcaps(
208 self.as_ref().to_glib_none().0,
209 caps.to_glib_none().0,
210 filter.to_glib_none().0,
211 ))
212 }
213 }
214
215 #[doc(alias = "gst_audio_decoder_set_allocation_caps")]
216 fn set_allocation_caps(&self, allocation_caps: Option<&gst::Caps>) {
217 unsafe {
218 ffi::gst_audio_decoder_set_allocation_caps(
219 self.as_ref().to_glib_none().0,
220 allocation_caps.to_glib_none().0,
221 );
222 }
223 }
224
225 #[doc(alias = "gst_audio_decoder_set_drainable")]
226 fn set_drainable(&self, enabled: bool) {
227 unsafe {
228 ffi::gst_audio_decoder_set_drainable(
229 self.as_ref().to_glib_none().0,
230 enabled.into_glib(),
231 );
232 }
233 }
234
235 #[doc(alias = "gst_audio_decoder_set_estimate_rate")]
236 fn set_estimate_rate(&self, enabled: bool) {
237 unsafe {
238 ffi::gst_audio_decoder_set_estimate_rate(
239 self.as_ref().to_glib_none().0,
240 enabled.into_glib(),
241 );
242 }
243 }
244
245 #[doc(alias = "gst_audio_decoder_set_latency")]
246 fn set_latency(&self, min: gst::ClockTime, max: impl Into<Option<gst::ClockTime>>) {
247 unsafe {
248 ffi::gst_audio_decoder_set_latency(
249 self.as_ref().to_glib_none().0,
250 min.into_glib(),
251 max.into().into_glib(),
252 );
253 }
254 }
255
256 #[doc(alias = "gst_audio_decoder_set_max_errors")]
257 #[doc(alias = "max-errors")]
258 fn set_max_errors(&self, num: i32) {
259 unsafe {
260 ffi::gst_audio_decoder_set_max_errors(self.as_ref().to_glib_none().0, num);
261 }
262 }
263
264 #[doc(alias = "gst_audio_decoder_set_min_latency")]
265 #[doc(alias = "min-latency")]
266 fn set_min_latency(&self, num: gst::ClockTime) {
267 unsafe {
268 ffi::gst_audio_decoder_set_min_latency(self.as_ref().to_glib_none().0, num.into_glib());
269 }
270 }
271
272 #[doc(alias = "gst_audio_decoder_set_needs_format")]
273 fn set_needs_format(&self, enabled: bool) {
274 unsafe {
275 ffi::gst_audio_decoder_set_needs_format(
276 self.as_ref().to_glib_none().0,
277 enabled.into_glib(),
278 );
279 }
280 }
281
282 #[doc(alias = "gst_audio_decoder_set_plc")]
283 #[doc(alias = "plc")]
284 fn set_plc(&self, enabled: bool) {
285 unsafe {
286 ffi::gst_audio_decoder_set_plc(self.as_ref().to_glib_none().0, enabled.into_glib());
287 }
288 }
289
290 #[doc(alias = "gst_audio_decoder_set_plc_aware")]
291 fn set_plc_aware(&self, plc: bool) {
292 unsafe {
293 ffi::gst_audio_decoder_set_plc_aware(self.as_ref().to_glib_none().0, plc.into_glib());
294 }
295 }
296
297 #[doc(alias = "gst_audio_decoder_set_tolerance")]
298 #[doc(alias = "tolerance")]
299 fn set_tolerance(&self, tolerance: gst::ClockTime) {
300 unsafe {
301 ffi::gst_audio_decoder_set_tolerance(
302 self.as_ref().to_glib_none().0,
303 tolerance.into_glib(),
304 );
305 }
306 }
307
308 #[doc(alias = "gst_audio_decoder_set_use_default_pad_acceptcaps")]
309 fn set_use_default_pad_acceptcaps(&self, use_: bool) {
310 unsafe {
311 ffi::gst_audio_decoder_set_use_default_pad_acceptcaps(
312 self.as_ref().to_glib_none().0,
313 use_.into_glib(),
314 );
315 }
316 }
317
318 #[cfg(feature = "v1_18")]
319 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
320 #[doc(alias = "max-errors")]
321 fn connect_max_errors_notify<F: Fn(&Self) + Send + Sync + 'static>(
322 &self,
323 f: F,
324 ) -> SignalHandlerId {
325 unsafe extern "C" fn notify_max_errors_trampoline<
326 P: IsA<AudioDecoder>,
327 F: Fn(&P) + Send + Sync + 'static,
328 >(
329 this: *mut ffi::GstAudioDecoder,
330 _param_spec: glib::ffi::gpointer,
331 f: glib::ffi::gpointer,
332 ) {
333 let f: &F = &*(f as *const F);
334 f(AudioDecoder::from_glib_borrow(this).unsafe_cast_ref())
335 }
336 unsafe {
337 let f: Box_<F> = Box_::new(f);
338 connect_raw(
339 self.as_ptr() as *mut _,
340 c"notify::max-errors".as_ptr() as *const _,
341 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
342 notify_max_errors_trampoline::<Self, F> as *const (),
343 )),
344 Box_::into_raw(f),
345 )
346 }
347 }
348
349 #[doc(alias = "min-latency")]
350 fn connect_min_latency_notify<F: Fn(&Self) + Send + Sync + 'static>(
351 &self,
352 f: F,
353 ) -> SignalHandlerId {
354 unsafe extern "C" fn notify_min_latency_trampoline<
355 P: IsA<AudioDecoder>,
356 F: Fn(&P) + Send + Sync + 'static,
357 >(
358 this: *mut ffi::GstAudioDecoder,
359 _param_spec: glib::ffi::gpointer,
360 f: glib::ffi::gpointer,
361 ) {
362 let f: &F = &*(f as *const F);
363 f(AudioDecoder::from_glib_borrow(this).unsafe_cast_ref())
364 }
365 unsafe {
366 let f: Box_<F> = Box_::new(f);
367 connect_raw(
368 self.as_ptr() as *mut _,
369 c"notify::min-latency".as_ptr() as *const _,
370 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
371 notify_min_latency_trampoline::<Self, F> as *const (),
372 )),
373 Box_::into_raw(f),
374 )
375 }
376 }
377
378 #[doc(alias = "plc")]
379 fn connect_plc_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
380 unsafe extern "C" fn notify_plc_trampoline<
381 P: IsA<AudioDecoder>,
382 F: Fn(&P) + Send + Sync + 'static,
383 >(
384 this: *mut ffi::GstAudioDecoder,
385 _param_spec: glib::ffi::gpointer,
386 f: glib::ffi::gpointer,
387 ) {
388 let f: &F = &*(f as *const F);
389 f(AudioDecoder::from_glib_borrow(this).unsafe_cast_ref())
390 }
391 unsafe {
392 let f: Box_<F> = Box_::new(f);
393 connect_raw(
394 self.as_ptr() as *mut _,
395 c"notify::plc".as_ptr() as *const _,
396 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
397 notify_plc_trampoline::<Self, F> as *const (),
398 )),
399 Box_::into_raw(f),
400 )
401 }
402 }
403
404 #[doc(alias = "tolerance")]
405 fn connect_tolerance_notify<F: Fn(&Self) + Send + Sync + 'static>(
406 &self,
407 f: F,
408 ) -> SignalHandlerId {
409 unsafe extern "C" fn notify_tolerance_trampoline<
410 P: IsA<AudioDecoder>,
411 F: Fn(&P) + Send + Sync + 'static,
412 >(
413 this: *mut ffi::GstAudioDecoder,
414 _param_spec: glib::ffi::gpointer,
415 f: glib::ffi::gpointer,
416 ) {
417 let f: &F = &*(f as *const F);
418 f(AudioDecoder::from_glib_borrow(this).unsafe_cast_ref())
419 }
420 unsafe {
421 let f: Box_<F> = Box_::new(f);
422 connect_raw(
423 self.as_ptr() as *mut _,
424 c"notify::tolerance".as_ptr() as *const _,
425 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
426 notify_tolerance_trampoline::<Self, F> as *const (),
427 )),
428 Box_::into_raw(f),
429 )
430 }
431 }
432}
433
434impl<O: IsA<AudioDecoder>> AudioDecoderExt for O {}