diff options
author | Ling Hu <ling.hu@nokia.com> | 2011-03-10 15:31:39 +1000 |
---|---|---|
committer | Ling Hu <ling.hu@nokia.com> | 2011-03-15 13:39:02 +1000 |
commit | 729ddefb071436736dbdcf9c2de6465d77adb0f8 (patch) | |
tree | bebd6351cb125c558c16d5d118398c2cfd33b4bd | |
parent | 8f9828233f324d13054e62d3453dda565f74497f (diff) |
Fix a potential crash in audio device enumeration under Windows
Reviewed-by: Jonas Rabbe
-rw-r--r-- | src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp index 939774030a..a3cd55c86c 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp @@ -406,42 +406,43 @@ QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode) unsigned long iNumDevs = mode == QAudio::AudioOutput ? waveOutGetNumDevs() : waveInGetNumDevs(); if (SUCCEEDED(hr)) { - // Create the enumerator for the video capture category - hr = pDevEnum->CreateClassEnumerator( + // Create the enumerator for the audio input/output category + if (pDevEnum->CreateClassEnumerator( mode == QAudio::AudioOutput ? CLSID_AudioRendererCategory : CLSID_AudioInputDeviceCategory, - &pEnum, 0); - pEnum->Reset(); - // go through and find all video capture devices - IMoniker *pMoniker = NULL; - while (pEnum->Next(1, &pMoniker, NULL) == S_OK) { - IPropertyBag *pPropBag; - hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag, - reinterpret_cast<void **>(&pPropBag)); - if (FAILED(hr)) { - pMoniker->Release(); - continue; // skip this one - } - // Find if it is a wave device - VARIANT var; - VariantInit(&var); - hr = pPropBag->Read(mode == QAudio::AudioOutput ? L"WaveOutID" : L"WaveInID", &var, 0); - if (SUCCEEDED(hr)) { - LONG waveID = var.lVal; - if (waveID >= 0 && waveID < LONG(iNumDevs)) { - VariantClear(&var); - // Find the description - hr = pPropBag->Read(L"FriendlyName", &var, 0); - if (SUCCEEDED(hr)) { - QByteArray device; - QDataStream ds(&device, QIODevice::WriteOnly); - ds << quint32(waveID) << QString::fromWCharArray(var.bstrVal); - devices.append(device); + &pEnum, 0) == S_OK) { + pEnum->Reset(); + // go through and find all audio devices + IMoniker *pMoniker = NULL; + while (pEnum->Next(1, &pMoniker, NULL) == S_OK) { + IPropertyBag *pPropBag; + hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag, + reinterpret_cast<void **>(&pPropBag)); + if (FAILED(hr)) { + pMoniker->Release(); + continue; // skip this one + } + // Find if it is a wave device + VARIANT var; + VariantInit(&var); + hr = pPropBag->Read(mode == QAudio::AudioOutput ? L"WaveOutID" : L"WaveInID", &var, 0); + if (SUCCEEDED(hr)) { + LONG waveID = var.lVal; + if (waveID >= 0 && waveID < LONG(iNumDevs)) { + VariantClear(&var); + // Find the description + hr = pPropBag->Read(L"FriendlyName", &var, 0); + if (SUCCEEDED(hr)) { + QByteArray device; + QDataStream ds(&device, QIODevice::WriteOnly); + ds << quint32(waveID) << QString::fromWCharArray(var.bstrVal); + devices.append(device); + } } } - } - pPropBag->Release(); - pMoniker->Release(); + pPropBag->Release(); + pMoniker->Release(); + } } } CoUninitialize(); |