a2dp-codecs & avinfo: Simplify defintions and parsing of aptX family
authorPali Rohár <pali.rohar@gmail.com>
Sat, 26 Jan 2019 10:46:06 +0000 (11:46 +0100)
committerhimanshu <h.himanshu@samsung.com>
Wed, 22 Jan 2020 13:20:51 +0000 (18:50 +0530)
Reuse whole a2dp_aptx_t structure and defines as they are same for aptX Low
Latency and aptX HD.

Change-Id: Ibeebd93c7c795f86ba07a8b2ce6df056c4c5c1a0
Signed-off-by: himanshu <h.himanshu@samsung.com>
profiles/audio/a2dp-codecs.h
tools/avinfo.c

index 0bdd291..16088dc 100755 (executable)
 #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 */
 #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
 
@@ -359,25 +343,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
 
@@ -429,25 +401,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
index 02fc1f2..ea7a93e 100755 (executable)
@@ -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");
 }