gstreamer_audio/
audio_encoder.rs1use 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")]
11 fn negotiate(&self) -> Result<(), gst::FlowError> {
12 unsafe {
13 let ret = from_glib(ffi::gst_audio_encoder_negotiate(
14 self.as_ref().to_glib_none().0,
15 ));
16 if ret {
17 Ok(())
18 } else {
19 Err(gst::FlowError::NotNegotiated)
20 }
21 }
22 }
23
24 #[doc(alias = "gst_audio_encoder_set_output_format")]
25 fn set_output_format(&self, caps: &gst::Caps) -> Result<(), gst::FlowError> {
26 unsafe {
27 let ret = from_glib(ffi::gst_audio_encoder_set_output_format(
28 self.as_ref().to_glib_none().0,
29 caps.to_glib_none().0,
30 ));
31 if ret {
32 Ok(())
33 } else {
34 Err(gst::FlowError::NotNegotiated)
35 }
36 }
37 }
38
39 #[doc(alias = "get_allocator")]
40 #[doc(alias = "gst_audio_encoder_get_allocator")]
41 fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
42 unsafe {
43 let mut allocator = ptr::null_mut();
44 let mut params = mem::MaybeUninit::uninit();
45 ffi::gst_audio_encoder_get_allocator(
46 self.as_ref().to_glib_none().0,
47 &mut allocator,
48 params.as_mut_ptr(),
49 );
50 (from_glib_full(allocator), params.assume_init().into())
51 }
52 }
53
54 #[doc(alias = "gst_audio_encoder_set_headers")]
55 fn set_headers(&self, headers: impl IntoIterator<Item = gst::Buffer>) {
56 unsafe {
57 ffi::gst_audio_encoder_set_headers(
58 self.as_ref().to_glib_none().0,
59 headers
60 .into_iter()
61 .collect::<glib::List<_>>()
62 .into_glib_ptr(),
63 );
64 }
65 }
66
67 fn sink_pad(&self) -> &gst::Pad {
68 unsafe {
69 let elt = &*(self.as_ptr() as *const ffi::GstAudioEncoder);
70 &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
71 }
72 }
73
74 fn src_pad(&self) -> &gst::Pad {
75 unsafe {
76 let elt = &*(self.as_ptr() as *const ffi::GstAudioEncoder);
77 &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
78 }
79 }
80
81 fn input_segment(&self) -> gst::Segment {
82 unsafe {
83 let ptr: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _);
84 glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
85 let segment = ptr.input_segment;
86 glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
87 from_glib_none(&segment as *const gst::ffi::GstSegment)
88 }
89 }
90
91 fn output_segment(&self) -> gst::Segment {
92 unsafe {
93 let ptr: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _);
94 glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
95 let segment = ptr.output_segment;
96 glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
97 from_glib_none(&segment as *const gst::ffi::GstSegment)
98 }
99 }
100}
101
102impl<O: IsA<AudioEncoder>> AudioEncoderExtManual for O {}