]> code.delx.au - pulseaudio/blob - src/modules/bluetooth/bluetooth-util.h
c69ba71af576821434fde7edf437f4727e16e668
[pulseaudio] / src / modules / bluetooth / bluetooth-util.h
1 #ifndef foobluetoothutilhfoo
2 #define foobluetoothutilhfoo
3
4 /***
5 This file is part of PulseAudio.
6
7 Copyright 2008-2013 João Paulo Rechi Vita
8
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2.1 of the
12 License, or (at your option) any later version.
13
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA.
23 ***/
24
25 #include <dbus/dbus.h>
26
27 #include <pulsecore/llist.h>
28 #include <pulsecore/macro.h>
29
30 #define PA_BLUETOOTH_ERROR_NOT_SUPPORTED "org.bluez.Error.NotSupported"
31
32 /* UUID copied from bluez/audio/device.h */
33 #define GENERIC_AUDIO_UUID "00001203-0000-1000-8000-00805f9b34fb"
34
35 #define HSP_HS_UUID "00001108-0000-1000-8000-00805f9b34fb"
36 #define HSP_AG_UUID "00001112-0000-1000-8000-00805f9b34fb"
37
38 #define HFP_HS_UUID "0000111e-0000-1000-8000-00805f9b34fb"
39 #define HFP_AG_UUID "0000111f-0000-1000-8000-00805f9b34fb"
40
41 #define ADVANCED_AUDIO_UUID "0000110d-0000-1000-8000-00805f9b34fb"
42
43 #define A2DP_SOURCE_UUID "0000110a-0000-1000-8000-00805f9b34fb"
44 #define A2DP_SINK_UUID "0000110b-0000-1000-8000-00805f9b34fb"
45
46 #define HSP_MAX_GAIN 15
47
48 typedef struct pa_bluetooth_uuid pa_bluetooth_uuid;
49 typedef struct pa_bluetooth_device pa_bluetooth_device;
50 typedef struct pa_bluetooth_discovery pa_bluetooth_discovery;
51 typedef struct pa_bluetooth_transport pa_bluetooth_transport;
52
53 struct userdata;
54
55 struct pa_bluetooth_uuid {
56 char *uuid;
57 PA_LLIST_FIELDS(pa_bluetooth_uuid);
58 };
59
60 enum profile {
61 PROFILE_A2DP,
62 PROFILE_A2DP_SOURCE,
63 PROFILE_HSP,
64 PROFILE_HFGW,
65 PROFILE_OFF
66 };
67
68 #define PA_BLUETOOTH_PROFILE_COUNT PROFILE_OFF
69
70 struct pa_bluetooth_hook_uuid_data {
71 pa_bluetooth_device *device;
72 const char *uuid;
73 };
74
75 /* Hook data: pa_bluetooth_discovery pointer. */
76 typedef enum pa_bluetooth_hook {
77 PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED, /* Call data: pa_bluetooth_device */
78 PA_BLUETOOTH_HOOK_DEVICE_UUID_ADDED, /* Call data: pa_bluetooth_hook_uuid_data */
79 PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED, /* Call data: pa_bluetooth_transport */
80 PA_BLUETOOTH_HOOK_TRANSPORT_NREC_CHANGED, /* Call data: pa_bluetooth_transport */
81 PA_BLUETOOTH_HOOK_TRANSPORT_MICROPHONE_GAIN_CHANGED, /* Call data: pa_bluetooth_transport */
82 PA_BLUETOOTH_HOOK_TRANSPORT_SPEAKER_GAIN_CHANGED, /* Call data: pa_bluetooth_transport */
83 PA_BLUETOOTH_HOOK_MAX
84 } pa_bluetooth_hook_t;
85
86 typedef enum pa_bluetooth_transport_state {
87 PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED,
88 PA_BLUETOOTH_TRANSPORT_STATE_IDLE, /* Connected but not playing */
89 PA_BLUETOOTH_TRANSPORT_STATE_PLAYING
90 } pa_bluetooth_transport_state_t;
91
92 struct pa_bluetooth_transport {
93 pa_bluetooth_device *device;
94 char *owner;
95 char *path;
96 enum profile profile;
97 uint8_t codec;
98 uint8_t *config;
99 int config_size;
100
101 pa_bluetooth_transport_state_t state;
102 bool nrec;
103 uint16_t microphone_gain; /* Used for HSP/HFP */
104 uint16_t speaker_gain; /* Used for HSP/HFP */
105 };
106
107 /* This enum is shared among Audio, Headset, AudioSink, and AudioSource, although not all values are acceptable in all profiles */
108 typedef enum pa_bt_audio_state {
109 PA_BT_AUDIO_STATE_INVALID = -1,
110 PA_BT_AUDIO_STATE_DISCONNECTED,
111 PA_BT_AUDIO_STATE_CONNECTING,
112 PA_BT_AUDIO_STATE_CONNECTED,
113 PA_BT_AUDIO_STATE_PLAYING
114 } pa_bt_audio_state_t;
115
116 struct pa_bluetooth_device {
117 pa_bluetooth_discovery *discovery;
118 bool dead;
119
120 int device_info_valid; /* 0: no results yet; 1: good results; -1: bad results ... */
121
122 /* Device information */
123 char *name;
124 char *path;
125 pa_bluetooth_transport *transports[PA_BLUETOOTH_PROFILE_COUNT];
126 int paired;
127 char *alias;
128 PA_LLIST_HEAD(pa_bluetooth_uuid, uuids);
129 char *address;
130 int class;
131 int trusted;
132
133 /* Audio state */
134 pa_bt_audio_state_t audio_state;
135
136 /* AudioSink, AudioSource, Headset and HandsfreeGateway states */
137 pa_bt_audio_state_t profile_state[PA_BLUETOOTH_PROFILE_COUNT];
138 };
139
140 pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core);
141 pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y);
142 void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *d);
143
144 pa_bluetooth_device* pa_bluetooth_discovery_get_by_path(pa_bluetooth_discovery *d, const char* path);
145 pa_bluetooth_device* pa_bluetooth_discovery_get_by_address(pa_bluetooth_discovery *d, const char* address);
146
147 bool pa_bluetooth_device_any_audio_connected(const pa_bluetooth_device *d);
148
149 int pa_bluetooth_transport_acquire(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu);
150 void pa_bluetooth_transport_release(pa_bluetooth_transport *t);
151
152 void pa_bluetooth_transport_set_microphone_gain(pa_bluetooth_transport *t, uint16_t value);
153 void pa_bluetooth_transport_set_speaker_gain(pa_bluetooth_transport *t, uint16_t value);
154
155 pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hook_t hook);
156
157 typedef enum pa_bt_form_factor {
158 PA_BT_FORM_FACTOR_UNKNOWN,
159 PA_BT_FORM_FACTOR_HEADSET,
160 PA_BT_FORM_FACTOR_HANDSFREE,
161 PA_BT_FORM_FACTOR_MICROPHONE,
162 PA_BT_FORM_FACTOR_SPEAKER,
163 PA_BT_FORM_FACTOR_HEADPHONE,
164 PA_BT_FORM_FACTOR_PORTABLE,
165 PA_BT_FORM_FACTOR_CAR,
166 PA_BT_FORM_FACTOR_HIFI,
167 PA_BT_FORM_FACTOR_PHONE,
168 } pa_bt_form_factor_t;
169
170 pa_bt_form_factor_t pa_bluetooth_get_form_factor(uint32_t class);
171 const char *pa_bt_form_factor_to_string(pa_bt_form_factor_t ff);
172
173 char *pa_bluetooth_cleanup_name(const char *name);
174
175 bool pa_bluetooth_uuid_has(pa_bluetooth_uuid *uuids, const char *uuid);
176 const char *pa_bt_profile_to_string(enum profile profile);
177
178 #endif