2017-07-03 15:08:43 +00:00
|
|
|
extern crate gstreamer as gst;
|
|
|
|
use gst::*;
|
|
|
|
|
|
|
|
use std::u64;
|
2017-07-11 18:21:56 +00:00
|
|
|
use std::env;
|
2017-08-17 13:17:02 +00:00
|
|
|
use std::process;
|
2017-07-03 15:08:43 +00:00
|
|
|
|
|
|
|
fn main() {
|
2017-07-11 18:21:56 +00:00
|
|
|
let pipeline_str = env::args().collect::<Vec<String>>()[1..].join(" ");
|
|
|
|
|
2017-07-03 15:08:43 +00:00
|
|
|
gst::init().unwrap();
|
|
|
|
|
2017-08-17 13:17:02 +00:00
|
|
|
let mut context = ParseContext::new();
|
|
|
|
let pipeline =
|
|
|
|
match gst::parse_launch_full(&pipeline_str, Some(&mut context), PARSE_FLAG_NONE) {
|
|
|
|
Ok(pipeline) => pipeline,
|
|
|
|
Err(err) => {
|
|
|
|
if let Some(ParseError::NoSuchElement) = err.kind::<ParseError>() {
|
|
|
|
println!("Missing element(s): {:?}", context.get_missing_elements());
|
|
|
|
} else {
|
|
|
|
println!("Failed to parse pipeline: {}", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
process::exit(-1);
|
|
|
|
}
|
|
|
|
};
|
2017-07-03 15:08:43 +00:00
|
|
|
let bus = pipeline.get_bus().unwrap();
|
|
|
|
|
|
|
|
let ret = pipeline.set_state(gst::State::Playing);
|
|
|
|
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
let msg = match bus.timed_pop(u64::MAX) {
|
|
|
|
None => break,
|
|
|
|
Some(msg) => msg,
|
|
|
|
};
|
|
|
|
|
|
|
|
match msg.view() {
|
2017-07-30 14:06:44 +00:00
|
|
|
MessageView::Eos(..) => break,
|
2017-07-03 15:08:43 +00:00
|
|
|
MessageView::Error(err) => {
|
2017-07-10 21:33:24 +00:00
|
|
|
println!(
|
|
|
|
"Error from {}: {} ({:?})",
|
|
|
|
msg.get_src().get_path_string(),
|
|
|
|
err.get_error(),
|
|
|
|
err.get_debug()
|
|
|
|
);
|
2017-07-03 15:08:43 +00:00
|
|
|
break;
|
2017-07-10 21:33:24 +00:00
|
|
|
}
|
2017-07-03 15:08:43 +00:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
2017-07-05 07:40:02 +00:00
|
|
|
|
|
|
|
let ret = pipeline.set_state(gst::State::Null);
|
|
|
|
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
2017-07-03 15:08:43 +00:00
|
|
|
}
|