forked from mirrors/gstreamer-rs
Fix up some error handling in basic-tutorial-12
And minor code cleanup
This commit is contained in:
parent
b9fa4870ad
commit
890b47eef9
1 changed files with 7 additions and 14 deletions
|
@ -1,12 +1,11 @@
|
||||||
extern crate gstreamer as gst;
|
|
||||||
extern crate glib;
|
extern crate glib;
|
||||||
|
extern crate gstreamer as gst;
|
||||||
use gst::prelude::*;
|
use gst::prelude::*;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
extern crate failure;
|
extern crate failure;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
|
|
||||||
|
|
||||||
#[path = "../tutorials-common.rs"]
|
#[path = "../tutorials-common.rs"]
|
||||||
mod tutorials_common;
|
mod tutorials_common;
|
||||||
|
|
||||||
|
@ -19,19 +18,14 @@ fn tutorial_main() -> Result<(), Error> {
|
||||||
"https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm";
|
"https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm";
|
||||||
let pipeline = gst::parse_launch(&format!("playbin uri={}", uri))?;
|
let pipeline = gst::parse_launch(&format!("playbin uri={}", uri))?;
|
||||||
|
|
||||||
let mut is_live = false;
|
|
||||||
|
|
||||||
// Start playing
|
// Start playing
|
||||||
let ret = pipeline.set_state(gst::State::Playing);
|
let ret = pipeline.set_state(gst::State::Playing).into_result()?;
|
||||||
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
let is_live = ret == gst::StateChangeSuccess::NoPreroll;
|
||||||
if ret == gst::StateChangeReturn::NoPreroll {
|
|
||||||
is_live = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let main_loop = glib::MainLoop::new(None, false);
|
let main_loop = glib::MainLoop::new(None, false);
|
||||||
let main_loop_clone = main_loop.clone();
|
let main_loop_clone = main_loop.clone();
|
||||||
let pipeline_weak = pipeline.downgrade();
|
let pipeline_weak = pipeline.downgrade();
|
||||||
let bus = pipeline.get_bus().unwrap();
|
let bus = pipeline.get_bus().expect("Pipeline has no bus");
|
||||||
bus.add_watch(move |_, msg| {
|
bus.add_watch(move |_, msg| {
|
||||||
let pipeline = match pipeline_weak.upgrade() {
|
let pipeline = match pipeline_weak.upgrade() {
|
||||||
Some(pipeline) => pipeline,
|
Some(pipeline) => pipeline,
|
||||||
|
@ -63,7 +57,7 @@ fn tutorial_main() -> Result<(), Error> {
|
||||||
let percent = buffering.get_percent();
|
let percent = buffering.get_percent();
|
||||||
print!("Buffering ({}%)\r", percent);
|
print!("Buffering ({}%)\r", percent);
|
||||||
match std::io::stdout().flush() {
|
match std::io::stdout().flush() {
|
||||||
Ok(_) => {},
|
Ok(_) => {}
|
||||||
Err(err) => eprintln!("Failed: {}", err),
|
Err(err) => eprintln!("Failed: {}", err),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -87,15 +81,14 @@ fn tutorial_main() -> Result<(), Error> {
|
||||||
main_loop.run();
|
main_loop.run();
|
||||||
|
|
||||||
bus.remove_watch();
|
bus.remove_watch();
|
||||||
let ret = pipeline.set_state(gst::State::Null);
|
let _ = pipeline.set_state(gst::State::Null);
|
||||||
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match tutorials_common::run(tutorial_main) {
|
match tutorials_common::run(tutorial_main) {
|
||||||
Ok(_) => {},
|
Ok(_) => {}
|
||||||
Err(err) => eprintln!("Failed: {}", err),
|
Err(err) => eprintln!("Failed: {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue