[pulseaudio-discuss] [RFC next v0 03/11] bluetooth: Add backend->core notification of new transports

Mikel Astiz mikel.astiz.oss at gmail.com
Wed May 15 01:46:48 PDT 2013


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

Backends are responsible for the notification of new transports, which
is backend-dependant. The core still holds ownership of the transport
objects.
---
 src/modules/bluetooth/bluetooth-util.c | 45 ++++++++++++++++++++++++----------
 src/modules/bluetooth/bluetooth-util.h | 13 ++++++++++
 2 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 2e3203e..56156a9 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -1594,23 +1594,22 @@ static int setup_dbus(pa_bluetooth_discovery *y) {
 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) {
     pa_bluetooth_transport *t;
+    pa_bluetooth_transport_new_data data;
 
-    t = pa_xnew0(pa_bluetooth_transport, 1);
-    t->device = d;
-    t->owner = pa_xstrdup(owner);
-    t->path = pa_xstrdup(path);
-    t->profile = p;
-    t->config_size = size;
-
-    if (size > 0) {
-        t->config = pa_xnew(uint8_t, size);
-        memcpy(t->config, config, size);
-    }
+    data.device = d;
+    data.profile = p;
+    data.config_size = size;
+    data.config = config;
 
     if (d->discovery->version == BLUEZ_VERSION_4)
-        t->state = audio_state_to_transport_state(d->profile_state[p]);
+        data.state = audio_state_to_transport_state(d->profile_state[p]);
     else
-        t->state = PA_BLUETOOTH_TRANSPORT_STATE_IDLE;
+        data.state = PA_BLUETOOTH_TRANSPORT_STATE_IDLE;
+
+    t = pa_bt_backend_notify_transport_added(&data);
+
+    t->owner = pa_xstrdup(owner);
+    t->path = pa_xstrdup(path);
 
     return t;
 }
@@ -2277,6 +2276,26 @@ void pa_bt_backend_unregister(pa_bluetooth_discovery *y, pa_bluetooth_backend *b
     y->profiles[p].backend_private = NULL;
 }
 
+pa_bluetooth_transport *pa_bt_backend_notify_transport_added(pa_bluetooth_transport_new_data *data) {
+    pa_bluetooth_transport *t;
+
+    pa_assert(data);
+
+    t = pa_xnew0(pa_bluetooth_transport, 1);
+    t->device = data->device;
+    t->profile = data->profile;
+    t->state = data->state;
+
+    if ((t->config_size = data->config_size) > 0) {
+        pa_assert(data->config);
+
+        t->config = pa_xnew(uint8_t, data->config_size);
+        memcpy(t->config, data->config, data->config_size);
+    }
+
+    return t;
+}
+
 void pa_bt_backend_notify_transport_removed(pa_bluetooth_transport *t) {
     pa_bluetooth_discovery *y;
     pa_bluetooth_device *d;
diff --git a/src/modules/bluetooth/bluetooth-util.h b/src/modules/bluetooth/bluetooth-util.h
index 3f54802..1a72ca6 100644
--- a/src/modules/bluetooth/bluetooth-util.h
+++ b/src/modules/bluetooth/bluetooth-util.h
@@ -188,6 +188,19 @@ int pa_bt_backend_register(pa_bluetooth_discovery *y, pa_bluetooth_backend *b, e
 void pa_bt_backend_unregister(pa_bluetooth_discovery *y, pa_bluetooth_backend *b, enum profile p);
 
 /* Reporting of events from backend to Bluetooth core */
+typedef struct pa_bluetooth_transport_new_data {
+    pa_bluetooth_device *device;
+    enum profile profile;
+    uint8_t codec;
+    const uint8_t *config;
+    int config_size;
+    pa_bluetooth_transport_state_t state;
+    bool nrec;
+    uint16_t microphone_gain;
+    uint16_t speaker_gain;
+} pa_bluetooth_transport_new_data;
+
+pa_bluetooth_transport *pa_bt_backend_notify_transport_added(pa_bluetooth_transport_new_data *data);
 void pa_bt_backend_notify_transport_removed(pa_bluetooth_transport *t);
 void pa_bt_backend_notify_state(pa_bluetooth_transport *t, pa_bluetooth_transport_state_t state);
 void pa_bt_backend_notify_nrec(pa_bluetooth_transport *t, bool nrec);
-- 
1.8.1.4



More information about the pulseaudio-discuss mailing list