gstreamer-rs/examples/src/bin/futures.rs

61 lines
1.6 KiB
Rust
Raw Normal View History

2017-07-31 13:12:08 +00:00
extern crate gstreamer as gst;
use gst::prelude::*;
2017-07-31 13:12:08 +00:00
extern crate futures;
use futures::executor::block_on;
use futures::prelude::*;
2017-07-31 13:12:08 +00:00
use std::env;
2017-11-12 18:07:02 +00:00
#[path = "../examples-common.rs"]
mod examples_common;
fn example_main() {
2017-07-31 13:12:08 +00:00
let pipeline_str = env::args().collect::<Vec<String>>()[1..].join(" ");
gst::init().unwrap();
let pipeline = gst::parse_launch(&pipeline_str).unwrap();
let bus = pipeline.get_bus().unwrap();
let ret = pipeline.set_state(gst::State::Playing);
assert_ne!(ret, gst::StateChangeReturn::Failure);
let messages = gst::BusStream::new(&bus)
.for_each(|msg| {
use gst::MessageView;
let quit = match msg.view() {
MessageView::Eos(..) => true,
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);
true
}
_ => false,
};
if quit {
Err(())
} else {
Ok(())
2017-07-31 13:12:08 +00:00
}
2018-10-08 12:02:23 +00:00
})
.and_then(|_| Ok(()));
2017-07-31 13:12:08 +00:00
let _ = block_on(messages);
2017-07-31 13:12:08 +00:00
let ret = pipeline.set_state(gst::State::Null);
assert_ne!(ret, gst::StateChangeReturn::Failure);
}
2017-11-12 18:07:02 +00:00
fn main() {
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common::run(example_main);
}