From e82d3884106b6c2d360041f97dbb730fe343efac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 12 May 2022 10:34:11 +0300 Subject: [PATCH] utils/streamproducer: Index hashmap by appsrc instance instead of pointer This behaves the same but requires a little bit less code. --- gstreamer-utils/src/streamproducer.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/gstreamer-utils/src/streamproducer.rs b/gstreamer-utils/src/streamproducer.rs index 5e91ede8e..4e85cb00c 100644 --- a/gstreamer-utils/src/streamproducer.rs +++ b/gstreamer-utils/src/streamproducer.rs @@ -56,11 +56,7 @@ impl StreamProducer { /// Add an appsrc to dispatch data to pub fn add_consumer(&self, consumer: &gst_app::AppSrc) { let mut consumers = self.consumers.lock().unwrap(); - if consumers - .consumers - .get(&(consumer.as_ptr() as usize)) - .is_some() - { + if consumers.consumers.contains_key(consumer) { gst::error!(CAT, obj: &self.appsink, "Consumer already added"); return; } @@ -89,7 +85,7 @@ impl StreamProducer { .unwrap(); consumers.consumers.insert( - consumer.as_ptr() as usize, + consumer.clone(), StreamConsumer::new(consumer, fku_probe_id), ); } @@ -102,7 +98,7 @@ impl StreamProducer { .lock() .unwrap() .consumers - .remove(&(consumer.as_ptr() as usize)) + .remove(consumer) .is_some() { gst::debug!(CAT, obj: &self.appsink, "Removed consumer {}", name); @@ -274,7 +270,7 @@ struct StreamConsumers { /// Whether the consumers' appsrc latency needs updating latency_updated: bool, /// The consumers, AppSrc pointer value -> consumer - consumers: HashMap, + consumers: HashMap, /// Whether appsrc samples should be forwarded to consumers yet discard: bool, }