1 #ifndef foobluez4utilhfoo
2 #define foobluez4utilhfoo
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 <dbus/dbus.h>
25 #include <pulsecore/llist.h>
26 #include <pulsecore/macro.h>
28 #define PA_BLUEZ4_ERROR_NOT_SUPPORTED "org.bluez.Error.NotSupported"
30 #define PA_BLUEZ4_UUID_A2DP_SOURCE "0000110a-0000-1000-8000-00805f9b34fb"
31 #define PA_BLUEZ4_UUID_A2DP_SINK "0000110b-0000-1000-8000-00805f9b34fb"
32 #define PA_BLUEZ4_UUID_HSP_HS "00001108-0000-1000-8000-00805f9b34fb"
33 #define PA_BLUEZ4_UUID_HSP_AG "00001112-0000-1000-8000-00805f9b34fb"
34 #define PA_BLUEZ4_UUID_HFP_HF "0000111e-0000-1000-8000-00805f9b34fb"
35 #define PA_BLUEZ4_UUID_HFP_AG "0000111f-0000-1000-8000-00805f9b34fb"
37 #define HSP_MAX_GAIN 15
39 typedef struct pa_bluez4_device pa_bluez4_device;
40 typedef struct pa_bluez4_discovery pa_bluez4_discovery;
41 typedef struct pa_bluez4_transport pa_bluez4_transport;
45 typedef enum pa_bluez4_profile {
46 PA_BLUEZ4_PROFILE_A2DP_SINK,
47 PA_BLUEZ4_PROFILE_A2DP_SOURCE,
48 PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT,
49 PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY,
51 } pa_bluez4_profile_t;
53 #define PA_BLUEZ4_PROFILE_COUNT PA_BLUEZ4_PROFILE_OFF
55 struct pa_bluez4_hook_uuid_data {
56 pa_bluez4_device *device;
60 /* Hook data: pa_bluez4_discovery pointer. */
61 typedef enum pa_bluez4_hook {
62 PA_BLUEZ4_HOOK_DEVICE_CONNECTION_CHANGED, /* Call data: pa_bluez4_device */
63 PA_BLUEZ4_HOOK_DEVICE_UUID_ADDED, /* Call data: pa_bluez4_hook_uuid_data */
64 PA_BLUEZ4_HOOK_TRANSPORT_STATE_CHANGED, /* Call data: pa_bluez4_transport */
65 PA_BLUEZ4_HOOK_TRANSPORT_NREC_CHANGED, /* Call data: pa_bluez4_transport */
66 PA_BLUEZ4_HOOK_TRANSPORT_MICROPHONE_GAIN_CHANGED, /* Call data: pa_bluez4_transport */
67 PA_BLUEZ4_HOOK_TRANSPORT_SPEAKER_GAIN_CHANGED, /* Call data: pa_bluez4_transport */
71 typedef enum pa_bluez4_transport_state {
72 PA_BLUEZ4_TRANSPORT_STATE_DISCONNECTED,
73 PA_BLUEZ4_TRANSPORT_STATE_IDLE, /* Connected but not playing */
74 PA_BLUEZ4_TRANSPORT_STATE_PLAYING
75 } pa_bluez4_transport_state_t;
77 struct pa_bluez4_transport {
78 pa_bluez4_device *device;
81 pa_bluez4_profile_t profile;
86 pa_bluez4_transport_state_t state;
88 uint16_t microphone_gain; /* Used for HSP/HFP */
89 uint16_t speaker_gain; /* Used for HSP/HFP */
92 /* This enum is shared among Audio, Headset, AudioSink, and AudioSource, although not all values are acceptable in all profiles */
93 typedef enum pa_bluez4_audio_state {
94 PA_BLUEZ4_AUDIO_STATE_INVALID = -1,
95 PA_BLUEZ4_AUDIO_STATE_DISCONNECTED,
96 PA_BLUEZ4_AUDIO_STATE_CONNECTING,
97 PA_BLUEZ4_AUDIO_STATE_CONNECTED,
98 PA_BLUEZ4_AUDIO_STATE_PLAYING
99 } pa_bluez4_audio_state_t;
101 struct pa_bluez4_device {
102 pa_bluez4_discovery *discovery;
105 int device_info_valid; /* 0: no results yet; 1: good results; -1: bad results ... */
107 /* Device information */
110 pa_bluez4_transport *transports[PA_BLUEZ4_PROFILE_COUNT];
115 pa_hashmap *uuids; /* char* -> char* (hashmap-as-a-set) */
119 pa_bluez4_audio_state_t audio_state;
121 /* AudioSink, AudioSource, Headset and HandsfreeGateway states */
122 pa_bluez4_audio_state_t profile_state[PA_BLUEZ4_PROFILE_COUNT];
125 pa_bluez4_discovery* pa_bluez4_discovery_get(pa_core *core);
126 pa_bluez4_discovery* pa_bluez4_discovery_ref(pa_bluez4_discovery *y);
127 void pa_bluez4_discovery_unref(pa_bluez4_discovery *d);
129 pa_bluez4_device* pa_bluez4_discovery_get_by_path(pa_bluez4_discovery *d, const char* path);
130 pa_bluez4_device* pa_bluez4_discovery_get_by_address(pa_bluez4_discovery *d, const char* address);
132 bool pa_bluez4_device_any_audio_connected(const pa_bluez4_device *d);
134 int pa_bluez4_transport_acquire(pa_bluez4_transport *t, bool optional, size_t *imtu, size_t *omtu);
135 void pa_bluez4_transport_release(pa_bluez4_transport *t);
137 void pa_bluez4_transport_set_microphone_gain(pa_bluez4_transport *t, uint16_t value);
138 void pa_bluez4_transport_set_speaker_gain(pa_bluez4_transport *t, uint16_t value);
140 pa_hook* pa_bluez4_discovery_hook(pa_bluez4_discovery *y, pa_bluez4_hook_t hook);
142 typedef enum pa_bluez4_form_factor {
143 PA_BLUEZ4_FORM_FACTOR_UNKNOWN,
144 PA_BLUEZ4_FORM_FACTOR_HEADSET,
145 PA_BLUEZ4_FORM_FACTOR_HANDSFREE,
146 PA_BLUEZ4_FORM_FACTOR_MICROPHONE,
147 PA_BLUEZ4_FORM_FACTOR_SPEAKER,
148 PA_BLUEZ4_FORM_FACTOR_HEADPHONE,
149 PA_BLUEZ4_FORM_FACTOR_PORTABLE,
150 PA_BLUEZ4_FORM_FACTOR_CAR,
151 PA_BLUEZ4_FORM_FACTOR_HIFI,
152 PA_BLUEZ4_FORM_FACTOR_PHONE,
153 } pa_bluez4_form_factor_t;
155 pa_bluez4_form_factor_t pa_bluez4_get_form_factor(uint32_t class);
156 const char *pa_bluez4_form_factor_to_string(pa_bluez4_form_factor_t ff);
158 const char *pa_bluez4_profile_to_string(pa_bluez4_profile_t profile);