player: keep a reference to bus_watch_guard

In order to receive the message from the bus
the API enforces to keep a reference to the bus_watch_guard
otherwise the watch gets lost.
This commit is contained in:
Stéphane Cerveau 2023-11-28 17:16:12 +01:00
parent 24121856ee
commit 9c03de5d00

View file

@ -67,6 +67,7 @@ pub struct PlayerInner {
pipeline: RefCell<Option<gst::Pipeline>>,
current_state: Cell<PipelineState>,
n_video_sink: Cell<usize>,
bus_watch_guard: RefCell<Option<gst::bus::BusWatchGuard>>,
}
impl Player {
@ -76,6 +77,7 @@ impl Player {
pipeline: RefCell::new(None),
current_state: Cell::new(PipelineState::Stopped),
n_video_sink: Cell::new(0),
bus_watch_guard: RefCell::new(None),
}));
Ok(pipeline)
@ -176,12 +178,13 @@ impl Player {
let bus = pipeline.bus().expect("Pipeline had no bus");
let pipeline_weak = self.downgrade();
let _ = bus.add_watch_local(move |_bus, msg| {
let bus_watch_guard = bus.add_watch_local(move |_bus, msg| {
let pipeline = upgrade_weak!(pipeline_weak, glib::ControlFlow::Break);
pipeline.on_pipeline_message(msg);
glib::ControlFlow::Continue
})?;
*self.pipeline.borrow_mut() = Some(pipeline);
*self.bus_watch_guard.borrow_mut() = Some(bus_watch_guard);
}
self.set_state(new_state).map_err(|error| {