[pulseaudio-discuss] [RFCv3 08/20] bluetooth: Create a pa_bluetooth_transport for each HF card

jprvita at gmail.com jprvita at gmail.com
Sun Apr 21 20:07:38 PDT 2013


From: João Paulo Rechi Vita <jprvita at openbossa.org>

Every time a HF card is found a new pa_transport is created on the
pa_bluetooth_device representing the bluetooth audio device. This way
the module-bluetooth-device is loaded if necessary, and kept around even
when all other transports get disconnected.
---
 src/modules/bluetooth/bluetooth-util.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 6334c79..26623a4 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -135,8 +135,13 @@ struct handsfree_card {
 
     int fd;
     uint8_t codec;
+
+    pa_bluetooth_device *device;
 };
 
+static pa_bluetooth_transport *transport_new(pa_bluetooth_device *d, const char *owner, const char *path, enum profile p,
+                                             const uint8_t *config, int size);
+
 static void get_properties_reply(DBusPendingCall *pending, void *userdata);
 static pa_dbus_pending* send_and_add_to_pending(pa_bluetooth_discovery *y, DBusMessage *m, DBusPendingCallNotifyFunction func,
                                                 void *call_data);
@@ -1214,6 +1219,21 @@ static void hfagent_card_found(pa_bluetooth_discovery *y, const char *path, DBus
     }
 
     pa_hashmap_put(y->hf_cards, hf_card->path, hf_card);
+
+    hf_card->device = pa_bluetooth_discovery_get_by_address(y, hf_card->remote);
+    if(hf_card->device) {
+        bool old_any_connected = pa_bluetooth_device_any_audio_connected(hf_card->device);
+        pa_bluetooth_transport *t = transport_new(hf_card->device, y->ofono_bus_id, path,
+                                                                    PROFILE_HFGW, NULL, 0);
+        hf_card->device->transports[PROFILE_HFGW] = t;
+        pa_assert_se(pa_hashmap_put(y->transports, t->path, t) >= 0);
+        pa_hook_fire(&y->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED], t);
+
+        if (old_any_connected != pa_bluetooth_device_any_audio_connected(hf_card->device))
+            run_callback(hf_card->device, false);
+    } else
+        pa_log_error("Device doesnt exist for %s", path);
+
     return;
 
 fail:
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list