Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

Fall back when microphone names are ambiguous

webadderallbc664b0d3550
diff --git a/electron/native/wgc-capture/src/wasapi_loopback.cpp b/electron/native/wgc-capture/src/wasapi_loopback.cpp
index 9d04880d..240264d8 100644
--- a/electron/native/wgc-capture/src/wasapi_loopback.cpp
+++ b/electron/native/wgc-capture/src/wasapi_loopback.cpp
@@ -128,20 +128,27 @@ IMMDevice* WasapiCapture::findCaptureDeviceByName(const std::wstring& targetName
UINT count = 0;
collection->GetCount(&count);
+ IMMDevice* matchingDevice = nullptr;
for (UINT i = 0; i < count; i++) {
IMMDevice* dev = nullptr;
if (FAILED(collection->Item(i, &dev)) || !dev) continue;
const std::wstring candidateName = getDeviceFriendlyName(dev);
if (deviceNamesMatch(candidateName, targetName)) {
- collection->Release();
- return dev;
+ if (matchingDevice) {
+ matchingDevice->Release();
+ dev->Release();
+ collection->Release();
+ return nullptr;
+ }
+ matchingDevice = dev;
+ continue;
}
dev->Release();
}
collection->Release();
- return nullptr;
+ return matchingDevice;
}
bool WasapiCapture::initializeLoopback(const std::string& outputPath) {