| 1 | // Take a look at the license at the top of the repository in the LICENSE file. |
| 2 | |
| 3 | use std::{mem, ptr}; |
| 4 | |
| 5 | use glib::{prelude::*, translate::*}; |
| 6 | |
| 7 | use crate::{ffi, AudioEncoder}; |
| 8 | |
| 9 | mod sealed { |
| 10 | pub trait Sealed {} |
| 11 | impl<T: super::IsA<super::AudioEncoder>> Sealed for T {} |
| 12 | } |
| 13 | |
| 14 | pub 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 | fn input_segment(&self) -> gst::Segment { |
| 87 | unsafe { |
| 88 | let ptr: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _); |
| 89 | glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock)); |
| 90 | let segment = ptr.input_segment; |
| 91 | glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock)); |
| 92 | from_glib_none(&segment as *const gst::ffi::GstSegment) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | fn output_segment(&self) -> gst::Segment { |
| 97 | unsafe { |
| 98 | let ptr: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _); |
| 99 | glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock)); |
| 100 | let segment = ptr.output_segment; |
| 101 | glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock)); |
| 102 | from_glib_none(&segment as *const gst::ffi::GstSegment) |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | impl<O: IsA<AudioEncoder>> AudioEncoderExtManual for O {} |
| 108 | |