File indexing completed on 2024-04-28 15:17:50

0001 /*
0002  *  BlueZ - Bluetooth protocol stack for Linux
0003  *
0004  *  SPDX-FileCopyrightText: 2006-2010 Nokia Corporation
0005  *  SPDX-FileCopyrightText: 2004-2010 Marcel Holtmann <marcel@holtmann.org>
0006  *
0007  *  SPDX-License-Identifier: LGPL-2.1-or-later
0008  */
0009 
0010 #ifndef BLUEZQT_A2DPCODECS_H
0011 #define BLUEZQT_A2DPCODECS_H
0012 
0013 #include <stdint.h>
0014 
0015 // clang-format off
0016 
0017 #define A2DP_CODEC_SBC          0x00
0018 #define A2DP_CODEC_MPEG12       0x01
0019 #define A2DP_CODEC_MPEG24       0x02
0020 #define A2DP_CODEC_ATRAC        0x04
0021 #define A2DP_CODEC_VENDOR       0xFF
0022 
0023 #define SBC_SAMPLING_FREQ_16000     (1 << 3)
0024 #define SBC_SAMPLING_FREQ_32000     (1 << 2)
0025 #define SBC_SAMPLING_FREQ_44100     (1 << 1)
0026 #define SBC_SAMPLING_FREQ_48000     1
0027 
0028 #define SBC_CHANNEL_MODE_MONO       (1 << 3)
0029 #define SBC_CHANNEL_MODE_DUAL_CHANNEL   (1 << 2)
0030 #define SBC_CHANNEL_MODE_STEREO     (1 << 1)
0031 #define SBC_CHANNEL_MODE_JOINT_STEREO   1
0032 
0033 #define SBC_BLOCK_LENGTH_4      (1 << 3)
0034 #define SBC_BLOCK_LENGTH_8      (1 << 2)
0035 #define SBC_BLOCK_LENGTH_12     (1 << 1)
0036 #define SBC_BLOCK_LENGTH_16     1
0037 
0038 #define SBC_SUBBANDS_4          (1 << 1)
0039 #define SBC_SUBBANDS_8          1
0040 
0041 #define SBC_ALLOCATION_SNR      (1 << 1)
0042 #define SBC_ALLOCATION_LOUDNESS     1
0043 
0044 #define MAX_BITPOOL 64
0045 #define MIN_BITPOOL 2
0046 
0047 #define MPEG_CHANNEL_MODE_MONO      (1 << 3)
0048 #define MPEG_CHANNEL_MODE_DUAL_CHANNEL  (1 << 2)
0049 #define MPEG_CHANNEL_MODE_STEREO    (1 << 1)
0050 #define MPEG_CHANNEL_MODE_JOINT_STEREO  1
0051 
0052 #define MPEG_LAYER_MP1          (1 << 2)
0053 #define MPEG_LAYER_MP2          (1 << 1)
0054 #define MPEG_LAYER_MP3          1
0055 
0056 #define MPEG_SAMPLING_FREQ_16000    (1 << 5)
0057 #define MPEG_SAMPLING_FREQ_22050    (1 << 4)
0058 #define MPEG_SAMPLING_FREQ_24000    (1 << 3)
0059 #define MPEG_SAMPLING_FREQ_32000    (1 << 2)
0060 #define MPEG_SAMPLING_FREQ_44100    (1 << 1)
0061 #define MPEG_SAMPLING_FREQ_48000    1
0062 
0063 #define MPEG_BIT_RATE_VBR       0x8000
0064 #define MPEG_BIT_RATE_320000        0x4000
0065 #define MPEG_BIT_RATE_256000        0x2000
0066 #define MPEG_BIT_RATE_224000        0x1000
0067 #define MPEG_BIT_RATE_192000        0x0800
0068 #define MPEG_BIT_RATE_160000        0x0400
0069 #define MPEG_BIT_RATE_128000        0x0200
0070 #define MPEG_BIT_RATE_112000        0x0100
0071 #define MPEG_BIT_RATE_96000     0x0080
0072 #define MPEG_BIT_RATE_80000     0x0040
0073 #define MPEG_BIT_RATE_64000     0x0020
0074 #define MPEG_BIT_RATE_56000     0x0010
0075 #define MPEG_BIT_RATE_48000     0x0008
0076 #define MPEG_BIT_RATE_40000     0x0004
0077 #define MPEG_BIT_RATE_32000     0x0002
0078 #define MPEG_BIT_RATE_FREE      0x0001
0079 
0080 #define AAC_OBJECT_TYPE_MPEG2_AAC_LC    0x80
0081 #define AAC_OBJECT_TYPE_MPEG4_AAC_LC    0x40
0082 #define AAC_OBJECT_TYPE_MPEG4_AAC_LTP   0x20
0083 #define AAC_OBJECT_TYPE_MPEG4_AAC_SCA   0x10
0084 
0085 #define AAC_SAMPLING_FREQ_8000      0x0800
0086 #define AAC_SAMPLING_FREQ_11025     0x0400
0087 #define AAC_SAMPLING_FREQ_12000     0x0200
0088 #define AAC_SAMPLING_FREQ_16000     0x0100
0089 #define AAC_SAMPLING_FREQ_22050     0x0080
0090 #define AAC_SAMPLING_FREQ_24000     0x0040
0091 #define AAC_SAMPLING_FREQ_32000     0x0020
0092 #define AAC_SAMPLING_FREQ_44100     0x0010
0093 #define AAC_SAMPLING_FREQ_48000     0x0008
0094 #define AAC_SAMPLING_FREQ_64000     0x0004
0095 #define AAC_SAMPLING_FREQ_88200     0x0002
0096 #define AAC_SAMPLING_FREQ_96000     0x0001
0097 
0098 #define AAC_CHANNELS_1          0x02
0099 #define AAC_CHANNELS_2          0x01
0100 
0101 #define AAC_GET_BITRATE(a) ((a).bitrate1 << 16 | \
0102                     (a).bitrate2 << 8 | (a).bitrate3)
0103 #define AAC_GET_FREQUENCY(a) ((a).frequency1 << 4 | (a).frequency2)
0104 
0105 #define AAC_SET_BITRATE(a, b) \
0106     do { \
0107         (a).bitrate1 = (b >> 16) & 0x7f; \
0108         (a).bitrate2 = (b >> 8) & 0xff; \
0109         (a).bitrate3 = b & 0xff; \
0110     } while (0)
0111 #define AAC_SET_FREQUENCY(a, f) \
0112     do { \
0113         (a).frequency1 = (f >> 4) & 0xff; \
0114         (a).frequency2 = f & 0x0f; \
0115     } while (0)
0116 
0117 #define AAC_INIT_BITRATE(b) \
0118     .bitrate1 = (b >> 16) & 0x7f, \
0119     .bitrate2 = (b >> 8) & 0xff, \
0120     .bitrate3 = b & 0xff,
0121 #define AAC_INIT_FREQUENCY(f) \
0122     .frequency1 = (f >> 4) & 0xff, \
0123     .frequency2 = f & 0x0f,
0124 
0125 #define APTX_VENDOR_ID          0x0000004f
0126 #define APTX_CODEC_ID           0x0001
0127 
0128 #define APTX_CHANNEL_MODE_MONO      0x01
0129 #define APTX_CHANNEL_MODE_STEREO    0x02
0130 
0131 #define APTX_SAMPLING_FREQ_16000    0x08
0132 #define APTX_SAMPLING_FREQ_32000    0x04
0133 #define APTX_SAMPLING_FREQ_44100    0x02
0134 #define APTX_SAMPLING_FREQ_48000    0x01
0135 
0136 #define LDAC_VENDOR_ID          0x0000012d
0137 #define LDAC_CODEC_ID           0x00aa
0138 
0139 typedef struct {
0140     uint32_t vendor_id;
0141     uint16_t codec_id;
0142 } __attribute__ ((packed)) a2dp_vendor_codec_t;
0143 
0144 #if __BYTE_ORDER == __LITTLE_ENDIAN
0145 
0146 typedef struct {
0147     uint8_t channel_mode:4;
0148     uint8_t frequency:4;
0149     uint8_t allocation_method:2;
0150     uint8_t subbands:2;
0151     uint8_t block_length:4;
0152     uint8_t min_bitpool;
0153     uint8_t max_bitpool;
0154 } __attribute__ ((packed)) a2dp_sbc_t;
0155 
0156 typedef struct {
0157     uint8_t channel_mode:4;
0158     uint8_t crc:1;
0159     uint8_t layer:3;
0160     uint8_t frequency:6;
0161     uint8_t mpf:1;
0162     uint8_t rfa:1;
0163     uint16_t bitrate;
0164 } __attribute__ ((packed)) a2dp_mpeg_t;
0165 
0166 typedef struct {
0167     uint8_t object_type;
0168     uint8_t frequency1;
0169     uint8_t rfa:2;
0170     uint8_t channels:2;
0171     uint8_t frequency2:4;
0172     uint8_t bitrate1:7;
0173     uint8_t vbr:1;
0174     uint8_t bitrate2;
0175     uint8_t bitrate3;
0176 } __attribute__ ((packed)) a2dp_aac_t;
0177 
0178 typedef struct {
0179     a2dp_vendor_codec_t info;
0180     uint8_t channel_mode:4;
0181     uint8_t frequency:4;
0182 } __attribute__ ((packed)) a2dp_aptx_t;
0183 
0184 typedef struct {
0185     a2dp_vendor_codec_t info;
0186     uint8_t unknown[2];
0187 } __attribute__ ((packed)) a2dp_ldac_t;
0188 
0189 #elif __BYTE_ORDER == __BIG_ENDIAN
0190 
0191 typedef struct {
0192     uint8_t frequency:4;
0193     uint8_t channel_mode:4;
0194     uint8_t block_length:4;
0195     uint8_t subbands:2;
0196     uint8_t allocation_method:2;
0197     uint8_t min_bitpool;
0198     uint8_t max_bitpool;
0199 } __attribute__ ((packed)) a2dp_sbc_t;
0200 
0201 typedef struct {
0202     uint8_t layer:3;
0203     uint8_t crc:1;
0204     uint8_t channel_mode:4;
0205     uint8_t rfa:1;
0206     uint8_t mpf:1;
0207     uint8_t frequency:6;
0208     uint16_t bitrate;
0209 } __attribute__ ((packed)) a2dp_mpeg_t;
0210 
0211 typedef struct {
0212     uint8_t object_type;
0213     uint8_t frequency1;
0214     uint8_t frequency2:4;
0215     uint8_t channels:2;
0216     uint8_t rfa:2;
0217     uint8_t vbr:1;
0218     uint8_t bitrate1:7;
0219     uint8_t bitrate2;
0220     uint8_t bitrate3;
0221 } __attribute__ ((packed)) a2dp_aac_t;
0222 
0223 typedef struct {
0224     a2dp_vendor_codec_t info;
0225     uint8_t frequency:4;
0226     uint8_t channel_mode:4;
0227 } __attribute__ ((packed)) a2dp_aptx_t;
0228 
0229 typedef struct {
0230     a2dp_vendor_codec_t info;
0231     uint8_t unknown[2];
0232 } __attribute__ ((packed)) a2dp_ldac_t;
0233 
0234 #else
0235 #error "Unknown byte order"
0236 #endif
0237 
0238 #ifdef __cplusplus
0239 extern "C" {
0240 #endif
0241 
0242 #include "bluezqt_export.h"
0243 
0244 BLUEZQT_EXPORT extern const a2dp_sbc_t sbcCapabilities;
0245 BLUEZQT_EXPORT extern const a2dp_aac_t aacCapabilities;
0246 
0247 #ifdef __cplusplus
0248 }
0249 #endif
0250 
0251 #endif