omxacmp3_unpackscalefactors_s8.c
来自「The OpenMAX DL (Development Layer) APIs 」· C语言 代码 · 共 390 行
C
390 行
/*** * File Name: omxACMP3_UnpackScaleFactors_S8.c* OpenMAX DL: v1.0.2* Revision: 10586* Date: Wednesday, March 5, 2008* * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.* * * Description:* This function is used to unpack scalefactors specified by ISO/IEC 13818-3**/#include "omxtypes.h"#include "armOMX.h"#include "omxAC.h"#include "armCOMM_Bitstream.h"#include "armCOMM.h"/* * Note: Negative scalefactors are saved for potentially illegal is_pos values required in Is stereo */static OMXResult armACMP3_MPEG2_UnpackScaleFactors_S8 ( const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT blockType, OMX_INT mixedBlock, OMX_INT *pPreflag, OMX_S8 *pScaleFactor, OMX_INT sfCompress, OMX_INT modeExt, OMX_INT ch){ OMX_INT BlkTypeNo, BlkNo = 0; OMX_S32 NewSLen[4], ISFCompress; OMX_U32 i, j, k; OMX_S8 scaleFactor; OMX_S8 illegalPos; const OMX_U8 SFBlockNo [6][3][4] = { { {6, 5, 5, 5}, { 9, 9, 9, 9 }, {6, 9, 9, 9} }, { {6, 5, 7, 3}, { 9, 9, 12, 6}, {6, 9, 12, 6} }, { {11, 10, 0, 0}, { 18, 18, 0, 0}, {15,18,0,0 } }, { {7, 7, 7, 0}, { 12, 12, 12, 0}, {6, 15, 12, 0} }, { {6, 6, 6, 3}, {12, 9, 9, 6}, {6, 12, 9, 6} }, { {8, 8, 5, 0}, {15,12,9,0}, {6,18,9,0} } }; BlkTypeNo = 0; if ((blockType == 2) && (mixedBlock == 0)) { BlkTypeNo = 1; } if ((blockType == 2) && (mixedBlock == 1)) { BlkTypeNo = 2; } if (!((( modeExt == 1) || (modeExt == 3)) && (ch == 1))) { if (sfCompress < 400) { NewSLen[0] = (sfCompress >> 4) / 5 ; NewSLen[1] = (sfCompress >> 4) % 5 ; NewSLen[2] = (sfCompress % 16) >> 2 ; NewSLen[3] = (sfCompress % 4); *pPreflag = 0; BlkNo = 0; } else if( sfCompress < 500) { NewSLen[0] = ((sfCompress - 400 ) >> 2) / 5 ; NewSLen[1] = ((sfCompress - 400) >> 2) % 5 ; NewSLen[2] = (sfCompress - 400 ) % 4 ; NewSLen[3] = 0; *pPreflag = 0; BlkNo = 1; } else if( sfCompress < 512) { NewSLen[0] = (sfCompress - 500 ) / 3 ; NewSLen[1] = (sfCompress - 500) % 3 ; NewSLen[2] = 0 ; NewSLen[3] = 0; *pPreflag = 1; BlkNo = 2; } } if((((modeExt == 1) || (modeExt == 3)) && (ch == 1))) { /* intensity scale = sfCompress %2; */ ISFCompress = sfCompress >> 1; if(ISFCompress < 180) { NewSLen[0] = ISFCompress / 36 ; NewSLen[1] = (ISFCompress % 36 ) / 6 ; NewSLen[2] = (ISFCompress % 36) % 6; NewSLen[3] = 0; *pPreflag = 0; BlkNo = 3; } else if( ISFCompress < 244) { NewSLen[0] = ((ISFCompress - 180 ) % 64 ) >> 4 ; NewSLen[1] = ((ISFCompress - 180) % 16) >> 2 ; NewSLen[2] = (ISFCompress - 180 ) % 4 ; NewSLen[3] = 0; *pPreflag = 0; BlkNo = 4; } else if( ISFCompress < 255) { NewSLen[0] = (ISFCompress - 244 ) / 3 ; NewSLen[1] = (ISFCompress - 244 ) % 3 ; NewSLen[2] = 0 ; NewSLen[3] = 0; *pPreflag = 0; BlkNo = 5; } } k = 0; for(i = 0; i < 4; i++) { illegalPos = (1 << NewSLen[i]) -1; for(j = 0; j < SFBlockNo[BlkNo][BlkTypeNo][i]; j++) { if(NewSLen[i] == 0) { *pScaleFactor++ = 0; } else { scaleFactor = armGetBits (ppBitStream, pOffset, NewSLen[i]); if (scaleFactor== illegalPos) scaleFactor = -scaleFactor; *pScaleFactor++ = scaleFactor; } k++; } } return OMX_Sts_NoErr;}/** * Function: omxACMP3_UnpackScaleFactors_S8 (3.1.3.1.3) * * Description: * Unpacks short and/or long block scalefactors for one granule of one * channel and places the results in the vector pDstScaleFactor. Special * scalefactor values on the right channel of intensity-coded scalefactor * bands are returned to indicate illegal intensity positions. Before * returning to the caller, the function updates *ppBitStream and *pOffset * such that they point to the next available bit in the input bit stream. * Reference [ISO13818-3], sub-clause 2.4.1.7 * * Input Arguments: * * ppBitStream - double pointer to the first bit stream buffer byte that is * associated with the scalefactors for the current frame, granule, * and channel * pOffset - pointer to the next bit in the byte referenced by * *ppBitStream. Valid within the range of 0 to 7, where 0 * corresponds to the most significant bit and 7 corresponds to the * least significant bit. * pSideInfo - pointer to the MP3 side information structure associated * with the current granule and channel * pScfsi - pointer to scalefactor selection information for the current * channel * channel - channel index; can take on the values of either 0 or 1 * granule - granule index; can take on the values of either 0 or 1 * pFrameHeader - pointer to MP3 frame header structure for the current * frame * * Output Arguments: * * pDstScaleFactor - pointer to the scalefactor vector for long and/or * short blocks. Special scalefactor values on the right channel * of intensity-coded scalefactor bands shall be used to indicate * illegal intensity positions as follows: * i) for MPEG-1 streams (pFrameHeader->id==1), the value 7 [ISO11172-3, section 2.4.3.4.9.3], and ii) for MPEG-2 streams (pFrameHeader->id==0), * a negative value. * ppBitStream - updated double pointer to the next bit stream byte * pOffset - updated pointer to the next bit in the bit stream (indexes the * bits of the byte pointed to by *ppBitStream). Valid within the * range of 0 to 7, where 0 corresponds to the most significant bit * and 7 corresponds to the least significant bit. * * Return Value: * * OMX_Sts_NoErr - no error * OMX_Sts_BadArgErr - Bad arguments; one or more of the following * pointers is NULL: * - *ppBitStream pOffset pDstScaleFactor pSideInfo, pScfsi ppBitStream * pFrameHeader Bad arguments are also flagged when the value of * *pOffset exceeds [0,7] or the granule or channel indices have * values other than 0 or 1. * OMX_Sts_Err - input data errors detected; one or more of the following * are true: * - pFrameHeader ->id exceeds [0,1], * - pSideInfo->blockType exceeds [0,3], * - pSideInfo->mixedBlock exceeds [0,1] when * pFrameHeader->id==1, pSideInfo->blockType==2, * and pSideInfo->winSwitch==1. * - pScfsi[0..3] exceeds [0,1] when pFrameHeader->id==1 and * either pSideInfo->blockType!=2 or pSideInfo->winSwitch!=1. * - pFrameHeader->id indicates that the bit stream is MPEG-1 and * pSideInfo->sfCompress exceeds [0,15] * - pFrameHeader->id indicates the bit stream is MPEG-2 and * pSideInfo->sfCompress exceeds [0,511] * - pFrameHeader->modeExt exceeds [0, 3] * */OMXResult omxACMP3_UnpackScaleFactors_S8 ( const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_S8 *pDstScaleFactor, OMXMP3SideInfo *pSideInfo, OMX_INT *pScfsi, OMXMP3FrameHeader *pFrameHeader, OMX_INT granule, OMX_INT channel ){ OMX_INT sfb, win, Band, Scfsi; OMX_S8 scaleFactor; const OMX_U8 LongSfbLength [] = {0, 6, 11, 16, 21}; OMX_S8 *pScaleFactor = pDstScaleFactor; /*const OMX_U8 ShortSfbLength [] = {0, 6, 12};*/ const OMX_U8 SLen [2][16] = {{0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4}, {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}}; /* Arguments check */ armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pOffset == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pDstScaleFactor == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pSideInfo == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pScfsi == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pFrameHeader == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(*pOffset < 0, OMX_Sts_BadArgErr) armRetArgErrIf(*pOffset > 7, OMX_Sts_BadArgErr) armRetArgErrIf(granule < 0, OMX_Sts_BadArgErr) armRetArgErrIf(granule > 1, OMX_Sts_BadArgErr) armRetArgErrIf(channel < 0, OMX_Sts_BadArgErr) armRetArgErrIf(channel > 1, OMX_Sts_BadArgErr) /* Validate ID */ armRetArgErrIf(pFrameHeader->id < 0, OMX_Sts_Err) armRetArgErrIf(pFrameHeader->id > 1, OMX_Sts_Err) /* Validate Mode Ext */ armRetArgErrIf(pFrameHeader->modeExt < 0, OMX_Sts_Err) armRetArgErrIf(pFrameHeader->modeExt > 3, OMX_Sts_Err) /* Validate Block Type */ armRetArgErrIf(pSideInfo->blockType < 0, OMX_Sts_Err) armRetArgErrIf(pSideInfo->blockType > 3, OMX_Sts_Err) sfb = 0; if (pFrameHeader->id == 1) { /* MPEG1 */ /* Validate Scale Factor Compress */ armRetArgErrIf(pSideInfo->sfCompress < 0, OMX_Sts_Err) armRetArgErrIf(pSideInfo->sfCompress > 15, OMX_Sts_Err) /* Get Scalefactors */ if ((pSideInfo->winSwitch == 1) && (pSideInfo->blockType == 2)) { /* Validate Mixed Block Flag */ armRetArgErrIf(pSideInfo->mixedBlock < 0, OMX_Sts_Err) armRetArgErrIf(pSideInfo->mixedBlock > 1, OMX_Sts_Err) if (pSideInfo->mixedBlock) { /* Short & Long */ for (sfb = 0; sfb < 8; sfb++) { scaleFactor = armGetBits (ppBitStream, pOffset, SLen [0] [pSideInfo->sfCompress]); *pScaleFactor++ = scaleFactor; } for (sfb = 3; sfb < 12; sfb++) { for (win = 0; win < 3; win++) { scaleFactor = armGetBits (ppBitStream, pOffset, SLen [(sfb < 6)? 0 : 1] [pSideInfo->sfCompress]); *pScaleFactor++ = scaleFactor; } } } else { /* Only Short */ for (sfb = 0; sfb < 12; sfb++) { for (win = 0; win < 3; win++) { scaleFactor = armGetBits (ppBitStream, pOffset, SLen [(sfb < 6)? 0 : 1] [pSideInfo->sfCompress]); *pScaleFactor++ = scaleFactor; } } } } else { /* Only Long */ for (Band = 0; Band < 4; Band++) { Scfsi = pScfsi [Band]; armRetDataErrIf(Scfsi < 0 || Scfsi > 1, OMX_Sts_Err); /* Validate Mixed Block Flag */ if ((Scfsi == 0) || (granule == 0)) { for (sfb = LongSfbLength [Band]; sfb < LongSfbLength [Band + 1]; sfb++) { scaleFactor = armGetBits (ppBitStream, pOffset, SLen [(Band >> 1)] [pSideInfo->sfCompress]); pScaleFactor [sfb] = scaleFactor; } } } pScaleFactor [sfb] = 0; } } else { /* MPEG2 */ /* Validate Scale Factor Compress */ armRetArgErrIf(pSideInfo->sfCompress < 0, OMX_Sts_Err) armRetArgErrIf(pSideInfo->sfCompress > 511, OMX_Sts_Err) armACMP3_MPEG2_UnpackScaleFactors_S8 ( ppBitStream, pOffset, pSideInfo->blockType, pSideInfo->mixedBlock, &(pSideInfo->preFlag), pScaleFactor, pSideInfo->sfCompress, pFrameHeader->modeExt, channel); } return OMX_Sts_NoErr;}/****************************************************************************** END OF FILE*****************************************************************************/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?