2018-11-05 10:10:14 +00:00
|
|
|
// This example demonstrates how to use the gstreamer crate in conjunction
|
|
|
|
// with the future trait. The example waits for either an error to occur,
|
|
|
|
// or for an EOS message. When a message notifying about either of both
|
|
|
|
// is received, the future is resolved.
|
|
|
|
|
2017-07-31 13:12:08 +00:00
|
|
|
use std::env;
|
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use futures::{executor::LocalPool, prelude::*};
|
|
|
|
use gst::prelude::*;
|
|
|
|
|
2017-11-12 18:07:02 +00:00
|
|
|
#[path = "../examples-common.rs"]
|
|
|
|
mod examples_common;
|
|
|
|
|
2019-11-11 10:56:20 +00:00
|
|
|
async fn message_loop(bus: gst::Bus) {
|
2020-01-22 07:23:10 +00:00
|
|
|
let mut messages = bus.stream();
|
2019-05-02 18:35:12 +00:00
|
|
|
|
2019-11-11 10:56:20 +00:00
|
|
|
while let Some(msg) = messages.next().await {
|
2019-05-02 18:35:12 +00:00
|
|
|
use gst::MessageView;
|
|
|
|
|
|
|
|
// Determine whether we want to quit: on EOS or error message
|
|
|
|
// we quit, otherwise simply continue.
|
|
|
|
match msg.view() {
|
2019-11-11 10:56:20 +00:00
|
|
|
MessageView::Eos(..) => break,
|
2019-05-02 18:35:12 +00:00
|
|
|
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-05-02 18:35:12 +00:00
|
|
|
);
|
2019-11-11 10:56:20 +00:00
|
|
|
break;
|
2017-07-31 13:12:08 +00:00
|
|
|
}
|
2019-05-02 18:35:12 +00:00
|
|
|
_ => (),
|
|
|
|
};
|
2019-11-11 10:56:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn example_main() {
|
|
|
|
// Read the pipeline to launch from the commandline, using the launch syntax.
|
|
|
|
let pipeline_str = env::args().collect::<Vec<String>>()[1..].join(" ");
|
|
|
|
|
|
|
|
gst::init().unwrap();
|
|
|
|
|
|
|
|
// Create a pipeline from the launch-syntax given on the cli.
|
|
|
|
let pipeline = gst::parse_launch(&pipeline_str).unwrap();
|
2021-04-11 19:39:50 +00:00
|
|
|
let bus = pipeline.bus().unwrap();
|
2019-05-02 18:35:12 +00:00
|
|
|
|
2019-11-11 10:56:20 +00:00
|
|
|
pipeline
|
|
|
|
.set_state(gst::State::Playing)
|
|
|
|
.expect("Unable to set the pipeline to the `Playing` state");
|
2019-05-02 18:35:12 +00:00
|
|
|
|
2019-11-11 10:56:20 +00:00
|
|
|
// Use a LocalPool as executor. This runs single threaded on this very thread.
|
|
|
|
let mut pool = LocalPool::new();
|
2017-07-31 13:12:08 +00:00
|
|
|
|
2019-11-11 10:56:20 +00:00
|
|
|
// Run until our message loop finishes, e.g. EOS/error happens
|
|
|
|
pool.run_until(message_loop(bus));
|
2017-07-31 13:12:08 +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");
|
2017-07-31 13:12:08 +00:00
|
|
|
}
|
2017-08-17 10:07:32 +00:00
|
|
|
|
2017-11-12 18:07:02 +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)
|
2017-11-12 18:07:02 +00:00
|
|
|
examples_common::run(example_main);
|
|
|
|
}
|