1/*
2 * BlueZ - Bluetooth protocol stack for Linux
3 *
4 * SPDX-FileCopyrightText: 2006-2010 Nokia Corporation
5 * SPDX-FileCopyrightText: 2004-2010 Marcel Holtmann <marcel@holtmann.org>
6 *
7 * SPDX-License-Identifier: LGPL-2.1-or-later
8 */
9
10#ifndef BLUEZQT_A2DPCODECS_H
11#define BLUEZQT_A2DPCODECS_H
12
13#include <stdint.h>
14
15// clang-format off
16
17#define A2DP_CODEC_SBC 0x00
18#define A2DP_CODEC_MPEG12 0x01
19#define A2DP_CODEC_MPEG24 0x02
20#define A2DP_CODEC_ATRAC 0x04
21#define A2DP_CODEC_VENDOR 0xFF
22
23#define SBC_SAMPLING_FREQ_16000 (1 << 3)
24#define SBC_SAMPLING_FREQ_32000 (1 << 2)
25#define SBC_SAMPLING_FREQ_44100 (1 << 1)
26#define SBC_SAMPLING_FREQ_48000 1
27
28#define SBC_CHANNEL_MODE_MONO (1 << 3)
29#define SBC_CHANNEL_MODE_DUAL_CHANNEL (1 << 2)
30#define SBC_CHANNEL_MODE_STEREO (1 << 1)
31#define SBC_CHANNEL_MODE_JOINT_STEREO 1
32
33#define SBC_BLOCK_LENGTH_4 (1 << 3)
34#define SBC_BLOCK_LENGTH_8 (1 << 2)
35#define SBC_BLOCK_LENGTH_12 (1 << 1)
36#define SBC_BLOCK_LENGTH_16 1
37
38#define SBC_SUBBANDS_4 (1 << 1)
39#define SBC_SUBBANDS_8 1
40
41#define SBC_ALLOCATION_SNR (1 << 1)
42#define SBC_ALLOCATION_LOUDNESS 1
43
44#define MAX_BITPOOL 64
45#define MIN_BITPOOL 2
46
47#define MPEG_CHANNEL_MODE_MONO (1 << 3)
48#define MPEG_CHANNEL_MODE_DUAL_CHANNEL (1 << 2)
49#define MPEG_CHANNEL_MODE_STEREO (1 << 1)
50#define MPEG_CHANNEL_MODE_JOINT_STEREO 1
51
52#define MPEG_LAYER_MP1 (1 << 2)
53#define MPEG_LAYER_MP2 (1 << 1)
54#define MPEG_LAYER_MP3 1
55
56#define MPEG_SAMPLING_FREQ_16000 (1 << 5)
57#define MPEG_SAMPLING_FREQ_22050 (1 << 4)
58#define MPEG_SAMPLING_FREQ_24000 (1 << 3)
59#define MPEG_SAMPLING_FREQ_32000 (1 << 2)
60#define MPEG_SAMPLING_FREQ_44100 (1 << 1)
61#define MPEG_SAMPLING_FREQ_48000 1
62
63#define MPEG_BIT_RATE_VBR 0x8000
64#define MPEG_BIT_RATE_320000 0x4000
65#define MPEG_BIT_RATE_256000 0x2000
66#define MPEG_BIT_RATE_224000 0x1000
67#define MPEG_BIT_RATE_192000 0x0800
68#define MPEG_BIT_RATE_160000 0x0400
69#define MPEG_BIT_RATE_128000 0x0200
70#define MPEG_BIT_RATE_112000 0x0100
71#define MPEG_BIT_RATE_96000 0x0080
72#define MPEG_BIT_RATE_80000 0x0040
73#define MPEG_BIT_RATE_64000 0x0020
74#define MPEG_BIT_RATE_56000 0x0010
75#define MPEG_BIT_RATE_48000 0x0008
76#define MPEG_BIT_RATE_40000 0x0004
77#define MPEG_BIT_RATE_32000 0x0002
78#define MPEG_BIT_RATE_FREE 0x0001
79
80#define AAC_OBJECT_TYPE_MPEG2_AAC_LC 0x80
81#define AAC_OBJECT_TYPE_MPEG4_AAC_LC 0x40
82#define AAC_OBJECT_TYPE_MPEG4_AAC_LTP 0x20
83#define AAC_OBJECT_TYPE_MPEG4_AAC_SCA 0x10
84
85#define AAC_SAMPLING_FREQ_8000 0x0800
86#define AAC_SAMPLING_FREQ_11025 0x0400
87#define AAC_SAMPLING_FREQ_12000 0x0200
88#define AAC_SAMPLING_FREQ_16000 0x0100
89#define AAC_SAMPLING_FREQ_22050 0x0080
90#define AAC_SAMPLING_FREQ_24000 0x0040
91#define AAC_SAMPLING_FREQ_32000 0x0020
92#define AAC_SAMPLING_FREQ_44100 0x0010
93#define AAC_SAMPLING_FREQ_48000 0x0008
94#define AAC_SAMPLING_FREQ_64000 0x0004
95#define AAC_SAMPLING_FREQ_88200 0x0002
96#define AAC_SAMPLING_FREQ_96000 0x0001
97
98#define AAC_CHANNELS_1 0x02
99#define AAC_CHANNELS_2 0x01
100
101#define AAC_GET_BITRATE(a) ((a).bitrate1 << 16 | \
102 (a).bitrate2 << 8 | (a).bitrate3)
103#define AAC_GET_FREQUENCY(a) ((a).frequency1 << 4 | (a).frequency2)
104
105#define AAC_SET_BITRATE(a, b) \
106 do { \
107 (a).bitrate1 = (b >> 16) & 0x7f; \
108 (a).bitrate2 = (b >> 8) & 0xff; \
109 (a).bitrate3 = b & 0xff; \
110 } while (0)
111#define AAC_SET_FREQUENCY(a, f) \
112 do { \
113 (a).frequency1 = (f >> 4) & 0xff; \
114 (a).frequency2 = f & 0x0f; \
115 } while (0)
116
117#define AAC_INIT_BITRATE(b) \
118 .bitrate1 = (b >> 16) & 0x7f, \
119 .bitrate2 = (b >> 8) & 0xff, \
120 .bitrate3 = b & 0xff,
121#define AAC_INIT_FREQUENCY(f) \
122 .frequency1 = (f >> 4) & 0xff, \
123 .frequency2 = f & 0x0f,
124
125#define APTX_VENDOR_ID 0x0000004f
126#define APTX_CODEC_ID 0x0001
127
128#define APTX_CHANNEL_MODE_MONO 0x01
129#define APTX_CHANNEL_MODE_STEREO 0x02
130
131#define APTX_SAMPLING_FREQ_16000 0x08
132#define APTX_SAMPLING_FREQ_32000 0x04
133#define APTX_SAMPLING_FREQ_44100 0x02
134#define APTX_SAMPLING_FREQ_48000 0x01
135
136#define LDAC_VENDOR_ID 0x0000012d
137#define LDAC_CODEC_ID 0x00aa
138
139typedef struct {
140 uint32_t vendor_id;
141 uint16_t codec_id;
142} __attribute__ ((packed)) a2dp_vendor_codec_t;
143
144#if __BYTE_ORDER == __LITTLE_ENDIAN
145
146typedef struct {
147 uint8_t channel_mode:4;
148 uint8_t frequency:4;
149 uint8_t allocation_method:2;
150 uint8_t subbands:2;
151 uint8_t block_length:4;
152 uint8_t min_bitpool;
153 uint8_t max_bitpool;
154} __attribute__ ((packed)) a2dp_sbc_t;
155
156typedef struct {
157 uint8_t channel_mode:4;
158 uint8_t crc:1;
159 uint8_t layer:3;
160 uint8_t frequency:6;
161 uint8_t mpf:1;
162 uint8_t rfa:1;
163 uint16_t bitrate;
164} __attribute__ ((packed)) a2dp_mpeg_t;
165
166typedef struct {
167 uint8_t object_type;
168 uint8_t frequency1;
169 uint8_t rfa:2;
170 uint8_t channels:2;
171 uint8_t frequency2:4;
172 uint8_t bitrate1:7;
173 uint8_t vbr:1;
174 uint8_t bitrate2;
175 uint8_t bitrate3;
176} __attribute__ ((packed)) a2dp_aac_t;
177
178typedef struct {
179 a2dp_vendor_codec_t info;
180 uint8_t channel_mode:4;
181 uint8_t frequency:4;
182} __attribute__ ((packed)) a2dp_aptx_t;
183
184typedef struct {
185 a2dp_vendor_codec_t info;
186 uint8_t unknown[2];
187} __attribute__ ((packed)) a2dp_ldac_t;
188
189#elif __BYTE_ORDER == __BIG_ENDIAN
190
191typedef struct {
192 uint8_t frequency:4;
193 uint8_t channel_mode:4;
194 uint8_t block_length:4;
195 uint8_t subbands:2;
196 uint8_t allocation_method:2;
197 uint8_t min_bitpool;
198 uint8_t max_bitpool;
199} __attribute__ ((packed)) a2dp_sbc_t;
200
201typedef struct {
202 uint8_t layer:3;
203 uint8_t crc:1;
204 uint8_t channel_mode:4;
205 uint8_t rfa:1;
206 uint8_t mpf:1;
207 uint8_t frequency:6;
208 uint16_t bitrate;
209} __attribute__ ((packed)) a2dp_mpeg_t;
210
211typedef struct {
212 uint8_t object_type;
213 uint8_t frequency1;
214 uint8_t frequency2:4;
215 uint8_t channels:2;
216 uint8_t rfa:2;
217 uint8_t vbr:1;
218 uint8_t bitrate1:7;
219 uint8_t bitrate2;
220 uint8_t bitrate3;
221} __attribute__ ((packed)) a2dp_aac_t;
222
223typedef struct {
224 a2dp_vendor_codec_t info;
225 uint8_t frequency:4;
226 uint8_t channel_mode:4;
227} __attribute__ ((packed)) a2dp_aptx_t;
228
229typedef struct {
230 a2dp_vendor_codec_t info;
231 uint8_t unknown[2];
232} __attribute__ ((packed)) a2dp_ldac_t;
233
234#else
235#error "Unknown byte order"
236#endif
237
238#ifdef __cplusplus
239extern "C" {
240#endif
241
242#include "bluezqt_export.h"
243
244BLUEZQT_EXPORT extern const a2dp_sbc_t sbcCapabilities;
245BLUEZQT_EXPORT extern const a2dp_aac_t aacCapabilities;
246
247#ifdef __cplusplus
248}
249#endif
250
251#endif
252

source code of bluez-qt/src/a2dp-codecs.h