[pulseaudio-commits] 5 commits - configure.ac src/Makefile.am src/modules

David Henningsson diwic at kemper.freedesktop.org
Fri Nov 14 02:46:31 PST 2014


 configure.ac                                      |   33 ++++++++++------
 src/Makefile.am                                   |   12 +++++-
 src/modules/bluetooth/backend-native.c            |    6 +--
 src/modules/bluetooth/backend-null.c              |   37 ------------------
 src/modules/bluetooth/backend-ofono.c             |   30 ++++++++-------
 src/modules/bluetooth/bluez5-util.c               |   43 +++++++++++++++++-----
 src/modules/bluetooth/bluez5-util.h               |   28 ++++++++++++--
 src/modules/bluetooth/module-bluetooth-discover.c |    5 ++
 src/modules/bluetooth/module-bluez5-discover.c    |   39 +++++++++++++++++++
 9 files changed, 151 insertions(+), 82 deletions(-)

New commits:
commit 9ae85b1a29b5b9a0637a0f755457f749a141c920
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Mon Nov 10 16:13:13 2014 +0100

    bluetooth: Select headset backend through module argument
    
    This patch adds a module argument "headset=ofono|native|auto" to
    module-bluetooth-discover and module-bluez5-discover.
    
    To make Arun's happy, the default is 'native' if compiled in, otherwise
    'ofono'. 'Auto' will try to autoswitch depending on whether ofono is
    running or not.
    
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index 4121b76..6894e83 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -87,6 +87,7 @@ struct pa_bluetooth_discovery {
     pa_hashmap *devices;
     pa_hashmap *transports;
 
+    int headset_backend;
     pa_bluetooth_backend *ofono_backend, *native_backend;
     PA_LLIST_HEAD(pa_dbus_pending, pending);
 };
@@ -865,6 +866,9 @@ void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is
     pa_assert(y);
 
     pa_log_debug("oFono is running: %s", pa_yes_no(is_running));
+    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;
@@ -911,9 +915,9 @@ static void get_managed_objects_reply(DBusPendingCall *pending, void *userdata)
 
     y->objects_listed = true;
 
-    if (!y->ofono_backend)
+    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)
+    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:
@@ -1568,7 +1572,7 @@ static void endpoint_done(pa_bluetooth_discovery *y, pa_bluetooth_profile_t prof
     }
 }
 
-pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
+pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c, int headset_backend) {
     pa_bluetooth_discovery *y;
     DBusError err;
     DBusConnection *conn;
@@ -1577,6 +1581,7 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
     y = pa_xnew0(pa_bluetooth_discovery, 1);
     PA_REFCNT_INIT(y);
     y->core = c;
+    y->headset_backend = headset_backend;
     y->adapters = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL,
                                       (pa_free_cb_t) adapter_free);
     y->devices = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL,
diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez5-util.h
index 21f56b2..9a6488d 100644
--- a/src/modules/bluetooth/bluez5-util.h
+++ b/src/modules/bluetooth/bluez5-util.h
@@ -154,7 +154,11 @@ pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hoo
 
 const char *pa_bluetooth_profile_to_string(pa_bluetooth_profile_t profile);
 
-pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core);
+#define HEADSET_BACKEND_OFONO 0
+#define HEADSET_BACKEND_NATIVE 1
+#define HEADSET_BACKEND_AUTO 2
+
+pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core, int headset_backend);
 pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y);
 void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y);
 void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is_running);
diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c
index 0bcfcf9..b54d573 100644
--- a/src/modules/bluetooth/module-bluetooth-discover.c
+++ b/src/modules/bluetooth/module-bluetooth-discover.c
@@ -33,6 +33,9 @@ PA_MODULE_AUTHOR("João Paulo Rechi Vita");
 PA_MODULE_DESCRIPTION("Detect available Bluetooth daemon and load the corresponding discovery module");
 PA_MODULE_VERSION(PACKAGE_VERSION);
 PA_MODULE_LOAD_ONCE(true);
