]> code.delx.au - pulseaudio/commitdiff
Revert "bluetooth: Update to new BlueZ 5 transport acquire/release API"
authorJoão Paulo Rechi Vita <jprvita@openbossa.org>
Tue, 13 Aug 2013 04:53:40 +0000 (01:53 -0300)
committerTanu Kaskinen <tanu.kaskinen@linux.intel.com>
Sun, 29 Sep 2013 13:54:35 +0000 (16:54 +0300)
This reverts commit 9615def4b96f0bab365ddc03f6c003f382a54752.

This is part of the reversion of BlueZ 5 support so it can be added back
in a separate set of modules. This makes the code easier to maintain and
decrease PulseAudio's binary size.

src/modules/bluetooth/bluetooth-util.c
src/modules/bluetooth/module-bluetooth-device.c

index 98517df1fab420d1df050f4c720f5e8ec8ff1170..41584113509cea4d1a0ab0cd88c38d638e7cca7a 100644 (file)
@@ -1448,52 +1448,40 @@ bool pa_bluetooth_device_any_audio_connected(const pa_bluetooth_device *d) {
 }
 
 int pa_bluetooth_transport_acquire(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu) {
+    const char *accesstype = "rw";
+    const char *interface;
     DBusMessage *m, *r;
     DBusError err;
     int ret;
     uint16_t i, o;
-    const char *method;
 
     pa_assert(t);
     pa_assert(t->device);
     pa_assert(t->device->discovery);
 
-    dbus_error_init(&err);
-
-    if (t->device->discovery->version == BLUEZ_VERSION_4) {
-        const char *accesstype = "rw";
-
-        if (optional) {
-            /* We are trying to acquire the transport only if the stream is
-               playing, without actually initiating the stream request from our side
-               (which is typically undesireable specially for hfgw use-cases.
-               However this approach is racy, since the stream could have been
-               suspended in the meantime, so we can't really guarantee that the
-               stream will not be requested with the API in BlueZ 4.x */
-            if (t->state < PA_BLUETOOTH_TRANSPORT_STATE_PLAYING) {
-                pa_log_info("Failed optional acquire of unavailable transport %s", t->path);
-                return -1;
-            }
+    interface = t->device->discovery->version == BLUEZ_VERSION_4 ? "org.bluez.MediaTransport" : "org.bluez.MediaTransport1";
+
+    if (optional) {
+        /* FIXME: we are trying to acquire the transport only if the stream is
+           playing, without actually initiating the stream request from our side
+           (which is typically undesireable specially for hfgw use-cases.
+           However this approach is racy, since the stream could have been
+           suspended in the meantime, so we can't really guarantee that the
+           stream will not be requested until BlueZ's API supports this
+           atomically. */
+        if (t->state < PA_BLUETOOTH_TRANSPORT_STATE_PLAYING) {
+            pa_log_info("Failed optional acquire of transport %s", t->path);
+            return -1;
         }
-
-        method = "Acquire";
-        pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, "org.bluez.MediaTransport", method));
-        pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_STRING, &accesstype, DBUS_TYPE_INVALID));
-    } else {
-        pa_assert(t->device->discovery->version == BLUEZ_VERSION_5);
-
-        method = optional ? "TryAcquire" : "Acquire";
-        pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, "org.bluez.MediaTransport1", method));
     }
 
+    dbus_error_init(&err);
+
+    pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, interface, "Acquire"));
+    pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_STRING, &accesstype, DBUS_TYPE_INVALID));
     r = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(t->device->discovery->connection), m, -1, &err);
 
     if (!r) {
-        if (optional && pa_streq(err.name, "org.bluez.Error.NotAvailable"))
-            pa_log_info("Failed optional acquire of unavailable transport %s", t->path);
-        else
-            pa_log("Transport %s() failed for transport %s (%s)", method, t->path, err.message);
-
         dbus_error_free(&err);
         return -1;
     }
@@ -1518,6 +1506,8 @@ fail:
 }
 
 void pa_bluetooth_transport_release(pa_bluetooth_transport *t) {
+    const char *accesstype = "rw";
+    const char *interface;
     DBusMessage *m;
     DBusError err;
 
@@ -1525,18 +1515,12 @@ void pa_bluetooth_transport_release(pa_bluetooth_transport *t) {
     pa_assert(t->device);
     pa_assert(t->device->discovery);
 
-    dbus_error_init(&err);
-
-    if (t->device->discovery->version == BLUEZ_VERSION_4) {
-        const char *accesstype = "rw";
+    interface = t->device->discovery->version == BLUEZ_VERSION_4 ? "org.bluez.MediaTransport" : "org.bluez.MediaTransport1";
 
-        pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, "org.bluez.MediaTransport", "Release"));
-        pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_STRING, &accesstype, DBUS_TYPE_INVALID));
-    } else {
-        pa_assert(t->device->discovery->version == BLUEZ_VERSION_5);
-        pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, "org.bluez.MediaTransport1", "Release"));
-    }
+    dbus_error_init(&err);
 
+    pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, interface, "Release"));
+    pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_STRING, &accesstype, DBUS_TYPE_INVALID));
     dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(t->device->discovery->connection), m, -1, &err);
 
     if (dbus_error_is_set(&err)) {
index de29e527513501e28f0ee323acd3a1dba517e54c..6e21863419f4e12ca14032b1b4c19b1c86713613 100644 (file)
@@ -367,8 +367,14 @@ static int bt_transport_acquire(struct userdata *u, bool optional) {
     pa_log_debug("Acquiring transport %s", u->transport->path);
 
     u->stream_fd = pa_bluetooth_transport_acquire(u->transport, optional, &u->read_link_mtu, &u->write_link_mtu);
-    if (u->stream_fd < 0)
+    if (u->stream_fd < 0) {
+        if (!optional)
+            pa_log("Failed to acquire transport %s", u->transport->path);
+        else
+            pa_log_info("Failed optional acquire of transport %s", u->transport->path);
+
         return -1;
+    }
 
     u->transport_acquired = true;
     pa_log_info("Transport %s acquired: fd %d", u->transport->path, u->stream_fd);