Tizen 2.0 Release
[framework/connectivity/bluez.git] / audio / a2dp.h
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2006-2010  Nokia Corporation
6  *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
7  *  Copyright (C) 2011  BMW Car IT GmbH. All rights reserved.
8  *
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23  *
24  */
25
26 #define A2DP_CODEC_SBC                  0x00
27 #define A2DP_CODEC_MPEG12               0x01
28 #define A2DP_CODEC_MPEG24               0x02
29 #define A2DP_CODEC_ATRAC                0x03
30
31 #define SBC_SAMPLING_FREQ_16000         (1 << 3)
32 #define SBC_SAMPLING_FREQ_32000         (1 << 2)
33 #define SBC_SAMPLING_FREQ_44100         (1 << 1)
34 #define SBC_SAMPLING_FREQ_48000         1
35
36 #define SBC_CHANNEL_MODE_MONO           (1 << 3)
37 #define SBC_CHANNEL_MODE_DUAL_CHANNEL   (1 << 2)
38 #define SBC_CHANNEL_MODE_STEREO         (1 << 1)
39 #define SBC_CHANNEL_MODE_JOINT_STEREO   1
40
41 #define SBC_BLOCK_LENGTH_4              (1 << 3)
42 #define SBC_BLOCK_LENGTH_8              (1 << 2)
43 #define SBC_BLOCK_LENGTH_12             (1 << 1)
44 #define SBC_BLOCK_LENGTH_16             1
45
46 #define SBC_SUBBANDS_4                  (1 << 1)
47 #define SBC_SUBBANDS_8                  1
48
49 #define SBC_ALLOCATION_SNR              (1 << 1)
50 #define SBC_ALLOCATION_LOUDNESS         1
51
52 #define MPEG_CHANNEL_MODE_MONO          (1 << 3)
53 #define MPEG_CHANNEL_MODE_DUAL_CHANNEL  (1 << 2)
54 #define MPEG_CHANNEL_MODE_STEREO        (1 << 1)
55 #define MPEG_CHANNEL_MODE_JOINT_STEREO  1
56
57 #define MPEG_LAYER_MP1                  (1 << 2)
58 #define MPEG_LAYER_MP2                  (1 << 1)
59 #define MPEG_LAYER_MP3                  1
60
61 #define MPEG_SAMPLING_FREQ_16000        (1 << 5)
62 #define MPEG_SAMPLING_FREQ_22050        (1 << 4)
63 #define MPEG_SAMPLING_FREQ_24000        (1 << 3)
64 #define MPEG_SAMPLING_FREQ_32000        (1 << 2)
65 #define MPEG_SAMPLING_FREQ_44100        (1 << 1)
66 #define MPEG_SAMPLING_FREQ_48000        1
67
68 #define MAX_BITPOOL 64
69 #define MIN_BITPOOL 2
70
71 #if __BYTE_ORDER == __LITTLE_ENDIAN
72
73 struct sbc_codec_cap {
74         struct avdtp_media_codec_capability cap;
75         uint8_t channel_mode:4;
76         uint8_t frequency:4;
77         uint8_t allocation_method:2;
78         uint8_t subbands:2;
79         uint8_t block_length:4;
80         uint8_t min_bitpool;
81         uint8_t max_bitpool;
82 } __attribute__ ((packed));
83
84 struct mpeg_codec_cap {
85         struct avdtp_media_codec_capability cap;
86         uint8_t channel_mode:4;
87         uint8_t crc:1;
88         uint8_t layer:3;
89         uint8_t frequency:6;
90         uint8_t mpf:1;
91         uint8_t rfa:1;
92         uint16_t bitrate;
93 } __attribute__ ((packed));
94
95 #elif __BYTE_ORDER == __BIG_ENDIAN
96
97 struct sbc_codec_cap {
98         struct avdtp_media_codec_capability cap;
99         uint8_t frequency:4;
100         uint8_t channel_mode:4;
101         uint8_t block_length:4;
102         uint8_t subbands:2;
103         uint8_t allocation_method:2;
104         uint8_t min_bitpool;
105         uint8_t max_bitpool;
106 } __attribute__ ((packed));
107
108 struct mpeg_codec_cap {
109         struct avdtp_media_codec_capability cap;
110         uint8_t layer:3;
111         uint8_t crc:1;
112         uint8_t channel_mode:4;
113         uint8_t rfa:1;
114         uint8_t mpf:1;
115         uint8_t frequency:6;
116         uint16_t bitrate;
117 } __attribute__ ((packed));
118
119 #else
120 #error "Unknown byte order"
121 #endif
122
123 struct a2dp_sep;
124 struct a2dp_setup;
125
126 typedef void (*a2dp_endpoint_select_t) (struct a2dp_setup *setup, void *ret,
127                                         int size);
128 typedef void (*a2dp_endpoint_config_t) (struct a2dp_setup *setup, gboolean ret);
129
130 struct a2dp_endpoint {
131         const char *(*get_name) (struct a2dp_sep *sep, void *user_data);
132         size_t (*get_capabilities) (struct a2dp_sep *sep,
133                                                 uint8_t **capabilities,
134                                                 void *user_data);
135         int (*select_configuration) (struct a2dp_sep *sep,
136                                                 uint8_t *capabilities,
137                                                 size_t length,
138                                                 struct a2dp_setup *setup,
139                                                 a2dp_endpoint_select_t cb,
140                                                 void *user_data);
141         int (*set_configuration) (struct a2dp_sep *sep,
142                                                 struct audio_device *dev,
143                                                 uint8_t *configuration,
144                                                 size_t length,
145                                                 struct a2dp_setup *setup,
146                                                 a2dp_endpoint_config_t cb,
147                                                 void *user_data);
148         void (*clear_configuration) (struct a2dp_sep *sep, void *user_data);
149         void (*set_delay) (struct a2dp_sep *sep, uint16_t delay,
150                                                         void *user_data);
151 };
152
153 typedef void (*a2dp_select_cb_t) (struct avdtp *session,
154                                         struct a2dp_sep *sep, GSList *caps,
155                                         void *user_data);
156 typedef void (*a2dp_config_cb_t) (struct avdtp *session, struct a2dp_sep *sep,
157                                         struct avdtp_stream *stream,
158                                         struct avdtp_error *err,
159                                         void *user_data);
160 typedef void (*a2dp_stream_cb_t) (struct avdtp *session,
161                                         struct avdtp_error *err,
162                                         void *user_data);
163
164 int a2dp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config);
165 void a2dp_unregister(const bdaddr_t *src);
166
167 struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
168                                 uint8_t codec, gboolean delay_reporting,
169                                 struct a2dp_endpoint *endpoint,
170                                 void *user_data, GDestroyNotify destroy,
171                                 int *err);
172 void a2dp_remove_sep(struct a2dp_sep *sep);
173
174 struct a2dp_sep *a2dp_get(struct avdtp *session, struct avdtp_remote_sep *sep);
175
176 unsigned int a2dp_select_capabilities(struct avdtp *session,
177                                         uint8_t type, const char *sender,
178                                         a2dp_select_cb_t cb,
179                                         void *user_data);
180 unsigned int a2dp_config(struct avdtp *session, struct a2dp_sep *sep,
181                                 a2dp_config_cb_t cb, GSList *caps,
182                                 void *user_data);
183 unsigned int a2dp_resume(struct avdtp *session, struct a2dp_sep *sep,
184                                 a2dp_stream_cb_t cb, void *user_data);
185 unsigned int a2dp_suspend(struct avdtp *session, struct a2dp_sep *sep,
186                                 a2dp_stream_cb_t cb, void *user_data);
187 gboolean a2dp_cancel(struct audio_device *dev, unsigned int id);
188
189 gboolean a2dp_sep_lock(struct a2dp_sep *sep, struct avdtp *session);
190 gboolean a2dp_sep_unlock(struct a2dp_sep *sep, struct avdtp *session);
191 gboolean a2dp_sep_get_lock(struct a2dp_sep *sep);
192 struct avdtp_stream *a2dp_sep_get_stream(struct a2dp_sep *sep);
193 struct a2dp_sep *a2dp_get_sep(struct avdtp *session,
194                                 struct avdtp_stream *stream);