Commit ce5c01a8 authored by Sebastian Dröge's avatar Sebastian Dröge 🍵

Implement gst::Iterator as a generic type to not require using glib::Values everywhere

parent 8085c4ce
......@@ -81,7 +81,6 @@ manual = [
"GLib.Source",
"GLib.DateTime",
"GObject.Object",
"Gst.Iterator",
"Gst.Segment",
]
......
......@@ -5,10 +5,10 @@ fn main() {
gst::init().unwrap();
let identity = gst::ElementFactory::make("identity", None).unwrap();
let mut iter = identity.iterate_pads().unwrap();
let mut iter = identity.iterate_pads();
while let Some(res) = iter.next() {
match res {
Ok(pad) => println!("Pad: {}", pad.get::<gst::Pad>().unwrap().get_name()),
Ok(pad) => println!("Pad: {}", pad.get_name()),
Err(gst::IteratorError::Resync) => {
println!("Iterator resync");
iter.resync();
......
......@@ -5,7 +5,6 @@ use ChildProxy;
use Element;
#[cfg(feature = "v1_10")]
use ElementFlags;
use Iterator;
use Object;
use Pad;
use PadDirection;
......@@ -62,17 +61,17 @@ pub trait BinExt {
#[cfg(feature = "v1_10")]
fn get_suppressed_flags(&self) -> ElementFlags;
fn iterate_all_by_interface(&self, iface: glib::types::Type) -> Option<Iterator>;
//fn iterate_all_by_interface(&self, iface: glib::types::Type) -> /*Ignored*/Option<Iterator>;
fn iterate_elements(&self) -> Option<Iterator>;
//fn iterate_elements(&self) -> /*Ignored*/Option<Iterator>;
fn iterate_recurse(&self) -> Option<Iterator>;
//fn iterate_recurse(&self) -> /*Ignored*/Option<Iterator>;
fn iterate_sinks(&self) -> Option<Iterator>;
//fn iterate_sinks(&self) -> /*Ignored*/Option<Iterator>;
fn iterate_sorted(&self) -> Option<Iterator>;
//fn iterate_sorted(&self) -> /*Ignored*/Option<Iterator>;
fn iterate_sources(&self) -> Option<Iterator>;
//fn iterate_sources(&self) -> /*Ignored*/Option<Iterator>;
fn recalculate_latency(&self) -> Result<(), glib::error::BoolError>;
......@@ -152,41 +151,29 @@ impl<O: IsA<Bin> + IsA<glib::object::Object>> BinExt for O {
}
}
fn iterate_all_by_interface(&self, iface: glib::types::Type) -> Option<Iterator> {
unsafe {
from_glib_full(ffi::gst_bin_iterate_all_by_interface(self.to_glib_none().0, iface.to_glib()))
}
}
//fn iterate_all_by_interface(&self, iface: glib::types::Type) -> /*Ignored*/Option<Iterator> {
// unsafe { TODO: call ffi::gst_bin_iterate_all_by_interface() }
//}
fn iterate_elements(&self) -> Option<Iterator> {
unsafe {
from_glib_full(ffi::gst_bin_iterate_elements(self.to_glib_none().0))
}
}
//fn iterate_elements(&self) -> /*Ignored*/Option<Iterator> {
// unsafe { TODO: call ffi::gst_bin_iterate_elements() }
//}
fn iterate_recurse(&self) -> Option<Iterator> {
unsafe {
from_glib_full(ffi::gst_bin_iterate_recurse(self.to_glib_none().0))
}
}
//fn iterate_recurse(&self) -> /*Ignored*/Option<Iterator> {
// unsafe { TODO: call ffi::gst_bin_iterate_recurse() }
//}
fn iterate_sinks(&self) -> Option<Iterator> {
unsafe {
from_glib_full(ffi::gst_bin_iterate_sinks(self.to_glib_none().0))
}
}
//fn iterate_sinks(&self) -> /*Ignored*/Option<Iterator> {
// unsafe { TODO: call ffi::gst_bin_iterate_sinks() }
//}
fn iterate_sorted(&self) -> Option<Iterator> {
unsafe {
from_glib_full(ffi::gst_bin_iterate_sorted(self.to_glib_none().0))
}
}
//fn iterate_sorted(&self) -> /*Ignored*/Option<Iterator> {
// unsafe { TODO: call ffi::gst_bin_iterate_sorted() }
//}
fn iterate_sources(&self) -> Option<Iterator> {
unsafe {
from_glib_full(ffi::gst_bin_iterate_sources(self.to_glib_none().0))
}
}
//fn iterate_sources(&self) -> /*Ignored*/Option<Iterator> {
// unsafe { TODO: call ffi::gst_bin_iterate_sources() }
//}
fn recalculate_latency(&self) -> Result<(), glib::error::BoolError> {
unsafe {
......
......@@ -9,7 +9,6 @@ use Context;
use ElementFactory;
use Error;
use Format;
use Iterator;
use Message;
use Object;
use Pad;
......@@ -131,11 +130,11 @@ pub trait ElementExt {
fn is_locked_state(&self) -> bool;
fn iterate_pads(&self) -> Option<Iterator>;
//fn iterate_pads(&self) -> /*Ignored*/Option<Iterator>;
fn iterate_sink_pads(&self) -> Option<Iterator>;
//fn iterate_sink_pads(&self) -> /*Ignored*/Option<Iterator>;
fn iterate_src_pads(&self) -> Option<Iterator>;
//fn iterate_src_pads(&self) -> /*Ignored*/Option<Iterator>;
fn link<P: IsA<Element>>(&self, dest: &P) -> Result<(), glib::error::BoolError>;
......@@ -347,23 +346,17 @@ impl<O: IsA<Element> + IsA<glib::object::Object>> ElementExt for O {
}
}
fn iterate_pads(&self) -> Option<Iterator> {
unsafe {
from_glib_full(ffi::gst_element_iterate_pads(self.to_glib_none().0))
}
}
//fn iterate_pads(&self) -> /*Ignored*/Option<Iterator> {
// unsafe { TODO: call ffi::gst_element_iterate_pads() }
//}
fn iterate_sink_pads(&self) -> Option<Iterator> {
unsafe {
from_glib_full(ffi::gst_element_iterate_sink_pads(self.to_glib_none().0))
}
}
//fn iterate_sink_pads(&self) -> /*Ignored*/Option<Iterator> {
// unsafe { TODO: call ffi::gst_element_iterate_sink_pads() }
//}
fn iterate_src_pads(&self) -> Option<Iterator> {
unsafe {
from_glib_full(ffi::gst_element_iterate_src_pads(self.to_glib_none().0))
}
}
//fn iterate_src_pads(&self) -> /*Ignored*/Option<Iterator> {
// unsafe { TODO: call ffi::gst_element_iterate_src_pads() }
//}
fn link<P: IsA<Element>>(&self, dest: &P) -> Result<(), glib::error::BoolError> {
unsafe {
......
......@@ -7,7 +7,6 @@ use Event;
use EventType;
use FlowReturn;
use Format;
use Iterator;
use Object;
use PadDirection;
use PadLinkCheck;
......@@ -130,9 +129,9 @@ pub trait PadExt {
fn is_linked(&self) -> bool;
fn iterate_internal_links(&self) -> Option<Iterator>;
//fn iterate_internal_links(&self) -> /*Ignored*/Option<Iterator>;
fn iterate_internal_links_default<'a, P: IsA<Object> + 'a, Q: Into<Option<&'a P>>>(&self, parent: Q) -> Option<Iterator>;
//fn iterate_internal_links_default<'a, P: IsA<Object> + 'a, Q: Into<Option<&'a P>>>(&self, parent: Q) -> /*Ignored*/Option<Iterator>;
fn link<P: IsA<Pad>>(&self, sinkpad: &P) -> PadLinkReturn;
......@@ -384,19 +383,13 @@ impl<O: IsA<Pad> + IsA<glib::object::Object>> PadExt for O {
}
}
fn iterate_internal_links(&self) -> Option<Iterator> {
unsafe {
from_glib_full(ffi::gst_pad_iterate_internal_links(self.to_glib_none().0))
}
}
//fn iterate_internal_links(&self) -> /*Ignored*/Option<Iterator> {
// unsafe { TODO: call ffi::gst_pad_iterate_internal_links() }
//}
fn iterate_internal_links_default<'a, P: IsA<Object> + 'a, Q: Into<Option<&'a P>>>(&self, parent: Q) -> Option<Iterator> {
let parent = parent.into();
let parent = parent.to_glib_none();
unsafe {
from_glib_full(ffi::gst_pad_iterate_internal_links_default(self.to_glib_none().0, parent.0))
}
}
//fn iterate_internal_links_default<'a, P: IsA<Object> + 'a, Q: Into<Option<&'a P>>>(&self, parent: Q) -> /*Ignored*/Option<Iterator> {
// unsafe { TODO: call ffi::gst_pad_iterate_internal_links_default() }
//}
fn link<P: IsA<Pad>>(&self, sinkpad: &P) -> PadLinkReturn {
unsafe {
......
// This file was generated by gir (6a48033) from gir-files (???)
// DO NOT EDIT
use Iterator;
use Object;
use Pad;
use ffi;
......@@ -21,14 +20,9 @@ glib_wrapper! {
}
impl ProxyPad {
pub fn iterate_internal_links_default<'a, P: IsA<Pad>, Q: IsA<Object> + 'a, R: Into<Option<&'a Q>>>(pad: &P, parent: R) -> Option<Iterator> {
skip_assert_initialized!();
let parent = parent.into();
let parent = parent.to_glib_none();
unsafe {
from_glib_full(ffi::gst_proxy_pad_iterate_internal_links_default(pad.to_glib_none().0, parent.0))
}
}
//pub fn iterate_internal_links_default<'a, P: IsA<Pad>, Q: IsA<Object> + 'a, R: Into<Option<&'a Q>>>(pad: &P, parent: R) -> /*Ignored*/Option<Iterator> {
// unsafe { TODO: call ffi::gst_proxy_pad_iterate_internal_links_default() }
//}
}
unsafe impl Send for ProxyPad {}
......
......@@ -11,13 +11,20 @@ use Element;
use glib;
use glib::IsA;
use glib::translate::{from_glib, ToGlibPtr};
use glib::translate::{from_glib, from_glib_full, ToGlibPtr, ToGlib};
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>;
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>;
}
impl<O: IsA<Bin>> BinExtManual for O {
......@@ -50,4 +57,40 @@ impl<O: IsA<Bin>> BinExtManual for O {
Ok(())
}
fn iterate_all_by_interface(&self, iface: glib::types::Type) -> ::Iterator<Element> {
unsafe {
from_glib_full(ffi::gst_bin_iterate_all_by_interface(self.to_glib_none().0, iface.to_glib()))
}
}
fn iterate_elements(&self) -> ::Iterator<Element> {
unsafe {
from_glib_full(ffi::gst_bin_iterate_elements(self.to_glib_none().0))
}
}
fn iterate_recurse(&self) -> ::Iterator<Element> {
unsafe {
from_glib_full(ffi::gst_bin_iterate_recurse(self.to_glib_none().0))
}
}
fn iterate_sinks(&self) -> ::Iterator<Element> {
unsafe {
from_glib_full(ffi::gst_bin_iterate_sinks(self.to_glib_none().0))
}
}
fn iterate_sorted(&self) -> ::Iterator<Element> {
unsafe {
from_glib_full(ffi::gst_bin_iterate_sorted(self.to_glib_none().0))
}
}
fn iterate_sources(&self) -> ::Iterator<Element> {
unsafe {
from_glib_full(ffi::gst_bin_iterate_sources(self.to_glib_none().0))
}
}
}
......@@ -10,9 +10,10 @@ use Element;
use glib;
use glib::IsA;
use glib::translate::{from_glib, from_glib_none, FromGlibPtrContainer, ToGlibPtr};
use glib::translate::{from_glib, from_glib_none, from_glib_full, FromGlibPtrContainer, ToGlibPtr};
use QueryRef;
use Event;
use Pad;
use PadTemplate;
use miniobject::MiniObject;
......@@ -87,6 +88,10 @@ pub trait ElementExtManual {
line: i32,
structure: ::Structure,
);
fn iterate_pads(&self) -> ::Iterator<Pad>;
fn iterate_sink_pads(&self) -> ::Iterator<Pad>;
fn iterate_src_pads(&self) -> ::Iterator<Pad>;
}
impl<O: IsA<Element>> ElementExtManual for O {
......@@ -210,6 +215,24 @@ impl<O: IsA<Element>> ElementExtManual for O {
);
}
}
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))
}
}
}
lazy_static!{
......
This diff is collapsed.
......@@ -147,7 +147,7 @@ pub trait PadExtManual {
fn set_iterate_internal_links_function<F>(&self, func: F)
where
F: Fn(&Pad, &::Object) -> ::Iterator + Send + Sync + 'static;
F: Fn(&Pad, &::Object) -> ::Iterator<Pad> + Send + Sync + 'static;
fn set_link_function<F>(&self, func: F)
where
......@@ -473,11 +473,11 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_iterate_internal_links_function<F>(&self, func: F)
where
F: Fn(&Pad, &::Object) -> ::Iterator + Send + Sync + 'static,
F: Fn(&Pad, &::Object) -> ::Iterator<Pad> + Send + Sync + 'static,
{
unsafe {
let func_box: Box<
Fn(&Pad, &::Object) -> ::Iterator + Send + Sync + 'static,
Fn(&Pad, &::Object) -> ::Iterator<Pad> + Send + Sync + 'static,
> = Box::new(func);
ffi::gst_pad_set_iterate_internal_links_function_full(
self.to_glib_none().0,
......@@ -755,7 +755,7 @@ unsafe extern "C" fn trampoline_iterate_internal_links_function(
) -> *mut ffi::GstIterator {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &::Object) -> ::Iterator + Send + Sync + 'static) =
let func: &&(Fn(&Pad, &::Object) -> ::Iterator<Pad> + Send + Sync + 'static) =
transmute((*pad).iterintlinkdata);
// Steal the iterator and return it
......
......@@ -77,4 +77,13 @@ impl ProxyPad {
}
}
}
pub fn iterate_internal_links_default<'a, P: IsA<Pad>, Q: IsA<Object> + 'a, R: Into<Option<&'a Q>>>(pad: &P, parent: R) -> Option<::Iterator<Pad>> {
skip_assert_initialized!();
let parent = parent.into();
let parent = parent.to_glib_none();
unsafe {
from_glib_full(ffi::gst_proxy_pad_iterate_internal_links_default(pad.to_glib_none().0, parent.0))
}
}
}
......@@ -392,6 +392,14 @@ impl<'a> glib::translate::ToGlibPtrMut<'a, *mut ffi::GstSegment> for Segment {
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*const ffi::GstSegment> for Segment {
#[inline]
unsafe fn from_glib_none(ptr: *const ffi::GstSegment) -> Self {
Segment(ptr::read(ptr))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut ffi::GstSegment> for Segment {
#[inline]
......@@ -400,6 +408,14 @@ impl glib::translate::FromGlibPtrNone<*mut ffi::GstSegment> for Segment {
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstSegment> for Segment {
#[inline]
unsafe fn from_glib_borrow(ptr: *mut ffi::GstSegment) -> Self {
Segment(ptr::read(ptr))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrFull<*mut ffi::GstSegment> for Segment {
#[inline]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment