From 668b2b3fdf0a9ab1cba44c8dcbc85868ea34da31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 15 Nov 2021 11:45:30 +0200 Subject: [PATCH] gstreamer: Use `glib::List` in various places for reducing allocations when working with factory lists Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/359 --- gstreamer/Gir.toml | 85 ++++++++++++++++ gstreamer/src/auto/device_monitor.rs | 13 --- gstreamer/src/auto/device_provider.rs | 12 --- gstreamer/src/auto/device_provider_factory.rs | 11 --- gstreamer/src/auto/element_factory.rs | 53 ---------- gstreamer/src/auto/functions.rs | 11 --- gstreamer/src/auto/registry.rs | 84 ---------------- gstreamer/src/auto/tracer_factory.rs | 9 +- gstreamer/src/auto/type_find_factory.rs | 7 -- gstreamer/src/device_monitor.rs | 12 +++ gstreamer/src/device_provider.rs | 12 +++ gstreamer/src/device_provider_factory.rs | 16 +++ gstreamer/src/element_factory.rs | 37 ++++++- ...y_list_type.rs => element_factory_type.rs} | 10 +- gstreamer/src/functions.rs | 11 +++ gstreamer/src/lib.rs | 8 +- gstreamer/src/registry.rs | 97 +++++++++++++++++++ gstreamer/src/tracer_factory.rs | 18 ++++ gstreamer/src/typefind.rs | 6 +- gstreamer/src/typefind_factory.rs | 14 +++ 20 files changed, 316 insertions(+), 210 deletions(-) create mode 100644 gstreamer/src/device_provider_factory.rs rename gstreamer/src/{element_factory_list_type.rs => element_factory_type.rs} (95%) create mode 100644 gstreamer/src/registry.rs create mode 100644 gstreamer/src/tracer_factory.rs create mode 100644 gstreamer/src/typefind_factory.rs diff --git a/gstreamer/Gir.toml b/gstreamer/Gir.toml index 5dc05b0b9..8f503e379 100644 --- a/gstreamer/Gir.toml +++ b/gstreamer/Gir.toml @@ -1091,6 +1091,28 @@ final_type = true # separate name/value arrays need to be merged manual = true + [[object.function]] + name = "get_static_pad_templates" + # Use glib::List as return type + manual = true + + [[object.function]] + name = "list_is_type" + rename = "has_type" + # Renamed flags type + manual = true + + [[object.function]] + name = "list_filter" + # can_{sink,src}_{all,any}_caps() around an iterator is the same + ignore = true + + [[object.function]] + name = "list_get_elements" + rename = "factories_with_type" + # Use glib::List as return type + manual = true + [[object]] name = "Gst.TypeFindFactory" status = "generate" @@ -1101,10 +1123,21 @@ final_type = true # Set up native functions in `TypeFind`, calling into trait argument manual = true + [[object.function]] + name = "get_list" + rename = "factories" + # Use glib::List as return type + manual = true + [[object]] name = "Gst.DeviceProviderFactory" status = "generate" final_type = true + [[object.function]] + name = "list_get_device_providers" + rename = "factories" + # Use glib::List as return type + manual = true [[object]] name = "Gst.DeviceProvider" @@ -1124,6 +1157,11 @@ manual_traits = ["DeviceProviderExtManual"] # better manual function manual = true + [[object.function]] + name = "get_devices" + # Use glib::List as return type + manual = true + [[object]] name = "Gst.DeviceMonitor" status = "generate" @@ -1148,6 +1186,11 @@ manual_traits = ["DeviceMonitorExtManual"] # Use DeviceMonitorFilterId and return Result<(), glib::BoolError> manual = true + [[object.function]] + name = "get_devices" + # Use glib::List as return type + manual = true + [[object]] name = "Gst.Device" status = "generate" @@ -1655,6 +1698,36 @@ final_type = true [object.function.return] bool_return_is_error = "Failed to add plugin" + [[object.function]] + name = "feature_filter" + rename = "features_filtered" + # Use glib::List as return type + manual = true + + [[object.function]] + name = "get_feature_list" + rename = "features" + # Use glib::List as return type + manual = true + + [[object.function]] + name = "get_feature_list_by_plugin" + rename = "features_by_plugin" + # Use glib::List as return type + manual = true + + [[object.function]] + name = "get_plugin_list" + rename = "plugins" + # Use glib::List as return type + manual = true + + [[object.function]] + name = "plugin_filter" + rename = "plugins_filtered" + # Use glib::List as return type + manual = true + [[object]] name = "Gst.BufferPool" status = "generate" @@ -2041,6 +2114,12 @@ status = "generate" # implemented as part of Tracer subclassing manual = true + [[object.function]] + name = "tracing_get_active_tracers" + rename = "active_tracers" + # Use glib::List as return type + manual = true + [[object]] name = "Gst.State" status = "generate" @@ -2262,6 +2341,12 @@ status = "generate" name = "Gst.TracerFactory" status = "generate" + [[object.function]] + name = "get_list" + rename = "factories" + # Use glib::List as return type + manual = true + [[object]] name = "Gst.URIType" status = "generate" diff --git a/gstreamer/src/auto/device_monitor.rs b/gstreamer/src/auto/device_monitor.rs index 3cb9daf20..e052e9678 100644 --- a/gstreamer/src/auto/device_monitor.rs +++ b/gstreamer/src/auto/device_monitor.rs @@ -4,7 +4,6 @@ // DO NOT EDIT use crate::Bus; -use crate::Device; use crate::Object; use glib::object::Cast; use glib::object::IsA; @@ -37,10 +36,6 @@ pub trait DeviceMonitorExt: 'static { #[doc(alias = "get_bus")] fn bus(&self) -> Bus; - #[doc(alias = "gst_device_monitor_get_devices")] - #[doc(alias = "get_devices")] - fn devices(&self) -> Vec; - #[doc(alias = "gst_device_monitor_get_providers")] #[doc(alias = "get_providers")] fn providers(&self) -> Vec; @@ -80,14 +75,6 @@ impl> DeviceMonitorExt for O { } } - fn devices(&self) -> Vec { - unsafe { - FromGlibPtrContainer::from_glib_full(ffi::gst_device_monitor_get_devices( - self.as_ref().to_glib_none().0, - )) - } - } - fn providers(&self) -> Vec { unsafe { FromGlibPtrContainer::from_glib_full(ffi::gst_device_monitor_get_providers( diff --git a/gstreamer/src/auto/device_provider.rs b/gstreamer/src/auto/device_provider.rs index 3528970bd..a40f39b3c 100644 --- a/gstreamer/src/auto/device_provider.rs +++ b/gstreamer/src/auto/device_provider.rs @@ -50,10 +50,6 @@ pub trait DeviceProviderExt: 'static { #[doc(alias = "get_bus")] fn bus(&self) -> Bus; - #[doc(alias = "gst_device_provider_get_devices")] - #[doc(alias = "get_devices")] - fn devices(&self) -> Vec; - #[doc(alias = "gst_device_provider_get_factory")] #[doc(alias = "get_factory")] fn factory(&self) -> Option; @@ -139,14 +135,6 @@ impl> DeviceProviderExt for O { } } - fn devices(&self) -> Vec { - unsafe { - FromGlibPtrContainer::from_glib_full(ffi::gst_device_provider_get_devices( - self.as_ref().to_glib_none().0, - )) - } - } - fn factory(&self) -> Option { unsafe { from_glib_none(ffi::gst_device_provider_get_factory( diff --git a/gstreamer/src/auto/device_provider_factory.rs b/gstreamer/src/auto/device_provider_factory.rs index f415d18ee..b5ac8c831 100644 --- a/gstreamer/src/auto/device_provider_factory.rs +++ b/gstreamer/src/auto/device_provider_factory.rs @@ -6,7 +6,6 @@ use crate::DeviceProvider; use crate::Object; use crate::PluginFeature; -use crate::Rank; use glib::translate::*; glib::wrapper! { @@ -91,16 +90,6 @@ impl DeviceProviderFactory { )) } } - - #[doc(alias = "gst_device_provider_factory_list_get_device_providers")] - pub fn list_get_device_providers(minrank: Rank) -> Vec { - assert_initialized_main_thread!(); - unsafe { - FromGlibPtrContainer::from_glib_full( - ffi::gst_device_provider_factory_list_get_device_providers(minrank.into_glib()), - ) - } - } } unsafe impl Send for DeviceProviderFactory {} diff --git a/gstreamer/src/auto/element_factory.rs b/gstreamer/src/auto/element_factory.rs index 11ddae30c..9e702af11 100644 --- a/gstreamer/src/auto/element_factory.rs +++ b/gstreamer/src/auto/element_factory.rs @@ -5,12 +5,8 @@ use crate::Caps; use crate::Element; -use crate::ElementFactoryListType; use crate::Object; -use crate::PadDirection; use crate::PluginFeature; -use crate::Rank; -use crate::StaticPadTemplate; use crate::URIType; use glib::translate::*; @@ -112,16 +108,6 @@ impl ElementFactory { unsafe { ffi::gst_element_factory_get_num_pad_templates(self.to_glib_none().0) } } - #[doc(alias = "gst_element_factory_get_static_pad_templates")] - #[doc(alias = "get_static_pad_templates")] - pub fn static_pad_templates(&self) -> Vec { - unsafe { - FromGlibPtrContainer::from_glib_none(ffi::gst_element_factory_get_static_pad_templates( - self.to_glib_none().0, - )) - } - } - #[doc(alias = "gst_element_factory_get_uri_protocols")] #[doc(alias = "get_uri_protocols")] pub fn uri_protocols(&self) -> Vec { @@ -148,51 +134,12 @@ impl ElementFactory { } } - #[doc(alias = "gst_element_factory_list_is_type")] - pub fn list_is_type(&self, type_: ElementFactoryListType) -> bool { - unsafe { - from_glib(ffi::gst_element_factory_list_is_type( - self.to_glib_none().0, - type_.into_glib(), - )) - } - } - #[doc(alias = "gst_element_factory_find")] pub fn find(name: &str) -> Option { assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::gst_element_factory_find(name.to_glib_none().0)) } } - #[doc(alias = "gst_element_factory_list_filter")] - pub fn list_filter( - list: &[ElementFactory], - caps: &Caps, - direction: PadDirection, - subsetonly: bool, - ) -> Vec { - assert_initialized_main_thread!(); - unsafe { - FromGlibPtrContainer::from_glib_full(ffi::gst_element_factory_list_filter( - list.to_glib_none().0, - caps.to_glib_none().0, - direction.into_glib(), - subsetonly.into_glib(), - )) - } - } - - #[doc(alias = "gst_element_factory_list_get_elements")] - pub fn list_get_elements(type_: ElementFactoryListType, minrank: Rank) -> Vec { - assert_initialized_main_thread!(); - unsafe { - FromGlibPtrContainer::from_glib_full(ffi::gst_element_factory_list_get_elements( - type_.into_glib(), - minrank.into_glib(), - )) - } - } - #[doc(alias = "gst_element_factory_make")] pub fn make(factoryname: &str, name: Option<&str>) -> Result { assert_initialized_main_thread!(); diff --git a/gstreamer/src/auto/functions.rs b/gstreamer/src/auto/functions.rs index f13b4cbe2..72ad187dc 100644 --- a/gstreamer/src/auto/functions.rs +++ b/gstreamer/src/auto/functions.rs @@ -14,9 +14,6 @@ use crate::PluginAPIFlags; #[cfg(any(feature = "v1_12", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_12")))] use crate::StackTraceFlags; -#[cfg(any(feature = "v1_18", feature = "dox"))] -#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] -use crate::Tracer; use glib::object::IsA; use glib::translate::*; use std::mem; @@ -239,14 +236,6 @@ pub fn parse_launchv(argv: &[&str]) -> Result { } } -#[cfg(any(feature = "v1_18", feature = "dox"))] -#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] -#[doc(alias = "gst_tracing_get_active_tracers")] -pub fn tracing_get_active_tracers() -> Vec { - assert_initialized_main_thread!(); - unsafe { FromGlibPtrContainer::from_glib_full(ffi::gst_tracing_get_active_tracers()) } -} - #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[doc(alias = "gst_type_mark_as_plugin_api")] diff --git a/gstreamer/src/auto/registry.rs b/gstreamer/src/auto/registry.rs index 9d8f6c83e..b6b60fa3b 100644 --- a/gstreamer/src/auto/registry.rs +++ b/gstreamer/src/auto/registry.rs @@ -69,34 +69,6 @@ impl Registry { } } - #[doc(alias = "gst_registry_feature_filter")] - pub fn feature_filter bool>( - &self, - filter: P, - first: bool, - ) -> Vec { - let filter_data: P = filter; - unsafe extern "C" fn filter_func bool>( - feature: *mut ffi::GstPluginFeature, - user_data: glib::ffi::gpointer, - ) -> glib::ffi::gboolean { - let feature = from_glib_borrow(feature); - let callback: *mut P = user_data as *const _ as usize as *mut P; - let res = (*callback)(&feature); - res.into_glib() - } - let filter = Some(filter_func::

