mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-21 17:11:04 +00:00
Finish appsink bindings
This commit is contained in:
parent
ffa474e1e9
commit
7ff8a5c460
4 changed files with 106 additions and 24 deletions
|
@ -32,6 +32,16 @@ name = "GstApp.AppSink"
|
|||
status = "generate"
|
||||
trait = false
|
||||
|
||||
[[object.property]]
|
||||
name = "buffer-list"
|
||||
# Has getter function
|
||||
ignore = true
|
||||
|
||||
[[object.property]]
|
||||
name = "eos"
|
||||
# Has getter function
|
||||
ignore = true
|
||||
|
||||
[[object]]
|
||||
name = "GstApp.AppSrc"
|
||||
status = "generate"
|
||||
|
@ -82,7 +92,6 @@ trait = false
|
|||
# Has getter function
|
||||
ignore = true
|
||||
|
||||
|
||||
[[object]]
|
||||
name = "Gst.Caps"
|
||||
status = "manual"
|
||||
|
|
95
gstreamer-app/src/app_sink.rs
Normal file
95
gstreamer-app/src/app_sink.rs
Normal file
|
@ -0,0 +1,95 @@
|
|||
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use AppSink;
|
||||
use ffi;
|
||||
use gst_ffi;
|
||||
use glib::translate::*;
|
||||
use gst;
|
||||
use std::mem::transmute;
|
||||
use glib::source::CallbackGuard;
|
||||
use glib_ffi::gpointer;
|
||||
use std::ptr;
|
||||
|
||||
pub struct AppSinkCallbacks {
|
||||
eos: Box<Fn(&AppSink) + Send + Sync + 'static>,
|
||||
new_preroll: Box<Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>,
|
||||
new_sample: Box<Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>,
|
||||
callbacks: ffi::GstAppSinkCallbacks,
|
||||
}
|
||||
|
||||
impl AppSinkCallbacks {
|
||||
pub fn new<F, G, H>(eos: F, new_preroll: G, new_sample: H) -> Self
|
||||
where
|
||||
F: Fn(&AppSink) + Send + Sync + 'static,
|
||||
G: Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static,
|
||||
H: Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static,
|
||||
{
|
||||
AppSinkCallbacks {
|
||||
eos: Box::new(eos),
|
||||
new_preroll: Box::new(new_preroll),
|
||||
new_sample: Box::new(new_sample),
|
||||
callbacks: ffi::GstAppSinkCallbacks {
|
||||
eos: Some(trampoline_eos),
|
||||
new_preroll: Some(trampoline_new_preroll),
|
||||
new_sample: Some(trampoline_new_sample),
|
||||
_gst_reserved: [
|
||||
ptr::null_mut(),
|
||||
ptr::null_mut(),
|
||||
ptr::null_mut(),
|
||||
ptr::null_mut(),
|
||||
],
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn trampoline_eos(appsink: *mut ffi::GstAppSink, callbacks: gpointer) {
|
||||
let _guard = CallbackGuard::new();
|
||||
let callbacks: &AppSinkCallbacks = transmute(callbacks);
|
||||
|
||||
(callbacks.eos)(&from_glib_none(appsink));
|
||||
}
|
||||
|
||||
unsafe extern "C" fn trampoline_new_preroll(
|
||||
appsink: *mut ffi::GstAppSink,
|
||||
callbacks: gpointer,
|
||||
) -> gst_ffi::GstFlowReturn {
|
||||
let _guard = CallbackGuard::new();
|
||||
let callbacks: &AppSinkCallbacks = transmute(callbacks);
|
||||
|
||||
(callbacks.new_preroll)(&from_glib_none(appsink)).to_glib()
|
||||
}
|
||||
|
||||
unsafe extern "C" fn trampoline_new_sample(
|
||||
appsink: *mut ffi::GstAppSink,
|
||||
callbacks: gpointer,
|
||||
) -> gst_ffi::GstFlowReturn {
|
||||
let _guard = CallbackGuard::new();
|
||||
let callbacks: &AppSinkCallbacks = transmute(callbacks);
|
||||
|
||||
(callbacks.new_sample)(&from_glib_none(appsink)).to_glib()
|
||||
}
|
||||
|
||||
unsafe extern "C" fn destroy_callbacks(ptr: gpointer) {
|
||||
let _guard = CallbackGuard::new();
|
||||
Box::<Box<AppSinkCallbacks>>::from_raw(ptr as *mut _);
|
||||
}
|
||||
|
||||
impl AppSink {
|
||||
pub fn set_callbacks(&self, callbacks: AppSinkCallbacks) {
|
||||
unsafe {
|
||||
ffi::gst_app_sink_set_callbacks(
|
||||
self.to_glib_none().0,
|
||||
mut_override(&callbacks.callbacks),
|
||||
Box::into_raw(Box::new(callbacks)) as *mut _,
|
||||
Some(destroy_callbacks),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
// DO NOT EDIT
|
||||
|
||||
use ffi;
|
||||
use glib::Value;
|
||||
use glib::signal::connect;
|
||||
use glib::translate::*;
|
||||
use glib_ffi;
|
||||
|
@ -136,28 +135,6 @@ impl AppSink {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_property_buffer_list(&self) -> bool {
|
||||
let mut value = Value::from(&false);
|
||||
unsafe {
|
||||
gobject_ffi::g_object_get_property(self.to_glib_none().0, "buffer-list".to_glib_none().0, value.to_glib_none_mut().0);
|
||||
}
|
||||
value.get().unwrap()
|
||||
}
|
||||
|
||||
pub fn set_property_buffer_list(&self, buffer_list: bool) {
|
||||
unsafe {
|
||||
gobject_ffi::g_object_set_property(self.to_glib_none().0, "buffer-list".to_glib_none().0, Value::from(&buffer_list).to_glib_none().0);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_property_eos(&self) -> bool {
|
||||
let mut value = Value::from(&false);
|
||||
unsafe {
|
||||
gobject_ffi::g_object_get_property(self.to_glib_none().0, "eos".to_glib_none().0, value.to_glib_none_mut().0);
|
||||
}
|
||||
value.get().unwrap()
|
||||
}
|
||||
|
||||
pub fn connect_eos<F: Fn(&AppSink) + Send + Sync + 'static>(&self, f: F) -> u64 {
|
||||
unsafe {
|
||||
let f: Box_<Box_<Fn(&AppSink) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
|
||||
|
|
|
@ -35,3 +35,4 @@ pub use auto::*;
|
|||
pub use auto::traits::*;
|
||||
|
||||
mod app_src;
|
||||
mod app_sink;
|
||||
|
|
Loading…
Reference in a new issue