start virtmic with no target when audio capture is requested
This commit is contained in:
parent
a814d9cc1b
commit
6492cb9a35
|
@ -63,6 +63,15 @@ void DiscordPage::featurePermissionRequested(const QUrl &securityOrigin,
|
||||||
// Allow every permission asked
|
// Allow every permission asked
|
||||||
setFeaturePermission(securityOrigin, feature,
|
setFeaturePermission(securityOrigin, feature,
|
||||||
QWebEnginePage::PermissionGrantedByUser);
|
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,
|
bool DiscordPage::acceptNavigationRequest(const QUrl &url,
|
||||||
|
|
|
@ -90,58 +90,60 @@ void start(QString _target) {
|
||||||
{"audio.position", "FL,FR"}},
|
{"audio.position", "FL,FR"}},
|
||||||
pipewire::node::type, pipewire::node::version, false);
|
pipewire::node::type, pipewire::node::version, false);
|
||||||
|
|
||||||
auto reg_events = reg.listen<pipewire::registry_listener>();
|
if (target != "None") {
|
||||||
reg_events.on<pipewire::registry_event::global>(
|
auto reg_events = reg.listen<pipewire::registry_listener>();
|
||||||
[&](const pipewire::global &global) {
|
reg_events.on<pipewire::registry_event::global>(
|
||||||
if (global.type == pipewire::node::type) {
|
[&](const pipewire::global &global) {
|
||||||
auto node = reg.bind<pipewire::node>(global.id);
|
if (global.type == pipewire::node::type) {
|
||||||
std::cout << "[virtmic] "
|
auto node = reg.bind<pipewire::node>(global.id);
|
||||||
<< "Added : " << node.info().props["node.name"]
|
std::cout << "[virtmic] "
|
||||||
<< std::endl;
|
<< "Added : " << node.info().props["node.name"]
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
if (!nodes.count(global.id)) {
|
if (!nodes.count(global.id)) {
|
||||||
nodes.emplace(global.id, node.info());
|
nodes.emplace(global.id, node.info());
|
||||||
link(target, core);
|
link(target, core);
|
||||||
}
|
|
||||||
}
|
|
||||||
if (global.type == pipewire::port::type) {
|
|
||||||
auto port = reg.bind<pipewire::port>(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<pipewire::port>(std::move(port));
|
|
||||||
} else {
|
|
||||||
virt_fr = std::make_unique<pipewire::port>(std::move(port));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ports.emplace(global.id, std::move(port));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
link(target, core);
|
|
||||||
}
|
}
|
||||||
}
|
if (global.type == pipewire::port::type) {
|
||||||
});
|
auto port = reg.bind<pipewire::port>(global.id);
|
||||||
|
auto info = port.info();
|
||||||
|
|
||||||
reg_events.on<pipewire::registry_event::global_removed>(
|
if (info.props.count("node.id")) {
|
||||||
[&](const std::uint32_t id) {
|
auto node_id = std::stoul(info.props["node.id"]);
|
||||||
if (nodes.count(id)) {
|
|
||||||
auto info = nodes.at(id);
|
if (node_id == virtual_mic.id() &&
|
||||||
std::cout << "[virtmic] "
|
info.direction == pipewire::port_direction::input) {
|
||||||
<< "Removed: " << info.props["node.name"] << std::endl;
|
if (info.props["audio.channel"] == "FL") {
|
||||||
nodes.erase(id);
|
virt_fl = std::make_unique<pipewire::port>(std::move(port));
|
||||||
}
|
} else {
|
||||||
if (ports.count(id)) {
|
virt_fr = std::make_unique<pipewire::port>(std::move(port));
|
||||||
ports.erase(id);
|
}
|
||||||
}
|
} else {
|
||||||
if (links.count(id)) {
|
ports.emplace(global.id, std::move(port));
|
||||||
links.erase(id);
|
}
|
||||||
}
|
|
||||||
});
|
link(target, core);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
reg_events.on<pipewire::registry_event::global_removed>(
|
||||||
|
[&](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) {
|
while (true) {
|
||||||
main_loop.run();
|
main_loop.run();
|
||||||
|
|
Loading…
Reference in New Issue