]> granicus.if.org Git - esp-idf/commitdiff
component/bt: remove SBC frame scramling
authorbaohongde <baohongde@espressif.com>
Mon, 25 Mar 2019 12:28:55 +0000 (20:28 +0800)
committerbaohongde <baohongde@espressif.com>
Fri, 24 May 2019 09:33:52 +0000 (17:33 +0800)
components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c
components/bt/bluedroid/external/sbc/encoder/srce/sbc_encoder.c
components/bt/bluedroid/stack/a2dp/a2d_sbc.c
components/bt/bluedroid/stack/a2dp/include/a2d_int.h
components/bt/bluedroid/stack/include/stack/a2d_sbc.h

index a4697bc26e32fbade9a40ad4bd049fea51625a20..c67b9783cfcd9ee6306aee794e81b6a68c0ce8a5 100644 (file)
@@ -1375,8 +1375,7 @@ static void btc_media_aa_prep_sbc_2_send(UINT8 nb_frame)
             if (btc_media_aa_read_feeding()) {
                 /* SBC encode and descramble frame */
                 SBC_Encoder(&(btc_sbc_encoder));
-                A2D_SbcChkFrInit(btc_sbc_encoder.pu8Packet);
-                A2D_SbcDescramble(btc_sbc_encoder.pu8Packet, btc_sbc_encoder.u16PacketLength);
+
                 /* Update SBC frame length */
                 p_buf->len += btc_sbc_encoder.u16PacketLength;
                 nb_frame--;
index c08d4a5cce8c6960ba21bd8853f9049463c4b98f..378111b0078ff973789acde7647aecd92f36b206 100644 (file)
 
 SINT16 EncMaxShiftCounter;
 
-/*************************************************************************************************
- * SBC encoder scramble code
- * Purpose: to tie the SBC code with BTE/mobile stack code,
- *          especially for the case when the SBC is ported into a third-party Multimedia chip
- *
- * Algorithm:
- *  init process: all counters reset to 0,
- *                calculate base_index: (6 + s16NumOfChannels*s16NumOfSubBands/2)
- *    scramble side:    the init process happens every time SBC_Encoder_Init() is called.
- *    descramble side:  it would be nice to know if he "init" process has happened.
- *                      alter the SBC SYNC word 0x9C (1001 1100) to 0x8C (1000 1100).
- *
- *  scramble process:
- *    The CRC byte:
- *    Every SBC frame has a frame header.
- *    The 1st byte is the sync word and the following 2 bytes are about the stream format.
- *    They are supposed to be "constant" within a "song"
- *    The 4th byte is the CRC byte. The CRC byte is bound to be random.
- *    Derive 2 items from the CRC byte; one is the "use" bit, the other is the "index".
- *
- *    SBC keeps 2 sets of "use" & "index"; derived the current and the previous frame.
- *
- *    The "use" bit is any bit in SBC_PRTC_USE_MASK is set.
- *    If set, SBC uses the "index" from the current frame.
- *    If not set, SBC uses the "index" from the previous frame or 0.
- *
- *    index = (CRC & 0x3) + ((CRC & 0x30) >> 2) // 8 is the max index
- *
- *    if(index > 0)
- *    {
- *        p = &u8frame[base_index];
- *        if((index&1)&&(u16PacketLength > (base_index+index*2)))
- *        {
- *            // odd index: swap 2 bytes
- *            tmp = p[index];
- *            p[index] = p[index*2];
- *            p[index*2] = tmp;
- *        }
- *        else
- *        {
- *            // even index: shift by 3
- *            tmp = (p[index] >> 5) + (p[index] << 3);
- *            p[index] = tmp;
- *        }
- *    }
- *    //else index is 0. The frame stays unaltered
- *
- */
-
-#define SBC_PRTC_CRC_IDX        3
-#define SBC_PRTC_USE_MASK       0x64
-#define SBC_PRTC_SYNC_MASK      0x10
-#define SBC_PRTC_CIDX           0
-#define SBC_PRTC_LIDX           1
-typedef struct {
-    UINT8   use;
-    UINT8   idx;
-} tSBC_FR_CB;
-
-typedef struct {
-    tSBC_FR_CB      fr[2];
-    UINT8           init;
-    UINT8           index;
-    UINT8           base;
-} tSBC_PRTC_CB;
-tSBC_PRTC_CB sbc_prtc_cb;
-
-#define SBC_PRTC_IDX(sc) (((sc) & 0x3) + (((sc) & 0x30) >> 2))
-#define SBC_PRTC_CHK_INIT(ar) {if(sbc_prtc_cb.init == 0){sbc_prtc_cb.init=1; ar[0] &= ~SBC_PRTC_SYNC_MASK;}}
-#define SBC_PRTC_C2L() {p_last=&sbc_prtc_cb.fr[SBC_PRTC_LIDX]; p_cur=&sbc_prtc_cb.fr[SBC_PRTC_CIDX]; \
-                        p_last->idx = p_cur->idx; p_last->use = p_cur->use;}
-#define SBC_PRTC_GETC(ar) {p_cur->use = ar[SBC_PRTC_CRC_IDX] & SBC_PRTC_USE_MASK; \
-                           p_cur->idx = SBC_PRTC_IDX(ar[SBC_PRTC_CRC_IDX]);}
-#define SBC_PRTC_CHK_CRC(ar) {SBC_PRTC_C2L();SBC_PRTC_GETC(ar);sbc_prtc_cb.index = (p_cur->use)?SBC_PRTC_CIDX:SBC_PRTC_LIDX;}
-#define SBC_PRTC_SCRMB(ar) {idx = sbc_prtc_cb.fr[sbc_prtc_cb.index].idx; \
-    if(idx > 0){if((idx&1)&&(pstrEncParams->u16PacketLength > (sbc_prtc_cb.base+(idx<<1)))) {tmp2=idx<<1; tmp=ar[idx];ar[idx]=ar[tmp2];ar[tmp2]=tmp;} \
-                else{tmp2=ar[idx]; tmp=(tmp2>>5)+(tmp2<<3);ar[idx]=(UINT8)tmp;}}}
-
 #if (SBC_JOINT_STE_INCLUDED == TRUE)
 SINT32   s32LRDiff[SBC_MAX_NUM_OF_BLOCKS]    = {0};
 SINT32   s32LRSum[SBC_MAX_NUM_OF_BLOCKS]     = {0};
