gstreamer: allow to register using Rank enum directly

Prevent user to have to cast to a u32 manually.
This commit is contained in:
Guillaume Desmottes 2019-06-04 10:52:58 +05:30 committed by Sebastian Dröge
parent 2c31baaa0c
commit 1cd733fb0b
6 changed files with 53 additions and 25 deletions

View file

@ -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"

View file

@ -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 {}

View file

@ -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 {}

View file

@ -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>;
}

View file

@ -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)]

View file

@ -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<F>(
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::<F>),
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| {