audio/sink,src: Add support for overriding reset vfunc

This commit is contained in:
Sebastian Dröge 2020-06-30 23:44:29 +03:00
parent cc866b53d0
commit 03893f895c
2 changed files with 62 additions and 0 deletions

View file

@ -40,6 +40,10 @@ pub trait AudioSinkImpl: AudioSinkImplExt + BaseSinkImpl + Send + Sync + 'static
fn write(&self, sink: &AudioSink, audio_data: &[u8]) -> Result<i32, LoggableError> { fn write(&self, sink: &AudioSink, audio_data: &[u8]) -> Result<i32, LoggableError> {
self.parent_write(sink, audio_data) self.parent_write(sink, audio_data)
} }
fn reset(&self, sink: &AudioSink) {
self.parent_reset(sink)
}
} }
pub trait AudioSinkImplExt { pub trait AudioSinkImplExt {
@ -53,6 +57,7 @@ pub trait AudioSinkImplExt {
) -> Result<(), LoggableError>; ) -> Result<(), LoggableError>;
fn parent_unprepare(&self, sink: &AudioSink) -> Result<(), LoggableError>; fn parent_unprepare(&self, sink: &AudioSink) -> Result<(), LoggableError>;
fn parent_write(&self, sink: &AudioSink, audio_data: &[u8]) -> Result<i32, LoggableError>; fn parent_write(&self, sink: &AudioSink, audio_data: &[u8]) -> Result<i32, LoggableError>;
fn parent_reset(&self, sink: &AudioSink);
} }
impl<T: AudioSinkImpl + ObjectImpl> AudioSinkImplExt for T { impl<T: AudioSinkImpl + ObjectImpl> AudioSinkImplExt for T {
@ -167,6 +172,17 @@ impl<T: AudioSinkImpl + ObjectImpl> AudioSinkImplExt for T {
} }
} }
} }
fn parent_reset(&self, sink: &AudioSink) {
unsafe {
let data = self.get_type_data();
let parent_class =
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSinkClass;
if let Some(f) = (*parent_class).reset {
f(sink.to_glib_none().0)
}
}
}
} }
unsafe impl<T: ObjectSubclass + AudioSinkImpl + BaseSinkImpl> IsSubclassable<T> for AudioSinkClass unsafe impl<T: ObjectSubclass + AudioSinkImpl + BaseSinkImpl> IsSubclassable<T> for AudioSinkClass
@ -183,6 +199,7 @@ where
klass.prepare = Some(audiosink_prepare::<T>); klass.prepare = Some(audiosink_prepare::<T>);
klass.unprepare = Some(audiosink_unprepare::<T>); klass.unprepare = Some(audiosink_unprepare::<T>);
klass.write = Some(audiosink_write::<T>); klass.write = Some(audiosink_write::<T>);
klass.reset = Some(audiosink_reset::<T>);
} }
} }
} }
@ -314,3 +331,17 @@ where
imp.write(&wrap, data_slice).unwrap_or(-1) imp.write(&wrap, data_slice).unwrap_or(-1)
}) })
} }
unsafe extern "C" fn audiosink_reset<T: ObjectSubclass>(ptr: *mut gst_audio_sys::GstAudioSink)
where
T: AudioSinkImpl,
T::Instance: PanicPoison,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), (), {
imp.reset(&wrap);
});
}

View file

@ -42,6 +42,10 @@ pub trait AudioSrcImpl: AudioSrcImplExt + BaseSrcImpl + Send + Sync + 'static {
) -> Result<(u32, gst::ClockTime), LoggableError> { ) -> Result<(u32, gst::ClockTime), LoggableError> {
self.parent_read(src, audio_data) self.parent_read(src, audio_data)
} }
fn reset(&self, src: &AudioSrc) {
self.parent_reset(src)
}
} }
pub trait AudioSrcImplExt { pub trait AudioSrcImplExt {
@ -59,6 +63,7 @@ pub trait AudioSrcImplExt {
src: &AudioSrc, src: &AudioSrc,
audio_data: &mut [u8], audio_data: &mut [u8],
) -> Result<(u32, gst::ClockTime), LoggableError>; ) -> Result<(u32, gst::ClockTime), LoggableError>;
fn parent_reset(&self, src: &AudioSrc);
} }
impl<T: AudioSrcImpl + ObjectImpl> AudioSrcImplExt for T { impl<T: AudioSrcImpl + ObjectImpl> AudioSrcImplExt for T {
@ -183,6 +188,17 @@ impl<T: AudioSrcImpl + ObjectImpl> AudioSrcImplExt for T {
} }
} }
} }
fn parent_reset(&self, src: &AudioSrc) {
unsafe {
let data = self.get_type_data();
let parent_class =
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSrcClass;
if let Some(f) = (*parent_class).reset {
f(src.to_glib_none().0)
}
}
}
} }
unsafe impl<T: ObjectSubclass + AudioSrcImpl + BaseSrcImpl> IsSubclassable<T> for AudioSrcClass unsafe impl<T: ObjectSubclass + AudioSrcImpl + BaseSrcImpl> IsSubclassable<T> for AudioSrcClass
@ -199,6 +215,7 @@ where
klass.prepare = Some(audiosrc_prepare::<T>); klass.prepare = Some(audiosrc_prepare::<T>);
klass.unprepare = Some(audiosrc_unprepare::<T>); klass.unprepare = Some(audiosrc_unprepare::<T>);
klass.read = Some(audiosrc_read::<T>); klass.read = Some(audiosrc_read::<T>);
klass.reset = Some(audiosrc_reset::<T>);
} }
} }
} }
@ -334,3 +351,17 @@ where
res res
}) })
} }
unsafe extern "C" fn audiosrc_reset<T: ObjectSubclass>(ptr: *mut gst_audio_sys::GstAudioSrc)
where
T: AudioSrcImpl,
T::Instance: PanicPoison,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), (), {
imp.reset(&wrap);
});
}