Add bindings for Pad::stream_lock()

This commit is contained in:
Sebastian Dröge 2017-08-03 11:09:39 +03:00
parent ed90fcbd10
commit d6c032be7b

View file

@ -23,6 +23,7 @@ use std::ptr;
use glib::{IsA, StaticType}; use glib::{IsA, StaticType};
use glib::translate::{from_glib, from_glib_full, from_glib_none, FromGlib, ToGlib, ToGlibPtr}; use glib::translate::{from_glib, from_glib_full, from_glib_none, FromGlib, ToGlib, ToGlibPtr};
use glib::source::CallbackGuard; use glib::source::CallbackGuard;
use glib_ffi;
use glib_ffi::gpointer; use glib_ffi::gpointer;
use glib::Object; use glib::Object;
@ -64,6 +65,16 @@ pub enum PadProbeData<'a> {
Unknown, Unknown,
} }
pub struct StreamLock(Pad);
impl Drop for StreamLock {
fn drop(&mut self) {
unsafe {
let pad: *mut ffi::GstPad = self.0.to_glib_none().0;
glib_ffi::g_rec_mutex_unlock(&mut (*pad).stream_rec_lock);
}
}
}
pub trait PadExtManual { pub trait PadExtManual {
fn add_probe<F>(&self, mask: PadProbeType, func: F) -> PadProbeId fn add_probe<F>(&self, mask: PadProbeType, func: F) -> PadProbeId
where where
@ -93,6 +104,8 @@ pub trait PadExtManual {
) -> bool; ) -> bool;
fn push_event(&self, event: Event) -> bool; fn push_event(&self, event: Event) -> bool;
fn send_event(&self, event: Event) -> bool; fn send_event(&self, event: Event) -> bool;
fn stream_lock(&self) -> StreamLock;
} }
impl<O: IsA<Pad>> PadExtManual for O { impl<O: IsA<Pad>> PadExtManual for O {
@ -246,6 +259,14 @@ impl<O: IsA<Pad>> PadExtManual for O {
)) ))
} }
} }
fn stream_lock(&self) -> StreamLock {
unsafe {
let pad = self.to_glib_none().0;
glib_ffi::g_rec_mutex_lock(&mut (*pad).stream_rec_lock);
StreamLock(from_glib_none(pad))
}
}
} }
unsafe extern "C" fn trampoline_pad_probe( unsafe extern "C" fn trampoline_pad_probe(