Skip to contentSkip to conversation

a2dp-codecs & avinfo: Simplify defintions and parsing of aptX family

PATCH Applied Pali Rohár 2 participants 2 messages Jan 26, 2019 – Jan 31, 2019 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 a2dp-codecs & avinfo: Simplify defintions and parsing of aptX family

Reuse whole a2dp_aptx_t structure and defines as they are same for aptX Low Latency and aptX HD.

---
 profiles/audio/a2dp-codecs.h | 46 ++++++--------------------------------
 tools/avinfo.c               | 53 +++++++++++++-------------------------------
 2 files changed, 22 insertions(+), 77 deletions(-)
profiles/audio/a2dp-codecs.h +7 -39
index f31f3a311..4789e27ed 100644
@@ -213,14 +213,6 @@
 #define APTX_LL_VENDOR_ID		0x0000000a
 #define APTX_LL_CODEC_ID		0x0002
 
-#define APTX_LL_CHANNEL_MODE_MONO	0x01
-#define APTX_LL_CHANNEL_MODE_STEREO	0x02
-
-#define APTX_LL_SAMPLING_FREQ_16000	0x08
-#define APTX_LL_SAMPLING_FREQ_32000	0x04
-#define APTX_LL_SAMPLING_FREQ_44100	0x02
-#define APTX_LL_SAMPLING_FREQ_48000	0x01
-
 /* Default parameters for aptX Low Latency encoder */
 
 /* Target codec buffer level = 180 */
@@ -244,14 +236,6 @@
 #define APTX_HD_VENDOR_ID		0x000000D7
 #define APTX_HD_CODEC_ID		0x0024
 
-#define APTX_HD_CHANNEL_MODE_MONO	0x1
-#define APTX_HD_CHANNEL_MODE_STEREO	0x2
-
-#define APTX_HD_SAMPLING_FREQ_16000	0x8
-#define APTX_HD_SAMPLING_FREQ_32000	0x4
-#define APTX_HD_SAMPLING_FREQ_44100	0x2
-#define APTX_HD_SAMPLING_FREQ_48000	0x1
-
 #define LDAC_VENDOR_ID			0x0000012d
 #define LDAC_CODEC_ID			0x00aa
 
@@ -360,25 +344,13 @@ typedef struct {
 } __attribute__ ((packed)) a2dp_faststream_t;
 
 typedef struct {
-	a2dp_vendor_codec_t info;
-	uint8_t channel_mode:4;
-	uint8_t frequency:4;
+	a2dp_aptx_t aptx;
 	uint8_t bidirect_link:1;
 	uint8_t has_new_caps:1;
 	uint8_t reserved:6;
 	a2dp_aptx_ll_new_caps_t new_caps[0];
 } __attribute__ ((packed)) a2dp_aptx_ll_t;
 
-typedef struct {
-	a2dp_vendor_codec_t info;
-	uint8_t channel_mode:4;
-	uint8_t frequency:4;
-	uint8_t reserved0;
-	uint8_t reserved1;
-	uint8_t reserved2;
-	uint8_t reserved3;
-} __attribute__ ((packed)) a2dp_aptx_hd_t;
-
 #elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \
 	__BYTE_ORDER == __BIG_ENDIAN
 
@@ -430,25 +402,21 @@ typedef struct {
 } __attribute__ ((packed)) a2dp_faststream_t;
 
 typedef struct {
-	a2dp_vendor_codec_t info;
-	uint8_t frequency:4;
-	uint8_t channel_mode:4;
+	a2dp_aptx_t aptx;
 	uint8_t reserved:6;
 	uint8_t has_new_caps:1;
 	uint8_t bidirect_link:1;
 	a2dp_aptx_ll_new_caps_t new_caps[0];
 } __attribute__ ((packed)) a2dp_aptx_ll_t;
 
+#else
+#error "Unknown byte order"
+#endif
+
 typedef struct {
-	a2dp_vendor_codec_t info;
-	uint8_t frequency:4;
-	uint8_t channel_mode:4;
+	a2dp_aptx_t aptx;
 	uint8_t reserved0;
 	uint8_t reserved1;
 	uint8_t reserved2;
 	uint8_t reserved3;
 } __attribute__ ((packed)) a2dp_aptx_hd_t;
