gstreamer_audio/subclass/
audio_decoder.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{mem, ptr};
4
5use glib::translate::*;
6use gst::subclass::prelude::*;
7
8use crate::{ffi, prelude::*, AudioDecoder};
9
10pub trait AudioDecoderImpl: AudioDecoderImplExt + ElementImpl {
11    /// Optional.
12    ///  Called when the element changes to GST_STATE_READY.
13    ///  Allows opening external resources.
14    fn open(&self) -> Result<(), gst::ErrorMessage> {
15        self.parent_open()
16    }
17
18    /// Optional.
19    ///  Called when the element changes to GST_STATE_NULL.
20    ///  Allows closing external resources.
21    fn close(&self) -> Result<(), gst::ErrorMessage> {
22        self.parent_close()
23    }
24
25    /// Optional.
26    ///  Called when the element starts processing.
27    ///  Allows opening external resources.
28    fn start(&self) -> Result<(), gst::ErrorMessage> {
29        self.parent_start()
30    }
31
32    /// Optional.
33    ///  Called when the element stops processing.
34    ///  Allows closing external resources.
35    fn stop(&self) -> Result<(), gst::ErrorMessage> {
36        self.parent_stop()
37    }
38
39    /// Notifies subclass of incoming data format (caps).
40    fn set_format(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
41        self.parent_set_format(caps)
42    }
43
44    fn parse(&self, adapter: &gst_base::Adapter) -> Result<(u32, u32), gst::FlowError> {
45        self.parent_parse(adapter)
46    }
47
48    /// Provides input data (or NULL to clear any remaining data)
49    ///  to subclass. Input data ref management is performed by
50    ///  base class, subclass should not care or intervene,
51    ///  and input data is only valid until next call to base class,
52    ///  most notably a call to [`AudioDecoderExt::finish_frame()`][crate::prelude::AudioDecoderExt::finish_frame()].
53    fn handle_frame(
54        &self,
55        buffer: Option<&gst::Buffer>,
56    ) -> Result<gst::FlowSuccess, gst::FlowError> {
57        self.parent_handle_frame(buffer)
58    }
59
60    /// Optional.
61    ///  Called just prior to pushing (encoded data) buffer downstream.
62    ///  Subclass has full discretionary access to buffer,
63    ///  and a not OK flow return will abort downstream pushing.
64    fn pre_push(&self, buffer: gst::Buffer) -> Result<Option<gst::Buffer>, gst::FlowError> {
65        self.parent_pre_push(buffer)
66    }
67
68    /// Optional.
69    ///  Instructs subclass to clear any codec caches and discard
70    ///  any pending samples and not yet returned decoded data.
71    ///  `hard` indicates whether a FLUSH is being processed,
72    ///  or otherwise a DISCONT (or conceptually similar).
73    fn flush(&self, hard: bool) {
74        self.parent_flush(hard)
75    }
76
77    /// Negotiate with downstream elements to currently configured [`AudioInfo`][crate::AudioInfo].
78    /// Unmark GST_PAD_FLAG_NEED_RECONFIGURE in any case. But mark it again if
79    /// negotiate fails.
80    ///
81    /// # Returns
82    ///
83    /// [`true`] if the negotiation succeeded, else [`false`].
84    fn negotiate(&self) -> Result<(), gst::LoggableError> {
85        self.parent_negotiate()
86    }
87
88    fn caps(&self, filter: Option<&gst::Caps>) -> gst::Caps {
89        self.parent_caps(filter)
90    }
91
92    /// Optional.
93    ///  Event handler on the sink pad. Subclasses should chain up to
94    ///  the parent implementation to invoke the default handler.
95    fn sink_event(&self, event: gst::Event) -> bool {
96        self.parent_sink_event(event)
97    }
98
99    /// Optional.
100    ///  Query handler on the sink pad. This function should
101    ///  return TRUE if the query could be performed. Subclasses
102    ///  should chain up to the parent implementation to invoke the
103    ///  default handler. Since: 1.6
104    fn sink_query(&self, query: &mut gst::QueryRef) -> bool {
105        self.parent_sink_query(query)
106    }
107
108    /// Optional.
109    ///  Event handler on the src pad. Subclasses should chain up to
110    ///  the parent implementation to invoke the default handler.
111    fn src_event(&self, event: gst::Event) -> bool {
112        self.parent_src_event(event)
113    }
114
115    /// Optional.
116    ///  Query handler on the source pad. This function should
117    ///  return TRUE if the query could be performed. Subclasses
118    ///  should chain up to the parent implementation to invoke the
119    ///  default handler. Since: 1.6
120    fn src_query(&self, query: &mut gst::QueryRef) -> bool {
121        self.parent_src_query(query)
122    }
123
124    /// Optional.
125    ///  Propose buffer allocation parameters for upstream elements.
126    ///  Subclasses should chain up to the parent implementation to
127    ///  invoke the default handler.
128    fn propose_allocation(
129        &self,
130        query: &mut gst::query::Allocation,
131    ) -> Result<(), gst::LoggableError> {
132        self.parent_propose_allocation(query)
133    }
134
135    /// Optional.
136    ///  Setup the allocation parameters for allocating output
137    ///  buffers. The passed in query contains the result of the
138    ///  downstream allocation query.
139    ///  Subclasses should chain up to the parent implementation to
140    ///  invoke the default handler.
141    fn decide_allocation(
142        &self,
143        query: &mut gst::query::Allocation,
144    ) -> Result<(), gst::LoggableError> {
145        self.parent_decide_allocation(query)
146    }
147}
148
149mod sealed {
150    pub trait Sealed {}
151    impl<T: super::AudioDecoderImplExt> Sealed for T {}
152}
153
154pub trait AudioDecoderImplExt: sealed::Sealed + ObjectSubclass {
155    fn parent_open(&self) -> Result<(), gst::ErrorMessage> {
156        unsafe {
157            let data = Self::type_data();
158            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
159            (*parent_class)
160                .open
161                .map(|f| {
162                    if from_glib(f(self
163                        .obj()
164                        .unsafe_cast_ref::<AudioDecoder>()
165                        .to_glib_none()
166                        .0))
167                    {
168                        Ok(())
169                    } else {
170                        Err(gst::error_msg!(
171                            gst::CoreError::StateChange,
172                            ["Parent function `open` failed"]
173                        ))
174                    }
175                })
176                .unwrap_or(Ok(()))
177        }
178    }
179
180    fn parent_close(&self) -> Result<(), gst::ErrorMessage> {
181        unsafe {
182            let data = Self::type_data();
183            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
184            (*parent_class)
185                .close
186                .map(|f| {
187                    if from_glib(f(self
188                        .obj()
189                        .unsafe_cast_ref::<AudioDecoder>()
190                        .to_glib_none()
191                        .0))
192                    {
193                        Ok(())
194                    } else {
195                        Err(gst::error_msg!(
196                            gst::CoreError::StateChange,
197                            ["Parent function `close` failed"]
198                        ))
199                    }
200                })
201                .unwrap_or(Ok(()))
202        }
203    }
204
205    fn parent_start(&self) -> Result<(), gst::ErrorMessage> {
206        unsafe {
207            let data = Self::type_data();
208            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
209            (*parent_class)
210                .start
211                .map(|f| {
212                    if from_glib(f(self
213                        .obj()
214                        .unsafe_cast_ref::<AudioDecoder>()
215                        .to_glib_none()
216                        .0))
217                    {
218                        Ok(())
219                    } else {
220                        Err(gst::error_msg!(
221                            gst::CoreError::StateChange,
222                            ["Parent function `start` failed"]
223                        ))
224                    }
225                })
226                .unwrap_or(Ok(()))
227        }
228    }
229
230    fn parent_stop(&self) -> Result<(), gst::ErrorMessage> {
231        unsafe {
232            let data = Self::type_data();
233            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
234            (*parent_class)
235                .stop
236                .map(|f| {
237                    if from_glib(f(self
238                        .obj()
239                        .unsafe_cast_ref::<AudioDecoder>()
240                        .to_glib_none()
241                        .0))
242                    {
243                        Ok(())
244                    } else {
245                        Err(gst::error_msg!(
246                            gst::CoreError::StateChange,
247                            ["Parent function `stop` failed"]
248                        ))
249                    }
250                })
251                .unwrap_or(Ok(()))
252        }
253    }
254
255    fn parent_set_format(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
256        unsafe {
257            let data = Self::type_data();
258            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
259            (*parent_class)
260                .set_format
261                .map(|f| {
262                    gst::result_from_gboolean!(
263                        f(
264                            self.obj()
265                                .unsafe_cast_ref::<AudioDecoder>()
266                                .to_glib_none()
267                                .0,
268                            caps.to_glib_none().0
269                        ),
270                        gst::CAT_RUST,
271                        "parent function `set_format` failed"
272                    )
273                })
274                .unwrap_or(Ok(()))
275        }
276    }
277
278    fn parent_parse(&self, adapter: &gst_base::Adapter) -> Result<(u32, u32), gst::FlowError> {
279        unsafe {
280            let data = Self::type_data();
281            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
282            (*parent_class)
283                .parse
284                .map(|f| {
285                    let mut offset = mem::MaybeUninit::uninit();
286                    let mut len = mem::MaybeUninit::uninit();
287                    gst::FlowSuccess::try_from_glib(f(
288                        self.obj()
289                            .unsafe_cast_ref::<AudioDecoder>()
290                            .to_glib_none()
291                            .0,
292                        adapter.to_glib_none().0,
293                        offset.as_mut_ptr(),
294                        len.as_mut_ptr(),
295                    ))
296                    .map(|_| {
297                        let offset = offset.assume_init();
298                        let len = len.assume_init();
299                        assert!(offset >= 0);
300                        assert!(len >= 0);
301                        (offset as u32, len as u32)
302                    })
303                })
304                .unwrap_or_else(|| Ok((0, adapter.available() as u32)))
305        }
306    }
307
308    fn parent_handle_frame(
309        &self,
310        buffer: Option<&gst::Buffer>,
311    ) -> Result<gst::FlowSuccess, gst::FlowError> {
312        unsafe {
313            let data = Self::type_data();
314            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
315            (*parent_class)
316                .handle_frame
317                .map(|f| {
318                    try_from_glib(f(
319                        self.obj()
320                            .unsafe_cast_ref::<AudioDecoder>()
321                            .to_glib_none()
322                            .0,
323                        buffer
324                            .map(|buffer| buffer.as_mut_ptr() as *mut *mut gst::ffi::GstBuffer)
325                            .unwrap_or(ptr::null_mut()),
326                    ))
327                })
328                .unwrap_or(Err(gst::FlowError::Error))
329        }
330    }
331
332    fn parent_pre_push(&self, buffer: gst::Buffer) -> Result<Option<gst::Buffer>, gst::FlowError> {
333        unsafe {
334            let data = Self::type_data();
335            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
336            if let Some(f) = (*parent_class).pre_push {
337                let mut buffer = buffer.into_glib_ptr();
338                gst::FlowSuccess::try_from_glib(f(
339                    self.obj()
340                        .unsafe_cast_ref::<AudioDecoder>()
341                        .to_glib_none()
342                        .0,
343                    &mut buffer,
344                ))
345                .map(|_| from_glib_full(buffer))
346            } else {
347                Ok(Some(buffer))
348            }
349        }
350    }
351
352    fn parent_flush(&self, hard: bool) {
353        unsafe {
354            let data = Self::type_data();
355            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
356            (*parent_class)
357                .flush
358                .map(|f| {
359                    f(
360                        self.obj()
361                            .unsafe_cast_ref::<AudioDecoder>()
362                            .to_glib_none()
363                            .0,
364                        hard.into_glib(),
365                    )
366                })
367                .unwrap_or(())
368        }
369    }
370
371    fn parent_negotiate(&self) -> Result<(), gst::LoggableError> {
372        unsafe {
373            let data = Self::type_data();
374            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
375            (*parent_class)
376                .negotiate
377                .map(|f| {
378                    gst::result_from_gboolean!(
379                        f(self
380                            .obj()
381                            .unsafe_cast_ref::<AudioDecoder>()
382                            .to_glib_none()
383                            .0),
384                        gst::CAT_RUST,
385                        "Parent function `negotiate` failed"
386                    )
387                })
388                .unwrap_or(Ok(()))
389        }
390    }
391
392    fn parent_caps(&self, filter: Option<&gst::Caps>) -> gst::Caps {
393        unsafe {
394            let data = Self::type_data();
395            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
396            (*parent_class)
397                .getcaps
398                .map(|f| {
399                    from_glib_full(f(
400                        self.obj()
401                            .unsafe_cast_ref::<AudioDecoder>()
402                            .to_glib_none()
403                            .0,
404                        filter.to_glib_none().0,
405                    ))
406                })
407                .unwrap_or_else(|| {
408                    self.obj()
409                        .unsafe_cast_ref::<AudioDecoder>()
410                        .proxy_getcaps(None, filter)
411                })
412        }
413    }
414
415    fn parent_sink_event(&self, event: gst::Event) -> bool {
416        unsafe {
417            let data = Self::type_data();
418            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
419            let f = (*parent_class)
420                .sink_event
421                .expect("Missing parent function `sink_event`");
422            from_glib(f(
423                self.obj()
424                    .unsafe_cast_ref::<AudioDecoder>()
425                    .to_glib_none()
426                    .0,
427                event.into_glib_ptr(),
428            ))
429        }
430    }
431
432    fn parent_sink_query(&self, query: &mut gst::QueryRef) -> bool {
433        unsafe {
434            let data = Self::type_data();
435            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
436            let f = (*parent_class)
437                .sink_query
438                .expect("Missing parent function `sink_query`");
439            from_glib(f(
440                self.obj()
441                    .unsafe_cast_ref::<AudioDecoder>()
442                    .to_glib_none()
443                    .0,
444                query.as_mut_ptr(),
445            ))
446        }
447    }
448
449    fn parent_src_event(&self, event: gst::Event) -> bool {
450        unsafe {
451            let data = Self::type_data();
452            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
453            let f = (*parent_class)
454                .src_event
455                .expect("Missing parent function `src_event`");
456            from_glib(f(
457                self.obj()
458                    .unsafe_cast_ref::<AudioDecoder>()
459                    .to_glib_none()
460                    .0,
461                event.into_glib_ptr(),
462            ))
463        }
464    }
465
466    fn parent_src_query(&self, query: &mut gst::QueryRef) -> bool {
467        unsafe {
468            let data = Self::type_data();
469            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
470            let f = (*parent_class)
471                .src_query
472                .expect("Missing parent function `src_query`");
473            from_glib(f(
474                self.obj()
475                    .unsafe_cast_ref::<AudioDecoder>()
476                    .to_glib_none()
477                    .0,
478                query.as_mut_ptr(),
479            ))
480        }
481    }
482
483    fn parent_propose_allocation(
484        &self,
485        query: &mut gst::query::Allocation,
486    ) -> Result<(), gst::LoggableError> {
487        unsafe {
488            let data = Self::type_data();
489            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
490            (*parent_class)
491                .propose_allocation
492                .map(|f| {
493                    gst::result_from_gboolean!(
494                        f(
495                            self.obj()
496                                .unsafe_cast_ref::<AudioDecoder>()
497                                .to_glib_none()
498                                .0,
499                            query.as_mut_ptr(),
500                        ),
501                        gst::CAT_RUST,
502                        "Parent function `propose_allocation` failed",
503                    )
504                })
505                .unwrap_or(Ok(()))
506        }
507    }
508
509    fn parent_decide_allocation(
510        &self,
511        query: &mut gst::query::Allocation,
512    ) -> Result<(), gst::LoggableError> {
513        unsafe {
514            let data = Self::type_data();
515            let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
516            (*parent_class)
517                .decide_allocation
518                .map(|f| {
519                    gst::result_from_gboolean!(
520                        f(
521                            self.obj()
522                                .unsafe_cast_ref::<AudioDecoder>()
523                                .to_glib_none()
524                                .0,
525                            query.as_mut_ptr(),
526                        ),
527                        gst::CAT_RUST,
528                        "Parent function `decide_allocation` failed",
529                    )
530                })
531                .unwrap_or(Ok(()))
532        }
533    }
534}
535
536impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {}
537
538unsafe impl<T: AudioDecoderImpl> IsSubclassable<T> for AudioDecoder {
539    fn class_init(klass: &mut glib::Class<Self>) {
540        Self::parent_class_init::<T>(klass);
541        let klass = klass.as_mut();
542        klass.open = Some(audio_decoder_open::<T>);
543        klass.close = Some(audio_decoder_close::<T>);
544        klass.start = Some(audio_decoder_start::<T>);
545        klass.stop = Some(audio_decoder_stop::<T>);
546        klass.set_format = Some(audio_decoder_set_format::<T>);
547        klass.parse = Some(audio_decoder_parse::<T>);
548        klass.handle_frame = Some(audio_decoder_handle_frame::<T>);
549        klass.pre_push = Some(audio_decoder_pre_push::<T>);
550        klass.flush = Some(audio_decoder_flush::<T>);
551        klass.negotiate = Some(audio_decoder_negotiate::<T>);
552        klass.getcaps = Some(audio_decoder_getcaps::<T>);
553        klass.sink_event = Some(audio_decoder_sink_event::<T>);
554        klass.src_event = Some(audio_decoder_src_event::<T>);
555        klass.sink_query = Some(audio_decoder_sink_query::<T>);
556        klass.src_query = Some(audio_decoder_src_query::<T>);
557        klass.propose_allocation = Some(audio_decoder_propose_allocation::<T>);
558        klass.decide_allocation = Some(audio_decoder_decide_allocation::<T>);
559    }
560}
561
562unsafe extern "C" fn audio_decoder_open<T: AudioDecoderImpl>(
563    ptr: *mut ffi::GstAudioDecoder,
564) -> glib::ffi::gboolean {
565    let instance = &*(ptr as *mut T::Instance);
566    let imp = instance.imp();
567
568    gst::panic_to_error!(imp, false, {
569        match imp.open() {
570            Ok(()) => true,
571            Err(err) => {
572                imp.post_error_message(err);
573                false
574            }
575        }
576    })
577    .into_glib()
578}
579
580unsafe extern "C" fn audio_decoder_close<T: AudioDecoderImpl>(
581    ptr: *mut ffi::GstAudioDecoder,
582) -> glib::ffi::gboolean {
583    let instance = &*(ptr as *mut T::Instance);
584    let imp = instance.imp();
585
586    gst::panic_to_error!(imp, false, {
587        match imp.close() {
588            Ok(()) => true,
589            Err(err) => {
590                imp.post_error_message(err);
591                false
592            }
593        }
594    })
595    .into_glib()
596}
597
598unsafe extern "C" fn audio_decoder_start<T: AudioDecoderImpl>(
599    ptr: *mut ffi::GstAudioDecoder,
600) -> glib::ffi::gboolean {
601    let instance = &*(ptr as *mut T::Instance);
602    let imp = instance.imp();
603
604    gst::panic_to_error!(imp, false, {
605        match imp.start() {
606            Ok(()) => true,
607            Err(err) => {
608                imp.post_error_message(err);
609                false
610            }
611        }
612    })
613    .into_glib()
614}
615
616unsafe extern "C" fn audio_decoder_stop<T: AudioDecoderImpl>(
617    ptr: *mut ffi::GstAudioDecoder,
618) -> glib::ffi::gboolean {
619    let instance = &*(ptr as *mut T::Instance);
620    let imp = instance.imp();
621
622    gst::panic_to_error!(imp, false, {
623        match imp.stop() {
624            Ok(()) => true,
625            Err(err) => {
626                imp.post_error_message(err);
627                false
628            }
629        }
630    })
631    .into_glib()
632}
633
634unsafe extern "C" fn audio_decoder_set_format<T: AudioDecoderImpl>(
635    ptr: *mut ffi::GstAudioDecoder,
636    caps: *mut gst::ffi::GstCaps,
637) -> glib::ffi::gboolean {
638    let instance = &*(ptr as *mut T::Instance);
639    let imp = instance.imp();
640
641    gst::panic_to_error!(imp, false, {
642        match imp.set_format(&from_glib_borrow(caps)) {
643            Ok(()) => true,
644            Err(err) => {
645                err.log_with_imp(imp);
646                false
647            }
648        }
649    })
650    .into_glib()
651}
652
653unsafe extern "C" fn audio_decoder_parse<T: AudioDecoderImpl>(
654    ptr: *mut ffi::GstAudioDecoder,
655    adapter: *mut gst_base::ffi::GstAdapter,
656    offset: *mut i32,
657    len: *mut i32,
658) -> gst::ffi::GstFlowReturn {
659    let instance = &*(ptr as *mut T::Instance);
660    let imp = instance.imp();
661
662    gst::panic_to_error!(imp, gst::FlowReturn::Error, {
663        match imp.parse(&from_glib_borrow(adapter)) {
664            Ok((new_offset, new_len)) => {
665                assert!(new_offset <= i32::MAX as u32);
666                assert!(new_len <= i32::MAX as u32);
667                *offset = new_offset as i32;
668                *len = new_len as i32;
669                Ok(gst::FlowSuccess::Ok)
670            }
671            Err(err) => Err(err),
672        }
673        .into()
674    })
675    .into_glib()
676}
677
678unsafe extern "C" fn audio_decoder_handle_frame<T: AudioDecoderImpl>(
679    ptr: *mut ffi::GstAudioDecoder,
680    buffer: *mut *mut gst::ffi::GstBuffer,
681) -> gst::ffi::GstFlowReturn {
682    // FIXME: Misgenerated in gstreamer-audio-sys
683    let buffer = buffer as *mut gst::ffi::GstBuffer;
684    let instance = &*(ptr as *mut T::Instance);
685    let imp = instance.imp();
686
687    gst::panic_to_error!(imp, gst::FlowReturn::Error, {
688        imp.handle_frame(Option::<gst::Buffer>::from_glib_none(buffer).as_ref())
689            .into()
690    })
691    .into_glib()
692}
693
694unsafe extern "C" fn audio_decoder_pre_push<T: AudioDecoderImpl>(
695    ptr: *mut ffi::GstAudioDecoder,
696    buffer: *mut *mut gst::ffi::GstBuffer,
697) -> gst::ffi::GstFlowReturn {
698    let instance = &*(ptr as *mut T::Instance);
699    let imp = instance.imp();
700
701    gst::panic_to_error!(imp, gst::FlowReturn::Error, {
702        match imp.pre_push(from_glib_full(*buffer)) {
703            Ok(Some(new_buffer)) => {
704                *buffer = new_buffer.into_glib_ptr();
705                Ok(gst::FlowSuccess::Ok)
706            }
707            Ok(None) => {
708                *buffer = ptr::null_mut();
709                Ok(gst::FlowSuccess::Ok)
710            }
711            Err(err) => Err(err),
712        }
713        .into()
714    })
715    .into_glib()
716}
717
718unsafe extern "C" fn audio_decoder_flush<T: AudioDecoderImpl>(
719    ptr: *mut ffi::GstAudioDecoder,
720    hard: glib::ffi::gboolean,
721) {
722    let instance = &*(ptr as *mut T::Instance);
723    let imp = instance.imp();
724
725    gst::panic_to_error!(imp, (), { AudioDecoderImpl::flush(imp, from_glib(hard)) })
726}
727
728unsafe extern "C" fn audio_decoder_negotiate<T: AudioDecoderImpl>(
729    ptr: *mut ffi::GstAudioDecoder,
730) -> glib::ffi::gboolean {
731    let instance = &*(ptr as *mut T::Instance);
732    let imp = instance.imp();
733
734    gst::panic_to_error!(imp, false, {
735        match imp.negotiate() {
736            Ok(()) => true,
737            Err(err) => {
738                err.log_with_imp(imp);
739                false
740            }
741        }
742    })
743    .into_glib()
744}
745
746unsafe extern "C" fn audio_decoder_getcaps<T: AudioDecoderImpl>(
747    ptr: *mut ffi::GstAudioDecoder,
748    filter: *mut gst::ffi::GstCaps,
749) -> *mut gst::ffi::GstCaps {
750    let instance = &*(ptr as *mut T::Instance);
751    let imp = instance.imp();
752
753    gst::panic_to_error!(imp, gst::Caps::new_empty(), {
754        AudioDecoderImpl::caps(
755            imp,
756            Option::<gst::Caps>::from_glib_borrow(filter)
757                .as_ref()
758                .as_ref(),
759        )
760    })
761    .into_glib_ptr()
762}
763
764unsafe extern "C" fn audio_decoder_sink_event<T: AudioDecoderImpl>(
765    ptr: *mut ffi::GstAudioDecoder,
766    event: *mut gst::ffi::GstEvent,
767) -> glib::ffi::gboolean {
768    let instance = &*(ptr as *mut T::Instance);
769    let imp = instance.imp();
770
771    gst::panic_to_error!(imp, false, { imp.sink_event(from_glib_full(event)) }).into_glib()
772}
773
774unsafe extern "C" fn audio_decoder_sink_query<T: AudioDecoderImpl>(
775    ptr: *mut ffi::GstAudioDecoder,
776    query: *mut gst::ffi::GstQuery,
777) -> glib::ffi::gboolean {
778    let instance = &*(ptr as *mut T::Instance);
779    let imp = instance.imp();
780
781    gst::panic_to_error!(imp, false, {
782        imp.sink_query(gst::QueryRef::from_mut_ptr(query))
783    })
784    .into_glib()
785}
786
787unsafe extern "C" fn audio_decoder_src_event<T: AudioDecoderImpl>(
788    ptr: *mut ffi::GstAudioDecoder,
789    event: *mut gst::ffi::GstEvent,
790) -> glib::ffi::gboolean {
791    let instance = &*(ptr as *mut T::Instance);
792    let imp = instance.imp();
793
794    gst::panic_to_error!(imp, false, { imp.src_event(from_glib_full(event)) }).into_glib()
795}
796
797unsafe extern "C" fn audio_decoder_src_query<T: AudioDecoderImpl>(
798    ptr: *mut ffi::GstAudioDecoder,
799    query: *mut gst::ffi::GstQuery,
800) -> glib::ffi::gboolean {
801    let instance = &*(ptr as *mut T::Instance);
802    let imp = instance.imp();
803
804    gst::panic_to_error!(imp, false, {
805        imp.src_query(gst::QueryRef::from_mut_ptr(query))
806    })
807    .into_glib()
808}
809
810unsafe extern "C" fn audio_decoder_propose_allocation<T: AudioDecoderImpl>(
811    ptr: *mut ffi::GstAudioDecoder,
812    query: *mut gst::ffi::GstQuery,
813) -> glib::ffi::gboolean {
814    let instance = &*(ptr as *mut T::Instance);
815    let imp = instance.imp();
816    let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
817        gst::QueryViewMut::Allocation(allocation) => allocation,
818        _ => unreachable!(),
819    };
820
821    gst::panic_to_error!(imp, false, {
822        match imp.propose_allocation(query) {
823            Ok(()) => true,
824            Err(err) => {
825                err.log_with_imp(imp);
826                false
827            }
828        }
829    })
830    .into_glib()
831}
832
833unsafe extern "C" fn audio_decoder_decide_allocation<T: AudioDecoderImpl>(
834    ptr: *mut ffi::GstAudioDecoder,
835    query: *mut gst::ffi::GstQuery,
836) -> glib::ffi::gboolean {
837    let instance = &*(ptr as *mut T::Instance);
838    let imp = instance.imp();
839    let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
840        gst::QueryViewMut::Allocation(allocation) => allocation,
841        _ => unreachable!(),
842    };
843
844    gst::panic_to_error!(imp, false, {
845        match imp.decide_allocation(query) {
846            Ok(()) => true,
847            Err(err) => {
848                err.log_with_imp(imp);
849                false
850            }
851        }
852    })
853    .into_glib()
854}