From 6492cb9a3590357423ab3bd9c587d7df2fe258f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20J=C3=BCrgens?= Date: Tue, 26 Jul 2022 16:02:36 +0200 Subject: [PATCH] start virtmic with no target when audio capture is requested --- src/discordpage.cpp | 9 +++++ src/virtmic.cpp | 98 +++++++++++++++++++++++---------------------- 2 files changed, 59 insertions(+), 48 deletions(-) diff --git a/src/discordpage.cpp b/src/discordpage.cpp index ef7ae34..eb7a4e2 100644 --- a/src/discordpage.cpp +++ b/src/discordpage.cpp @@ -63,6 +63,15 @@ void DiscordPage::featurePermissionRequested(const QUrl &securityOrigin, // Allow every permission asked setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionGrantedByUser); + + if (feature == QWebEnginePage::Feature::MediaAudioCapture) { + if (m_virtmicProcess.state() == QProcess::NotRunning) { + qDebug() << "[virtmic] Starting Virtmic with no target to make sure " + "Discord can find all the audio devices"; + m_virtmicProcess.start(QApplication::arguments()[0], + {"--virtmic", "None"}); + } + } } bool DiscordPage::acceptNavigationRequest(const QUrl &url, diff --git a/src/virtmic.cpp b/src/virtmic.cpp index f46fae7..758b1a9 100644 --- a/src/virtmic.cpp +++ b/src/virtmic.cpp @@ -90,58 +90,60 @@ void start(QString _target) { {"audio.position", "FL,FR"}}, pipewire::node::type, pipewire::node::version, false); - auto reg_events = reg.listen(); - reg_events.on( - [&](const pipewire::global &global) { - if (global.type == pipewire::node::type) { - auto node = reg.bind(global.id); - std::cout << "[virtmic] " - << "Added : " << node.info().props["node.name"] - << std::endl; + if (target != "None") { + auto reg_events = reg.listen(); + reg_events.on( + [&](const pipewire::global &global) { + if (global.type == pipewire::node::type) { + auto node = reg.bind(global.id); + std::cout << "[virtmic] " + << "Added : " << node.info().props["node.name"] + << std::endl; - if (!nodes.count(global.id)) { - nodes.emplace(global.id, node.info()); - link(target, core); - } - } - if (global.type == pipewire::port::type) { - auto port = reg.bind(global.id); - auto info = port.info(); - - if (info.props.count("node.id")) { - auto node_id = std::stoul(info.props["node.id"]); - - if (node_id == virtual_mic.id() && - info.direction == pipewire::port_direction::input) { - if (info.props["audio.channel"] == "FL") { - virt_fl = std::make_unique(std::move(port)); - } else { - virt_fr = std::make_unique(std::move(port)); - } - } else { - ports.emplace(global.id, std::move(port)); + if (!nodes.count(global.id)) { + nodes.emplace(global.id, node.info()); + link(target, core); } - - link(target, core); } - } - }); + if (global.type == pipewire::port::type) { + auto port = reg.bind(global.id); + auto info = port.info(); - reg_events.on( - [&](const std::uint32_t id) { - if (nodes.count(id)) { - auto info = nodes.at(id); - std::cout << "[virtmic] " - << "Removed: " << info.props["node.name"] << std::endl; - nodes.erase(id); - } - if (ports.count(id)) { - ports.erase(id); - } - if (links.count(id)) { - links.erase(id); - } - }); + if (info.props.count("node.id")) { + auto node_id = std::stoul(info.props["node.id"]); + + if (node_id == virtual_mic.id() && + info.direction == pipewire::port_direction::input) { + if (info.props["audio.channel"] == "FL") { + virt_fl = std::make_unique(std::move(port)); + } else { + virt_fr = std::make_unique(std::move(port)); + } + } else { + ports.emplace(global.id, std::move(port)); + } + + link(target, core); + } + } + }); + + reg_events.on( + [&](const std::uint32_t id) { + if (nodes.count(id)) { + auto info = nodes.at(id); + std::cout << "[virtmic] " + << "Removed: " << info.props["node.name"] << std::endl; + nodes.erase(id); + } + if (ports.count(id)) { + ports.erase(id); + } + if (links.count(id)) { + links.erase(id); + } + }); + } while (true) { main_loop.run();