mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
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@canonical.com>
This commit is contained in:
parent
d63305f103
commit
9ae85b1a29
4 changed files with 55 additions and 6 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue