2
This file is part of PulseAudio.
4
Copyright 2008-2013 João Paulo Rechi Vita
6
PulseAudio is free software; you can redistribute it and/or modify
7
it under the terms of the GNU Lesser General Public License as
8
published by the Free Software Foundation; either version 2.1 of the
9
License, or (at your option) any later version.
11
PulseAudio is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
24
#include <pulsecore/core.h>
25
#include <pulsecore/core-util.h>
26
#include <pulsecore/macro.h>
27
#include <pulsecore/module.h>
28
#include <pulsecore/modargs.h>
29
#include <pulsecore/shared.h>
31
#include "bluez5-util.h"
33
#include "module-bluez5-discover-symdef.h"
35
PA_MODULE_AUTHOR("João Paulo Rechi Vita");
36
PA_MODULE_DESCRIPTION("Detect available BlueZ 5 Bluetooth audio devices and load BlueZ 5 Bluetooth audio drivers");
37
PA_MODULE_VERSION(PACKAGE_VERSION);
38
PA_MODULE_LOAD_ONCE(true);
40
"headset=ofono|native|auto|both "
41
"sco_sink=<name of sink> "
42
"sco_source=<name of source> "
45
static const char* const valid_modargs[] = {
56
pa_hashmap *loaded_device_paths;
57
pa_hook_slot *device_connection_changed_slot;
58
pa_bluetooth_discovery *discovery;
61
static pa_hook_result_t device_connection_changed_cb(pa_bluetooth_discovery *y, const pa_bluetooth_device *d, struct userdata *u) {
67
module_loaded = pa_hashmap_get(u->loaded_device_paths, d->path) ? true : false;
69
if (module_loaded && !pa_bluetooth_device_any_transport_connected(d)) {
70
/* disconnection, the module unloads itself */
71
pa_log_debug("Unregistering module for %s", d->path);
72
pa_hashmap_remove(u->loaded_device_paths, d->path);
76
if (!module_loaded && pa_bluetooth_device_any_transport_connected(d)) {
77
/* a new device has been connected */
79
char *args = pa_sprintf_malloc("path=%s", d->path);
81
if (pa_modargs_get_value(u->modargs, "sco_sink", NULL) &&
82
pa_modargs_get_value(u->modargs, "sco_source", NULL)) {
85
tmp = pa_sprintf_malloc("%s sco_sink=\"%s\" sco_source=\"%s\"", args,
86
pa_modargs_get_value(u->modargs, "sco_sink", NULL),
87
pa_modargs_get_value(u->modargs, "sco_source", NULL));
91
pa_log_debug("Loading module-bluez5-device %s", args);
92
m = pa_module_load(u->module->core, "module-bluez5-device", args);
96
/* No need to duplicate the path here since the device object will
97
* exist for the whole hashmap entry lifespan */
98
pa_hashmap_put(u->loaded_device_paths, d->path, d->path);
100
pa_log_warn("Failed to load module for device %s", d->path);
108
#ifdef HAVE_BLUEZ_5_NATIVE_HEADSET
109
#ifdef HAVE_BLUEZ_5_OFONO_HEADSET
110
const char *default_headset_backend = "both";
112
const char *default_headset_backend = "native";
115
const char *default_headset_backend = "ofono";
118
int pa__init(pa_module *m) {
121
const char *headset_str;
126
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
127
pa_log("failed to parse module arguments.");
131
pa_assert_se(headset_str = pa_modargs_get_value(ma, "headset", default_headset_backend));
132
if (pa_streq(headset_str, "ofono"))
133
headset_backend = HEADSET_BACKEND_OFONO;
134
else if (pa_streq(headset_str, "native"))
135
headset_backend = HEADSET_BACKEND_NATIVE;
136
else if (pa_streq(headset_str, "auto"))
137
headset_backend = HEADSET_BACKEND_AUTO;
138
else if (pa_streq(headset_str, "both"))
139
headset_backend = HEADSET_BACKEND_BOTH;
141
pa_log("headset parameter must be either ofono, native, auto or both (found %s)", headset_str);
145
m->userdata = u = pa_xnew0(struct userdata, 1);
149
u->loaded_device_paths = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
151
if (!(u->discovery = pa_bluetooth_discovery_get(u->core, headset_backend)))
154
u->device_connection_changed_slot =
155
pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED),
156
PA_HOOK_NORMAL, (pa_hook_cb_t) device_connection_changed_cb, u);
166
void pa__done(pa_module *m) {
171
if (!(u = m->userdata))
174
if (u->device_connection_changed_slot)
175
pa_hook_slot_free(u->device_connection_changed_slot);
178
pa_bluetooth_discovery_unref(u->discovery);
180
if (u->loaded_device_paths)
181
pa_hashmap_free(u->loaded_device_paths);
184
pa_modargs_free(u->modargs);