gstreamer_audio/
audio_encoder.rs
1use std::{mem, ptr};
4
5use glib::{prelude::*, translate::*};
6
7use crate::{ffi, AudioEncoder};
8
9pub trait AudioEncoderExtManual: IsA<AudioEncoder> + 'static {
10 #[doc(alias = "gst_audio_encoder_negotiate")]
18 fn negotiate(&self) -> Result<(), gst::FlowError> {
19 unsafe {
20 let ret = from_glib(ffi::gst_audio_encoder_negotiate(
21 self.as_ref().to_glib_none().0,
22 ));
23 if ret {
24 Ok(())
25 } else {
26 Err(gst::FlowError::NotNegotiated)
27 }
28 }
29 }
30
31 #[doc(alias = "gst_audio_encoder_set_output_format")]
39 fn set_output_format(&self, caps: &gst::Caps) -> Result<(), gst::FlowError> {
40 unsafe {
41 let ret = from_glib(ffi::gst_audio_encoder_set_output_format(
42 self.as_ref().to_glib_none().0,
43 caps.to_glib_none().0,
44 ));
45 if ret {
46 Ok(())
47 } else {
48 Err(gst::FlowError::NotNegotiated)
49 }
50 }
51 }
52
53 #[doc(alias = "get_allocator")]
69 #[doc(alias = "gst_audio_encoder_get_allocator")]
70 fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
71 unsafe {
72 let mut allocator = ptr::null_mut();
73 let mut params = mem::MaybeUninit::uninit();
74 ffi::gst_audio_encoder_get_allocator(
75 self.as_ref().to_glib_none().0,
76 &mut allocator,
77 params.as_mut_ptr(),
78 );
79 (from_glib_full(allocator), params.assume_init().into())
80 }
81 }
82
83 #[doc(alias = "gst_audio_encoder_set_headers")]
88 fn set_headers(&self, headers: impl IntoIterator<Item = gst::Buffer>) {
89 unsafe {
90 ffi::gst_audio_encoder_set_headers(
91 self.as_ref().to_glib_none().0,
92 headers
93 .into_iter()
94 .collect::<glib::List<_>>()
95 .into_glib_ptr(),
96 );
97 }
98 }
99
100 fn sink_pad(&self) -> &gst::Pad {
101 unsafe {
102 let elt = &*(self.as_ptr() as *const ffi::GstAudioEncoder);
103 &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
104 }
105 }
106
107 fn src_pad(&self) -> &gst::Pad {
108 unsafe {
109 let elt = &*(self.as_ptr() as *const ffi::GstAudioEncoder);
110 &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
111 }
112 }
113
114 fn input_segment(&self) -> gst::Segment {
115 unsafe {
116 let ptr: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _);
117 glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
118 let segment = ptr.input_segment;
119 glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
120 from_glib_none(&segment as *const gst::ffi::GstSegment)
121 }
122 }
123
124 fn output_segment(&self) -> gst::Segment {
125 unsafe {
126 let ptr: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _);
127 glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
128 let segment = ptr.output_segment;
129 glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
130 from_glib_none(&segment as *const gst::ffi::GstSegment)
131 }
132 }
133}
134
135impl<O: IsA<AudioEncoder>> AudioEncoderExtManual for O {}