allow sharing all desktop audio

This commit is contained in:
Malte Jürgens 2022-08-04 15:27:39 +02:00
parent b42fde85d1
commit c325dd6798
2 changed files with 16 additions and 8 deletions

View file

@ -71,8 +71,10 @@ void StreamDialog::startStream() {
void StreamDialog::updateTargets() { void StreamDialog::updateTargets() {
m_targetComboBox->clear(); m_targetComboBox->clear();
m_targetComboBox->addItem("None"); m_targetComboBox->addItem("[None]");
m_targetComboBox->addItem("[All Desktop Audio]");
for (auto target : Virtmic::getTargets()) { for (auto target : Virtmic::getTargets()) {
m_targetComboBox->addItem(target); m_targetComboBox->addItem(target);
} }
m_targetComboBox->setCurrentText("[All Desktop Audio]");
} }

View file

@ -6,6 +6,8 @@
namespace Virtmic { namespace Virtmic {
const QStringList EXCLUDE_TARGETS{"Chromium input", "discord-screenaudio"};
QVector<QString> getTargets() { QVector<QString> getTargets() {
auto main_loop = pipewire::main_loop(); auto main_loop = pipewire::main_loop();
auto context = pipewire::context(main_loop); auto context = pipewire::context(main_loop);
@ -20,11 +22,11 @@ QVector<QString> getTargets() {
if (global.type == pipewire::node::type) { if (global.type == pipewire::node::type) {
auto node = reg.bind<pipewire::node>(global.id); auto node = reg.bind<pipewire::node>(global.id);
auto info = node.info(); auto info = node.info();
auto name = QString::fromStdString(info.props["application.name"]);
if (info.props.count("application.name")) { if (name != "" && !EXCLUDE_TARGETS.contains(name) &&
auto name = QString::fromStdString(info.props["application.name"]); !targets.contains(name)) {
if (!targets.contains(name)) targets.append(name);
targets.append(name);
} }
} }
}); });
@ -65,15 +67,19 @@ void start(QString _target) {
continue; continue;
auto &parent = nodes.at(parent_id); auto &parent = nodes.at(parent_id);
auto name = parent.props["application.name"];
if (parent.props["application.name"].find(target) != std::string::npos) { if (name == target ||
(target == "[All Desktop Audio]" &&
!EXCLUDE_TARGETS.contains(QString::fromStdString(name)))) {
auto fl = port.info().props["audio.channel"] == "FL"; auto fl = port.info().props["audio.channel"] == "FL";
links.emplace( links.emplace(
port_id, port_id,
core.create<pipewire::link_factory>( core.create<pipewire::link_factory>(
{fl ? virt_fl->info().id : virt_fr->info().id, port_id})); {fl ? virt_fl->info().id : virt_fr->info().id, port_id}));
qDebug(virtmicLog) << QString("Link: %1:%2 -> %3") qDebug(virtmicLog) << QString("Link: %1:%2 -> %3")
.arg(QString::fromStdString(target)) .arg(QString::fromStdString(
parent.props["application.name"]))
.arg(port_id) .arg(port_id)
.arg(fl ? virt_fl->info().id .arg(fl ? virt_fl->info().id
: virt_fr->info().id) : virt_fr->info().id)
@ -94,7 +100,7 @@ void start(QString _target) {
pipewire::node::type, pipewire::node::version, pipewire::node::type, pipewire::node::version,
pipewire::update_strategy::none); pipewire::update_strategy::none);
if (target == "None") { if (target == "[None]") {
while (true) { while (true) {
main_loop.run(); main_loop.run();
} }