From 9d35eff8d54bfe9bd01027657144caf0b3e5a2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 29 Jul 2017 15:10:10 +0100 Subject: [PATCH] Add ChildProxy bindings --- Gir_Gst.toml | 2 + gstreamer/src/auto/bin.rs | 3 +- gstreamer/src/auto/child_proxy.rs | 147 ++++++++++++++++++++++++++++++ gstreamer/src/auto/functions.rs | 20 ++-- gstreamer/src/auto/mod.rs | 5 + gstreamer/src/auto/object.rs | 2 +- gstreamer/src/auto/pipeline.rs | 3 +- gstreamer/src/child_proxy.rs | 47 ++++++++++ gstreamer/src/lib.rs | 2 + 9 files changed, 220 insertions(+), 11 deletions(-) create mode 100644 gstreamer/src/auto/child_proxy.rs create mode 100644 gstreamer/src/child_proxy.rs diff --git a/Gir_Gst.toml b/Gir_Gst.toml index 9d0d3ab5c..c5b03f453 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -55,11 +55,13 @@ generate = [ "Gst.PadMode", "Gst.SchedulingFlags", "Gst.IteratorResult", + "Gst.ChildProxy", ] manual = [ "GLib.Error", "GLib.Source", + "GObject.Object", "Gst.Structure", "Gst.Iterator", ] diff --git a/gstreamer/src/auto/bin.rs b/gstreamer/src/auto/bin.rs index 1bac1fa96..ba39b703c 100644 --- a/gstreamer/src/auto/bin.rs +++ b/gstreamer/src/auto/bin.rs @@ -1,6 +1,7 @@ // This file was generated by gir (a01311c+) from gir-files (???) // DO NOT EDIT +use ChildProxy; use Element; use Iterator; use Object; @@ -21,7 +22,7 @@ use std::mem::transmute; use std::ptr; glib_wrapper! { - pub struct Bin(Object): Element, Object; + pub struct Bin(Object): Element, Object, ChildProxy; match fn { get_type => || ffi::gst_bin_get_type(), diff --git a/gstreamer/src/auto/child_proxy.rs b/gstreamer/src/auto/child_proxy.rs new file mode 100644 index 000000000..4f7917f03 --- /dev/null +++ b/gstreamer/src/auto/child_proxy.rs @@ -0,0 +1,147 @@ +// This file was generated by gir (a01311c+) from gir-files (???) +// DO NOT EDIT + +use ffi; +use glib; +use glib::object::Downcast; +use glib::object::IsA; +use glib::signal::connect; +use glib::translate::*; +use glib_ffi; +use gobject_ffi; +use libc; +use std::boxed::Box as Box_; +use std::mem; +use std::mem::transmute; +use std::ptr; + +glib_wrapper! { + pub struct ChildProxy(Object); + + match fn { + get_type => || ffi::gst_child_proxy_get_type(), + } +} + +unsafe impl Send for ChildProxy {} +unsafe impl Sync for ChildProxy {} + +pub trait ChildProxyExt { + fn child_added>(&self, child: &P, name: &str); + + fn child_removed>(&self, child: &P, name: &str); + + //fn get(&self, first_property_name: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs); + + fn get_child_by_index(&self, index: u32) -> Option; + + fn get_child_by_name(&self, name: &str) -> Option; + + fn get_children_count(&self) -> u32; + + //fn get_property(&self, name: &str, value: /*Ignored*/glib::Value); + + //fn get_valist(&self, first_property_name: &str, var_args: /*Unknown conversion*//*Unimplemented*/Unsupported); + + //fn lookup(&self, name: &str, pspec: /*Ignored*/glib::ParamSpec) -> Option; + + //fn set(&self, first_property_name: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs); + + //fn set_property(&self, name: &str, value: /*Ignored*/&glib::Value); + + //fn set_valist(&self, first_property_name: &str, var_args: /*Unknown conversion*//*Unimplemented*/Unsupported); + + fn connect_child_added(&self, f: F) -> u64; + + fn connect_child_removed(&self, f: F) -> u64; +} + +impl + IsA> ChildProxyExt for O { + fn child_added>(&self, child: &P, name: &str) { + unsafe { + ffi::gst_child_proxy_child_added(self.to_glib_none().0, child.to_glib_none().0, name.to_glib_none().0); + } + } + + fn child_removed>(&self, child: &P, name: &str) { + unsafe { + ffi::gst_child_proxy_child_removed(self.to_glib_none().0, child.to_glib_none().0, name.to_glib_none().0); + } + } + + //fn get(&self, first_property_name: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) { + // unsafe { TODO: call ffi::gst_child_proxy_get() } + //} + + fn get_child_by_index(&self, index: u32) -> Option { + unsafe { + from_glib_full(ffi::gst_child_proxy_get_child_by_index(self.to_glib_none().0, index)) + } + } + + fn get_child_by_name(&self, name: &str) -> Option { + unsafe { + from_glib_full(ffi::gst_child_proxy_get_child_by_name(self.to_glib_none().0, name.to_glib_none().0)) + } + } + + fn get_children_count(&self) -> u32 { + unsafe { + ffi::gst_child_proxy_get_children_count(self.to_glib_none().0) + } + } + + //fn get_property(&self, name: &str, value: /*Ignored*/glib::Value) { + // unsafe { TODO: call ffi::gst_child_proxy_get_property() } + //} + + //fn get_valist(&self, first_property_name: &str, var_args: /*Unknown conversion*//*Unimplemented*/Unsupported) { + // unsafe { TODO: call ffi::gst_child_proxy_get_valist() } + //} + + //fn lookup(&self, name: &str, pspec: /*Ignored*/glib::ParamSpec) -> Option { + // unsafe { TODO: call ffi::gst_child_proxy_lookup() } + //} + + //fn set(&self, first_property_name: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) { + // unsafe { TODO: call ffi::gst_child_proxy_set() } + //} + + //fn set_property(&self, name: &str, value: /*Ignored*/&glib::Value) { + // unsafe { TODO: call ffi::gst_child_proxy_set_property() } + //} + + //fn set_valist(&self, first_property_name: &str, var_args: /*Unknown conversion*//*Unimplemented*/Unsupported) { + // unsafe { TODO: call ffi::gst_child_proxy_set_valist() } + //} + + fn connect_child_added(&self, f: F) -> u64 { + unsafe { + let f: Box_> = Box_::new(Box_::new(f)); + connect(self.to_glib_none().0, "child-added", + transmute(child_added_trampoline:: as usize), Box_::into_raw(f) as *mut _) + } + } + + fn connect_child_removed(&self, f: F) -> u64 { + unsafe { + let f: Box_> = Box_::new(Box_::new(f)); + connect(self.to_glib_none().0, "child-removed", + transmute(child_removed_trampoline:: as usize), Box_::into_raw(f) as *mut _) + } + } +} + +unsafe extern "C" fn child_added_trampoline

