[pulseaudio-commits] src/modules

Georg Chini gchini at kemper.freedesktop.org
Sat Mar 11 18:05:18 UTC 2017


 src/modules/bluetooth/backend-native.c |   23 ++++++++++++++++++++---
 src/modules/bluetooth/bluez5-util.c    |   11 +++--------
 src/modules/bluetooth/bluez5-util.h    |    6 ++++--
 3 files changed, 27 insertions(+), 13 deletions(-)

New commits:
commit adc2e8cd0acc7e49aa1c32fa78a3ad27f457ffd7
Author: Georg Chini <georg at chini.tk>
Date:   Sat Mar 11 19:02:16 2017 +0100

    bluetooth: use native and ofono backends in parallel with headset=auto
    
    This patch changes the behavior of the headset=auto switch for module-bluez5-discover.
    With headset=auto now both backends will be active at the same time for the AG role and
    the switching between the backends is only done for the HS role.
    headset=ofono and headset=native remain unchanged.
    
    This allows to use old HSP only headsets while running ofono and to have headset support
    via pulseaudio if ofono is started with the --noplugin=hfp_ag_bluez5 option.

diff --git a/src/modules/bluetooth/backend-native.c b/src/modules/bluetooth/backend-native.c
index 4cfa8d0..e6bf6fe 100644
--- a/src/modules/bluetooth/backend-native.c
+++ b/src/modules/bluetooth/backend-native.c
@@ -40,6 +40,7 @@ struct pa_bluetooth_backend {
   pa_core *core;
   pa_dbus_connection *connection;
   pa_bluetooth_discovery *discovery;
+  bool enable_hs_role;
 
   PA_LLIST_HEAD(pa_dbus_pending, pending);
 };
@@ -657,7 +658,20 @@ static void profile_done(pa_bluetooth_backend *b, pa_bluetooth_profile_t profile
     }
 }
 
-pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y) {
+void pa_bluetooth_native_backend_enable_hs_role(pa_bluetooth_backend *native_backend, bool enable_hs_role) {
+
+   if (enable_hs_role == native_backend->enable_hs_role)
+       return;
+
+   if (enable_hs_role)
+       profile_init(native_backend, PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY);
+   else
+       profile_done(native_backend, PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY);
+
+   native_backend->enable_hs_role = enable_hs_role;
+}
+
+pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y, bool enable_hs_role) {
     pa_bluetooth_backend *backend;
     DBusError err;
 
@@ -675,8 +689,10 @@ pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_d
     }
 
     backend->discovery = y;
+    backend->enable_hs_role = enable_hs_role;
 
-    profile_init(backend, PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY);
+    if (enable_hs_role)
+       profile_init(backend, PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY);
     profile_init(backend, PA_BLUETOOTH_PROFILE_HEADSET_HEAD_UNIT);
 
     return backend;
@@ -687,7 +703,8 @@ void pa_bluetooth_native_backend_free(pa_bluetooth_backend *backend) {
 
     pa_dbus_free_pending_list(&backend->pending);
 
-    profile_done(backend, PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY);
+    if (backend->enable_hs_role)
+       profile_done(backend, PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY);
     profile_done(backend, PA_BLUETOOTH_PROFILE_HEADSET_HEAD_UNIT);
 
     pa_dbus_connection_unref(backend->connection);
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index 7d63f35..8d59b6b 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -982,12 +982,7 @@ void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is
     if (y->headset_backend != HEADSET_BACKEND_AUTO)
         return;
 
-    if (is_running && y->native_backend) {
-        pa_bluetooth_native_backend_free(y->native_backend);
-        y->native_backend = NULL;
-    }
-    else if (!is_running && !y->native_backend)
-        y->native_backend = pa_bluetooth_native_backend_new(y->core, y);
+    pa_bluetooth_native_backend_enable_hs_role(y->native_backend, !is_running);
 }
 
 static void get_managed_objects_reply(DBusPendingCall *pending, void *userdata) {
@@ -1028,10 +1023,10 @@ static void get_managed_objects_reply(DBusPendingCall *pending, void *userdata)
 
     y->objects_listed = true;
 
+    if (!y->native_backend && y->headset_backend != HEADSET_BACKEND_OFONO)
+        y->native_backend = pa_bluetooth_native_backend_new(y->core, y, (y->headset_backend == HEADSET_BACKEND_NATIVE));
     if (!y->ofono_backend && y->headset_backend != HEADSET_BACKEND_NATIVE)
         y->ofono_backend = pa_bluetooth_ofono_backend_new(y->core, y);
-    if (!y->ofono_backend && !y->native_backend && y->headset_backend != HEADSET_BACKEND_OFONO)
-        y->native_backend = pa_bluetooth_native_backend_new(y->core, y);
 
 finish:
     dbus_message_unref(r);
diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez5-util.h
index ef0c731..a3e7bf3 100644
--- a/src/modules/bluetooth/bluez5-util.h
+++ b/src/modules/bluetooth/bluez5-util.h
@@ -129,13 +129,15 @@ static inline void pa_bluetooth_ofono_backend_free(pa_bluetooth_backend *b) {}
 #endif
 
 #ifdef HAVE_BLUEZ_5_NATIVE_HEADSET
-pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y);
+pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y, bool enable_hs_role);
 void pa_bluetooth_native_backend_free(pa_bluetooth_backend *b);
+void pa_bluetooth_native_backend_enable_hs_role(pa_bluetooth_backend *b, bool enable_hs_role);
 #else
-static inline pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y) {
+static inline pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y, bool enable_hs_role) {
     return NULL;
 }
 static inline void pa_bluetooth_native_backend_free(pa_bluetooth_backend *b) {}
+static inline void pa_bluetooth_native_backend_enable_hs_role(pa_bluetooth_backend *b, bool enable_hs_role) {}
 #endif
 
 pa_bluetooth_transport *pa_bluetooth_transport_new(pa_bluetooth_device *d, const char *owner, const char *path,



More information about the pulseaudio-commits mailing list