[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] pactl, pacmd: Allow to unset the configured default sink or source

PulseAudio Marge Bot (@pulseaudio-merge-bot) gitlab at gitlab.freedesktop.org
Sat Mar 25 20:57:46 UTC 2023



PulseAudio Marge Bot pushed to branch master at PulseAudio / pulseaudio


Commits:
86e9c901 by Georg Chini at 2023-03-25T20:55:48+00:00
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>

- - - - -


4 changed files:

- man/pactl.1.xml.in
- man/pulse-cli-syntax.5.xml.in
- src/pulsecore/cli-command.c
- src/pulsecore/protocol-native.c


Changes:

=====================================
man/pactl.1.xml.in
=====================================
@@ -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>


=====================================
man/pulse-cli-syntax.5.xml.in
=====================================
@@ -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>


=====================================
src/pulsecore/cli-command.c
=====================================
@@ -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);


=====================================
src/pulsecore/protocol-native.c
=====================================
@@ -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;
+
+            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);
+        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;
+
+            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_core_set_configured_default_sink(c->protocol->core, sink_name);
     }
 
     pa_pstream_send_simple_ack(c->pstream, tag);



View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/86e9c901289d2e1a3c2c6cb5885294a829f3eb27

-- 
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/86e9c901289d2e1a3c2c6cb5885294a829f3eb27
You're receiving this email because of your account on gitlab.freedesktop.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20230325/a0236534/attachment-0001.htm>


More information about the pulseaudio-commits mailing list