From 318d72708cb6dfd63758a0eae9154b00f929c8b2 Mon Sep 17 00:00:00 2001 From: evgeny Date: Thu, 1 Oct 2026 18:29:43 +0300 Subject: [PATCH] Preserve voice autoplay ordering while decoding in a worker --- tools/chatgui/src/mainwindow.cpp | 7 ++++--- tools/chatgui/src/voiceplayback.cpp | 1 + tools/chatgui/src/voiceplayback.h | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/chatgui/src/mainwindow.cpp b/tools/chatgui/src/mainwindow.cpp index 1bb2d5b1..08e58b32 100644 --- a/tools/chatgui/src/mainwindow.cpp +++ b/tools/chatgui/src/mainwindow.cpp @@ -968,7 +968,7 @@ void MainWindow::autoPlayCheckNewMessage(const QString& channelId) { } void MainWindow::autoPlayTimerTick() { - if (SoundManager::instance()->isCurrentPcmPlaying()) + if (VoicePlayer::isPreparing() || SoundManager::instance()->isCurrentPcmPlaying()) return; while (!m_autoPlayQueue.isEmpty()) { @@ -996,8 +996,9 @@ void MainWindow::autoPlayTimerTick() { DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "auto-play: playing ch=%s msg=%lld file=%s dur=%.1fs", qPrintable(chId), (long long)msgId, qPrintable(fullPath), (double)dur); MessageDelegate::stopAllAutoPlay(); - float actualDur = VoicePlayer::playOpusFile(fullPath); - MessageDelegate::startAutoPlay(fullPath, actualDur); + VoicePlayer::playOpusFile(fullPath, this, [fullPath](float actualDur) { + MessageDelegate::startAutoPlay(fullPath, actualDur); + }); return; } } diff --git a/tools/chatgui/src/voiceplayback.cpp b/tools/chatgui/src/voiceplayback.cpp index 6c337ab2..4306d138 100644 --- a/tools/chatgui/src/voiceplayback.cpp +++ b/tools/chatgui/src/voiceplayback.cpp @@ -86,6 +86,7 @@ static unsigned s_decodeGeneration = 0; /* Только GUI-поток. */ static bool s_decoding = false; void VoicePlayer::cancelPending() { s_decodeGeneration++; } +bool VoicePlayer::isPreparing() { return s_decoding; } /* Декодирование и выделение PCM выполняются в worker; GUI принимает готовый буфер. */ void VoicePlayer::playOpusFile(const QString& filePath, QObject* context, std::function ready) { diff --git a/tools/chatgui/src/voiceplayback.h b/tools/chatgui/src/voiceplayback.h index 58129a14..08820b1d 100644 --- a/tools/chatgui/src/voiceplayback.h +++ b/tools/chatgui/src/voiceplayback.h @@ -12,6 +12,7 @@ class VoicePlayer { public: static void playOpusFile(const QString& filePath, QObject* context, std::function ready); static void cancelPending(); + static bool isPreparing(); static int decodeOpusFile(const QString& filePath, std::vector& outPcm, int& outSampleRate, int& outChannels, float& outDurationSec); static float playOpusFromReader(MediaBlockReader& reader);