mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 11:01:10 +00:00
app: Remove signals bindings from appsrc/appsink for the signals that also have callbacks
The callbacks are more flexible and performant. Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/338
This commit is contained in:
parent
33484258d1
commit
04e6c1b547
4 changed files with 136 additions and 323 deletions
|
@ -61,17 +61,35 @@ final_type = true
|
||||||
# Action signal
|
# Action signal
|
||||||
ignore = true
|
ignore = true
|
||||||
|
|
||||||
|
[[object.property]]
|
||||||
|
name = "emit-signals"
|
||||||
|
# Use callbacks instead
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.function]]
|
||||||
|
name = "get_emit_signals"
|
||||||
|
# Use callbacks instead
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.function]]
|
||||||
|
name = "set_emit_signals"
|
||||||
|
# Use callbacks instead
|
||||||
|
ignore = true
|
||||||
|
|
||||||
[[object.signal]]
|
[[object.signal]]
|
||||||
name = "new-sample"
|
name = "new-sample"
|
||||||
concurrency = "send"
|
# Use callbacks instead
|
||||||
|
ignore = true
|
||||||
|
|
||||||
[[object.signal]]
|
[[object.signal]]
|
||||||
name = "new-preroll"
|
name = "new-preroll"
|
||||||
concurrency = "send"
|
# Use callbacks instead
|
||||||
|
ignore = true
|
||||||
|
|
||||||
[[object.signal]]
|
[[object.signal]]
|
||||||
name = "eos"
|
name = "eos"
|
||||||
concurrency = "send"
|
# Use callbacks instead
|
||||||
|
ignore = true
|
||||||
|
|
||||||
[[object.function]]
|
[[object.function]]
|
||||||
name = "set_caps"
|
name = "set_caps"
|
||||||
|
@ -124,6 +142,36 @@ final_type = true
|
||||||
# Action signal
|
# Action signal
|
||||||
ignore = true
|
ignore = true
|
||||||
|
|
||||||
|
[[object.property]]
|
||||||
|
name = "emit-signals"
|
||||||
|
# Use callbacks instead
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.function]]
|
||||||
|
name = "get_emit_signals"
|
||||||
|
# Use callbacks instead
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.function]]
|
||||||
|
name = "set_emit_signals"
|
||||||
|
# Use callbacks instead
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.signal]]
|
||||||
|
name = "enough-data"
|
||||||
|
# Use callbacks instead
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.signal]]
|
||||||
|
name = "need-data"
|
||||||
|
# Use callbacks instead
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.signal]]
|
||||||
|
name = "seek-data"
|
||||||
|
# Use callbacks instead
|
||||||
|
ignore = true
|
||||||
|
|
||||||
[[object.function]]
|
[[object.function]]
|
||||||
name = "set_latency"
|
name = "set_latency"
|
||||||
# ClockTime
|
# ClockTime
|
||||||
|
|
|
@ -45,12 +45,6 @@ impl AppSink {
|
||||||
unsafe { from_glib(ffi::gst_app_sink_get_drop(self.to_glib_none().0)) }
|
unsafe { from_glib(ffi::gst_app_sink_get_drop(self.to_glib_none().0)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_app_sink_get_emit_signals")]
|
|
||||||
#[doc(alias = "get_emit_signals")]
|
|
||||||
pub fn emits_signals(&self) -> bool {
|
|
||||||
unsafe { from_glib(ffi::gst_app_sink_get_emit_signals(self.to_glib_none().0)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "gst_app_sink_get_max_buffers")]
|
#[doc(alias = "gst_app_sink_get_max_buffers")]
|
||||||
#[doc(alias = "get_max_buffers")]
|
#[doc(alias = "get_max_buffers")]
|
||||||
pub fn max_buffers(&self) -> u32 {
|
pub fn max_buffers(&self) -> u32 {
|
||||||
|
@ -115,13 +109,6 @@ impl AppSink {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_app_sink_set_emit_signals")]
|
|
||||||
pub fn set_emit_signals(&self, emit: bool) {
|
|
||||||
unsafe {
|
|
||||||
ffi::gst_app_sink_set_emit_signals(self.to_glib_none().0, emit.into_glib());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "gst_app_sink_set_max_buffers")]
|
#[doc(alias = "gst_app_sink_set_max_buffers")]
|
||||||
pub fn set_max_buffers(&self, max: u32) {
|
pub fn set_max_buffers(&self, max: u32) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -186,86 +173,6 @@ impl AppSink {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "eos")]
|
|
||||||
pub fn connect_eos<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId {
|
|
||||||
unsafe extern "C" fn eos_trampoline<F: Fn(&AppSink) + Send + 'static>(
|
|
||||||
this: *mut ffi::GstAppSink,
|
|
||||||
f: glib::ffi::gpointer,
|
|
||||||
) {
|
|
||||||
let f: &F = &*(f as *const F);
|
|
||||||
f(&from_glib_borrow(this))
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
let f: Box_<F> = Box_::new(f);
|
|
||||||
connect_raw(
|
|
||||||
self.as_ptr() as *mut _,
|
|
||||||
b"eos\0".as_ptr() as *const _,
|
|
||||||
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
||||||
eos_trampoline::<F> as *const (),
|
|
||||||
)),
|
|
||||||
Box_::into_raw(f),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "new-preroll")]
|
|
||||||
pub fn connect_new_preroll<
|
|
||||||
F: Fn(&Self) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static,
|
|
||||||
>(
|
|
||||||
&self,
|
|
||||||
f: F,
|
|
||||||
) -> SignalHandlerId {
|
|
||||||
unsafe extern "C" fn new_preroll_trampoline<
|
|
||||||
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static,
|
|
||||||
>(
|
|
||||||
this: *mut ffi::GstAppSink,
|
|
||||||
f: glib::ffi::gpointer,
|
|
||||||
) -> gst::ffi::GstFlowReturn {
|
|
||||||
let f: &F = &*(f as *const F);
|
|
||||||
f(&from_glib_borrow(this)).into_glib()
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
let f: Box_<F> = Box_::new(f);
|
|
||||||
connect_raw(
|
|
||||||
self.as_ptr() as *mut _,
|
|
||||||
b"new-preroll\0".as_ptr() as *const _,
|
|
||||||
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
||||||
new_preroll_trampoline::<F> as *const (),
|
|
||||||
)),
|
|
||||||
Box_::into_raw(f),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "new-sample")]
|
|
||||||
pub fn connect_new_sample<
|
|
||||||
F: Fn(&Self) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static,
|
|
||||||
>(
|
|
||||||
&self,
|
|
||||||
f: F,
|
|
||||||
) -> SignalHandlerId {
|
|
||||||
unsafe extern "C" fn new_sample_trampoline<
|
|
||||||
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static,
|
|
||||||
>(
|
|
||||||
this: *mut ffi::GstAppSink,
|
|
||||||
f: glib::ffi::gpointer,
|
|
||||||
) -> gst::ffi::GstFlowReturn {
|
|
||||||
let f: &F = &*(f as *const F);
|
|
||||||
f(&from_glib_borrow(this)).into_glib()
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
let f: Box_<F> = Box_::new(f);
|
|
||||||
connect_raw(
|
|
||||||
self.as_ptr() as *mut _,
|
|
||||||
b"new-sample\0".as_ptr() as *const _,
|
|
||||||
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
||||||
new_sample_trampoline::<F> as *const (),
|
|
||||||
)),
|
|
||||||
Box_::into_raw(f),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "buffer-list")]
|
#[doc(alias = "buffer-list")]
|
||||||
pub fn connect_buffer_list_notify<F: Fn(&Self) + Send + Sync + 'static>(
|
pub fn connect_buffer_list_notify<F: Fn(&Self) + Send + Sync + 'static>(
|
||||||
&self,
|
&self,
|
||||||
|
@ -346,34 +253,6 @@ impl AppSink {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "emit-signals")]
|
|
||||||
pub fn connect_emit_signals_notify<F: Fn(&Self) + Send + Sync + 'static>(
|
|
||||||
&self,
|
|
||||||
f: F,
|
|
||||||
) -> SignalHandlerId {
|
|
||||||
unsafe extern "C" fn notify_emit_signals_trampoline<
|
|
||||||
F: Fn(&AppSink) + Send + Sync + 'static,
|
|
||||||
>(
|
|
||||||
this: *mut ffi::GstAppSink,
|
|
||||||
_param_spec: glib::ffi::gpointer,
|
|
||||||
f: glib::ffi::gpointer,
|
|
||||||
) {
|
|
||||||
let f: &F = &*(f as *const F);
|
|
||||||
f(&from_glib_borrow(this))
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
let f: Box_<F> = Box_::new(f);
|
|
||||||
connect_raw(
|
|
||||||
self.as_ptr() as *mut _,
|
|
||||||
b"notify::emit-signals\0".as_ptr() as *const _,
|
|
||||||
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
||||||
notify_emit_signals_trampoline::<F> as *const (),
|
|
||||||
)),
|
|
||||||
Box_::into_raw(f),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "eos")]
|
#[doc(alias = "eos")]
|
||||||
pub fn connect_eos_notify<F: Fn(&Self) + Send + Sync + 'static>(
|
pub fn connect_eos_notify<F: Fn(&Self) + Send + Sync + 'static>(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -47,12 +47,6 @@ impl AppSrc {
|
||||||
unsafe { from_glib(ffi::gst_app_src_get_duration(self.to_glib_none().0)) }
|
unsafe { from_glib(ffi::gst_app_src_get_duration(self.to_glib_none().0)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_app_src_get_emit_signals")]
|
|
||||||
#[doc(alias = "get_emit_signals")]
|
|
||||||
pub fn emits_signals(&self) -> bool {
|
|
||||||
unsafe { from_glib(ffi::gst_app_src_get_emit_signals(self.to_glib_none().0)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "gst_app_src_get_max_bytes")]
|
#[doc(alias = "gst_app_src_get_max_bytes")]
|
||||||
#[doc(alias = "get_max_bytes")]
|
#[doc(alias = "get_max_bytes")]
|
||||||
pub fn max_bytes(&self) -> u64 {
|
pub fn max_bytes(&self) -> u64 {
|
||||||
|
@ -102,13 +96,6 @@ impl AppSrc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_app_src_set_emit_signals")]
|
|
||||||
pub fn set_emit_signals(&self, emit: bool) {
|
|
||||||
unsafe {
|
|
||||||
ffi::gst_app_src_set_emit_signals(self.to_glib_none().0, emit.into_glib());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "gst_app_src_set_max_bytes")]
|
#[doc(alias = "gst_app_src_set_max_bytes")]
|
||||||
pub fn set_max_bytes(&self, max: u64) {
|
pub fn set_max_bytes(&self, max: u64) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -312,85 +299,6 @@ impl AppSrc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "enough-data")]
|
|
||||||
pub fn connect_enough_data<F: Fn(&Self) + Send + Sync + 'static>(
|
|
||||||
&self,
|
|
||||||
f: F,
|
|
||||||
) -> SignalHandlerId {
|
|
||||||
unsafe extern "C" fn enough_data_trampoline<F: Fn(&AppSrc) + Send + Sync + 'static>(
|
|
||||||
this: *mut ffi::GstAppSrc,
|
|
||||||
f: glib::ffi::gpointer,
|
|
||||||
) {
|
|
||||||
let f: &F = &*(f as *const F);
|
|
||||||
f(&from_glib_borrow(this))
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
let f: Box_<F> = Box_::new(f);
|
|
||||||
connect_raw(
|
|
||||||
self.as_ptr() as *mut _,
|
|
||||||
b"enough-data\0".as_ptr() as *const _,
|
|
||||||
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
||||||
enough_data_trampoline::<F> as *const (),
|
|
||||||
)),
|
|
||||||
Box_::into_raw(f),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "need-data")]
|
|
||||||
pub fn connect_need_data<F: Fn(&Self, u32) + Send + Sync + 'static>(
|
|
||||||
&self,
|
|
||||||
f: F,
|
|
||||||
) -> SignalHandlerId {
|
|
||||||
unsafe extern "C" fn need_data_trampoline<F: Fn(&AppSrc, u32) + Send + Sync + 'static>(
|
|
||||||
this: *mut ffi::GstAppSrc,
|
|
||||||
length: libc::c_uint,
|
|
||||||
f: glib::ffi::gpointer,
|
|
||||||
) {
|
|
||||||
let f: &F = &*(f as *const F);
|
|
||||||
f(&from_glib_borrow(this), length)
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
let f: Box_<F> = Box_::new(f);
|
|
||||||
connect_raw(
|
|
||||||
self.as_ptr() as *mut _,
|
|
||||||
b"need-data\0".as_ptr() as *const _,
|
|
||||||
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
||||||
need_data_trampoline::<F> as *const (),
|
|
||||||
)),
|
|
||||||
Box_::into_raw(f),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "seek-data")]
|
|
||||||
pub fn connect_seek_data<F: Fn(&Self, u64) -> bool + Send + Sync + 'static>(
|
|
||||||
&self,
|
|
||||||
f: F,
|
|
||||||
) -> SignalHandlerId {
|
|
||||||
unsafe extern "C" fn seek_data_trampoline<
|
|
||||||
F: Fn(&AppSrc, u64) -> bool + Send + Sync + 'static,
|
|
||||||
>(
|
|
||||||
this: *mut ffi::GstAppSrc,
|
|
||||||
offset: u64,
|
|
||||||
f: glib::ffi::gpointer,
|
|
||||||
) -> glib::ffi::gboolean {
|
|
||||||
let f: &F = &*(f as *const F);
|
|
||||||
f(&from_glib_borrow(this), offset).into_glib()
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
let f: Box_<F> = Box_::new(f);
|
|
||||||
connect_raw(
|
|
||||||
self.as_ptr() as *mut _,
|
|
||||||
b"seek-data\0".as_ptr() as *const _,
|
|
||||||
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
||||||
seek_data_trampoline::<F> as *const (),
|
|
||||||
)),
|
|
||||||
Box_::into_raw(f),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "block")]
|
#[doc(alias = "block")]
|
||||||
pub fn connect_block_notify<F: Fn(&Self) + Send + Sync + 'static>(
|
pub fn connect_block_notify<F: Fn(&Self) + Send + Sync + 'static>(
|
||||||
&self,
|
&self,
|
||||||
|
@ -499,34 +407,6 @@ impl AppSrc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "emit-signals")]
|
|
||||||
pub fn connect_emit_signals_notify<F: Fn(&Self) + Send + Sync + 'static>(
|
|
||||||
&self,
|
|
||||||
f: F,
|
|
||||||
) -> SignalHandlerId {
|
|
||||||
unsafe extern "C" fn notify_emit_signals_trampoline<
|
|
||||||
F: Fn(&AppSrc) + Send + Sync + 'static,
|
|
||||||
>(
|
|
||||||
this: *mut ffi::GstAppSrc,
|
|
||||||
_param_spec: glib::ffi::gpointer,
|
|
||||||
f: glib::ffi::gpointer,
|
|
||||||
) {
|
|
||||||
let f: &F = &*(f as *const F);
|
|
||||||
f(&from_glib_borrow(this))
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
let f: Box_<F> = Box_::new(f);
|
|
||||||
connect_raw(
|
|
||||||
self.as_ptr() as *mut _,
|
|
||||||
b"notify::emit-signals\0".as_ptr() as *const _,
|
|
||||||
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
||||||
notify_emit_signals_trampoline::<F> as *const (),
|
|
||||||
)),
|
|
||||||
Box_::into_raw(f),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "format")]
|
#[doc(alias = "format")]
|
||||||
pub fn connect_format_notify<F: Fn(&Self) + Send + Sync + 'static>(
|
pub fn connect_format_notify<F: Fn(&Self) + Send + Sync + 'static>(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -136,7 +136,10 @@ fn main() {
|
||||||
let data: Arc<Mutex<CustomData>> = Arc::new(Mutex::new(CustomData::new(&appsrc, &appsink)));
|
let data: Arc<Mutex<CustomData>> = Arc::new(Mutex::new(CustomData::new(&appsrc, &appsink)));
|
||||||
|
|
||||||
let data_weak = Arc::downgrade(&data);
|
let data_weak = Arc::downgrade(&data);
|
||||||
appsrc.connect_need_data(move |_, _size| {
|
let data_weak2 = Arc::downgrade(&data);
|
||||||
|
appsrc.set_callbacks(
|
||||||
|
gst_app::AppSrcCallbacks::builder()
|
||||||
|
.need_data(move |_, _size| {
|
||||||
let data = match data_weak.upgrade() {
|
let data = match data_weak.upgrade() {
|
||||||
Some(data) => data,
|
Some(data) => data,
|
||||||
None => return,
|
None => return,
|
||||||
|
@ -194,11 +197,9 @@ fn main() {
|
||||||
glib::Continue(appsrc.push_buffer(buffer).is_ok())
|
glib::Continue(appsrc.push_buffer(buffer).is_ok())
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.enough_data(move |_| {
|
||||||
let data_weak = Arc::downgrade(&data);
|
let data = match data_weak2.upgrade() {
|
||||||
appsrc.connect_enough_data(move |_| {
|
|
||||||
let data = match data_weak.upgrade() {
|
|
||||||
Some(data) => data,
|
Some(data) => data,
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
@ -208,14 +209,17 @@ fn main() {
|
||||||
println!("stop feeding");
|
println!("stop feeding");
|
||||||
glib::source::source_remove(source);
|
glib::source::source_remove(source);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.build(),
|
||||||
|
);
|
||||||
|
|
||||||
// configure appsink
|
// configure appsink
|
||||||
appsink.set_emit_signals(true);
|
|
||||||
appsink.set_caps(Some(&audio_caps));
|
appsink.set_caps(Some(&audio_caps));
|
||||||
|
|
||||||
let data_weak = Arc::downgrade(&data);
|
let data_weak = Arc::downgrade(&data);
|
||||||
appsink.connect_new_sample(move |_| {
|
appsink.set_callbacks(
|
||||||
|
gst_app::AppSinkCallbacks::builder()
|
||||||
|
.new_sample(move |_| {
|
||||||
let data = match data_weak.upgrade() {
|
let data = match data_weak.upgrade() {
|
||||||
Some(data) => data,
|
Some(data) => data,
|
||||||
None => return Ok(gst::FlowSuccess::Ok),
|
None => return Ok(gst::FlowSuccess::Ok),
|
||||||
|
@ -234,7 +238,9 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(gst::FlowSuccess::Ok)
|
Ok(gst::FlowSuccess::Ok)
|
||||||
});
|
})
|
||||||
|
.build(),
|
||||||
|
);
|
||||||
|
|
||||||
let main_loop = glib::MainLoop::new(None, false);
|
let main_loop = glib::MainLoop::new(None, false);
|
||||||
let main_loop_clone = main_loop.clone();
|
let main_loop_clone = main_loop.clone();
|
||||||
|
|
Loading…
Reference in a new issue