Tutorials: message handlers: invoke generic Message method from the concrete message

Generic methods for events, messages and queries can now be invoked from the concrete type.
This commit is contained in:
fengalin 2018-01-29 15:26:01 +01:00 committed by Sebastian Dröge
parent 21c687f256
commit ce28fed070
8 changed files with 24 additions and 24 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -238,8 +238,8 @@ mod tutorial5 {
.get_bus() .get_bus()
.unwrap() .unwrap()
.connect_message(move |_, msg| match msg.view() { .connect_message(move |_, msg| match msg.view() {
gst::MessageView::Application(_) => { gst::MessageView::Application(application) => {
if msg.get_structure().map(|s| s.get_name()) == Some("tags-changed") { if application.get_structure().map(|s| s.get_name()) == Some("tags-changed") {
analyze_streams(&pipeline, &textbuf); analyze_streams(&pipeline, &textbuf);
} }
} }
@ -339,16 +339,16 @@ mod tutorial5 {
gst::MessageView::Error(err) => { gst::MessageView::Error(err) => {
println!( println!(
"Error from {:?}: {} ({:?})", "Error from {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()), err.get_src().map(|s| s.get_path_string()),
err.get_error(), err.get_error(),
err.get_debug() err.get_debug()
); );
} }
// This is called when the pipeline changes states. We use it to // This is called when the pipeline changes states. We use it to
// keep track of the current state. // keep track of the current state.
gst::MessageView::StateChanged(view) => { gst::MessageView::StateChanged(state_changed) => {
if msg.get_src().map(|s| s == pipeline).unwrap_or(false) { if state_changed.get_src().map(|s| s == pipeline).unwrap_or(false) {
println!("State set to {:?}", view.get_current()); println!("State set to {:?}", state_changed.get_current());
} }
} }
_ => (), _ => (),

View file

@ -126,7 +126,7 @@ fn tutorial_main() {
MessageView::Error(err) => { MessageView::Error(err) => {
println!( println!(
"Error received from element {:?}: {} ({:?})", "Error received from element {:?}: {} ({:?})",
msg.get_src().map(|s| s.get_path_string()), err.get_src().map(|s| s.get_path_string()),
err.get_error(), err.get_error(),
err.get_debug() err.get_debug()
); );
@ -136,11 +136,11 @@ fn tutorial_main() {
println!("End-Of-Stream reached."); println!("End-Of-Stream reached.");
break; break;
} }
MessageView::StateChanged(state) => MessageView::StateChanged(state_changed) =>
// We are only interested in state-changed messages from the pipeline // We are only interested in state-changed messages from the pipeline
if msg.get_src().map(|s| s == pipeline).unwrap_or(false) { if state_changed.get_src().map(|s| s == pipeline).unwrap_or(false) {
let new_state = state.get_current(); let new_state = state_changed.get_current();
let old_state = state.get_old(); let old_state = state_changed.get_old();
println!( println!(
"Pipeline state changed from {:?} to {:?}", "Pipeline state changed from {:?} to {:?}",

View file

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

View file

@ -242,7 +242,7 @@ fn main() {
let main_loop = &main_loop_clone; let main_loop = &main_loop_clone;
eprintln!( eprintln!(
"Error received from element {:?}: {}", "Error received from element {:?}: {}",
msg.get_src().map(|s| s.get_path_string()), err.get_src().map(|s| s.get_path_string()),
err.get_error() err.get_error()
); );
eprintln!("Debugging information: {:?}", err.get_debug()); eprintln!("Debugging information: {:?}", err.get_debug());