+PA_MODULE_USAGE(
+    "headset=ofono|native|auto (bluez 5 only)"
+);
 
 struct userdata {
     uint32_t bluez5_module_idx;
@@ -50,7 +53,7 @@ int pa__init(pa_module* m) {
     u->bluez4_module_idx = PA_INVALID_INDEX;
 
     if (pa_module_exists("module-bluez5-discover")) {
-        mm = pa_module_load(m->core, "module-bluez5-discover",  NULL);
+        mm = pa_module_load(m->core, "module-bluez5-discover", m->argument);
         if (mm)
             u->bluez5_module_idx = mm->index;
     }
diff --git a/src/modules/bluetooth/module-bluez5-discover.c b/src/modules/bluetooth/module-bluez5-discover.c
index 0b7bf49..570cdba 100644
--- a/src/modules/bluetooth/module-bluez5-discover.c
+++ b/src/modules/bluetooth/module-bluez5-discover.c
@@ -27,6 +27,7 @@
 #include <pulsecore/core-util.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/module.h>
+#include <pulsecore/modargs.h>
 #include <pulsecore/shared.h>
 
 #include "bluez5-util.h"
@@ -37,6 +38,14 @@ PA_MODULE_AUTHOR("João Paulo Rechi Vita");
 PA_MODULE_DESCRIPTION("Detect available BlueZ 5 Bluetooth audio devices and load BlueZ 5 Bluetooth audio drivers");
 PA_MODULE_VERSION(PACKAGE_VERSION);
 PA_MODULE_LOAD_ONCE(true);
+PA_MODULE_USAGE(
+    "headset=ofono|native|auto"
+);
+
+static const char* const valid_modargs[] = {
+    "headset",
+    NULL
+};
 
 struct userdata {
     pa_module *module;
@@ -83,26 +92,54 @@ static pa_hook_result_t device_connection_changed_cb(pa_bluetooth_discovery *y,
     return PA_HOOK_OK;
 }
 
+#ifdef HAVE_BLUEZ_5_NATIVE_HEADSET
+const char *default_headset_backend = "native";
+#else
+const char *default_headset_backend = "ofono";
+#endif
+
 int pa__init(pa_module *m) {
     struct userdata *u;
+    pa_modargs *ma;
+    const char *headset_str;
+    int headset_backend;
 
     pa_assert(m);
 
+    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
+        pa_log("failed to parse module arguments.");
+        goto fail;
+    }
+
+    pa_assert_se(headset_str = pa_modargs_get_value(ma, "headset", default_headset_backend));
+    if (pa_streq(headset_str, "ofono"))
+        headset_backend = HEADSET_BACKEND_OFONO;
+    else if (pa_streq(headset_str, "native"))
+        headset_backend = HEADSET_BACKEND_NATIVE;
+    else if (pa_streq(headset_str, "auto"))
+        headset_backend = HEADSET_BACKEND_AUTO;
+    else {
+        pa_log("headset parameter must be either ofono, native or auto (found %s)", headset_str);
+        goto fail;
+    }
+
     m->userdata = u = pa_xnew0(struct userdata, 1);
     u->module = m;
     u->core = m->core;
     u->loaded_device_paths = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
 
-    if (!(u->discovery = pa_bluetooth_discovery_get(u->core)))
+    if (!(u->discovery = pa_bluetooth_discovery_get(u->core, headset_backend)))
         goto fail;
 
     u->device_connection_changed_slot =
         pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED),
                         PA_HOOK_NORMAL, (pa_hook_cb_t) device_connection_changed_cb, u);
 
+    pa_modargs_free(ma);
     return 0;
 
 fail:
+    pa_modargs_free(ma);
     pa__done(m);
     return -1;
 }

commit d63305f10336e4eada275e024343a84689ecb24b
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Mon Nov 3 12:17:41 2014 +0100

    bluez 5: remove null headset backend
    
    There is no need to have a "null" backend anymore.
    
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/modules/bluetooth/backend-null.c b/src/modules/bluetooth/backend-null.c
deleted file mode 100644
index 6e621a7..0000000
--- a/src/modules/bluetooth/backend-null.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/***
-  This file is part of PulseAudio.
-
-  Copyright 2013 João Paulo Rechi Vita
-
-  PulseAudio is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as
-  published by the Free Software Foundation; either version 2.1 of the
-  License, or (at your option) any later version.
-
-  PulseAudio is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with PulseAudio; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-  USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <pulsecore/log.h>
-
-#include "bluez5-util.h"
-
-pa_bluetooth_backend *pa_bluetooth_backend_new(pa_core *c, pa_bluetooth_discovery *y) {
-    pa_log_debug("Bluetooth Headset Backend API support disabled");
-    return NULL;
-}
-
-void pa_bluetooth_backend_free(pa_bluetooth_backend *b) {
-    /* Nothing to do here */
-}

