Skip to content

Commit

Permalink
Merge pull request loki-47-6F-64#372 from Logical-sh/no-sink-path-reb…
Browse files Browse the repository at this point in the history
…ased

[Linux Pulse/Pipewire] No sink path *rebased*
  • Loading branch information
ReenigneArcher authored Oct 11, 2022
2 parents 4352541 + 907798f commit f51a84c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
8 changes: 7 additions & 1 deletion src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,14 @@ void capture(safe::mail_t mail, config_t config, void *channel_data) {
if(!ref->sink_flag->exchange(true, std::memory_order_acquire)) {
ref->restore_sink = !config.flags[config_t::HOST_AUDIO];

// If the sink is empty (Host has no sink!), definately switch to the virtual.
if(ref->sink.host.empty()) {
if(control->set_sink(*sink)) {
return;
}
}
// If the client requests audio on the host, don't change the default sink
if(!config.flags[config_t::HOST_AUDIO] && control->set_sink(*sink)) {
else if(!config.flags[config_t::HOST_AUDIO] && control->set_sink(*sink)) {
return;
}
}
Expand Down
27 changes: 16 additions & 11 deletions src/platform/linux/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,7 @@ class server_t : public audio_control_t {
}

auto sink_name = get_default_sink_name();
if(sink_name.empty()) {
BOOST_LOG(warning) << "Couldn't find an active sink"sv;
}
else {
sink.host = sink_name;
}
sink.host = sink_name;

if(index.stereo == PA_INVALID_INDEX) {
index.stereo = load_null(stereo, speaker::map_stereo, sizeof(speaker::map_stereo));
Expand Down Expand Up @@ -380,6 +375,10 @@ class server_t : public audio_control_t {
}
}

if(sink_name.empty()) {
BOOST_LOG(warning) << "Couldn't find an active default sink. Continuing with virtual audio only."sv;
}

if(nullcount == 3) {
sink.null = std::make_optional(sink_t::null_t { stereo, surround51, surround71 });
}
Expand All @@ -388,16 +387,18 @@ class server_t : public audio_control_t {
}

std::string get_default_sink_name() {
std::string sink_name = "@DEFAULT_SINK@"s;
auto alarm = safe::make_alarm<int>();
std::string sink_name;
auto alarm = safe::make_alarm<int>();

cb_simple_t<pa_server_info *> server_f = [&](ctx_t::pointer ctx, const pa_server_info *server_info) {
if(!server_info) {
BOOST_LOG(error) << "Couldn't get pulseaudio server info: "sv << pa_strerror(pa_context_errno(ctx));
alarm->ring(-1);
}

sink_name = server_info->default_sink_name;
if(server_info->default_sink_name) {
sink_name = server_info->default_sink_name;
}
alarm->ring(0);
};

Expand All @@ -408,8 +409,12 @@ class server_t : public audio_control_t {
}

std::string get_monitor_name(const std::string &sink_name) {
std::string monitor_name = "@DEFAULT_MONITOR@"s;
auto alarm = safe::make_alarm<int>();
std::string monitor_name;
auto alarm = safe::make_alarm<int>();

if(sink_name.empty()) {
return monitor_name;
}

cb_t<pa_sink_info *> sink_f = [&](ctx_t::pointer ctx, const pa_sink_info *sink_info, int eol) {
if(!sink_info) {
Expand Down

0 comments on commit f51a84c

Please sign in to comment.