[pulseaudio-discuss] [RFCv2 14/17] bluetooth: Suspend sink/source on HFP's stream HUP

jprvita at gmail.com jprvita at gmail.com
Mon Apr 15 14:53:29 PDT 2013


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

When the Audio Connection is disconnected 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 ae05a17..9a0b765 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -193,6 +193,7 @@ struct userdata {
 
 enum {
     BLUETOOTH_MESSAGE_IO_THREAD_FAILED,
+    BLUETOOTH_MESSAGE_TRANSPORT_STATE_CHANGED,
     BLUETOOTH_MESSAGE_MAX
 };
 
@@ -527,18 +528,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;
         }
     }
@@ -1175,6 +1183,12 @@ io_fail:
         pending_read_bytes = 0;
         writable = false;
 
+        if (u->profile == PROFILE_HFGW && pa_bluetooth_discovery_get_bluez_version(u->discovery) == BLUEZ_VERSION_5) {
+            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