gstreamer_audio/subclass/
audio_encoder.rs1use std::ptr;
4
5use glib::translate::*;
6use gst::subclass::prelude::*;
7
8use crate::{AudioEncoder, AudioInfo, ffi, prelude::*};
9
10pub trait AudioEncoderImpl: ElementImpl + ObjectSubclass<Type: IsA<AudioEncoder>> {
11 fn open(&self) -> Result<(), gst::ErrorMessage> {
12 self.parent_open()
13 }
14
15 fn close(&self) -> Result<(), gst::ErrorMessage> {
16 self.parent_close()
17 }
18
19 fn start(&self) -> Result<(), gst::ErrorMessage> {
20 self.parent_start()
21 }
22
23 fn stop(&self) -> Result<(), gst::ErrorMessage> {
24 self.parent_stop()
25 }
26
27 fn set_format(&self, info: &AudioInfo) -> Result<(), gst::LoggableError> {
28 self.parent_set_format(info)
29 }
30
31 fn handle_frame(
32 &self,
33 buffer: Option<&gst::Buffer>,
34 ) -> Result<gst::FlowSuccess, gst::FlowError> {
35 self.parent_handle_frame(buffer)
36 }
37
38 fn pre_push(&self, buffer: gst::Buffer) -> Result<Option<gst::Buffer>, gst::FlowError> {
39 self.parent_pre_push(buffer)
40 }
41
42 fn flush(&self) {
43 self.parent_flush()
44 }
45
46 fn negotiate(&self) -> Result<(), gst::LoggableError> {
47 self.parent_negotiate()
48 }
49
50 fn caps(&self, filter: Option<&gst::Caps>) -> gst::Caps {
51 self.parent_caps(filter)
52 }
53
54 fn sink_event(&self, event: gst::Event) -> bool {
55 self.parent_sink_event(event)
56 }
57
58 fn sink_query(&self, query: &mut gst::QueryRef) -> bool {
59 self.parent_sink_query(query)
60 }
61
62 fn src_event(&self, event: gst::Event) -> bool {
63 self.parent_src_event(event)
64 }
65
66 fn src_query(&self, query: &mut gst::QueryRef) -> bool {
67 self.parent_src_query(query)
68 }
69
70 fn propose_allocation(
71 &self,
72 query: &mut gst::query::Allocation,
73 ) -> Result<(), gst::LoggableError> {
74 self.parent_propose_allocation(query)
75 }
76
77 fn decide_allocation(
78 &self,
79 query: &mut gst::query::Allocation,
80 ) -> Result<(), gst::LoggableError> {
81 self.parent_decide_allocation(query)
82 }
83
84 #[cfg(feature = "v1_30")]
85 #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
86 fn prepare_allocator(&self, caps: Option<&gst::Caps>) -> Result<(), gst::LoggableError> {
87 self.parent_prepare_allocator(caps)
88 }
89}
90
91pub trait AudioEncoderImplExt: AudioEncoderImpl {
92 fn parent_open(&self) -> Result<(), gst::ErrorMessage> {
93 unsafe {
94 let data = Self::type_data();
95 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
96 (*parent_class)
97 .open
98 .map(|f| {
99 if from_glib(f(self
100 .obj()
101 .unsafe_cast_ref::<AudioEncoder>()
102 .to_glib_none()
103 .0))
104 {
105 Ok(())
106 } else {
107 Err(gst::error_msg!(
108 gst::CoreError::StateChange,
109 ["Parent function `open` failed"]
110 ))
111 }
112 })
113 .unwrap_or(Ok(()))
114 }
115 }
116
117 fn parent_close(&self) -> Result<(), gst::ErrorMessage> {
118 unsafe {
119 let data = Self::type_data();
120 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
121 (*parent_class)
122 .close
123 .map(|f| {
124 if from_glib(f(self
125 .obj()
126 .unsafe_cast_ref::<AudioEncoder>()
127 .to_glib_none()
128 .0))
129 {
130 Ok(())
131 } else {
132 Err(gst::error_msg!(
133 gst::CoreError::StateChange,
134 ["Parent function `close` failed"]
135 ))
136 }
137 })
138 .unwrap_or(Ok(()))
139 }
140 }
141
142 fn parent_start(&self) -> Result<(), gst::ErrorMessage> {
143 unsafe {
144 let data = Self::type_data();
145 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
146 (*parent_class)
147 .start
148 .map(|f| {
149 if from_glib(f(self
150 .obj()
151 .unsafe_cast_ref::<AudioEncoder>()
152 .to_glib_none()
153 .0))
154 {
155 Ok(())
156 } else {
157 Err(gst::error_msg!(
158 gst::CoreError::StateChange,
159 ["Parent function `start` failed"]
160 ))
161 }
162 })
163 .unwrap_or(Ok(()))
164 }
165 }
166
167 fn parent_stop(&self) -> Result<(), gst::ErrorMessage> {
168 unsafe {
169 let data = Self::type_data();
170 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
171 (*parent_class)
172 .stop
173 .map(|f| {
174 if from_glib(f(self
175 .obj()
176 .unsafe_cast_ref::<AudioEncoder>()
177 .to_glib_none()
178 .0))
179 {
180 Ok(())
181 } else {
182 Err(gst::error_msg!(
183 gst::CoreError::StateChange,
184 ["Parent function `stop` failed"]
185 ))
186 }
187 })
188 .unwrap_or(Ok(()))
189 }
190 }
191
192 fn parent_set_format(&self, info: &AudioInfo) -> Result<(), gst::LoggableError> {
193 unsafe {
194 let data = Self::type_data();
195 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
196 (*parent_class)
197 .set_format
198 .map(|f| {
199 gst::result_from_gboolean!(
200 f(
201 self.obj()
202 .unsafe_cast_ref::<AudioEncoder>()
203 .to_glib_none()
204 .0,
205 info.to_glib_none().0 as *mut _
206 ),
207 gst::CAT_RUST,
208 "parent function `set_format` failed"
209 )
210 })
211 .unwrap_or(Ok(()))
212 }
213 }
214
215 fn parent_handle_frame(
216 &self,
217 buffer: Option<&gst::Buffer>,
218 ) -> Result<gst::FlowSuccess, gst::FlowError> {
219 unsafe {
220 let data = Self::type_data();
221 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
222 (*parent_class)
223 .handle_frame
224 .map(|f| {
225 try_from_glib(f(
226 self.obj()
227 .unsafe_cast_ref::<AudioEncoder>()
228 .to_glib_none()
229 .0,
230 buffer
231 .map(|buffer| buffer.as_mut_ptr() as *mut *mut gst::ffi::GstBuffer)
232 .unwrap_or(ptr::null_mut()),
233 ))
234 })
235 .unwrap_or(Err(gst::FlowError::Error))
236 }
237 }
238
239 fn parent_pre_push(&self, buffer: gst::Buffer) -> Result<Option<gst::Buffer>, gst::FlowError> {
240 unsafe {
241 let data = Self::type_data();
242 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
243 if let Some(f) = (*parent_class).pre_push {
244 let mut buffer = buffer.into_glib_ptr();
245 gst::FlowSuccess::try_from_glib(f(
246 self.obj()
247 .unsafe_cast_ref::<AudioEncoder>()
248 .to_glib_none()
249 .0,
250 &mut buffer,
251 ))
252 .map(|_| from_glib_full(buffer))
253 } else {
254 Ok(Some(buffer))
255 }
256 }
257 }
258
259 fn parent_flush(&self) {
260 unsafe {
261 let data = Self::type_data();
262 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
263 (*parent_class)
264 .flush
265 .map(|f| {
266 f(self
267 .obj()
268 .unsafe_cast_ref::<AudioEncoder>()
269 .to_glib_none()
270 .0)
271 })
272 .unwrap_or(())
273 }
274 }
275
276 fn parent_negotiate(&self) -> Result<(), gst::LoggableError> {
277 unsafe {
278 let data = Self::type_data();
279 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
280 (*parent_class)
281 .negotiate
282 .map(|f| {
283 gst::result_from_gboolean!(
284 f(self
285 .obj()
286 .unsafe_cast_ref::<AudioEncoder>()
287 .to_glib_none()
288 .0),
289 gst::CAT_RUST,
290 "Parent function `negotiate` failed"
291 )
292 })
293 .unwrap_or(Ok(()))
294 }
295 }
296
297 fn parent_caps(&self, filter: Option<&gst::Caps>) -> gst::Caps {
298 unsafe {
299 let data = Self::type_data();
300 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
301 (*parent_class)
302 .getcaps
303 .map(|f| {
304 from_glib_full(f(
305 self.obj()
306 .unsafe_cast_ref::<AudioEncoder>()
307 .to_glib_none()
308 .0,
309 filter.to_glib_none().0,
310 ))
311 })
312 .unwrap_or_else(|| {
313 self.obj()
314 .unsafe_cast_ref::<AudioEncoder>()
315 .proxy_getcaps(None, filter)
316 })
317 }
318 }
319
320 fn parent_sink_event(&self, event: gst::Event) -> bool {
321 unsafe {
322 let data = Self::type_data();
323 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
324 let f = (*parent_class)
325 .sink_event
326 .expect("Missing parent function `sink_event`");
327 from_glib(f(
328 self.obj()
329 .unsafe_cast_ref::<AudioEncoder>()
330 .to_glib_none()
331 .0,
332 event.into_glib_ptr(),
333 ))
334 }
335 }
336
337 fn parent_sink_query(&self, query: &mut gst::QueryRef) -> bool {
338 unsafe {
339 let data = Self::type_data();
340 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
341 let f = (*parent_class)
342 .sink_query
343 .expect("Missing parent function `sink_query`");
344 from_glib(f(
345 self.obj()
346 .unsafe_cast_ref::<AudioEncoder>()
347 .to_glib_none()
348 .0,
349 query.as_mut_ptr(),
350 ))
351 }
352 }
353
354 fn parent_src_event(&self, event: gst::Event) -> bool {
355 unsafe {
356 let data = Self::type_data();
357 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
358 let f = (*parent_class)
359 .src_event
360 .expect("Missing parent function `src_event`");
361 from_glib(f(
362 self.obj()
363 .unsafe_cast_ref::<AudioEncoder>()
364 .to_glib_none()
365 .0,
366 event.into_glib_ptr(),
367 ))
368 }
369 }
370
371 fn parent_src_query(&self, query: &mut gst::QueryRef) -> bool {
372 unsafe {
373 let data = Self::type_data();
374 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
375 let f = (*parent_class)
376 .src_query
377 .expect("Missing parent function `src_query`");
378 from_glib(f(
379 self.obj()
380 .unsafe_cast_ref::<AudioEncoder>()
381 .to_glib_none()
382 .0,
383 query.as_mut_ptr(),
384 ))
385 }
386 }
387
388 fn parent_propose_allocation(
389 &self,
390 query: &mut gst::query::Allocation,
391 ) -> Result<(), gst::LoggableError> {
392 unsafe {
393 let data = Self::type_data();
394 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
395 (*parent_class)
396 .propose_allocation
397 .map(|f| {
398 gst::result_from_gboolean!(
399 f(
400 self.obj()
401 .unsafe_cast_ref::<AudioEncoder>()
402 .to_glib_none()
403 .0,
404 query.as_mut_ptr(),
405 ),
406 gst::CAT_RUST,
407 "Parent function `propose_allocation` failed",
408 )
409 })
410 .unwrap_or(Ok(()))
411 }
412 }
413
414 fn parent_decide_allocation(
415 &self,
416 query: &mut gst::query::Allocation,
417 ) -> Result<(), gst::LoggableError> {
418 unsafe {
419 let data = Self::type_data();
420 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
421 (*parent_class)
422 .decide_allocation
423 .map(|f| {
424 gst::result_from_gboolean!(
425 f(
426 self.obj()
427 .unsafe_cast_ref::<AudioEncoder>()
428 .to_glib_none()
429 .0,
430 query.as_mut_ptr(),
431 ),
432 gst::CAT_RUST,
433 "Parent function `decide_allocation` failed",
434 )
435 })
436 .unwrap_or(Ok(()))
437 }
438 }
439
440 #[cfg(feature = "v1_30")]
441 #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
442 fn parent_prepare_allocator(&self, caps: Option<&gst::Caps>) -> Result<(), gst::LoggableError> {
443 unsafe {
444 let data = Self::type_data();
445 let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
446 (*parent_class)
447 .prepare_allocator
448 .map(|f| {
449 gst::result_from_gboolean!(
450 f(
451 self.obj()
452 .unsafe_cast_ref::<AudioEncoder>()
453 .to_glib_none()
454 .0,
455 caps.to_glib_none().0
456 ),
457 gst::CAT_RUST,
458 "Parent function `prepare_allocator` failed",
459 )
460 })
461 .unwrap_or(Ok(()))
462 }
463 }
464}
465
466impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {}
467
468unsafe impl<T: AudioEncoderImpl> IsSubclassable<T> for AudioEncoder {
469 fn class_init(klass: &mut glib::Class<Self>) {
470 Self::parent_class_init::<T>(klass);
471 let klass = klass.as_mut();
472 klass.open = Some(audio_encoder_open::<T>);
473 klass.close = Some(audio_encoder_close::<T>);
474 klass.start = Some(audio_encoder_start::<T>);
475 klass.stop = Some(audio_encoder_stop::<T>);
476 klass.set_format = Some(audio_encoder_set_format::<T>);
477 klass.handle_frame = Some(audio_encoder_handle_frame::<T>);
478 klass.pre_push = Some(audio_encoder_pre_push::<T>);
479 klass.flush = Some(audio_encoder_flush::<T>);
480 klass.negotiate = Some(audio_encoder_negotiate::<T>);
481 klass.getcaps = Some(audio_encoder_getcaps::<T>);
482 klass.sink_event = Some(audio_encoder_sink_event::<T>);
483 klass.src_event = Some(audio_encoder_src_event::<T>);
484 klass.sink_query = Some(audio_encoder_sink_query::<T>);
485 klass.src_query = Some(audio_encoder_src_query::<T>);
486 klass.propose_allocation = Some(audio_encoder_propose_allocation::<T>);
487 klass.decide_allocation = Some(audio_encoder_decide_allocation::<T>);
488 #[cfg(feature = "v1_30")]
489 {
490 klass.prepare_allocator = Some(audio_encoder_prepare_allocator::<T>);
491 }
492 }
493}
494
495unsafe extern "C" fn audio_encoder_open<T: AudioEncoderImpl>(
496 ptr: *mut ffi::GstAudioEncoder,
497) -> glib::ffi::gboolean {
498 unsafe {
499 let instance = &*(ptr as *mut T::Instance);
500 let imp = instance.imp();
501
502 gst::panic_to_error!(imp, false, {
503 match imp.open() {
504 Ok(()) => true,
505 Err(err) => {
506 imp.post_error_message(err);
507 false
508 }
509 }
510 })
511 .into_glib()
512 }
513}
514
515unsafe extern "C" fn audio_encoder_close<T: AudioEncoderImpl>(
516 ptr: *mut ffi::GstAudioEncoder,
517) -> glib::ffi::gboolean {
518 unsafe {
519 let instance = &*(ptr as *mut T::Instance);
520 let imp = instance.imp();
521
522 gst::panic_to_error!(imp, false, {
523 match imp.close() {
524 Ok(()) => true,
525 Err(err) => {
526 imp.post_error_message(err);
527 false
528 }
529 }
530 })
531 .into_glib()
532 }
533}
534
535unsafe extern "C" fn audio_encoder_start<T: AudioEncoderImpl>(
536 ptr: *mut ffi::GstAudioEncoder,
537) -> glib::ffi::gboolean {
538 unsafe {
539 let instance = &*(ptr as *mut T::Instance);
540 let imp = instance.imp();
541
542 gst::panic_to_error!(imp, false, {
543 match imp.start() {
544 Ok(()) => true,
545 Err(err) => {
546 imp.post_error_message(err);
547 false
548 }
549 }
550 })
551 .into_glib()
552 }
553}
554
555unsafe extern "C" fn audio_encoder_stop<T: AudioEncoderImpl>(
556 ptr: *mut ffi::GstAudioEncoder,
557) -> glib::ffi::gboolean {
558 unsafe {
559 let instance = &*(ptr as *mut T::Instance);
560 let imp = instance.imp();
561
562 gst::panic_to_error!(imp, false, {
563 match imp.stop() {
564 Ok(()) => true,
565 Err(err) => {
566 imp.post_error_message(err);
567 false
568 }
569 }
570 })
571 .into_glib()
572 }
573}
574
575unsafe extern "C" fn audio_encoder_set_format<T: AudioEncoderImpl>(
576 ptr: *mut ffi::GstAudioEncoder,
577 info: *mut ffi::GstAudioInfo,
578) -> glib::ffi::gboolean {
579 unsafe {
580 let instance = &*(ptr as *mut T::Instance);
581 let imp = instance.imp();
582
583 gst::panic_to_error!(imp, false, {
584 match imp.set_format(&from_glib_none(info)) {
585 Ok(()) => true,
586 Err(err) => {
587 err.log_with_imp(imp);
588 false
589 }
590 }
591 })
592 .into_glib()
593 }
594}
595
596unsafe extern "C" fn audio_encoder_handle_frame<T: AudioEncoderImpl>(
597 ptr: *mut ffi::GstAudioEncoder,
598 buffer: *mut *mut gst::ffi::GstBuffer,
599) -> gst::ffi::GstFlowReturn {
600 unsafe {
601 let buffer = buffer as *mut gst::ffi::GstBuffer;
603 let instance = &*(ptr as *mut T::Instance);
604 let imp = instance.imp();
605
606 gst::panic_to_error!(imp, gst::FlowReturn::Error, {
607 imp.handle_frame(Option::<gst::Buffer>::from_glib_none(buffer).as_ref())
608 .into()
609 })
610 .into_glib()
611 }
612}
613
614unsafe extern "C" fn audio_encoder_pre_push<T: AudioEncoderImpl>(
615 ptr: *mut ffi::GstAudioEncoder,
616 buffer: *mut *mut gst::ffi::GstBuffer,
617) -> gst::ffi::GstFlowReturn {
618 unsafe {
619 let instance = &*(ptr as *mut T::Instance);
620 let imp = instance.imp();
621
622 gst::panic_to_error!(imp, gst::FlowReturn::Error, {
623 match imp.pre_push(from_glib_full(*buffer)) {
624 Ok(Some(new_buffer)) => {
625 *buffer = new_buffer.into_glib_ptr();
626 Ok(gst::FlowSuccess::Ok)
627 }
628 Ok(None) => {
629 *buffer = ptr::null_mut();
630 Ok(gst::FlowSuccess::Ok)
631 }
632 Err(err) => Err(err),
633 }
634 .into()
635 })
636 .into_glib()
637 }
638}
639
640unsafe extern "C" fn audio_encoder_flush<T: AudioEncoderImpl>(ptr: *mut ffi::GstAudioEncoder) {
641 unsafe {
642 let instance = &*(ptr as *mut T::Instance);
643 let imp = instance.imp();
644
645 gst::panic_to_error!(imp, (), { AudioEncoderImpl::flush(imp,) })
646 }
647}
648
649unsafe extern "C" fn audio_encoder_negotiate<T: AudioEncoderImpl>(
650 ptr: *mut ffi::GstAudioEncoder,
651) -> glib::ffi::gboolean {
652 unsafe {
653 let instance = &*(ptr as *mut T::Instance);
654 let imp = instance.imp();
655
656 gst::panic_to_error!(imp, false, {
657 match imp.negotiate() {
658 Ok(()) => true,
659 Err(err) => {
660 err.log_with_imp(imp);
661 false
662 }
663 }
664 })
665 .into_glib()
666 }
667}
668
669unsafe extern "C" fn audio_encoder_getcaps<T: AudioEncoderImpl>(
670 ptr: *mut ffi::GstAudioEncoder,
671 filter: *mut gst::ffi::GstCaps,
672) -> *mut gst::ffi::GstCaps {
673 unsafe {
674 let instance = &*(ptr as *mut T::Instance);
675 let imp = instance.imp();
676
677 gst::panic_to_error!(imp, gst::Caps::new_empty(), {
678 AudioEncoderImpl::caps(
679 imp,
680 Option::<gst::Caps>::from_glib_borrow(filter)
681 .as_ref()
682 .as_ref(),
683 )
684 })
685 .into_glib_ptr()
686 }
687}
688
689unsafe extern "C" fn audio_encoder_sink_event<T: AudioEncoderImpl>(
690 ptr: *mut ffi::GstAudioEncoder,
691 event: *mut gst::ffi::GstEvent,
692) -> glib::ffi::gboolean {
693 unsafe {
694 let instance = &*(ptr as *mut T::Instance);
695 let imp = instance.imp();
696
697 gst::panic_to_error!(imp, false, { imp.sink_event(from_glib_full(event)) }).into_glib()
698 }
699}
700
701unsafe extern "C" fn audio_encoder_sink_query<T: AudioEncoderImpl>(
702 ptr: *mut ffi::GstAudioEncoder,
703 query: *mut gst::ffi::GstQuery,
704) -> glib::ffi::gboolean {
705 unsafe {
706 let instance = &*(ptr as *mut T::Instance);
707 let imp = instance.imp();
708
709 gst::panic_to_error!(imp, false, {
710 imp.sink_query(gst::QueryRef::from_mut_ptr(query))
711 })
712 .into_glib()
713 }
714}
715
716unsafe extern "C" fn audio_encoder_src_event<T: AudioEncoderImpl>(
717 ptr: *mut ffi::GstAudioEncoder,
718 event: *mut gst::ffi::GstEvent,
719) -> glib::ffi::gboolean {
720 unsafe {
721 let instance = &*(ptr as *mut T::Instance);
722 let imp = instance.imp();
723
724 gst::panic_to_error!(imp, false, { imp.src_event(from_glib_full(event)) }).into_glib()
725 }
726}
727
728unsafe extern "C" fn audio_encoder_src_query<T: AudioEncoderImpl>(
729 ptr: *mut ffi::GstAudioEncoder,
730 query: *mut gst::ffi::GstQuery,
731) -> glib::ffi::gboolean {
732 unsafe {
733 let instance = &*(ptr as *mut T::Instance);
734 let imp = instance.imp();
735
736 gst::panic_to_error!(imp, false, {
737 imp.src_query(gst::QueryRef::from_mut_ptr(query))
738 })
739 .into_glib()
740 }
741}
742
743unsafe extern "C" fn audio_encoder_propose_allocation<T: AudioEncoderImpl>(
744 ptr: *mut ffi::GstAudioEncoder,
745 query: *mut gst::ffi::GstQuery,
746) -> glib::ffi::gboolean {
747 unsafe {
748 let instance = &*(ptr as *mut T::Instance);
749 let imp = instance.imp();
750 let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
751 gst::QueryViewMut::Allocation(allocation) => allocation,
752 _ => unreachable!(),
753 };
754
755 gst::panic_to_error!(imp, false, {
756 match imp.propose_allocation(query) {
757 Ok(()) => true,
758 Err(err) => {
759 err.log_with_imp(imp);
760 false
761 }
762 }
763 })
764 .into_glib()
765 }
766}
767
768unsafe extern "C" fn audio_encoder_decide_allocation<T: AudioEncoderImpl>(
769 ptr: *mut ffi::GstAudioEncoder,
770 query: *mut gst::ffi::GstQuery,
771) -> glib::ffi::gboolean {
772 unsafe {
773 let instance = &*(ptr as *mut T::Instance);
774 let imp = instance.imp();
775 let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
776 gst::QueryViewMut::Allocation(allocation) => allocation,
777 _ => unreachable!(),
778 };
779
780 gst::panic_to_error!(imp, false, {
781 match imp.decide_allocation(query) {
782 Ok(()) => true,
783 Err(err) => {
784 err.log_with_imp(imp);
785 false
786 }
787 }
788 })
789 .into_glib()
790 }
791}
792
793#[cfg(feature = "v1_30")]
794#[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
795unsafe extern "C" fn audio_encoder_prepare_allocator<T: AudioEncoderImpl>(
796 ptr: *mut ffi::GstAudioEncoder,
797 caps: *mut gst::ffi::GstCaps,
798) -> glib::ffi::gboolean {
799 unsafe {
800 let instance = &*(ptr as *mut T::Instance);
801 let imp = instance.imp();
802 let caps = Option::<gst::Caps>::from_glib_none(caps);
803
804 gst::panic_to_error!(imp, false, {
805 match imp.prepare_allocator(caps.as_ref()) {
806 Ok(()) => true,
807 Err(err) => {
808 err.log_with_imp(imp);
809 false
810 }
811 }
812 })
813 .into_glib()
814 }
815}