1#[macro_export]
10macro_rules! plugin_define(
11 ($name:expr, $description:expr, $plugin_init:ident,
12 $version:expr, $license:expr, $source:expr,
13 $package:expr, $origin:expr, $release_datetime:expr) => {
14 pub mod plugin_desc {
15 use $crate::glib::translate::{from_glib_borrow, ToGlib};
16
17 #[allow(non_camel_case_types)]
19 type c_char = i8;
20
21 #[repr(C)]
22 pub struct GstPluginDesc($crate::gst_ffi::GstPluginDesc);
23 unsafe impl Sync for GstPluginDesc {}
24
25 #[no_mangle]
26 #[allow(non_upper_case_globals)]
27 pub static gst_plugin_desc: GstPluginDesc = GstPluginDesc($crate::gst_ffi::GstPluginDesc {
28 major_version: 1,
29 minor_version: 8,
30 name: $name as *const u8 as *const c_char,
31 description: $description as *const u8 as *const c_char,
32 plugin_init: Some(plugin_init_trampoline),
33 version: $version as *const u8 as *const c_char,
34 license: $license as *const u8 as *const c_char,
35 source: $source as *const u8 as *const c_char,
36 package: $package as *const u8 as *const c_char,
37 origin: $origin as *const u8 as *const c_char,
38 release_datetime: $release_datetime as *const u8 as *const c_char,
39 _gst_reserved: [0 as $crate::glib_ffi::gpointer; 4],
40 });
41
42 unsafe extern "C" fn plugin_init_trampoline(plugin: *mut $crate::gst_ffi::GstPlugin) -> $crate::glib_ffi::gboolean {
43 use std::panic::{self, AssertUnwindSafe};
44
45 let result = panic::catch_unwind(AssertUnwindSafe(|| super::$plugin_init(&from_glib_borrow(plugin)).to_glib()));
46 match result {
47 Ok(result) => result,
48 Err(err) => {
49 let cat = $crate::gst::DebugCategory::get("GST_PLUGIN_LOADING").unwrap();
50 if let Some(cause) = err.downcast_ref::<&str>() {
51 gst_error!(cat, "Failed to initialize plugin due to panic: {}", cause);
52 } else if let Some(cause) = err.downcast_ref::<String>() {
53 gst_error!(cat, "Failed to initialize plugin due to panic: {}", cause);
54 } else {
55 gst_error!(cat, "Failed to initialize plugin due to panic");
56 }
57
58 $crate::glib_ffi::GFALSE
59 }
60 }
61 }
62 }
63 };
64);