summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVaL Doroshchuk <valentyn.doroshchuk@qt.io>2019-10-25 12:29:34 +0200
committerVaL Doroshchuk <valentyn.doroshchuk@qt.io>2020-03-25 11:33:30 +0000
commit61a6a09429cf8c34a356748a3bb76fc7868a54b1 (patch)
treef693ebef1103ebea29932c8aba9dc40a426a3676
parentc22f263c5d7bd602197215978d59e53d67a7dd6d (diff)
ALSA: Calculate buffer size based on min period time
When defualt buffer size (100000us) and period time (20000us) are out of range, currently buffer size is computed with respect of either 2 or 4 chunks of maximum buffer time. Which is not enough. Fixing computing of buffer time based on minimum period time: How many minimum periods could fit in maximum suggested buffer time. Fixes: QTBUG-43256 Task-number: QTBUG-79526 Change-Id: I722e5145e3b6d323e306da420ec764db3575225f Reviewed-by: Christian Strømme <christian.stromme@qt.io> (cherry picked from commit 8b92454d6fffcee7a8cf1fb5e0c92920c77733c8) Reviewed-by: Andy Shaw <andy.shaw@qt.io>
-rw-r--r--src/plugins/alsa/qalsaaudiooutput.cpp34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/plugins/alsa/qalsaaudiooutput.cpp b/src/plugins/alsa/qalsaaudiooutput.cpp
index ddbe04de9..5c8ae171c 100644
--- a/src/plugins/alsa/qalsaaudiooutput.cpp
+++ b/src/plugins/alsa/qalsaaudiooutput.cpp
@@ -53,9 +53,11 @@
#include <QtMultimedia/private/qaudiohelpers_p.h>
#include "qalsaaudiooutput.h"
#include "qalsaaudiodeviceinfo.h"
+#include <QLoggingCategory>
QT_BEGIN_NAMESPACE
+Q_LOGGING_CATEGORY(lcAlsaOutput, "qt.multimedia.alsa.output")
//#define DEBUG_AUDIO 1
QAlsaAudioOutput::QAlsaAudioOutput(const QByteArray &device)
@@ -403,28 +405,22 @@ bool QAlsaAudioOutput::open()
fatal = true;
errMessage = QString::fromLatin1("QAudioOutput: buffer/period min and max: err = %1").arg(err);
} else {
- if (maxBufferTime < buffer_time || buffer_time < minBufferTime || maxPeriodTime < period_time || minPeriodTime > period_time) {
-#ifdef DEBUG_AUDIO
- qDebug()<<"defaults out of range";
- qDebug()<<"pmin="<<minPeriodTime<<", pmax="<<maxPeriodTime<<", bmin="<<minBufferTime<<", bmax="<<maxBufferTime;
-#endif
- period_time = minPeriodTime;
- if (period_time*4 <= maxBufferTime) {
- // Use 4 periods if possible
- buffer_time = period_time*4;
- chunks = 4;
- } else if (period_time*2 <= maxBufferTime) {
- // Use 2 periods if possible
- buffer_time = period_time*2;
- chunks = 2;
+ static unsigned user_buffer_time = qEnvironmentVariableIntValue("QT_ALSA_OUTPUT_BUFFER_TIME");
+ static unsigned user_period_time = qEnvironmentVariableIntValue("QT_ALSA_OUTPUT_PERIOD_TIME");
+ const bool outOfRange = maxBufferTime < buffer_time || buffer_time < minBufferTime || maxPeriodTime < period_time || minPeriodTime > period_time;
+ if (outOfRange || user_period_time || user_buffer_time) {
+ period_time = user_period_time ? user_period_time : minPeriodTime;
+ if (!user_buffer_time) {
+ chunks = maxBufferTime / period_time;
+ buffer_time = period_time * chunks;
} else {
- qWarning()<<"QAudioOutput: alsa only supports single period!";
- fatal = true;
+ buffer_time = user_buffer_time;
+ chunks = buffer_time / period_time;
}
-#ifdef DEBUG_AUDIO
- qDebug()<<"used: buffer_time="<<buffer_time<<", period_time="<<period_time;
-#endif
}
+ qCDebug(lcAlsaOutput) << "buffer time: [" << minBufferTime << "-" << maxBufferTime << "] =" << buffer_time;
+ qCDebug(lcAlsaOutput) << "period time: [" << minPeriodTime << "-" << maxPeriodTime << "] =" << period_time;
+ qCDebug(lcAlsaOutput) << "chunks =" << chunks;
}
}
if ( !fatal ) {