use BoolError for plugin registration

This commit is contained in:
Thijs Vermeir 2018-11-04 19:46:07 +01:00
parent 46f80da72e
commit cee861f341
17 changed files with 56 additions and 40 deletions

View file

@ -306,10 +306,9 @@ impl ImplTypeStatic<BaseTransform> for AudioEchoStatic {
} }
} }
pub fn register(plugin: &gst::Plugin) { pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
let audioecho_static = AudioEchoStatic; let type_ = register_type(AudioEchoStatic);
let type_ = register_type(audioecho_static); gst::Element::register(plugin, "rsaudioecho", 0, type_)
gst::Element::register(plugin, "rsaudioecho", 0, type_);
} }
struct RingBuffer { struct RingBuffer {

View file

@ -21,9 +21,8 @@ extern crate num_traits;
mod audioecho; mod audioecho;
fn plugin_init(plugin: &gst::Plugin) -> bool { fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
audioecho::register(plugin); audioecho::register(plugin)
true
} }
plugin_define!( plugin_define!(

View file

@ -7,6 +7,7 @@ license = "MIT/Apache-2.0"
[dependencies] [dependencies]
url = "1.1" url = "1.1"
glib = { git = "https://github.com/gtk-rs/glib" }
gst-plugin = { path="../gst-plugin" } gst-plugin = { path="../gst-plugin" }
gst-plugin-simple = { path="../gst-plugin-simple" } gst-plugin-simple = { path="../gst-plugin-simple" }
gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }

View file

@ -8,6 +8,7 @@
#![crate_type = "cdylib"] #![crate_type = "cdylib"]
extern crate glib;
#[macro_use] #[macro_use]
extern crate gst_plugin; extern crate gst_plugin;
extern crate gst_plugin_simple; extern crate gst_plugin_simple;
@ -24,7 +25,7 @@ mod filesrc;
use filesink::FileSink; use filesink::FileSink;
use filesrc::FileSrc; use filesrc::FileSrc;
fn plugin_init(plugin: &gst::Plugin) -> bool { fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
source_register( source_register(
plugin, plugin,
SourceInfo { SourceInfo {
@ -38,7 +39,7 @@ fn plugin_init(plugin: &gst::Plugin) -> bool {
protocols: vec!["file".into()], protocols: vec!["file".into()],
push_only: false, push_only: false,
}, },
); )?;
sink_register( sink_register(
plugin, plugin,
@ -52,9 +53,9 @@ fn plugin_init(plugin: &gst::Plugin) -> bool {
create_instance: FileSink::new_boxed, create_instance: FileSink::new_boxed,
protocols: vec!["file".into()], protocols: vec!["file".into()],
}, },
); )?;
true Ok(())
} }
plugin_define!( plugin_define!(

View file

@ -7,6 +7,7 @@ license = "MIT/Apache-2.0"
[dependencies] [dependencies]
url = "1.1" url = "1.1"
glib = { git = "https://github.com/gtk-rs/glib" }
gst-plugin = { path="../gst-plugin" } gst-plugin = { path="../gst-plugin" }
gst-plugin-simple = { path="../gst-plugin-simple" } gst-plugin-simple = { path="../gst-plugin-simple" }
gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }

View file

@ -9,6 +9,7 @@
#![crate_type = "cdylib"] #![crate_type = "cdylib"]
extern crate flavors; extern crate flavors;
extern crate glib;
#[macro_use] #[macro_use]
extern crate gst_plugin; extern crate gst_plugin;
extern crate gst_plugin_simple; extern crate gst_plugin_simple;
@ -25,7 +26,7 @@ mod flvdemux;
use flvdemux::FlvDemux; use flvdemux::FlvDemux;
fn plugin_init(plugin: &gst::Plugin) -> bool { fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
demuxer_register( demuxer_register(
plugin, plugin,
DemuxerInfo { DemuxerInfo {
@ -39,9 +40,9 @@ fn plugin_init(plugin: &gst::Plugin) -> bool {
input_caps: gst::Caps::new_simple("video/x-flv", &[]), input_caps: gst::Caps::new_simple("video/x-flv", &[]),
output_caps: gst::Caps::new_any(), output_caps: gst::Caps::new_any(),
}, },
); )?;
true Ok(())
} }
plugin_define!( plugin_define!(

View file

@ -7,6 +7,7 @@ license = "MIT/Apache-2.0"
[dependencies] [dependencies]
url = "1.1" url = "1.1"
glib = { git = "https://github.com/gtk-rs/glib" }
gst-plugin = { path="../gst-plugin" } gst-plugin = { path="../gst-plugin" }
gst-plugin-simple = { path="../gst-plugin-simple" } gst-plugin-simple = { path="../gst-plugin-simple" }
reqwest = "0.8" reqwest = "0.8"

View file

@ -8,6 +8,7 @@
#![crate_type = "cdylib"] #![crate_type = "cdylib"]
extern crate glib;
#[macro_use] #[macro_use]
extern crate gst_plugin; extern crate gst_plugin;
extern crate gst_plugin_simple; extern crate gst_plugin_simple;
@ -22,7 +23,7 @@ mod httpsrc;
use httpsrc::HttpSrc; use httpsrc::HttpSrc;
fn plugin_init(plugin: &gst::Plugin) -> bool { fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
source_register( source_register(
plugin, plugin,
SourceInfo { SourceInfo {
@ -38,7 +39,7 @@ fn plugin_init(plugin: &gst::Plugin) -> bool {
}, },
); );
true Ok(())
} }
plugin_define!( plugin_define!(

View file

@ -12,6 +12,7 @@ use std::collections::BTreeMap;
use std::u32; use std::u32;
use std::u64; use std::u64;
use glib;
use gobject_subclass::object::*; use gobject_subclass::object::*;
use gst_plugin::element::*; use gst_plugin::element::*;
use gst_plugin::error::*; use gst_plugin::error::*;
@ -671,7 +672,10 @@ impl ImplTypeStatic<Element> 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 name = demuxer_info.name.clone();
let rank = demuxer_info.rank; 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); let type_ = register_type(demuxer_static);
gst::Element::register(plugin, &name, rank, type_); gst::Element::register(plugin, &name, rank, type_)
} }

View file

@ -289,7 +289,7 @@ impl URIHandlerImplStatic<BaseSink> 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 name = sink_info.name.clone();
let rank = sink_info.rank; 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); let type_ = register_type(sink_static);
gst::Element::register(plugin, &name, rank, type_); gst::Element::register(plugin, &name, rank, type_)
} }

