win-wasapi: Fix crash on certain devices

Not all devices return PKEY_AudioEngine_DeviceFormat properties.

Per MSDN, if the PROPERTYKEY referenced in key is not present in
the property store, this method returns S_OK and the vt member of
the structure pointed to by pv is set to VT_EMPTY.
This commit is contained in:
Richard Stanway 2020-03-20 17:53:18 +01:00
parent b19ea6fe35
commit 21737d5f7a

View File

@ -319,10 +319,12 @@ void WASAPISource::Initialize()
resSample =
store->GetValue(PKEY_AudioEngine_DeviceFormat, &prop);
if (!FAILED(resSample)) {
deviceFormatProperties =
(PWAVEFORMATEX)prop.blob.pBlobData;
device_sample = std::to_string(
deviceFormatProperties->nSamplesPerSec);
if (prop.vt != VT_EMPTY && prop.blob.pBlobData) {
deviceFormatProperties =
(PWAVEFORMATEX)prop.blob.pBlobData;
device_sample = std::to_string(
deviceFormatProperties->nSamplesPerSec);
}
}
}