@@ -130,9 +52,6 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
     UINT32 u32CountSum, u32CountDiff;
     SINT32 *pSum, *pDiff;
 #endif
-    UINT8  *pu8;
-    tSBC_FR_CB  *p_cur, *p_last;
-    UINT32       idx, tmp, tmp2;
     register SINT32  s32NumOfSubBands = pstrEncParams->s16NumOfSubBands;
 
     pstrEncParams->pu8NextPacket = pstrEncParams->pu8Packet;
@@ -263,22 +182,9 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
             sbc_enc_bit_alloc_mono(pstrEncParams);
         }
 
-        /* save the beginning of the frame. pu8NextPacket is modified in EncPacking() */
-        pu8 = pstrEncParams->pu8NextPacket;
         /* Quantize the encoded audio */
         EncPacking(pstrEncParams);
 
-        /* scramble the code */
-        SBC_PRTC_CHK_INIT(pu8);
-        SBC_PRTC_CHK_CRC(pu8);
-#if 0
-        if (pstrEncParams->u16PacketLength > ((sbc_prtc_cb.fr[sbc_prtc_cb.index].idx * 2) + sbc_prtc_cb.base)) {
-            printf("len: %d, idx: %d\n", pstrEncParams->u16PacketLength, sbc_prtc_cb.fr[sbc_prtc_cb.index].idx);
-        } else {
-            printf("len: %d, idx: %d!!!!\n", pstrEncParams->u16PacketLength, sbc_prtc_cb.fr[sbc_prtc_cb.index].idx);
-        }
-#endif
-        SBC_PRTC_SCRMB((&pu8[sbc_prtc_cb.base]));
     } while (--(pstrEncParams->u8NumPacketToEncode));
 
     pstrEncParams->u8NumPacketToEncode = 1; /* default is one for retrocompatibility purpose */
@@ -395,9 +301,6 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
                      pstrEncParams->u16BitRate, pstrEncParams->s16BitPool);
 
     SbcAnalysisInit();
-
-    memset(&sbc_prtc_cb, 0, sizeof(tSBC_PRTC_CB));
-    sbc_prtc_cb.base = 6 + pstrEncParams->s16NumOfChannels * pstrEncParams->s16NumOfSubBands / 2;
 }
 
 #endif /* #if (defined(SBC_ENC_INCLUDED) && SBC_ENC_INCLUDED == TRUE) */
