Fix up tutorials and examples for Message::get_src() returning an Option now

This commit is contained in:
Sebastian Dröge 2017-11-16 13:58:56 +02:00
parent 1dbc63dcb3
commit f895f484cc
20 changed files with 74 additions and 53 deletions

View file

@ -140,7 +140,9 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
MessageView::Error(err) => {
pipeline.set_state(gst::State::Null).into_result()?;
Err(ErrorMessage {
src: msg.get_src().get_path_string(),
src: msg.get_src()
.map(|s| s.get_path_string())
.unwrap_or(String::from("None")),
error: err.get_error().description().into(),
debug: err.get_debug(),
cause: err.get_error(),

View file

@ -111,7 +111,9 @@ fn main_loop(pipeline: gst::Pipeline, appsrc: gst_app::AppSrc) -> Result<(), Err
MessageView::Error(err) => {
pipeline.set_state(gst::State::Null).into_result()?;
Err(ErrorMessage {
src: msg.get_src().get_path_string(),
src: msg.get_src()
.map(|s| s.get_path_string())
.unwrap_or(String::from("None")),
error: err.get_error().description().into(),
debug: err.get_debug(),
cause: err.get_error(),

View file

@ -6,6 +6,7 @@ extern crate glib;
use std::env;
use std::error::Error as StdError;
#[cfg(feature = "v1_10")]
use std::sync::{Arc, Mutex};
extern crate failure;
@ -137,7 +138,12 @@ fn example_main() -> Result<(), Error> {
);
#[cfg(not(feature = "v1_10"))]
gst_element_error!(dbin, gst::LibraryError::Failed, ("Failed to insert sink"));
gst_element_error!(
dbin,
gst::LibraryError::Failed,
("Failed to insert sink"),
["{}", err]
);
}
});
@ -169,7 +175,9 @@ fn example_main() -> Result<(), Error> {
.expect("error-details message without actual error"),
_ => Err(
ErrorMessage {
src: msg.get_src().get_path_string(),
src: msg.get_src()
.map(|s| s.get_path_string())
.unwrap_or(String::from("None")),
error: err.get_error().description().into(),
debug: err.get_debug(),
cause: err.get_error(),
@ -180,7 +188,9 @@ fn example_main() -> Result<(), Error> {
#[cfg(not(feature = "v1_10"))]
{
Err(ErrorMessage {
src: msg.get_src().get_path_string(),
src: msg.get_src()
.map(|s| s.get_path_string())
.unwrap_or(String::from("None")),
error: err.get_error().description().into(),
debug: err.get_debug(),
cause: err.get_error(),
@ -190,8 +200,8 @@ fn example_main() -> Result<(), Error> {
}
MessageView::StateChanged(s) => {
println!(
"State changed from {}: {:?} -> {:?} ({:?})",
msg.get_src().get_path_string(),
"State changed from {:?}: {:?} -> {:?} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
s.get_old(),
s.get_current(),
s.get_pending()

View file

@ -44,8 +44,8 @@ fn example_main() {
}
MessageView::Error(err) => {
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);

View file

@ -92,8 +92,8 @@ fn create_ui(app: &gtk::Application) {
MessageView::Eos(..) => gtk::main_quit(),
MessageView::Error(err) => {
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);

View file

@ -162,8 +162,8 @@ fn create_ui(app: &gtk::Application) {
MessageView::Eos(..) => gtk::main_quit(),
MessageView::Error(err) => {
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);

View file

@ -38,8 +38,8 @@ fn example_main() {
MessageView::Eos(..) => break,
MessageView::Error(err) => {
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);

View file

@ -33,8 +33,8 @@ fn example_main() {
MessageView::Eos(..) => main_loop.quit(),
MessageView::Error(err) => {
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);

View file

@ -60,8 +60,8 @@ fn example_main() {
MessageView::Eos(..) => break,
MessageView::Error(err) => {
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);

View file

@ -75,8 +75,8 @@ fn example_main() {
MessageView::Eos(..) => break,
MessageView::Error(err) => {
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);

View file

@ -72,8 +72,8 @@ fn example_main() {
MessageView::Eos(..) => main_loop.quit(),
MessageView::Error(err) => {
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);

View file

@ -62,8 +62,8 @@ fn example_main() {
MessageView::Eos(_) | MessageView::AsyncDone(_) => break,
MessageView::Error(err) => {
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);

View file

@ -40,8 +40,8 @@ fn example_main() {
MessageView::Eos(..) => true,
MessageView::Error(err) => {
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);

View file

@ -26,8 +26,8 @@ fn tutorial_main() {
MessageView::Eos(..) => break,
MessageView::Error(err) => {
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);

View file

@ -39,8 +39,8 @@ fn tutorial_main() {
match msg.view() {
MessageView::Error(err) => {
eprintln!(
"Error received from element {}: {}",
msg.get_src().get_path_string(),
"Error received from element {:?}: {}",
msg.get_src().map(|s| s.get_path_string()),
err.get_error()
);
eprintln!("Debugging information: {:?}", err.get_debug());

View file

@ -92,20 +92,22 @@ fn tutorial_main() {
match msg.view() {
MessageView::Error(err) => {
eprintln!(
"Error received from element {}: {}",
msg.get_src().get_path_string(),
"Error received from element {:?} {}",
msg.get_src().map(|s| s.get_path_string()),
err.get_error()
);
eprintln!("Debugging information: {:?}", err.get_debug());
break;
}
MessageView::StateChanged(s) => if msg.get_src() == pipeline {
MessageView::StateChanged(s) => {
if msg.get_src().map(|s| s == pipeline).unwrap_or(false) {
println!(
"Pipeline state changed from {:?} to {:?}",
s.get_old(),
s.get_current()
);
},
}
}
MessageView::Eos(..) => break,
_ => (),
}

View file

@ -101,8 +101,8 @@ fn handle_message(custom_data: &mut CustomData, msg: &gst::GstRc<gst::MessageRef
match msg.view() {
MessageView::Error(err) => {
println!(
"Error received from element {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error received from element {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);
@ -116,7 +116,10 @@ fn handle_message(custom_data: &mut CustomData, msg: &gst::GstRc<gst::MessageRef
// The duration has changed, mark the current one as invalid
custom_data.duration = gst::CLOCK_TIME_NONE;
}
MessageView::StateChanged(state) => if msg.get_src() == custom_data.playbin {
MessageView::StateChanged(state) => if msg.get_src()
.map(|s| s == custom_data.playbin)
.unwrap_or(false)
{
let new_state = state.get_current();
let old_state = state.get_old();

View file

@ -337,17 +337,19 @@ mod tutorial5 {
// This is called when an error message is posted on the bus
gst::MessageView::Error(err) => {
println!(
"Error from {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);
}
// This is called when the pipeline changes states. We use it to
// keep track of the current state.
gst::MessageView::StateChanged(view) => if msg.get_src() == pipeline {
gst::MessageView::StateChanged(view) => {
if msg.get_src().map(|s| s == pipeline).unwrap_or(false) {
println!("State set to {:?}", view.get_current());
},
}
}
_ => (),
}
});

View file

@ -125,8 +125,8 @@ fn tutorial_main() {
match msg.view() {
MessageView::Error(err) => {
println!(
"Error received from element {}: {} ({:?})",
msg.get_src().get_path_string(),
"Error received from element {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()),
err.get_error(),
err.get_debug()
);
@ -138,7 +138,7 @@ fn tutorial_main() {
}
MessageView::StateChanged(state) =>
// We are only interested in state-changed messages from the pipeline
if msg.get_src() == pipeline {
if msg.get_src().map(|s| s == pipeline).unwrap_or(false) {
let new_state = state.get_current();
let old_state = state.get_old();

View file

@ -78,8 +78,8 @@ fn tutorial_main() {
match msg.view() {
MessageView::Error(err) => {
eprintln!(
"Error received from element {}: {}",
msg.get_src().get_path_string(),
"Error received from element {:?}: {}",
msg.get_src().map(|s| s.get_path_string()),
err.get_error()
);
eprintln!("Debugging information: {:?}", err.get_debug());