[pulseaudio-discuss] [RFC 23/24] bluetooth: Suspend source and sink for PROFILE_HFP_AG

jprvita at gmail.com jprvita at gmail.com
Tue Mar 26 22:17:02 PDT 2013


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

When the remote device disconnects the Audio Connection a POLL_HUP will
happen on the stream fd and the sink and source should be suspended.
---
 src/modules/bluetooth/module-bluetooth-device.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index b533947..a691fc8 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -189,6 +189,7 @@ struct userdata {
 
 enum {
     BLUETOOTH_MESSAGE_IO_THREAD_FAILED,
+    BLUETOOTH_MESSAGE_TRANSPORT_STATE_CHANGED,
     BLUETOOTH_MESSAGE_MAX
 };
 
@@ -523,18 +524,25 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
     return (r < 0 || !failed) ? r : -1;
 }
 
+static void handle_transport_state_change(struct userdata *u, struct pa_bluetooth_transport *transport);
+
 /* Called from main thread context */
 static int device_process_msg(pa_msgobject *obj, int code, void *data, int64_t offset, pa_memchunk *chunk) {
-    struct bluetooth_msg *u = BLUETOOTH_MSG(obj);
+    struct bluetooth_msg *b = BLUETOOTH_MSG(obj);
+    struct userdata *u = data;
 
     switch (code) {
+        case BLUETOOTH_MESSAGE_TRANSPORT_STATE_CHANGED:
+            handle_transport_state_change(u, u->transport);
+            break;
+
         case BLUETOOTH_MESSAGE_IO_THREAD_FAILED: {
-            if (u->card->module->unload_requested)
+            if (b->card->module->unload_requested)
                 break;
 
             pa_log_debug("Switching the profile to off due to IO thread failure.");
 
-            pa_assert_se(pa_card_set_profile(u->card, "off", false) >= 0);
+            pa_assert_se(pa_card_set_profile(b->card, "off", false) >= 0);
             break;
         }
     }
@@ -1171,6 +1179,12 @@ io_fail:
         pending_read_bytes = 0;
         writable = false;
 
+        if (u->profile == PROFILE_HFP_AG) {
+            u->transport->state = PA_BLUETOOTH_TRANSPORT_STATE_IDLE;
+            pa_asyncmsgq_post(pa_thread_mq_get()->outq, PA_MSGOBJECT(u->msg), BLUETOOTH_MESSAGE_TRANSPORT_STATE_CHANGED, u, 0,
+                              NULL, NULL);
+        }
+
         teardown_stream(u);
     }
 
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list