File indexing completed on 2024-04-28 03:52:00

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