mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-26 11:31:06 +00:00
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
This commit is contained in:
parent
7991b4d8eb
commit
08e2f6d917
3 changed files with 105 additions and 1 deletions
38
gstreamer/src/device_provider.rs
Normal file
38
gstreamer/src/device_provider.rs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
|
||||||
|
//
|
||||||
|
// 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 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<O: IsA<DeviceProvider>> 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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,12 +10,16 @@ use Element;
|
||||||
|
|
||||||
use glib;
|
use glib;
|
||||||
use glib::IsA;
|
use glib::IsA;
|
||||||
use glib::translate::{from_glib, ToGlibPtr};
|
use glib::translate::{from_glib, from_glib_none, FromGlibPtrContainer, ToGlibPtr};
|
||||||
use QueryRef;
|
use QueryRef;
|
||||||
use Event;
|
use Event;
|
||||||
|
use PadTemplate;
|
||||||
use miniobject::MiniObject;
|
use miniobject::MiniObject;
|
||||||
|
|
||||||
|
use std::ffi::CStr;
|
||||||
|
|
||||||
use ffi;
|
use ffi;
|
||||||
|
use gobject_ffi;
|
||||||
|
|
||||||
impl Element {
|
impl Element {
|
||||||
pub fn link_many<E: IsA<Element>>(elements: &[&E]) -> Result<(), glib::BoolError> {
|
pub fn link_many<E: IsA<Element>>(elements: &[&E]) -> Result<(), glib::BoolError> {
|
||||||
|
@ -47,6 +51,11 @@ pub trait ElementExtManual {
|
||||||
fn query(&self, query: &mut QueryRef) -> bool;
|
fn query(&self, query: &mut QueryRef) -> bool;
|
||||||
|
|
||||||
fn send_event(&self, event: Event) -> 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<PadTemplate>;
|
||||||
|
fn get_pad_template_list(&self) -> Vec<PadTemplate>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<O: IsA<Element>> ElementExtManual for O {
|
impl<O: IsA<Element>> ElementExtManual for O {
|
||||||
|
@ -67,4 +76,51 @@ impl<O: IsA<Element>> 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<PadTemplate> {
|
||||||
|
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<PadTemplate> {
|
||||||
|
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() };
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,13 +85,23 @@ mod ghost_pad;
|
||||||
mod child_proxy;
|
mod child_proxy;
|
||||||
mod tag_setter;
|
mod tag_setter;
|
||||||
mod iterator;
|
mod iterator;
|
||||||
|
mod device_provider;
|
||||||
pub use element::ElementExtManual;
|
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 bin::BinExtManual;
|
||||||
pub use pad::{PadExtManual, PadProbeData, PadProbeId, PadProbeInfo, PAD_PROBE_ID_INVALID};
|
pub use pad::{PadExtManual, PadProbeData, PadProbeId, PadProbeInfo, PAD_PROBE_ID_INVALID};
|
||||||
pub use gobject::GObjectExtManualGst;
|
pub use gobject::GObjectExtManualGst;
|
||||||
pub use child_proxy::ChildProxyExtManual;
|
pub use child_proxy::ChildProxyExtManual;
|
||||||
pub use tag_setter::TagSetterExtManual;
|
pub use tag_setter::TagSetterExtManual;
|
||||||
pub use self::iterator::Iterator;
|
pub use self::iterator::Iterator;
|
||||||
|
pub use device_provider::DeviceProviderExtManual;
|
||||||
|
|
||||||
mod value;
|
mod value;
|
||||||
pub use value::*;
|
pub use value::*;
|
||||||
|
|
Loading…
Reference in a new issue