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

@ -174,7 +174,9 @@ License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
<option>
<p><opt>set-default-sink</opt> <arg>SINK</arg></p>
<optdesc><p>Make the specified sink (identified by its symbolic name or numerical index) the default sink.</p></optdesc>
<optdesc><p>Make the specified sink (identified by its symbolic name or numerical index) the default sink.
Use the special name \@NONE@ to unset the user defined default sink. This will make pulseaudio return to the default
sink selection based on sink priority.</p></optdesc>
</option>
<option>
@ -189,7 +191,9 @@ License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
<option>
<p><opt>set-default-source</opt> <arg>SOURCE</arg></p>
<optdesc><p>Make the specified source (identified by its symbolic name or numerical index) the default source.</p></optdesc>
<optdesc><p>Make the specified source (identified by its symbolic name or numerical index) the default source.
Use the special name \@NONE@ to unset the user defined default source. This will make pulseaudio return to the default
source selection based on source priority.</p></optdesc>
</option>
<option>

View File

@ -143,8 +143,10 @@ License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
<p><opt>set-default-sink|set-default-source</opt> <arg>index|name</arg></p>
<optdesc><p>Make a sink (resp. source) the default. You may specify the
sink (resp. source) by its index in the sink (resp. source) list or by its
name.</p><p>Note that defaults may be overridden by various policy modules
or by specific stream configurations.</p></optdesc>
name. Use the special name \@NONE@ to unset the user defined default sink or
source. In this case, pulseaudio will return to the default sink or source
selection based on priority.</p><p>Note that defaults may be overridden by
various policy modules or by specific stream configurations.</p></optdesc>
</option>
<option>

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);