From cee861f341e66f2ed3501e0b4b667172b9ff8535 Mon Sep 17 00:00:00 2001 From: Thijs Vermeir Date: Sun, 4 Nov 2018 19:46:07 +0100 Subject: [PATCH] use BoolError for plugin registration --- gst-plugin-audiofx/src/audioecho.rs | 7 +++---- gst-plugin-audiofx/src/lib.rs | 5 ++--- gst-plugin-file/Cargo.toml | 1 + gst-plugin-file/src/lib.rs | 9 +++++---- gst-plugin-flv/Cargo.toml | 1 + gst-plugin-flv/src/lib.rs | 7 ++++--- gst-plugin-http/Cargo.toml | 1 + gst-plugin-http/src/lib.rs | 5 +++-- gst-plugin-simple/src/demuxer.rs | 8 ++++++-- gst-plugin-simple/src/sink.rs | 4 ++-- gst-plugin-simple/src/source.rs | 7 +++++-- gst-plugin-togglerecord/src/lib.rs | 5 ++--- gst-plugin-togglerecord/src/togglerecord.rs | 7 +++---- gst-plugin-tutorial/src/lib.rs | 8 ++++---- gst-plugin-tutorial/src/rgb2gray.rs | 4 ++-- gst-plugin-tutorial/src/sinesrc.rs | 4 ++-- gst-plugin/src/plugin.rs | 13 ++++++++++--- 17 files changed, 56 insertions(+), 40 deletions(-) diff --git a/gst-plugin-audiofx/src/audioecho.rs b/gst-plugin-audiofx/src/audioecho.rs index e04826ec..81bffe35 100644 --- a/gst-plugin-audiofx/src/audioecho.rs +++ b/gst-plugin-audiofx/src/audioecho.rs @@ -306,10 +306,9 @@ impl ImplTypeStatic for AudioEchoStatic { } } -pub fn register(plugin: &gst::Plugin) { - let audioecho_static = AudioEchoStatic; - let type_ = register_type(audioecho_static); - gst::Element::register(plugin, "rsaudioecho", 0, type_); +pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { + let type_ = register_type(AudioEchoStatic); + gst::Element::register(plugin, "rsaudioecho", 0, type_) } struct RingBuffer { diff --git a/gst-plugin-audiofx/src/lib.rs b/gst-plugin-audiofx/src/lib.rs index 809a46de..4c1dbbb8 100644 --- a/gst-plugin-audiofx/src/lib.rs +++ b/gst-plugin-audiofx/src/lib.rs @@ -21,9 +21,8 @@ extern crate num_traits; mod audioecho; -fn plugin_init(plugin: &gst::Plugin) -> bool { - audioecho::register(plugin); - true +fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { + audioecho::register(plugin) } plugin_define!( diff --git a/gst-plugin-file/Cargo.toml b/gst-plugin-file/Cargo.toml index 1e3547b6..ffe64a01 100644 --- a/gst-plugin-file/Cargo.toml +++ b/gst-plugin-file/Cargo.toml @@ -7,6 +7,7 @@ license = "MIT/Apache-2.0" [dependencies] url = "1.1" +glib = { git = "https://github.com/gtk-rs/glib" } gst-plugin = { path="../gst-plugin" } gst-plugin-simple = { path="../gst-plugin-simple" } gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } diff --git a/gst-plugin-file/src/lib.rs b/gst-plugin-file/src/lib.rs index cba80edc..e9f20e1e 100644 --- a/gst-plugin-file/src/lib.rs +++ b/gst-plugin-file/src/lib.rs @@ -8,6 +8,7 @@ #![crate_type = "cdylib"] +extern crate glib; #[macro_use] extern crate gst_plugin; extern crate gst_plugin_simple; @@ -24,7 +25,7 @@ mod filesrc; use filesink::FileSink; use filesrc::FileSrc; -fn plugin_init(plugin: &gst::Plugin) -> bool { +fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { source_register( plugin, SourceInfo { @@ -38,7 +39,7 @@ fn plugin_init(plugin: &gst::Plugin) -> bool { protocols: vec!["file".into()], push_only: false, }, - ); + )?; sink_register( plugin, @@ -52,9 +53,9 @@ fn plugin_init(plugin: &gst::Plugin) -> bool { create_instance: FileSink::new_boxed, protocols: vec!["file".into()], }, - ); + )?; - true + Ok(()) } plugin_define!( diff --git a/gst-plugin-flv/Cargo.toml b/gst-plugin-flv/Cargo.toml index ae0aad39..e69637b0 100644 --- a/gst-plugin-flv/Cargo.toml +++ b/gst-plugin-flv/Cargo.toml @@ -7,6 +7,7 @@ license = "MIT/Apache-2.0" [dependencies] url = "1.1" +glib = { git = "https://github.com/gtk-rs/glib" } gst-plugin = { path="../gst-plugin" } gst-plugin-simple = { path="../gst-plugin-simple" } gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } diff --git a/gst-plugin-flv/src/lib.rs b/gst-plugin-flv/src/lib.rs index 02461c43..adf8654e 100644 --- a/gst-plugin-flv/src/lib.rs +++ b/gst-plugin-flv/src/lib.rs @@ -9,6 +9,7 @@ #![crate_type = "cdylib"] extern crate flavors; +extern crate glib; #[macro_use] extern crate gst_plugin; extern crate gst_plugin_simple; @@ -25,7 +26,7 @@ mod flvdemux; use flvdemux::FlvDemux; -fn plugin_init(plugin: &gst::Plugin) -> bool { +fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { demuxer_register( plugin, DemuxerInfo { @@ -39,9 +40,9 @@ fn plugin_init(plugin: &gst::Plugin) -> bool { input_caps: gst::Caps::new_simple("video/x-flv", &[]), output_caps: gst::Caps::new_any(), }, - ); + )?; - true + Ok(()) } plugin_define!( diff --git a/gst-plugin-http/Cargo.toml b/gst-plugin-http/Cargo.toml index ed3b9cf0..a9bb71b8 100644 --- a/gst-plugin-http/Cargo.toml +++ b/gst-plugin-http/Cargo.toml @@ -7,6 +7,7 @@ license = "MIT/Apache-2.0" [dependencies] url = "1.1" +glib = { git = "https://github.com/gtk-rs/glib" } gst-plugin = { path="../gst-plugin" } gst-plugin-simple = { path="../gst-plugin-simple" } reqwest = "0.8" diff --git a/gst-plugin-http/src/lib.rs b/gst-plugin-http/src/lib.rs index 1cf292ab..f8b62225 100644 --- a/gst-plugin-http/src/lib.rs +++ b/gst-plugin-http/src/lib.rs @@ -8,6 +8,7 @@ #![crate_type = "cdylib"] +extern crate glib; #[macro_use] extern crate gst_plugin; extern crate gst_plugin_simple; @@ -22,7 +23,7 @@ mod httpsrc; use httpsrc::HttpSrc; -fn plugin_init(plugin: &gst::Plugin) -> bool { +fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { source_register( plugin, SourceInfo { @@ -38,7 +39,7 @@ fn plugin_init(plugin: &gst::Plugin) -> bool { }, ); - true + Ok(()) } plugin_define!( diff --git a/gst-plugin-simple/src/demuxer.rs b/gst-plugin-simple/src/demuxer.rs index b34b629a..4fb75958 100644 --- a/gst-plugin-simple/src/demuxer.rs +++ b/gst-plugin-simple/src/demuxer.rs @@ -12,6 +12,7 @@ use std::collections::BTreeMap; use std::u32; use std::u64; +use glib; use gobject_subclass::object::*; use gst_plugin::element::*; use gst_plugin::error::*; @@ -671,7 +672,10 @@ impl ImplTypeStatic for DemuxerStatic { } } -pub fn demuxer_register(plugin: &gst::Plugin, demuxer_info: DemuxerInfo) { +pub fn demuxer_register( + plugin: &gst::Plugin, + demuxer_info: DemuxerInfo, +) -> Result<(), glib::BoolError> { let name = demuxer_info.name.clone(); let rank = demuxer_info.rank; @@ -681,5 +685,5 @@ pub fn demuxer_register(plugin: &gst::Plugin, demuxer_info: DemuxerInfo) { }; let type_ = register_type(demuxer_static); - gst::Element::register(plugin, &name, rank, type_); + gst::Element::register(plugin, &name, rank, type_) } diff --git a/gst-plugin-simple/src/sink.rs b/gst-plugin-simple/src/sink.rs index a749ab6e..66f21ac1 100644 --- a/gst-plugin-simple/src/sink.rs +++ b/gst-plugin-simple/src/sink.rs @@ -289,7 +289,7 @@ impl URIHandlerImplStatic for SinkStatic { } } -pub fn sink_register(plugin: &gst::Plugin, sink_info: SinkInfo) { +pub fn sink_register(plugin: &gst::Plugin, sink_info: SinkInfo) -> Result<(), glib::BoolError> { let name = sink_info.name.clone(); let rank = sink_info.rank; @@ -299,5 +299,5 @@ pub fn sink_register(plugin: &gst::Plugin, sink_info: SinkInfo) { }; let type_ = register_type(sink_static); - gst::Element::register(plugin, &name, rank, type_); + gst::Element::register(plugin, &name, rank, type_) } diff --git a/gst-plugin-simple/src/source.rs b/gst-plugin-simple/src/source.rs index f87b74cc..94512efb 100644 --- a/gst-plugin-simple/src/source.rs +++ b/gst-plugin-simple/src/source.rs @@ -373,7 +373,10 @@ impl URIHandlerImplStatic for SourceStatic { } } -pub fn source_register(plugin: &gst::Plugin, source_info: SourceInfo) { +pub fn source_register( + plugin: &gst::Plugin, + source_info: SourceInfo, +) -> Result<(), glib::BoolError> { let name = source_info.name.clone(); let rank = source_info.rank; @@ -383,5 +386,5 @@ pub fn source_register(plugin: &gst::Plugin, source_info: SourceInfo) { }; let type_ = register_type(source_static); - gst::Element::register(plugin, &name, rank, type_); + gst::Element::register(plugin, &name, rank, type_) } diff --git a/gst-plugin-togglerecord/src/lib.rs b/gst-plugin-togglerecord/src/lib.rs index bc70354d..818dd8d4 100644 --- a/gst-plugin-togglerecord/src/lib.rs +++ b/gst-plugin-togglerecord/src/lib.rs @@ -29,9 +29,8 @@ extern crate parking_lot; mod togglerecord; -fn plugin_init(plugin: &gst::Plugin) -> bool { - togglerecord::register(plugin); - true +fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { + togglerecord::register(plugin) } plugin_define!( diff --git a/gst-plugin-togglerecord/src/togglerecord.rs b/gst-plugin-togglerecord/src/togglerecord.rs index 110f173f..ccd9b9e8 100644 --- a/gst-plugin-togglerecord/src/togglerecord.rs +++ b/gst-plugin-togglerecord/src/togglerecord.rs @@ -1387,8 +1387,7 @@ impl ImplTypeStatic for ToggleRecordStatic { } } -pub fn register(plugin: &gst::Plugin) { - let togglerecord_static = ToggleRecordStatic; - let type_ = register_type(togglerecord_static); - gst::Element::register(plugin, "togglerecord", 0, type_); +pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { + let type_ = register_type(ToggleRecordStatic); + gst::Element::register(plugin, "togglerecord", 0, type_) } diff --git a/gst-plugin-tutorial/src/lib.rs b/gst-plugin-tutorial/src/lib.rs index e2a8cbab..c6cf3d4f 100644 --- a/gst-plugin-tutorial/src/lib.rs +++ b/gst-plugin-tutorial/src/lib.rs @@ -24,10 +24,10 @@ mod sinesrc; // Plugin entry point that should register all elements provided by this plugin, // and everything else that this plugin might provide (e.g. typefinders or device providers). -fn plugin_init(plugin: &gst::Plugin) -> bool { - rgb2gray::register(plugin); - sinesrc::register(plugin); - true +fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { + rgb2gray::register(plugin)?; + sinesrc::register(plugin)?; + Ok(()) } // Static plugin metdata that is directly stored in the plugin shared object and read by GStreamer diff --git a/gst-plugin-tutorial/src/rgb2gray.rs b/gst-plugin-tutorial/src/rgb2gray.rs index 6ec65b07..32d297ba 100644 --- a/gst-plugin-tutorial/src/rgb2gray.rs +++ b/gst-plugin-tutorial/src/rgb2gray.rs @@ -556,7 +556,7 @@ impl ImplTypeStatic for Rgb2GrayStatic { // Registers the type for our element, and then registers in GStreamer under // the name "rsrgb2gray" for being able to instantiate it via e.g. // gst::ElementFactory::make(). -pub fn register(plugin: &gst::Plugin) { +pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { let type_ = register_type(Rgb2GrayStatic); - gst::Element::register(plugin, "rsrgb2gray", 0, type_); + gst::Element::register(plugin, "rsrgb2gray", 0, type_) } diff --git a/gst-plugin-tutorial/src/sinesrc.rs b/gst-plugin-tutorial/src/sinesrc.rs index 303238ca..030f6630 100644 --- a/gst-plugin-tutorial/src/sinesrc.rs +++ b/gst-plugin-tutorial/src/sinesrc.rs @@ -825,7 +825,7 @@ impl ImplTypeStatic for SineSrcStatic { // Registers the type for our element, and then registers in GStreamer under // the name "sinesrc" for being able to instantiate it via e.g. // gst::ElementFactory::make(). -pub fn register(plugin: &gst::Plugin) { +pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { let type_ = register_type(SineSrcStatic); - gst::Element::register(plugin, "rssinesrc", 0, type_); + gst::Element::register(plugin, "rssinesrc", 0, type_) } diff --git a/gst-plugin/src/plugin.rs b/gst-plugin/src/plugin.rs index 24122505..e8719ecf 100644 --- a/gst-plugin/src/plugin.rs +++ b/gst-plugin/src/plugin.rs @@ -42,9 +42,16 @@ macro_rules! plugin_define( unsafe extern "C" fn plugin_init_trampoline(plugin: *mut $crate::gst_ffi::GstPlugin) -> $crate::glib_ffi::gboolean { use std::panic::{self, AssertUnwindSafe}; - let result = panic::catch_unwind(AssertUnwindSafe(|| super::$plugin_init(&from_glib_borrow(plugin)).to_glib())); - match result { - Ok(result) => result, + let panic_result = panic::catch_unwind(AssertUnwindSafe(|| super::$plugin_init(&from_glib_borrow(plugin)))); + match panic_result { + Ok(register_result) => match register_result { + Ok(_) => $crate::glib_ffi::GTRUE, + Err(err) => { + let cat = $crate::gst::DebugCategory::get("GST_PLUGIN_LOADING").unwrap(); + 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>() {