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::{prelude::*, translate::*};
6
7use crate::AudioEncoder;
8
9mod sealed {
10 pub trait Sealed {}
11 impl<T: super::IsA<super::AudioEncoder>> Sealed for T {}
12}
13
14pub trait AudioEncoderExtManual: sealed::Sealed + IsA<AudioEncoder> + 'static {
15 #[doc(alias = "gst_audio_encoder_negotiate")]
16 fn negotiate(&self) -> Result<(), gst::FlowError> {
17 unsafe {
18 let ret = from_glib(ffi::gst_audio_encoder_negotiate(
19 self.as_ref().to_glib_none().0,
20 ));
21 if ret {
22 Ok(())
23 } else {
24 Err(gst::FlowError::NotNegotiated)
25 }
26 }
27 }
28
29 #[doc(alias = "gst_audio_encoder_set_output_format")]
30 fn set_output_format(&self, caps: &gst::Caps) -> Result<(), gst::FlowError> {
31 unsafe {
32 let ret = from_glib(ffi::gst_audio_encoder_set_output_format(
33 self.as_ref().to_glib_none().0,
34 caps.to_glib_none().0,
35 ));
36 if ret {
37 Ok(())
38 } else {
39 Err(gst::FlowError::NotNegotiated)
40 }
41 }
42 }
43
44 #[doc(alias = "get_allocator")]
45 #[doc(alias = "gst_audio_encoder_get_allocator")]
46 fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
47 unsafe {
48 let mut allocator = ptr::null_mut();
49 let mut params = mem::MaybeUninit::uninit();
50 ffi::gst_audio_encoder_get_allocator(
51 self.as_ref().to_glib_none().0,
52 &mut allocator,
53 params.as_mut_ptr(),
54 );
55 (from_glib_full(allocator), params.assume_init().into())
56 }
57 }
58
59 #[doc(alias = "gst_audio_encoder_set_headers")]
60 fn set_headers(&self, headers: impl IntoIterator<Item = gst::Buffer>) {
61 unsafe {
62 ffi::gst_audio_encoder_set_headers(
63 self.as_ref().to_glib_none().0,
64 headers
65 .into_iter()
66 .collect::<glib::List<_>>()
67 .into_glib_ptr(),
68 );
69 }
70 }
71
72 fn sink_pad(&self) -> &gst::Pad {
73 unsafe {
74 let elt = &*(self.as_ptr() as *const ffi::GstAudioEncoder);
75 &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
76 }
77 }
78
79 fn src_pad(&self) -> &gst::Pad {
80 unsafe {
81 let elt = &*(self.as_ptr() as *const ffi::GstAudioEncoder);
82 &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
83 }
84 }
85}
86
87impl<O: IsA<AudioEncoder>> AudioEncoderExtManual for O {}
88