2017-09-01 10:42:59 +00:00
|
|
|
#[cfg(feature = "tokio")]
|
2017-07-31 13:12:08 +00:00
|
|
|
extern crate gstreamer as gst;
|
2017-08-17 10:07:32 +00:00
|
|
|
#[cfg(feature = "tokio")]
|
2017-08-17 14:58:15 +00:00
|
|
|
use gst::prelude::*;
|
2017-07-31 13:12:08 +00:00
|
|
|
|
2017-08-17 10:07:32 +00:00
|
|
|
#[cfg(feature = "tokio")]
|
2017-07-31 13:12:08 +00:00
|
|
|
extern crate futures;
|
2017-08-17 10:07:32 +00:00
|
|
|
#[cfg(feature = "tokio")]
|
2017-07-31 13:12:08 +00:00
|
|
|
use futures::stream::Stream;
|
2017-08-17 10:07:32 +00:00
|
|
|
#[cfg(feature = "tokio")]
|
2017-07-31 13:12:08 +00:00
|
|
|
extern crate tokio_core;
|
2017-08-17 10:07:32 +00:00
|
|
|
#[cfg(feature = "tokio")]
|
2017-07-31 13:12:08 +00:00
|
|
|
use tokio_core::reactor::Core;
|
|
|
|
|
2017-08-17 10:07:32 +00:00
|
|
|
#[cfg(feature = "tokio")]
|
2017-07-31 13:12:08 +00:00
|
|
|
use std::env;
|
|
|
|
|
2017-11-12 18:07:02 +00:00
|
|
|
#[allow(unused_imports)]
|
|
|
|
#[path = "../examples-common.rs"]
|
|
|
|
mod examples_common;
|
|
|
|
|
2017-08-17 10:07:32 +00:00
|
|
|
#[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);
|
|
|
|
|
2017-08-17 15:16:48 +00:00
|
|
|
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!(
|
2017-11-16 11:58:56 +00:00
|
|
|
"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-08-17 10:07:32 +00:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-08-17 10:07:32 +00:00
|
|
|
#[cfg(not(feature = "tokio"))]
|
|
|
|
fn main() {
|
|
|
|
println!("Please compile with --features tokio");
|
|
|
|
}
|