as _); - let super_callback0: &P = &filter_data; - unsafe { - FromGlibPtrContainer::from_glib_full(ffi::gst_registry_feature_filter( - self.to_glib_none().0, - filter, - first.into_glib(), - super_callback0 as *const _ as usize as *mut _, - )) - } - } - #[doc(alias = "gst_registry_find_feature")] pub fn find_feature(&self, name: &str, type_: glib::types::Type) -> Option { unsafe { @@ -118,44 +90,12 @@ impl Registry { } } - #[doc(alias = "gst_registry_get_feature_list")] - #[doc(alias = "get_feature_list")] - pub fn feature_list(&self, type_: glib::types::Type) -> Vec { - unsafe { - FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_feature_list( - self.to_glib_none().0, - type_.into_glib(), - )) - } - } - - #[doc(alias = "gst_registry_get_feature_list_by_plugin")] - #[doc(alias = "get_feature_list_by_plugin")] - pub fn feature_list_by_plugin(&self, name: &str) -> Vec { - unsafe { - FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_feature_list_by_plugin( - self.to_glib_none().0, - name.to_glib_none().0, - )) - } - } - #[doc(alias = "gst_registry_get_feature_list_cookie")] #[doc(alias = "get_feature_list_cookie")] pub fn feature_list_cookie(&self) -> u32 { unsafe { ffi::gst_registry_get_feature_list_cookie(self.to_glib_none().0) } } - #[doc(alias = "gst_registry_get_plugin_list")] - #[doc(alias = "get_plugin_list")] - pub fn plugin_list(&self) -> Vec { - unsafe { - FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_plugin_list( - self.to_glib_none().0, - )) - } - } - #[doc(alias = "gst_registry_lookup")] pub fn lookup(&self, filename: &str) -> Option { unsafe { @@ -176,30 +116,6 @@ impl Registry { } } - #[doc(alias = "gst_registry_plugin_filter")] - pub fn plugin_filter bool>(&self, filter: P, first: bool) -> Vec { - let filter_data: P = filter; - unsafe extern "C" fn filter_func bool>( - plugin: *mut ffi::GstPlugin, - user_data: glib::ffi::gpointer, - ) -> glib::ffi::gboolean { - let plugin = from_glib_borrow(plugin); - let callback: *mut P = user_data as *const _ as usize as *mut P; - let res = (*callback)(&plugin); - res.into_glib() - } - let filter = Some(filter_func::

