Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@onestream.live>2022-04-08 16:33:00 +0300
committerGuillaume Desmottes <guillaume.desmottes@onestream.live>2022-04-08 17:53:12 +0300
commit00416a991ce5e24ae622bff4eb4a3054c5aa77e3 (patch)
treeee964bd4e3eefefe62dd7872463cf0c2e6dd7018
parent8edf13ad3e1c1028a2c1df8010c4bf0c84ac9d37 (diff)
uriplaylistbin: break reference cycle
Passing ownership of item to the probe callback was introducing a reference cycle as the item is owning the sinkpad.
-rw-r--r--utils/uriplaylistbin/src/uriplaylistbin/imp.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/utils/uriplaylistbin/src/uriplaylistbin/imp.rs b/utils/uriplaylistbin/src/uriplaylistbin/imp.rs
index 92f0e85df..803b1386c 100644
--- a/utils/uriplaylistbin/src/uriplaylistbin/imp.rs
+++ b/utils/uriplaylistbin/src/uriplaylistbin/imp.rs
@@ -6,8 +6,8 @@
//
// SPDX-License-Identifier: MPL-2.0
-use std::sync::Arc;
use std::sync::{mpsc, Mutex, MutexGuard};
+use std::sync::{Arc, Weak};
use gst::glib;
use gst::prelude::*;
@@ -621,6 +621,14 @@ impl Item {
_ => panic!("invalid state: {:?}", inner.state),
}
}
+
+ fn downgrade(&self) -> Weak<Mutex<ItemInner>> {
+ Arc::downgrade(&self.inner)
+ }
+
+ fn upgrade(weak: &Weak<Mutex<ItemInner>>) -> Option<Item> {
+ weak.upgrade().map(|inner| Item { inner })
+ }
}
#[derive(Debug, Clone)]
@@ -1415,7 +1423,8 @@ impl UriPlaylistBin {
// block pad until next item is reaching the `Blocked` state
let receiver = Mutex::new(item.receiver());
let element_weak = element.downgrade();
- let item_clone = item.clone();
+ // passing ownership of item to the probe callback would introduce a reference cycle as the item is owning the sinkpad
+ let item_weak = item.downgrade();
sink_pad.add_probe(gst::PadProbeType::BLOCK_DOWNSTREAM, move |pad, info| {
let element = match element_weak.upgrade() {
@@ -1423,7 +1432,10 @@ impl UriPlaylistBin {
None => return gst::PadProbeReturn::Remove,
};
let parent = pad.parent().unwrap();
- let item = &item_clone;
+ let item = match Item::upgrade(&item_weak) {
+ Some(item) => item,
+ None => return gst::PadProbeReturn::Remove,
+ };
if !item.is_streaming() {
// block pad until next item is ready