forked from mirrors/gstreamer-rs
50a1535771
And use it in the launch example to print more useful error information, like which elements are missing.
55 lines
1.5 KiB
Rust
55 lines
1.5 KiB
Rust
extern crate gstreamer as gst;
|
|
use gst::*;
|
|
|
|
use std::u64;
|
|
use std::env;
|
|
use std::process;
|
|
|
|
fn main() {
|
|
let pipeline_str = env::args().collect::<Vec<String>>()[1..].join(" ");
|
|
|
|
gst::init().unwrap();
|
|
|
|
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);
|
|
}
|
|
};
|
|
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() {
|
|
MessageView::Eos(..) => break,
|
|
MessageView::Error(err) => {
|
|
println!(
|
|
"Error from {}: {} ({:?})",
|
|
msg.get_src().get_path_string(),
|
|
err.get_error(),
|
|
err.get_debug()
|
|
);
|
|
break;
|
|
}
|
|
_ => (),
|
|
}
|
|
}
|
|
|
|
let ret = pipeline.set_state(gst::State::Null);
|
|
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
|
}
|