]> code.delx.au - pulseaudio/blobdiff - src/modules/module-position-event-sounds.c
bluetooth: Use a helper function for setting device_info_valid
[pulseaudio] / src / modules / module-position-event-sounds.c
index 7221b14f089e5254258d3957cb9e25fe411ed85b..531fee7a7c8e89d8b904f75d3e729c455a0e2250 100644 (file)
 #endif
 
 #include <unistd.h>
-#include <string.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <ctype.h>
 
 #include <pulse/xmalloc.h>
 #include <pulse/volume.h>
 #include <pulse/channelmap.h>
 
-#include <pulsecore/core-error.h>
 #include <pulsecore/module.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/modargs.h>
@@ -47,7 +44,7 @@
 PA_MODULE_AUTHOR("Lennart Poettering");
 PA_MODULE_DESCRIPTION("Position event sounds between L and R depending on the position on screen of the widget triggering them.");
 PA_MODULE_VERSION(PACKAGE_VERSION);
-PA_MODULE_LOAD_ONCE(TRUE);
+PA_MODULE_LOAD_ONCE(true);
 
 static const char* const valid_modargs[] = {
     NULL
@@ -55,6 +52,7 @@ static const char* const valid_modargs[] = {
 
 struct userdata {
     pa_hook_slot *sink_input_fixate_hook_slot;
+    const char *name;
 };
 
 static int parse_pos(const char *pos, double *f) {
@@ -74,9 +72,9 @@ static int parse_pos(const char *pos, double *f) {
 }
 
 static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *core, pa_sink_input_new_data *data, struct userdata *u) {
-    const char *hpos, *vpos, *role;
+    const char *hpos, *vpos, *role, *id;
     double f;
-    char t[PA_CVOLUME_SNPRINT_MAX];
+    char t[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
     pa_cvolume v;
 
     pa_assert(data);
@@ -87,6 +85,22 @@ static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *core, pa_sink_i
     if (!pa_streq(role, "event"))
         return PA_HOOK_OK;
 
+    if ((id = pa_proplist_gets(data->proplist, PA_PROP_EVENT_ID))) {
+
+        /* The test sounds should never be positioned in space, since
+         * they might be triggered themselves to configure the speakers
+         * in space, which we don't want to mess up. */
+
+        if (pa_startswith(id, "audio-channel-"))
+            return PA_HOOK_OK;
+
+        if (pa_streq(id, "audio-volume-change"))
+            return PA_HOOK_OK;
+
+        if (pa_streq(id, "audio-test-signal"))
+            return PA_HOOK_OK;
+    }
+
     if (!(hpos = pa_proplist_gets(data->proplist, PA_PROP_EVENT_MOUSE_HPOS)))
         hpos = pa_proplist_gets(data->proplist, PA_PROP_WINDOW_HPOS);
 
@@ -118,8 +132,13 @@ static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *core, pa_sink_i
         }
     }
 
-    pa_log_debug("Final volume factor %s.", pa_cvolume_snprint(t, sizeof(t), &v));
-    pa_sink_input_new_data_apply_volume_factor_sink(data, &v);
+    pa_log_debug("Final volume factor %s.",
+                 pa_cvolume_snprint_verbose(t,
+                                            sizeof(t),
+                                            &v,
+                                            &data->sink->channel_map,
+                                            data->sink->flags & PA_SINK_DECIBEL_VOLUME));
+    pa_sink_input_new_data_add_volume_factor_sink(data, u->name, &v);
 
     return PA_HOOK_OK;
 }
@@ -139,6 +158,7 @@ int pa__init(pa_module*m) {
     u->sink_input_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) sink_input_fixate_hook_callback, u);
 
     pa_modargs_free(ma);
+    u->name = m->name;
 
     return 0;
 
@@ -148,7 +168,7 @@ fail:
     if (ma)
         pa_modargs_free(ma);
 
-    return  -1;
+    return -1;
 }
 
 void pa__done(pa_module*m) {