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() {
m_targetComboBox->clear();
m_targetComboBox->addItem("None");
m_targetComboBox->addItem("[None]");
m_targetComboBox->addItem("[All Desktop Audio]");
for (auto target : Virtmic::getTargets()) {
m_targetComboBox->addItem(target);
}
m_targetComboBox->setCurrentText("[All Desktop Audio]");
}

View File

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