f4b5ca34979f2b77a9d4e1ff7a7bb3f8539a78ca
[platform/upstream/pulseaudio.git] / src / modules / bluetooth / bluez4-util.h
1 #ifndef foobluez4utilhfoo
2 #define foobluez4utilhfoo
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 <dbus/dbus.h>
24
25 #include <pulsecore/llist.h>
26 #include <pulsecore/macro.h>
27
28 #define PA_BLUEZ4_ERROR_NOT_SUPPORTED "org.bluez.Error.NotSupported"
29
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"
36
37 #define HSP_MAX_GAIN 15
38
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;
42
43 struct userdata;
44
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,
50     PA_BLUEZ4_PROFILE_OFF
51 } pa_bluez4_profile_t;
52
53 #define PA_BLUEZ4_PROFILE_COUNT PA_BLUEZ4_PROFILE_OFF
54
55 struct pa_bluez4_hook_uuid_data {
56     pa_bluez4_device *device;
57     const char *uuid;
58 };
59
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 */
68     PA_BLUEZ4_HOOK_MAX
69 } pa_bluez4_hook_t;
70
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;
76
77 struct pa_bluez4_transport {
78     pa_bluez4_device *device;
79     char *owner;
80     char *path;
81     pa_bluez4_profile_t profile;
82     uint8_t codec;
83     uint8_t *config;
84     int config_size;
85
86     pa_bluez4_transport_state_t state;
87     bool nrec;
88     uint16_t microphone_gain; /* Used for HSP/HFP */
89     uint16_t speaker_gain; /* Used for HSP/HFP */
90 };
91
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;
100
101 struct pa_bluez4_device {
102     pa_bluez4_discovery *discovery;
103     bool dead;
104
105     int device_info_valid;      /* 0: no results yet; 1: good results; -1: bad results ... */
106
107     /* Device information */
108     char *name;
109     char *path;
110     pa_bluez4_transport *transports[PA_BLUEZ4_PROFILE_COUNT];
111     int paired;
112     char *alias;
113     char *address;
114     int class;
115     pa_hashmap *uuids; /* char* -> char* (hashmap-as-a-set) */
116     int trusted;
117
118     /* Audio state */
119     pa_bluez4_audio_state_t audio_state;
120
121     /* AudioSink, AudioSource, Headset and HandsfreeGateway states */
122     pa_bluez4_audio_state_t profile_state[PA_BLUEZ4_PROFILE_COUNT];
123 };
124
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);
128
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);
131
132 bool pa_bluez4_device_any_audio_connected(const pa_bluez4_device *d);
133
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);
136
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);
139
140 pa_hook* pa_bluez4_discovery_hook(pa_bluez4_discovery *y, pa_bluez4_hook_t hook);
141
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;
154
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);
157
158 const char *pa_bluez4_profile_to_string(pa_bluez4_profile_t profile);
159
160 #endif