[pulseaudio-discuss] [PATCH next v0 11/11] bluetooth: Connect all hooks during module load/unload

Mikel Astiz mikel.astiz.oss at gmail.com
Thu Dec 6 06:55:36 PST 2012


From: Mikel Astiz <mikel.astiz at bmw-carit.de>

Move the connection of sink/source-related hooks to module
initialization and shutdown, to group all of them together. There is
no need to connect them every time the card profile is changed.
---
 src/modules/bluetooth/module-bluetooth-device.c | 42 +++++++++++--------------
 1 file changed, 19 insertions(+), 23 deletions(-)

diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 608f80a..2bd55b6 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -122,8 +122,6 @@ struct hsp_info {
     void (*sco_sink_set_volume)(pa_sink *s);
     pa_source *sco_source;
     void (*sco_source_set_volume)(pa_source *s);
-    pa_hook_slot *sink_state_changed_slot;
-    pa_hook_slot *source_state_changed_slot;
 };
 
 struct bluetooth_msg {
@@ -146,6 +144,8 @@ struct userdata {
     pa_bluetooth_transport *transport;
     char *accesstype;
     pa_hook_slot *discovery_slot;
+    pa_hook_slot *sink_state_changed_slot;
+    pa_hook_slot *source_state_changed_slot;
     pa_hook_slot *transport_state_changed_slot;
     pa_hook_slot *transport_nrec_changed_slot;
 
@@ -1684,10 +1684,6 @@ static int add_sink(struct userdata *u) {
         pa_proplist_sets(p, "bluetooth.protocol", profile_to_string(u->profile));
         pa_proplist_update(u->sink->proplist, PA_UPDATE_MERGE, p);
         pa_proplist_free(p);
-
-        if (!u->hsp.sink_state_changed_slot)
-            u->hsp.sink_state_changed_slot = pa_hook_connect(&u->core->hooks[PA_CORE_HOOK_SINK_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_state_changed_cb, u);
-
     } else {
         pa_sink_new_data data;
         pa_bool_t b;
@@ -1758,10 +1754,6 @@ static int add_source(struct userdata *u) {
     if (USE_SCO_OVER_PCM(u)) {
         u->source = u->hsp.sco_source;
         pa_proplist_sets(u->source->proplist, "bluetooth.protocol", profile_to_string(u->profile));
-
-        if (!u->hsp.source_state_changed_slot)
-            u->hsp.source_state_changed_slot = pa_hook_connect(&u->core->hooks[PA_CORE_HOOK_SOURCE_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) source_state_changed_cb, u);
-
     } else {
         pa_source_new_data data;
         pa_bool_t b;
@@ -2037,16 +2029,6 @@ static void stop_thread(struct userdata *u) {
         u->rtpoll_item = NULL;
     }
 
-    if (u->hsp.sink_state_changed_slot) {
-        pa_hook_slot_free(u->hsp.sink_state_changed_slot);
-        u->hsp.sink_state_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;
-    }
-
     if (u->transport) {
         bt_transport_release(u);
         u->transport = NULL;
@@ -2636,6 +2618,14 @@ int pa__init(pa_module* m) {
         pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_DEVICE_UUID_ADDED),
                         PA_HOOK_NORMAL, (pa_hook_cb_t) uuid_added_cb, u);
 
+    u->sink_state_changed_slot =
+        pa_hook_connect(&u->core->hooks[PA_CORE_HOOK_SINK_STATE_CHANGED],
+                        PA_HOOK_NORMAL, (pa_hook_cb_t) sink_state_changed_cb, u);
+
+    u->source_state_changed_slot =
+        pa_hook_connect(&u->core->hooks[PA_CORE_HOOK_SOURCE_STATE_CHANGED],
+                        PA_HOOK_NORMAL, (pa_hook_cb_t) source_state_changed_cb, u);
+
     u->transport_state_changed_slot =
         pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED),
                         PA_HOOK_NORMAL, (pa_hook_cb_t) transport_state_changed_cb, u);
@@ -2734,6 +2724,15 @@ void pa__done(pa_module *m) {
     if (u->discovery_slot)
         pa_hook_slot_free(u->discovery_slot);
 
+    if (u->uuid_added_slot)
+        pa_hook_slot_free(u->uuid_added_slot);
+
+    if (u->sink_state_changed_slot)
+        pa_hook_slot_free(u->sink_state_changed_slot);
+
+    if (u->source_state_changed_slot)
+        pa_hook_slot_free(u->source_state_changed_slot);
+
     if (u->transport_state_changed_slot)
         pa_hook_slot_free(u->transport_state_changed_slot);
 
@@ -2765,9 +2764,6 @@ void pa__done(pa_module *m) {
         pa_dbus_connection_unref(u->connection);
     }
 
-    if (u->uuid_added_slot)
-        pa_hook_slot_free(u->uuid_added_slot);
-
     if (u->msg)
         pa_xfree(u->msg);
 
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list