diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2023-04-14 12:46:43 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2023-04-14 12:46:43 +0300 |
commit | 47159ad3c224e01e634a66d0afa3baa43066c228 (patch) | |
tree | de56561d41545c31d79eaf73721f8b749941f66b /video | |
parent | aabfb61834375301e313fd8fd8b8fc6849b57695 (diff) |
Make sure to keep around and drop bus watches after usage in all the examples
Diffstat (limited to 'video')
-rw-r--r-- | video/gtk4/examples/gtksink.rs | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/video/gtk4/examples/gtksink.rs b/video/gtk4/examples/gtksink.rs index bdb3da2e1..3dddce252 100644 --- a/video/gtk4/examples/gtksink.rs +++ b/video/gtk4/examples/gtksink.rs @@ -95,42 +95,44 @@ fn create_ui(app: >k::Application) { .expect("Unable to set the pipeline to the `Playing` state"); let app_weak = app.downgrade(); - bus.add_watch_local(move |_, msg| { - use gst::MessageView; - - let app = match app_weak.upgrade() { - Some(app) => app, - None => return glib::Continue(false), - }; - - match msg.view() { - MessageView::Eos(..) => app.quit(), - MessageView::Error(err) => { - println!( - "Error from {:?}: {} ({:?})", - err.src().map(|s| s.path_string()), - err.error(), - err.debug() - ); - app.quit(); - } - _ => (), - }; - - glib::Continue(true) - }) - .expect("Failed to add bus watch"); + let bus_watch = bus + .add_watch_local(move |_, msg| { + use gst::MessageView; + + let app = match app_weak.upgrade() { + Some(app) => app, + None => return glib::Continue(false), + }; + + match msg.view() { + MessageView::Eos(..) => app.quit(), + MessageView::Error(err) => { + println!( + "Error from {:?}: {} ({:?})", + err.src().map(|s| s.path_string()), + err.error(), + err.debug() + ); + app.quit(); + } + _ => (), + }; + + glib::Continue(true) + }) + .expect("Failed to add bus watch"); let timeout_id = RefCell::new(Some(timeout_id)); let pipeline = RefCell::new(Some(pipeline)); + let bus_watch = RefCell::new(Some(bus_watch)); app.connect_shutdown(move |_| { window.close(); + drop(bus_watch.borrow_mut().take()); if let Some(pipeline) = pipeline.borrow_mut().take() { pipeline .set_state(gst::State::Null) .expect("Unable to set the pipeline to the `Null` state"); - pipeline.bus().unwrap().remove_watch().unwrap(); } if let Some(timeout_id) = timeout_id.borrow_mut().take() { |