linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali.rohar@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH] a2dp-codecs & avinfo: Simplify defintions and parsing of aptX family
Date: Sat, 26 Jan 2019 11:46:06 +0100	[thread overview]
Message-ID: <20190126104606.26486-1-pali.rohar@gmail.com> (raw)

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(-)

diff --git a/profiles/audio/a2dp-codecs.h b/profiles/audio/a2dp-codecs.h
index f31f3a311..4789e27ed 100644
--- a/profiles/audio/a2dp-codecs.h
+++ b/profiles/audio/a2dp-codecs.h
@@ -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
diff --git a/tools/avinfo.c b/tools/avinfo.c
index 42f539f43..852d7b67e 100644
--- a/tools/avinfo.c
+++ b/tools/avinfo.c
@@ -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");
 }
-- 
2.11.0


             reply	other threads:[~2019-01-26 10:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-26 10:46 Pali Rohár [this message]
2019-01-31 10:50 ` [PATCH] a2dp-codecs & avinfo: Simplify defintions and parsing of aptX family Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190126104606.26486-1-pali.rohar@gmail.com \
    --to=pali.rohar@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).