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) {
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 {

View file

@ -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!(

View file

@ -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" }

View file

@ -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!(

View file

@ -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" }

View file

@ -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!(

View file

@ -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"

View file

@ -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!(

View file

@ -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<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 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_)
}

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 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_)
}

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 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_)
}

View file

@ -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!(

View file

@ -1387,8 +1387,7 @@ impl ImplTypeStatic<Element> 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_)
}

View file

@ -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

View file

@ -556,7 +556,7 @@ impl ImplTypeStatic<BaseTransform> 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_)
}

View file

@ -825,7 +825,7 @@ impl ImplTypeStatic<BaseSrc> 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_)
}

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 {
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>() {