forked from mirrors/gstreamer-rs
Add gst::Iterator example with Resync handling
This commit is contained in:
parent
f7bce553cd
commit
8085c4ce8e
2 changed files with 33 additions and 0 deletions
22
examples/src/bin/iterator.rs
Normal file
22
examples/src/bin/iterator.rs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -429,6 +429,17 @@ mod tests {
|
|||
let vals: Vec<_> = it.map(|v| v.unwrap().get::<i32>().unwrap()).collect();
|
||||
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 it = Iterator::from_vec(vec);
|
||||
let mut vals = Vec::new();
|
||||
|
|
Loading…
Reference in a new issue