2018-04-23 17:31:27 +00:00
|
|
|
use gst::prelude::*;
|
|
|
|
|
|
|
|
use futures::prelude::*;
|
|
|
|
|
|
|
|
use std::env;
|
|
|
|
|
|
|
|
#[path = "../examples-common.rs"]
|
|
|
|
mod examples_common;
|
|
|
|
|
2019-11-11 10:56:20 +00:00
|
|
|
async fn message_handler(loop_: glib::MainLoop, bus: gst::Bus) {
|
2020-01-22 07:23:10 +00:00
|
|
|
let mut messages = bus.stream();
|
2019-11-11 10:56:20 +00:00
|
|
|
|
|
|
|
while let Some(msg) = messages.next().await {
|
|
|
|
use gst::MessageView;
|
|
|
|
|
|
|
|
// Determine whether we want to quit: on EOS or error message
|
|
|
|
// we quit, otherwise simply continue.
|
|
|
|
match msg.view() {
|
|
|
|
MessageView::Eos(..) => loop_.quit(),
|
|
|
|
MessageView::Error(err) => {
|
|
|
|
println!(
|
|
|
|
"Error from {:?}: {} ({:?})",
|
2021-04-11 19:39:50 +00:00
|
|
|
err.src().map(|s| s.path_string()),
|
|
|
|
err.error(),
|
|
|
|
err.debug()
|
2019-11-11 10:56:20 +00:00
|
|
|
);
|
|
|
|
loop_.quit();
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-23 17:31:27 +00:00
|
|
|
fn example_main() {
|
2019-05-02 18:35:12 +00:00
|
|
|
// Get the default main context and make it also the thread default, then create
|
|
|
|
// a main loop for it
|
2018-04-23 17:31:27 +00:00
|
|
|
let ctx = glib::MainContext::default();
|
2019-05-02 18:35:12 +00:00
|
|
|
let loop_ = glib::MainLoop::new(Some(&ctx), false);
|
2018-04-23 17:31:27 +00:00
|
|
|
|
2019-05-02 18:35:12 +00:00
|
|
|
// Read the pipeline to launch from the commandline, using the launch syntax.
|
2018-04-23 17:31:27 +00:00
|
|
|
let pipeline_str = env::args().collect::<Vec<String>>()[1..].join(" ");
|
|
|
|
|
|
|
|
gst::init().unwrap();
|
|
|
|
|
2019-05-02 18:35:12 +00:00
|
|
|
// Create a pipeline from the launch-syntax given on the cli.
|
2018-04-23 17:31:27 +00:00
|
|
|
let pipeline = gst::parse_launch(&pipeline_str).unwrap();
|
2021-04-11 19:39:50 +00:00
|
|
|
let bus = pipeline.bus().unwrap();
|
2018-04-23 17:31:27 +00:00
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
pipeline
|
|
|
|
.set_state(gst::State::Playing)
|
|
|
|
.expect("Unable to set the pipeline to the `Playing` state");
|
2018-04-23 17:31:27 +00:00
|
|
|
|
2019-05-02 18:35:12 +00:00
|
|
|
// Spawn our message handling stream
|
2019-11-11 10:56:20 +00:00
|
|
|
ctx.spawn_local(message_handler(loop_.clone(), bus));
|
2019-05-02 18:35:12 +00:00
|
|
|
|
|
|
|
// And run until something is quitting the loop, i.e. an EOS
|
|
|
|
// or error message is received above
|
|
|
|
loop_.run();
|
2018-04-23 17:31:27 +00:00
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
pipeline
|
|
|
|
.set_state(gst::State::Null)
|
|
|
|
.expect("Unable to set the pipeline to the `Null` state");
|
2018-04-23 17:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2021-04-10 11:42:04 +00:00
|
|
|
// tutorials_common::run is only required to set up the application environment on macOS
|
|
|
|
// (but not necessary in normal Cocoa applications where this is set up automatically)
|
2018-04-23 17:31:27 +00:00
|
|
|
examples_common::run(example_main);
|
|
|
|
}
|