Various nullability fixes to plugin bindings, and add add_dependency() API

Also fix structure ownership for the cache data API
This commit is contained in:
Sebastian Dröge 2017-12-17 14:26:17 +02:00
parent 4b2fd0e593
commit 5108c941ed
7 changed files with 174 additions and 34 deletions

View file

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

View file

@ -29136,7 +29136,9 @@ codec libraries are currently installed.</doc>
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".</doc>
<type name="utf8" c:type="const gchar**"/>
<array c:type="gchar**">
<type name="utf8" c:type="gchar*"/>
</array>
</parameter>
<parameter name="paths"
transfer-ownership="none"
@ -29144,7 +29146,9 @@ codec libraries are currently installed.</doc>
allow-none="1">
<doc xml:space="preserve">%NULL-terminated array of directories/paths where dependent files
may be, or %NULL.</doc>
<type name="utf8" c:type="const gchar**"/>
<array c:type="gchar**">
<type name="utf8" c:type="gchar*"/>
</array>
</parameter>
<parameter name="names"
transfer-ownership="none"
@ -29154,7 +29158,9 @@ codec libraries are currently installed.</doc>
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.</doc>
<type name="utf8" c:type="const gchar**"/>
<array c:type="gchar**">
<type name="utf8" c:type="gchar*"/>
</array>
</parameter>
<parameter name="flags" transfer-ownership="none">
<doc xml:space="preserve">optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE</doc>

View file

@ -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<ffi::GstPluginDependencyFlags> 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<Self> {
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;

View file

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

View file

@ -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<Option<&'a str>>, Q: Into<Option<&'b str>>, R: Into<Option<&'c str>>>(&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<Option<&'a str>>, Q: Into<Option<&'b str>>, R: Into<Option<&'c str>>>(&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<Structure> {
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<String> {
pub fn add_dependency_simple<'a, 'b, 'c, P: Into<Option<&'a str>>, Q: Into<Option<&'b str>>, R: Into<Option<&'c str>>>(&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<String> {
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<String> {
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<String> {
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<String> {
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<String> {
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<String> {
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<Plugin> {
assert_initialized_main_thread!();
unsafe {

View file

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

33
gstreamer/src/plugin.rs Normal file
View file

@ -0,0 +1,33 @@
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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());
}
}
}