[pulseaudio-discuss] [PATCH 5/6] pactl: New command: device-manager-set-routing-enabled

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Wed Jan 14 13:27:13 PST 2015


---
 man/pactl.1.xml.in               |  9 +++++++++
 shell-completion/bash/pulseaudio |  7 ++++++-
 shell-completion/zsh/_pulseaudio |  2 ++
 src/utils/pactl.c                | 32 ++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/man/pactl.1.xml.in b/man/pactl.1.xml.in
index 8cff2e4..e59f44a 100644
--- a/man/pactl.1.xml.in
+++ b/man/pactl.1.xml.in
@@ -273,6 +273,15 @@ License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
       is loaded.</p></optdesc>
     </option>
 
+    <option>
+      <p><opt>device-manager-set-routing-enabled</opt> <arg>ENABLED</arg></p>
+      <optdesc><p>Enable or disable routing in device-manager. The argument is
+      a boolean. When routing is enabled, device-manager routes streams to the
+      highest priority device that is currently available. This command works
+      only if module-device-manager is loaded. Querying the current state has
+      not been implemented yet.</p></optdesc>
+    </option>
+
   </section>
 
   <section name="Authors">
diff --git a/shell-completion/bash/pulseaudio b/shell-completion/bash/pulseaudio
index 6d598ce..e641419 100644
--- a/shell-completion/bash/pulseaudio
+++ b/shell-completion/bash/pulseaudio
@@ -129,7 +129,8 @@ _pactl() {
                     set-sink-formats set-port-latency-offset subscribe help
                     device-manager-list-devices
                     device-manager-set-device-description
-                    device-manager-delete-entries)
+                    device-manager-delete-entries
+                    device-manager-set-routing-enabled)
 
     _init_completion -n = || return
     preprev=${words[$cword-2]}
@@ -244,6 +245,10 @@ _pactl() {
             COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
             ;;
 
+        device-manager-set-routing-enabled)
+            COMPREPLY=($(compgen -W 'true false' -- "$cur"))
+            ;;
+
         -s)
             _known_hosts_real "$cur" ;;
     esac
diff --git a/shell-completion/zsh/_pulseaudio b/shell-completion/zsh/_pulseaudio
index 4e8eae4..bbdd8cb 100644
--- a/shell-completion/zsh/_pulseaudio
+++ b/shell-completion/zsh/_pulseaudio
@@ -289,6 +289,7 @@ _pactl_completion() {
             'device-manager-list-devices: list devices in the device-manager database'
             'device-manager-set-device-description: set the description of a device'
             'device-manager-delete-entries: delete device entries from the device-manager database'
+            'device-manager-set-routing-enabled: enable or disable routing in device-manager'
         )
 
         _describe 'pactl commands' _pactl_commands
@@ -519,6 +520,7 @@ _pactl_completion() {
             set-port-latency-offset)               _set_port_latency_offset_parameter;;
             device-manager-set-device-description) if ((CURRENT == 2)); then _device_manager_devices; fi;;
             device-manager-delete-entries)         _device_manager_devices;;
+            device-manager-set-routing-enabled)    if ((CURRENT == 2)); then compadd true false; fi;;
         esac
     }
 
diff --git a/src/utils/pactl.c b/src/utils/pactl.c
index e5eba49..81c8851 100644
--- a/src/utils/pactl.c
+++ b/src/utils/pactl.c
@@ -90,6 +90,8 @@ static enum mute_flags {
     TOGGLE_MUTE = 2
 } mute = INVALID_MUTE;
 
+bool routing_enabled;
+
 static pa_proplist *proplist = NULL;
 
 static SNDFILE *sndfile = NULL;
@@ -140,6 +142,7 @@ static enum {
     DEVICE_MANAGER_LIST_DEVICES,
     DEVICE_MANAGER_SET_DEVICE_DESCRIPTION,
     DEVICE_MANAGER_DELETE_ENTRIES,
+    DEVICE_MANAGER_SET_ROUTING_ENABLED,
 } action = NONE;
 
 static void quit(int ret) {
@@ -1504,6 +1507,11 @@ static void context_state_callback(pa_context *c, void *userdata) {
                     o = pa_ext_device_manager_delete(c, (const char * const *) devices, simple_callback, (void *) false);
                     break;
 
+                case DEVICE_MANAGER_SET_ROUTING_ENABLED:
+                    o = pa_ext_device_manager_enable_role_device_priority_routing(c, routing_enabled, simple_callback,
+                                                                                  (void *) false);
+                    break;
+
                 case NONE:
                     pa_assert_not_reached();
             }
@@ -1661,6 +1669,7 @@ static void help(const char *argv0) {
     printf("%s %s %s\n",    argv0, _("[options]"), "device-manager-list-devices");
     printf("%s %s %s %s\n", argv0, _("[options]"), "device-manager-set-device-description", _("DEVICE DESCRIPTION"));
     printf("%s %s %s %s\n", argv0, _("[options]"), "device-manager-delete-entries", _("DEVICE [DEVICE ...]"));
+    printf("%s %s %s %s\n", argv0, _("[options]"), "device-manager-set-routing-enabled", "1|0");
     printf(_("\nThe special names @DEFAULT_SINK@, @DEFAULT_SOURCE@ and @DEFAULT_MONITOR@\n"
              "can be used to specify the default sink, source and monitor.\n"));
 
@@ -2165,6 +2174,29 @@ int main(int argc, char *argv[]) {
             for (i = 0; i < n_devices; i++)
                 devices[i] = pa_xstrdup(argv[optind + 1 + i]);
 
+        } else if (pa_streq(argv[optind], "device-manager-set-routing-enabled")) {
+            int r;
+
+            action = DEVICE_MANAGER_SET_ROUTING_ENABLED;
+
+            if (argc < optind + 2) {
+                pa_log(_("Too few arguments. You have to specify whether routing should be enabled or not."));
+                goto quit;
+            }
+
+            if (argc > optind + 2) {
+                pa_log(_("Too many arguments."));
+                goto quit;
+            }
+
+            r = pa_parse_boolean(argv[optind + 1]);
+            if (r >= 0)
+                routing_enabled = r;
+            else {
+                pa_log(_("Failed to parse boolean: %s"), argv[optind + 1]);
+                goto quit;
+            }
+
         } else if (pa_streq(argv[optind], "help")) {
             help(bn);
             ret = 0;
-- 
1.9.3



More information about the pulseaudio-discuss mailing list