[pulseaudio-discuss] [PATCH 1/6] pactl: Add support for device-manager subscription

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


---
 src/utils/pactl.c | 80 ++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 49 insertions(+), 31 deletions(-)

diff --git a/src/utils/pactl.c b/src/utils/pactl.c
index 1dc8c3f..a3ff527 100644
--- a/src/utils/pactl.c
+++ b/src/utils/pactl.c
@@ -35,6 +35,7 @@
 #include <sndfile.h>
 
 #include <pulse/pulseaudio.h>
+#include <pulse/ext-device-manager.h>
 #include <pulse/ext-device-restore.h>
 
 #include <pulsecore/i18n.h>
@@ -813,7 +814,9 @@ static void get_sample_info_callback(pa_context *c, const pa_sample_info *i, int
 }
 
 static void simple_callback(pa_context *c, int success, void *userdata) {
-    if (!success) {
+    bool ignore_errors = (bool) userdata;
+
+    if (!success && !ignore_errors) {
         pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c)));
         quit(1);
         return;
@@ -873,7 +876,7 @@ static void unload_module_by_name_callback(pa_context *c, const pa_module_info *
     if (pa_streq(module_name, i->name)) {
         unloaded = true;
         actions++;
-        pa_operation_unref(pa_context_unload_module(c, i->index, simple_callback, NULL));
+        pa_operation_unref(pa_context_unload_module(c, i->index, simple_callback, (void *) false));
     }
 }
 
