Make sure to keep around and drop bus watches after usage in all the examples

This commit is contained in:
Sebastian Dröge 2023-04-14 12:46:43 +03:00
parent aabfb61834
commit 47159ad3c2
8 changed files with 217 additions and 206 deletions

View file

@ -192,7 +192,8 @@ fn main() {
let bus = pipeline.bus().unwrap();
let l_clone = l.clone();
bus.add_watch(move |_, msg| {
let _bus_watch = bus
.add_watch(move |_, msg| {
use gst::MessageView;
match msg.view() {

View file

@ -108,7 +108,8 @@ fn main() {
let terminated_count = Arc::new(AtomicU32::new(0));
let pipeline_clone = pipeline.clone();
let l_clone = l.clone();
bus.add_watch(move |_, msg| {
let _bus_watch = bus
.add_watch(move |_, msg| {
use gst::MessageView;
match msg.view() {
MessageView::Eos(_) => {

View file

@ -170,7 +170,8 @@ fn run(pipeline: gst::Pipeline) {
let bus = pipeline.bus().unwrap();
let l_clone = l.clone();
bus.add_watch(move |_, msg| {
let _bus_watch = bus
.add_watch(move |_, msg| {
use gst::MessageView;
match msg.view() {
MessageView::Eos(_) => {

View file

@ -135,7 +135,8 @@ fn multiple_contexts_queue() {
let bus = pipeline.bus().unwrap();
let l_clone = l.clone();
bus.add_watch(move |_, msg| {
let _bus_watch = bus
.add_watch(move |_, msg| {
use gst::MessageView;
match msg.view() {
@ -281,7 +282,8 @@ fn multiple_contexts_proxy() {
let bus = pipeline.bus().unwrap();
let l_clone = l.clone();
bus.add_watch(move |_, msg| {
let _bus_watch = bus
.add_watch(move |_, msg| {
use gst::MessageView;
match msg.view() {
@ -405,7 +407,7 @@ fn eos() {
});
let l_clone = l.clone();
pipeline
let _bus_watch = pipeline
.bus()
.unwrap()
.add_watch(move |_, msg| {
@ -561,7 +563,7 @@ fn premature_shutdown() {
});
let l_clone = l.clone();
pipeline
let _bus_watch = pipeline
.bus()
.unwrap()
.add_watch(move |_, msg| {
@ -657,7 +659,7 @@ fn socket_play_null_play() {
});
let l_clone = l.clone();
pipeline
let _bus_watch = pipeline
.bus()
.unwrap()
.add_watch(move |_, msg| {

View file

@ -154,7 +154,8 @@ fn create_ui(app: &gtk::Application) {
let bus = pipeline.bus().unwrap();
let app_weak = app.downgrade();
bus.add_watch_local(move |_, msg| {
let bus_watch = bus
.add_watch_local(move |_, msg| {
use gst::MessageView;
let app = match app_weak.upgrade() {
@ -185,11 +186,11 @@ fn create_ui(app: &gtk::Application) {
// 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();
}

View file

@ -10,7 +10,7 @@
use gio::prelude::*;
use gst::{glib, prelude::*};
use gtk::prelude::*;
use std::cell::Cell;
use std::cell::{Cell, RefCell};
struct DroppingProbe(glib::WeakRef<gst::Pad>, Option<gst::PadProbeId>);
@ -106,7 +106,7 @@ fn create_window(app: &gtk::Application) {
}
});
{
let bus_watch = {
let bus = pipeline.bus().unwrap();
let window = window.downgrade();
bus.add_watch_local(move |_, msg| {
@ -136,8 +136,8 @@ fn create_window(app: &gtk::Application) {
glib::Continue(true)
})
.unwrap();
}
.unwrap()
};
{
let pipeline = pipeline.clone();
@ -148,7 +148,9 @@ fn create_window(app: &gtk::Application) {
});
}
let bus_watch = RefCell::new(Some(bus_watch));
window.connect_unrealize(move |_| {
drop(bus_watch.borrow_mut().take());
pipeline
.set_state(gst::State::Null)
.expect("Failed to stop pipeline");

View file

@ -284,7 +284,8 @@ fn create_ui(app: &gtk::Application) {
let bus = pipeline.bus().unwrap();
let app_weak = app.downgrade();
bus.add_watch_local(move |_, msg| {
let bus_watch = bus
.add_watch_local(move |_, msg| {
use gst::MessageView;
let app = match app_weak.upgrade() {
@ -315,11 +316,11 @@ fn create_ui(app: &gtk::Application) {
// 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();
}

View file

@ -95,7 +95,8 @@ fn create_ui(app: &gtk::Application) {
.expect("Unable to set the pipeline to the `Playing` state");
let app_weak = app.downgrade();
bus.add_watch_local(move |_, msg| {
let bus_watch = bus
.add_watch_local(move |_, msg| {
use gst::MessageView;
let app = match app_weak.upgrade() {
@ -123,14 +124,15 @@ fn create_ui(app: &gtk::Application) {
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() {