From 61a6a09429cf8c34a356748a3bb76fc7868a54b1 Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Fri, 25 Oct 2019 12:29:34 +0200 Subject: ALSA: Calculate buffer size based on min period time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (cherry picked from commit 8b92454d6fffcee7a8cf1fb5e0c92920c77733c8) Reviewed-by: Andy Shaw --- src/plugins/alsa/qalsaaudiooutput.cpp | 34 +++++++++++++++------------------- 1 file 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 #include "qalsaaudiooutput.h" #include "qalsaaudiodeviceinfo.h" +#include 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="< 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="<