as _); - let super_callback0: &P = &filter_data; - unsafe { - FromGlibPtrContainer::from_glib_full(ffi::gst_registry_plugin_filter( - self.to_glib_none().0, - filter, - first.into_glib(), - super_callback0 as *const _ as usize as *mut _, - )) - } - } - #[doc(alias = "gst_registry_remove_feature")] pub fn remove_feature(&self, feature: &impl IsA) { unsafe { diff --git a/gstreamer/src/auto/tracer_factory.rs b/gstreamer/src/auto/tracer_factory.rs index 58abf6aeb..3135db6e1 100644 --- a/gstreamer/src/auto/tracer_factory.rs +++ b/gstreamer/src/auto/tracer_factory.rs @@ -5,6 +5,8 @@ use crate::Object; use crate::PluginFeature; +#[cfg(any(feature = "v1_14", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] use glib::translate::*; glib::wrapper! { @@ -28,13 +30,6 @@ impl TracerFactory { )) } } - - #[doc(alias = "gst_tracer_factory_get_list")] - #[doc(alias = "get_list")] - pub fn list() -> Vec { - assert_initialized_main_thread!(); - unsafe { FromGlibPtrContainer::from_glib_full(ffi::gst_tracer_factory_get_list()) } - } } unsafe impl Send for TracerFactory {} diff --git a/gstreamer/src/auto/type_find_factory.rs b/gstreamer/src/auto/type_find_factory.rs index 55c2388bb..a3a6924d4 100644 --- a/gstreamer/src/auto/type_find_factory.rs +++ b/gstreamer/src/auto/type_find_factory.rs @@ -42,13 +42,6 @@ impl TypeFindFactory { )) } } - - #[doc(alias = "gst_type_find_factory_get_list")] - #[doc(alias = "get_list")] - pub fn list() -> Vec { - assert_initialized_main_thread!(); - unsafe { FromGlibPtrContainer::from_glib_full(ffi::gst_type_find_factory_get_list()) } - } } unsafe impl Send for TypeFindFactory {} diff --git a/gstreamer/src/device_monitor.rs b/gstreamer/src/device_monitor.rs index 55cc313a9..66d071310 100644 --- a/gstreamer/src/device_monitor.rs +++ b/gstreamer/src/device_monitor.rs @@ -58,6 +58,10 @@ pub trait DeviceMonitorExtManual: 'static { #[doc(alias = "gst_device_monitor_remove_filter")] fn remove_filter(&self, filter_id: DeviceMonitorFilterId) -> Result<(), glib::error::BoolError>; + + #[doc(alias = "gst_device_monitor_get_devices")] + #[doc(alias = "get_devices")] + fn devices(&self) -> glib::List; } impl> DeviceMonitorExtManual for O { @@ -95,4 +99,12 @@ impl> DeviceMonitorExtManual for O { ) } } + + fn devices(&self) -> glib::List { + unsafe { + FromGlibPtrContainer::from_glib_full(ffi::gst_device_monitor_get_devices( + self.as_ref().to_glib_none().0, + )) + } + } } diff --git a/gstreamer/src/device_provider.rs b/gstreamer/src/device_provider.rs index 5743712d9..6a3f4dfc0 100644 --- a/gstreamer/src/device_provider.rs +++ b/gstreamer/src/device_provider.rs @@ -36,6 +36,10 @@ pub trait DeviceProviderExtManual: 'static { #[doc(alias = "get_metadata")] #[doc(alias = "gst_device_provider_class_get_metadata")] fn metadata<'a>(&self, key: &str) -> Option<&'a str>; + + #[doc(alias = "gst_device_provider_get_devices")] + #[doc(alias = "get_devices")] + fn devices(&self) -> glib::List; } impl> DeviceProviderExtManual for O { @@ -53,4 +57,12 @@ impl> DeviceProviderExtManual for O { } } } + + fn devices(&self) -> glib::List { + unsafe { + FromGlibPtrContainer::from_glib_full(ffi::gst_device_provider_get_devices( + self.as_ref().to_glib_none().0, + )) + } + } } diff --git a/gstreamer/src/device_provider_factory.rs b/gstreamer/src/device_provider_factory.rs new file mode 100644 index 000000000..2e1809c21 --- /dev/null +++ b/gstreamer/src/device_provider_factory.rs @@ -0,0 +1,16 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::DeviceProviderFactory; +use glib::translate::*; + +impl DeviceProviderFactory { + #[doc(alias = "gst_device_provider_factory_list_get_device_providers")] + pub fn factories(minrank: crate::Rank) -> glib::List { + assert_initialized_main_thread!(); + unsafe { + FromGlibPtrContainer::from_glib_full( + ffi::gst_device_provider_factory_list_get_device_providers(minrank.into_glib()), + ) + } + } +} diff --git a/gstreamer/src/element_factory.rs b/gstreamer/src/element_factory.rs index e4885227e..95554c74b 100644 --- a/gstreamer/src/element_factory.rs +++ b/gstreamer/src/element_factory.rs @@ -3,10 +3,11 @@ #[cfg(any(feature = "v1_20", feature = "dox"))] use crate::Element; use crate::ElementFactory; +use crate::Rank; +use crate::StaticPadTemplate; #[cfg(any(feature = "v1_20", feature = "dox"))] use glib::prelude::*; -#[cfg(any(feature = "v1_20", feature = "dox"))] use glib::translate::*; impl ElementFactory { @@ -62,4 +63,38 @@ impl ElementFactory { .ok_or_else(|| glib::bool_error!("Failed to create element from factory name")) } } + + #[doc(alias = "gst_element_factory_get_static_pad_templates")] + #[doc(alias = "get_static_pad_templates")] + pub fn static_pad_templates(&self) -> glib::List { + unsafe { + glib::List::from_glib_none_static(ffi::gst_element_factory_get_static_pad_templates( + self.to_glib_none().0, + ) as *mut _) + } + } + + #[doc(alias = "gst_element_factory_list_is_type")] + pub fn has_type(&self, type_: crate::ElementFactoryType) -> bool { + unsafe { + from_glib(ffi::gst_element_factory_list_is_type( + self.to_glib_none().0, + type_.into_glib(), + )) + } + } + + #[doc(alias = "gst_element_factory_list_get_elements")] + pub fn factories_with_type( + type_: crate::ElementFactoryType, + minrank: Rank, + ) -> glib::List { + assert_initialized_main_thread!(); + unsafe { + FromGlibPtrContainer::from_glib_full(ffi::gst_element_factory_list_get_elements( + type_.into_glib(), + minrank.into_glib(), + )) + } + } } diff --git a/gstreamer/src/element_factory_list_type.rs b/gstreamer/src/element_factory_type.rs similarity index 95% rename from gstreamer/src/element_factory_list_type.rs rename to gstreamer/src/element_factory_type.rs index 3dfdf25c4..e1d655415 100644 --- a/gstreamer/src/element_factory_list_type.rs +++ b/gstreamer/src/element_factory_type.rs @@ -5,7 +5,7 @@ use glib::translate::*; bitflags! { #[doc(alias = "GstElementFactoryListType")] - pub struct ElementFactoryListType: u64 { + pub struct ElementFactoryType: u64 { #[doc(alias = "GST_ELEMENT_FACTORY_TYPE_DECODER")] const DECODER = ffi::GST_ELEMENT_FACTORY_TYPE_DECODER as u64; #[doc(alias = "GST_ELEMENT_FACTORY_TYPE_ENCODER")] @@ -57,7 +57,7 @@ bitflags! { } #[doc(hidden)] -impl IntoGlib for ElementFactoryListType { +impl IntoGlib for ElementFactoryType { type GlibType = ffi::GstElementFactoryListType; fn into_glib(self) -> ffi::GstElementFactoryListType { @@ -66,9 +66,9 @@ impl IntoGlib for ElementFactoryListType { } #[doc(hidden)] -impl FromGlib for ElementFactoryListType { - unsafe fn from_glib(value: ffi::GstElementFactoryListType) -> ElementFactoryListType { +impl FromGlib for ElementFactoryType { + unsafe fn from_glib(value: ffi::GstElementFactoryListType) -> ElementFactoryType { skip_assert_initialized!(); - ElementFactoryListType::from_bits_truncate(value) + ElementFactoryType::from_bits_truncate(value) } } diff --git a/gstreamer/src/functions.rs b/gstreamer/src/functions.rs index f7dbd2438..136783441 100644 --- a/gstreamer/src/functions.rs +++ b/gstreamer/src/functions.rs @@ -10,6 +10,9 @@ use crate::Element; use crate::Object; use crate::ParseContext; use crate::ParseFlags; +#[cfg(any(feature = "v1_18", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] +use crate::Tracer; pub fn parse_bin_from_description_with_name( bin_description: &str, @@ -190,6 +193,14 @@ pub fn type_is_plugin_api(type_: glib::types::Type) -> Option glib::List { + assert_initialized_main_thread!(); + unsafe { FromGlibPtrContainer::from_glib_full(ffi::gst_tracing_get_active_tracers()) } +} + #[cfg(test)] mod tests { use super::*; diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 10964fd4a..7b399e6c9 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -142,10 +142,11 @@ mod pipeline; mod allocation_params; pub use self::allocation_params::AllocationParams; -mod element_factory_list_type; -pub use element_factory_list_type::*; +mod element_factory_type; +pub use element_factory_type::*; mod tracer; +mod tracer_factory; // OS dependent Bus extensions (also import the other platform mod for doc) #[cfg(any(all(unix, feature = "v1_14"), feature = "dox"))] @@ -164,6 +165,7 @@ mod date_time; mod date_time_serde; mod device_monitor; mod device_provider; +mod device_provider_factory; mod enums; pub use crate::enums::MessageType; mod ghost_pad; @@ -171,6 +173,7 @@ mod gobject; mod iterator; mod object; mod pad; +mod registry; pub use crate::pad::PadBuilder; mod control_binding; mod control_source; @@ -204,6 +207,7 @@ pub mod stream_collection; mod typefind; pub use crate::typefind::*; +mod typefind_factory; pub mod format; pub use crate::format::{ diff --git a/gstreamer/src/registry.rs b/gstreamer/src/registry.rs new file mode 100644 index 000000000..e3bd90c9d --- /dev/null +++ b/gstreamer/src/registry.rs @@ -0,0 +1,97 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::Plugin; +use crate::PluginFeature; +use crate::Registry; + +use glib::translate::*; + +impl Registry { + #[doc(alias = "gst_registry_feature_filter")] + pub fn features_filtered bool>( + &self, + filter: P, + first: bool, + ) -> glib::List { + let filter_data: P = filter; + unsafe extern "C" fn filter_func bool>( + feature: *mut ffi::GstPluginFeature, + user_data: glib::ffi::gpointer, + ) -> glib::ffi::gboolean { + let feature = from_glib_borrow(feature); + let callback: *mut P = user_data as *const _ as usize as *mut P; + let res = (*callback)(&feature); + res.into_glib() + } + let filter = Some(filter_func::

