diff --git a/Gir_Gst.toml b/Gir_Gst.toml index f65a3b702..420a338c1 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -83,6 +83,8 @@ manual = [ "GLib.DateTime", "GObject.Object", "Gst.Segment", + "Gst.StaticCaps", + "Gst.StaticPadTemplate", ] [[object]] @@ -447,6 +449,11 @@ status = "generate" # Pass by value ignore = true + [[object.function]] + name = "new_from_static_template" + # Correct mutability + ignore = true + [[object]] name = "Gst.PadTemplate" status = "generate" diff --git a/gstreamer/src/auto/element_factory.rs b/gstreamer/src/auto/element_factory.rs index 45919bdcb..c5181d505 100644 --- a/gstreamer/src/auto/element_factory.rs +++ b/gstreamer/src/auto/element_factory.rs @@ -7,6 +7,7 @@ use ElementFactoryListType; use Object; use PadDirection; use Rank; +use StaticPadTemplate; use URIType; use ffi; use glib; @@ -81,9 +82,11 @@ impl ElementFactory { } } - //pub fn get_static_pad_templates(&self) -> /*Ignored*/Vec { - // unsafe { TODO: call ffi::gst_element_factory_get_static_pad_templates() } - //} + pub fn get_static_pad_templates(&self) -> Vec { + unsafe { + FromGlibPtrContainer::from_glib_none(ffi::gst_element_factory_get_static_pad_templates(self.to_glib_none().0)) + } + } pub fn get_uri_protocols(&self) -> Vec { unsafe { diff --git a/gstreamer/src/auto/pad.rs b/gstreamer/src/auto/pad.rs index 0b9c85717..ce66d31f8 100644 --- a/gstreamer/src/auto/pad.rs +++ b/gstreamer/src/auto/pad.rs @@ -50,10 +50,6 @@ impl Pad { } } - //pub fn new_from_static_template(templ: /*Ignored*/&mut StaticPadTemplate, name: &str) -> Pad { - // unsafe { TODO: call ffi::gst_pad_new_from_static_template() } - //} - pub fn new_from_template<'a, P: Into>>(templ: &PadTemplate, name: P) -> Pad { skip_assert_initialized!(); let name = name.into(); diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index b7e7aedf3..769ae54ec 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -83,6 +83,10 @@ pub mod event; pub use event::{Event, EventRef, EventView}; pub mod context; pub use context::{Context, ContextRef}; +mod static_caps; +pub use static_caps::*; +mod static_pad_template; +pub use static_pad_template::*; mod element; mod bin; diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index 3890b347f..bbb1be850 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -15,6 +15,7 @@ use FlowReturn; use Query; use QueryRef; use Event; +use StaticPadTemplate; use miniobject::MiniObject; use std::mem::transmute; @@ -24,8 +25,8 @@ use std::cell::RefCell; use glib; use glib::{IsA, StaticType}; -use glib::translate::{from_glib, from_glib_borrow, from_glib_full, from_glib_none, FromGlib, - ToGlib, ToGlibPtr}; +use glib::translate::{mut_override, from_glib, from_glib_borrow, from_glib_full, from_glib_none, + FromGlib, ToGlib, ToGlibPtr}; use glib::source::CallbackGuard; use glib_ffi; use glib_ffi::gpointer; @@ -35,6 +36,15 @@ use libc; use ffi; +impl Pad { + pub fn new_from_static_template(templ: &StaticPadTemplate, name: &str) -> Pad { + assert_initialized_main_thread!(); + unsafe { + from_glib_none(ffi::gst_pad_new_from_static_template(mut_override(templ.to_glib_none().0), name.to_glib_none().0)) + } + } +} + #[derive(Debug, Default, PartialEq, Eq)] pub struct PadProbeId(libc::c_ulong); pub const PAD_PROBE_ID_INVALID: PadProbeId = PadProbeId(0); diff --git a/gstreamer/src/static_caps.rs b/gstreamer/src/static_caps.rs new file mode 100644 index 000000000..5292899df --- /dev/null +++ b/gstreamer/src/static_caps.rs @@ -0,0 +1,119 @@ +// 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 Caps; + +use ffi; +use glib_ffi; +use gobject_ffi; + +use std::ptr; +use glib; +use glib::translate::{from_glib_full, from_glib_none, mut_override, FromGlibPtrNone, ToGlibPtr, + ToGlibPtrMut}; + +#[repr(C)] +pub struct StaticCaps(ffi::GstStaticCaps); + +impl StaticCaps { + pub fn get(&self) -> Caps { + unsafe { from_glib_full(ffi::gst_static_caps_get(mut_override(&self.0))) } + } +} + +unsafe impl Send for StaticCaps {} +unsafe impl Sync for StaticCaps {} + +impl glib::types::StaticType for StaticCaps { + fn static_type() -> glib::types::Type { + unsafe { glib::translate::from_glib(ffi::gst_static_caps_get_type()) } + } +} + +#[doc(hidden)] +impl<'a> glib::value::FromValueOptional<'a> for StaticCaps { + unsafe fn from_value_optional(value: &glib::Value) -> Option { + Option::::from_glib_none( + gobject_ffi::g_value_get_boxed(value.to_glib_none().0) as *mut ffi::GstStaticCaps, + ) + } +} + +#[doc(hidden)] +impl glib::value::SetValue for StaticCaps { + unsafe fn set_value(value: &mut glib::Value, this: &Self) { + gobject_ffi::g_value_set_boxed( + value.to_glib_none_mut().0, + glib::translate::ToGlibPtr::<*const ffi::GstStaticCaps>::to_glib_none(this).0 as + glib_ffi::gpointer, + ) + } +} + +#[doc(hidden)] +impl glib::value::SetValueOptional for StaticCaps { + unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) { + gobject_ffi::g_value_set_boxed( + value.to_glib_none_mut().0, + glib::translate::ToGlibPtr::<*const ffi::GstStaticCaps>::to_glib_none(&this).0 as + glib_ffi::gpointer, + ) + } +} + +#[doc(hidden)] +impl glib::translate::GlibPtrDefault for StaticCaps { + type GlibType = *mut ffi::GstStaticCaps; +} + +#[doc(hidden)] +impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticCaps> for StaticCaps { + type Storage = &'a StaticCaps; + + fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstStaticCaps, Self> { + glib::translate::Stash(&self.0, self) + } + + fn to_glib_full(&self) -> *const ffi::GstStaticCaps { + unimplemented!() + } +} + +#[doc(hidden)] +impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticCaps> for StaticCaps { + #[inline] + unsafe fn from_glib_none(ptr: *const ffi::GstStaticCaps) -> Self { + StaticCaps(ptr::read(ptr)) + } +} + +#[doc(hidden)] +impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticCaps> for StaticCaps { + #[inline] + unsafe fn from_glib_none(ptr: *mut ffi::GstStaticCaps) -> Self { + StaticCaps(ptr::read(ptr)) + } +} + +#[doc(hidden)] +impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticCaps> for StaticCaps { + #[inline] + unsafe fn from_glib_borrow(ptr: *mut ffi::GstStaticCaps) -> Self { + StaticCaps(ptr::read(ptr)) + } +} + +#[doc(hidden)] +impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticCaps> for StaticCaps { + #[inline] + unsafe fn from_glib_full(ptr: *mut ffi::GstStaticCaps) -> Self { + let caps = from_glib_none(ptr); + glib_ffi::g_free(ptr as *mut _); + caps + } +} diff --git a/gstreamer/src/static_pad_template.rs b/gstreamer/src/static_pad_template.rs new file mode 100644 index 000000000..4cbb82e60 --- /dev/null +++ b/gstreamer/src/static_pad_template.rs @@ -0,0 +1,140 @@ +// 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 PadTemplate; +use Caps; + +use ffi; +use glib_ffi; +use gobject_ffi; + +use std::ffi::CStr; +use std::ptr; +use glib; +use glib::translate::{from_glib, from_glib_full, from_glib_none, mut_override, FromGlibPtrNone, + ToGlibPtr, ToGlibPtrMut}; + +#[repr(C)] +pub struct StaticPadTemplate(ffi::GstStaticPadTemplate); + +impl StaticPadTemplate { + pub fn get(&self) -> PadTemplate { + unsafe { from_glib_full(ffi::gst_static_pad_template_get(mut_override(&self.0))) } + } + + pub fn get_caps(&self) -> Caps { + unsafe { from_glib_full(ffi::gst_static_pad_template_get_caps(mut_override(&self.0))) } + } + + pub fn name_template<'a>(&self) -> &'a str { + unsafe { CStr::from_ptr(self.0.name_template).to_str().unwrap() } + } + + pub fn direction(&self) -> ::PadDirection { + from_glib(self.0.direction) + } + + pub fn presence(&self) -> ::PadPresence { + from_glib(self.0.presence) + } +} + +unsafe impl Send for StaticPadTemplate {} +unsafe impl Sync for StaticPadTemplate {} + +impl glib::types::StaticType for StaticPadTemplate { + fn static_type() -> glib::types::Type { + unsafe { glib::translate::from_glib(ffi::gst_static_pad_template_get_type()) } + } +} + +#[doc(hidden)] +impl<'a> glib::value::FromValueOptional<'a> for StaticPadTemplate { + unsafe fn from_value_optional(value: &glib::Value) -> Option { + Option::::from_glib_none( + gobject_ffi::g_value_get_boxed(value.to_glib_none().0) as + *mut ffi::GstStaticPadTemplate, + ) + } +} + +#[doc(hidden)] +impl glib::value::SetValue for StaticPadTemplate { + unsafe fn set_value(value: &mut glib::Value, this: &Self) { + gobject_ffi::g_value_set_boxed( + value.to_glib_none_mut().0, + glib::translate::ToGlibPtr::<*const ffi::GstStaticPadTemplate>::to_glib_none(this).0 as + glib_ffi::gpointer, + ) + } +} + +#[doc(hidden)] +impl glib::value::SetValueOptional for StaticPadTemplate { + unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) { + gobject_ffi::g_value_set_boxed( + value.to_glib_none_mut().0, + glib::translate::ToGlibPtr::<*const ffi::GstStaticPadTemplate>::to_glib_none(&this).0 as + glib_ffi::gpointer, + ) + } +} + +#[doc(hidden)] +impl glib::translate::GlibPtrDefault for StaticPadTemplate { + type GlibType = *mut ffi::GstStaticPadTemplate; +} + +#[doc(hidden)] +impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticPadTemplate> for StaticPadTemplate { + type Storage = &'a StaticPadTemplate; + + fn to_glib_none( + &'a self, + ) -> glib::translate::Stash<'a, *const ffi::GstStaticPadTemplate, Self> { + glib::translate::Stash(&self.0, self) + } + + fn to_glib_full(&self) -> *const ffi::GstStaticPadTemplate { + unimplemented!() + } +} + +#[doc(hidden)] +impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticPadTemplate> for StaticPadTemplate { + #[inline] + unsafe fn from_glib_none(ptr: *const ffi::GstStaticPadTemplate) -> Self { + StaticPadTemplate(ptr::read(ptr)) + } +} + +#[doc(hidden)] +impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate { + #[inline] + unsafe fn from_glib_none(ptr: *mut ffi::GstStaticPadTemplate) -> Self { + StaticPadTemplate(ptr::read(ptr)) + } +} + +#[doc(hidden)] +impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate { + #[inline] + unsafe fn from_glib_borrow(ptr: *mut ffi::GstStaticPadTemplate) -> Self { + StaticPadTemplate(ptr::read(ptr)) + } +} + +#[doc(hidden)] +impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate { + #[inline] + unsafe fn from_glib_full(ptr: *mut ffi::GstStaticPadTemplate) -> Self { + let templ = from_glib_none(ptr); + glib_ffi::g_free(ptr as *mut _); + templ + } +}