Browse Source

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.
Richard Stanway 5 years ago
parent
commit
21737d5f7a
1 changed files with 6 additions and 4 deletions
  1. 6 4
      plugins/win-wasapi/win-wasapi.cpp

+ 6 - 4
plugins/win-wasapi/win-wasapi.cpp

@@ -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);
+			}
 		}
 	}