forked from mirrors/gstreamer-rs
appsrc need-data and all appsink callbacks can only be called from a single thread at a time
As such, make them FnMut and remove the Sync requirement from them. We can only do this for the callbacks and not the signals, because the signals can in theory be emitted from anybody (outside the object!) at any time.
This commit is contained in:
parent
5ef13a11b0
commit
062403bdac
2 changed files with 19 additions and 17 deletions
|
@ -14,11 +14,12 @@ use glib_ffi::gpointer;
|
||||||
use gst;
|
use gst;
|
||||||
use gst_ffi;
|
use gst_ffi;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
|
||||||
pub struct AppSinkCallbacks {
|
pub struct AppSinkCallbacks {
|
||||||
eos: Option<Box<Fn(&AppSink) + Send + Sync + 'static>>,
|
eos: Option<RefCell<Box<FnMut(&AppSink) + Send + 'static>>>,
|
||||||
new_preroll: Option<Box<Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>>,
|
new_preroll: Option<RefCell<Box<FnMut(&AppSink) -> gst::FlowReturn + Send + 'static>>>,
|
||||||
new_sample: Option<Box<Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>>,
|
new_sample: Option<RefCell<Box<FnMut(&AppSink) -> gst::FlowReturn + Send + 'static>>>,
|
||||||
callbacks: ffi::GstAppSinkCallbacks,
|
callbacks: ffi::GstAppSinkCallbacks,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,15 +38,15 @@ impl AppSinkCallbacks {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppSinkCallbacksBuilder {
|
pub struct AppSinkCallbacksBuilder {
|
||||||
eos: Option<Box<Fn(&AppSink) + Send + Sync + 'static>>,
|
eos: Option<RefCell<Box<FnMut(&AppSink) + Send + 'static>>>,
|
||||||
new_preroll: Option<Box<Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>>,
|
new_preroll: Option<RefCell<Box<FnMut(&AppSink) -> gst::FlowReturn + Send + 'static>>>,
|
||||||
new_sample: Option<Box<Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>>,
|
new_sample: Option<RefCell<Box<FnMut(&AppSink) -> gst::FlowReturn + Send + 'static>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppSinkCallbacksBuilder {
|
impl AppSinkCallbacksBuilder {
|
||||||
pub fn eos<F: Fn(&AppSink) + Send + Sync + 'static>(self, eos: F) -> Self {
|
pub fn eos<F: Fn(&AppSink) + Send + Sync + 'static>(self, eos: F) -> Self {
|
||||||
Self {
|
Self {
|
||||||
eos: Some(Box::new(eos)),
|
eos: Some(RefCell::new(Box::new(eos))),
|
||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +56,7 @@ impl AppSinkCallbacksBuilder {
|
||||||
new_preroll: F,
|
new_preroll: F,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
new_preroll: Some(Box::new(new_preroll)),
|
new_preroll: Some(RefCell::new(Box::new(new_preroll))),
|
||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +66,7 @@ impl AppSinkCallbacksBuilder {
|
||||||
new_sample: F,
|
new_sample: F,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
new_sample: Some(Box::new(new_sample)),
|
new_sample: Some(RefCell::new(Box::new(new_sample))),
|
||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +110,7 @@ unsafe extern "C" fn trampoline_eos(appsink: *mut ffi::GstAppSink, callbacks: gp
|
||||||
callbacks
|
callbacks
|
||||||
.eos
|
.eos
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|f| f(&from_glib_borrow(appsink)));
|
.map(|f| (&mut *f.borrow_mut())(&from_glib_borrow(appsink)));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_new_preroll(
|
unsafe extern "C" fn trampoline_new_preroll(
|
||||||
|
@ -122,7 +123,7 @@ unsafe extern "C" fn trampoline_new_preroll(
|
||||||
callbacks
|
callbacks
|
||||||
.new_preroll
|
.new_preroll
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|f| f(&from_glib_borrow(appsink)))
|
.map(|f| (&mut *f.borrow_mut())(&from_glib_borrow(appsink)))
|
||||||
.unwrap_or(gst::FlowReturn::Error)
|
.unwrap_or(gst::FlowReturn::Error)
|
||||||
.to_glib()
|
.to_glib()
|
||||||
}
|
}
|
||||||
|
@ -137,7 +138,7 @@ unsafe extern "C" fn trampoline_new_sample(
|
||||||
callbacks
|
callbacks
|
||||||
.new_sample
|
.new_sample
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|f| f(&from_glib_borrow(appsink)))
|
.map(|f| (&mut *f.borrow_mut())(&from_glib_borrow(appsink)))
|
||||||
.unwrap_or(gst::FlowReturn::Error)
|
.unwrap_or(gst::FlowReturn::Error)
|
||||||
.to_glib()
|
.to_glib()
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,10 @@ use glib_ffi::{gboolean, gpointer};
|
||||||
use gst;
|
use gst;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
|
||||||
pub struct AppSrcCallbacks {
|
pub struct AppSrcCallbacks {
|
||||||
need_data: Option<Box<Fn(&AppSrc, u32) + Send + Sync + 'static>>,
|
need_data: Option<RefCell<Box<FnMut(&AppSrc, u32) + Send + 'static>>>,
|
||||||
enough_data: Option<Box<Fn(&AppSrc) + Send + Sync + 'static>>,
|
enough_data: Option<Box<Fn(&AppSrc) + Send + Sync + 'static>>,
|
||||||
seek_data: Option<Box<Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>>,
|
seek_data: Option<Box<Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>>,
|
||||||
callbacks: ffi::GstAppSrcCallbacks,
|
callbacks: ffi::GstAppSrcCallbacks,
|
||||||
|
@ -38,15 +39,15 @@ impl AppSrcCallbacks {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppSrcCallbacksBuilder {
|
pub struct AppSrcCallbacksBuilder {
|
||||||
need_data: Option<Box<Fn(&AppSrc, u32) + Send + Sync + 'static>>,
|
need_data: Option<RefCell<Box<FnMut(&AppSrc, u32) + Send + 'static>>>,
|
||||||
enough_data: Option<Box<Fn(&AppSrc) + Send + Sync + 'static>>,
|
enough_data: Option<Box<Fn(&AppSrc) + Send + Sync + 'static>>,
|
||||||
seek_data: Option<Box<Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>>,
|
seek_data: Option<Box<Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppSrcCallbacksBuilder {
|
impl AppSrcCallbacksBuilder {
|
||||||
pub fn need_data<F: Fn(&AppSrc, u32) + Send + Sync + 'static>(self, need_data: F) -> Self {
|
pub fn need_data<F: FnMut(&AppSrc, u32) + Send + 'static>(self, need_data: F) -> Self {
|
||||||
Self {
|
Self {
|
||||||
need_data: Some(Box::new(need_data)),
|
need_data: Some(RefCell::new(Box::new(need_data))),
|
||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +116,7 @@ unsafe extern "C" fn trampoline_need_data(
|
||||||
callbacks
|
callbacks
|
||||||
.need_data
|
.need_data
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|f| f(&from_glib_borrow(appsrc), length));
|
.map(|f| (&mut *f.borrow_mut())(&from_glib_borrow(appsrc), length));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn trampoline_enough_data(appsrc: *mut ffi::GstAppSrc, callbacks: gpointer) {
|
unsafe extern "C" fn trampoline_enough_data(appsrc: *mut ffi::GstAppSrc, callbacks: gpointer) {
|
||||||
|
|
Loading…
Reference in a new issue