2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-07-07 11:47:28 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::Bin;
|
|
|
|
use crate::BinFlags;
|
|
|
|
use crate::Element;
|
|
|
|
use crate::LoggableError;
|
2017-07-05 08:09:49 +00:00
|
|
|
|
2021-04-26 12:15:53 +00:00
|
|
|
use glib::prelude::*;
|
2019-01-16 20:23:56 +00:00
|
|
|
use glib::signal::connect_raw;
|
|
|
|
use glib::signal::SignalHandlerId;
|
|
|
|
use glib::translate::*;
|
2019-01-16 11:32:58 +00:00
|
|
|
use glib::GString;
|
2017-07-05 08:09:49 +00:00
|
|
|
|
2019-01-16 20:23:56 +00:00
|
|
|
use std::boxed::Box as Box_;
|
2020-04-13 16:18:57 +00:00
|
|
|
use std::mem::transmute;
|
2018-11-11 07:33:12 +00:00
|
|
|
use std::path;
|
|
|
|
|
2018-12-08 09:22:42 +00:00
|
|
|
pub trait GstBinExtManual: 'static {
|
2017-07-05 08:09:49 +00:00
|
|
|
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
|
|
|
|
2019-01-24 21:11:43 +00:00
|
|
|
fn connect_do_latency<F: Fn(&Self) -> Result<(), LoggableError> + Send + Sync + 'static>(
|
2019-01-16 20:23:56 +00:00
|
|
|
&self,
|
|
|
|
f: F,
|
|
|
|
) -> SignalHandlerId;
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_all_by_element_factory_name(&self, factory_name: &str) -> crate::Iterator<Element>;
|
|
|
|
fn iterate_all_by_interface(&self, iface: glib::types::Type) -> crate::Iterator<Element>;
|
|
|
|
fn iterate_elements(&self) -> crate::Iterator<Element>;
|
|
|
|
fn iterate_recurse(&self) -> crate::Iterator<Element>;
|
|
|
|
fn iterate_sinks(&self) -> crate::Iterator<Element>;
|
|
|
|
fn iterate_sorted(&self) -> crate::Iterator<Element>;
|
|
|
|
fn iterate_sources(&self) -> crate::Iterator<Element>;
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_children")]
|
2021-04-11 19:39:50 +00:00
|
|
|
fn children(&self) -> Vec<Element>;
|
2018-11-11 07:33:12 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn debug_to_dot_data(&self, details: crate::DebugGraphDetails) -> GString;
|
|
|
|
fn debug_to_dot_file<Q: AsRef<path::Path>>(
|
|
|
|
&self,
|
|
|
|
details: crate::DebugGraphDetails,
|
|
|
|
file_name: Q,
|
|
|
|
);
|
2018-11-11 07:33:12 +00:00
|
|
|
fn debug_to_dot_file_with_ts<Q: AsRef<path::Path>>(
|
|
|
|
&self,
|
2020-11-21 13:46:48 +00:00
|
|
|
details: crate::DebugGraphDetails,
|
2018-11-11 07:33:12 +00:00
|
|
|
file_name: Q,
|
|
|
|
);
|
2020-01-06 15:23:39 +00:00
|
|
|
|
|
|
|
fn set_bin_flags(&self, flags: BinFlags);
|
|
|
|
|
|
|
|
fn unset_bin_flags(&self, flags: BinFlags);
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_bin_flags")]
|
2021-04-11 19:39:50 +00:00
|
|
|
fn bin_flags(&self) -> BinFlags;
|
2017-07-05 08:09:49 +00:00
|
|
|
}
|
|
|
|
|
2018-10-28 11:30:41 +00:00
|
|
|
impl<O: IsA<Bin>> GstBinExtManual for O {
|
2017-07-05 08:09:49 +00:00
|
|
|
fn add_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError> {
|
|
|
|
for e in elements {
|
|
|
|
unsafe {
|
2020-12-17 22:38:06 +00:00
|
|
|
glib::result_from_gboolean!(
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_bin_add(self.as_ref().to_glib_none().0, e.as_ref().to_glib_none().0),
|
2019-01-25 17:15:01 +00:00
|
|
|
"Failed to add elements"
|
|
|
|
)?;
|
2017-07-05 08:09:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2020-12-17 22:38:06 +00:00
|
|
|
glib::result_from_gboolean!(
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_bin_remove(
|
2019-01-25 17:15:01 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
e.as_ref().to_glib_none().0,
|
|
|
|
),
|
|
|
|
"Failed to remove elements"
|
|
|
|
)?;
|
2017-07-05 08:09:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-01-24 21:11:43 +00:00
|
|
|
fn connect_do_latency<F: Fn(&Self) -> Result<(), LoggableError> + Send + Sync + 'static>(
|
2019-01-16 20:23:56 +00:00
|
|
|
&self,
|
|
|
|
f: F,
|
|
|
|
) -> SignalHandlerId {
|
|
|
|
unsafe {
|
2019-01-29 16:22:05 +00:00
|
|
|
let f: Box_<F> = Box_::new(f);
|
2019-01-16 20:23:56 +00:00
|
|
|
connect_raw(
|
|
|
|
self.as_ptr() as *mut _,
|
|
|
|
b"do-latency\0".as_ptr() as *const _,
|
2020-04-13 16:18:57 +00:00
|
|
|
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
|
|
do_latency_trampoline::<Self, F> as *const (),
|
|
|
|
)),
|
2019-01-29 16:22:05 +00:00
|
|
|
Box_::into_raw(f),
|
2019-01-16 20:23:56 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_all_by_element_factory_name(&self, factory_name: &str) -> crate::Iterator<Element> {
|
2020-05-02 19:12:36 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib_full(ffi::gst_bin_iterate_all_by_element_factory_name(
|
2020-05-02 19:12:36 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
factory_name.to_glib_none().0,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_all_by_interface(&self, iface: glib::types::Type) -> crate::Iterator<Element> {
|
2017-09-17 15:41:02 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib_full(ffi::gst_bin_iterate_all_by_interface(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
iface.into_glib(),
|
2017-10-17 09:06:51 +00:00
|
|
|
))
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_elements(&self) -> crate::Iterator<Element> {
|
2019-01-16 11:32:58 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib_full(ffi::gst_bin_iterate_elements(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
))
|
|
|
|
}
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_recurse(&self) -> crate::Iterator<Element> {
|
|
|
|
unsafe { from_glib_full(ffi::gst_bin_iterate_recurse(self.as_ref().to_glib_none().0)) }
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_sinks(&self) -> crate::Iterator<Element> {
|
|
|
|
unsafe { from_glib_full(ffi::gst_bin_iterate_sinks(self.as_ref().to_glib_none().0)) }
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_sorted(&self) -> crate::Iterator<Element> {
|
|
|
|
unsafe { from_glib_full(ffi::gst_bin_iterate_sorted(self.as_ref().to_glib_none().0)) }
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_sources(&self) -> crate::Iterator<Element> {
|
|
|
|
unsafe { from_glib_full(ffi::gst_bin_iterate_sources(self.as_ref().to_glib_none().0)) }
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
2017-10-25 10:56:32 +00:00
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
fn children(&self) -> Vec<Element> {
|
2017-10-25 10:56:32 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let bin: &ffi::GstBin = &*(self.as_ptr() as *const _);
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&bin.element.object.lock);
|
2017-10-25 10:56:32 +00:00
|
|
|
FromGlibPtrContainer::from_glib_none(bin.children)
|
|
|
|
}
|
|
|
|
}
|
2018-11-11 07:33:12 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn debug_to_dot_data(&self, details: crate::DebugGraphDetails) -> GString {
|
|
|
|
crate::debug_bin_to_dot_data(self, details)
|
2018-11-11 07:33:12 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn debug_to_dot_file<Q: AsRef<path::Path>>(
|
|
|
|
&self,
|
|
|
|
details: crate::DebugGraphDetails,
|
|
|
|
file_name: Q,
|
|
|
|
) {
|
|
|
|
crate::debug_bin_to_dot_file(self, details, file_name)
|
2018-11-11 07:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn debug_to_dot_file_with_ts<Q: AsRef<path::Path>>(
|
|
|
|
&self,
|
2020-11-21 13:46:48 +00:00
|
|
|
details: crate::DebugGraphDetails,
|
2018-11-11 07:33:12 +00:00
|
|
|
file_name: Q,
|
|
|
|
) {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::debug_bin_to_dot_file_with_ts(self, details, file_name)
|
2018-11-11 07:33:12 +00:00
|
|
|
}
|
2020-01-06 15:23:39 +00:00
|
|
|
|
|
|
|
fn set_bin_flags(&self, flags: BinFlags) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
2021-04-27 15:15:46 +00:00
|
|
|
(*ptr).flags |= flags.into_glib();
|
2020-01-06 15:23:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unset_bin_flags(&self, flags: BinFlags) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
2021-04-27 15:15:46 +00:00
|
|
|
(*ptr).flags &= !flags.into_glib();
|
2020-01-06 15:23:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
fn bin_flags(&self) -> BinFlags {
|
2020-01-06 15:23:39 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
2020-01-06 15:23:39 +00:00
|
|
|
from_glib((*ptr).flags)
|
|
|
|
}
|
|
|
|
}
|
2017-07-05 08:09:49 +00:00
|
|
|
}
|
2017-10-26 11:29:37 +00:00
|
|
|
|
2019-01-29 16:22:05 +00:00
|
|
|
unsafe extern "C" fn do_latency_trampoline<
|
|
|
|
P,
|
|
|
|
F: Fn(&P) -> Result<(), LoggableError> + Send + Sync + 'static,
|
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
this: *mut ffi::GstBin,
|
|
|
|
f: glib::ffi::gpointer,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-01-16 20:23:56 +00:00
|
|
|
where
|
|
|
|
P: IsA<Bin>,
|
|
|
|
{
|
2019-02-21 17:30:36 +00:00
|
|
|
let f: &F = &*(f as *const F);
|
2020-04-05 14:52:56 +00:00
|
|
|
match f(&Bin::from_glib_borrow(this).unsafe_cast_ref()) {
|
2019-01-16 20:23:56 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-04-05 14:52:56 +00:00
|
|
|
err.log_with_object(&*Bin::from_glib_borrow(this));
|
2019-01-16 20:23:56 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2021-04-27 15:15:46 +00:00
|
|
|
.into_glib()
|
2019-01-16 20:23:56 +00:00
|
|
|
}
|
|
|
|
|
2017-10-26 11:29:37 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::prelude::*;
|
2017-10-26 11:29:37 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_get_children() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2017-10-26 11:29:37 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let bin = crate::Bin::new(None);
|
|
|
|
bin.add(&crate::ElementFactory::make("identity", Some("identity0")).unwrap())
|
2017-10-26 11:29:37 +00:00
|
|
|
.unwrap();
|
2020-11-21 13:46:48 +00:00
|
|
|
bin.add(&crate::ElementFactory::make("identity", Some("identity1")).unwrap())
|
2017-10-26 11:29:37 +00:00
|
|
|
.unwrap();
|
|
|
|
|
2018-07-27 10:36:40 +00:00
|
|
|
let mut child_names = bin
|
2021-04-11 19:39:50 +00:00
|
|
|
.children()
|
2017-10-26 11:29:37 +00:00
|
|
|
.iter()
|
2021-04-11 19:39:50 +00:00
|
|
|
.map(|c| c.name())
|
2018-12-09 16:06:12 +00:00
|
|
|
.collect::<Vec<GString>>();
|
2017-10-26 11:29:37 +00:00
|
|
|
child_names.sort();
|
|
|
|
assert_eq!(
|
|
|
|
child_names,
|
|
|
|
vec![String::from("identity0"), String::from("identity1")]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|