pactl, pacmd: Allow to unset the configured default sink or source

Currently there is no way to unset the default sink or source once it was
configured manually by the user.
This patch introduces the special name @NONE@, which can be used with the pacmd
or pactl set-default-sink and set-default-source commands to unset the user
configured default. When the default is unset, pulseaudio will return to the
standard default sink or source selection mechanism based on priority.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/785>
This commit is contained in:
Georg Chini 2023-03-20 21:35:10 +01:00 committed by PulseAudio Marge Bot
parent 25bfdb3ab8
commit 86e9c90128
4 changed files with 35 additions and 15 deletions

View file

@ -1038,7 +1038,9 @@ static int pa_cli_command_sink_default(pa_core *c, pa_tokenizer *t, pa_strbuf *b
return -1;
}
if ((s = pa_namereg_get(c, n, PA_NAMEREG_SINK)))
if (pa_streq(n, "@NONE@"))
pa_core_set_configured_default_sink(c, NULL);
else if ((s = pa_namereg_get(c, n, PA_NAMEREG_SINK)))
pa_core_set_configured_default_sink(c, s->name);
else
pa_strbuf_printf(buf, "Sink %s does not exist.\n", n);
@ -1060,7 +1062,9 @@ static int pa_cli_command_source_default(pa_core *c, pa_tokenizer *t, pa_strbuf
return -1;
}
if ((s = pa_namereg_get(c, n, PA_NAMEREG_SOURCE)))
if (pa_streq(n, "@NONE@"))
pa_core_set_configured_default_source(c, NULL);
else if ((s = pa_namereg_get(c, n, PA_NAMEREG_SOURCE)))
pa_core_set_configured_default_source(c, s->name);
else
pa_strbuf_printf(buf, "Source %s does not exist.\n", n);

View file

@ -4379,23 +4379,33 @@ static void command_set_default_sink_or_source(pa_pdispatch *pd, uint32_t comman
}
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
CHECK_VALIDITY(c->pstream, !s || pa_namereg_is_valid_name(s), tag, PA_ERR_INVALID);
CHECK_VALIDITY(c->pstream, !s || pa_namereg_is_valid_name(s) || pa_safe_streq(s,"@NONE@"), tag, PA_ERR_INVALID);
if (command == PA_COMMAND_SET_DEFAULT_SOURCE) {
pa_source *source;
char *source_name = NULL;
source = pa_namereg_get(c->protocol->core, s, PA_NAMEREG_SOURCE);
CHECK_VALIDITY(c->pstream, source, tag, PA_ERR_NOENTITY);
if (!pa_safe_streq(s,"@NONE@")) {
pa_source *source;
pa_core_set_configured_default_source(c->protocol->core, source->name);
source = pa_namereg_get(c->protocol->core, s, PA_NAMEREG_SOURCE);
CHECK_VALIDITY(c->pstream, source, tag, PA_ERR_NOENTITY);
source_name = source->name;
}
pa_core_set_configured_default_source(c->protocol->core, source_name);
} else {
pa_sink *sink;
char *sink_name = NULL;
pa_assert(command == PA_COMMAND_SET_DEFAULT_SINK);
sink = pa_namereg_get(c->protocol->core, s, PA_NAMEREG_SINK);
CHECK_VALIDITY(c->pstream, sink, tag, PA_ERR_NOENTITY);
if (!pa_safe_streq(s,"@NONE@")) {
pa_sink *sink;
pa_core_set_configured_default_sink(c->protocol->core, sink->name);
sink = pa_namereg_get(c->protocol->core, s, PA_NAMEREG_SINK);
CHECK_VALIDITY(c->pstream, sink, tag, PA_ERR_NOENTITY);
sink_name = sink->name;
}
pa_core_set_configured_default_sink(c->protocol->core, sink_name);
}
pa_pstream_send_simple_ack(c->pstream, tag);