diff --git a/gst-plugin-audiofx/src/audioecho.rs b/gst-plugin-audiofx/src/audioecho.rs index da7687e2..815cfefb 100644 --- a/gst-plugin-audiofx/src/audioecho.rs +++ b/gst-plugin-audiofx/src/audioecho.rs @@ -14,6 +14,7 @@ use gst_base::prelude::*; use gst_audio; use gst_audio::prelude::*; +use gst_plugin::properties::*; use gst_plugin::object::*; use gst_plugin::element::*; use gst_plugin::base_transform::*; diff --git a/gst-plugin-simple/src/sink.rs b/gst-plugin-simple/src/sink.rs index dbceae3b..7bd329e1 100644 --- a/gst-plugin-simple/src/sink.rs +++ b/gst-plugin-simple/src/sink.rs @@ -17,6 +17,7 @@ use gst_base; use gst_base::prelude::*; use gst_plugin::object::*; +use gst_plugin::properties::*; use gst_plugin::element::*; use gst_plugin::base_sink::*; use gst_plugin::uri_handler::*; diff --git a/gst-plugin-simple/src/source.rs b/gst-plugin-simple/src/source.rs index b253f83d..33006242 100644 --- a/gst-plugin-simple/src/source.rs +++ b/gst-plugin-simple/src/source.rs @@ -19,6 +19,7 @@ use gst_base; use gst_base::prelude::*; use gst_plugin::object::*; +use gst_plugin::properties::*; use gst_plugin::element::*; use gst_plugin::base_src::*; use gst_plugin::uri_handler::*; diff --git a/gst-plugin/src/lib.rs b/gst-plugin/src/lib.rs index 76ed1e68..fe1b593e 100644 --- a/gst-plugin/src/lib.rs +++ b/gst-plugin/src/lib.rs @@ -67,6 +67,7 @@ pub mod adapter; pub mod plugin; pub mod bytes; +pub mod properties; #[macro_use] pub mod object; #[macro_use] diff --git a/gst-plugin/src/object.rs b/gst-plugin/src/object.rs index ad228ec3..96777136 100644 --- a/gst-plugin/src/object.rs +++ b/gst-plugin/src/object.rs @@ -20,6 +20,8 @@ use gobject_ffi; use glib; use glib::translate::*; +use properties::*; + pub trait ObjectImpl: Send + Sync + 'static { fn set_property(&self, _obj: &glib::Object, _id: u32, _value: &glib::Value) { unimplemented!() @@ -164,110 +166,7 @@ pub unsafe trait ObjectClass { pspecs.push(ptr::null_mut()); for property in properties { - match *property { - Property::Boolean(name, nick, description, default, mutability) => unsafe { - pspecs.push(gobject_ffi::g_param_spec_boolean( - name.to_glib_none().0, - nick.to_glib_none().0, - description.to_glib_none().0, - default.to_glib(), - mutability.into(), - )); - }, - Property::Int(name, nick, description, (min, max), default, mutability) => unsafe { - pspecs.push(gobject_ffi::g_param_spec_int( - name.to_glib_none().0, - nick.to_glib_none().0, - description.to_glib_none().0, - min, - max, - default, - mutability.into(), - )); - }, - Property::Int64(name, nick, description, (min, max), default, mutability) => unsafe { - pspecs.push(gobject_ffi::g_param_spec_int64( - name.to_glib_none().0, - nick.to_glib_none().0, - description.to_glib_none().0, - min, - max, - default, - mutability.into(), - )); - }, - Property::UInt(name, nick, description, (min, max), default, mutability) => unsafe { - pspecs.push(gobject_ffi::g_param_spec_uint( - name.to_glib_none().0, - nick.to_glib_none().0, - description.to_glib_none().0, - min, - max, - default, - mutability.into(), - )); - }, - Property::UInt64(name, nick, description, (min, max), default, mutability) => unsafe { - pspecs.push(gobject_ffi::g_param_spec_uint64( - name.to_glib_none().0, - nick.to_glib_none().0, - description.to_glib_none().0, - min, - max, - default, - mutability.into(), - )); - }, - Property::Float(name, nick, description, (min, max), default, mutability) => unsafe { - pspecs.push(gobject_ffi::g_param_spec_float( - name.to_glib_none().0, - nick.to_glib_none().0, - description.to_glib_none().0, - min, - max, - default, - mutability.into(), - )); - }, - Property::Double(name, nick, description, (min, max), default, mutability) => unsafe { - pspecs.push(gobject_ffi::g_param_spec_double( - name.to_glib_none().0, - nick.to_glib_none().0, - description.to_glib_none().0, - min, - max, - default, - mutability.into(), - )); - }, - Property::String(name, nick, description, default, mutability) => unsafe { - pspecs.push(gobject_ffi::g_param_spec_string( - name.to_glib_none().0, - nick.to_glib_none().0, - description.to_glib_none().0, - default.to_glib_none().0, - mutability.into(), - )); - }, - Property::Boxed(name, nick, description, type_, mutability) => unsafe { - pspecs.push(gobject_ffi::g_param_spec_boxed( - name.to_glib_none().0, - nick.to_glib_none().0, - description.to_glib_none().0, - type_.to_glib(), - mutability.into(), - )); - }, - Property::Object(name, nick, description, type_, mutability) => unsafe { - pspecs.push(gobject_ffi::g_param_spec_object( - name.to_glib_none().0, - nick.to_glib_none().0, - description.to_glib_none().0, - type_.to_glib(), - mutability.into(), - )); - }, - } + pspecs.push(property.into()); } unsafe { @@ -282,86 +181,6 @@ pub unsafe trait ObjectClass { unsafe impl ObjectClass for ClassStruct {} -#[derive(Clone, Copy, PartialEq, Eq, Debug)] -pub enum PropertyMutability { - Readable, - Writable, - ReadWrite, -} - -impl Into for PropertyMutability { - fn into(self) -> gobject_ffi::GParamFlags { - use self::PropertyMutability::*; - - match self { - Readable => gobject_ffi::G_PARAM_READABLE, - Writable => gobject_ffi::G_PARAM_WRITABLE, - ReadWrite => gobject_ffi::G_PARAM_READWRITE, - } - } -} - -pub enum Property<'a> { - Boolean(&'a str, &'a str, &'a str, bool, PropertyMutability), - Int( - &'a str, - &'a str, - &'a str, - (i32, i32), - i32, - PropertyMutability, - ), - Int64( - &'a str, - &'a str, - &'a str, - (i64, i64), - i64, - PropertyMutability, - ), - UInt( - &'a str, - &'a str, - &'a str, - (u32, u32), - u32, - PropertyMutability, - ), - UInt64( - &'a str, - &'a str, - &'a str, - (u64, u64), - u64, - PropertyMutability, - ), - Float( - &'a str, - &'a str, - &'a str, - (f32, f32), - f32, - PropertyMutability, - ), - Double( - &'a str, - &'a str, - &'a str, - (f64, f64), - f64, - PropertyMutability, - ), - String( - &'a str, - &'a str, - &'a str, - Option<&'a str>, - PropertyMutability, - ), - Boxed(&'a str, &'a str, &'a str, glib::Type, PropertyMutability), - Object(&'a str, &'a str, &'a str, glib::Type, PropertyMutability), -} - unsafe extern "C" fn class_init( klass: glib_ffi::gpointer, _klass_data: glib_ffi::gpointer, diff --git a/gst-plugin/src/properties.rs b/gst-plugin/src/properties.rs new file mode 100644 index 00000000..cc551ce5 --- /dev/null +++ b/gst-plugin/src/properties.rs @@ -0,0 +1,204 @@ +// 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 gobject_ffi; + +use glib; +use glib::translate::*; + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum PropertyMutability { + Readable, + Writable, + ReadWrite, +} + +impl Into for PropertyMutability { + fn into(self) -> gobject_ffi::GParamFlags { + use self::PropertyMutability::*; + + match self { + Readable => gobject_ffi::G_PARAM_READABLE, + Writable => gobject_ffi::G_PARAM_WRITABLE, + ReadWrite => gobject_ffi::G_PARAM_READWRITE, + } + } +} + +#[derive(Debug, Clone)] +pub enum Property<'a> { + Boolean(&'a str, &'a str, &'a str, bool, PropertyMutability), + Int( + &'a str, + &'a str, + &'a str, + (i32, i32), + i32, + PropertyMutability, + ), + Int64( + &'a str, + &'a str, + &'a str, + (i64, i64), + i64, + PropertyMutability, + ), + UInt( + &'a str, + &'a str, + &'a str, + (u32, u32), + u32, + PropertyMutability, + ), + UInt64( + &'a str, + &'a str, + &'a str, + (u64, u64), + u64, + PropertyMutability, + ), + Float( + &'a str, + &'a str, + &'a str, + (f32, f32), + f32, + PropertyMutability, + ), + Double( + &'a str, + &'a str, + &'a str, + (f64, f64), + f64, + PropertyMutability, + ), + String( + &'a str, + &'a str, + &'a str, + Option<&'a str>, + PropertyMutability, + ), + Boxed(&'a str, &'a str, &'a str, glib::Type, PropertyMutability), + Object(&'a str, &'a str, &'a str, glib::Type, PropertyMutability), +} + +impl<'a> Into<*mut gobject_ffi::GParamSpec> for &'a Property<'a> { + fn into(self) -> *mut gobject_ffi::GParamSpec { + unsafe { + match *self { + Property::Boolean(name, nick, description, default, mutability) => { + gobject_ffi::g_param_spec_boolean( + name.to_glib_none().0, + nick.to_glib_none().0, + description.to_glib_none().0, + default.to_glib(), + mutability.into(), + ) + } + Property::Int(name, nick, description, (min, max), default, mutability) => { + gobject_ffi::g_param_spec_int( + name.to_glib_none().0, + nick.to_glib_none().0, + description.to_glib_none().0, + min, + max, + default, + mutability.into(), + ) + } + Property::Int64(name, nick, description, (min, max), default, mutability) => { + gobject_ffi::g_param_spec_int64( + name.to_glib_none().0, + nick.to_glib_none().0, + description.to_glib_none().0, + min, + max, + default, + mutability.into(), + ) + } + Property::UInt(name, nick, description, (min, max), default, mutability) => { + gobject_ffi::g_param_spec_uint( + name.to_glib_none().0, + nick.to_glib_none().0, + description.to_glib_none().0, + min, + max, + default, + mutability.into(), + ) + } + Property::UInt64(name, nick, description, (min, max), default, mutability) => { + gobject_ffi::g_param_spec_uint64( + name.to_glib_none().0, + nick.to_glib_none().0, + description.to_glib_none().0, + min, + max, + default, + mutability.into(), + ) + } + Property::Float(name, nick, description, (min, max), default, mutability) => { + gobject_ffi::g_param_spec_float( + name.to_glib_none().0, + nick.to_glib_none().0, + description.to_glib_none().0, + min, + max, + default, + mutability.into(), + ) + } + Property::Double(name, nick, description, (min, max), default, mutability) => { + gobject_ffi::g_param_spec_double( + name.to_glib_none().0, + nick.to_glib_none().0, + description.to_glib_none().0, + min, + max, + default, + mutability.into(), + ) + } + Property::String(name, nick, description, default, mutability) => { + gobject_ffi::g_param_spec_string( + name.to_glib_none().0, + nick.to_glib_none().0, + description.to_glib_none().0, + default.to_glib_none().0, + mutability.into(), + ) + } + Property::Boxed(name, nick, description, type_, mutability) => { + gobject_ffi::g_param_spec_boxed( + name.to_glib_none().0, + nick.to_glib_none().0, + description.to_glib_none().0, + type_.to_glib(), + mutability.into(), + ) + } + Property::Object(name, nick, description, type_, mutability) => { + gobject_ffi::g_param_spec_object( + name.to_glib_none().0, + nick.to_glib_none().0, + description.to_glib_none().0, + type_.to_glib(), + mutability.into(), + ) + } + } + } + } +}