as _); + let super_callback0: &P = &filter_data; + unsafe { + FromGlibPtrContainer::from_glib_full(ffi::gst_registry_feature_filter( + self.to_glib_none().0, + filter, + first.into_glib(), + super_callback0 as *const _ as usize as *mut _, + )) + } + } + + #[doc(alias = "gst_registry_get_feature_list")] + #[doc(alias = "get_feature_list")] + pub fn features(&self, type_: glib::types::Type) -> glib::List { + unsafe { + FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_feature_list( + self.to_glib_none().0, + type_.into_glib(), + )) + } + } + + #[doc(alias = "gst_registry_get_feature_list_by_plugin")] + #[doc(alias = "get_feature_list_by_plugin")] + pub fn features_by_plugin(&self, name: &str) -> glib::List { + unsafe { + FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_feature_list_by_plugin( + self.to_glib_none().0, + name.to_glib_none().0, + )) + } + } + + #[doc(alias = "gst_registry_get_plugin_list")] + #[doc(alias = "get_plugin_list")] + pub fn plugins(&self) -> glib::List { + unsafe { + FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_plugin_list( + self.to_glib_none().0, + )) + } + } + + #[doc(alias = "gst_registry_plugin_filter")] + pub fn plugins_filtered bool>( + &self, + filter: P, + first: bool, + ) -> glib::List { + let filter_data: P = filter; + unsafe extern "C" fn filter_func bool>( + plugin: *mut ffi::GstPlugin, + user_data: glib::ffi::gpointer, + ) -> glib::ffi::gboolean { + let plugin = from_glib_borrow(plugin); + let callback: *mut P = user_data as *const _ as usize as *mut P; + let res = (*callback)(&plugin); + res.into_glib() + } + let filter = Some(filter_func::