index 00977fc398b610239bf0b8db19a423e6c8b0e519..1319d11fa72a500dcd5cde5578a4649d37cd05b3 100644 (file)
 
 #if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
 
-/*************************************************************************************************
- * SBC descramble code
- * Purpose: to tie the SBC code with BTE/mobile stack code,
- *          especially for the case when the SBC is ported into a third-party Multimedia chip
- *
- * Algorithm:
- *  init process: all counters reset to 0,
- *                calculate base_index: (6 + s16NumOfChannels*s16NumOfSubBands/2)
- *    scramble side:    the init process happens every time SBC_Encoder_Init() is called.
- *    descramble side:  it would be nice to know if he "init" process has happened.
- *                      alter the SBC SYNC word 0x9C (1001 1100) to 0x8C (1000 1100).
- *
- *  scramble process:
- *    The CRC byte:
- *    Every SBC frame has a frame header.
- *    The 1st byte is the sync word and the following 2 bytes are about the stream format.
- *    They are supposed to be "constant" within a "song"
- *    The 4th byte is the CRC byte. The CRC byte is bound to be random.
- *    Derive 2 items from the CRC byte; one is the "use" bit, the other is the "index".
- *
- *    SBC keeps 2 sets of "use" & "index"; derived the current and the previous frame.
- *
- *    The "use" bit is any bit in SBC_PRTC_USE_MASK is set.
- *    If set, SBC uses the "index" from the current frame.
- *    If not set, SBC uses the "index" from the previous frame or 0.
- *
- *    index = (CRC & 0x3) + ((CRC & 0x30) >> 2) // 8 is the max index
- *
- *    if(index > 0)
- *    {
- *        p = &u8frame[base_index];
- *        if((index&1)&&(u16PacketLength > (base_index+index*2)))
- *        {
- *            // odd index: swap 2 bytes
- *            tmp = p[index];
- *            p[index] = p[index*2];
- *            p[index*2] = tmp;
- *        }
- *        else
- *        {
- *            // even index: shift by 3
- *            tmp = (p[index] >> 3) + (p[index] << 5);
- *            p[index] = tmp;
- *        }
- *    }
- *    //else index is 0. The frame stays unaltered
- *
- */
-#define A2D_SBC_SYNC_WORD       0x9C
-#define A2D_SBC_CRC_IDX         3
-#define A2D_SBC_USE_MASK        0x64
-#define A2D_SBC_SYNC_MASK       0x10
-#define A2D_SBC_CIDX            0
-#define A2D_SBC_LIDX            1
-#define A2D_SBC_CH_M_BITS       0xC /* channel mode bits: 0: mono; 1 ch */
-#define A2D_SBC_SUBBAND_BIT     0x1 /* num of subband bit: 0:4; 1: 8 */
-
-#define A2D_SBC_GET_IDX(sc) (((sc) & 0x3) + (((sc) & 0x30) >> 2))
-
-typedef struct {
-    UINT8   use;
-    UINT8   idx;
-} tA2D_SBC_FR_CB;
-
-typedef struct {
-    tA2D_SBC_FR_CB  fr[2];
-    UINT8           index;
-    UINT8           base;
-} tA2D_SBC_DS_CB;
-
-static tA2D_SBC_DS_CB a2d_sbc_ds_cb;
-/*int a2d_count = 0;*/
-/******************************************************************************
-**
-** Function         A2D_SbcChkFrInit
-**
-** Description      check if need to init the descramble control block.
-**
-** Returns          nothing.
-******************************************************************************/
-void A2D_SbcChkFrInit(UINT8 *p_pkt)
-{
-    UINT8   fmt;
-    UINT8   num_chnl = 1;
-    UINT8   num_subband = 4;
-
-    if ((p_pkt[0] & A2D_SBC_SYNC_MASK) == 0) {
-        a2d_cb.use_desc = TRUE;
-        fmt = p_pkt[1];
-        p_pkt[0] |= A2D_SBC_SYNC_MASK;
-        memset(&a2d_sbc_ds_cb, 0, sizeof(tA2D_SBC_DS_CB));
-        if (fmt & A2D_SBC_CH_M_BITS) {
-            num_chnl = 2;
-        }
-        if (fmt & A2D_SBC_SUBBAND_BIT) {
-            num_subband = 8;
-        }
-        a2d_sbc_ds_cb.base = 6 + num_chnl * num_subband / 2;
-        /*printf("base: %d\n", a2d_sbc_ds_cb.base);
-        a2d_count = 0;*/
-    }
-}
-
-/******************************************************************************
-**
-** Function         A2D_SbcDescramble
-**
-** Description      descramble the packet.
-**
-** Returns          nothing.
-******************************************************************************/
-void A2D_SbcDescramble(UINT8 *p_pkt, UINT16 len)
-{
-    tA2D_SBC_FR_CB *p_cur, *p_last;
-    UINT32   idx, tmp, tmp2;
-
-    if (a2d_cb.use_desc) {
-        /* c2l */
-        p_last  = &a2d_sbc_ds_cb.fr[A2D_SBC_LIDX];
-        p_cur   = &a2d_sbc_ds_cb.fr[A2D_SBC_CIDX];
-        p_last->idx = p_cur->idx;
-        p_last->use = p_cur->use;
-        /* getc */
-        p_cur->use = p_pkt[A2D_SBC_CRC_IDX] & A2D_SBC_USE_MASK;
-        p_cur->idx = A2D_SBC_GET_IDX(p_pkt[A2D_SBC_CRC_IDX]);
-        a2d_sbc_ds_cb.index = (p_cur->use) ? A2D_SBC_CIDX : A2D_SBC_LIDX;
-        /*
-        printf("%05d: ar[%02d]: x%02x, msk: x%02x, use: %s, idx: %02d, ",
-            a2d_count++,
-            A2D_SBC_CRC_IDX, p_pkt[A2D_SBC_CRC_IDX], A2D_SBC_USE_MASK,
-            (p_cur->use)?"cur":"lst", p_cur->idx);
-        */
-        /* descramble */
-        idx = a2d_sbc_ds_cb.fr[a2d_sbc_ds_cb.index].idx;
-        if (idx > 0) {
-            p_pkt = &p_pkt[a2d_sbc_ds_cb.base];
-            if ((idx & 1) && (len > (a2d_sbc_ds_cb.base + (idx << 1)))) {
-                tmp2        = (idx << 1);
-                tmp         = p_pkt[idx];
-                p_pkt[idx]  = p_pkt[tmp2];
-                p_pkt[tmp2]  = tmp;
-                /*
-                printf("tmp2: %02d, len: %d, idx: %d\n",
-                    tmp2, len, a2d_sbc_ds_cb.fr[a2d_sbc_ds_cb.index].idx);
-                    */
-            } else {
-                tmp2        = p_pkt[idx];
-                tmp         = (tmp2 >> 3) + (tmp2 << 5);
-                p_pkt[idx]  = (UINT8)tmp;
-                /*
-                printf("tmp: x%02x, len: %d, idx: %d(cmp:%d)\n",
-                    (UINT8)tmp2, len, a2d_sbc_ds_cb.fr[a2d_sbc_ds_cb.index].idx,
-                    (a2d_sbc_ds_cb.base+(idx<<1)));
-                    */
-            }
-        }
-        /*
-        else
-        {
-            printf("!!!!\n");
-        }
-        */
-    }
-}
-
 /******************************************************************************
 **
 ** Function         A2D_BldSbcInfo
index ddd3e9646413f12179e281115200cb557d8a7721..0791a975f9a609a897e8c1c95a51437c238dd2b7 100644 (file)
@@ -51,7 +51,6 @@ typedef struct {
 typedef struct {
     tA2D_FIND_CB    find;   /* find service control block */
     UINT8           trace_level;
-    BOOLEAN         use_desc;
     UINT16          avdt_sdp_ver;   /* AVDTP version */
 } tA2D_CB;
 
index 98b63e46ca94e5f8f292336f635983b5e41875dd..065f264f9c3ffb065ae3971c1c8cbbd9def6c115 100644 (file)
@@ -92,26 +92,6 @@ typedef struct {
 extern "C"
 {
 #endif
-/******************************************************************************
-**
-** Function         A2D_SbcChkFrInit
-**
-** Description      check if need to init the descramble control block.
-**
-** Returns          nothing.
-******************************************************************************/
-extern void A2D_SbcChkFrInit(UINT8 *p_pkt);
-
-/******************************************************************************
-**
-** Function         A2D_SbcDescramble
-**
-** Description      descramble the packet.
-**
-** Returns          nothing.
-******************************************************************************/
-extern void A2D_SbcDescramble(UINT8 *p_pkt, UINT16 len);
-
 /******************************************************************************
 **
 ** Function         A2D_BldSbcInfo