-
-#else
-#error "Unknown byte order"
-#endif
tools/avinfo.c +15 -38

78 lines not on this page · raw message

Signature · 1 line
2.11.0
maintainer Applied
#1 lore raw

Hi Pali,

Quoted 188 lines · Pali Rohár

Reuse whole a2dp_aptx_t structure and defines as they are same for aptX Low Latency and aptX HD.

---
 profiles/audio/a2dp-codecs.h | 46 ++++++--------------------------------
 tools/avinfo.c               | 53 +++++++++++++-------------------------------
 2 files changed, 22 insertions(+), 77 deletions(-)
profiles/audio/a2dp-codecs.h +7 -39
index f31f3a311..4789e27ed 100644
@@ -213,14 +213,6 @@
 #define APTX_LL_VENDOR_ID              0x0000000a
 #define APTX_LL_CODEC_ID               0x0002
 
-#define APTX_LL_CHANNEL_MODE_MONO      0x01
-#define APTX_LL_CHANNEL_MODE_STEREO    0x02
-
-#define APTX_LL_SAMPLING_FREQ_16000    0x08
-#define APTX_LL_SAMPLING_FREQ_32000    0x04
-#define APTX_LL_SAMPLING_FREQ_44100    0x02
-#define APTX_LL_SAMPLING_FREQ_48000    0x01
-
 /* Default parameters for aptX Low Latency encoder */
 
 /* Target codec buffer level = 180 */
@@ -244,14 +236,6 @@
 #define APTX_HD_VENDOR_ID              0x000000D7
 #define APTX_HD_CODEC_ID               0x0024
 
-#define APTX_HD_CHANNEL_MODE_MONO      0x1
-#define APTX_HD_CHANNEL_MODE_STEREO    0x2
-
-#define APTX_HD_SAMPLING_FREQ_16000    0x8
-#define APTX_HD_SAMPLING_FREQ_32000    0x4
-#define APTX_HD_SAMPLING_FREQ_44100    0x2
-#define APTX_HD_SAMPLING_FREQ_48000    0x1
-
 #define LDAC_VENDOR_ID                 0x0000012d
 #define LDAC_CODEC_ID                  0x00aa
 
@@ -360,25 +344,13 @@ typedef struct {
 } __attribute__ ((packed)) a2dp_faststream_t;
 
 typedef struct {
-       a2dp_vendor_codec_t info;
-       uint8_t channel_mode:4;
-       uint8_t frequency:4;
+       a2dp_aptx_t aptx;
        uint8_t bidirect_link:1;
        uint8_t has_new_caps:1;
        uint8_t reserved:6;
        a2dp_aptx_ll_new_caps_t new_caps[0];
 } __attribute__ ((packed)) a2dp_aptx_ll_t;
 
-typedef struct {
-       a2dp_vendor_codec_t info;
-       uint8_t channel_mode:4;
-       uint8_t frequency:4;
-       uint8_t reserved0;
-       uint8_t reserved1;
-       uint8_t reserved2;
-       uint8_t reserved3;
-} __attribute__ ((packed)) a2dp_aptx_hd_t;
-
 #elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \
        __BYTE_ORDER == __BIG_ENDIAN
 
@@ -430,25 +402,21 @@ typedef struct {
 } __attribute__ ((packed)) a2dp_faststream_t;
 
 typedef struct {
-       a2dp_vendor_codec_t info;
-       uint8_t frequency:4;
-       uint8_t channel_mode:4;
+       a2dp_aptx_t aptx;
        uint8_t reserved:6;
        uint8_t has_new_caps:1;
        uint8_t bidirect_link:1;
        a2dp_aptx_ll_new_caps_t new_caps[0];
 } __attribute__ ((packed)) a2dp_aptx_ll_t;
 