commit 5f6cb5872b0896a55072a6b06486bf116bf2d866
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Mon Nov 3 12:16:31 2014 +0100

    bluez 5: Fix a debug message
    
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/modules/bluetooth/backend-native.c b/src/modules/bluetooth/backend-native.c
index 66dacf9..86af422 100644
--- a/src/modules/bluetooth/backend-native.c
+++ b/src/modules/bluetooth/backend-native.c
@@ -468,7 +468,7 @@ pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_d
     pa_bluetooth_backend *backend;
     DBusError err;
 
-    pa_log_debug("Bluetooth Headset Backend API support using the NULL backend");
+    pa_log_debug("Bluetooth Headset Backend API support using the native backend");
 
     backend = pa_xnew0(pa_bluetooth_backend, 1);
     backend->core = c;

commit aea3518569fadc65e4eb9003c8190938ad7b26d0
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Mon Nov 3 12:13:20 2014 +0100

    bluez 5: Load the native headset backend if the oFono one is unavailable
    
    This implements some autodetect if both headset backends are compiled in:
    First we try to contact the oFono service, if that's not working,
    then we start the native backend instead.
    
    Likewise if the oFono service is going offline/online, we load/unload
    the native backend accordingly.
    
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
index 797d35c..1f0c80f 100644
--- a/src/modules/bluetooth/backend-ofono.c
+++ b/src/modules/bluetooth/backend-ofono.c
@@ -336,6 +336,16 @@ static void hf_audio_agent_get_cards(pa_bluetooth_backend *hf) {
     hf_dbus_send_and_add_to_pending(hf, m, hf_audio_agent_get_cards_reply, NULL);
 }
 
+static void ofono_bus_id_destroy(pa_bluetooth_backend *backend) {
+    pa_hashmap_remove_all(backend->cards);
+
+    if (backend->ofono_bus_id) {
+        pa_xfree(backend->ofono_bus_id);
+        backend->ofono_bus_id = NULL;
+        pa_bluetooth_discovery_set_ofono_running(backend->discovery, false);
+    }
+}
+
 static void hf_audio_agent_register_reply(DBusPendingCall *pending, void *userdata) {
     DBusMessage *r;
     pa_dbus_pending *p;
@@ -360,6 +370,8 @@ finish:
 
     PA_LLIST_REMOVE(pa_dbus_pending, backend->pending, p);
     pa_dbus_pending_free(p);
+
+    pa_bluetooth_discovery_set_ofono_running(backend->discovery, backend->ofono_bus_id != NULL);
 }
 
 static void hf_audio_agent_register(pa_bluetooth_backend *hf) {
@@ -393,8 +405,7 @@ static void hf_audio_agent_unregister(pa_bluetooth_backend *backend) {
         pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID));
         pa_assert_se(dbus_connection_send(pa_dbus_connection_get(backend->connection), m, NULL));
 
-        pa_xfree(backend->ofono_bus_id);
-        backend->ofono_bus_id = NULL;
+        ofono_bus_id_destroy(backend);
     }
 }
 
@@ -429,11 +440,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *da
 
             if (old_owner && *old_owner) {
                 pa_log_debug("oFono disappeared");
-
-                pa_hashmap_remove_all(backend->cards);
-
-                pa_xfree(backend->ofono_bus_id);
-                backend->ofono_bus_id = NULL;
+                ofono_bus_id_destroy(backend);
             }
 
             if (new_owner && *new_owner) {
@@ -490,10 +497,7 @@ static DBusMessage *hf_audio_agent_release(DBusConnection *c, DBusMessage *m, vo
 
     pa_log_debug("HF audio agent has been unregistered by oFono (%s)", backend->ofono_bus_id);
 
-    pa_hashmap_remove_all(backend->cards);
-
-    pa_xfree(backend->ofono_bus_id);
-    backend->ofono_bus_id = NULL;
+    ofono_bus_id_destroy(backend);
 
     pa_assert_se(r = dbus_message_new_method_return(m));
 
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index f7bf654..4121b76 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -861,6 +861,18 @@ static void parse_interfaces_and_properties(pa_bluetooth_discovery *y, DBusMessa
     return;
 }
 
+void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is_running) {
+    pa_assert(y);
+
+    pa_log_debug("oFono is running: %s", pa_yes_no(is_running));
+    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);
+}
+
 static void get_managed_objects_reply(DBusPendingCall *pending, void *userdata) {
     pa_dbus_pending *p;
     pa_bluetooth_discovery *y;
diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez5-util.h
index d1abd39..21f56b2 100644
--- a/src/modules/bluetooth/bluez5-util.h
+++ b/src/modules/bluetooth/bluez5-util.h
@@ -157,4 +157,5 @@ const char *pa_bluetooth_profile_to_string(pa_bluetooth_profile_t profile);
 pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core);
 pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y);
 void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y);
