From e4acf61af374782a4a483db3c91d3959bda891a1 Mon Sep 17 00:00:00 2001 From: Thijs Vermeir Date: Sat, 3 Nov 2018 23:54:09 +0100 Subject: [PATCH] create plugin_register_static in plugin_define! --- gst-plugin/src/plugin.rs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/gst-plugin/src/plugin.rs b/gst-plugin/src/plugin.rs index e8719ecf..8ed213b1 100644 --- a/gst-plugin/src/plugin.rs +++ b/gst-plugin/src/plugin.rs @@ -12,7 +12,10 @@ macro_rules! plugin_define( $version:expr, $license:expr, $source:expr, $package:expr, $origin:expr, $release_datetime:expr) => { pub mod plugin_desc { - use $crate::glib::translate::{from_glib_borrow, ToGlib}; + use $crate::glib::translate::{from_glib_borrow, ToGlib, from_glib}; + + const MAJOR_VERSION: i32 = 1; + const MINOR_VERSION: i32 = 8; // Not using c_char here because it requires the libc crate #[allow(non_camel_case_types)] @@ -25,8 +28,8 @@ macro_rules! plugin_define( #[no_mangle] #[allow(non_upper_case_globals)] pub static gst_plugin_desc: GstPluginDesc = GstPluginDesc($crate::gst_ffi::GstPluginDesc { - major_version: 1, - minor_version: 8, + major_version: MAJOR_VERSION, + minor_version: MINOR_VERSION, name: $name as *const u8 as *const c_char, description: $description as *const u8 as *const c_char, plugin_init: Some(plugin_init_trampoline), @@ -39,6 +42,23 @@ macro_rules! plugin_define( _gst_reserved: [0 as $crate::glib_ffi::gpointer; 4], }); + pub fn plugin_register_static() -> bool { + unsafe { + from_glib($crate::gst_ffi::gst_plugin_register_static( + MAJOR_VERSION, + MINOR_VERSION, + $name as *const u8 as *const c_char, + $description as *const u8 as *const c_char, + Some(plugin_init_trampoline), + $version as *const u8 as *const c_char, + $license as *const u8 as *const c_char, + $source as *const u8 as *const c_char, + $package as *const u8 as *const c_char, + $origin as *const u8 as *const c_char, + )) + } + } + unsafe extern "C" fn plugin_init_trampoline(plugin: *mut $crate::gst_ffi::GstPlugin) -> $crate::glib_ffi::gboolean { use std::panic::{self, AssertUnwindSafe}; @@ -51,7 +71,7 @@ macro_rules! plugin_define( gst_error!(cat, "Failed to register plugin: {}", err); $crate::glib_ffi::GFALSE } - } + } Err(err) => { let cat = $crate::gst::DebugCategory::get("GST_PLUGIN_LOADING").unwrap(); if let Some(cause) = err.downcast_ref::<&str>() { @@ -67,5 +87,6 @@ macro_rules! plugin_define( } } } + pub use plugin_desc::plugin_register_static; }; );