1 #ifndef foobluez5utilhfoo
2 #define foobluez5utilhfoo
5 This file is part of PulseAudio.
7 Copyright 2008-2013 João Paulo Rechi Vita
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.
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.
19 You should have received a copy of the GNU Lesser General Public
20 License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
23 #include <pulsecore/core.h>
25 #define PA_BLUETOOTH_UUID_A2DP_SOURCE "0000110a-0000-1000-8000-00805f9b34fb"
26 #define PA_BLUETOOTH_UUID_A2DP_SINK "0000110b-0000-1000-8000-00805f9b34fb"
27 #define PA_BLUETOOTH_UUID_HSP_HS "00001108-0000-1000-8000-00805f9b34fb"
28 #define PA_BLUETOOTH_UUID_HSP_AG "00001112-0000-1000-8000-00805f9b34fb"
29 #define PA_BLUETOOTH_UUID_HFP_HF "0000111e-0000-1000-8000-00805f9b34fb"
30 #define PA_BLUETOOTH_UUID_HFP_AG "0000111f-0000-1000-8000-00805f9b34fb"
35 #define pa_log_debug(...) pa_log_level_meta(PA_LOG_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__)
39 typedef struct pa_bluetooth_transport pa_bluetooth_transport;
40 typedef struct pa_bluetooth_device pa_bluetooth_device;
41 typedef struct pa_bluetooth_adapter pa_bluetooth_adapter;
42 typedef struct pa_bluetooth_discovery pa_bluetooth_discovery;
43 typedef struct pa_bluetooth_backend pa_bluetooth_backend;
45 typedef enum pa_bluetooth_hook {
46 PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED, /* Call data: pa_bluetooth_device */
47 PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED, /* Call data: pa_bluetooth_transport */
49 PA_BLUETOOTH_HOOK_SCO_STATE_CHANGED, /* Call data: pa_bluetooth_transport */
50 PA_BLUETOOTH_HOOK_AVC_MODE_CHANGED, /* Call data: pa_bluetooth_transport */
52 PA_BLUETOOTH_HOOK_TRANSPORT_MICROPHONE_GAIN_CHANGED, /* Call data: pa_bluetooth_transport */
53 PA_BLUETOOTH_HOOK_TRANSPORT_SPEAKER_GAIN_CHANGED, /* Call data: pa_bluetooth_transport */
55 } pa_bluetooth_hook_t;
57 typedef enum profile {
58 PA_BLUETOOTH_PROFILE_A2DP_SINK,
59 PA_BLUETOOTH_PROFILE_A2DP_SOURCE,
60 PA_BLUETOOTH_PROFILE_HEADSET_HEAD_UNIT,
61 PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY,
62 PA_BLUETOOTH_PROFILE_OFF
63 } pa_bluetooth_profile_t;
64 #define PA_BLUETOOTH_PROFILE_COUNT PA_BLUETOOTH_PROFILE_OFF
66 typedef enum pa_bluetooth_transport_state {
67 PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED,
68 PA_BLUETOOTH_TRANSPORT_STATE_IDLE,
69 PA_BLUETOOTH_TRANSPORT_STATE_PLAYING
70 } pa_bluetooth_transport_state_t;
72 #ifdef TIZEN_BT_AVC_TARGET
73 typedef enum pa_bluetooth_avc_mode {
74 PA_BLUETOOTH_AVC_OFF, /* Absolute Volume Control (AVC) : No */
75 PA_BLUETOOTH_AVC_NULL, /* Absolute Volume Control (AVC) : Volume 0 */
76 PA_BLUETOOTH_AVC_MAX /* Absolute Volume Control (AVC) : MAX Volume */
77 } pa_bluetooth_avc_mode_t;
80 typedef int (*pa_bluetooth_transport_acquire_cb)(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu);
81 typedef void (*pa_bluetooth_transport_release_cb)(pa_bluetooth_transport *t);
82 typedef void (*pa_bluetooth_transport_destroy_cb)(pa_bluetooth_transport *t);
83 typedef void (*pa_bluetooth_transport_set_speaker_gain_cb)(pa_bluetooth_transport *t, uint16_t gain);
84 typedef void (*pa_bluetooth_transport_set_microphone_gain_cb)(pa_bluetooth_transport *t, uint16_t gain);
86 struct pa_bluetooth_transport {
87 pa_bluetooth_device *device;
91 pa_bluetooth_profile_t profile;
97 uint16_t microphone_gain;
98 uint16_t speaker_gain;
100 #ifdef TIZEN_BT_AVC_TARGET
104 pa_bluetooth_transport_state_t state;
106 pa_bluetooth_transport_acquire_cb acquire;
107 pa_bluetooth_transport_release_cb release;
108 pa_bluetooth_transport_destroy_cb destroy;
109 pa_bluetooth_transport_set_speaker_gain_cb set_speaker_gain;
110 pa_bluetooth_transport_set_microphone_gain_cb set_microphone_gain;
114 struct pa_bluetooth_device {
115 pa_bluetooth_discovery *discovery;
116 pa_bluetooth_adapter *adapter;
118 bool properties_received;
119 bool tried_to_link_with_adapter;
123 /* Device information */
128 uint32_t class_of_device;
129 pa_hashmap *uuids; /* char* -> char* (hashmap-as-a-set) */
131 pa_bluetooth_transport *transports[PA_BLUETOOTH_PROFILE_COUNT];
133 pa_time_event *wait_for_profiles_timer;
136 struct pa_bluetooth_adapter {
137 pa_bluetooth_discovery *discovery;
144 #ifdef HAVE_BLUEZ_5_OFONO_HEADSET
145 pa_bluetooth_backend *pa_bluetooth_ofono_backend_new(pa_core *c, pa_bluetooth_discovery *y);
146 void pa_bluetooth_ofono_backend_free(pa_bluetooth_backend *b);
148 static inline pa_bluetooth_backend *pa_bluetooth_ofono_backend_new(pa_core *c, pa_bluetooth_discovery *y) {
151 static inline void pa_bluetooth_ofono_backend_free(pa_bluetooth_backend *b) {}
154 #ifdef HAVE_BLUEZ_5_NATIVE_HEADSET
155 pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y, bool enable_hs_role);
156 void pa_bluetooth_native_backend_free(pa_bluetooth_backend *b);
157 void pa_bluetooth_native_backend_enable_hs_role(pa_bluetooth_backend *b, bool enable_hs_role);
159 static inline pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y, bool enable_hs_role) {
162 static inline void pa_bluetooth_native_backend_free(pa_bluetooth_backend *b) {}
163 static inline void pa_bluetooth_native_backend_enable_hs_role(pa_bluetooth_backend *b, bool enable_hs_role) {}
166 pa_bluetooth_transport *pa_bluetooth_transport_new(pa_bluetooth_device *d, const char *owner, const char *path,
167 pa_bluetooth_profile_t p, const uint8_t *config, size_t size);
169 void pa_bluetooth_transport_set_state(pa_bluetooth_transport *t, pa_bluetooth_transport_state_t state);
170 void pa_bluetooth_transport_put(pa_bluetooth_transport *t);
171 void pa_bluetooth_transport_unlink(pa_bluetooth_transport *t);
172 void pa_bluetooth_transport_free(pa_bluetooth_transport *t);
174 bool pa_bluetooth_device_any_transport_connected(const pa_bluetooth_device *d);
176 bool pa_bluetooth_device_sink_transport_connected(const pa_bluetooth_device *d);
177 bool pa_bluetooth_device_source_transport_connected(const pa_bluetooth_device *d);
178 #ifdef TIZEN_BT_AVC_TARGET
179 int pa_bluetooth_transport_get_avc_mode(pa_bluetooth_transport *t, unsigned int *mode);
183 pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_path(pa_bluetooth_discovery *y, const char *path);
184 pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_address(pa_bluetooth_discovery *y, const char *remote, const char *local);
186 pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hook_t hook);
188 const char *pa_bluetooth_profile_to_string(pa_bluetooth_profile_t profile);
190 #define HEADSET_BACKEND_OFONO 0
191 #define HEADSET_BACKEND_NATIVE 1
192 #define HEADSET_BACKEND_AUTO 2
194 pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core, int headset_backend);
195 pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y);
196 void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y);
197 void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is_running);
199 #ifdef BLUETOOTH_APTX_SUPPORT
200 int pa_load_aptx(const char *aptx_lib_name);
201 int pa_unload_aptx(void);
202 void* pa_aptx_get_handle(void);