From 517e1c963b5b04a455db66f8450b4c91892db362 Mon Sep 17 00:00:00 2001 From: Miriam Zimmerman Date: Mon, 9 Dec 2024 13:11:01 -0500 Subject: [PATCH] Fix occasional-crash bug. --- .../src/webrtc/peer_connection_factory.rs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/rust/src/webrtc/peer_connection_factory.rs b/src/rust/src/webrtc/peer_connection_factory.rs index c8c04159..f1f82992 100644 --- a/src/rust/src/webrtc/peer_connection_factory.rs +++ b/src/rust/src/webrtc/peer_connection_factory.rs @@ -205,17 +205,20 @@ impl AudioConfig { }; #[cfg(all(not(feature = "sim"), feature = "native"))] - let (adm_borrowed, backend_name) = { - let mut adm = AudioDeviceModule::new(); - // Initialize the ADM here. This isn't strictly necessary, but allows - // us to log the backend name (e.g. audiounit vs audiounit-rust). - adm.init(); - let backend_name = adm.backend_name(); - ( - webrtc::ptr::Borrowed::from_ptr(Box::into_raw(Box::new(adm))).to_void(), - backend_name, - ) - }; + let (adm_borrowed, backend_name) = + if self.audio_device_module_type == RffiAudioDeviceModuleType::RingRtc { + let mut adm = AudioDeviceModule::new(); + // Initialize the ADM here. This isn't strictly necessary, but allows + // us to log the backend name (e.g. audiounit vs audiounit-rust). + adm.init(); + let backend_name = adm.backend_name(); + ( + webrtc::ptr::Borrowed::from_ptr(Box::into_raw(Box::new(adm))).to_void(), + backend_name, + ) + } else { + (webrtc::ptr::Borrowed::null(), None) + }; #[cfg(any(feature = "sim", not(feature = "native")))] let backend_name = None;