2018-11-05 10:10:14 +00:00
|
|
|
// This is a simplified rust-reimplementation of the gst-launch-<version>
|
|
|
|
// cli tool. It has no own parameters and simply parses the cli arguments
|
|
|
|
// as launch syntax.
|
|
|
|
// When the parsing succeeded, the pipeline is run until it exits.
|
|
|
|
// Main difference between this example and the launch example is the use of
|
|
|
|
// GLib's main loop to operate GStreamer's bus. This allows to also do other
|
|
|
|
// things from the main loop (timeouts, UI events, socket events, ...) instead
|
|
|
|
// of just handling messages from GStreamer's bus.
|
|
|
|
|
2017-07-11 18:21:56 +00:00
|
|
|
use std::env;
|
2017-07-05 16:10:58 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use gst::prelude::*;
|
|
|
|
|
2017-11-12 18:07:02 +00:00
|
|
|
#[path = "../examples-common.rs"]
|
|
|
|
mod examples_common;
|
|
|
|
|
|
|
|
fn example_main() {
|
2018-11-05 10:10:14 +00:00
|
|
|
// Get a string containing the passed pipeline launch syntax
|
2017-07-11 18:21:56 +00:00
|
|
|
let pipeline_str = env::args().collect::<Vec<String>>()[1..].join(" ");
|
|
|
|
|
2017-07-05 16:10:58 +00:00
|
|
|
gst::init().unwrap();
|
|
|
|
|
2018-11-05 10:10:14 +00:00
|
|
|
// Like teasered above, we use GLib's main loop to operate GStreamer's bus.
|
2017-08-17 14:58:15 +00:00
|
|
|
let main_loop = glib::MainLoop::new(None, false);
|
2017-07-05 16:10:58 +00:00
|
|
|
|
2018-11-05 10:10:14 +00:00
|
|
|
// Let GStreamer create a pipeline from the parsed launch syntax on the cli.
|
2017-07-11 18:21:56 +00:00
|
|
|
let pipeline = gst::parse_launch(&pipeline_str).unwrap();
|
2021-04-11 19:39:50 +00:00
|
|
|
let bus = pipeline.bus().unwrap();
|
2017-07-05 16:10:58 +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");
|
2017-07-05 16:10:58 +00:00
|
|
|
|
2017-07-11 16:29:16 +00:00
|
|
|
let main_loop_clone = main_loop.clone();
|
|
|
|
|
|
|
|
//bus.add_signal_watch();
|
2021-02-28 16:32:44 +00:00
|
|
|
//bus.connect_message(None, move |_, msg| {
|
2023-04-12 08:28:44 +00:00
|
|
|
let _bus_watch = 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 {:?}: {} ({:?})",
|
|
|
|
err.src().map(|s| s.path_string()),
|
|
|
|
err.error(),
|
|
|
|
err.debug()
|
|
|
|
);
|
|
|
|
main_loop.quit();
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
};
|
|
|
|
|
|
|
|
glib::Continue(true)
|
|
|
|
})
|
|
|
|
.expect("Failed to add bus watch");
|
2017-07-05 16:10:58 +00:00
|
|
|
|
2017-07-11 16:29:16 +00:00
|
|
|
main_loop.run();
|
2017-07-05 16:10:58 +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-05 16:10:58 +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);
|
|
|
|
}
|