From bc59458e19b8059d4e577105d63184bbf417d6eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20J=C3=BCrgens?= Date: Tue, 26 Jul 2022 16:33:34 +0200 Subject: [PATCH] use rohrkabel as submodule and update it to v1.2 --- .gitmodules | 3 + CMakeLists.txt | 26 +++++--- src/discordpage.cpp | 1 + src/virtmic.cpp | 140 +++++++++++++++++++++++-------------------- src/virtmic.h | 1 - submodules/rohrkabel | 1 + 6 files changed, 98 insertions(+), 74 deletions(-) create mode 100644 .gitmodules create mode 160000 submodules/rohrkabel diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..900b7d9 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "submodules/rohrkabel"] + path = submodules/rohrkabel + url = https://github.com/Soundux/rohrkabel diff --git a/CMakeLists.txt b/CMakeLists.txt index a3f41e6..1e1777b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/src/discordpage.cpp b/src/discordpage.cpp index eb7a4e2..aa4d946 100644 --- a/src/discordpage.cpp +++ b/src/discordpage.cpp @@ -89,6 +89,7 @@ void DiscordPage::stopVirtmic() { if (m_virtmicProcess.state() == QProcess::Running) { qDebug() << "[virtmic] Stopping Virtmic"; m_virtmicProcess.kill(); + m_virtmicProcess.waitForFinished(); } } diff --git a/src/virtmic.cpp b/src/virtmic.cpp index 758b1a9..1730136 100644 --- a/src/virtmic.cpp +++ b/src/virtmic.cpp @@ -1,5 +1,8 @@ #include "virtmic.h" +#include +#include + namespace Virtmic { QVector getTargets() { @@ -24,7 +27,7 @@ QVector 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( - {virt_fl->info().id, port_id})); + links.emplace(port_id, core.create_simple( + virt_fl->info().id, port_id)); std::cout << "[virtmic] " << virt_fl->info().id << std::endl; } else { - links.emplace(port_id, core.create( - {virt_fr->info().id, port_id})); + links.emplace(port_id, core.create_simple( + 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(); - reg_events.on( - [&](const pipewire::global &global) { - if (global.type == pipewire::node::type) { - auto node = reg.bind(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(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(std::move(port)); - } else { - virt_fr = std::make_unique(std::move(port)); - } - } else { - ports.emplace(global.id, std::move(port)); - } - - link(target, core); - } - } - }); - - reg_events.on( - [&](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(); + reg_events.on( + [&](const pipewire::global &global) { + if (global.type == pipewire::node::type) { + auto node = reg.bind(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(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(std::move(port)); + } else { + virt_fr = std::make_unique(std::move(port)); + } + } else { + ports.emplace(global.id, std::move(port)); + } + + link(target, core); + } + } + }); + + reg_events.on( + [&](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(); } diff --git a/src/virtmic.h b/src/virtmic.h index 7543942..361f240 100644 --- a/src/virtmic.h +++ b/src/virtmic.h @@ -3,7 +3,6 @@ #include #include #include -#include namespace Virtmic { diff --git a/submodules/rohrkabel b/submodules/rohrkabel new file mode 160000 index 0000000..a2d04d1 --- /dev/null +++ b/submodules/rohrkabel @@ -0,0 +1 @@ +Subproject commit a2d04d1e27a7b0aa2c2fe4de28b60ada22c7c348