summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoni Poikelin <joni.poikelin@qt.io>2024-01-31 07:53:05 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-02-09 20:57:41 +0000
commit1e1f6b6c1c5df9e7d4b7aaa0c94cbe5027226593 (patch)
treef35c7f454bc357fe6be742308707973aa8f966c4
parenta46ea51c86b76e9beb320ad9975af3199af09343 (diff)
alsa: Prevent buffer underrun errors when QIODevice has no data to read
Fixes: QTBUG-114900 Pick-to: 6.6 6.5 Change-Id: I093538ea4f1b4f9fdcf22d38343b4c8aff55a39d Reviewed-by: Artem Dyomin <artem.dyomin@qt.io> Reviewed-by: Lars Knoll <lars@knoll.priv.no> (cherry picked from commit c39a9a4f26fda6560de4ffb0cd4451c7482a9b6e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/multimedia/alsa/qalsaaudiosink.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/multimedia/alsa/qalsaaudiosink.cpp b/src/multimedia/alsa/qalsaaudiosink.cpp
index 2417d6051..98a68861f 100644
--- a/src/multimedia/alsa/qalsaaudiosink.cpp
+++ b/src/multimedia/alsa/qalsaaudiosink.cpp
@@ -157,6 +157,11 @@ void QAlsaAudioSink::start(QIODevice* device)
pullMode = true;
audioSource = device;
+ connect(audioSource, &QIODevice::readyRead, timer, [this] {
+ if (!timer->isActive()) {
+ timer->start(period_time / 1000);
+ }
+ });
deviceState = QAudio::ActiveState;
open();
@@ -606,11 +611,13 @@ bool QAlsaAudioSink::deviceReady()
} else if(l == 0) {
// Did not get any data to output
+ timer->stop();
+ snd_pcm_drain(handle);
bytesAvailable = bytesFree();
if(bytesAvailable > snd_pcm_frames_to_bytes(handle, buffer_frames-period_frames)) {
// Underrun
if (deviceState != QAudio::IdleState) {
- errorState = QAudio::UnderrunError;
+ errorState = audioSource->atEnd() ? QAudio::NoError : QAudio::UnderrunError;
emit errorChanged(errorState);
deviceState = QAudio::IdleState;
emit stateChanged(deviceState);