mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-29 04:51:09 +00:00
Finish appsrc bindings
This commit is contained in:
parent
7c600bfce3
commit
ffa474e1e9
4 changed files with 152 additions and 98 deletions
|
@ -37,6 +37,52 @@ name = "GstApp.AppSrc"
|
||||||
status = "generate"
|
status = "generate"
|
||||||
trait = false
|
trait = false
|
||||||
|
|
||||||
|
[[object.function]]
|
||||||
|
name = "push_buffer"
|
||||||
|
# Pass by value
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.signal]]
|
||||||
|
name = "end-of-stream"
|
||||||
|
# Action signal
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.signal]]
|
||||||
|
name = "push-buffer"
|
||||||
|
# Action signal
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.signal]]
|
||||||
|
name = "push-sample"
|
||||||
|
# Action signal
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.property]]
|
||||||
|
name = "current-level-bytes"
|
||||||
|
# Has getter function
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.property]]
|
||||||
|
name = "duration"
|
||||||
|
# Has getter function
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.property]]
|
||||||
|
name = "max-latency"
|
||||||
|
# Has getter function
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.property]]
|
||||||
|
name = "min-latency"
|
||||||
|
# Has getter function
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
[[object.property]]
|
||||||
|
name = "stream-type"
|
||||||
|
# Has getter function
|
||||||
|
ignore = true
|
||||||
|
|
||||||
|
|
||||||
[[object]]
|
[[object]]
|
||||||
name = "Gst.Caps"
|
name = "Gst.Caps"
|
||||||
status = "manual"
|
status = "manual"
|
||||||
|
|
105
gstreamer-app/src/app_src.rs
Normal file
105
gstreamer-app/src/app_src.rs
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
// 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 AppSrc;
|
||||||
|
use ffi;
|
||||||
|
use glib::translate::*;
|
||||||
|
use gst;
|
||||||
|
use std::mem::transmute;
|
||||||
|
use glib::source::CallbackGuard;
|
||||||
|
use glib_ffi::{gboolean, gpointer};
|
||||||
|
use std::ptr;
|
||||||
|
|
||||||
|
pub struct AppSrcCallbacks {
|
||||||
|
need_data: Box<Fn(&AppSrc, u32) + Send + Sync + 'static>,
|
||||||
|
enough_data: Box<Fn(&AppSrc) + Send + Sync + 'static>,
|
||||||
|
seek_data: Box<Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>,
|
||||||
|
callbacks: ffi::GstAppSrcCallbacks,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AppSrcCallbacks {
|
||||||
|
pub fn new<F, G, H>(need_data: F, enough_data: G, seek_data: H) -> Self
|
||||||
|
where
|
||||||
|
F: Fn(&AppSrc, u32) + Send + Sync + 'static,
|
||||||
|
G: Fn(&AppSrc) + Send + Sync + 'static,
|
||||||
|
H: Fn(&AppSrc, u64) -> bool + Send + Sync + 'static,
|
||||||
|
{
|
||||||
|
AppSrcCallbacks {
|
||||||
|
need_data: Box::new(need_data),
|
||||||
|
enough_data: Box::new(enough_data),
|
||||||
|
seek_data: Box::new(seek_data),
|
||||||
|
callbacks: ffi::GstAppSrcCallbacks {
|
||||||
|
need_data: Some(trampoline_need_data),
|
||||||
|
enough_data: Some(trampoline_enough_data),
|
||||||
|
seek_data: Some(trampoline_seek_data),
|
||||||
|
_gst_reserved: [
|
||||||
|
ptr::null_mut(),
|
||||||
|
ptr::null_mut(),
|
||||||
|
ptr::null_mut(),
|
||||||
|
ptr::null_mut(),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe extern "C" fn trampoline_need_data(
|
||||||
|
appsrc: *mut ffi::GstAppSrc,
|
||||||
|
length: u32,
|
||||||
|
callbacks: gpointer,
|
||||||
|
) {
|
||||||
|
let _guard = CallbackGuard::new();
|
||||||
|
let callbacks: &AppSrcCallbacks = transmute(callbacks);
|
||||||
|
|
||||||
|
(callbacks.need_data)(&from_glib_none(appsrc), length);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe extern "C" fn trampoline_enough_data(appsrc: *mut ffi::GstAppSrc, callbacks: gpointer) {
|
||||||
|
let _guard = CallbackGuard::new();
|
||||||
|
let callbacks: &AppSrcCallbacks = transmute(callbacks);
|
||||||
|
|
||||||
|
(callbacks.enough_data)(&from_glib_none(appsrc));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe extern "C" fn trampoline_seek_data(
|
||||||
|
appsrc: *mut ffi::GstAppSrc,
|
||||||
|
offset: u64,
|
||||||
|
callbacks: gpointer,
|
||||||
|
) -> gboolean {
|
||||||
|
let _guard = CallbackGuard::new();
|
||||||
|
let callbacks: &AppSrcCallbacks = transmute(callbacks);
|
||||||
|
|
||||||
|
(callbacks.seek_data)(&from_glib_none(appsrc), offset).to_glib()
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe extern "C" fn destroy_callbacks(ptr: gpointer) {
|
||||||
|
let _guard = CallbackGuard::new();
|
||||||
|
Box::<Box<AppSrcCallbacks>>::from_raw(ptr as *mut _);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AppSrc {
|
||||||
|
pub fn push_buffer(&self, buffer: gst::Buffer) -> gst::FlowReturn {
|
||||||
|
unsafe {
|
||||||
|
from_glib(ffi::gst_app_src_push_buffer(
|
||||||
|
self.to_glib_none().0,
|
||||||
|
buffer.into_ptr(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_callbacks(&self, callbacks: AppSrcCallbacks) {
|
||||||
|
unsafe {
|
||||||
|
ffi::gst_app_src_set_callbacks(
|
||||||
|
self.to_glib_none().0,
|
||||||
|
mut_override(&callbacks.callbacks),
|
||||||
|
Box::into_raw(Box::new(callbacks)) as *mut _,
|
||||||
|
Some(destroy_callbacks),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -86,12 +86,6 @@ impl AppSrc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_buffer(&self, buffer: &gst::Buffer) -> gst::FlowReturn {
|
|
||||||
unsafe {
|
|
||||||
from_glib(ffi::gst_app_src_push_buffer(self.to_glib_none().0, buffer.to_glib_full()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn push_sample(&self, sample: &gst::Sample) -> gst::FlowReturn {
|
pub fn push_sample(&self, sample: &gst::Sample) -> gst::FlowReturn {
|
||||||
unsafe {
|
unsafe {
|
||||||
from_glib(ffi::gst_app_src_push_sample(self.to_glib_none().0, sample.to_glib_none().0))
|
from_glib(ffi::gst_app_src_push_sample(self.to_glib_none().0, sample.to_glib_none().0))
|
||||||
|
@ -159,28 +153,6 @@ impl AppSrc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_property_current_level_bytes(&self) -> u64 {
|
|
||||||
let mut value = Value::from(&0u64);
|
|
||||||
unsafe {
|
|
||||||
gobject_ffi::g_object_get_property(self.to_glib_none().0, "current-level-bytes".to_glib_none().0, value.to_glib_none_mut().0);
|
|
||||||
}
|
|
||||||
value.get().unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_property_duration(&self) -> u64 {
|
|
||||||
let mut value = Value::from(&0u64);
|
|
||||||
unsafe {
|
|
||||||
gobject_ffi::g_object_get_property(self.to_glib_none().0, "duration".to_glib_none().0, value.to_glib_none_mut().0);
|
|
||||||
}
|
|
||||||
value.get().unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_property_duration(&self, duration: u64) {
|
|
||||||
unsafe {
|
|
||||||
gobject_ffi::g_object_set_property(self.to_glib_none().0, "duration".to_glib_none().0, Value::from(&duration).to_glib_none().0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_property_format(&self) -> gst::Format {
|
pub fn get_property_format(&self) -> gst::Format {
|
||||||
let mut value = Value::from(&0);
|
let mut value = Value::from(&0);
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -210,34 +182,6 @@ impl AppSrc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_property_max_latency(&self) -> i64 {
|
|
||||||
let mut value = Value::from(&0i64);
|
|
||||||
unsafe {
|
|
||||||
gobject_ffi::g_object_get_property(self.to_glib_none().0, "max-latency".to_glib_none().0, value.to_glib_none_mut().0);
|
|
||||||
}
|
|
||||||
value.get().unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_property_max_latency(&self, max_latency: i64) {
|
|
||||||
unsafe {
|
|
||||||
gobject_ffi::g_object_set_property(self.to_glib_none().0, "max-latency".to_glib_none().0, Value::from(&max_latency).to_glib_none().0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_property_min_latency(&self) -> i64 {
|
|
||||||
let mut value = Value::from(&0i64);
|
|
||||||
unsafe {
|
|
||||||
gobject_ffi::g_object_get_property(self.to_glib_none().0, "min-latency".to_glib_none().0, value.to_glib_none_mut().0);
|
|
||||||
}
|
|
||||||
value.get().unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_property_min_latency(&self, min_latency: i64) {
|
|
||||||
unsafe {
|
|
||||||
gobject_ffi::g_object_set_property(self.to_glib_none().0, "min-latency".to_glib_none().0, Value::from(&min_latency).to_glib_none().0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_property_min_percent(&self) -> u32 {
|
pub fn get_property_min_percent(&self) -> u32 {
|
||||||
let mut value = Value::from(&0u32);
|
let mut value = Value::from(&0u32);
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -252,14 +196,6 @@ impl AppSrc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn connect_end_of_stream<F: Fn(&AppSrc) -> gst::FlowReturn + Send + Sync + 'static>(&self, f: F) -> u64 {
|
|
||||||
unsafe {
|
|
||||||
let f: Box_<Box_<Fn(&AppSrc) -> gst::FlowReturn + Send + Sync + 'static>> = Box_::new(Box_::new(f));
|
|
||||||
connect(self.to_glib_none().0, "end-of-stream",
|
|
||||||
transmute(end_of_stream_trampoline as usize), Box_::into_raw(f) as *mut _)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn connect_enough_data<F: Fn(&AppSrc) + Send + Sync + 'static>(&self, f: F) -> u64 {
|
pub fn connect_enough_data<F: Fn(&AppSrc) + Send + Sync + 'static>(&self, f: F) -> u64 {
|
||||||
unsafe {
|
unsafe {
|
||||||
let f: Box_<Box_<Fn(&AppSrc) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
|
let f: Box_<Box_<Fn(&AppSrc) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
|
||||||
|
@ -276,22 +212,6 @@ impl AppSrc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn connect_push_buffer<F: Fn(&AppSrc, &gst::Buffer) -> gst::FlowReturn + Send + Sync + 'static>(&self, f: F) -> u64 {
|
|
||||||
unsafe {
|
|
||||||
let f: Box_<Box_<Fn(&AppSrc, &gst::Buffer) -> gst::FlowReturn + Send + Sync + 'static>> = Box_::new(Box_::new(f));
|
|
||||||
connect(self.to_glib_none().0, "push-buffer",
|
|
||||||
transmute(push_buffer_trampoline as usize), Box_::into_raw(f) as *mut _)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn connect_push_sample<F: Fn(&AppSrc, &gst::Sample) -> gst::FlowReturn + Send + Sync + 'static>(&self, f: F) -> u64 {
|
|
||||||
unsafe {
|
|
||||||
let f: Box_<Box_<Fn(&AppSrc, &gst::Sample) -> gst::FlowReturn + Send + Sync + 'static>> = Box_::new(Box_::new(f));
|
|
||||||
connect(self.to_glib_none().0, "push-sample",
|
|
||||||
transmute(push_sample_trampoline as usize), Box_::into_raw(f) as *mut _)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn connect_seek_data<F: Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>(&self, f: F) -> u64 {
|
pub fn connect_seek_data<F: Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>(&self, f: F) -> u64 {
|
||||||
unsafe {
|
unsafe {
|
||||||
let f: Box_<Box_<Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>> = Box_::new(Box_::new(f));
|
let f: Box_<Box_<Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>> = Box_::new(Box_::new(f));
|
||||||
|
@ -304,12 +224,6 @@ impl AppSrc {
|
||||||
unsafe impl Send for AppSrc {}
|
unsafe impl Send for AppSrc {}
|
||||||
unsafe impl Sync for AppSrc {}
|
unsafe impl Sync for AppSrc {}
|
||||||
|
|
||||||
unsafe extern "C" fn end_of_stream_trampoline(this: *mut ffi::GstAppSrc, f: glib_ffi::gpointer) -> gst_ffi::GstFlowReturn {
|
|
||||||
callback_guard!();
|
|
||||||
let f: &Box_<Fn(&AppSrc) -> gst::FlowReturn + Send + Sync + 'static> = transmute(f);
|
|
||||||
f(&from_glib_none(this)).to_glib()
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" fn enough_data_trampoline(this: *mut ffi::GstAppSrc, f: glib_ffi::gpointer) {
|
unsafe extern "C" fn enough_data_trampoline(this: *mut ffi::GstAppSrc, f: glib_ffi::gpointer) {
|
||||||
callback_guard!();
|
callback_guard!();
|
||||||
let f: &Box_<Fn(&AppSrc) + Send + Sync + 'static> = transmute(f);
|
let f: &Box_<Fn(&AppSrc) + Send + Sync + 'static> = transmute(f);
|
||||||
|
@ -322,18 +236,6 @@ unsafe extern "C" fn need_data_trampoline(this: *mut ffi::GstAppSrc, length: lib
|
||||||
f(&from_glib_none(this), length)
|
f(&from_glib_none(this), length)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn push_buffer_trampoline(this: *mut ffi::GstAppSrc, buffer: *mut gst_ffi::GstBuffer, f: glib_ffi::gpointer) -> gst_ffi::GstFlowReturn {
|
|
||||||
callback_guard!();
|
|
||||||
let f: &Box_<Fn(&AppSrc, &gst::Buffer) -> gst::FlowReturn + Send + Sync + 'static> = transmute(f);
|
|
||||||
f(&from_glib_none(this), &from_glib_none(buffer)).to_glib()
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" fn push_sample_trampoline(this: *mut ffi::GstAppSrc, sample: *mut gst_ffi::GstSample, f: glib_ffi::gpointer) -> gst_ffi::GstFlowReturn {
|
|
||||||
callback_guard!();
|
|
||||||
let f: &Box_<Fn(&AppSrc, &gst::Sample) -> gst::FlowReturn + Send + Sync + 'static> = transmute(f);
|
|
||||||
f(&from_glib_none(this), &from_glib_none(sample)).to_glib()
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" fn seek_data_trampoline(this: *mut ffi::GstAppSrc, offset: u64, f: glib_ffi::gpointer) -> glib_ffi::gboolean {
|
unsafe extern "C" fn seek_data_trampoline(this: *mut ffi::GstAppSrc, offset: u64, f: glib_ffi::gpointer) -> glib_ffi::gboolean {
|
||||||
callback_guard!();
|
callback_guard!();
|
||||||
let f: &Box_<Fn(&AppSrc, u64) -> bool + Send + Sync + 'static> = transmute(f);
|
let f: &Box_<Fn(&AppSrc, u64) -> bool + Send + Sync + 'static> = transmute(f);
|
||||||
|
|
|
@ -34,3 +34,4 @@ mod auto;
|
||||||
pub use auto::*;
|
pub use auto::*;
|
||||||
pub use auto::traits::*;
|
pub use auto::traits::*;
|
||||||
|
|
||||||
|
mod app_src;
|
||||||
|
|
Loading…
Reference in a new issue