use rohrkabel as submodule and update it to v1.2

This commit is contained in:
Malte Jürgens 2022-07-26 16:33:34 +02:00
parent 6492cb9a35
commit bc59458e19
No known key found for this signature in database
GPG key ID: D29FBD5F93C0CFC3
6 changed files with 98 additions and 74 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "submodules/rohrkabel"]
path = submodules/rohrkabel
url = https://github.com/Soundux/rohrkabel

View file

@ -22,14 +22,26 @@ set(discord-screenaudio_SRC
resources.qrc resources.qrc
) )
include(FetchContent) # Adapted from https://cliutils.gitlab.io/modern-cmake/chapters/projects/submodule.html
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Updating submodules")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "`git submodule update --init --recursive` failed with ${GIT_SUBMOD_RESULT}, please provide the submodules manually")
endif()
endif()
endif()
FetchContent_Declare( if(NOT EXISTS "${PROJECT_SOURCE_DIR}/submodules/rohrkabel/CMakeLists.txt")
rohrkabel message(FATAL_ERROR "Rohrkabel was not found since you are not in a Git checkout or have GIT_SUBMODULE disabled. Please provide rohrkabel manually to `./submodules/rohrkabel`.")
GIT_REPOSITORY "https://github.com/Soundux/rohrkabel" endif()
GIT_TAG "d87403f48d3a95aa4bcf4cd60112d9e4bb090d5d"
) add_subdirectory(submodules/rohrkabel)
FetchContent_MakeAvailable(rohrkabel)
add_executable(discord-screenaudio ${discord-screenaudio_SRC}) add_executable(discord-screenaudio ${discord-screenaudio_SRC})

View file

@ -89,6 +89,7 @@ void DiscordPage::stopVirtmic() {
if (m_virtmicProcess.state() == QProcess::Running) { if (m_virtmicProcess.state() == QProcess::Running) {
qDebug() << "[virtmic] Stopping Virtmic"; qDebug() << "[virtmic] Stopping Virtmic";
m_virtmicProcess.kill(); m_virtmicProcess.kill();
m_virtmicProcess.waitForFinished();
} }
} }

View file

@ -1,5 +1,8 @@
#include "virtmic.h" #include "virtmic.h"
#include <rohrkabel/loop/main.hpp>
#include <rohrkabel/registry/registry.hpp>
namespace Virtmic { namespace Virtmic {
QVector<QString> getTargets() { QVector<QString> getTargets() {
@ -24,7 +27,7 @@ QVector<QString> getTargets() {
} }
} }
}); });
core.sync(); core.update();
return targets; return targets;
} }
@ -67,12 +70,12 @@ void start(QString _target) {
<< "Link : " << target << ":" << port_id << " -> "; << "Link : " << target << ":" << port_id << " -> ";
if (port.info().props["audio.channel"] == "FL") { if (port.info().props["audio.channel"] == "FL") {
links.emplace(port_id, core.create<pipewire::link_factory>( links.emplace(port_id, core.create_simple<pipewire::link_factory>(
{virt_fl->info().id, port_id})); virt_fl->info().id, port_id));
std::cout << "[virtmic] " << virt_fl->info().id << std::endl; std::cout << "[virtmic] " << virt_fl->info().id << std::endl;
} else { } else {
links.emplace(port_id, core.create<pipewire::link_factory>( links.emplace(port_id, core.create_simple<pipewire::link_factory>(
{virt_fr->info().id, port_id})); virt_fr->info().id, port_id));
std::cout << "[virtmic] " << virt_fr->info().id << std::endl; std::cout << "[virtmic] " << virt_fr->info().id << std::endl;
} }
} }
@ -81,70 +84,75 @@ void start(QString _target) {
std::string target = _target.toLatin1().toStdString(); std::string target = _target.toLatin1().toStdString();
auto virtual_mic = auto virtual_mic = core.create("adapter",
core.create("adapter", {{"node.name", "discord-screenaudio-virtmic"},
{{"node.name", "discord-screenaudio-virtmic"}, {"media.class", "Audio/Source/Virtual"},
{"media.class", "Audio/Source/Virtual"}, {"factory.name", "support.null-audio-sink"},
{"factory.name", "support.null-audio-sink"}, {"audio.channels", "2"},
{"audio.channels", "2"}, {"audio.position", "FL,FR"}},
{"audio.position", "FL,FR"}}, pipewire::node::type, pipewire::node::version,
pipewire::node::type, pipewire::node::version, false); pipewire::update_strategy::none);
if (target != "None") { if (target == "None") {
auto reg_events = reg.listen<pipewire::registry_listener>(); while (true) {
reg_events.on<pipewire::registry_event::global>( main_loop.run();
[&](const pipewire::global &global) { }
if (global.type == pipewire::node::type) { return;
auto node = reg.bind<pipewire::node>(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<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);
}
}
});
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);
}
});
} }
auto reg_events = reg.listen<pipewire::registry_listener>();
reg_events.on<pipewire::registry_event::global>(
[&](const pipewire::global &global) {
if (global.type == pipewire::node::type) {
auto node = reg.bind<pipewire::node>(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<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);
}
}
});
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();
} }

View file

@ -3,7 +3,6 @@
#include <QString> #include <QString>
#include <QVector> #include <QVector>
#include <iostream> #include <iostream>
#include <rohrkabel/registry/registry.hpp>
namespace Virtmic { namespace Virtmic {

1
submodules/rohrkabel Submodule

@ -0,0 +1 @@
Subproject commit a2d04d1e27a7b0aa2c2fe4de28b60ada22c7c348