mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-09-30 07:42:16 +00:00
c99928d030
FormatValue is now renamed to GenericFormattedValue and the API slightly changed. In addition there is now a FormattedValue trait, and a SpecificFormattedValue trait plus types for Bytes, Buffers and the existing ClockTime. This allows to create functions like Pad::query_duration<F: SpecificFormattedValue>() -> Option<F> and doesn't require the caller to unwrap the generic value anymore, which is completely unneeded in these cases. In addition, Segment became FormattedSegment<T> with API to upcast/downcast between the specific formatted values and the generic formatted value. This greatly simplifies usage of Segments.
98 lines
2.8 KiB
Rust
98 lines
2.8 KiB
Rust
extern crate gstreamer as gst;
|
|
use gst::prelude::*;
|
|
|
|
extern crate glib;
|
|
|
|
use std::env;
|
|
|
|
#[path = "../examples-common.rs"]
|
|
mod examples_common;
|
|
|
|
fn example_main() {
|
|
let pipeline_str = env::args().collect::<Vec<String>>()[1..].join(" ");
|
|
|
|
gst::init().unwrap();
|
|
|
|
let main_loop = glib::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 || {
|
|
use gst::QueryView;
|
|
|
|
let pipeline = &pipeline_clone;
|
|
|
|
//let pos = pipeline.query_position(gst::Format::Time).unwrap_or(-1);
|
|
//let dur = pipeline.query_duration(gst::Format::Time).unwrap_or(-1);
|
|
let pos = {
|
|
let mut q = gst::Query::new_position(gst::Format::Time);
|
|
if pipeline.query(q.get_mut().unwrap()) {
|
|
match q.view() {
|
|
QueryView::Position(ref p) => Some(p.get_result()),
|
|
_ => None,
|
|
}
|
|
} else {
|
|
None
|
|
}
|
|
}.and_then(|pos| pos.try_into_time().ok())
|
|
.unwrap();
|
|
|
|
let dur = {
|
|
let mut q = gst::Query::new_duration(gst::Format::Time);
|
|
if pipeline.query(q.get_mut().unwrap()) {
|
|
match q.view() {
|
|
QueryView::Duration(ref p) => Some(p.get_result()),
|
|
_ => None,
|
|
}
|
|
} else {
|
|
None
|
|
}
|
|
}.and_then(|dur| dur.try_into_time().ok())
|
|
.unwrap();
|
|
|
|
println!("{} / {}", pos, dur);
|
|
|
|
glib::Continue(true)
|
|
});
|
|
|
|
//bus.add_signal_watch();
|
|
//bus.connect_message(move |_, msg| {
|
|
bus.add_watch(move |_, msg| {
|
|
use gst::MessageView;
|
|
|
|
let main_loop = &main_loop_clone;
|
|
match msg.view() {
|
|
MessageView::Eos(..) => main_loop.quit(),
|
|
MessageView::Error(err) => {
|
|
println!(
|
|
"Error from {:?}: {} ({:?})",
|
|
msg.get_src().map(|s| s.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);
|
|
}
|
|
|
|
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);
|
|
}
|