@@ -910,7 +913,7 @@ static void get_sink_volume_callback(pa_context *c, const pa_sink_info *i, int i
     cv = i->volume;
     fill_volume(&cv, i->channel_map.channels);
 
-    pa_operation_unref(pa_context_set_sink_volume_by_name(c, sink_name, &cv, simple_callback, NULL));
+    pa_operation_unref(pa_context_set_sink_volume_by_name(c, sink_name, &cv, simple_callback, (void *) false));
 }
 
 static void get_source_volume_callback(pa_context *c, const pa_source_info *i, int is_last, void *userdata) {
@@ -930,7 +933,7 @@ static void get_source_volume_callback(pa_context *c, const pa_source_info *i, i
     cv = i->volume;
     fill_volume(&cv, i->channel_map.channels);
 
-    pa_operation_unref(pa_context_set_source_volume_by_name(c, source_name, &cv, simple_callback, NULL));
+    pa_operation_unref(pa_context_set_source_volume_by_name(c, source_name, &cv, simple_callback, (void *) false));
 }
 
 static void get_sink_input_volume_callback(pa_context *c, const pa_sink_input_info *i, int is_last, void *userdata) {
@@ -950,7 +953,7 @@ static void get_sink_input_volume_callback(pa_context *c, const pa_sink_input_in
     cv = i->volume;
     fill_volume(&cv, i->channel_map.channels);
 
-    pa_operation_unref(pa_context_set_sink_input_volume(c, sink_input_idx, &cv, simple_callback, NULL));
+    pa_operation_unref(pa_context_set_sink_input_volume(c, sink_input_idx, &cv, simple_callback, (void *) false));
 }
 
 static void get_source_output_volume_callback(pa_context *c, const pa_source_output_info *o, int is_last, void *userdata) {
@@ -970,7 +973,7 @@ static void get_source_output_volume_callback(pa_context *c, const pa_source_out
     cv = o->volume;
     fill_volume(&cv, o->channel_map.channels);
 
-    pa_operation_unref(pa_context_set_source_output_volume(c, source_output_idx, &cv, simple_callback, NULL));
+    pa_operation_unref(pa_context_set_source_output_volume(c, source_output_idx, &cv, simple_callback, (void *) false));
 }
 
 static void sink_toggle_mute_callback(pa_context *c, const pa_sink_info *i, int is_last, void *userdata) {
@@ -985,7 +988,7 @@ static void sink_toggle_mute_callback(pa_context *c, const pa_sink_info *i, int
 
     pa_assert(i);
 
-    pa_operation_unref(pa_context_set_sink_mute_by_name(c, i->name, !i->mute, simple_callback, NULL));
+    pa_operation_unref(pa_context_set_sink_mute_by_name(c, i->name, !i->mute, simple_callback, (void *) false));
 }
 
 static void source_toggle_mute_callback(pa_context *c, const pa_source_info *o, int is_last, void *userdata) {
@@ -1000,7 +1003,7 @@ static void source_toggle_mute_callback(pa_context *c, const pa_source_info *o,
 
     pa_assert(o);
 
-    pa_operation_unref(pa_context_set_source_mute_by_name(c, o->name, !o->mute, simple_callback, NULL));
+    pa_operation_unref(pa_context_set_source_mute_by_name(c, o->name, !o->mute, simple_callback, (void *) false));
 }
 
 static void sink_input_toggle_mute_callback(pa_context *c, const pa_sink_input_info *i, int is_last, void *userdata) {
@@ -1015,7 +1018,7 @@ static void sink_input_toggle_mute_callback(pa_context *c, const pa_sink_input_i
 
     pa_assert(i);
 
-    pa_operation_unref(pa_context_set_sink_input_mute(c, i->index, !i->mute, simple_callback, NULL));
+    pa_operation_unref(pa_context_set_sink_input_mute(c, i->index, !i->mute, simple_callback, (void *) false));
 }
 
 static void source_output_toggle_mute_callback(pa_context *c, const pa_source_output_info *o, int is_last, void *userdata) {
@@ -1030,7 +1033,7 @@ static void source_output_toggle_mute_callback(pa_context *c, const pa_source_ou
 
     pa_assert(o);
 
-    pa_operation_unref(pa_context_set_source_output_mute(c, o->index, !o->mute, simple_callback, NULL));
+    pa_operation_unref(pa_context_set_source_output_mute(c, o->index, !o->mute, simple_callback, (void *) false));
 }
 
 /* PA_MAX_FORMATS is defined in internal.h so we just define a sane value here */
@@ -1055,7 +1058,7 @@ static void set_sink_formats(pa_context *c, uint32_t sink, const char *str) {
         pa_xfree(format);
     }
 
-    o = pa_ext_device_restore_save_formats(c, PA_DEVICE_TYPE_SINK, sink, i, f_arr, simple_callback, NULL);
+    o = pa_ext_device_restore_save_formats(c, PA_DEVICE_TYPE_SINK, sink, i, f_arr, simple_callback, (void *) false);
     if (o) {
         pa_operation_unref(o);
         actions++;
@@ -1184,6 +1187,13 @@ static void context_subscribe_callback(pa_context *c, pa_subscription_event_type
     fflush(stdout);
 }
 
+static void device_manager_subscribe_callback(pa_context *c, void *userdata) {
+    pa_assert(c);
+
+    printf(_("Event on device manager\n"));
+    fflush(stdout);
+}
+
 static void context_state_callback(pa_context *c, void *userdata) {
     pa_operation *o = NULL;
 
@@ -1206,11 +1216,11 @@ static void context_state_callback(pa_context *c, void *userdata) {
                     break;
 
                 case PLAY_SAMPLE:
-                    o = pa_context_play_sample(c, sample_name, sink_name, PA_VOLUME_NORM, simple_callback, NULL);
+                    o = pa_context_play_sample(c, sample_name, sink_name, PA_VOLUME_NORM, simple_callback, (void *) false);
                     break;
 
                 case REMOVE_SAMPLE:
-                    o = pa_context_remove_sample(c, sample_name, simple_callback, NULL);
+                    o = pa_context_remove_sample(c, sample_name, simple_callback, (void *) false);
                     break;
 
                 case UPLOAD_SAMPLE:
@@ -1224,7 +1234,7 @@ static void context_state_callback(pa_context *c, void *userdata) {
                     break;
 
                 case EXIT:
-                    o = pa_context_exit_daemon(c, simple_callback, NULL);
+                    o = pa_context_exit_daemon(c, simple_callback, (void *) false);
                     break;
 
                 case LIST:
@@ -1300,11 +1310,11 @@ static void context_state_callback(pa_context *c, void *userdata) {
                     break;
 
                 case MOVE_SINK_INPUT:
-                    o = pa_context_move_sink_input_by_name(c, sink_input_idx, sink_name, simple_callback, NULL);
+                    o = pa_context_move_sink_input_by_name(c, sink_input_idx, sink_name, simple_callback, (void *) false);
                     break;
 
                 case MOVE_SOURCE_OUTPUT:
-                    o = pa_context_move_source_output_by_name(c, source_output_idx, source_name, simple_callback, NULL);
+                    o = pa_context_move_source_output_by_name(c, source_output_idx, source_name, simple_callback, (void *) false);
                     break;
 
                 case LOAD_MODULE:
@@ -1315,69 +1325,69 @@ static void context_state_callback(pa_context *c, void *userdata) {
                     if (module_name)
                         o = pa_context_get_module_info_list(c, unload_module_by_name_callback, NULL);
                     else
-                        o = pa_context_unload_module(c, module_index, simple_callback, NULL);
+                        o = pa_context_unload_module(c, module_index, simple_callback, (void *) false);
                     break;
 
                 case SUSPEND_SINK:
                     if (sink_name)
-                        o = pa_context_suspend_sink_by_name(c, sink_name, suspend, simple_callback, NULL);
+                        o = pa_context_suspend_sink_by_name(c, sink_name, suspend, simple_callback, (void *) false);
                     else
-                        o = pa_context_suspend_sink_by_index(c, PA_INVALID_INDEX, suspend, simple_callback, NULL);
+                        o = pa_context_suspend_sink_by_index(c, PA_INVALID_INDEX, suspend, simple_callback, (void *) false);
                     break;
 
                 case SUSPEND_SOURCE:
                     if (source_name)
-                        o = pa_context_suspend_source_by_name(c, source_name, suspend, simple_callback, NULL);
+                        o = pa_context_suspend_source_by_name(c, source_name, suspend, simple_callback, (void *) false);
                     else
-                        o = pa_context_suspend_source_by_index(c, PA_INVALID_INDEX, suspend, simple_callback, NULL);
+                        o = pa_context_suspend_source_by_index(c, PA_INVALID_INDEX, suspend, simple_callback, (void *) false);
                     break;
 
                 case SET_CARD_PROFILE:
-                    o = pa_context_set_card_profile_by_name(c, card_name, profile_name, simple_callback, NULL);
+                    o = pa_context_set_card_profile_by_name(c, card_name, profile_name, simple_callback, (void *) false);
                     break;
 
                 case SET_SINK_PORT:
-                    o = pa_context_set_sink_port_by_name(c, sink_name, port_name, simple_callback, NULL);
+                    o = pa_context_set_sink_port_by_name(c, sink_name, port_name, simple_callback, (void *) false);
                     break;
 
                 case SET_DEFAULT_SINK:
-                    o = pa_context_set_default_sink(c, sink_name, simple_callback, NULL);
+                    o = pa_context_set_default_sink(c, sink_name, simple_callback, (void *) false);
                     break;
 
                 case SET_SOURCE_PORT:
-                    o = pa_context_set_source_port_by_name(c, source_name, port_name, simple_callback, NULL);
+                    o = pa_context_set_source_port_by_name(c, source_name, port_name, simple_callback, (void *) false);
                     break;
 
                 case SET_DEFAULT_SOURCE:
-                    o = pa_context_set_default_source(c, source_name, simple_callback, NULL);
+                    o = pa_context_set_default_source(c, source_name, simple_callback, (void *) false);
                     break;
 
                 case SET_SINK_MUTE:
                     if (mute == TOGGLE_MUTE)
                         o = pa_context_get_sink_info_by_name(c, sink_name, sink_toggle_mute_callback, NULL);
                     else
-                        o = pa_context_set_sink_mute_by_name(c, sink_name, mute, simple_callback, NULL);
+                        o = pa_context_set_sink_mute_by_name(c, sink_name, mute, simple_callback, (void *) false);
                     break;
 
                 case SET_SOURCE_MUTE:
                     if (mute == TOGGLE_MUTE)
                         o = pa_context_get_source_info_by_name(c, source_name, source_toggle_mute_callback, NULL);
                     else
-                        o = pa_context_set_source_mute_by_name(c, source_name, mute, simple_callback, NULL);
+                        o = pa_context_set_source_mute_by_name(c, source_name, mute, simple_callback, (void *) false);
                     break;
 
                 case SET_SINK_INPUT_MUTE:
                     if (mute == TOGGLE_MUTE)
                         o = pa_context_get_sink_input_info(c, sink_input_idx, sink_input_toggle_mute_callback, NULL);
                     else
-                        o = pa_context_set_sink_input_mute(c, sink_input_idx, mute, simple_callback, NULL);
+                        o = pa_context_set_sink_input_mute(c, sink_input_idx, mute, simple_callback, (void *) false);
                     break;
 
                 case SET_SOURCE_OUTPUT_MUTE:
                     if (mute == TOGGLE_MUTE)
                         o = pa_context_get_source_output_info(c, source_output_idx, source_output_toggle_mute_callback, NULL);
                     else
-                        o = pa_context_set_source_output_mute(c, source_output_idx, mute, simple_callback, NULL);
+                        o = pa_context_set_source_output_mute(c, source_output_idx, mute, simple_callback, (void *) false);
                     break;
 
                 case SET_SINK_VOLUME:
@@ -1401,7 +1411,7 @@ static void context_state_callback(pa_context *c, void *userdata) {
                     break;
 
                 case SET_PORT_LATENCY_OFFSET:
-                    o = pa_context_set_port_latency_offset(c, card_name, port_name, latency_offset, simple_callback, NULL);
+                    o = pa_context_set_port_latency_offset(c, card_name, port_name, latency_offset, simple_callback, (void *) false);
                     break;
 
                 case SUBSCRIBE:
@@ -1419,6 +1429,14 @@ static void context_state_callback(pa_context *c, void *userdata) {
                                              PA_SUBSCRIPTION_MASK_CARD,
                                              NULL,
                                              NULL);
+                    if (o) {
+                        pa_operation_unref(o);
+                        actions++;
+                    }
+
+                    pa_ext_device_manager_set_subscribe_cb(c, device_manager_subscribe_callback, NULL);
+                    o = pa_ext_device_manager_subscribe(c, true, simple_callback, (void *) true);
+
                     break;
 
                 default:
-- 
1.9.3



More information about the pulseaudio-discuss mailing list