Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(recording): drop the word tier from microphone matching too
EtienneLescot28fcbc38693b
diff --git a/electron/native/wgc-capture/src/wasapi_loopback_capture.cpp b/electron/native/wgc-capture/src/wasapi_loopback_capture.cppindex 6970670ce..69fc58272 100644--- a/electron/native/wgc-capture/src/wasapi_loopback_capture.cpp+++ b/electron/native/wgc-capture/src/wasapi_loopback_capture.cpp@@ -66,31 +66,21 @@ std::wstring normalizeDeviceName(const std::wstring& value) {}/**- * Is `word` one of the space-separated words of `haystack`?+ * How well a candidate endpoint answers a requested name, or 0 for "not this+ * one" -- which the caller must treat as a real answer.*- * Both sides have already been through `normalizeDeviceName`, so a word is- * exactly what sits between two spaces.+ * Only decisive matches count: equal once normalized, or one containing the+ * other, which is the ordinary case since Chromium appends USB ids to what the+ * driver reports.+ *+ * A further tier used to score shared WORDS, to bridge names differing more than+ * that. It bridged endpoints that were not the same device -- a requested+ * "micro" matched the "microphone" that opens nearly every Windows endpoint+ * name, so asking for a microphone that does not exist quietly recorded+ * whichever one sorted first, and the fallback warning could not fire because a+ * device HAD been resolved (getopenscreen/openscreen#404). Returning 0 is what+ * makes that warning reachable.*/-bool containsWord(const std::wstring& haystack, const std::wstring& word) {- if (haystack.empty() || word.empty()) {- return false;- }- size_t pos = 0;- while (pos <= haystack.size()) {- const size_t end = haystack.find(L' ', pos);- const std::wstring candidate =- haystack.substr(pos, end == std::wstring::npos ? std::wstring::npos : end - pos);- if (candidate == word) {- return true;- }- if (end == std::wstring::npos) {- break;- }- pos = end + 1;- }- return false;-}-int scoreDeviceName(const std::wstring& candidateName, const std::wstring& candidateId, const std::wstring& requestedName) {const std::wstring candidate = normalizeDeviceName(candidateName);const std::wstring id = normalizeDeviceName(candidateId);@@ -108,30 +98,7 @@ int scoreDeviceName(const std::wstring& candidateName, const std::wstring& candireturn 800;}- // Whole words from here down, never substrings. `candidate.find(word)` let a- // requested "micro" match the "microphone" that begins almost every endpoint- // name on Windows, so a name matching nothing still scored high enough to- // win -- and the recording quietly used a microphone nobody asked for, with- // the fallback warning unable to fire because a device HAD been resolved- // (getopenscreen/openscreen#404).- int score = 0;- size_t pos = 0;- while (pos < requested.size()) {- const size_t end = requested.find(L' ', pos);- const std::wstring word = requested.substr(pos, end == std::wstring::npos ? std::wstring::npos : end - pos);- if (word.size() > 1 && word != L"microphone" && word != L"mic" && word != L"audio" && word != L"input") {- if (containsWord(candidate, word)) {- score += 100;- } else if (containsWord(id, word)) {- score += 50;- }- }- if (end == std::wstring::npos) {- break;- }- pos = end + 1;- }- return score;+ return 0;}std::wstring getDeviceFriendlyName(IMMDevice* device) {diff --git a/scripts/test-windows-microphone-selection.mjs b/scripts/test-windows-microphone-selection.mjsindex c06a51df8..4d7e28a49 100644--- a/scripts/test-windows-microphone-selection.mjs+++ b/scripts/test-windows-microphone-selection.mjs@@ -107,6 +107,13 @@ const cases = [deviceName: "A Microphone That Is Not Here",expectDefaulted: true,},+ {+ label: "shares-a-brand-only",+ why: "another device from the same maker is still another device — a shared brand must not answer for it",+ deviceId: "",+ deviceName: "Logitech Blue Yeti",+ expectDefaulted: true,+ },{label: "plain-default-request",why: "no particular device was asked for, so the default endpoint is the right answer and no warning is due",diff --git a/technical-documentation/architecture/recording.md b/technical-documentation/architecture/recording.mdindex 982884fe3..0abea732e 100644--- a/technical-documentation/architecture/recording.md+++ b/technical-documentation/architecture/recording.md@@ -59,7 +59,7 @@ Two consequences follow, and both were once bugs:Electron resolves selected sources, devices, and paths before launching the helper. The helper does not guess a DirectShow camera: Windows receives the resolved selection. A helper error is reported explicitly rather than silently switching a Windows native feature to browser capture.-The microphone is chosen the same way and carries the same requirement: the helper resolves it by name, and `RecordingPrefs` therefore carries `micDeviceName` beside `micDeviceId` so a HUD rebuilt for a new take knows it without waiting on its own device enumeration. A request that names no microphone, or names one matching no endpoint, makes the helper capture the Windows default input — it reports that as `microphone-defaulted` rather than doing it quietly. Name matching is by whole words: a requested "micro" matching the "microphone" that opens nearly every Windows endpoint name is how a name that fitted nothing still selected a device. `npm run test:wgc-mic-selection:win` drives the real helper through those cases, because WASAPI cannot run on Linux CI.+The microphone is chosen the same way and carries the same requirement: the helper resolves it by name, and `RecordingPrefs` therefore carries `micDeviceName` beside `micDeviceId` so a HUD rebuilt for a new take knows it without waiting on its own device enumeration. A request that names no microphone, or names one matching no endpoint, makes the helper capture the Windows default input — it reports that as `microphone-defaulted` rather than doing it quietly. Name matching is deliberately strict — equal once normalized, or one containing the other, and nothing weaker. A tier that scored shared *words* used to bridge the rest and answered for devices that were not the same one: a requested "micro" matches the "microphone" that opens nearly every Windows endpoint name, so a name fitting nothing still selected a device and the fallback warning could not fire. `npm run test:wgc-mic-selection:win` drives the real helper through those cases, because WASAPI cannot run on Linux CI.Two things follow from Windows matching a camera by **name** while Chromium selects one by **id**. First, the renderer reads both halves off the `MediaStreamTrack` it opened rather than from separate state, so a request can never carry one camera's id beside another's name — the failure that let the HUD preview show the chosen camera while the recording captured a different one. Second, a camera the helper cannot open is a warning (`webcam-unavailable`), not a failed recording: the take continues as screen and audio, and the renderer says so at that moment instead of leaving the absence to be discovered in the editor. The DirectShow fallback negotiates the camera's own format first and only asks for RGB32 — inserting a colour converter — when that format is one the helper cannot unpack, which is the only way devices absent from Media Foundation, such as NVIDIA Broadcast, can be captured at all.