2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2018-11-18 12:20:16 +00:00
|
|
|
|
2018-11-19 23:47:58 +00:00
|
|
|
pub const MAJOR_VERSION: i32 = 1;
|
|
|
|
|
|
|
|
#[cfg(not(feature = "v1_10"))]
|
|
|
|
pub const MINOR_VERSION: i32 = 8;
|
|
|
|
#[cfg(all(feature = "v1_10", not(feature = "v1_12")))]
|
|
|
|
pub const MINOR_VERSION: i32 = 10;
|
2019-05-26 23:36:30 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2018-11-19 23:47:58 +00:00
|
|
|
pub const MINOR_VERSION: i32 = 12;
|
|
|
|
|
2018-11-18 12:20:16 +00:00
|
|
|
#[macro_export]
|
2020-12-20 15:09:22 +00:00
|
|
|
macro_rules! plugin_define(
|
2019-05-26 23:36:30 +00:00
|
|
|
($name:ident, $description:expr, $plugin_init:ident,
|
2018-11-18 12:20:16 +00:00
|
|
|
$version:expr, $license:expr, $source:expr,
|
|
|
|
$package:expr, $origin:expr, $release_datetime:expr) => {
|
|
|
|
pub mod plugin_desc {
|
2020-10-24 17:06:59 +00:00
|
|
|
#[repr(transparent)]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub struct GstPluginDesc($crate::ffi::GstPluginDesc);
|
2019-12-18 15:04:42 +00:00
|
|
|
unsafe impl Send for GstPluginDesc {}
|
2018-11-18 12:20:16 +00:00
|
|
|
unsafe impl Sync for GstPluginDesc {}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
#[allow(non_upper_case_globals)]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub static gst_plugin_desc: GstPluginDesc = GstPluginDesc($crate::ffi::GstPluginDesc {
|
2020-06-09 09:24:30 +00:00
|
|
|
major_version: $crate::subclass::MAJOR_VERSION,
|
|
|
|
minor_version: $crate::subclass::MINOR_VERSION,
|
2019-05-26 23:36:30 +00:00
|
|
|
name: concat!(stringify!($name), "\0") as *const str as *const _,
|
2018-11-20 09:13:58 +00:00
|
|
|
description: concat!($description, "\0") as *const str as *const _,
|
2018-11-18 12:20:16 +00:00
|
|
|
plugin_init: Some(plugin_init_trampoline),
|
2018-11-20 09:13:58 +00:00
|
|
|
version: concat!($version, "\0") as *const str as *const _,
|
|
|
|
license: concat!($license, "\0") as *const str as *const _,
|
|
|
|
source: concat!($source, "\0") as *const str as *const _,
|
|
|
|
package: concat!($package, "\0") as *const str as *const _,
|
|
|
|
origin: concat!($origin, "\0") as *const str as *const _,
|
|
|
|
release_datetime: concat!($release_datetime, "\0") as *const str as *const _,
|
2020-11-21 13:46:48 +00:00
|
|
|
_gst_reserved: [0 as $crate::glib::ffi::gpointer; 4],
|
2018-11-18 12:20:16 +00:00
|
|
|
});
|
|
|
|
|
2020-08-29 14:55:06 +00:00
|
|
|
pub fn plugin_register_static() -> Result<(), $crate::glib::BoolError> {
|
2018-11-18 12:20:16 +00:00
|
|
|
unsafe {
|
2020-12-17 22:38:06 +00:00
|
|
|
$crate::glib::result_from_gboolean!(
|
2020-11-21 13:46:48 +00:00
|
|
|
$crate::ffi::gst_plugin_register_static(
|
2020-06-09 09:24:30 +00:00
|
|
|
$crate::subclass::MAJOR_VERSION,
|
|
|
|
$crate::subclass::MINOR_VERSION,
|
2019-05-26 23:36:30 +00:00
|
|
|
concat!(stringify!($name), "\0") as *const str as *const _,
|
2019-01-16 20:23:56 +00:00
|
|
|
concat!($description, "\0") as *const str as _,
|
|
|
|
Some(plugin_init_trampoline),
|
|
|
|
concat!($version, "\0") as *const str as *const _,
|
|
|
|
concat!($license, "\0") as *const str as *const _,
|
|
|
|
concat!($source, "\0") as *const str as *const _,
|
|
|
|
concat!($package, "\0") as *const str as *const _,
|
|
|
|
concat!($origin, "\0") as *const str as *const _,
|
|
|
|
),
|
|
|
|
"Failed to register the plugin"
|
|
|
|
)
|
2018-11-18 12:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-18 08:15:56 +00:00
|
|
|
#[allow(clippy::missing_safety_doc)]
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe extern "C" fn plugin_init_trampoline(plugin: *mut $crate::ffi::GstPlugin) -> $crate::glib::ffi::gboolean {
|
2018-11-18 12:20:16 +00:00
|
|
|
use std::panic::{self, AssertUnwindSafe};
|
|
|
|
|
2021-04-28 06:28:54 +00:00
|
|
|
let panic_result = panic::catch_unwind(AssertUnwindSafe(|| super::$plugin_init(&$crate::glib::translate::from_glib_borrow(plugin))));
|
2018-11-18 12:20:16 +00:00
|
|
|
match panic_result {
|
|
|
|
Ok(register_result) => match register_result {
|
2020-11-21 13:46:48 +00:00
|
|
|
Ok(_) => $crate::glib::ffi::GTRUE,
|
2018-11-18 12:20:16 +00:00
|
|
|
Err(err) => {
|
|
|
|
let cat = $crate::DebugCategory::get("GST_PLUGIN_LOADING").unwrap();
|
2019-08-30 16:14:05 +00:00
|
|
|
$crate::gst_error!(cat, "Failed to register plugin: {}", err);
|
2020-11-21 13:46:48 +00:00
|
|
|
$crate::glib::ffi::GFALSE
|
2018-11-18 12:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
let cat = $crate::DebugCategory::get("GST_PLUGIN_LOADING").unwrap();
|
|
|
|
if let Some(cause) = err.downcast_ref::<&str>() {
|
2019-08-30 16:14:05 +00:00
|
|
|
$crate::gst_error!(cat, "Failed to initialize plugin due to panic: {}", cause);
|
2018-11-18 12:20:16 +00:00
|
|
|
} else if let Some(cause) = err.downcast_ref::<String>() {
|
2019-08-30 16:14:05 +00:00
|
|
|
$crate::gst_error!(cat, "Failed to initialize plugin due to panic: {}", cause);
|
2018-11-18 12:20:16 +00:00
|
|
|
} else {
|
2019-08-30 16:14:05 +00:00
|
|
|
$crate::gst_error!(cat, "Failed to initialize plugin due to panic");
|
2018-11-18 12:20:16 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
$crate::glib::ffi::GFALSE
|
2018-11-18 12:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-12 12:24:16 +00:00
|
|
|
pub use self::plugin_desc::plugin_register_static;
|
2018-11-18 12:20:16 +00:00
|
|
|
};
|
|
|
|
);
|