Bluetooth : Support AVC target feature
[platform/upstream/pulseaudio.git] / src / modules / bluetooth / bluez5-util.h
1 #ifndef foobluez5utilhfoo
2 #define foobluez5utilhfoo
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, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #include <pulsecore/core.h>
24
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"
31
32 #ifdef __TIZEN_BT__
33 #ifdef pa_log_debug
34 #undef pa_log_debug
35 #define pa_log_debug(...)  pa_log_level_meta(PA_LOG_INFO,   __FILE__, __LINE__, __func__, __VA_ARGS__)
36 #endif
37 #endif
38
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;
44
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 */
48 #ifdef __TIZEN_BT__
49     PA_BLUETOOTH_HOOK_SCO_STATE_CHANGED,            /* Call data: pa_bluetooth_transport */
50     PA_BLUETOOTH_HOOK_AVC_MODE_CHANGED,            /* Call data: pa_bluetooth_transport */
51 #endif
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 */
54     PA_BLUETOOTH_HOOK_MAX
55 } pa_bluetooth_hook_t;
56
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
65
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;
71
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;
78 #endif
79
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);
85
86 struct pa_bluetooth_transport {
87     pa_bluetooth_device *device;
88
89     char *owner;
90     char *path;
91     pa_bluetooth_profile_t profile;
92
93     uint8_t codec;
94     uint8_t *config;
95     size_t config_size;
96
97     uint16_t microphone_gain;
98     uint16_t speaker_gain;
99
100 #ifdef TIZEN_BT_AVC_TARGET
101     uint32_t avc_mode;
102 #endif
103
104     pa_bluetooth_transport_state_t state;
105
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;
111     void *userdata;
112 };
113
114 struct pa_bluetooth_device {
115     pa_bluetooth_discovery *discovery;
116     pa_bluetooth_adapter *adapter;
117
118     bool properties_received;
119     bool tried_to_link_with_adapter;
120     bool valid;
121     bool autodetect_mtu;
122
123     /* Device information */
124     char *path;
125     char *adapter_path;
126     char *alias;
127     char *address;
128     uint32_t class_of_device;
129     pa_hashmap *uuids; /* char* -> char* (hashmap-as-a-set) */
130
131     pa_bluetooth_transport *transports[PA_BLUETOOTH_PROFILE_COUNT];
132
133     pa_time_event *wait_for_profiles_timer;
134 };
135
136 struct pa_bluetooth_adapter {
137     pa_bluetooth_discovery *discovery;
138     char *path;
139     char *address;
140
141     bool valid;
142 };
143
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);
147 #else
148 static inline pa_bluetooth_backend *pa_bluetooth_ofono_backend_new(pa_core *c, pa_bluetooth_discovery *y) {
149     return NULL;
150 }
151 static inline void pa_bluetooth_ofono_backend_free(pa_bluetooth_backend *b) {}
152 #endif
153
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);
158 #else
159 static inline pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y, bool enable_hs_role) {
160     return NULL;
161 }
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) {}
164 #endif
165
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);
168
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);
173
174 bool pa_bluetooth_device_any_transport_connected(const pa_bluetooth_device *d);
175 #ifdef __TIZEN_BT__
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);
180 #endif
181 #endif
182
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);
185
186 pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hook_t hook);
187
188 const char *pa_bluetooth_profile_to_string(pa_bluetooth_profile_t profile);
189
190 #define HEADSET_BACKEND_OFONO 0
191 #define HEADSET_BACKEND_NATIVE 1
192 #define HEADSET_BACKEND_AUTO 2
193
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);
198
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);
203 #endif
204
205 #endif