From 3c73c7d6455cc33693664928317cb164c11969b7 Mon Sep 17 00:00:00 2001 From: evgeny Date: Fri, 16 Oct 2026 17:11:57 +0200 Subject: [PATCH] Keep microphone buffer resizing outside the GUI close path --- tools/chatgui/src/audio_capture.cpp | 8 +++++++- tools/chatgui/src/audio_device.h | 1 + tools/chatgui/src/call_audio_engine.cpp | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/chatgui/src/audio_capture.cpp b/tools/chatgui/src/audio_capture.cpp index 126ebd08..ef10abe0 100644 --- a/tools/chatgui/src/audio_capture.cpp +++ b/tools/chatgui/src/audio_capture.cpp @@ -60,7 +60,13 @@ struct AudioCapture::Session { } } void recover() { - if (device.needsRecovery()) { stop(); device.retryLater(); } + if (device.needsRecovery()) { + if (device.resizingBuffer()) { + for (auto& slot : consumers) if (slot.client) detach(slot); + device.closeAsync(); + } else stop(); + device.retryLater(); + } if (device.initialized()) { prepare(); return; } auto* context = SoundManager::instance()->context(); if (!context || !device.retryReady()) return; diff --git a/tools/chatgui/src/audio_device.h b/tools/chatgui/src/audio_device.h index 27a9f4d1..2f794f62 100644 --- a/tools/chatgui/src/audio_device.h +++ b/tools/chatgui/src/audio_device.h @@ -25,6 +25,7 @@ public: bool closing() const { return !m_closeDone.load(std::memory_order_acquire); } bool captureTimedOut() const; // Секунда без корректного PCM; нулевые сэмплы считаются данными. bool needsRecovery(); + bool resizingBuffer() const { return m_resizePending; } // После needsRecovery(): переоткрытие с увеличенным буфером. bool retryReady() const; void retryLater(); void retryNow(); diff --git a/tools/chatgui/src/call_audio_engine.cpp b/tools/chatgui/src/call_audio_engine.cpp index ab1be915..6a97adc1 100644 --- a/tools/chatgui/src/call_audio_engine.cpp +++ b/tools/chatgui/src/call_audio_engine.cpp @@ -100,7 +100,8 @@ void CallAudioEngine::recoverDevices() { } if (!m_captureError.isEmpty() || m_capture.closing()) return; if (!m_ending && ((m_capture.initialized() && !m_voice.captureRunning()) || m_capture.needsRecovery())) { - m_capture.close(); m_voice.stopCapture(); + if (m_capture.resizingBuffer()) m_capture.closeAsync(); else m_capture.close(); + m_voice.stopCapture(); call_audio_reset_io(m_callId.load(), 0); m_capture.retryLater(); } if (!m_ending && m_capture.retryReady()) openCapture();