[pulseaudio-discuss] [RFC 2/2] bluetooth: Add inband ringtone property

Frédéric Danis frederic.danis at linux.intel.com
Mon Nov 12 07:19:10 PST 2012


---
 src/modules/bluetooth/module-bluetooth-device.c |   37 +++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 656852d..c734d6c 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -122,6 +122,7 @@ struct hsp_info {
     pa_source *sco_source;
     void (*sco_source_set_volume)(pa_source *s);
     pa_hook_slot *sink_state_changed_slot;
+    pa_hook_slot *sink_property_changed_slot;
     pa_hook_slot *source_state_changed_slot;
     pa_hook_slot *nrec_changed_slot;
     pa_hook_slot *output_gain_slot;
@@ -1593,6 +1594,34 @@ static pa_hook_result_t sink_state_changed_cb(pa_core *c, pa_sink *s, struct use
     return PA_HOOK_OK;
 }
 
+static pa_hook_result_t sink_property_changed_cb(pa_core *c, pa_sink *s, struct userdata *u) {
+    const char *str;
+    int val;
+    dbus_bool_t value;
+    const char *name = "InbandRingtone";
+
+    pa_assert(c);
+    pa_sink_assert_ref(s);
+    pa_assert(u);
+
+    if (s != u->sink)
+        return PA_HOOK_OK;
+
+    str = pa_proplist_gets(u->sink->proplist, "bluetooth.bsir");
+    if (str == NULL)
+        return PA_HOOK_OK;
+
+    val = pa_parse_boolean(str);
+    if (val < 0)
+        return PA_HOOK_OK;
+
+    value = !!val;
+
+    send_property_update(u, name, DBUS_TYPE_BOOLEAN, &value);
+
+    return PA_HOOK_OK;
+}
+
 static pa_hook_result_t source_state_changed_cb(pa_core *c, pa_source *s, struct userdata *u) {
     pa_assert(c);
     pa_source_assert_ref(s);
@@ -1804,6 +1833,9 @@ static int add_sink(struct userdata *u) {
         pa_sink_set_set_volume_callback(u->sink, sink_set_volume_cb);
         u->sink->n_volume_steps = 16;
 
+        if (!u->hsp.sink_property_changed_slot)
+            u->hsp.sink_property_changed_slot = pa_hook_connect(&u->core->hooks[PA_CORE_HOOK_SINK_PROPLIST_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_property_changed_cb, u);
+
         k = pa_sprintf_malloc("bluetooth-device@%p", (void*) u->sink);
         pa_shared_set(u->core, k, u);
         pa_xfree(k);
@@ -2112,6 +2144,11 @@ static void stop_thread(struct userdata *u) {
         u->hsp.sink_state_changed_slot = NULL;
     }
 
+    if (u->hsp.sink_property_changed_slot) {
+        pa_hook_slot_free(u->hsp.sink_property_changed_slot);
+        u->hsp.sink_property_changed_slot = NULL;
+    }
+
     if (u->hsp.source_state_changed_slot) {
         pa_hook_slot_free(u->hsp.source_state_changed_slot);
         u->hsp.source_state_changed_slot = NULL;
-- 
1.7.9.5



More information about the pulseaudio-discuss mailing list