From a8741dd5688431a18e6368fdcdef9cc73cd409cd Mon Sep 17 00:00:00 2001 From: cooper Date: Mon, 4 May 2026 21:46:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(recorder):=20watchdog=20=E4=BB=8E=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E5=BC=80=E5=A7=8B=E6=97=B6=E8=AE=A1=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E6=85=A2=E5=90=AF=E5=8A=A8=E8=AF=AF=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 StreamState::stream_start_time 字段 - 在 watchdog 线程内部记录启动时间 - 确保首次回调截止时间从 stream.play() 成功后开始计时 - 修复慢速后端可能导致的过早超时问题 --- openless-all/app/src-tauri/src/recorder.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openless-all/app/src-tauri/src/recorder.rs b/openless-all/app/src-tauri/src/recorder.rs index d1ed3d72..4057abdb 100644 --- a/openless-all/app/src-tauri/src/recorder.rs +++ b/openless-all/app/src-tauri/src/recorder.rs @@ -144,6 +144,9 @@ fn run_audio_thread( let watchdog_handle = thread::Builder::new() .name("openless-recorder-watchdog".into()) .spawn(move || { + // 记录 watchdog 启动时间,确保首次回调截止时间从播放真正开始时计时 + let watchdog_start_time = std::time::Instant::now(); + while !stop_flag_for_watchdog.load(Ordering::SeqCst) { thread::sleep(std::time::Duration::from_millis(WATCHDOG_CHECK_INTERVAL_MS)); @@ -165,7 +168,7 @@ fn run_audio_thread( } None => { // 尚未收到首次回调,检查是否超过截止时间 - let elapsed = state_for_watchdog.stream_start_time.elapsed(); + let elapsed = watchdog_start_time.elapsed(); if elapsed.as_secs() > FIRST_CALLBACK_DEADLINE_SECS { log::error!( "[recorder] watchdog: {} 秒内未收到首次回调,触发错误恢复", @@ -337,8 +340,6 @@ struct StreamState { callback_count: AtomicUsize, peak_input_rms_milli: AtomicUsize, peak_output_rms_milli: AtomicUsize, - /// Stream 启动时间(用于检测"首次回调永远不到达") - stream_start_time: std::time::Instant, /// 最后一次成功调用 consumer 的时间戳(用于 liveness 检测) last_callback_time: Mutex>, } @@ -351,7 +352,6 @@ impl StreamState { callback_count: AtomicUsize::new(0), peak_input_rms_milli: AtomicUsize::new(0), peak_output_rms_milli: AtomicUsize::new(0), - stream_start_time: std::time::Instant::now(), // 初始化为 None,只有在第一次回调后才开始计时,避免误报慢启动设备 last_callback_time: Mutex::new(None), }