Add basic-tutorial-1 from the GStreamer tutorials

https://cgit.freedesktop.org/gstreamer/gst-docs/tree/examples/tutorials/basic-tutorial-1.c
This commit is contained in:
Sebastian Dröge 2017-09-08 11:51:27 +03:00
parent 7dfab61390
commit 6f6db8ac47
3 changed files with 54 additions and 0 deletions

View file

@ -7,4 +7,5 @@ members = [
"gstreamer-player", "gstreamer-player",
"gstreamer-video", "gstreamer-video",
"examples", "examples",
"tutorials",
] ]

11
tutorials/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "tutorials"
version = "0.9.0"
authors = ["Sebastian Dröge <sebastian@centricular.com>"]
[dependencies]
glib = { version = "0.3", git = "https://github.com/gtk-rs/glib" }
gstreamer = { path = "../gstreamer" }
[badges]
travis-ci = { repository = "sdroege/gstreamer-rs", branch = "master" }

View file

@ -0,0 +1,42 @@
extern crate gstreamer as gst;
use gst::prelude::*;
use std::u64;
fn main() {
gst::init().unwrap();
let uri = "https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm";
let pipeline = gst::parse_launch(&format!("playbin uri={}", uri)).unwrap();
let ret = pipeline.set_state(gst::State::Playing);
assert_ne!(ret, gst::StateChangeReturn::Failure);
let bus = pipeline.get_bus().unwrap();
loop {
use gst::MessageView;
let msg = match bus.timed_pop(u64::MAX) {
None => break,
Some(msg) => msg,
};
match msg.view() {
MessageView::Eos(..) => break,
MessageView::Error(err) => {
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
err.get_error(),
err.get_debug()
);
break;
}
_ => (),
}
}
let ret = pipeline.set_state(gst::State::Null);
assert_ne!(ret, gst::StateChangeReturn::Failure);
}