mirror of
https://github.com/espressif/esp-idf.git
synced 2026-08-18 06:35:35 +03:00
fix(bt/bluedroid): fixed multiple high-severity issues from AI code review in SBC
This commit is contained in:
@@ -372,7 +372,7 @@ OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
*
|
||||
* @param frameData Pointer to the SBC data.
|
||||
*
|
||||
* @param frameBytes Number of bytes avaiable in the frameData buffer
|
||||
* @param frameBytes Number of bytes available in the frameData buffer
|
||||
*
|
||||
*/
|
||||
OI_UINT8 OI_CODEC_SBC_FrameCount(OI_BYTE *frameData,
|
||||
@@ -447,7 +447,7 @@ OI_UINT16 OI_CODEC_SBC_CalculatePcmBytes(OI_CODEC_SBC_COMMON_CONTEXT *common);
|
||||
* @return pointer to text string containing codec version text
|
||||
*
|
||||
*/
|
||||
OI_CHAR *OI_CODEC_Version(void);
|
||||
const OI_CHAR *OI_CODEC_Version(void);
|
||||
|
||||
|
||||
/**
|
||||
@@ -457,11 +457,13 @@ OI_CHAR *OI_CODEC_Version(void);
|
||||
@{
|
||||
*/
|
||||
|
||||
#ifdef OI_DEBUG
|
||||
extern const OI_CHAR *const OI_CODEC_SBC_FreqText[];
|
||||
extern const OI_CHAR *const OI_CODEC_SBC_ModeText[];
|
||||
extern const OI_CHAR *const OI_CODEC_SBC_SubbandsText[];
|
||||
extern const OI_CHAR *const OI_CODEC_SBC_BlocksText[];
|
||||
extern const OI_CHAR *const OI_CODEC_SBC_AllocText[];
|
||||
#endif
|
||||
|
||||
/**
|
||||
@}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*
|
||||
******************************************************************************/
|
||||
#include "common/bt_target.h"
|
||||
#include <stdlib.h>
|
||||
#include <oi_codec_sbc_private.h>
|
||||
|
||||
#if (defined(SBC_DEC_INCLUDED) && SBC_DEC_INCLUDED == TRUE)
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
@ingroup codec_internal
|
||||
*/
|
||||
|
||||
/**@addgroup codec_internal*/
|
||||
/**@addtogroup codec_internal*/
|
||||
/**@{*/
|
||||
#include "common/bt_target.h"
|
||||
#include <oi_codec_sbc_private.h>
|
||||
@@ -78,7 +78,7 @@ static void stereoBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common)
|
||||
}
|
||||
sbL = 0;
|
||||
sbR = nrof_subbands;
|
||||
while (excess) {
|
||||
while (excess && sbL < nrof_subbands) {
|
||||
excess = allocExcessBits(&common->bits.uint8[sbL], excess);
|
||||
++sbL;
|
||||
if (!excess) {
|
||||
@@ -107,7 +107,9 @@ PRIVATE void OI_SBC_ComputeBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common)
|
||||
* Using an array of function pointers prevents the compiler from creating a suboptimal
|
||||
* monolithic inlined bit allocation function.
|
||||
*/
|
||||
balloc[common->frameInfo.mode](common);
|
||||
if (common->frameInfo.mode < OI_ARRAYSIZE(balloc)) {
|
||||
balloc[common->frameInfo.mode](common);
|
||||
}
|
||||
}
|
||||
|
||||
OI_UINT32 OI_CODEC_SBC_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO *frame)
|
||||
@@ -137,6 +139,10 @@ OI_UINT16 OI_CODEC_SBC_CalculateBitpool(OI_CODEC_SBC_FRAME_INFO *frame,
|
||||
OI_UINT16 hdr;
|
||||
OI_UINT16 bits;
|
||||
|
||||
if ((frameLen <= SBC_HEADER_LEN) || (nrof_blocks == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (frame->mode == SBC_JOINT_STEREO) {
|
||||
hdr = 9 * nrof_subbands;
|
||||
} else {
|
||||
|
||||
@@ -51,10 +51,11 @@ OI_UINT32 OI_SBC_MaxBitpool(OI_CODEC_SBC_FRAME_INFO *frame)
|
||||
case SBC_STEREO:
|
||||
case SBC_JOINT_STEREO:
|
||||
return 32 * frame->nrof_subbands;
|
||||
default:
|
||||
ERROR(("Invalid frame mode %d", frame->mode));
|
||||
OI_ASSERT(FALSE);
|
||||
}
|
||||
|
||||
ERROR(("Invalid frame mode %d", frame->mode));
|
||||
OI_ASSERT(FALSE);
|
||||
return 0; /* Should never be reached */
|
||||
}
|
||||
|
||||
@@ -102,10 +103,6 @@ INLINE OI_UINT16 OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *fram
|
||||
return internal_CalculateFramelen(frame);
|
||||
}
|
||||
|
||||
|
||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
|
||||
/*
|
||||
* Computes the bit need for each sample and as also returns a counts of bit needs that are greater
|
||||
* than one. This count is used in the first phase of bit allocation.
|
||||
@@ -242,7 +239,7 @@ OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||
*
|
||||
* @param bitpool The bitpool we have to work within
|
||||
*
|
||||
* @param bitneeds An array of bit needs (more acturately allocation prioritities) for each
|
||||
* @param bitneeds An array of bit needs (more acturately allocation priorities) for each
|
||||
* subband across all blocks in the SBC frame
|
||||
*
|
||||
* @param subbands The number of subbands over which the adkustment is calculated. For mono and
|
||||
@@ -309,7 +306,7 @@ OI_INT adjustToFitBitpool(const OI_UINT bitpool,
|
||||
|
||||
|
||||
/*
|
||||
* The bit allocator trys to avoid single bit allocations except as a last resort. So in the case
|
||||
* The bit allocator tries to avoid single bit allocations except as a last resort. So in the case
|
||||
* where a bitneed of 1 was passed over during the adsjustment phase 2 bits are now allocated.
|
||||
*/
|
||||
INLINE OI_INT allocAdjustedBits(OI_UINT8 *dest,
|
||||
@@ -380,7 +377,7 @@ void oneChannelBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||
++sb;
|
||||
}
|
||||
sb = 0;
|
||||
while (excess) {
|
||||
while (excess && (sb < nrof_subbands)) {
|
||||
excess = allocExcessBits(&allocBits[sb], excess);
|
||||
++sb;
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ This file drives SBC decoding.
|
||||
#include "common/bt_target.h"
|
||||
#include "oi_codec_sbc_private.h"
|
||||
#include "oi_bitstream.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if (defined(SBC_DEC_INCLUDED) && SBC_DEC_INCLUDED == TRUE)
|
||||
|
||||
OI_CHAR *const OI_Codec_Copyright = "Copyright 2002-2007 Open Interface North America, Inc. All rights reserved";
|
||||
const OI_CHAR *const OI_Codec_Copyright = "Copyright 2002-2007 Open Interface North America, Inc. All rights reserved";
|
||||
|
||||
INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
OI_UINT32 *decoderData,
|
||||
@@ -50,12 +50,9 @@ INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||
OI_BOOL enhanced,
|
||||
OI_BOOL msbc_enable)
|
||||
{
|
||||
OI_UINT i;
|
||||
OI_STATUS status;
|
||||
|
||||
for (i = 0; i < sizeof(*context); i++) {
|
||||
((char *)context)[i] = 0;
|
||||
}
|
||||
memset(context, 0, sizeof(*context));
|
||||
|
||||
#ifdef SBC_ENHANCED
|
||||
context->enhancedEnabled = enhanced ? TRUE : FALSE;
|
||||
@@ -126,7 +123,7 @@ INLINE void OI_SBC_ReadHeader(OI_CODEC_SBC_COMMON_CONTEXT *common, const OI_BYTE
|
||||
return;
|
||||
}
|
||||
|
||||
/* Avoid filling out all these strucutures if we already remember the values
|
||||
/* Avoid filling out all these structures if we already remember the values
|
||||
* from last time. Just in case we get a stream corresponding to data[1] ==
|
||||
* 0, DecoderReset is responsible for ensuring the lookup table entries have
|
||||
* already been populated
|
||||
@@ -179,10 +176,10 @@ PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||
common->frameInfo.join = 0;
|
||||
}
|
||||
i /= 2;
|
||||
do {
|
||||
while (i--) {
|
||||
*scale_factor++ = HIGH(f = *b++);
|
||||
*scale_factor++ = LOW(f);
|
||||
} while (--i);
|
||||
}
|
||||
/*
|
||||
* In this case we know that the scale factors end on a byte boundary so all we need to do
|
||||
* is initialize the bitstream.
|
||||
@@ -192,10 +189,10 @@ PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||
OI_ASSERT(common->frameInfo.nrof_subbands == 4 && common->frameInfo.mode == SBC_JOINT_STEREO);
|
||||
common->frameInfo.join = HIGH(f = *b++);
|
||||
i = (i - 1) / 2;
|
||||
do {
|
||||
while(i--) {
|
||||
*scale_factor++ = LOW(f);
|
||||
*scale_factor++ = HIGH(f = *b++);
|
||||
} while (--i);
|
||||
}
|
||||
*scale_factor++ = LOW(f);
|
||||
/*
|
||||
* In 4-subband joint stereo mode, the joint stereo information ends on a half-byte
|
||||
@@ -218,7 +215,7 @@ PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTR
|
||||
OI_UINT bitPtr = global_bs->bitPtr;
|
||||
|
||||
const OI_UINT iter_count = common->frameInfo.nrof_channels * common->frameInfo.nrof_subbands / 4;
|
||||
do {
|
||||
while (nrof_blocks--) {
|
||||
OI_UINT i;
|
||||
for (i = 0; i < iter_count; ++i) {
|
||||
OI_UINT32 sf_by4 = ((OI_UINT32 *)common->scale_factor)[i];
|
||||
@@ -250,7 +247,7 @@ PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTR
|
||||
*s++ = dequant;
|
||||
}
|
||||
}
|
||||
} while (--nrof_blocks);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -386,7 +386,7 @@ OI_UINT8 OI_CODEC_SBC_FrameCount(OI_BYTE *frameData,
|
||||
}
|
||||
|
||||
/* Extract and translate required fields from Header */
|
||||
subbands = mode = blocks = frameData[1];;
|
||||
subbands = mode = blocks = frameData[1];
|
||||
mode = (mode & (BIT3 | BIT2)) >> 2;
|
||||
blocks = block_values[(blocks & (BIT5 | BIT4)) >> 4];
|
||||
subbands = band_values[(subbands & BIT0)];
|
||||
|
||||
@@ -104,10 +104,6 @@
|
||||
#define SBC_DEQUANT_LONG_SCALED_OFFSET 1555931970
|
||||
#endif
|
||||
|
||||
#ifndef SBC_DEQUANT_LONG_UNSCALED_OFFSET
|
||||
#define SBC_DEQUANT_LONG_UNSCALED_OFFSET 2147483648
|
||||
#endif
|
||||
|
||||
#ifndef SBC_DEQUANT_SCALING_FACTOR
|
||||
#define SBC_DEQUANT_SCALING_FACTOR 1.38019122262781f
|
||||
#endif
|
||||
|
||||
@@ -33,13 +33,13 @@
|
||||
|
||||
#if (defined(SBC_DEC_INCLUDED) && SBC_DEC_INCLUDED == TRUE)
|
||||
|
||||
#ifdef OI_DEBUG
|
||||
const OI_CHAR *const OI_CODEC_SBC_FreqText[] = { "SBC_FREQ_16000", "SBC_FREQ_32000", "SBC_FREQ_44100", "SBC_FREQ_48000" };
|
||||
const OI_CHAR *const OI_CODEC_SBC_ModeText[] = { "SBC_MONO", "SBC_DUAL_CHANNEL", "SBC_STEREO", "SBC_JOINT_STEREO" };
|
||||
const OI_CHAR *const OI_CODEC_SBC_SubbandsText[] = { "SBC_SUBBANDS_4", "SBC_SUBBANDS_8" };
|
||||
const OI_CHAR *const OI_CODEC_SBC_BlocksText[] = { "SBC_BLOCKS_4", "SBC_BLOCKS_8", "SBC_BLOCKS_12", "SBC_BLOCKS_16" };
|
||||
const OI_CHAR *const OI_CODEC_SBC_AllocText[] = { "SBC_LOUDNESS", "SBC_SNR" };
|
||||
|
||||
#ifdef OI_DEBUG
|
||||
void OI_CODEC_SBC_DumpConfig(OI_CODEC_SBC_FRAME_INFO *frameInfo)
|
||||
{
|
||||
printf("SBC configuration\n");
|
||||
@@ -48,8 +48,8 @@ void OI_CODEC_SBC_DumpConfig(OI_CODEC_SBC_FRAME_INFO *frameInfo)
|
||||
printf(" subbands: %d\n", frameInfo->nrof_subbands);
|
||||
printf(" blocks: %d\n", frameInfo->nrof_blocks);
|
||||
printf(" channels: %d\n", frameInfo->nrof_channels);
|
||||
printf(" mode: %s\n", OI_CODEC_SBC_ModeText[frameInfo->mode]);
|
||||
printf(" alloc: %s\n", OI_CODEC_SBC_AllocText[frameInfo->alloc]);
|
||||
printf(" mode: %s\n", (frameInfo->mode < 4) ? OI_CODEC_SBC_ModeText[frameInfo->mode] : "INVALID");
|
||||
printf(" alloc: %s\n", (frameInfo->alloc < 2) ? OI_CODEC_SBC_AllocText[frameInfo->alloc] : "INVALID");
|
||||
printf(" bitpool: %d\n", frameInfo->bitpool);
|
||||
}
|
||||
#endif /* OI_DEBUG */
|
||||
|
||||
@@ -39,7 +39,7 @@ version number of the eSBC codec
|
||||
|
||||
#if (defined(SBC_DEC_INCLUDED) && SBC_DEC_INCLUDED == TRUE)
|
||||
/** Version string for the BLUEmagic 3.0 protocol stack and profiles */
|
||||
PRIVATE OI_CHAR *const codecVersion = "v1.5"
|
||||
PRIVATE const OI_CHAR *const codecVersion = "v1.5"
|
||||
#ifdef OI_SBC_EVAL
|
||||
" (Evaluation version)"
|
||||
#endif
|
||||
@@ -47,7 +47,7 @@ PRIVATE OI_CHAR *const codecVersion = "v1.5"
|
||||
|
||||
/** This function returns the version string for the BLUEmagic 3.0 protocol stack
|
||||
and profiles */
|
||||
OI_CHAR *OI_CODEC_Version(void)
|
||||
const OI_CHAR *OI_CODEC_Version(void)
|
||||
{
|
||||
return codecVersion;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
{ \
|
||||
__asm \
|
||||
{ \
|
||||
MUL s32OutLow,(SINT32)s16In2, (s32In1>>15) \
|
||||
MUL s32OutLow,(SINT32)s16In2, (s32In1>>15) \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
@@ -43,8 +43,8 @@
|
||||
#if (SBC_IS_64_MULT_IN_IDCT == TRUE)
|
||||
#define SBC_MULT_32_32(s32In2, s32In1, s32OutLow) \
|
||||
{ \
|
||||
s64Temp = ((SINT64) s32In2) * ((SINT64) s32In1)>>31; \
|
||||
s32OutLow = (SINT32) s64Temp; \
|
||||
s64Temp = ((SINT64) s32In2) * ((SINT64) s32In1)>>31; \
|
||||
s32OutLow = (SINT32) s64Temp; \
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
|
||||
@@ -103,26 +103,26 @@
|
||||
#endif
|
||||
|
||||
/* Set SBC_IPAQ_OPT to TRUE in case the target is an ARM */
|
||||
/* 32 and 64 bit mult will be performed using SINT64 ( usualy __int64 ) cast that usualy give optimal performance if supported */
|
||||
/* 32 and 64 bit mult will be performed using SINT64 ( usually __int64 ) cast that usually give optimal performance if supported */
|
||||
#ifndef SBC_IPAQ_OPT
|
||||
#define SBC_IPAQ_OPT TRUE
|
||||
#endif
|
||||
|
||||
/* Debug only: set SBC_IS_64_MULT_IN_WINDOW_ACCU to TRUE to use 64 bit multiplication in the windowing */
|
||||
/* -> not recomended, more MIPS for the same restitution. */
|
||||
/* -> not recommended, more MIPS for the same restitution. */
|
||||
#ifndef SBC_IS_64_MULT_IN_WINDOW_ACCU
|
||||
#define SBC_IS_64_MULT_IN_WINDOW_ACCU FALSE
|
||||
#endif /*SBC_IS_64_MULT_IN_WINDOW_ACCU */
|
||||
|
||||
/* Set SBC_IS_64_MULT_IN_IDCT to TRUE to use 64 bits multiplication in the DCT of Matrixing */
|
||||
/* -> more MIPS required for a better audio quality. comparasion with the SIG utilities shows a division by 10 of the RMS */
|
||||
/* -> more MIPS required for a better audio quality. comparison with the SIG utilities shows a division by 10 of the RMS */
|
||||
/* CAUTION: It only apply in the if SBC_FAST_DCT is set to TRUE */
|
||||
#ifndef SBC_IS_64_MULT_IN_IDCT
|
||||
#define SBC_IS_64_MULT_IN_IDCT FALSE
|
||||
#endif /*SBC_IS_64_MULT_IN_IDCT */
|
||||
|
||||
/* set SBC_IS_64_MULT_IN_QUANTIZER to TRUE to use 64 bits multiplication in the quantizer */
|
||||
/* setting this flag to FALSE add whistling noise at 5.5 and 11 KHz usualy not perceptible by human's hears. */
|
||||
/* setting this flag to FALSE add whistling noise at 5.5 and 11 KHz usually not perceptible by human's hears. */
|
||||
#ifndef SBC_IS_64_MULT_IN_QUANTIZER
|
||||
#define SBC_IS_64_MULT_IN_QUANTIZER TRUE
|
||||
#endif /*SBC_IS_64_MULT_IN_IDCT */
|
||||
@@ -183,7 +183,7 @@ typedef struct SBC_ENC_PARAMS_TAG {
|
||||
SINT16 as16PcmBuffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
|
||||
#endif
|
||||
|
||||
SINT16 s16ScartchMemForBitAlloc[16];
|
||||
SINT16 s16ScratchMemForBitAlloc[16];
|
||||
|
||||
SINT32 s32SbBuffer[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * SBC_MAX_NUM_OF_BLOCKS];
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
SINT16 *ps16GenTabPtr;
|
||||
SINT32 s32NumOfSubBands = pstrCodecParams->s16NumOfSubBands;
|
||||
|
||||
ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
|
||||
ps16BitNeed = pstrCodecParams->s16ScratchMemForBitAlloc;
|
||||
|
||||
for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++) {
|
||||
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
|
||||
|
||||
@@ -43,11 +43,11 @@ extern const SINT16 sbc_enc_as16Offset8[4][8];
|
||||
|
||||
void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
{
|
||||
/* CAUTIOM -> mips optim for arm 32 require to use SINT32 instead of SINT16 */
|
||||
/* CAUTION -> mips optim for arm 32 require to use SINT32 instead of SINT16 */
|
||||
/* Do not change variable type or name */
|
||||
SINT32 s32MaxBitNeed; /*to store the max bits needed per sb*/
|
||||
SINT32 s32BitCount; /*the used number of bits*/
|
||||
SINT32 s32SliceCount; /*to store hwo many slices can be put in bitpool*/
|
||||
SINT32 s32SliceCount; /*to store how many slices can be put in bitpool*/
|
||||
SINT32 s32BitSlice; /*number of bitslices in bitpool*/
|
||||
SINT32 s32Sb; /*counter for sub-band*/
|
||||
SINT32 s32Ch; /*counter for channel*/
|
||||
@@ -64,7 +64,7 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
ps16BitNeed = pstrCodecParams->as16ScaleFactor;
|
||||
s32MaxBitNeed = pstrCodecParams->s16MaxBitNeed;
|
||||
} else {
|
||||
ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
|
||||
ps16BitNeed = pstrCodecParams->s16ScratchMemForBitAlloc;
|
||||
pas16ScaleFactor = pstrCodecParams->as16ScaleFactor;
|
||||
s32MaxBitNeed = 0;
|
||||
ps16GenBufPtr = ps16BitNeed;
|
||||
|
||||
Reference in New Issue
Block a user