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

77 lines
1.9 KiB
Rust
Raw Normal View History

#[cfg(feature = "tokio")]
2017-07-31 13:12:08 +00:00
extern crate gstreamer as gst;
#[cfg(feature = "tokio")]
use gst::prelude::*;
2017-07-31 13:12:08 +00:00
#[cfg(feature = "tokio")]
2017-07-31 13:12:08 +00:00
extern crate futures;
#[cfg(feature = "tokio")]
2017-07-31 13:12:08 +00:00
use futures::stream::Stream;
#[cfg(feature = "tokio")]
2017-07-31 13:12:08 +00:00
extern crate tokio_core;
#[cfg(feature = "tokio")]
2017-07-31 13:12:08 +00:00
use tokio_core::reactor::Core;
#[cfg(feature = "tokio")]
2017-07-31 13:12:08 +00:00
use std::env;
#[cfg(feature = "tokio")]
2017-11-12 18:07:02 +00:00
#[path = "../examples-common.rs"]
mod examples_common;
#[cfg(feature = "tokio")]
2017-11-12 18:07:02 +00:00
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 mut core = Core::new().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;
2017-07-31 13:12:08 +00:00
let quit = match msg.view() {
MessageView::Eos(..) => true,
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
2017-07-31 13:12:08 +00:00
err.get_error(),
err.get_debug()
);
true
}
_ => false,
};
if quit {
Err(())
} else {
Ok(())
}
});
let _ = core.run(messages);
let ret = pipeline.set_state(gst::State::Null);
assert_ne!(ret, gst::StateChangeReturn::Failure);
}
2017-11-12 18:07:02 +00:00
#[cfg(feature = "tokio")]
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);
}
#[cfg(not(feature = "tokio"))]
fn main() {
println!("Please compile with --features tokio");
}