Browse Source

Preserve voice autoplay ordering while decoding in a worker

master
evgeny 1 day ago
parent
commit
318d72708c
  1. 7
      tools/chatgui/src/mainwindow.cpp
  2. 1
      tools/chatgui/src/voiceplayback.cpp
  3. 1
      tools/chatgui/src/voiceplayback.h

7
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;
}
}

1
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<void(float)> ready) {

1
tools/chatgui/src/voiceplayback.h

@ -12,6 +12,7 @@ class VoicePlayer {
public:
static void playOpusFile(const QString& filePath, QObject* context, std::function<void(float)> ready);
static void cancelPending();
static bool isPreparing();
static int decodeOpusFile(const QString& filePath, std::vector<int16_t>& outPcm,
int& outSampleRate, int& outChannels, float& outDurationSec);
static float playOpusFromReader(MediaBlockReader& reader);

Loading…
Cancel
Save