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
)
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(
rohrkabel
GIT_REPOSITORY "https://github.com/Soundux/rohrkabel"
GIT_TAG "d87403f48d3a95aa4bcf4cd60112d9e4bb090d5d"
)
FetchContent_MakeAvailable(rohrkabel)
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/submodules/rohrkabel/CMakeLists.txt")
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`.")
endif()
add_subdirectory(submodules/rohrkabel)
add_executable(discord-screenaudio ${discord-screenaudio_SRC})

View file

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

View file

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

View file

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

1
submodules/rohrkabel Submodule

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