gstreamer_audio/
audio_encoder.rs
1use std::{mem, ptr};
4
5use glib::{prelude::*, translate::*};
6
7use crate::{ffi, 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")]
23 fn negotiate(&self) -> Result<(), gst::FlowError> {
24 unsafe {
25 let ret = from_glib(ffi::gst_audio_encoder_negotiate(
26 self.as_ref().to_glib_none().0,
27 ));
28 if ret {
29 Ok(())
30 } else {
31 Err(gst::FlowError::NotNegotiated)
32 }
33 }
34 }
35
36 #[doc(alias = "gst_audio_encoder_set_output_format")]
44 fn set_output_format(&self, caps: &gst::Caps) -> Result<(), gst::FlowError> {
45 unsafe {
46 let ret = from_glib(ffi::gst_audio_encoder_set_output_format(
47 self.as_ref().to_glib_none().0,
48 caps.to_glib_none().0,
49 ));
50 if ret {
51 Ok(())
52 } else {
53 Err(gst::FlowError::NotNegotiated)
54 }
55 }
56 }
57
58 #[doc(alias = "get_allocator")]
74 #[doc(alias = "gst_audio_encoder_get_allocator")]
75 fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
76 unsafe {
77 let mut allocator = ptr::null_mut();
78 let mut params = mem::MaybeUninit::uninit();
79 ffi::gst_audio_encoder_get_allocator(
80 self.as_ref().to_glib_none().0,
81 &mut allocator,
82 params.as_mut_ptr(),
83 );
84 (from_glib_full(allocator), params.assume_init().into())
85 }
86 }
87
88 #[doc(alias = "gst_audio_encoder_set_headers")]
93 fn set_headers(&self, headers: impl IntoIterator<Item = gst::Buffer>) {
94 unsafe {
95 ffi::gst_audio_encoder_set_headers(
96 self.as_ref().to_glib_none().0,
97 headers
98 .into_iter()
99 .collect::<glib::List<_>>()
100 .into_glib_ptr(),
101 );
102 }
103 }
104
105 fn sink_pad(&self) -> &gst::Pad {
106 unsafe {
107 let elt = &*(self.as_ptr() as *const ffi::GstAudioEncoder);
108 &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
109 }
110 }
111
112 fn src_pad(&self) -> &gst::Pad {
113 unsafe {
114 let elt = &*(self.as_ptr() as *const ffi::GstAudioEncoder);
115 &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
116 }
117 }
118
119 fn input_segment(&self) -> gst::Segment {
120 unsafe {
121 let ptr: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _);
122 glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
123 let segment = ptr.input_segment;
124 glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
125 from_glib_none(&segment as *const gst::ffi::GstSegment)
126 }
127 }
128
129 fn output_segment(&self) -> gst::Segment {
130 unsafe {
131 let ptr: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _);
132 glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
133 let segment = ptr.output_segment;
134 glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
135 from_glib_none(&segment as *const gst::ffi::GstSegment)
136 }
137 }
138}
139
140impl<O: IsA<AudioEncoder>> AudioEncoderExtManual for O {}