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 /utils/togglerecord/examples | |
parent | aabfb61834375301e313fd8fd8b8fc6849b57695 (diff) |
Make sure to keep around and drop bus watches after usage in all the examples
Diffstat (limited to 'utils/togglerecord/examples')
-rw-r--r-- | utils/togglerecord/examples/gtk_recording.rs | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/utils/togglerecord/examples/gtk_recording.rs b/utils/togglerecord/examples/gtk_recording.rs index 7159a072..272a2d37 100644 --- a/utils/togglerecord/examples/gtk_recording.rs +++ b/utils/togglerecord/examples/gtk_recording.rs @@ -284,42 +284,43 @@ fn create_ui(app: >k::Application) { let bus = pipeline.bus().unwrap(); 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 {:?}: {} ({:?})", - msg.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 {:?}: {} ({:?})", + msg.src().map(|s| s.path_string()), + err.error(), + err.debug() + ); + app.quit(); + } + _ => (), + }; + + glib::Continue(true) + }) + .expect("Failed to add bus watch"); pipeline.set_state(gst::State::Playing).unwrap(); // Pipeline reference is owned by the closure below, so will be // destroyed once the app is destroyed let timeout_id = RefCell::new(Some(timeout_id)); + let bus_watch = RefCell::new(Some(bus_watch)); app.connect_shutdown(move |_| { + drop(bus_watch.borrow_mut().take()); pipeline.set_state(gst::State::Null).unwrap(); - bus.remove_watch().unwrap(); - if let Some(timeout_id) = timeout_id.borrow_mut().take() { timeout_id.remove(); } |