From 5108c941ed4f9d9f71c8ffc0f31f9a5442577f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 17 Dec 2017 14:26:17 +0200 Subject: [PATCH] Various nullability fixes to plugin bindings, and add add_dependency() API Also fix structure ownership for the cache data API --- Gir_Gst.toml | 56 ++++++++++++++++++++++++++++++++++++ gir-files/Gst-1.0.gir | 12 ++++++-- gstreamer/src/auto/flags.rs | 51 ++++++++++++++++++++++++++++++++ gstreamer/src/auto/mod.rs | 1 + gstreamer/src/auto/plugin.rs | 53 ++++++++++++++-------------------- gstreamer/src/lib.rs | 2 ++ gstreamer/src/plugin.rs | 33 +++++++++++++++++++++ 7 files changed, 174 insertions(+), 34 deletions(-) create mode 100644 gstreamer/src/plugin.rs diff --git a/Gir_Gst.toml b/Gir_Gst.toml index 360b3fe8b..0621bbac7 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -71,6 +71,7 @@ generate = [ "Gst.DebugGraphDetails", "Gst.ParseFlags", "Gst.TaskState", + "Gst.PluginDependencyFlags", ] manual = [ @@ -594,6 +595,61 @@ name = "Gst.Plugin" status = "generate" trait = false + [[object.function]] + name = "list_free" + # useless and unsafe + ignore = true + + [[object.function]] + name = "set_cache_data" + # pass by value + ignore = true + + [[object.function]] + name = "get_cache_data" + # structure ref + ignore = true + + [[object.function]] + name = "get_description" + [object.function.return] + nullable = false + + [[object.function]] + name = "get_name" + [object.function.return] + nullable = false + + [[object.function]] + name = "get_license" + [object.function.return] + nullable = false + + [[object.function]] + name = "get_origin" + [object.function.return] + nullable = false + + [[object.function]] + name = "get_package" + [object.function.return] + nullable = false + + [[object.function]] + name = "get_release_date_string" + [object.function.return] + nullable = false + + [[object.function]] + name = "get_source" + [object.function.return] + nullable = false + + [[object.function]] + name = "get_version" + [object.function.return] + nullable = false + [[object]] name = "Gst.PluginFeature" status = "generate" diff --git a/gir-files/Gst-1.0.gir b/gir-files/Gst-1.0.gir index 99537d013..207d0b51a 100644 --- a/gir-files/Gst-1.0.gir +++ b/gir-files/Gst-1.0.gir @@ -29136,7 +29136,9 @@ codec libraries are currently installed. or %NULL. Environment variable names may be followed by a path component which will be added to the content of the environment variable, e.g. "HOME/.mystuff/plugins". - + + + allow-none="1"> %NULL-terminated array of directories/paths where dependent files may be, or %NULL. - + + + depending on @flags) to be used in combination with the paths from @paths and/or the paths extracted from the environment variables in @env_vars, or %NULL. - + + + optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE diff --git a/gstreamer/src/auto/flags.rs b/gstreamer/src/auto/flags.rs index fcfc72c0c..da419d076 100644 --- a/gstreamer/src/auto/flags.rs +++ b/gstreamer/src/auto/flags.rs @@ -460,6 +460,57 @@ impl SetValue for ParseFlags { } } +bitflags! { + pub struct PluginDependencyFlags: u32 { + const NONE = 0; + const RECURSE = 1; + const PATHS_ARE_DEFAULT_ONLY = 2; + const FILE_NAME_IS_SUFFIX = 4; + const FILE_NAME_IS_PREFIX = 8; + } +} + +#[doc(hidden)] +impl ToGlib for PluginDependencyFlags { + type GlibType = ffi::GstPluginDependencyFlags; + + fn to_glib(&self) -> ffi::GstPluginDependencyFlags { + ffi::GstPluginDependencyFlags::from_bits_truncate(self.bits()) + } +} + +#[doc(hidden)] +impl FromGlib for PluginDependencyFlags { + fn from_glib(value: ffi::GstPluginDependencyFlags) -> PluginDependencyFlags { + skip_assert_initialized!(); + PluginDependencyFlags::from_bits_truncate(value.bits()) + } +} + +impl StaticType for PluginDependencyFlags { + fn static_type() -> Type { + unsafe { from_glib(ffi::gst_plugin_dependency_flags_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for PluginDependencyFlags { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for PluginDependencyFlags { + unsafe fn from_value(value: &Value) -> Self { + from_glib(ffi::GstPluginDependencyFlags::from_bits_truncate(gobject_ffi::g_value_get_flags(value.to_glib_none().0))) + } +} + +impl SetValue for PluginDependencyFlags { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib().bits()) + } +} + bitflags! { pub struct SchedulingFlags: u32 { const SEEKABLE = 1; diff --git a/gstreamer/src/auto/mod.rs b/gstreamer/src/auto/mod.rs index d71092e6f..38905c3ce 100644 --- a/gstreamer/src/auto/mod.rs +++ b/gstreamer/src/auto/mod.rs @@ -151,6 +151,7 @@ pub use self::flags::ElementFlags; pub use self::flags::PadLinkCheck; pub use self::flags::PadProbeType; pub use self::flags::ParseFlags; +pub use self::flags::PluginDependencyFlags; pub use self::flags::SchedulingFlags; pub use self::flags::SeekFlags; pub use self::flags::SegmentFlags; diff --git a/gstreamer/src/auto/plugin.rs b/gstreamer/src/auto/plugin.rs index 42b2cfa57..0c9fe7fc4 100644 --- a/gstreamer/src/auto/plugin.rs +++ b/gstreamer/src/auto/plugin.rs @@ -3,7 +3,7 @@ use Error; use Object; -use Structure; +use PluginDependencyFlags; use ffi; use glib::translate::*; use glib_ffi; @@ -21,21 +21,25 @@ glib_wrapper! { } impl Plugin { - //pub fn add_dependency<'a, 'b, 'c, P: Into>, Q: Into>, R: Into>>(&self, env_vars: P, paths: Q, names: R, flags: /*Ignored*/PluginDependencyFlags) { - // unsafe { TODO: call ffi::gst_plugin_add_dependency() } - //} - - //pub fn add_dependency_simple<'a, 'b, 'c, P: Into>, Q: Into>, R: Into>>(&self, env_vars: P, paths: Q, names: R, flags: /*Ignored*/PluginDependencyFlags) { - // unsafe { TODO: call ffi::gst_plugin_add_dependency_simple() } - //} - - pub fn get_cache_data(&self) -> Option { + pub fn add_dependency(&self, env_vars: &[&str], paths: &[&str], names: &[&str], flags: PluginDependencyFlags) { unsafe { - from_glib_none(ffi::gst_plugin_get_cache_data(self.to_glib_none().0)) + ffi::gst_plugin_add_dependency(self.to_glib_none().0, env_vars.to_glib_none().0, paths.to_glib_none().0, names.to_glib_none().0, flags.to_glib()); } } - pub fn get_description(&self) -> Option { + pub fn add_dependency_simple<'a, 'b, 'c, P: Into>, Q: Into>, R: Into>>(&self, env_vars: P, paths: Q, names: R, flags: PluginDependencyFlags) { + let env_vars = env_vars.into(); + let env_vars = env_vars.to_glib_none(); + let paths = paths.into(); + let paths = paths.to_glib_none(); + let names = names.into(); + let names = names.to_glib_none(); + unsafe { + ffi::gst_plugin_add_dependency_simple(self.to_glib_none().0, env_vars.0, paths.0, names.0, flags.to_glib()); + } + } + + pub fn get_description(&self) -> String { unsafe { from_glib_none(ffi::gst_plugin_get_description(self.to_glib_none().0)) } @@ -47,37 +51,37 @@ impl Plugin { } } - pub fn get_license(&self) -> Option { + pub fn get_license(&self) -> String { unsafe { from_glib_none(ffi::gst_plugin_get_license(self.to_glib_none().0)) } } - pub fn get_origin(&self) -> Option { + pub fn get_origin(&self) -> String { unsafe { from_glib_none(ffi::gst_plugin_get_origin(self.to_glib_none().0)) } } - pub fn get_package(&self) -> Option { + pub fn get_package(&self) -> String { unsafe { from_glib_none(ffi::gst_plugin_get_package(self.to_glib_none().0)) } } - pub fn get_release_date_string(&self) -> Option { + pub fn get_release_date_string(&self) -> String { unsafe { from_glib_none(ffi::gst_plugin_get_release_date_string(self.to_glib_none().0)) } } - pub fn get_source(&self) -> Option { + pub fn get_source(&self) -> String { unsafe { from_glib_none(ffi::gst_plugin_get_source(self.to_glib_none().0)) } } - pub fn get_version(&self) -> Option { + pub fn get_version(&self) -> String { unsafe { from_glib_none(ffi::gst_plugin_get_version(self.to_glib_none().0)) } @@ -95,19 +99,6 @@ impl Plugin { } } - pub fn set_cache_data(&self, cache_data: &mut Structure) { - unsafe { - ffi::gst_plugin_set_cache_data(self.to_glib_none().0, cache_data.to_glib_full()); - } - } - - pub fn list_free(list: &[Plugin]) { - assert_initialized_main_thread!(); - unsafe { - ffi::gst_plugin_list_free(list.to_glib_full()); - } - } - pub fn load_by_name(name: &str) -> Option { assert_initialized_main_thread!(); unsafe { diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 4e23b4087..164f100ae 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -124,6 +124,8 @@ pub use enums::{ClockError, ClockSuccess, FlowError, FlowSuccess, PadLinkError, StateChangeError, StateChangeSuccess}; pub use clock_time::ClockTime; +mod plugin; + pub mod format; pub use format::{FormattedValue, GenericFormattedValue, SpecificFormattedValue}; diff --git a/gstreamer/src/plugin.rs b/gstreamer/src/plugin.rs new file mode 100644 index 000000000..7b72f64e6 --- /dev/null +++ b/gstreamer/src/plugin.rs @@ -0,0 +1,33 @@ +// Copyright (C) 2017 Sebastian Dröge +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use Plugin; +use Structure; +use StructureRef; +use ffi; + +use glib::translate::*; + +impl Plugin { + pub fn get_cache_data(&self) -> Option<&StructureRef> { + unsafe { + let cache_data = ffi::gst_plugin_get_cache_data(self.to_glib_none().0); + if cache_data.is_null() { + None + } else { + Some(StructureRef::from_glib_borrow(cache_data)) + } + } + } + + pub fn set_cache_data(&self, cache_data: Structure) { + unsafe { + ffi::gst_plugin_set_cache_data(self.to_glib_none().0, cache_data.into_ptr()); + } + } +}