(this: *mut ffi::GstChildProxy, object: *mut gobject_ffi::GObject, name: *mut libc::c_char, f: glib_ffi::gpointer) +where P: IsA { + callback_guard!(); + let f: &Box_ = transmute(f); + f(&ChildProxy::from_glib_none(this).downcast_unchecked(), &from_glib_none(object), &String::from_glib_none(name)) +} + +unsafe extern "C" fn child_removed_trampoline

(this: *mut ffi::GstChildProxy, object: *mut gobject_ffi::GObject, name: *mut libc::c_char, f: glib_ffi::gpointer) +where P: IsA { + callback_guard!(); + let f: &Box_ = transmute(f); + f(&ChildProxy::from_glib_none(this).downcast_unchecked(), &from_glib_none(object), &String::from_glib_none(name)) +} diff --git a/gstreamer/src/auto/functions.rs b/gstreamer/src/auto/functions.rs index 0b26a9344..cb6a933d8 100644 --- a/gstreamer/src/auto/functions.rs +++ b/gstreamer/src/auto/functions.rs @@ -9,6 +9,7 @@ use FlowReturn; use Plugin; use ffi; use glib; +use glib::object::IsA; use glib::translate::*; use std::mem; use std::ptr; @@ -89,15 +90,15 @@ pub fn debug_is_colored() -> bool { } } -//pub fn debug_log<'a, P: IsA + 'a, Q: Into>>(category: /*Ignored*/&mut DebugCategory, level: /*Ignored*/DebugLevel, file: &str, function: &str, line: i32, object: Q, format: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) { +//pub fn debug_log<'a, P: IsA + 'a, Q: Into>>(category: /*Ignored*/&mut DebugCategory, level: /*Ignored*/DebugLevel, file: &str, function: &str, line: i32, object: Q, format: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) { // unsafe { TODO: call ffi::gst_debug_log() } //} -//pub fn debug_log_default<'a, P: IsA + 'a, Q: Into>, R: Into>>(category: /*Ignored*/&mut DebugCategory, level: /*Ignored*/DebugLevel, file: &str, function: &str, line: i32, object: Q, message: /*Ignored*/&mut DebugMessage, user_data: R) { +//pub fn debug_log_default<'a, P: IsA + 'a, Q: Into>, R: Into>>(category: /*Ignored*/&mut DebugCategory, level: /*Ignored*/DebugLevel, file: &str, function: &str, line: i32, object: Q, message: /*Ignored*/&mut DebugMessage, user_data: R) { // unsafe { TODO: call ffi::gst_debug_log_default() } //} -//pub fn debug_log_valist<'a, P: IsA + 'a, Q: Into>>(category: /*Ignored*/&mut DebugCategory, level: /*Ignored*/DebugLevel, file: &str, function: &str, line: i32, object: Q, format: &str, args: /*Unknown conversion*//*Unimplemented*/Unsupported) { +//pub fn debug_log_valist<'a, P: IsA + 'a, Q: Into>>(category: /*Ignored*/&mut DebugCategory, level: /*Ignored*/DebugLevel, file: &str, function: &str, line: i32, object: Q, format: &str, args: /*Unknown conversion*//*Unimplemented*/Unsupported) { // unsafe { TODO: call ffi::gst_debug_log_valist() } //} @@ -480,7 +481,7 @@ pub fn util_gdouble_to_guint64(value: f64) -> u64 { } //#[cfg(feature = "v1_12")] -//pub fn util_get_object_array>(object: &P, name: &str, array: /*Ignored*/glib::ValueArray) -> bool { +//pub fn util_get_object_array>(object: &P, name: &str, array: /*Ignored*/glib::ValueArray) -> bool { // unsafe { TODO: call ffi::gst_util_get_object_array() } //} @@ -533,12 +534,15 @@ pub fn util_seqnum_next() -> u32 { } } -//pub fn util_set_object_arg>(object: &P, name: &str, value: &str) { -// unsafe { TODO: call ffi::gst_util_set_object_arg() } -//} +pub fn util_set_object_arg>(object: &P, name: &str, value: &str) { + assert_initialized_main_thread!(); + unsafe { + ffi::gst_util_set_object_arg(object.to_glib_none().0, name.to_glib_none().0, value.to_glib_none().0); + } +} //#[cfg(feature = "v1_12")] -//pub fn util_set_object_array>(object: &P, name: &str, array: /*Ignored*/&glib::ValueArray) -> bool { +//pub fn util_set_object_array>(object: &P, name: &str, array: /*Ignored*/&glib::ValueArray) -> bool { // unsafe { TODO: call ffi::gst_util_set_object_array() } //} diff --git a/gstreamer/src/auto/mod.rs b/gstreamer/src/auto/mod.rs index eb31a67e3..f7c174193 100644 --- a/gstreamer/src/auto/mod.rs +++ b/gstreamer/src/auto/mod.rs @@ -8,6 +8,10 @@ pub use self::bin::BinExt; mod bus; pub use self::bus::Bus; +mod child_proxy; +pub use self::child_proxy::ChildProxy; +pub use self::child_proxy::ChildProxyExt; + mod clock; pub use self::clock::Clock; pub use self::clock::ClockExt; @@ -196,6 +200,7 @@ pub mod functions; #[doc(hidden)] pub mod traits { pub use super::BinExt; + pub use super::ChildProxyExt; pub use super::ClockExt; pub use super::DeviceExt; pub use super::DeviceMonitorExt; diff --git a/gstreamer/src/auto/object.rs b/gstreamer/src/auto/object.rs index 4223940dd..97da89e18 100644 --- a/gstreamer/src/auto/object.rs +++ b/gstreamer/src/auto/object.rs @@ -28,7 +28,7 @@ impl Object { } } - //pub fn default_deep_notify, Q: IsA, R: IsA>(object: &P, orig: &Q, pspec: &R, excluded_props: &[&str]) { + //pub fn default_deep_notify, Q: IsA, R: IsA>(object: &P, orig: &Q, pspec: &R, excluded_props: &[&str]) { // unsafe { TODO: call ffi::gst_object_default_deep_notify() } //} diff --git a/gstreamer/src/auto/pipeline.rs b/gstreamer/src/auto/pipeline.rs index a9722101c..405b1e634 100644 --- a/gstreamer/src/auto/pipeline.rs +++ b/gstreamer/src/auto/pipeline.rs @@ -2,6 +2,7 @@ // DO NOT EDIT use Bin; +use ChildProxy; use Clock; use ClockTime; use Element; @@ -16,7 +17,7 @@ use std::mem; use std::ptr; glib_wrapper! { - pub struct Pipeline(Object): Bin, Element, Object; + pub struct Pipeline(Object): Bin, Element, Object, ChildProxy; match fn { get_type => || ffi::gst_pipeline_get_type(), diff --git a/gstreamer/src/child_proxy.rs b/gstreamer/src/child_proxy.rs new file mode 100644 index 000000000..129849ddd --- /dev/null +++ b/gstreamer/src/child_proxy.rs @@ -0,0 +1,47 @@ +// Copyright (C) 2017 Sebastian Dröge +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use ffi; +use glib; +use glib::object::IsA; +use glib::translate::*; +use std::ptr; +use ChildProxy; + +pub trait ChildProxyExtManual { + fn get_property(&self, name: &str) -> Option; + fn set_property(&self, name: &str, value: &glib::Value) -> Result<(), glib::BoolError>; +} + +impl> ChildProxyExtManual for O { + fn get_property(&self, name: &str) -> Option { + unsafe { + let found: bool = from_glib(ffi::gst_child_proxy_lookup(self.to_glib_none().0, name.to_glib_none().0, ptr::null_mut(), ptr::null_mut())); + if !found { + return None; + } + + let mut value = glib::Value::uninitialized(); + ffi::gst_child_proxy_get_property(self.to_glib_none().0, name.to_glib_none().0, value.to_glib_none_mut().0); + Some(value) + } + } + + fn set_property(&self, name: &str, value: &glib::Value) -> Result<(), glib::BoolError> { + unsafe { + let found: bool = from_glib(ffi::gst_child_proxy_lookup(self.to_glib_none().0, name.to_glib_none().0, ptr::null_mut(), ptr::null_mut())); + if !found { + return Err(glib::BoolError("Child property not found")); + } + + ffi::gst_child_proxy_set_property(self.to_glib_none().0, name.to_glib_none().0, value.to_glib_none().0); + + Ok(()) + } + } +} diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 348141a24..c87366661 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -73,10 +73,12 @@ mod gobject; mod segment; mod proxy_pad; mod ghost_pad; +mod child_proxy; pub use element::ElementExtManual; pub use bin::BinExtManual; pub use pad::{PadExtManual, PadProbeId, PadProbeInfo, PadProbeData, PAD_PROBE_ID_INVALID}; pub use gobject::GObjectExtManualGst; +pub use child_proxy::ChildProxyExtManual; mod iterator; pub use self::iterator::Iterator;