From 6403c06990403453586f5db855e22aec9f5897e0 Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Sat, 11 May 2019 13:13:33 +0300 Subject: [PATCH] Add API for setting/getting object flags Implemented for Object, Pipeline, Bin, Element, Plugin. Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/104 --- Gir_Gst.toml | 5 + gstreamer/src/auto/flags.rs | 253 ++++++++++++++++++++++++++++++++ gstreamer/src/auto/mod.rs | 5 + gstreamer/src/auto/versions.txt | 2 +- gstreamer/src/element.rs | 21 +++ gstreamer/src/object.rs | 24 ++- gstreamer/src/pad.rs | 21 +++ gstreamer/src/pipeline.rs | 43 ++++++ gstreamer/src/plugin.rs | 16 ++ 9 files changed, 388 insertions(+), 2 deletions(-) create mode 100644 gstreamer/src/pipeline.rs diff --git a/Gir_Gst.toml b/Gir_Gst.toml index 84a9e4e26..61815dc5b 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -54,6 +54,11 @@ generate = [ "Gst.TocSetter", "Gst.ClockType", "Gst.ElementFlags", + "Gst.ObjectFlags", + "Gst.PadFlags", + "Gst.BinFlags", + "Gst.PipelineFlags", + "Gst.PluginFlags", "Gst.PadLinkCheck", "Gst.DebugLevel", "Gst.DebugColorFlags", diff --git a/gstreamer/src/auto/flags.rs b/gstreamer/src/auto/flags.rs index 672d79f72..f30648030 100644 --- a/gstreamer/src/auto/flags.rs +++ b/gstreamer/src/auto/flags.rs @@ -12,6 +12,55 @@ use glib::value::Value; use gobject_sys; use gst_sys; +bitflags! { + pub struct BinFlags: u32 { + const NO_RESYNC = 16384; + const STREAMS_AWARE = 32768; + const LAST = 524288; + } +} + +#[doc(hidden)] +impl ToGlib for BinFlags { + type GlibType = gst_sys::GstBinFlags; + + fn to_glib(&self) -> gst_sys::GstBinFlags { + self.bits() + } +} + +#[doc(hidden)] +impl FromGlib for BinFlags { + fn from_glib(value: gst_sys::GstBinFlags) -> BinFlags { + skip_assert_initialized!(); + BinFlags::from_bits_truncate(value) + } +} + +impl StaticType for BinFlags { + fn static_type() -> Type { + unsafe { from_glib(gst_sys::gst_bin_flags_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for BinFlags { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for BinFlags { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_sys::g_value_get_flags(value.to_glib_none().0)) + } +} + +impl SetValue for BinFlags { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_sys::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib()) + } +} + bitflags! { pub struct BufferCopyFlags: u32 { const NONE = 0; @@ -347,6 +396,114 @@ impl SetValue for ElementFlags { } } +bitflags! { + pub struct ObjectFlags: u32 { + const MAY_BE_LEAKED = 1; + const LAST = 16; + } +} + +#[doc(hidden)] +impl ToGlib for ObjectFlags { + type GlibType = gst_sys::GstObjectFlags; + + fn to_glib(&self) -> gst_sys::GstObjectFlags { + self.bits() + } +} + +#[doc(hidden)] +impl FromGlib for ObjectFlags { + fn from_glib(value: gst_sys::GstObjectFlags) -> ObjectFlags { + skip_assert_initialized!(); + ObjectFlags::from_bits_truncate(value) + } +} + +impl StaticType for ObjectFlags { + fn static_type() -> Type { + unsafe { from_glib(gst_sys::gst_object_flags_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for ObjectFlags { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for ObjectFlags { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_sys::g_value_get_flags(value.to_glib_none().0)) + } +} + +impl SetValue for ObjectFlags { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_sys::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib()) + } +} + +bitflags! { + pub struct PadFlags: u32 { + const BLOCKED = 16; + const FLUSHING = 32; + const EOS = 64; + const BLOCKING = 128; + const NEED_PARENT = 256; + const NEED_RECONFIGURE = 512; + const PENDING_EVENTS = 1024; + const FIXED_CAPS = 2048; + const PROXY_CAPS = 4096; + const PROXY_ALLOCATION = 8192; + const PROXY_SCHEDULING = 16384; + const ACCEPT_INTERSECT = 32768; + const ACCEPT_TEMPLATE = 65536; + const LAST = 1048576; + } +} + +#[doc(hidden)] +impl ToGlib for PadFlags { + type GlibType = gst_sys::GstPadFlags; + + fn to_glib(&self) -> gst_sys::GstPadFlags { + self.bits() + } +} + +#[doc(hidden)] +impl FromGlib for PadFlags { + fn from_glib(value: gst_sys::GstPadFlags) -> PadFlags { + skip_assert_initialized!(); + PadFlags::from_bits_truncate(value) + } +} + +impl StaticType for PadFlags { + fn static_type() -> Type { + unsafe { from_glib(gst_sys::gst_pad_flags_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for PadFlags { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for PadFlags { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_sys::g_value_get_flags(value.to_glib_none().0)) + } +} + +impl SetValue for PadFlags { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_sys::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib()) + } +} + bitflags! { pub struct PadLinkCheck: u32 { const NOTHING = 0; @@ -517,6 +674,54 @@ impl SetValue for ParseFlags { } } +bitflags! { + pub struct PipelineFlags: u32 { + const FIXED_CLOCK = 524288; + const LAST = 8388608; + } +} + +#[doc(hidden)] +impl ToGlib for PipelineFlags { + type GlibType = gst_sys::GstPipelineFlags; + + fn to_glib(&self) -> gst_sys::GstPipelineFlags { + self.bits() + } +} + +#[doc(hidden)] +impl FromGlib for PipelineFlags { + fn from_glib(value: gst_sys::GstPipelineFlags) -> PipelineFlags { + skip_assert_initialized!(); + PipelineFlags::from_bits_truncate(value) + } +} + +impl StaticType for PipelineFlags { + fn static_type() -> Type { + unsafe { from_glib(gst_sys::gst_pipeline_flags_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for PipelineFlags { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for PipelineFlags { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_sys::g_value_get_flags(value.to_glib_none().0)) + } +} + +impl SetValue for PipelineFlags { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_sys::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib()) + } +} + bitflags! { pub struct PluginDependencyFlags: u32 { const NONE = 0; @@ -569,6 +774,54 @@ impl SetValue for PluginDependencyFlags { } } +bitflags! { + pub struct PluginFlags: u32 { + const CACHED = 16; + const BLACKLISTED = 32; + } +} + +#[doc(hidden)] +impl ToGlib for PluginFlags { + type GlibType = gst_sys::GstPluginFlags; + + fn to_glib(&self) -> gst_sys::GstPluginFlags { + self.bits() + } +} + +#[doc(hidden)] +impl FromGlib for PluginFlags { + fn from_glib(value: gst_sys::GstPluginFlags) -> PluginFlags { + skip_assert_initialized!(); + PluginFlags::from_bits_truncate(value) + } +} + +impl StaticType for PluginFlags { + fn static_type() -> Type { + unsafe { from_glib(gst_sys::gst_plugin_flags_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for PluginFlags { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for PluginFlags { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_sys::g_value_get_flags(value.to_glib_none().0)) + } +} + +impl SetValue for PluginFlags { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_sys::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib()) + } +} + bitflags! { pub struct SchedulingFlags: u32 { const SEEKABLE = 1; diff --git a/gstreamer/src/auto/mod.rs b/gstreamer/src/auto/mod.rs index 697c5e033..2c8f4f7a4 100644 --- a/gstreamer/src/auto/mod.rs +++ b/gstreamer/src/auto/mod.rs @@ -156,16 +156,21 @@ pub use self::enums::URIError; pub use self::enums::URIType; mod flags; +pub use self::flags::BinFlags; pub use self::flags::BufferCopyFlags; pub use self::flags::BufferFlags; pub use self::flags::BufferPoolAcquireFlags; pub use self::flags::DebugColorFlags; pub use self::flags::DebugGraphDetails; pub use self::flags::ElementFlags; +pub use self::flags::ObjectFlags; +pub use self::flags::PadFlags; pub use self::flags::PadLinkCheck; pub use self::flags::PadProbeType; pub use self::flags::ParseFlags; +pub use self::flags::PipelineFlags; pub use self::flags::PluginDependencyFlags; +pub use self::flags::PluginFlags; pub use self::flags::SchedulingFlags; pub use self::flags::SeekFlags; pub use self::flags::SegmentFlags; diff --git a/gstreamer/src/auto/versions.txt b/gstreamer/src/auto/versions.txt index a9e0ccc5d..90eaf67a0 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 @ 58cffd4) +Generated by gir (https://github.com/gtk-rs/gir @ 7dc9574) from gir-files (https://github.com/gtk-rs/gir-files @ ???) diff --git a/gstreamer/src/element.rs b/gstreamer/src/element.rs index ff4369066..df5e36ca1 100644 --- a/gstreamer/src/element.rs +++ b/gstreamer/src/element.rs @@ -20,6 +20,7 @@ use glib::translate::{ }; use miniobject::MiniObject; use ClockTime; +use ElementFlags; use Event; use Format; use FormattedValue; @@ -138,6 +139,10 @@ pub trait ElementExtManual: 'static { line: u32, ); + fn set_element_flags(&self, flags: ElementFlags); + + fn get_element_flags(&self) -> ElementFlags; + #[cfg(any(feature = "v1_10", feature = "dox"))] #[allow(clippy::too_many_arguments)] fn message_full_with_details( @@ -308,6 +313,22 @@ impl> ElementExtManual for O { self.get_element_class().get_pad_template_list() } + fn set_element_flags(&self, flags: ElementFlags) { + unsafe { + let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; + let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); + (*ptr).flags |= flags.to_glib(); + } + } + + fn get_element_flags(&self) -> ElementFlags { + unsafe { + let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; + let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); + from_glib((*ptr).flags) + } + } + fn message_full( &self, type_: ElementMessageType, diff --git a/gstreamer/src/object.rs b/gstreamer/src/object.rs index 16c6e6564..bdd93dfa6 100644 --- a/gstreamer/src/object.rs +++ b/gstreamer/src/object.rs @@ -9,11 +9,13 @@ use glib; use glib::object::{Cast, ObjectExt}; use glib::signal::SignalHandlerId; -use glib::translate::{from_glib_borrow, from_glib_none, ToGlibPtr}; +use glib::translate::*; use glib::IsA; use gobject_sys; +use ObjectFlags; + pub trait GstObjectExtManual: 'static { fn connect_deep_notify< 'a, @@ -24,6 +26,10 @@ pub trait GstObjectExtManual: 'static { name: P, f: F, ) -> SignalHandlerId; + + fn set_object_flags(&self, flags: ObjectFlags); + + fn get_object_flags(&self) -> ObjectFlags; } impl> GstObjectExtManual for O { @@ -61,6 +67,22 @@ impl> GstObjectExtManual for O { }) .unwrap() } + + fn set_object_flags(&self, flags: ObjectFlags) { + unsafe { + let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; + let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); + (*ptr).flags |= flags.to_glib(); + } + } + + fn get_object_flags(&self) -> ObjectFlags { + unsafe { + let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; + let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); + from_glib((*ptr).flags) + } + } } #[cfg(test)] diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index 89086572d..45774a278 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -7,6 +7,7 @@ // except according to those terms. use miniobject::MiniObject; +use BinFlags; use Buffer; use BufferList; use Event; @@ -266,6 +267,10 @@ pub trait PadExtManual: 'static { ); fn store_sticky_event(&self, event: &Event) -> Result; + + fn set_bin_flags(&self, flags: BinFlags); + + fn get_bin_flags(&self) -> BinFlags; } impl> PadExtManual for O { @@ -995,6 +1000,22 @@ impl> PadExtManual for O { }; ret.into_result() } + + fn set_bin_flags(&self, flags: BinFlags) { + unsafe { + let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; + let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); + (*ptr).flags |= flags.to_glib(); + } + } + + fn get_bin_flags(&self) -> BinFlags { + unsafe { + let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; + let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); + from_glib((*ptr).flags) + } + } } unsafe extern "C" fn trampoline_pad_probe< diff --git a/gstreamer/src/pipeline.rs b/gstreamer/src/pipeline.rs new file mode 100644 index 000000000..2a0585202 --- /dev/null +++ b/gstreamer/src/pipeline.rs @@ -0,0 +1,43 @@ +// Copyright (c) 2019 Vivia Nikolaidou +// +// 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 glib; +use glib::object::{Cast, ObjectExt}; +use glib::signal::SignalHandlerId; +use glib::translate::*; +use glib::IsA; + +use gobject_sys; + +use PipelineFlags; + +pub trait GstPipelineExtManual: 'static { + fn set_pipeline_flags(&self, flags: PipelineFlags); + + fn get_pipeline_flags(&self) -> PipelineFlags; +} + +impl> GstPipelineExtManual for O { + fn set_pipeline_flags(&self, flags: PipelineFlags) { + unsafe { + let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; + let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); + (*ptr).flags |= flags.to_glib(); + } + } + + fn get_pipeline_flags(&self) -> PipelineFlags { + unsafe { + let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; + let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); + from_glib((*ptr).flags) + } + } +} + + diff --git a/gstreamer/src/plugin.rs b/gstreamer/src/plugin.rs index 3908766bd..db0ca7c54 100644 --- a/gstreamer/src/plugin.rs +++ b/gstreamer/src/plugin.rs @@ -8,10 +8,12 @@ use gst_sys; use Plugin; +use PluginFlags; use Structure; use StructureRef; use glib::translate::*; +use glib::IsA; impl Plugin { pub fn get_cache_data(&self) -> Option<&StructureRef> { @@ -31,3 +33,17 @@ impl Plugin { } } } + +pub trait GstPluginExtManual: 'static { + fn get_plugin_flags(&self) -> PluginFlags; +} + +impl> GstPluginExtManual for O { + fn get_plugin_flags(&self) -> PluginFlags { + unsafe { + let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; + let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); + from_glib((*ptr).flags) + } + } +}