+void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is_running);
 #endif

commit 1ffede3c855d47a371b2d846f2a496797c46e3af
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Mon Nov 3 11:01:00 2014 +0100

    bluez 5: Build both headset backends, if available
    
    Enable both ofono and native backends to be built into the same
    libbluez5-util. Never build the null backend.
    
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/configure.ac b/configure.ac
index 6b67dac..e91e990 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1035,18 +1035,22 @@ AM_CONDITIONAL([HAVE_BLUEZ], [test "x$HAVE_BLUEZ" = x1])
 
 ## Bluetooth Headset profiles backend ##
 
-AC_ARG_WITH(bluetooth_headset_backend,
-    AS_HELP_STRING([--with-bluetooth-headset-backend=<ofono|native|null>],[Backend for Bluetooth headset profiles (native)]))
-if test -z "$with_bluetooth_headset_backend" ; then
-    BLUETOOTH_HEADSET_BACKEND=native
-else
-    BLUETOOTH_HEADSET_BACKEND=$with_bluetooth_headset_backend
-fi
-
-AS_IF([test "x$BLUETOOTH_HEADSET_BACKEND" != "xofono" && test "x$BLUETOOTH_HEADSET_BACKEND" != "xnull" && test "x$BLUETOOTH_HEADSET_BACKEND" != "xnative"],
-    [AC_MSG_ERROR([*** Invalid Bluetooth Headset backend])])
-
-AC_SUBST(BLUETOOTH_HEADSET_BACKEND)
+AC_ARG_ENABLE([bluez5-ofono-headset],
+    AS_HELP_STRING([--disable-bluez5-ofono-headset],[Disable optional ofono headset backend support (Bluez 5)]))
+AS_IF([test "x$HAVE_BLUEZ_5" = "x1" && test "x$enable_bluez5_ofono_headset" != "xno"], HAVE_BLUEZ_5_OFONO_HEADSET=1)
+AC_SUBST(HAVE_BLUEZ_5_OFONO_HEADSET)
+AM_CONDITIONAL([HAVE_BLUEZ_5_OFONO_HEADSET], [test "x$HAVE_BLUEZ_5_OFONO_HEADSET" = x1])
+AS_IF([test "x$HAVE_BLUEZ_5_OFONO_HEADSET" = "x1"], AC_DEFINE([HAVE_BLUEZ_5_OFONO_HEADSET], 1, [Bluez 5 ofono headset backend enabled]))
+
+AC_ARG_ENABLE([bluez5-native-headset],
+    AS_HELP_STRING([--disable-bluez5-native-headset],[Disable optional native headset backend support (Bluez 5)]))
+AS_IF([test "x$HAVE_BLUEZ_5" = "x1" && test "x$enable_bluez5_native_headset" != "xno"], HAVE_BLUEZ_5_NATIVE_HEADSET=1)
+AS_IF([test "x$HAVE_BLUEZ_5_NATIVE_HEADSET" = "x1"], [PKG_CHECK_MODULES(BLUEZ, [ bluez >= 4.101 ], [],
+    [AC_MSG_ERROR([*** Bluez library not found (required by native headset backend)])])])
+
+AC_SUBST(HAVE_BLUEZ_5_NATIVE_HEADSET)
+AM_CONDITIONAL([HAVE_BLUEZ_5_NATIVE_HEADSET], [test "x$HAVE_BLUEZ_5_NATIVE_HEADSET" = x1])
+AS_IF([test "x$HAVE_BLUEZ_5_NATIVE_HEADSET" = "x1"], AC_DEFINE([HAVE_BLUEZ_5_NATIVE_HEADSET], 1, [Bluez 5 native headset backend enabled]))
 
 #### UDEV support (optional) ####
 
