blob: c900fcd142d10c67ded250187b674e1f482edb87 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2004-2008 Marcel Holtmann <marcel@holtmann.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/*
Message sequence chart of streaming sequence for A2DP transport
Audio daemon User
on snd_pcm_open
<--BT_GETCAPABILITIES_REQ
BT_GETCAPABILITIES_RSP-->
on snd_pcm_hw_params
<--BT_SETCONFIGURATION_REQ
BT_SETCONFIGURATION_RSP-->
on snd_pcm_prepare
<--BT_STREAMSTART_REQ
<Moves to streaming state>
BT_STREAMSTART_RSP-->
BT_STREAMFD_IND -->
< streams data >
..........
on snd_pcm_drop/snd_pcm_drain
<--BT_STREAMSTOP_REQ
<Moves to open state>
BT_STREAMSTOP_RSP-->
on IPC close or appl crash
<Moves to idle>
*/
#ifndef BT_AUDIOCLIENT_H
#define BT_AUDIOCLIENT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#define BT_AUDIO_IPC_PACKET_SIZE 128
#define BT_IPC_SOCKET_NAME "\0/org/bluez/audio"
/* Generic message header definition, except for RSP messages */
typedef struct {
uint8_t msg_type;
} __attribute__ ((packed)) bt_audio_msg_header_t;
/* Generic message header definition, for all RSP messages */
typedef struct {
bt_audio_msg_header_t msg_h;
uint8_t posix_errno;
} __attribute__ ((packed)) bt_audio_rsp_msg_header_t;
/* Messages list */
#define BT_GETCAPABILITIES_REQ 0
#define BT_GETCAPABILITIES_RSP 1
#define BT_SETCONFIGURATION_REQ 2
#define BT_SETCONFIGURATION_RSP 3
#define BT_STREAMSTART_REQ 4
#define BT_STREAMSTART_RSP 5
#define BT_STREAMSTOP_REQ 6
#define BT_STREAMSTOP_RSP 7
#define BT_STREAMSUSPEND_IND 8
#define BT_STREAMRESUME_IND 9
#define BT_CONTROL_REQ 10
#define BT_CONTROL_RSP 11
#define BT_CONTROL_IND 12
#define BT_STREAMFD_IND 13
/* BT_GETCAPABILITIES_REQ */
#define BT_CAPABILITIES_TRANSPORT_A2DP 0
#define BT_CAPABILITIES_TRANSPORT_SCO 1
#define BT_CAPABILITIES_TRANSPORT_ANY 2
#define BT_CAPABILITIES_ACCESS_MODE_READ 1
#define BT_CAPABILITIES_ACCESS_MODE_WRITE 2
#define BT_CAPABILITIES_ACCESS_MODE_READWRITE 3
#define BT_FLAG_AUTOCONNECT 1
struct bt_getcapabilities_req {
bt_audio_msg_header_t h;
char device[18]; /* Address of the remote Device */
uint8_t transport; /* Requested transport */
uint8_t flags; /* Requested flags */
} __attribute__ ((packed));
/* BT_GETCAPABILITIES_RSP */
/**
* SBC Codec parameters as per A2DP profile 1.0 § 4.3
*/
#define BT_SBC_SAMPLING_FREQ_16000 (1 << 3)
#define BT_SBC_SAMPLING_FREQ_32000 (1 << 2)
#define BT_SBC_SAMPLING_FREQ_44100 (1 << 1)
#define BT_SBC_SAMPLING_FREQ_48000 1
#define BT_A2DP_CHANNEL_MODE_MONO (1 << 3)
#define BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL (1 << 2)
#define BT_A2DP_CHANNEL_MODE_STEREO (1 << 1)
#define BT_A2DP_CHANNEL_MODE_JOINT_STEREO 1
#define BT_A2DP_BLOCK_LENGTH_4 (1 << 3)
#define BT_A2DP_BLOCK_LENGTH_8 (1 << 2)
#define BT_A2DP_BLOCK_LENGTH_12 (1 << 1)
#define BT_A2DP_BLOCK_LENGTH_16 1
#define BT_A2DP_SUBBANDS_4 (1 << 1)
#define BT_A2DP_SUBBANDS_8 1
#define BT_A2DP_ALLOCATION_SNR (1 << 1)
#define BT_A2DP_ALLOCATION_LOUDNESS 1
#define BT_MPEG_SAMPLING_FREQ_16000 (1 << 5)
#define BT_MPEG_SAMPLING_FREQ_22050 (1 << 4)
#define BT_MPEG_SAMPLING_FREQ_24000 (1 << 3)
#define BT_MPEG_SAMPLING_FREQ_32000 (1 << 2)
#define BT_MPEG_SAMPLING_FREQ_44100 (1 << 1)
#define BT_MPEG_SAMPLING_FREQ_48000 1
#define BT_MPEG_LAYER_1 (1 << 2)
#define BT_MPEG_LAYER_2 (1 << 1)
#define BT_MPEG_LAYER_3 1
typedef struct {
uint8_t channel_mode;
uint8_t frequency;
uint8_t allocation_method;
uint8_t subbands;
uint8_t block_length;
uint8_t min_bitpool;
uint8_t max_bitpool;
} __attribute__ ((packed)) sbc_capabilities_t;
typedef struct {
uint8_t channel_mode;
uint8_t crc;
uint8_t layer;
uint8_t frequency;
uint8_t mpf;
uint16_t bitrate;
} __attribute__ ((packed)) mpeg_capabilities_t;
struct bt_getcapabilities_rsp {
bt_audio_rsp_msg_header_t rsp_h;
uint8_t transport; /* Granted transport */
sbc_capabilities_t sbc_capabilities; /* A2DP only */
mpeg_capabilities_t mpeg_capabilities; /* A2DP only */
uint16_t sampling_rate; /* SCO only */
} __attribute__ ((packed));
/* BT_SETCONFIGURATION_REQ */
struct bt_setconfiguration_req {
bt_audio_msg_header_t h;
char device[18]; /* Address of the remote Device */
uint8_t transport; /* Requested transport */
uint8_t access_mode; /* Requested access mode */
sbc_capabilities_t sbc_capabilities; /* A2DP only - only one of this field
and next one must be filled */
mpeg_capabilities_t mpeg_capabilities; /* A2DP only */
} __attribute__ ((packed));
/* BT_SETCONFIGURATION_RSP */
struct bt_setconfiguration_rsp {
bt_audio_rsp_msg_header_t rsp_h;
uint8_t transport; /* Granted transport */
uint8_t access_mode; /* Granted access mode */
uint16_t link_mtu; /* Max length that transport supports */
} __attribute__ ((packed));
/* BT_STREAMSTART_REQ */
#define BT_STREAM_ACCESS_READ 0
#define BT_STREAM_ACCESS_WRITE 1
#define BT_STREAM_ACCESS_READWRITE 2
struct bt_streamstart_req {
bt_audio_msg_header_t h;
} __attribute__ ((packed));
/* BT_STREAMSTART_RSP */
struct bt_streamstart_rsp {
bt_audio_rsp_msg_header_t rsp_h;
} __attribute__ ((packed));
/* BT_STREAMFD_IND */
/* This message is followed by one byte of data containing the stream data fd
as ancilliary data */
struct bt_streamfd_ind {
bt_audio_msg_header_t h;
} __attribute__ ((packed));
/* BT_STREAMSTOP_REQ */
struct bt_streamstop_req {
bt_audio_msg_header_t h;
} __attribute__ ((packed));
/* BT_STREAMSTOP_RSP */
struct bt_streamstop_rsp {
bt_audio_rsp_msg_header_t rsp_h;
} __attribute__ ((packed));
/* BT_STREAMSUSPEND_IND */
struct bt_streamsuspend_ind {
bt_audio_msg_header_t h;
} __attribute__ ((packed));
/* BT_STREAMRESUME_IND */
struct bt_streamresume_ind {
bt_audio_msg_header_t h;
} __attribute__ ((packed));
/* BT_CONTROL_REQ */
#define BT_CONTROL_KEY_POWER 0x40
#define BT_CONTROL_KEY_VOL_UP 0x41
#define BT_CONTROL_KEY_VOL_DOWN 0x42
#define BT_CONTROL_KEY_MUTE 0x43
#define BT_CONTROL_KEY_PLAY 0x44
#define BT_CONTROL_KEY_STOP 0x45
#define BT_CONTROL_KEY_PAUSE 0x46
#define BT_CONTROL_KEY_RECORD 0x47
#define BT_CONTROL_KEY_REWIND 0x48
#define BT_CONTROL_KEY_FAST_FORWARD 0x49
#define BT_CONTROL_KEY_EJECT 0x4A
#define BT_CONTROL_KEY_FORWARD 0x4B
#define BT_CONTROL_KEY_BACKWARD 0x4C
struct bt_control_req {
bt_audio_msg_header_t h;
uint8_t mode; /* Control Mode */
uint8_t key; /* Control Key */
} __attribute__ ((packed));
/* BT_CONTROL_RSP */
struct bt_control_rsp {
bt_audio_rsp_msg_header_t rsp_h;
uint8_t mode; /* Control Mode */
uint8_t key; /* Control Key */
} __attribute__ ((packed));
/* BT_CONTROL_IND */
struct bt_control_ind {
bt_audio_msg_header_t h;
uint8_t mode; /* Control Mode */
uint8_t key; /* Control Key */
} __attribute__ ((packed));
/* Function declaration */
/* Opens a connection to the audio service: return a socket descriptor */
int bt_audio_service_open();
/* Closes a connection to the audio service */
int bt_audio_service_close(int sk);
/* Receives stream data file descriptor : must be called after a
BT_STREAMFD_IND message is returned */
int bt_audio_service_get_data_fd(int sk);
/* Human readable message type string */
const char *bt_audio_strmsg(int type);
#ifdef __cplusplus
}
#endif
#endif /* BT_AUDIOCLIENT_H */
|