diff options
author | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-03-13 16:25:15 +0100 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-04-14 14:42:21 +0000 |
commit | 07606dde9a1f6b89f582ff8f1fbc53e2d4eb2c22 (patch) | |
tree | fe9d60b38e6f4232619ba44dd8f15dd1eada444a /src/plugins/windowsaudio/qwindowsaudioinput.cpp | |
parent | b529cf242a596b47ebb0fc659e63439fa6e7cb79 (diff) |
WindowsAudio: improve supported formats detection.
QAudioDeviceInfo::isFormatSupported() now tries to open the device with
that format to theck if it is supported. We were before simply checking
that its parameters were included in the list of supported values,
which might be incomplete.
In addition, since the Windows API to check device capabilities is quite
limited, we now test additional common formats and add them to the
supported formats if the device can open them.
Task-number: QTBUG-42648
Change-Id: Idd0affbd6d91d4fd027a6a4c86c2f3fe008a118f
Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
Diffstat (limited to 'src/plugins/windowsaudio/qwindowsaudioinput.cpp')
-rw-r--r-- | src/plugins/windowsaudio/qwindowsaudioinput.cpp | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/src/plugins/windowsaudio/qwindowsaudioinput.cpp b/src/plugins/windowsaudio/qwindowsaudioinput.cpp index b44f206e8..ac92cf582 100644 --- a/src/plugins/windowsaudio/qwindowsaudioinput.cpp +++ b/src/plugins/windowsaudio/qwindowsaudioinput.cpp @@ -296,18 +296,9 @@ bool QWindowsAudioInput::open() period_size = 0; - if (!settings.isValid()) { + if (!qt_convertFormat(settings, &wfx)) { qWarning("QAudioInput: open error, invalid format."); - } else if (settings.channelCount() <= 0) { - qWarning("QAudioInput: open error, invalid number of channels (%d).", - settings.channelCount()); - } else if (settings.sampleSize() <= 0) { - qWarning("QAudioInput: open error, invalid sample size (%d).", - settings.sampleSize()); - } else if (settings.sampleRate() < 8000 || settings.sampleRate() > 96000) { - qWarning("QAudioInput: open error, sample rate out of range (%d).", settings.sampleRate()); } else if (buffer_size == 0) { - buffer_size = (settings.sampleRate() * settings.channelCount() @@ -327,20 +318,12 @@ bool QWindowsAudioInput::open() timeStamp.restart(); elapsedTimeOffset = 0; - wfx.nSamplesPerSec = settings.sampleRate(); - wfx.wBitsPerSample = settings.sampleSize(); - wfx.nChannels = settings.channelCount(); - wfx.cbSize = 0; - - wfx.wFormatTag = WAVE_FORMAT_PCM; - wfx.nBlockAlign = (wfx.wBitsPerSample >> 3) * wfx.nChannels; - wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec; QDataStream ds(&m_device, QIODevice::ReadOnly); quint32 deviceId; ds >> deviceId; - if (waveInOpen(&hWaveIn, UINT_PTR(deviceId), &wfx, + if (waveInOpen(&hWaveIn, UINT_PTR(deviceId), &wfx.Format, (DWORD_PTR)&waveInProc, (DWORD_PTR) this, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) { |