From 9923670426fb7706476bfa725addf5c8feab8aed Mon Sep 17 00:00:00 2001 From: arounyf Date: Tue, 5 May 2026 05:11:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20WebRTC=20=E9=9F=B3?= =?UTF-8?q?=E9=A2=91/=E8=A7=86=E9=A2=91=E6=8E=A5=E6=94=B6=E5=99=A8?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E6=97=B6=E7=A0=B4=E9=9F=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit start_audio_from_opus 和 start_from_video_frames 替换旧 handle 时先 abort 旧任务,防止新旧两个任务同时向同一个 track 写数据导致破音。 --- src/webrtc/universal_session.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/webrtc/universal_session.rs b/src/webrtc/universal_session.rs index 2cf41c57..eed763d5 100644 --- a/src/webrtc/universal_session.rs +++ b/src/webrtc/universal_session.rs @@ -674,7 +674,13 @@ impl UniversalSession { ); }); - *self.video_receiver_handle.lock().await = Some(handle); + { + let mut guard = self.video_receiver_handle.lock().await; + if let Some(old) = guard.take() { + old.abort(); + } + *guard = Some(handle); + } } pub async fn start_audio_from_opus( @@ -761,7 +767,13 @@ impl UniversalSession { ); }); - *self.audio_receiver_handle.lock().await = Some(handle); + { + let mut guard = self.audio_receiver_handle.lock().await; + if let Some(old) = guard.take() { + old.abort(); + } + *guard = Some(handle); + } } pub fn has_audio(&self) -> bool {