@@ -1509,6 +1513,8 @@ AS_IF([test "x$HAVE_SYSTEMD_LOGIN" = "x1"], ENABLE_SYSTEMD_LOGIN=yes, ENABLE_SYS
 AS_IF([test "x$HAVE_SYSTEMD_JOURNAL" = "x1"], ENABLE_SYSTEMD_JOURNAL=yes, ENABLE_SYSTEMD_JOURNAL=no)
 AS_IF([test "x$HAVE_BLUEZ_4" = "x1"], ENABLE_BLUEZ_4=yes, ENABLE_BLUEZ_4=no)
 AS_IF([test "x$HAVE_BLUEZ_5" = "x1"], ENABLE_BLUEZ_5=yes, ENABLE_BLUEZ_5=no)
+AS_IF([test "x$HAVE_BLUEZ_5_OFONO_HEADSET" = "x1"], ENABLE_BLUEZ_5_OFONO_HEADSET=yes, ENABLE_BLUEZ_5_OFONO_HEADSET=no)
+AS_IF([test "x$HAVE_BLUEZ_5_NATIVE_HEADSET" = "x1"], ENABLE_BLUEZ_5_NATIVE_HEADSET=yes, ENABLE_BLUEZ_5_NATIVE_HEADSET=no)
 AS_IF([test "x$HAVE_HAL_COMPAT" = "x1"], ENABLE_HAL_COMPAT=yes, ENABLE_HAL_COMPAT=no)
 AS_IF([test "x$HAVE_TCPWRAP" = "x1"], ENABLE_TCPWRAP=yes, ENABLE_TCPWRAP=no)
 AS_IF([test "x$HAVE_LIBSAMPLERATE" = "x1"], ENABLE_LIBSAMPLERATE=yes, ENABLE_LIBSAMPLERATE=no)
@@ -1563,7 +1569,8 @@ echo "
     Enable D-Bus:                  ${ENABLE_DBUS}
       Enable BlueZ 4:              ${ENABLE_BLUEZ_4}
       Enable BlueZ 5:              ${ENABLE_BLUEZ_5}
-        headset backend:           ${BLUETOOTH_HEADSET_BACKEND}
+        Enable ofono headsets:     ${ENABLE_BLUEZ_5_OFONO_HEADSET}
+        Enable native headsets:    ${ENABLE_BLUEZ_5_NATIVE_HEADSET}
     Enable udev:                   ${ENABLE_UDEV}
       Enable HAL->udev compat:     ${ENABLE_HAL_COMPAT}
     Enable systemd
diff --git a/src/Makefile.am b/src/Makefile.am
index 3cab31f..4e60a98 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2129,8 +2129,16 @@ module_bluez4_device_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) $(SBC_CFLAGS)
 libbluez5_util_la_SOURCES = \
 		modules/bluetooth/bluez5-util.c \
 		modules/bluetooth/bluez5-util.h \
-		modules/bluetooth/a2dp-codecs.h \
-		modules/bluetooth/backend- at BLUETOOTH_HEADSET_BACKEND@.c
+		modules/bluetooth/a2dp-codecs.h
+if HAVE_BLUEZ_5_OFONO_HEADSET
+libbluez5_util_la_SOURCES += \
+		modules/bluetooth/backend-ofono.c
+endif
+if HAVE_BLUEZ_5_NATIVE_HEADSET
+libbluez5_util_la_SOURCES += \
+		modules/bluetooth/backend-native.c
+endif
+
 libbluez5_util_la_LDFLAGS = -avoid-version
 libbluez5_util_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS)
 libbluez5_util_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
diff --git a/src/modules/bluetooth/backend-native.c b/src/modules/bluetooth/backend-native.c
index a9dc64c..66dacf9 100644
--- a/src/modules/bluetooth/backend-native.c
+++ b/src/modules/bluetooth/backend-native.c
@@ -464,7 +464,7 @@ static void profile_done(pa_bluetooth_backend *b, pa_bluetooth_profile_t profile
     }
 }
 
