mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-26 03:21:03 +00:00
Add futures example using the GLib futures executor
This commit is contained in:
parent
4b4f369200
commit
a4c3c7cd76
2 changed files with 69 additions and 0 deletions
|
@ -30,6 +30,7 @@ gtkvideooverlay = ["gtk", "gdk", "gio"]
|
||||||
gtkvideooverlay-x11 = ["gtkvideooverlay"]
|
gtkvideooverlay-x11 = ["gtkvideooverlay"]
|
||||||
gtkvideooverlay-quartz = ["gtkvideooverlay"]
|
gtkvideooverlay-quartz = ["gtkvideooverlay"]
|
||||||
generic-futures = ["gstreamer/futures", "futures"]
|
generic-futures = ["gstreamer/futures", "futures"]
|
||||||
|
glib-futures = ["generic-futures", "glib/futures"]
|
||||||
gst-rtsp-server = ["gstreamer-rtsp-server"]
|
gst-rtsp-server = ["gstreamer-rtsp-server"]
|
||||||
gst-rtsp-server-record = ["gstreamer-rtsp-server", "gstreamer-rtsp", "gio"]
|
gst-rtsp-server-record = ["gstreamer-rtsp-server", "gstreamer-rtsp", "gio"]
|
||||||
default-features = []
|
default-features = []
|
||||||
|
@ -100,6 +101,11 @@ name = "toc"
|
||||||
name = "futures"
|
name = "futures"
|
||||||
required-features = ["generic-futures"]
|
required-features = ["generic-futures"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "glib-futures"
|
||||||
|
required-features = ["glib-futures"]
|
||||||
|
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "rtsp-server-record"
|
name = "rtsp-server-record"
|
||||||
required-features = ["gst-rtsp-server-record"]
|
required-features = ["gst-rtsp-server-record"]
|
||||||
|
|
63
examples/src/bin/glib-futures.rs
Normal file
63
examples/src/bin/glib-futures.rs
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
extern crate gstreamer as gst;
|
||||||
|
use gst::prelude::*;
|
||||||
|
|
||||||
|
extern crate glib;
|
||||||
|
|
||||||
|
extern crate futures;
|
||||||
|
use futures::prelude::*;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
#[path = "../examples-common.rs"]
|
||||||
|
mod examples_common;
|
||||||
|
|
||||||
|
fn example_main() {
|
||||||
|
let ctx = glib::MainContext::default();
|
||||||
|
|
||||||
|
let pipeline_str = env::args().collect::<Vec<String>>()[1..].join(" ");
|
||||||
|
|
||||||
|
gst::init().unwrap();
|
||||||
|
|
||||||
|
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 messages = gst::BusStream::new(&bus)
|
||||||
|
.for_each(|msg| {
|
||||||
|
use gst::MessageView;
|
||||||
|
|
||||||
|
let quit = match msg.view() {
|
||||||
|
MessageView::Eos(..) => true,
|
||||||
|
MessageView::Error(err) => {
|
||||||
|
println!(
|
||||||
|
"Error from {:?}: {} ({:?})",
|
||||||
|
err.get_src().map(|s| s.get_path_string()),
|
||||||
|
err.get_error(),
|
||||||
|
err.get_debug()
|
||||||
|
);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
if quit {
|
||||||
|
Err(())
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.and_then(|_| Ok(()));
|
||||||
|
|
||||||
|
let _ = ctx.block_on(messages);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
Loading…
Reference in a new issue