[pulseaudio-discuss] [PATCH v3 1/3] bluetooth: ofono: Use Acquire method if available

Luiz Augusto von Dentz luiz.dentz at gmail.com
Thu May 25 08:36:35 UTC 2017


From: Luiz Augusto von Dentz <luiz.von.dentz at intel.com>

Attempt to use Acquire method if available.
---
 src/modules/bluetooth/backend-ofono.c | 59 +++++++++++++++++++++++++----------
 1 file changed, 43 insertions(+), 16 deletions(-)

diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
index 6e9a366..d098402 100644
--- a/src/modules/bluetooth/backend-ofono.c
+++ b/src/modules/bluetooth/backend-ofono.c
@@ -150,6 +150,46 @@ static int socket_accept(int sock)
     return 0;
 }
 
+static int card_acquire(struct hf_audio_card *card) {
+    pa_bluetooth_transport *t = card->transport;
+    DBusMessage *m, *r;
+    DBusError err;
+
+    if (card->connecting)
+        return -EAGAIN;
+
+    /* Try acquiring the stream first */
+    dbus_error_init(&err);
+    pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, "org.ofono.HandsfreeAudioCard", "Acquire"));
+    r = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(card->backend->connection), m, -1, &err);
+    if (!r) {
+        if (!pa_streq(err.name, DBUS_ERROR_UNKNOWN_METHOD)) {
+            pa_log_error("Failed to acquire %s: %s", err.name, err.message);
+            return -1;
+        }
+    } else if ((dbus_message_get_args(r, NULL,
+                         DBUS_TYPE_UNIX_FD, &card->fd,
+                         DBUS_TYPE_BYTE, &card->codec,
+                         DBUS_TYPE_INVALID) == true)) {
+        return card->fd;
+    } else
+        return -1;
+
+    /* Fallback to Connect as this might be an old version of ofono */
+    card->connecting = true;
+
+    dbus_error_init(&err);
+    pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, "org.ofono.HandsfreeAudioCard", "Connect"));
+    r = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(card->backend->connection), m, -1, &err);
+    if (!r)
+        return -1;
+
+    if (card->connecting)
+        return -EAGAIN;
+
+    return card->fd;
+}
+
 static int hf_audio_agent_transport_acquire(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu) {
     struct hf_audio_card *card = t->userdata;
     int err;
@@ -157,22 +197,9 @@ static int hf_audio_agent_transport_acquire(pa_bluetooth_transport *t, bool opti
     pa_assert(card);
 
     if (!optional && card->fd < 0) {
-        DBusMessage *m, *r;
-        DBusError derr;
-
-        if (card->connecting)
-            return -EAGAIN;
-
-        card->connecting = true;
-
-        dbus_error_init(&derr);
-        pa_assert_se(m = dbus_message_new_method_call(t->owner, t->path, "org.ofono.HandsfreeAudioCard", "Connect"));
-        r = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(card->backend->connection), m, -1, &derr);
-        if (!r)
-            return -1;
-
-        if (card->connecting)
-            return -EAGAIN;
+        err = card_acquire(card);
+        if (err < 0)
+            return err;
     }
 
     /* The correct block size should take into account the SCO MTU from
-- 
2.9.4



More information about the pulseaudio-discuss mailing list