summaryrefslogtreecommitdiff
path: root/src/multimedia/audio/qaudioinput_win32_p.cpp
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2010-09-22 15:41:34 +1000
committerAndrew den Exter <andrew.den-exter@nokia.com>2010-09-22 18:03:38 +1000
commit5b7d75a57e0ec8ee78f843ab0eb6485b8e3b4a22 (patch)
tree7a474601e5daa4cc6cfb823c0af870f6bd7eb155 /src/multimedia/audio/qaudioinput_win32_p.cpp
parent2836c2806e3bdfb6d29d99f74f1b15950fa39e35 (diff)
downloadqt4-tools-5b7d75a57e0ec8ee78f843ab0eb6485b8e3b4a22.tar.gz
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_win32_p.cpp')
-rw-r--r--src/multimedia/audio/qaudioinput_win32_p.cpp41
1 files changed, 36 insertions, 5 deletions
diff --git a/src/multimedia/audio/qaudioinput_win32_p.cpp b/src/multimedia/audio/qaudioinput_win32_p.cpp
index 3f6e77816c..225d2f1204 100644
--- a/src/multimedia/audio/qaudioinput_win32_p.cpp
+++ b/src/multimedia/audio/qaudioinput_win32_p.cpp
@@ -214,13 +214,44 @@ bool QAudioInputPrivate::open()
qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
#endif
header = 0;
- if(buffer_size == 0) {
- // Default buffer size, 200ms, default period size is 40ms
- buffer_size = settings.frequency()*settings.channels()*(settings.sampleSize()/8)*0.2;
- period_size = buffer_size/5;
+ period_size = 0;
+
+ if (!settings.isValid()) {
+ qWarning("QAudioInput: open error, invalid format.");
+ } else if (settings.channels() <= 0) {
+ qWarning("QAudioInput: open error, invalid number of channels (%d).",
+ settings.channels());
+ } else if (settings.sampleSize() <= 0) {
+ qWarning("QAudioInput: open error, invalid sample size (%d).",
+ settings.sampleSize());
+ } else if (settings.frequency() < 8000 || settings.frequency() > 48000) {
+ qWarning("QAudioInput: open error, frequency out of range (%d).", settings.frequency());
+ } else if (buffer_size == 0) {
+
+ buffer_size
+ = (settings.frequency()
+ * settings.channels()
+ * settings.sampleSize()
+#ifndef Q_OS_WINCE // Default buffer size, 200ms, default period size is 40ms
+ + 39) / 40;
+ period_size = buffer_size / 5;
+ } else {
+ period_size = buffer_size / 5;
+#else // For wince reduce size to 40ms for buffer size and 20ms period
+ + 199) / 200;
+ period_size = buffer_size / 2;
} else {
- period_size = buffer_size/5;
+ period_size = buffer_size / 2;
+#endif
}
+
+ if (period_size == 0) {
+ errorState = QAudio::OpenError;
+ deviceState = QAudio::StoppedState;
+ emit stateChanged(deviceState);
+ return false;
+ }
+
timeStamp.restart();
elapsedTimeOffset = 0;
wfx.nSamplesPerSec = settings.frequency();