Add API for setting/getting object flags

Implemented for Object, Pipeline, Bin, Element, Plugin.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/104
This commit is contained in:
Vivia Nikolaidou 2019-05-11 13:13:33 +03:00
parent 9067b500c8
commit 6403c06990
9 changed files with 388 additions and 2 deletions

View file

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

View file

@ -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<gst_sys::GstBinFlags> 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<Self> {
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<gst_sys::GstObjectFlags> 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<Self> {
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<gst_sys::GstPadFlags> 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<Self> {
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<gst_sys::GstPipelineFlags> 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<Self> {
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<gst_sys::GstPluginFlags> 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<Self> {
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;

View file

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

View file

@ -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 @ ???)

View file

@ -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<T: ::MessageErrorDomain>(
@ -308,6 +313,22 @@ impl<O: IsA<Element>> 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<T: ::MessageErrorDomain>(
&self,
type_: ElementMessageType,

View file

@ -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<O: IsA<::Object>> GstObjectExtManual for O {
@ -61,6 +67,22 @@ impl<O: IsA<::Object>> 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)]

View file

@ -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<FlowSuccess, FlowError>;
fn set_bin_flags(&self, flags: BinFlags);
fn get_bin_flags(&self) -> BinFlags;
}
impl<O: IsA<Pad>> PadExtManual for O {
@ -995,6 +1000,22 @@ impl<O: IsA<Pad>> 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<

43
gstreamer/src/pipeline.rs Normal file
View file

@ -0,0 +1,43 @@
// Copyright (c) 2019 Vivia Nikolaidou <vivia@ahiru.eu>
//
// 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 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<O: IsA<::Pipeline>> 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)
}
}
}

View file

@ -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<O: IsA<::Plugin>> 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)
}
}
}