View file

@ -373,7 +373,10 @@ impl URIHandlerImplStatic<BaseSrc> 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 name = source_info.name.clone();
let rank = source_info.rank; 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); let type_ = register_type(source_static);
gst::Element::register(plugin, &name, rank, type_); gst::Element::register(plugin, &name, rank, type_)
} }

View file

@ -29,9 +29,8 @@ extern crate parking_lot;
mod togglerecord; mod togglerecord;
fn plugin_init(plugin: &gst::Plugin) -> bool { fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
togglerecord::register(plugin); togglerecord::register(plugin)
true
} }
plugin_define!( plugin_define!(

View file

@ -1387,8 +1387,7 @@ impl ImplTypeStatic<Element> for ToggleRecordStatic {
} }
} }
pub fn register(plugin: &gst::Plugin) { pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
let togglerecord_static = ToggleRecordStatic; let type_ = register_type(ToggleRecordStatic);
let type_ = register_type(togglerecord_static); gst::Element::register(plugin, "togglerecord", 0, type_)
gst::Element::register(plugin, "togglerecord", 0, type_);
} }

View file

@ -24,10 +24,10 @@ mod sinesrc;
// Plugin entry point that should register all elements provided by this plugin, // 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). // and everything else that this plugin might provide (e.g. typefinders or device providers).
fn plugin_init(plugin: &gst::Plugin) -> bool { fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
rgb2gray::register(plugin); rgb2gray::register(plugin)?;
sinesrc::register(plugin); sinesrc::register(plugin)?;
true Ok(())
} }
// Static plugin metdata that is directly stored in the plugin shared object and read by GStreamer // Static plugin metdata that is directly stored in the plugin shared object and read by GStreamer

View file

@ -556,7 +556,7 @@ impl ImplTypeStatic<BaseTransform> for Rgb2GrayStatic {
// Registers the type for our element, and then registers in GStreamer under // Registers the type for our element, and then registers in GStreamer under
// the name "rsrgb2gray" for being able to instantiate it via e.g. // the name "rsrgb2gray" for being able to instantiate it via e.g.
// gst::ElementFactory::make(). // gst::ElementFactory::make().
pub fn register(plugin: &gst::Plugin) { pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
let type_ = register_type(Rgb2GrayStatic); let type_ = register_type(Rgb2GrayStatic);
gst::Element::register(plugin, "rsrgb2gray", 0, type_); gst::Element::register(plugin, "rsrgb2gray", 0, type_)
} }

View file

@ -825,7 +825,7 @@ impl ImplTypeStatic<BaseSrc> for SineSrcStatic {
// Registers the type for our element, and then registers in GStreamer under // Registers the type for our element, and then registers in GStreamer under
// the name "sinesrc" for being able to instantiate it via e.g. // the name "sinesrc" for being able to instantiate it via e.g.
// gst::ElementFactory::make(). // gst::ElementFactory::make().
pub fn register(plugin: &gst::Plugin) { pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
let type_ = register_type(SineSrcStatic); let type_ = register_type(SineSrcStatic);
gst::Element::register(plugin, "rssinesrc", 0, type_); gst::Element::register(plugin, "rssinesrc", 0, type_)
} }

View file

@ -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 { unsafe extern "C" fn plugin_init_trampoline(plugin: *mut $crate::gst_ffi::GstPlugin) -> $crate::glib_ffi::gboolean {
use std::panic::{self, AssertUnwindSafe}; use std::panic::{self, AssertUnwindSafe};
let result = panic::catch_unwind(AssertUnwindSafe(|| super::$plugin_init(&from_glib_borrow(plugin)).to_glib())); let panic_result = panic::catch_unwind(AssertUnwindSafe(|| super::$plugin_init(&from_glib_borrow(plugin))));
match result { match panic_result {
Ok(result) => 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) => { Err(err) => {
let cat = $crate::gst::DebugCategory::get("GST_PLUGIN_LOADING").unwrap(); let cat = $crate::gst::DebugCategory::get("GST_PLUGIN_LOADING").unwrap();
if let Some(cause) = err.downcast_ref::<&str>() { if let Some(cause) = err.downcast_ref::<&str>() {