[RFCv2 17/17] bluetooth: Postpone sink and source creation for BlueZ 5 HFP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jo?o Paulo Rechi Vita <jprvita@xxxxxxxxxxxxx>

CVSD and mSBC stream have different sample rates, and the CODEC of the
Audio Connection is only on NewConnection(). Since the sample rate is
needed to create the sink/source their creation is postponed to when the
transport changes its state to 'playing'.
---
 src/modules/bluetooth/module-bluetooth-device.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 22880c6..1f5bcbc 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -1579,6 +1579,11 @@ static pa_available_t get_port_availability(struct userdata *u, pa_direction_t d
     return result;
 }
 
+static void bt_transport_config(struct userdata *u);
+static int add_source(struct userdata *u);
+static int add_sink(struct userdata *u);
+static int start_thread(struct userdata *u);
+
 /* Run from main thread */
 static void handle_transport_state_change(struct userdata *u, struct pa_bluetooth_transport *transport) {
     bool acquire = false;
@@ -1613,6 +1618,18 @@ static void handle_transport_state_change(struct userdata *u, struct pa_bluetoot
 
     if (acquire)
         if (bt_transport_acquire(u, true) >= 0) {
+
+            /* Create sink and source with the correct sample rate for PROFILE_HFGW && BLUEZ5 */
+            if ((pa_bluetooth_discovery_get_bluez_version(u->discovery) == BLUEZ_VERSION_5) && profile == PROFILE_HFGW &&
+                (!u->sink || !u->source)) {
+
+                bt_transport_config(u);
+                add_sink(u);
+                add_source(u);
+                if (u->sink || u->source)
+                    start_thread(u);
+            }
+
             if (u->source) {
                 pa_log_debug("Resuming source %s, because the bluetooth audio state changed to 'playing'.", u->source->name);
                 pa_source_suspend(u->source, false, PA_SUSPEND_IDLE|PA_SUSPEND_USER);
@@ -2194,13 +2211,13 @@ static int init_profile(struct userdata *u) {
 
     if (u->profile == PROFILE_A2DP ||
         u->profile == PROFILE_HSP ||
-        u->profile == PROFILE_HFGW)
+        (u->profile == PROFILE_HFGW && pa_bluetooth_discovery_get_bluez_version(u->discovery) == BLUEZ_VERSION_4))
         if (add_sink(u) < 0)
             r = -1;
 
     if (u->profile == PROFILE_HSP ||
         u->profile == PROFILE_A2DP_SOURCE ||
-        u->profile == PROFILE_HFGW)
+        (u->profile == PROFILE_HFGW && pa_bluetooth_discovery_get_bluez_version(u->discovery) == BLUEZ_VERSION_4))
         if (add_source(u) < 0)
             r = -1;
 
-- 
1.7.11.7



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux