bluetooth: Suspend sink/source on HFP's stream HUP
authorJoão Paulo Rechi Vita <jprvita@openbossa.org>
Wed, 27 Mar 2013 04:43:42 +0000 (01:43 -0300)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 16 Oct 2013 10:52:05 +0000 (13:52 +0300)
When the Audio Connection is disconnected the sink and source should be
suspended.

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

index 2c0ef80..7803b22 100644 (file)
@@ -74,6 +74,7 @@ static const char* const valid_modargs[] = {
 
 enum {
     BLUETOOTH_MESSAGE_IO_THREAD_FAILED,
+    BLUETOOTH_MESSAGE_TRANSPORT_STATE_CHANGED,
     BLUETOOTH_MESSAGE_MAX
 };
 
@@ -1427,6 +1428,12 @@ io_fail:
         pending_read_bytes = 0;
         writable = false;
 
+        if (u->profile == PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY) {
+            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);
     }
 
@@ -1994,15 +2001,19 @@ static pa_hook_result_t transport_state_changed_cb(pa_bluetooth_discovery *y, pa
 
 /* Run 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;
     }