All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Frédéric Dalleau" <frederic.dalleau@linux.intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: "Frédéric Dalleau" <frederic.dalleau@linux.intel.com>
Subject: [PATCH 2/5] Add support for mSBC frame header
Date: Thu, 27 Sep 2012 16:44:25 +0200	[thread overview]
Message-ID: <1348757068-31048-3-git-send-email-frederic.dalleau@linux.intel.com> (raw)
In-Reply-To: <1348757068-31048-1-git-send-email-frederic.dalleau@linux.intel.com>

mSBC modifies header so that it contains: OxAD 0x00 0x00.
The first bytes allows to distinguish mSBC packets from standard SBC
packets used in A2DP. The two zero bytes are reserved for future definition.
---
 sbc/sbc.c |  104 +++++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 63 insertions(+), 41 deletions(-)

diff --git a/sbc/sbc.c b/sbc/sbc.c
index 7e4faa0..131755b 100644
--- a/sbc/sbc.c
+++ b/sbc/sbc.c
@@ -407,55 +407,71 @@ static int sbc_unpack_frame(sbc_t *sbc, const uint8_t *data,
 	if (len < 4)
 		return -1;
 
-	if (data[0] != SBC_SYNCWORD)
-		return -2;
-
-	frame->frequency = (data[1] >> 6) & 0x03;
+	if (sbc->flags & SBC_MSBC) {
+		if (data[0] != MSBC_SYNCWORD)
+			return -2;
+		if (data[1] != 0)
+			return -5;
+		if (data[2] != 0)
+			return -6;
 
-	frame->block_mode = (data[1] >> 4) & 0x03;
-	switch (frame->block_mode) {
-	case SBC_BLK_4:
-		frame->blocks = 4;
-		break;
-	case SBC_BLK_8:
-		frame->blocks = 8;
-		break;
-	case SBC_BLK_12:
-		frame->blocks = 12;
-		break;
-	case SBC_BLK_16:
-		frame->blocks = 16;
-		break;
-	}
-	if (sbc->flags & SBC_MSBC)
+		frame->frequency = SBC_FREQ_16000;
+		frame->block_mode = SBC_BLK_4;
 		frame->blocks = MSBC_BLOCKS;
-
-	frame->mode = (data[1] >> 2) & 0x03;
-	switch (frame->mode) {
-	case MONO:
+		frame->allocation = LOUDNESS;
+		frame->mode = MONO;
 		frame->channels = 1;
-		break;
-	case DUAL_CHANNEL:	/* fall-through */
-	case STEREO:
-	case JOINT_STEREO:
-		frame->channels = 2;
-		break;
-	}
+		frame->subband_mode = 1;
+		frame->subbands = 8;
+		frame->bitpool = 26;
+	} else {
+		if (data[0] != SBC_SYNCWORD)
+			return -2;
+
+		frame->frequency = (data[1] >> 6) & 0x03;
+		frame->block_mode = (data[1] >> 4) & 0x03;
+		switch (frame->block_mode) {
+		case SBC_BLK_4:
+			frame->blocks = 4;
+			break;
+		case SBC_BLK_8:
+			frame->blocks = 8;
+			break;
+		case SBC_BLK_12:
+			frame->blocks = 12;
+			break;
+		case SBC_BLK_16:
+			frame->blocks = 16;
+			break;
+		}
+
+		frame->mode = (data[1] >> 2) & 0x03;
+		switch (frame->mode) {
+		case MONO:
+			frame->channels = 1;
+			break;
+		case DUAL_CHANNEL:	/* fall-through */
+		case STEREO:
+		case JOINT_STEREO:
+			frame->channels = 2;
+			break;
+		}
 
-	frame->allocation = (data[1] >> 1) & 0x01;
+		frame->allocation = (data[1] >> 1) & 0x01;
 
-	frame->subband_mode = (data[1] & 0x01);
-	frame->subbands = frame->subband_mode ? 8 : 4;
+		frame->subband_mode = (data[1] & 0x01);
+		frame->subbands = frame->subband_mode ? 8 : 4;
 
-	frame->bitpool = data[2];
+		frame->bitpool = data[2];
 
-	if ((frame->mode == MONO || frame->mode == DUAL_CHANNEL) &&
-			frame->bitpool > 16 * frame->subbands)
-		return -4;
+		if ((frame->mode == MONO || frame->mode == DUAL_CHANNEL) &&
+				frame->bitpool > 16 * frame->subbands)
+			return -4;
 
-	if ((frame->mode == STEREO || frame->mode == JOINT_STEREO) &&
-			frame->bitpool > 32 * frame->subbands)
-		return -4;
+		if ((frame->mode == STEREO || frame->mode == JOINT_STEREO) &&
+				frame->bitpool > 32 * frame->subbands)
+			return -4;
+	}
 
 	/* data[3] is crc, we're checking it later */
 
@@ -800,6 +816,11 @@ static SBC_ALWAYS_INLINE ssize_t sbc_pack_frame_internal(sbc_t *sbc,
 	uint32_t levels[2][8];	/* levels are derived from that */
 	uint32_t sb_sample_delta[2][8];
 
+	if (sbc->flags & SBC_MSBC) {
+		data[0] = MSBC_SYNCWORD;
+		data[1] = 0;
+		data[2] = 0;
+	} else {
 		data[0] = SBC_SYNCWORD;
 
 		data[1] = (frame->frequency & 0x03) << 6;
@@ -831,6 +852,7 @@ static SBC_ALWAYS_INLINE ssize_t sbc_pack_frame_internal(sbc_t *sbc,
 		if ((frame->mode == STEREO || frame->mode == JOINT_STEREO) &&
 				frame->bitpool > frame_subbands << 5)
 			return -5;
+	}
 
 	/* Can't fill in crc yet */
 
-- 
1.7.9.5


  parent reply	other threads:[~2012-09-27 14:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-27 14:44 [PATCH 0/5] mSBC tests Frédéric Dalleau
2012-09-27 14:44 ` [PATCH 1/5] Add msbc encoding and decoding flag Frédéric Dalleau
2012-09-28 14:53   ` Marcel Holtmann
2012-09-27 14:44 ` Frédéric Dalleau [this message]
2012-09-28 14:45   ` [PATCH 2/5] Add support for mSBC frame header Marcel Holtmann
2012-09-27 14:44 ` [PATCH 3/5] update sbcdec for msbc Frédéric Dalleau
2012-09-27 14:44 ` [PATCH 4/5] update sbcenc " Frédéric Dalleau
2012-09-27 14:44 ` [PATCH 5/5] update sbcinfo " Frédéric Dalleau
2012-09-27 20:34 ` [PATCH 0/5] mSBC tests Siarhei Siamashka
2012-09-28  8:21   ` Dalleau, Frederic
2012-09-28 15:05   ` Marcel Holtmann
2012-10-30  2:18     ` Siarhei Siamashka

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=1348757068-31048-3-git-send-email-frederic.dalleau@linux.intel.com \
    --to=frederic.dalleau@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.