+#else
+#error "Unknown byte order"
+#endif
+
 typedef struct {
-       a2dp_vendor_codec_t info;
-       uint8_t frequency:4;
-       uint8_t channel_mode:4;
+       a2dp_aptx_t aptx;
        uint8_t reserved0;
        uint8_t reserved1;
        uint8_t reserved2;
        uint8_t reserved3;
 } __attribute__ ((packed)) a2dp_aptx_hd_t;
-
-#else
-#error "Unknown byte order"
-#endif
tools/avinfo.c +15 -39
index 42f539f43..852d7b67e 100644
@@ -168,15 +168,8 @@ struct avdtp_content_protection_capability {
        uint8_t data[0];
 } __attribute__ ((packed));
 
-static void print_aptx(a2dp_aptx_t *aptx, uint8_t size)
+static void print_aptx_common(a2dp_aptx_t *aptx)
 {
-       printf("\t\tVendor Specific Value (aptX)");
-
-       if (size < sizeof(*aptx)) {
-               printf(" (broken)\n");
-               return;
-       }
-
        printf("\n\t\t\tFrequencies: ");
        if (aptx->frequency & APTX_SAMPLING_FREQ_16000)
                printf("16kHz ");
@@ -192,6 +185,18 @@ static void print_aptx(a2dp_aptx_t *aptx, uint8_t size)
                printf("Mono ");
        if (aptx->channel_mode & APTX_CHANNEL_MODE_STEREO)
                printf("Stereo ");
+}
+
+static void print_aptx(a2dp_aptx_t *aptx, uint8_t size)
+{
+       printf("\t\tVendor Specific Value (aptX)");
+
+       if (size < sizeof(*aptx)) {
+               printf(" (broken)\n");
+               return;
+       }
+
+       print_aptx_common(aptx);
 
        printf("\n");
 }
@@ -242,21 +247,7 @@ static void print_aptx_ll(a2dp_aptx_ll_t *aptx_ll, uint8_t size)
                return;
        }
 
-       printf("\n\t\t\tFrequencies: ");
-       if (aptx_ll->frequency & APTX_LL_SAMPLING_FREQ_16000)
-               printf("16kHz ");
-       if (aptx_ll->frequency & APTX_LL_SAMPLING_FREQ_32000)
-               printf("32kHz ");
-       if (aptx_ll->frequency & APTX_LL_SAMPLING_FREQ_44100)
-               printf("44.1kHz ");
-       if (aptx_ll->frequency & APTX_LL_SAMPLING_FREQ_48000)
-               printf("48kHz ");
-
-       printf("\n\t\t\tChannel modes: ");
-       if (aptx_ll->channel_mode & APTX_LL_CHANNEL_MODE_MONO)
-               printf("Mono ");
-       if (aptx_ll->channel_mode & APTX_LL_CHANNEL_MODE_STEREO)
-               printf("Stereo ");
+       print_aptx_common(&aptx_ll->aptx);
 
        printf("\n\t\tBidirectional link: %s",
                        aptx_ll->bidirect_link ? "Yes" : "No");
@@ -292,21 +283,7 @@ static void print_aptx_hd(a2dp_aptx_hd_t *aptx_hd, uint8_t size)
                return;
        }
 
-       printf("\n\t\t\tFrequencies: ");
-       if (aptx_hd->frequency & APTX_HD_SAMPLING_FREQ_16000)
-               printf("16kHz ");
-       if (aptx_hd->frequency & APTX_HD_SAMPLING_FREQ_32000)
-               printf("32kHz ");
-       if (aptx_hd->frequency & APTX_HD_SAMPLING_FREQ_44100)
-               printf("44.1kHz ");
-       if (aptx_hd->frequency & APTX_HD_SAMPLING_FREQ_48000)
-               printf("48kHz ");
-
-       printf("\n\t\t\tChannel modes: ");
-       if (aptx_hd->channel_mode & APTX_HD_CHANNEL_MODE_MONO)
-               printf("Mono ");
-       if (aptx_hd->channel_mode & APTX_HD_CHANNEL_MODE_STEREO)
-               printf("Stereo ");
+       print_aptx_common(&aptx_hd->aptx);
 
        printf("\n");
 }
--
Quoted 1 line

2.11.0

Applied, thanks.

Signature · 1 line
Luiz Augusto von Dentz