mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-22 08:07:07 +00:00
Add example doing queries
This commit is contained in:
parent
5fa961f5b9
commit
77912e7164
1 changed files with 82 additions and 0 deletions
82
examples/src/bin/queries.rs
Normal file
82
examples/src/bin/queries.rs
Normal file
|
@ -0,0 +1,82 @@
|
|||
extern crate gstreamer as gst;
|
||||
use gst::*;
|
||||
|
||||
extern crate glib;
|
||||
use glib::*;
|
||||
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
let pipeline_str = env::args().collect::<Vec<String>>()[1..].join(" ");
|
||||
|
||||
gst::init().unwrap();
|
||||
|
||||
let main_loop = MainLoop::new(None, false);
|
||||
|
||||
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 main_loop_clone = main_loop.clone();
|
||||
|
||||
let pipeline_clone = pipeline.clone();
|
||||
glib::timeout_add_seconds(1, move || {
|
||||
let pipeline = &pipeline_clone;
|
||||
|
||||
//let pos = pipeline.query_position(Format::Time).unwrap_or(-1);
|
||||
//let dur = pipeline.query_duration(Format::Time).unwrap_or(-1);
|
||||
let pos = {
|
||||
let mut q = Query::new_position(Format::Time);
|
||||
pipeline.query(q.get_mut().unwrap());
|
||||
match q.view() {
|
||||
QueryView::Position(ref p) => {
|
||||
p.get().1
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
};
|
||||
|
||||
let dur = {
|
||||
let mut q = Query::new_duration(Format::Time);
|
||||
pipeline.query(q.get_mut().unwrap());
|
||||
match q.view() {
|
||||
QueryView::Duration(ref p) => {
|
||||
p.get().1
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
};
|
||||
|
||||
println!("{} / {}", pos, dur);
|
||||
|
||||
glib::Continue(true)
|
||||
});
|
||||
|
||||
//bus.add_signal_watch();
|
||||
//bus.connect_message(move |_, msg| {
|
||||
bus.add_watch(move |_, msg| {
|
||||
let main_loop = &main_loop_clone;
|
||||
match msg.view() {
|
||||
MessageView::Eos => main_loop.quit(),
|
||||
MessageView::Error(err) => {
|
||||
println!(
|
||||
"Error from {}: {} ({:?})",
|
||||
msg.get_src().get_path_string(),
|
||||
err.get_error(),
|
||||
err.get_debug()
|
||||
);
|
||||
main_loop.quit();
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
|
||||
glib::Continue(true)
|
||||
});
|
||||
|
||||
main_loop.run();
|
||||
|
||||
let ret = pipeline.set_state(gst::State::Null);
|
||||
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
||||
}
|
Loading…
Reference in a new issue