as _); + let super_callback0: &P = &filter_data; + unsafe { + FromGlibPtrContainer::from_glib_full(ffi::gst_registry_plugin_filter( + self.to_glib_none().0, + filter, + first.into_glib(), + super_callback0 as *const _ as usize as *mut _, + )) + } + } +} diff --git a/gstreamer/src/tracer_factory.rs b/gstreamer/src/tracer_factory.rs new file mode 100644 index 000000000..53a5f0521 --- /dev/null +++ b/gstreamer/src/tracer_factory.rs @@ -0,0 +1,18 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::TracerFactory; + +#[cfg(any(feature = "v1_14", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] +use glib::translate::*; + +impl TracerFactory { + #[cfg(any(feature = "v1_14", feature = "dox"))] + #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] + #[doc(alias = "gst_tracer_factory_get_list")] + #[doc(alias = "get_list")] + pub fn factories() -> glib::List { + assert_initialized_main_thread!(); + unsafe { FromGlibPtrContainer::from_glib_full(ffi::gst_tracer_factory_get_list()) } + } +} diff --git a/gstreamer/src/typefind.rs b/gstreamer/src/typefind.rs index da7ffab83..ab09b86ab 100644 --- a/gstreamer/src/typefind.rs +++ b/gstreamer/src/typefind.rs @@ -172,7 +172,7 @@ impl> SliceTypeFind { } pub fn run(&mut self) { - let factories = TypeFindFactory::list(); + let factories = TypeFindFactory::factories(); for factory in factories { factory.call_function(self); @@ -247,9 +247,7 @@ mod tests { fn test_typefind_call_function() { crate::init().unwrap(); - let xml_factory = TypeFindFactory::list() - .iter() - .cloned() + let xml_factory = TypeFindFactory::factories() .find(|f| { f.caps() .map(|c| { diff --git a/gstreamer/src/typefind_factory.rs b/gstreamer/src/typefind_factory.rs new file mode 100644 index 000000000..a7c950a67 --- /dev/null +++ b/gstreamer/src/typefind_factory.rs @@ -0,0 +1,14 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::TypeFindFactory; + +use glib::translate::*; + +impl TypeFindFactory { + #[doc(alias = "gst_type_find_factory_get_list")] + #[doc(alias = "get_list")] + pub fn factories() -> glib::List { + assert_initialized_main_thread!(); + unsafe { FromGlibPtrContainer::from_glib_full(ffi::gst_type_find_factory_get_list()) } + } +}