From 59d91b2abfd8a226bb7a56b9d6802b88ee906f26 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Fri, 19 Feb 2021 11:52:12 +0100 Subject: [PATCH] gstreamer/plugin_feature: Make load downcast to Self The loaded plugin feature is always of the same type as the unloaded one. Move `fn load` to PluginFeatureExtManual to implement this. --- gstreamer/Gir.toml | 3 +-- gstreamer/src/auto/plugin_feature.rs | 12 ---------- gstreamer/src/auto/versions.txt | 4 ++-- gstreamer/src/plugin_feature.rs | 33 +++++++++++++++++++++++++--- gstreamer/sys/build.rs | 4 ++-- gstreamer/sys/src/lib.rs | 4 ++-- gstreamer/sys/tests/abi.rs | 4 ++-- gstreamer/sys/tests/constant.c | 4 ++-- gstreamer/sys/tests/layout.c | 4 ++-- 9 files changed, 43 insertions(+), 29 deletions(-) diff --git a/gstreamer/Gir.toml b/gstreamer/Gir.toml index 7339093c3..29f24a10f 100644 --- a/gstreamer/Gir.toml +++ b/gstreamer/Gir.toml @@ -1240,8 +1240,7 @@ manual_traits = ["PluginFeatureExtManual"] [[object.function]] name = "load" - [object.function.return] - nullable_return_is_error = "Failed to load plugin feature" + manual = true [[object]] name = "Gst.Registry" diff --git a/gstreamer/src/auto/plugin_feature.rs b/gstreamer/src/auto/plugin_feature.rs index 12d798a92..965b01e86 100644 --- a/gstreamer/src/auto/plugin_feature.rs +++ b/gstreamer/src/auto/plugin_feature.rs @@ -29,9 +29,6 @@ pub trait PluginFeatureExt: 'static { #[doc(alias = "gst_plugin_feature_get_plugin_name")] fn get_plugin_name(&self) -> Option; - - #[doc(alias = "gst_plugin_feature_load")] - fn load(&self) -> Result; } impl> PluginFeatureExt for O { @@ -61,13 +58,4 @@ impl> PluginFeatureExt for O { )) } } - - fn load(&self) -> Result { - unsafe { - Option::<_>::from_glib_full(ffi::gst_plugin_feature_load( - self.as_ref().to_glib_none().0, - )) - .ok_or_else(|| glib::bool_error!("Failed to load plugin feature")) - } - } } diff --git a/gstreamer/src/auto/versions.txt b/gstreamer/src/auto/versions.txt index 15a504bb4..34d867430 100644 --- a/gstreamer/src/auto/versions.txt +++ b/gstreamer/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 1c7b41a) -from gir-files (https://github.com/gtk-rs/gir-files @ 3c0281db) +Generated by gir (https://github.com/gtk-rs/gir @ d8408d8) +from gir-files (https://github.com/gtk-rs/gir-files @ 5f5218e1) diff --git a/gstreamer/src/plugin_feature.rs b/gstreamer/src/plugin_feature.rs index 774aeeef7..f933d4f39 100644 --- a/gstreamer/src/plugin_feature.rs +++ b/gstreamer/src/plugin_feature.rs @@ -3,12 +3,13 @@ use crate::PluginFeature; use crate::Rank; -use glib::object::IsA; -use glib::translate::{from_glib, ToGlib, ToGlibPtr}; +use glib::object::{Cast, IsA}; +use glib::translate::{from_glib, FromGlibPtrFull, ToGlib, ToGlibPtr}; -pub trait PluginFeatureExtManual: 'static { +pub trait PluginFeatureExtManual: Sized + 'static { fn get_rank(&self) -> Rank; fn set_rank(&self, rank: Rank); + fn load(&self) -> Result; } impl> PluginFeatureExtManual for O { @@ -24,4 +25,30 @@ impl> PluginFeatureExtManual for O { ffi::gst_plugin_feature_set_rank(self.as_ref().to_glib_none().0, rank.to_glib() as u32); } } + + fn load(&self) -> Result { + unsafe { + let loaded = Option::::from_glib_full(ffi::gst_plugin_feature_load( + self.as_ref().to_glib_none().0, + )) + .ok_or_else(|| glib::bool_error!("Failed to load plugin feature"))?; + Ok(loaded.unsafe_cast()) + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::prelude::*; + + #[test] + fn test_load() { + crate::init().unwrap(); + + let factory = crate::ElementFactory::find("identity").unwrap(); + let loaded = factory.load().unwrap(); + assert_eq!(factory.get_type(), loaded.get_type()); + let _element = loaded.create(None).unwrap(); + } } diff --git a/gstreamer/sys/build.rs b/gstreamer/sys/build.rs index be8544dff..cce04378a 100644 --- a/gstreamer/sys/build.rs +++ b/gstreamer/sys/build.rs @@ -1,5 +1,5 @@ -// This file was generated by gir (https://github.com/gtk-rs/gir @ 1c7b41a) -// from gir-files (https://github.com/gtk-rs/gir-files @ 3c0281db) +// This file was generated by gir (https://github.com/gtk-rs/gir @ d8408d8) +// from gir-files (https://github.com/gtk-rs/gir-files @ 5f5218e1) // DO NOT EDIT #[cfg(not(feature = "dox"))] diff --git a/gstreamer/sys/src/lib.rs b/gstreamer/sys/src/lib.rs index e291c6567..a9b8f9fca 100644 --- a/gstreamer/sys/src/lib.rs +++ b/gstreamer/sys/src/lib.rs @@ -1,5 +1,5 @@ -// This file was generated by gir (https://github.com/gtk-rs/gir @ 1c7b41a) -// from gir-files (https://github.com/gtk-rs/gir-files @ 3c0281db) +// This file was generated by gir (https://github.com/gtk-rs/gir @ d8408d8) +// from gir-files (https://github.com/gtk-rs/gir-files @ 5f5218e1) // DO NOT EDIT #![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)] diff --git a/gstreamer/sys/tests/abi.rs b/gstreamer/sys/tests/abi.rs index 5da65ed54..2f48bbefb 100644 --- a/gstreamer/sys/tests/abi.rs +++ b/gstreamer/sys/tests/abi.rs @@ -1,5 +1,5 @@ -// This file was generated by gir (https://github.com/gtk-rs/gir @ 1c7b41a) -// from gir-files (https://github.com/gtk-rs/gir-files @ 3c0281db) +// This file was generated by gir (https://github.com/gtk-rs/gir @ d8408d8) +// from gir-files (https://github.com/gtk-rs/gir-files @ 5f5218e1) // DO NOT EDIT use gstreamer_sys::*; diff --git a/gstreamer/sys/tests/constant.c b/gstreamer/sys/tests/constant.c index 475fbb787..eebc99f4f 100644 --- a/gstreamer/sys/tests/constant.c +++ b/gstreamer/sys/tests/constant.c @@ -1,5 +1,5 @@ -// This file was generated by gir (https://github.com/gtk-rs/gir @ 1c7b41a) -// from gir-files (https://github.com/gtk-rs/gir-files @ 3c0281db) +// This file was generated by gir (https://github.com/gtk-rs/gir @ d8408d8) +// from gir-files (https://github.com/gtk-rs/gir-files @ 5f5218e1) // DO NOT EDIT #include "manual.h" diff --git a/gstreamer/sys/tests/layout.c b/gstreamer/sys/tests/layout.c index 75dc121e3..4de7c3345 100644 --- a/gstreamer/sys/tests/layout.c +++ b/gstreamer/sys/tests/layout.c @@ -1,5 +1,5 @@ -// This file was generated by gir (https://github.com/gtk-rs/gir @ 1c7b41a) -// from gir-files (https://github.com/gtk-rs/gir-files @ 3c0281db) +// This file was generated by gir (https://github.com/gtk-rs/gir @ d8408d8) +// from gir-files (https://github.com/gtk-rs/gir-files @ 5f5218e1) // DO NOT EDIT #include "manual.h"