From 08e2f6d917a02a8181cddebc9e1a01d6fe9fd52d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 17 Aug 2017 12:48:54 +0300 Subject: [PATCH] Add Element::get_metadata(), get_pad_template(), get_pad_template_list() and DeviceProvider::get_metadata() As wrapper around the C class functions. Fixes https://github.com/sdroege/gstreamer-rs/issues/28 --- gstreamer/src/device_provider.rs | 38 +++++++++++++++++++++ gstreamer/src/element.rs | 58 +++++++++++++++++++++++++++++++- gstreamer/src/lib.rs | 10 ++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 gstreamer/src/device_provider.rs diff --git a/gstreamer/src/device_provider.rs b/gstreamer/src/device_provider.rs new file mode 100644 index 000000000..b5248ae38 --- /dev/null +++ b/gstreamer/src/device_provider.rs @@ -0,0 +1,38 @@ +// 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 DeviceProvider; + +use glib::IsA; +use glib::translate::ToGlibPtr; + +use std::ffi::CStr; + +use ffi; +use gobject_ffi; + +pub trait DeviceProviderExtManual { + fn get_metadata(&self, key: &str) -> Option<&'static str>; +} + +impl> DeviceProviderExtManual for O { + fn get_metadata(&self, key: &str) -> Option<&'static str> { + unsafe { + let klass = (*(self.to_glib_none().0 as *mut gobject_ffi::GTypeInstance)).g_class as + *mut ffi::GstDeviceProviderClass; + + let ptr = ffi::gst_device_provider_class_get_metadata(klass, key.to_glib_none().0); + + if ptr.is_null() { + None + } else { + Some(CStr::from_ptr(ptr).to_str().unwrap()) + } + } + } +} diff --git a/gstreamer/src/element.rs b/gstreamer/src/element.rs index 04bcdebfa..7bd8d554e 100644 --- a/gstreamer/src/element.rs +++ b/gstreamer/src/element.rs @@ -10,12 +10,16 @@ use Element; use glib; use glib::IsA; -use glib::translate::{from_glib, ToGlibPtr}; +use glib::translate::{from_glib, from_glib_none, FromGlibPtrContainer, ToGlibPtr}; use QueryRef; use Event; +use PadTemplate; use miniobject::MiniObject; +use std::ffi::CStr; + use ffi; +use gobject_ffi; impl Element { pub fn link_many>(elements: &[&E]) -> Result<(), glib::BoolError> { @@ -47,6 +51,11 @@ pub trait ElementExtManual { fn query(&self, query: &mut QueryRef) -> bool; fn send_event(&self, event: Event) -> bool; + + fn get_metadata(&self, key: &str) -> Option<&'static str>; + + fn get_pad_template(&self, name: &str) -> Option; + fn get_pad_template_list(&self) -> Vec; } impl> ElementExtManual for O { @@ -67,4 +76,51 @@ impl> ElementExtManual for O { )) } } + + fn get_metadata(&self, key: &str) -> Option<&'static str> { + unsafe { + let klass = (*(self.to_glib_none().0 as *mut gobject_ffi::GTypeInstance)).g_class as + *mut ffi::GstElementClass; + + let ptr = ffi::gst_element_class_get_metadata(klass, key.to_glib_none().0); + + if ptr.is_null() { + None + } else { + Some(CStr::from_ptr(ptr).to_str().unwrap()) + } + } + } + + fn get_pad_template(&self, name: &str) -> Option { + unsafe { + let klass = (*(self.to_glib_none().0 as *mut gobject_ffi::GTypeInstance)).g_class as + *mut ffi::GstElementClass; + + from_glib_none(ffi::gst_element_class_get_pad_template( + klass, + name.to_glib_none().0, + )) + } + } + + fn get_pad_template_list(&self) -> Vec { + unsafe { + let klass = (*(self.to_glib_none().0 as *mut gobject_ffi::GTypeInstance)).g_class as + *mut ffi::GstElementClass; + + FromGlibPtrContainer::from_glib_none( + ffi::gst_element_class_get_pad_template_list(klass), + ) + } + } +} + +lazy_static!{ + pub static ref ELEMENT_METADATA_AUTHOR: &'static str = unsafe { CStr::from_ptr(ffi::GST_ELEMENT_METADATA_AUTHOR).to_str().unwrap() }; + pub static ref ELEMENT_METADATA_DESCRIPTION: &'static str = unsafe { CStr::from_ptr(ffi::GST_ELEMENT_METADATA_DESCRIPTION).to_str().unwrap() }; + pub static ref ELEMENT_METADATA_DOC_URI: &'static str = unsafe { CStr::from_ptr(ffi::GST_ELEMENT_METADATA_DOC_URI).to_str().unwrap() }; + pub static ref ELEMENT_METADATA_ICON_NAME: &'static str = unsafe { CStr::from_ptr(ffi::GST_ELEMENT_METADATA_ICON_NAME).to_str().unwrap() }; + pub static ref ELEMENT_METADATA_KLASS: &'static str = unsafe { CStr::from_ptr(ffi::GST_ELEMENT_METADATA_KLASS).to_str().unwrap() }; + pub static ref ELEMENT_METADATA_LONGNAME: &'static str = unsafe { CStr::from_ptr(ffi::GST_ELEMENT_METADATA_LONGNAME).to_str().unwrap() }; } diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 057f527b5..99a822632 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -85,13 +85,23 @@ mod ghost_pad; mod child_proxy; mod tag_setter; mod iterator; +mod device_provider; pub use element::ElementExtManual; +pub use element::{ + ELEMENT_METADATA_AUTHOR, + ELEMENT_METADATA_DESCRIPTION, + ELEMENT_METADATA_DOC_URI, + ELEMENT_METADATA_ICON_NAME, + ELEMENT_METADATA_KLASS, + ELEMENT_METADATA_LONGNAME, +}; pub use bin::BinExtManual; pub use pad::{PadExtManual, PadProbeData, PadProbeId, PadProbeInfo, PAD_PROBE_ID_INVALID}; pub use gobject::GObjectExtManualGst; pub use child_proxy::ChildProxyExtManual; pub use tag_setter::TagSetterExtManual; pub use self::iterator::Iterator; +pub use device_provider::DeviceProviderExtManual; mod value; pub use value::*;