📄 omxacmp3_unpacksideinfo.c
字号:
/** * * File Name: omxACMP3_UnpackSideInfo.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 a 9/17/32 byte sideinfo as specified in * ISO/IEC 13818-3 * */#include "omxtypes.h"#include "armOMX.h"#include "omxAC.h"#include "armAC.h"#include "armCOMM_Bitstream.h"#include "armCOMM.h"/** * Function: omxACMP3_UnpackSideInfo (3.1.3.1.2) * * Description: * Unpacks the side information from the input bit stream. Before * omxACMP3_UnpackSideInfo is called, the pointer *ppBitStream must point to * the first byte of the bit stream that contains the side information * associated with the current frame. Before returning to the caller, the * function updates the pointer *ppBitStream such that it references the next * byte after the side information. References 1. [ISO13818-3], sub-clause * 2.4.1.7 2. [ISO11172-3], sub-clauses 2.4.2.7 and 2.4.3.4.10.3 * * Input Arguments: * * ppBitStream - double pointer to the first byte of the side information * associated with the current frame in the bit stream buffer * pFrameHeader - pointer to the structure that contains the unpacked MP3 * frame header. The header structure provides format information * about the input bit stream. Both single- and dual-channel MPEG-1 * and MPEG-2 modes are supported. * * Output Arguments: * * pDstSideInfo - array of pointers to the MP3 side information * structure(s). The structure(s) contain(s) side information that * applies to all granules and all channels for the current frame. * Depending on the number of channels and granules associated with * the current frame, one or more of the structures are placed * contiguously in the buffer pointed by pDstSideInfo in the * following order: { granule 0 (channel 0, channel 1), granule 1 * (channel 0, channel 1) }. * pDstMainDataBegin - pointer to the main_data_begin field * pDstPrivateBits - pointer to the private bits field * pDstScfsi - pointer to the scalefactor selection information associated * with the current frame, organized contiguously in the buffer * pointed to by pDstScfsi in the following order: {channel 0 * (scfsi_band 0, scfsi_band 1, ..., scfsi_band 3), channel 1 * (scfsi_band 0, scfsi_band 1, ..., scfsi_band 3) }. * ppBitStream - double pointer to the bit stream buffer byte immediately * following the side information for the current frame * * Return Value: * * OMX_Sts_NoErr - no error * OMX_Sts_BadArgErr - bad argument; at least one of the following * pointers is NULL: ppBitStream pDstSideInfo pDstMainDataBegin * pDstPrivateBits pDstScfsi pFrameHeader * - *ppBitStream * OMX_Sts_Err - one or more elements of the MP3 frame header structure is * invalid, i.e., one or more of the following conditions is * true: * - pFrameHeader->id exceeds [0,1]; * - pFrameHeader->layer!=1 * - pFrameHeader->mode exceeds [0,3] * - pDstSideInfo[]->blockType==0 ( normal ) and pDstSideInfo[] >winSwitch==1 ( set ). * */OMXResult omxACMP3_UnpackSideInfo ( const OMX_U8 **ppBitStream, OMXMP3SideInfo *pDstSideInfo, OMX_INT *pDstMainDataBegin, OMX_INT *pDstPrivateBits, OMX_INT *pDstScfsi, OMXMP3FrameHeader *pFrameHeader){ OMX_INT i, j, k, BitIndex, len; OMX_U32 Granule, NumChan; OMX_INT Mpeg1Flag; /* Arguments check */ armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pDstSideInfo == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pDstMainDataBegin == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pDstPrivateBits == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pDstScfsi == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pFrameHeader == NULL, OMX_Sts_BadArgErr) /* Arguments check */ armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr) /* Frame Header Validation */ armRetArgErrIf(pFrameHeader->id < 0, OMX_Sts_Err) armRetArgErrIf(pFrameHeader->id > 1, OMX_Sts_Err) armRetArgErrIf(pFrameHeader->layer != 1, OMX_Sts_Err) armRetArgErrIf(pFrameHeader->mode < 0, OMX_Sts_Err) armRetArgErrIf(pFrameHeader->mode > 3, OMX_Sts_Err) armRetArgErrIf((pFrameHeader->id == 1 && pFrameHeader->idEx == 0), OMX_Sts_Err) /* Initialize bitstream parameters */ BitIndex = 0; /* Check whether stream is MPEG1 or MPEG2 */ if (pFrameHeader->id == 1 && pFrameHeader->idEx == 1) { Mpeg1Flag = 1; } else { Mpeg1Flag = 0; } /* Get main data begin offset from side info */ len = Mpeg1Flag ? ARM_MP3_MAIN_BEGIN_LEN1 : ARM_MP3_MAIN_BEGIN_LEN2; *pDstMainDataBegin = (OMX_INT) armGetBits (ppBitStream, &BitIndex, len); /* Get private bits from side info */ /* Also get number of channels */ if (pFrameHeader->mode == ARM_MP3_SINGLE_CHANNEL_MODE) { NumChan = 1; len = Mpeg1Flag ? ARM_MP3_PRIV_SINGLE_LEN1 : ARM_MP3_PRIV_SINGLE_LEN2; *pDstPrivateBits = (OMX_INT) armGetBits (ppBitStream, &BitIndex, len); } else { NumChan = 2; len = Mpeg1Flag ? ARM_MP3_PRIV_NOTSINGLE_LEN1 : ARM_MP3_PRIV_NOTSINGLE_LEN2; *pDstPrivateBits = (OMX_INT) armGetBits (ppBitStream, &BitIndex, len); } /* Get Scalefactor Selection Info from side info */ if (Mpeg1Flag) { for (j = 0; j < NumChan; j++) { /* For each SCFSI Band */ for (i = 0; i < 4; i++) { pDstScfsi [j * 4 + i] = (OMX_INT) armGetBits (ppBitStream, &BitIndex, 1); } } } /* Fill side info structure for both granule */ Granule = Mpeg1Flag ? 2 : 1; for (j = 0; j < Granule; j++) { for (i = 0; i < NumChan; i++) { pDstSideInfo->part23Len = armGetBits (ppBitStream, &BitIndex, 12); pDstSideInfo->bigVals = armGetBits (ppBitStream, &BitIndex, 9); pDstSideInfo->globGain = armGetBits (ppBitStream, &BitIndex, 8); pDstSideInfo->sfCompress = armGetBits (ppBitStream, &BitIndex, (Mpeg1Flag ? 4 : 9)); pDstSideInfo->winSwitch = armGetBits (ppBitStream, &BitIndex, 1); if (pDstSideInfo->winSwitch) { pDstSideInfo->blockType = armGetBits (ppBitStream, &BitIndex, 2); armRetArgErrIf(pDstSideInfo->blockType == 0, OMX_Sts_Err); pDstSideInfo->mixedBlock = armGetBits (ppBitStream, &BitIndex, 1); /* For each Region */ for (k = 0; k < 2; k++) { pDstSideInfo->pTableSelect [k] = armGetBits (ppBitStream, &BitIndex, 5); } /* For each Window */ for (k = 0; k < 3; k++) { pDstSideInfo->pSubBlkGain [k] = armGetBits (ppBitStream, &BitIndex, 3); } /* Update Fields */ if (pDstSideInfo->blockType == 2 && !pDstSideInfo->mixedBlock) { pDstSideInfo->reg0Cnt = 8; } else { pDstSideInfo->reg0Cnt = 7; } pDstSideInfo->reg1Cnt = 36; } else { /* For each Region */ for (k = 0; k < 3; k++) { pDstSideInfo->pTableSelect [k] = armGetBits (ppBitStream, &BitIndex, 5); } pDstSideInfo->reg0Cnt = armGetBits (ppBitStream, &BitIndex, 4); pDstSideInfo->reg1Cnt = armGetBits (ppBitStream, &BitIndex, 3); /* Update Fields */ pDstSideInfo->blockType = 0; pDstSideInfo->mixedBlock = 0; } if (Mpeg1Flag) { pDstSideInfo->preFlag = armGetBits (ppBitStream, &BitIndex, 1); } pDstSideInfo->sfScale = armGetBits (ppBitStream, &BitIndex, 1); pDstSideInfo->cnt1TabSel = armGetBits (ppBitStream, &BitIndex, 1); /* go to the next Side Info structure */ pDstSideInfo++; } } return OMX_Sts_NoErr;}/***************************************************************************** * END OF FILE *****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -