Skip to content

Commit ad801ee

Browse files
committed
Remove config sharing - ensure each hangsrc creates independent connection
1 parent 9e8857b commit ad801ee

File tree

1 file changed

+1
-54
lines changed

1 file changed

+1
-54
lines changed

src/source/imp.rs

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,9 @@ use hang::moq_lite;
88
use once_cell::sync::Lazy;
99
use std::sync::LazyLock;
1010
use std::sync::Mutex;
11-
use std::collections::HashMap;
12-
use std::sync::Arc;
13-
use std::sync::atomic::{AtomicUsize, Ordering};
14-
1511
static CAT: Lazy<gst::DebugCategory> =
1612
Lazy::new(|| gst::DebugCategory::new("hang-src", gst::DebugColorFlags::empty(), Some("Hang Source Element")));
1713

18-
#[derive(Clone)]
19-
struct SharedConfig {
20-
tls_disable_verify: bool,
21-
ref_count: Arc<std::sync::atomic::AtomicUsize>,
22-
}
23-
24-
type ConfigMap = HashMap<String, SharedConfig>;
25-
static CONFIG_MANAGER: Lazy<Arc<Mutex<ConfigMap>>> = Lazy::new(|| Arc::new(Mutex::new(HashMap::new())));
26-
2714
#[derive(Default, Clone)]
2815
struct Settings {
2916
pub url: Option<String>,
@@ -35,7 +22,6 @@ struct Settings {
3522
pub struct HangSrc {
3623
settings: Mutex<Settings>,
3724
runtime: Mutex<Option<tokio::runtime::Runtime>>,
38-
connection_url: Mutex<Option<String>>,
3925
}
4026

4127
#[glib::object_subclass]
@@ -177,37 +163,11 @@ impl HangSrc {
177163
let settings = self.settings.lock().unwrap();
178164
let url = url::Url::parse(settings.url.as_ref().expect("url is required"))?;
179165
let name = settings.broadcast.as_ref().expect("broadcast is required").clone();
180-
let url_key = url.to_string();
181-
182-
// Check if we already have config for this URL
183-
let tls_disable_verify = {
184-
let mut configs = CONFIG_MANAGER.lock().unwrap();
185-
if let Some(existing) = configs.get(&url_key) {
186-
gst::info!(CAT, "Reusing existing config for URL: {}", url_key);
187-
// Increment reference count
188-
existing.ref_count.fetch_add(1, Ordering::SeqCst);
189-
existing.tls_disable_verify
190-
} else {
191-
gst::info!(CAT, "Creating new config for URL: {}", url_key);
192-
193-
let config = SharedConfig {
194-
tls_disable_verify: settings.tls_disable_verify,
195-
ref_count: Arc::new(AtomicUsize::new(1)),
196-
};
197-
198-
let tls_setting = config.tls_disable_verify;
199-
configs.insert(url_key.clone(), config);
200-
tls_setting
201-
}
202-
};
203-
204-
// Store the connection URL for cleanup
205-
*self.connection_url.lock().unwrap() = Some(url_key);
206166

207167
// Create a dedicated connection for this broadcast
208168
let client = moq_native::ClientConfig {
209169
tls: moq_native::ClientTls {
210-
disable_verify: Some(tls_disable_verify),
170+
disable_verify: Some(settings.tls_disable_verify),
211171
..Default::default()
212172
},
213173
..Default::default()
@@ -427,18 +387,5 @@ impl HangSrc {
427387

428388
fn cleanup(&self) {
429389
// TODO kill spawned tasks
430-
431-
// Cleanup config reference
432-
if let Some(url_key) = self.connection_url.lock().unwrap().take() {
433-
let mut configs = CONFIG_MANAGER.lock().unwrap();
434-
if let Some(config) = configs.get(&url_key) {
435-
let ref_count = config.ref_count.fetch_sub(1, Ordering::SeqCst);
436-
if ref_count == 1 {
437-
// This was the last reference, remove the config
438-
gst::info!(CAT, "Removing config for URL: {}", url_key);
439-
configs.remove(&url_key);
440-
}
441-
}
442-
}
443390
}
444391
}

0 commit comments

Comments
 (0)