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 Bin;
|
|
|
|
use Element;
|
|
|
|
|
|
|
|
use glib;
|
|
|
|
use glib::IsA;
|
2017-10-17 09:06:51 +00:00
|
|
|
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr};
|
2017-07-05 08:09:49 +00:00
|
|
|
|
|
|
|
use ffi;
|
|
|
|
|
|
|
|
pub trait BinExtManual {
|
|
|
|
fn add_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError>;
|
|
|
|
fn remove_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError>;
|
2017-09-17 15:41:02 +00:00
|
|
|
|
|
|
|
fn iterate_all_by_interface(&self, iface: glib::types::Type) -> ::Iterator<Element>;
|
|
|
|
fn iterate_elements(&self) -> ::Iterator<Element>;
|
|
|
|
fn iterate_recurse(&self) -> ::Iterator<Element>;
|
|
|
|
fn iterate_sinks(&self) -> ::Iterator<Element>;
|
|
|
|
fn iterate_sorted(&self) -> ::Iterator<Element>;
|
|
|
|
fn iterate_sources(&self) -> ::Iterator<Element>;
|
2017-07-05 08:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<O: IsA<Bin>> BinExtManual for O {
|
|
|
|
fn add_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError> {
|
|
|
|
for e in elements {
|
|
|
|
unsafe {
|
2017-07-10 21:33:24 +00:00
|
|
|
let ret: bool =
|
|
|
|
from_glib(ffi::gst_bin_add(self.to_glib_none().0, e.to_glib_none().0));
|
2017-07-05 08:09:49 +00:00
|
|
|
if !ret {
|
|
|
|
return Err(glib::BoolError("Failed to add elements"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 16:40:31 +00:00
|
|
|
Ok(())
|
2017-07-05 08:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn remove_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError> {
|
|
|
|
for e in elements {
|
|
|
|
unsafe {
|
2017-07-10 21:33:24 +00:00
|
|
|
let ret: bool = from_glib(ffi::gst_bin_remove(
|
|
|
|
self.to_glib_none().0,
|
|
|
|
e.to_glib_none().0,
|
|
|
|
));
|
2017-07-05 08:09:49 +00:00
|
|
|
if !ret {
|
|
|
|
return Err(glib::BoolError("Failed to add elements"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 16:40:31 +00:00
|
|
|
Ok(())
|
2017-07-05 08:09:49 +00:00
|
|
|
}
|
2017-09-17 15:41:02 +00:00
|
|
|
|
|
|
|
fn iterate_all_by_interface(&self, iface: glib::types::Type) -> ::Iterator<Element> {
|
|
|
|
unsafe {
|
2017-10-17 09:06:51 +00:00
|
|
|
from_glib_full(ffi::gst_bin_iterate_all_by_interface(
|
|
|
|
self.to_glib_none().0,
|
|
|
|
iface.to_glib(),
|
|
|
|
))
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn iterate_elements(&self) -> ::Iterator<Element> {
|
2017-10-17 09:06:51 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_bin_iterate_elements(self.to_glib_none().0)) }
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn iterate_recurse(&self) -> ::Iterator<Element> {
|
2017-10-17 09:06:51 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_bin_iterate_recurse(self.to_glib_none().0)) }
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn iterate_sinks(&self) -> ::Iterator<Element> {
|
2017-10-17 09:06:51 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_bin_iterate_sinks(self.to_glib_none().0)) }
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn iterate_sorted(&self) -> ::Iterator<Element> {
|
2017-10-17 09:06:51 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_bin_iterate_sorted(self.to_glib_none().0)) }
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn iterate_sources(&self) -> ::Iterator<Element> {
|
2017-10-17 09:06:51 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_bin_iterate_sources(self.to_glib_none().0)) }
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
2017-07-05 08:09:49 +00:00
|
|
|
}
|