2017-07-07 11:47:28 +00:00
|
|
|
// 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.
|
|
|
|
|
2017-07-05 08:09:49 +00:00
|
|
|
use Element;
|
|
|
|
|
|
|
|
use glib;
|
|
|
|
use glib::IsA;
|
2017-09-17 15:41:02 +00:00
|
|
|
use glib::translate::{from_glib, from_glib_none, from_glib_full, FromGlibPtrContainer, ToGlibPtr};
|
2017-07-29 13:04:34 +00:00
|
|
|
use QueryRef;
|
2017-08-01 12:58:50 +00:00
|
|
|
use Event;
|
2017-09-17 15:41:02 +00:00
|
|
|
use Pad;
|
2017-08-17 09:48:54 +00:00
|
|
|
use PadTemplate;
|
2017-07-29 13:04:34 +00:00
|
|
|
use miniobject::MiniObject;
|
2017-07-05 08:09:49 +00:00
|
|
|
|
2017-08-17 09:48:54 +00:00
|
|
|
use std::ffi::CStr;
|
|
|
|
|
2017-07-05 08:09:49 +00:00
|
|
|
use ffi;
|
2017-08-17 09:48:54 +00:00
|
|
|
use gobject_ffi;
|
2017-07-05 08:09:49 +00:00
|
|
|
|
|
|
|
impl Element {
|
|
|
|
pub fn link_many<E: IsA<Element>>(elements: &[&E]) -> Result<(), glib::BoolError> {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-05 08:09:49 +00:00
|
|
|
for (e1, e2) in elements.iter().zip(elements.iter().skip(1)) {
|
|
|
|
unsafe {
|
2017-07-10 21:33:24 +00:00
|
|
|
let ret: bool = from_glib(ffi::gst_element_link(
|
|
|
|
e1.to_glib_none().0,
|
|
|
|
e2.to_glib_none().0,
|
|
|
|
));
|
2017-07-05 08:09:49 +00:00
|
|
|
if !ret {
|
|
|
|
return Err(glib::BoolError("Failed to link elements"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 16:40:31 +00:00
|
|
|
Ok(())
|
2017-07-05 08:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn unlink_many<E: IsA<Element>>(elements: &[&E]) {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-05 08:09:49 +00:00
|
|
|
for (e1, e2) in elements.iter().zip(elements.iter().skip(1)) {
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_element_unlink(e1.to_glib_none().0, e2.to_glib_none().0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 13:04:34 +00:00
|
|
|
|
2017-09-15 16:00:51 +00:00
|
|
|
pub enum ElementMessageType {
|
|
|
|
Error,
|
|
|
|
Warning,
|
|
|
|
Info,
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:04:34 +00:00
|
|
|
pub trait ElementExtManual {
|
|
|
|
fn query(&self, query: &mut QueryRef) -> bool;
|
2017-08-01 12:58:50 +00:00
|
|
|
|
|
|
|
fn send_event(&self, event: Event) -> bool;
|
2017-08-17 09:48:54 +00:00
|
|
|
|
2017-09-01 08:40:32 +00:00
|
|
|
fn get_metadata<'a>(&self, key: &str) -> Option<&'a str>;
|
2017-08-17 09:48:54 +00:00
|
|
|
|
|
|
|
fn get_pad_template(&self, name: &str) -> Option<PadTemplate>;
|
|
|
|
fn get_pad_template_list(&self) -> Vec<PadTemplate>;
|
2017-09-15 16:00:51 +00:00
|
|
|
|
|
|
|
fn message_full<T: ::MessageErrorDomain>(
|
|
|
|
&self,
|
|
|
|
type_: ElementMessageType,
|
|
|
|
code: T,
|
|
|
|
message: Option<&str>,
|
|
|
|
debug: Option<&str>,
|
|
|
|
file: &str,
|
|
|
|
function: &str,
|
|
|
|
line: i32,
|
|
|
|
);
|
|
|
|
#[cfg(feature = "v1_10")]
|
|
|
|
fn message_full_with_details<T: ::MessageErrorDomain>(
|
|
|
|
&self,
|
|
|
|
type_: ElementMessageType,
|
|
|
|
code: T,
|
|
|
|
message: Option<&str>,
|
|
|
|
debug: Option<&str>,
|
|
|
|
file: &str,
|
|
|
|
function: &str,
|
|
|
|
line: i32,
|
|
|
|
structure: ::Structure,
|
|
|
|
);
|
2017-09-17 15:41:02 +00:00
|
|
|
|
|
|
|
fn iterate_pads(&self) -> ::Iterator<Pad>;
|
|
|
|
fn iterate_sink_pads(&self) -> ::Iterator<Pad>;
|
|
|
|
fn iterate_src_pads(&self) -> ::Iterator<Pad>;
|
2017-07-29 13:04:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<O: IsA<Element>> ElementExtManual for O {
|
|
|
|
fn query(&self, query: &mut QueryRef) -> bool {
|
|
|
|
unsafe {
|
2017-07-31 11:16:42 +00:00
|
|
|
from_glib(ffi::gst_element_query(
|
|
|
|
self.to_glib_none().0,
|
|
|
|
query.as_mut_ptr(),
|
|
|
|
))
|
2017-07-29 13:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-01 12:58:50 +00:00
|
|
|
|
|
|
|
fn send_event(&self, event: Event) -> bool {
|
|
|
|
unsafe {
|
2017-08-02 16:41:33 +00:00
|
|
|
from_glib(ffi::gst_element_send_event(
|
|
|
|
self.to_glib_none().0,
|
|
|
|
event.into_ptr(),
|
|
|
|
))
|
2017-08-01 12:58:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-17 09:48:54 +00:00
|
|
|
|
2017-09-01 08:40:32 +00:00
|
|
|
fn get_metadata<'a>(&self, key: &str) -> Option<&'a str> {
|
2017-08-17 09:48:54 +00:00
|
|
|
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),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2017-09-15 16:00:51 +00:00
|
|
|
|
|
|
|
fn message_full<T: ::MessageErrorDomain>(
|
|
|
|
&self,
|
|
|
|
type_: ElementMessageType,
|
|
|
|
code: T,
|
|
|
|
message: Option<&str>,
|
|
|
|
debug: Option<&str>,
|
|
|
|
file: &str,
|
|
|
|
function: &str,
|
|
|
|
line: i32,
|
|
|
|
) {
|
|
|
|
unsafe {
|
|
|
|
let type_ = match type_ {
|
|
|
|
ElementMessageType::Error => ffi::GST_MESSAGE_ERROR,
|
|
|
|
ElementMessageType::Warning => ffi::GST_MESSAGE_WARNING,
|
|
|
|
ElementMessageType::Info => ffi::GST_MESSAGE_INFO,
|
|
|
|
};
|
|
|
|
|
|
|
|
ffi::gst_element_message_full(
|
|
|
|
self.to_glib_none().0,
|
|
|
|
type_,
|
|
|
|
T::domain(),
|
|
|
|
code.code(),
|
|
|
|
message.to_glib_full(),
|
|
|
|
debug.to_glib_full(),
|
|
|
|
file.to_glib_none().0,
|
|
|
|
function.to_glib_none().0,
|
|
|
|
line,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "v1_10")]
|
|
|
|
fn message_full_with_details<T: ::MessageErrorDomain>(
|
|
|
|
&self,
|
|
|
|
type_: ElementMessageType,
|
|
|
|
code: T,
|
|
|
|
message: Option<&str>,
|
|
|
|
debug: Option<&str>,
|
|
|
|
file: &str,
|
|
|
|
function: &str,
|
|
|
|
line: i32,
|
|
|
|
structure: ::Structure,
|
|
|
|
) {
|
|
|
|
unsafe {
|
|
|
|
let type_ = match type_ {
|
|
|
|
ElementMessageType::Error => ffi::GST_MESSAGE_ERROR,
|
|
|
|
ElementMessageType::Warning => ffi::GST_MESSAGE_WARNING,
|
|
|
|
ElementMessageType::Info => ffi::GST_MESSAGE_INFO,
|
|
|
|
};
|
|
|
|
|
|
|
|
ffi::gst_element_message_full_with_details(
|
|
|
|
self.to_glib_none().0,
|
|
|
|
type_,
|
|
|
|
T::domain(),
|
|
|
|
code.code(),
|
|
|
|
message.to_glib_full(),
|
|
|
|
debug.to_glib_full(),
|
|
|
|
file.to_glib_none().0,
|
|
|
|
function.to_glib_none().0,
|
|
|
|
line,
|
|
|
|
structure.into_ptr(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-09-17 15:41:02 +00:00
|
|
|
|
|
|
|
fn iterate_pads(&self) -> ::Iterator<Pad> {
|
|
|
|
unsafe {
|
|
|
|
from_glib_full(ffi::gst_element_iterate_pads(self.to_glib_none().0))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn iterate_sink_pads(&self) -> ::Iterator<Pad> {
|
|
|
|
unsafe {
|
|
|
|
from_glib_full(ffi::gst_element_iterate_sink_pads(self.to_glib_none().0))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn iterate_src_pads(&self) -> ::Iterator<Pad> {
|
|
|
|
unsafe {
|
|
|
|
from_glib_full(ffi::gst_element_iterate_src_pads(self.to_glib_none().0))
|
|
|
|
}
|
|
|
|
}
|
2017-08-17 09:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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() };
|
2017-07-29 13:04:34 +00:00
|
|
|
}
|