bin.rs 2.96 KB
Newer Older
Sebastian Dröge's avatar
Sebastian Dröge committed
1 2 3 4 5 6 7 8
// 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.

9 10 11 12 13
use Bin;
use Element;

use glib;
use glib::IsA;
14
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr};
15 16 17 18 19 20

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>;
21 22 23 24 25 26 27

    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>;
28 29 30 31 32 33
}

impl<O: IsA<Bin>> BinExtManual for O {
    fn add_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError> {
        for e in elements {
            unsafe {
34 35
                let ret: bool =
                    from_glib(ffi::gst_bin_add(self.to_glib_none().0, e.to_glib_none().0));
36 37 38 39 40 41
                if !ret {
                    return Err(glib::BoolError("Failed to add elements"));
                }
            }
        }

Sebastian Dröge's avatar
Sebastian Dröge committed
42
        Ok(())
43 44 45 46 47
    }

    fn remove_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError> {
        for e in elements {
            unsafe {
48 49 50 51
                let ret: bool = from_glib(ffi::gst_bin_remove(
                    self.to_glib_none().0,
                    e.to_glib_none().0,
                ));
52 53 54 55 56 57
                if !ret {
                    return Err(glib::BoolError("Failed to add elements"));
                }
            }
        }

Sebastian Dröge's avatar
Sebastian Dröge committed
58
        Ok(())
59
    }
60 61 62

    fn iterate_all_by_interface(&self, iface: glib::types::Type) -> ::Iterator<Element> {
        unsafe {
63 64 65 66
            from_glib_full(ffi::gst_bin_iterate_all_by_interface(
                self.to_glib_none().0,
                iface.to_glib(),
            ))
67 68 69 70
        }
    }

    fn iterate_elements(&self) -> ::Iterator<Element> {
71
        unsafe { from_glib_full(ffi::gst_bin_iterate_elements(self.to_glib_none().0)) }
72 73 74
    }

    fn iterate_recurse(&self) -> ::Iterator<Element> {
75
        unsafe { from_glib_full(ffi::gst_bin_iterate_recurse(self.to_glib_none().0)) }
76 77 78
    }

    fn iterate_sinks(&self) -> ::Iterator<Element> {
79
        unsafe { from_glib_full(ffi::gst_bin_iterate_sinks(self.to_glib_none().0)) }
80 81 82
    }

    fn iterate_sorted(&self) -> ::Iterator<Element> {
83
        unsafe { from_glib_full(ffi::gst_bin_iterate_sorted(self.to_glib_none().0)) }
84 85 86
    }

    fn iterate_sources(&self) -> ::Iterator<Element> {
87
        unsafe { from_glib_full(ffi::gst_bin_iterate_sources(self.to_glib_none().0)) }
88
    }
89
}