diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2010-09-22 05:41:34 (GMT) |
---|---|---|
committer | Andrew den Exter <andrew.den-exter@nokia.com> | 2010-09-22 08:03:38 (GMT) |
commit | 5b7d75a57e0ec8ee78f843ab0eb6485b8e3b4a22 (patch) | |
tree | 7a474601e5daa4cc6cfb823c0af870f6bd7eb155 /src/multimedia/audio/qaudioinput_alsa_p.cpp | |
parent | 2836c2806e3bdfb6d29d99f74f1b15950fa39e35 (diff) | |
download | Qt-5b7d75a57e0ec8ee78f843ab0eb6485b8e3b4a22.zip Qt-5b7d75a57e0ec8ee78f843ab0eb6485b8e3b4a22.tar.gz Qt-5b7d75a57e0ec8ee78f843ab0eb6485b8e3b4a22.tar.bz2 |
Verify the audio format before trying to open an audio device.
This was causing a crash on windows because the buffer and period sizes
were worked out to 0 with an invalid sample size and dividing one by the
other is division by 0.
Task-number: QTMOBILITY-438
Reviewed-by: Justin McPherson
Diffstat (limited to 'src/multimedia/audio/qaudioinput_alsa_p.cpp')
-rw-r--r-- | src/multimedia/audio/qaudioinput_alsa_p.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/multimedia/audio/qaudioinput_alsa_p.cpp b/src/multimedia/audio/qaudioinput_alsa_p.cpp index 58669b3..ddafa3d 100644 --- a/src/multimedia/audio/qaudioinput_alsa_p.cpp +++ b/src/multimedia/audio/qaudioinput_alsa_p.cpp @@ -152,7 +152,7 @@ int QAudioInputPrivate::xrun_recovery(int err) int QAudioInputPrivate::setFormat() { - snd_pcm_format_t format = SND_PCM_FORMAT_S16; + snd_pcm_format_t format = SND_PCM_FORMAT_UNKNOWN; if(settings.sampleSize() == 8) { format = SND_PCM_FORMAT_U8; @@ -204,7 +204,9 @@ int QAudioInputPrivate::setFormat() format = SND_PCM_FORMAT_FLOAT64_BE; } - return snd_pcm_hw_params_set_format( handle, hwparams, format); + return format != SND_PCM_FORMAT_UNKNOWN + ? snd_pcm_hw_params_set_format( handle, hwparams, format) + : -1; } QIODevice* QAudioInputPrivate::start(QIODevice* device) @@ -259,10 +261,26 @@ bool QAudioInputPrivate::open() elapsedTimeOffset = 0; int dir; - int err=-1; + int err = 0; int count=0; unsigned int freakuency=settings.frequency(); + if (!settings.isValid()) { + qWarning("QAudioOutput: open error, invalid format."); + } else if (settings.frequency() <= 0) { + qWarning("QAudioOutput: open error, invalid sample rate (%d).", + settings.frequency()); + } else { + err = -1; + } + + if (err == 0) { + errorState = QAudio::OpenError; + deviceState = QAudio::StoppedState; + return false; + } + + QString dev = QString(QLatin1String(m_device.constData())); QList<QByteArray> devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioInput); if(dev.compare(QLatin1String("default")) == 0) { |