src/multimedia/audio/qaudiooutput_alsa_p.cpp
changeset 19 fcece45ef507
parent 18 2f34d5167611
child 22 79de32ba3296
equal deleted inserted replaced
18:2f34d5167611 19:fcece45ef507
   367             fatal = true;
   367             fatal = true;
   368             errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err);
   368             errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err);
   369         }
   369         }
   370     }
   370     }
   371     if ( !fatal ) {
   371     if ( !fatal ) {
       
   372         unsigned int maxBufferTime = 0;
       
   373         unsigned int minBufferTime = 0;
       
   374         unsigned int maxPeriodTime = 0;
       
   375         unsigned int minPeriodTime = 0;
       
   376 
       
   377         err = snd_pcm_hw_params_get_buffer_time_max(hwparams, &maxBufferTime, &dir);
       
   378         if ( err >= 0)
       
   379             err = snd_pcm_hw_params_get_buffer_time_min(hwparams, &minBufferTime, &dir);
       
   380         if ( err >= 0)
       
   381             err = snd_pcm_hw_params_get_period_time_max(hwparams, &maxPeriodTime, &dir);
       
   382         if ( err >= 0)
       
   383             err = snd_pcm_hw_params_get_period_time_min(hwparams, &minPeriodTime, &dir);
       
   384 
       
   385         if ( err < 0 ) {
       
   386             fatal = true;
       
   387             errMessage = QString::fromLatin1("QAudioOutput: buffer/period min and max: err = %1").arg(err);
       
   388         } else {
       
   389             if (maxBufferTime < buffer_time || buffer_time < minBufferTime || maxPeriodTime < period_time || minPeriodTime > period_time) {
       
   390 #ifdef DEBUG_AUDIO
       
   391                 qDebug()<<"defaults out of range";
       
   392                 qDebug()<<"pmin="<<minPeriodTime<<", pmax="<<maxPeriodTime<<", bmin="<<minBufferTime<<", bmax="<<maxBufferTime;
       
   393 #endif
       
   394                 period_time = minPeriodTime;
       
   395                 if (period_time*4 <= maxBufferTime) {
       
   396                     // Use 4 periods if possible
       
   397                     buffer_time = period_time*4;
       
   398                     chunks = 4;
       
   399                 } else if (period_time*2 <= maxBufferTime) {
       
   400                     // Use 2 periods if possible
       
   401                     buffer_time = period_time*2;
       
   402                     chunks = 2;
       
   403                 } else {
       
   404                     qWarning()<<"QAudioOutput: alsa only supports single period!";
       
   405                     fatal = true;
       
   406                 }
       
   407 #ifdef DEBUG_AUDIO
       
   408                 qDebug()<<"used: buffer_time="<<buffer_time<<", period_time="<<period_time;
       
   409 #endif
       
   410             }
       
   411         }
       
   412     }
       
   413     if ( !fatal ) {
   372         err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir);
   414         err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir);
   373         if ( err < 0 ) {
   415         if ( err < 0 ) {
   374             fatal = true;
   416             fatal = true;
   375                 errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err);
   417             errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err);
   376         }
   418         }
   377     }
   419     }
   378     if ( !fatal ) {
   420     if ( !fatal ) {
   379         err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir);
   421         err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir);
   380         if ( err < 0 ) {
   422         if ( err < 0 ) {
   604     deviceReady();
   646     deviceReady();
   605 }
   647 }
   606 
   648 
   607 void QAudioOutputPrivate::feedback()
   649 void QAudioOutputPrivate::feedback()
   608 {
   650 {
   609     QMetaObject::invokeMethod(this, SLOT(updateAvailable()), Qt::QueuedConnection);
   651     updateAvailable();
   610 }
   652 }
       
   653 
   611 
   654 
   612 void QAudioOutputPrivate::updateAvailable()
   655 void QAudioOutputPrivate::updateAvailable()
   613 {
   656 {
   614 #ifdef DEBUG_AUDIO
   657 #ifdef DEBUG_AUDIO
   615     QTime now(QTime::currentTime());
   658     QTime now(QTime::currentTime());