1 #ifndef foobluetoothutilhfoo
2 #define foobluetoothutilhfoo
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, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include <dbus/dbus.h>
27 #include <pulsecore/llist.h>
28 #include <pulsecore/macro.h>
30 #define PA_BLUETOOTH_ERROR_NOT_SUPPORTED "org.bluez.Error.NotSupported"
32 /* UUID copied from bluez/audio/device.h */
33 #define GENERIC_AUDIO_UUID "00001203-0000-1000-8000-00805f9b34fb"
35 #define HSP_HS_UUID "00001108-0000-1000-8000-00805f9b34fb"
36 #define HSP_AG_UUID "00001112-0000-1000-8000-00805f9b34fb"
38 #define HFP_HS_UUID "0000111e-0000-1000-8000-00805f9b34fb"
39 #define HFP_AG_UUID "0000111f-0000-1000-8000-00805f9b34fb"
41 #define ADVANCED_AUDIO_UUID "0000110d-0000-1000-8000-00805f9b34fb"
43 #define A2DP_SOURCE_UUID "0000110a-0000-1000-8000-00805f9b34fb"
44 #define A2DP_SINK_UUID "0000110b-0000-1000-8000-00805f9b34fb"
46 #define HSP_MAX_GAIN 15
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
;
55 struct pa_bluetooth_uuid
{
57 PA_LLIST_FIELDS(pa_bluetooth_uuid
);
68 #define PA_BLUETOOTH_PROFILE_COUNT PROFILE_OFF
70 struct pa_bluetooth_hook_uuid_data
{
71 pa_bluetooth_device
*device
;
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 */
84 } pa_bluetooth_hook_t
;
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
;
92 struct pa_bluetooth_transport
{
93 pa_bluetooth_device
*device
;
101 pa_bluetooth_transport_state_t state
;
103 uint16_t microphone_gain
; /* Used for HSP/HFP */
104 uint16_t speaker_gain
; /* Used for HSP/HFP */
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
;
116 struct pa_bluetooth_device
{
117 pa_bluetooth_discovery
*discovery
;
120 int device_info_valid
; /* 0: no results yet; 1: good results; -1: bad results ... */
122 /* Device information */
125 pa_bluetooth_transport
*transports
[PA_BLUETOOTH_PROFILE_COUNT
];
128 PA_LLIST_HEAD(pa_bluetooth_uuid
, uuids
);
134 pa_bt_audio_state_t audio_state
;
136 /* AudioSink, AudioSource, Headset and HandsfreeGateway states */
137 pa_bt_audio_state_t profile_state
[PA_BLUETOOTH_PROFILE_COUNT
];
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
);
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
);
147 bool pa_bluetooth_device_any_audio_connected(const pa_bluetooth_device
*d
);
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
);
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
);
155 pa_hook
* pa_bluetooth_discovery_hook(pa_bluetooth_discovery
*y
, pa_bluetooth_hook_t hook
);
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
;
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
);
173 char *pa_bluetooth_cleanup_name(const char *name
);
175 bool pa_bluetooth_uuid_has(pa_bluetooth_uuid
*uuids
, const char *uuid
);
176 const char *pa_bt_profile_to_string(enum profile profile
);