summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio
diff options
context:
space:
mode:
authorKurt Korbatits <kurt.korbatits@nokia.com>2010-03-04 23:41:53 (GMT)
committerKurt Korbatits <kurt.korbatits@nokia.com>2010-03-04 23:41:53 (GMT)
commit98ade3747d44543bcb6b8a0e82cbb2c32d0cc20a (patch)
tree8a2101257401001db44fdb5bbee76363c072ab4a /src/multimedia/audio
parente384ef218722d9380988fbe3b1bd30848ceb2c5c (diff)
downloadQt-98ade3747d44543bcb6b8a0e82cbb2c32d0cc20a.zip
Qt-98ade3747d44543bcb6b8a0e82cbb2c32d0cc20a.tar.gz
Qt-98ade3747d44543bcb6b8a0e82cbb2c32d0cc20a.tar.bz2
Linux QAudioOutput playback stuttering
Adjust buffer and period sizes if system cannot work with defaults (alsa). Task-number:QTBUG-8339 Reviewed-by:Derick Hawcroft
Diffstat (limited to 'src/multimedia/audio')
-rw-r--r--src/multimedia/audio/qaudiooutput_alsa_p.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.cpp b/src/multimedia/audio/qaudiooutput_alsa_p.cpp
index b127103..e49c75a 100644
--- a/src/multimedia/audio/qaudiooutput_alsa_p.cpp
+++ b/src/multimedia/audio/qaudiooutput_alsa_p.cpp
@@ -369,10 +369,52 @@ bool QAudioOutputPrivate::open()
}
}
if ( !fatal ) {
+ unsigned int maxBufferTime = 0;
+ unsigned int minBufferTime = 0;
+ unsigned int maxPeriodTime = 0;
+ unsigned int minPeriodTime = 0;
+
+ err = snd_pcm_hw_params_get_buffer_time_max(hwparams, &maxBufferTime, &dir);
+ if ( err >= 0)
+ err = snd_pcm_hw_params_get_buffer_time_min(hwparams, &minBufferTime, &dir);
+ if ( err >= 0)
+ err = snd_pcm_hw_params_get_period_time_max(hwparams, &maxPeriodTime, &dir);
+ if ( err >= 0)
+ err = snd_pcm_hw_params_get_period_time_min(hwparams, &minPeriodTime, &dir);
+
+ if ( err < 0 ) {
+ 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;
+ } else {
+ qWarning()<<"QAudioOutput: alsa only supports single period!";
+ fatal = true;
+ }
+#ifdef DEBUG_AUDIO
+ qDebug()<<"used: buffer_time="<<buffer_time<<", period_time="<<period_time;
+#endif
+ }
+ }
+ }
+ if ( !fatal ) {
err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir);
if ( err < 0 ) {
fatal = true;
- errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err);
+ errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err);
}
}
if ( !fatal ) {