Add gst::Iterator example with Resync handling

This commit is contained in:
Sebastian Dröge 2017-09-17 14:59:01 +03:00
parent f7bce553cd
commit 8085c4ce8e
2 changed files with 33 additions and 0 deletions

View file

@ -0,0 +1,22 @@
extern crate gstreamer as gst;
use gst::prelude::*;
fn main() {
gst::init().unwrap();
let identity = gst::ElementFactory::make("identity", None).unwrap();
let mut iter = identity.iterate_pads().unwrap();
while let Some(res) = iter.next() {
match res {
Ok(pad) => println!("Pad: {}", pad.get::<gst::Pad>().unwrap().get_name()),
Err(gst::IteratorError::Resync) => {
println!("Iterator resync");
iter.resync();
}
Err(gst::IteratorError::Error) => {
println!("Error");
break;
}
}
}
}

View file

@ -429,6 +429,17 @@ mod tests {
let vals: Vec<_> = it.map(|v| v.unwrap().get::<i32>().unwrap()).collect(); let vals: Vec<_> = it.map(|v| v.unwrap().get::<i32>().unwrap()).collect();
assert_eq!(vals, [1, 2, 3]); assert_eq!(vals, [1, 2, 3]);
let vec = vec![1i32, 2, 3];
let mut it = Iterator::from_vec(vec);
let mut vals = Vec::new();
while let Some(res) = it.next() {
match res {
Ok(v) => vals.push(v.get::<i32>().unwrap()),
_ => unreachable!(),
}
}
assert_eq!(vals, [1, 2, 3]);
let vec = vec![1i32, 2, 3]; let vec = vec![1i32, 2, 3];
let it = Iterator::from_vec(vec); let it = Iterator::from_vec(vec);
let mut vals = Vec::new(); let mut vals = Vec::new();