From 1cd733fb0bfe983aa66f10cb976721f67f73b297 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Tue, 4 Jun 2019 10:52:58 +0530 Subject: [PATCH] gstreamer: allow to register using Rank enum directly Prevent user to have to cast to a u32 manually. --- Gir_Gst.toml | 6 ++---- gstreamer/src/auto/device_provider.rs | 10 ---------- gstreamer/src/auto/element.rs | 8 -------- gstreamer/src/device_provider.rs | 25 +++++++++++++++++++++++++ gstreamer/src/element.rs | 22 ++++++++++++++++++++++ gstreamer/src/typefind.rs | 7 ++++--- 6 files changed, 53 insertions(+), 25 deletions(-) diff --git a/Gir_Gst.toml b/Gir_Gst.toml index 9e809744e..ef6033455 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -535,8 +535,7 @@ status = "generate" [[object.function]] name = "register" - [object.function.return] - bool_return_is_error = "Failed to register element factory" + ignore = true [[object]] name = "Gst.ElementFactory" @@ -568,8 +567,7 @@ status = "generate" [[object.function]] name = "register" - [object.function.return] - bool_return_is_error = "Failed to register device provider factory" + ignore = true [[object.function]] name = "get_metadata" diff --git a/gstreamer/src/auto/device_provider.rs b/gstreamer/src/auto/device_provider.rs index 3c91a9eea..fe604c7c8 100644 --- a/gstreamer/src/auto/device_provider.rs +++ b/gstreamer/src/auto/device_provider.rs @@ -6,7 +6,6 @@ use Bus; use Device; use DeviceProviderFactory; use Object; -use Plugin; use glib; use glib::GString; use glib::object::Cast; @@ -28,15 +27,6 @@ glib_wrapper! { } } -impl DeviceProvider { - pub fn register(plugin: Option<&Plugin>, name: &str, rank: u32, type_: glib::types::Type) -> Result<(), glib::error::BoolError> { - assert_initialized_main_thread!(); - unsafe { - glib_result_from_gboolean!(gst_sys::gst_device_provider_register(plugin.to_glib_none().0, name.to_glib_none().0, rank, type_.to_glib()), "Failed to register device provider factory") - } - } -} - unsafe impl Send for DeviceProvider {} unsafe impl Sync for DeviceProvider {} diff --git a/gstreamer/src/auto/element.rs b/gstreamer/src/auto/element.rs index 104e6e101..53ed21549 100644 --- a/gstreamer/src/auto/element.rs +++ b/gstreamer/src/auto/element.rs @@ -14,7 +14,6 @@ use Object; use Pad; use PadLinkCheck; use PadTemplate; -use Plugin; use URIType; use glib; use glib::object::Cast; @@ -45,13 +44,6 @@ impl Element { if error.is_null() { Ok(from_glib_none(ret)) } else { Err(from_glib_full(error)) } } } - - pub fn register(plugin: Option<&Plugin>, name: &str, rank: u32, type_: glib::types::Type) -> Result<(), glib::error::BoolError> { - assert_initialized_main_thread!(); - unsafe { - glib_result_from_gboolean!(gst_sys::gst_element_register(plugin.to_glib_none().0, name.to_glib_none().0, rank, type_.to_glib()), "Failed to register element factory") - } - } } unsafe impl Send for Element {} diff --git a/gstreamer/src/device_provider.rs b/gstreamer/src/device_provider.rs index 48f0fa82e..6a67259f5 100644 --- a/gstreamer/src/device_provider.rs +++ b/gstreamer/src/device_provider.rs @@ -7,8 +7,11 @@ // except according to those terms. use DeviceProvider; +use Plugin; +use Rank; use glib::object::IsA; +use glib::translate::ToGlib; use glib::translate::ToGlibPtr; use std::ffi::CStr; @@ -16,6 +19,28 @@ use std::ffi::CStr; use gobject_sys; use gst_sys; +impl DeviceProvider { + pub fn register( + plugin: Option<&Plugin>, + name: &str, + rank: Rank, + type_: glib::types::Type, + ) -> Result<(), glib::error::BoolError> { + assert_initialized_main_thread!(); + unsafe { + glib_result_from_gboolean!( + gst_sys::gst_device_provider_register( + plugin.to_glib_none().0, + name.to_glib_none().0, + rank.to_glib() as u32, + type_.to_glib() + ), + "Failed to register device provider factory" + ) + } + } +} + pub trait DeviceProviderExtManual: 'static { fn get_metadata<'a>(&self, key: &str) -> Option<&'a str>; } diff --git a/gstreamer/src/element.rs b/gstreamer/src/element.rs index 8f1e98b73..f42b57c47 100644 --- a/gstreamer/src/element.rs +++ b/gstreamer/src/element.rs @@ -27,7 +27,9 @@ use FormattedValue; use GenericFormattedValue; use Pad; use PadTemplate; +use Plugin; use QueryRef; +use Rank; use SpecificFormattedValue; use State; use StateChange; @@ -74,6 +76,26 @@ impl Element { } } } + + pub fn register( + plugin: Option<&Plugin>, + name: &str, + rank: Rank, + type_: glib::types::Type, + ) -> Result<(), glib::error::BoolError> { + assert_initialized_main_thread!(); + unsafe { + glib_result_from_gboolean!( + gst_sys::gst_element_register( + plugin.to_glib_none().0, + name.to_glib_none().0, + rank.to_glib() as u32, + type_.to_glib() + ), + "Failed to register element factory" + ) + } + } } #[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] diff --git a/gstreamer/src/typefind.rs b/gstreamer/src/typefind.rs index 6706eb5f4..5829fca31 100644 --- a/gstreamer/src/typefind.rs +++ b/gstreamer/src/typefind.rs @@ -9,6 +9,7 @@ use gst_sys; use Caps; use Plugin; +use Rank; use TypeFindFactory; use TypeFindProbability; @@ -35,7 +36,7 @@ impl<'a> TypeFind<'a> { pub fn register( plugin: Option<&Plugin>, name: &str, - rank: u32, + rank: Rank, extensions: Option<&str>, possible_caps: Option<&Caps>, func: F, @@ -50,7 +51,7 @@ impl<'a> TypeFind<'a> { let res = gst_sys::gst_type_find_register( plugin.to_glib_none().0, name.to_glib_none().0, - rank, + rank.to_glib() as u32, Some(type_find_trampoline::), extensions.to_glib_none().0, possible_caps.to_glib_none().0, @@ -265,7 +266,7 @@ mod tests { TypeFind::register( None, "test_typefind", - ::Rank::Primary.to_glib() as u32, + ::Rank::Primary, None, Some(&Caps::new_simple("test/test", &[])), |typefind| {