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/>.
27
#include <pulse/xmalloc.h>
28
#include <pulsecore/module.h>
29
#include <pulsecore/core-util.h>
30
#include <pulsecore/modargs.h>
31
#include <pulsecore/macro.h>
32
#include <pulsecore/core-util.h>
33
#include <pulsecore/dbus-shared.h>
35
#include "module-bluez4-discover-symdef.h"
36
#include "bluez4-util.h"
38
PA_MODULE_AUTHOR("João Paulo Rechi Vita");
39
PA_MODULE_DESCRIPTION("Detect available BlueZ 4 Bluetooth audio devices and load BlueZ 4 Bluetooth audio drivers");
40
PA_MODULE_VERSION(PACKAGE_VERSION);
41
PA_MODULE_USAGE("profile=<a2dp|hsp|hfgw> "
42
"sco_sink=<name of sink> "
43
"sco_source=<name of source> ");
44
PA_MODULE_LOAD_ONCE(true);
46
static const char* const valid_modargs[] = {
50
"async", /* deprecated */
58
pa_bluez4_discovery *discovery;
68
static pa_hook_result_t load_module_for_device(pa_bluez4_discovery *y, const pa_bluez4_device *d, struct userdata *u) {
69
struct module_info *mi;
74
mi = pa_hashmap_get(u->hashmap, d->path);
76
if (pa_bluez4_device_any_audio_connected(d)) {
82
/* Oh, awesome, a new device has shown up and been connected! */
84
args = pa_sprintf_malloc("address=\"%s\" path=\"%s\"", d->address, d->path);
86
if (pa_modargs_get_value(u->modargs, "profile", NULL)) {
89
profile = pa_sprintf_malloc("%s profile=\"%s\"", args,
90
pa_modargs_get_value(u->modargs, "profile", NULL));
95
if (pa_modargs_get_value(u->modargs, "sco_sink", NULL) &&
96
pa_modargs_get_value(u->modargs, "sco_source", NULL)) {
99
tmp = pa_sprintf_malloc("%s sco_sink=\"%s\" sco_source=\"%s\"", args,
100
pa_modargs_get_value(u->modargs, "sco_sink", NULL),
101
pa_modargs_get_value(u->modargs, "sco_source", NULL));
106
pa_log_debug("Loading module-bluez4-device %s", args);
107
m = pa_module_load(u->module->core, "module-bluez4-device", args);
111
mi = pa_xnew(struct module_info, 1);
112
mi->module = m->index;
113
mi->path = pa_xstrdup(d->path);
115
pa_hashmap_put(u->hashmap, mi->path, mi);
117
pa_log_debug("Failed to load module for device %s", d->path);
124
/* Hmm, disconnection? Then the module unloads itself */
126
pa_log_debug("Unregistering module for %s", d->path);
127
pa_hashmap_remove(u->hashmap, mi->path);
136
int pa__init(pa_module* m) {
138
pa_modargs *ma = NULL;
142
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
143
pa_log("Failed to parse module arguments");
147
if (pa_modargs_get_value(ma, "async", NULL))
148
pa_log_warn("The 'async' argument is deprecated and does nothing.");
150
m->userdata = u = pa_xnew0(struct userdata, 1);
155
u->hashmap = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
157
if (!(u->discovery = pa_bluez4_discovery_get(u->core)))
160
u->slot = pa_hook_connect(pa_bluez4_discovery_hook(u->discovery, PA_BLUEZ4_HOOK_DEVICE_CONNECTION_CHANGED),
161
PA_HOOK_NORMAL, (pa_hook_cb_t) load_module_for_device, u);
174
void pa__done(pa_module* m) {
179
if (!(u = m->userdata))
183
pa_hook_slot_free(u->slot);
186
pa_bluez4_discovery_unref(u->discovery);
189
struct module_info *mi;
191
while ((mi = pa_hashmap_steal_first(u->hashmap))) {
196
pa_hashmap_free(u->hashmap);
200
pa_modargs_free(u->modargs);