-pa_bluetooth_backend *pa_bluetooth_backend_new(pa_core *c, pa_bluetooth_discovery *y) {
+pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y) {
     pa_bluetooth_backend *backend;
     DBusError err;
 
@@ -488,7 +488,7 @@ pa_bluetooth_backend *pa_bluetooth_backend_new(pa_core *c, pa_bluetooth_discover
     return backend;
 }
 
-void pa_bluetooth_backend_free(pa_bluetooth_backend *backend) {
+void pa_bluetooth_native_backend_free(pa_bluetooth_backend *backend) {
     pa_assert(backend);
 
     pa_dbus_free_pending_list(&backend->pending);
diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
index ba10ed6..797d35c 100644
--- a/src/modules/bluetooth/backend-ofono.c
+++ b/src/modules/bluetooth/backend-ofono.c
@@ -582,7 +582,7 @@ static DBusHandlerResult hf_audio_agent_handler(DBusConnection *c, DBusMessage *
     return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-pa_bluetooth_backend *pa_bluetooth_backend_new(pa_core *c, pa_bluetooth_discovery *y) {
+pa_bluetooth_backend *pa_bluetooth_ofono_backend_new(pa_core *c, pa_bluetooth_discovery *y) {
     pa_bluetooth_backend *backend;
     DBusError err;
     static const DBusObjectPathVTable vtable_hf_audio_agent = {
@@ -635,7 +635,7 @@ pa_bluetooth_backend *pa_bluetooth_backend_new(pa_core *c, pa_bluetooth_discover
     return backend;
 }
 
-void pa_bluetooth_backend_free(pa_bluetooth_backend *backend) {
+void pa_bluetooth_ofono_backend_free(pa_bluetooth_backend *backend) {
     pa_assert(backend);
 
     pa_dbus_free_pending_list(&backend->pending);
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index 9431aed..f7bf654 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -87,7 +87,7 @@ struct pa_bluetooth_discovery {
     pa_hashmap *devices;
     pa_hashmap *transports;
 
-    pa_bluetooth_backend *backend;
+    pa_bluetooth_backend *ofono_backend, *native_backend;
     PA_LLIST_HEAD(pa_dbus_pending, pending);
 };
 
@@ -899,8 +899,10 @@ static void get_managed_objects_reply(DBusPendingCall *pending, void *userdata)
 
     y->objects_listed = true;
 
-    if (!y->backend)
-        y->backend = pa_bluetooth_backend_new(y->core, y);
+    if (!y->ofono_backend)
+        y->ofono_backend = pa_bluetooth_ofono_backend_new(y->core, y);
+    if (!y->ofono_backend && !y->native_backend)
+        y->native_backend = pa_bluetooth_native_backend_new(y->core, y);
 
 finish:
     dbus_message_unref(r);
@@ -954,9 +956,13 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
                 pa_hashmap_remove_all(y->devices);
                 pa_hashmap_remove_all(y->adapters);
                 y->objects_listed = false;
-                if (y->backend) {
-                    pa_bluetooth_backend_free(y->backend);
-                    y->backend = NULL;
+                if (y->ofono_backend) {
+                    pa_bluetooth_ofono_backend_free(y->ofono_backend);
+                    y->ofono_backend = NULL;
+                }
+                if (y->native_backend) {
+                    pa_bluetooth_native_backend_free(y->native_backend);
+                    y->native_backend = NULL;
                 }
             }
 
@@ -1648,8 +1654,10 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
         pa_hashmap_free(y->transports);
     }
 
-    if (y->backend)
-        pa_bluetooth_backend_free(y->backend);
+    if (y->ofono_backend)
+        pa_bluetooth_ofono_backend_free(y->ofono_backend);
+    if (y->native_backend)
+        pa_bluetooth_native_backend_free(y->native_backend);
 
     if (y->connection) {
 
diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez5-util.h
index 3ef0ac8..d1abd39 100644
--- a/src/modules/bluetooth/bluez5-util.h
+++ b/src/modules/bluetooth/bluez5-util.h
@@ -117,8 +117,25 @@ struct pa_bluetooth_adapter {
     bool valid;
 };
 
-pa_bluetooth_backend *pa_bluetooth_backend_new(pa_core *c, pa_bluetooth_discovery *y);
-void pa_bluetooth_backend_free(pa_bluetooth_backend *b);
+#ifdef HAVE_BLUEZ_5_OFONO_HEADSET
+pa_bluetooth_backend *pa_bluetooth_ofono_backend_new(pa_core *c, pa_bluetooth_discovery *y);
+void pa_bluetooth_ofono_backend_free(pa_bluetooth_backend *b);
+#else
+static inline pa_bluetooth_backend *pa_bluetooth_ofono_backend_new(pa_core *c, pa_bluetooth_discovery *y) {
+    return NULL;
+}
+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);
+void pa_bluetooth_native_backend_free(pa_bluetooth_backend *b);
+#else
+static inline pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y) {
+    return NULL;
+}
+static inline void pa_bluetooth_native_backend_free(pa_bluetooth_backend *b) {}
+#endif
 
 pa_bluetooth_transport *pa_bluetooth_transport_new(pa_bluetooth_device *d, const char *owner, const char *path,
                                                    pa_bluetooth_profile_t p, const uint8_t *config, size_t size);



More information about the pulseaudio-commits mailing list