BluezQt

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

KDE's Doxygen guidelines are available online.