📄 mbheaddec.c
字号:
/*************************************************************************This software module was originally developed by Wei-ge Chen (wchen@microsoft.com), Microsoft Corporation Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation Simon Winder (swinder@microsoft.com), Microsoft Corporation (date: July, 1997)and edited by Yoshihiro Kikuchi (TOSHIBA CORPORATION) Takeshi Nagai (TOSHIBA CORPORATION) Toshiaki Watanabe (TOSHIBA CORPORATION) Noboru Yamaguchi (TOSHIBA CORPORATION)and also edited by Dick van Smirren (D.vanSmirren@research.kpn.com), KPN Research Cor Quist (C.P.Quist@research.kpn.com), KPN Research (date: July, 1998)and also edited by Yoshinori Suzuki (Hitachi, Ltd.)and also edited by Hideaki Kimata (NTT)in the course of development of the MPEG-4 Video (ISO/IEC 14496-2). This software module is an implementation of a part of one or more MPEG-4 Video tools as specified by the MPEG-4 Video. ISO/IEC gives users of the MPEG-4 Video free license to this software module or modifications thereof for use in hardware or software products claiming conformance to the MPEG-4 Video. Those intending to use this software module in hardware or software products are advised that its use may infringe existing patents. The original developer of this software module and his/her company, the subsequent editors and their companies, and ISO/IEC have no liability for use of this software module or modifications thereof in an implementation. Copyright is not released for non MPEG-4 Video conforming products. Microsoft retains full right to use the code for his/her own purpose, assign or donate the code to a third party and to inhibit third parties from using the code for non <MPEG standard> conforming products. This copyright notice must be included in all copies or derivative works. Copyright (c) 1996, 1997.Module Name: MBHeadDec.cppAbstract: MacroBlock overhead decoderRevision History: This software module was edited by Hiroyuki Katata (katata@imgsl.mkhar.sharp.co.jp), Sharp Corporation Norio Ito (norio@imgsl.mkhar.sharp.co.jp), Sharp Corporation Shuichi Watanabe (watanabe@imgsl.mkhar.sharp.co.jp), Sharp Corporation (date: October, 1997) for object based temporal scalability. Dec 20, 1997: Interlaced tools added by NextLevel Systems (GI) X. Chen (xchen@nlvl.com), B. Eifrig (beifrig@nlvl.com) Feb. 24, 1999: GMC added by Y. Suzuki (Hitachi, Ltd.) Mar.13 2000 : MB stuffing decoding added by Hideaki Kimata (NTT) May.25 2000 : MB stuffing decoding on the last MB by Hideaki Kimata (NTT)*************************************************************************/#include "typeapi.h"#include "codehead.h"#include "mode.h"#include "global.h"#ifdef UNDER_CE#include "bitstrm.h"#include "huffman.h"#else#include "entropy/bitstrm.h"#include "entropy/huffman.h"#endif#include "vopses.h"#include "vopsedec.h"//#define USE_BSFAST// Moved from vopses.cppVoid setDCVLCMode(CMBMode* pmbmd, Bool *pbBoundary){ if(pmbmd->m_dctMd == INTRA || pmbmd->m_dctMd == INTRAQ || !pmbmd->m_bSkip) { Int iQP; if(*pbBoundary) { *pbBoundary = FALSE; iQP = pmbmd->m_stepSize; // current qp } else iQP = pmbmd->m_stepSize - pmbmd->m_intStepDelta; // previous qp if (g_pVOP->iIntraDcSwitchThr != 0) { if (g_pVOP->iIntraDcSwitchThr == 7) pmbmd->m_bCodeDcAsAc = TRUE; else if (iQP >= (2 * g_pVOP->iIntraDcSwitchThr + 11)) pmbmd->m_bCodeDcAsAc = TRUE; else pmbmd->m_bCodeDcAsAc = FALSE; } else pmbmd->m_bCodeDcAsAc = FALSE; }}INLINE Void decodeMBTextureHeadOfIVOP (CMBMode* pmbmd, Int *iCurrentQP, Bool *pbRestart){ Int iBlk = 0, iCBPC = 0, iCBPY = 0, iMCBPC = 8; #ifdef USE_BSFAST _BSFAST_DECL; UInt bitsread; _BSFAST_INIT();#endif while (iMCBPC == 8) {#ifdef USE_BSFAST iMCBPC = decodeSymbol_WithFastBS (m_pentrdecMCBPCintra,_BSFastCurrentBits(), &bitsread); _BSFastSkipBits(bitsread); _BSFastCheckedPreload();#else iMCBPC = decodeSymbol (m_pentrdecMCBPCintra);#endif // USE_BSFAST }#ifndef NO_ASSERTS assert (iMCBPC >= 0 && iMCBPC <= 8);#endif pmbmd->m_dctMd = INTRA; pmbmd->m_bSkip = FALSE; //reset for direct mode pmbmd->m_bMCSEL = FALSE; //reset for direct mode pmbmd->m_bFieldMV = 0; pmbmd->m_intStepDelta = 0; if (iMCBPC > 3) pmbmd->m_dctMd = INTRAQ; iCBPC = iMCBPC % 4; if (!main_short_video_header) {#ifdef USE_BSFAST pmbmd->m_bACPrediction = _BSFastGetBits(1);#else MP4V_RETSINGLEBIT(&pmbmd->m_bACPrediction);#endif }#ifdef USE_BSFAST iCBPY = decodeSymbol_WithFastBS (m_pentrdecCBPY,_BSFastCurrentBits(), &bitsread); _BSFastSkipBits(bitsread); _BSFastCheckedPreload();#else iCBPY = decodeSymbol (m_pentrdecCBPY);#endif // USE_BSFAST SETCBPYANDC (pmbmd, iCBPC, iCBPY); if (pmbmd->m_dctMd == INTRAQ) { Int iQuantMax; Int iDQUANT;#ifdef USE_BSFAST iDQUANT = _BSFastGetBits(2);#else iDQUANT = getBits (2);#endif switch (iDQUANT) { case 0: pmbmd->m_intStepDelta = -1; break; case 1: pmbmd->m_intStepDelta = -2; break; case 2: pmbmd->m_intStepDelta = 1; break; case 3: pmbmd->m_intStepDelta = 2; break;#ifndef NO_ASSERTS default: assert (FALSE);#endif } (*iCurrentQP) += pmbmd->m_intStepDelta; iQuantMax = (1<<g_pVOL->uiQuantPrecision) - 1; CHECKRANGE ((*iCurrentQP), 1, iQuantMax); }#ifdef USE_BSFAST _BSFAST_DONE();#endif pmbmd->m_stepSize = (*iCurrentQP);#ifdef ENABLE_INTERLACING if (g_pVOP->bInterlace) pmbmd->m_bFieldDCT = getSingleBit (); // get dct_type#endif setDCVLCMode(pmbmd, pbRestart);}// InterINLINE Void decodeMBTextureHeadOfPVOP (CMBMode* pmbmd, Int *iCurrentQP, Bool *pbRestart){ Int iBlk = 0, iCBPC = 0, iCBPY = 0, iMCBPC;#ifdef USE_BSFAST _BSFAST_DECL; UInt bitsread; _BSFAST_INIT();#endif do { if (MP4V_EOF()) return;#ifdef USE_BSFAST pmbmd->m_bSkip = _BSFastGetBits(1);#else MP4V_RETSINGLEBIT(&pmbmd->m_bSkip);#endif if (!pmbmd->m_bSkip) {#ifdef USE_BSFAST iMCBPC = decodeSymbol_WithFastBS (m_pentrdecMCBPCinter,_BSFastCurrentBits(), &bitsread); _BSFastSkipBits(bitsread); _BSFastCheckedPreload();#else iMCBPC = decodeSymbol (m_pentrdecMCBPCinter);#endif // USE_BSFAST#ifndef NO_ASSERTS assert (iMCBPC >= 0 && iMCBPC <= 20); #endif } } while((!pmbmd->m_bSkip) && (iMCBPC == 20)); if (!pmbmd->m_bSkip) { Int iMBtype = iMCBPC / 4; //per H.263's MBtype pmbmd -> m_bFieldMV = FALSE; switch (iMBtype) { case 0: pmbmd->m_dctMd = INTER; pmbmd -> m_bhas4MVForward = FALSE; break; case 1: pmbmd->m_dctMd = INTERQ; pmbmd -> m_bhas4MVForward = FALSE; break; case 2: pmbmd -> m_dctMd = INTER; pmbmd -> m_bhas4MVForward = TRUE; break; case 3: pmbmd->m_dctMd = INTRA; break; case 4: pmbmd->m_dctMd = INTRAQ; break;#ifndef NO_ASSERTS default: assert (FALSE);#endif } iCBPC = iMCBPC % 4;// GMC pmbmd->m_bMCSEL = FALSE;#ifdef ENABLE_SPRITE if((pmbmd->m_dctMd == INTER || pmbmd->m_dctMd == INTERQ) && (pmbmd -> m_bhas4MVForward == FALSE) && (g_pVOP->vopPredType == SPRITE)) {#ifdef USE_BSFAST pmbmd->m_bMCSEL = _BSFastGetBits(1);#else MP4V_RETSINGLEBIT (&pmbmd->m_bMCSEL);#endif }#endif// ~GMC if (pmbmd->m_dctMd == INTRA || pmbmd->m_dctMd == INTRAQ) { if (!main_short_video_header) {#ifdef USE_BSFAST pmbmd->m_bACPrediction = _BSFastGetBits(1);#else MP4V_RETSINGLEBIT(&pmbmd->m_bACPrediction);#endif }#ifdef USE_BSFAST iCBPY = decodeSymbol_WithFastBS (m_pentrdecCBPY,_BSFastCurrentBits(), &bitsread);#else iCBPY = decodeSymbol (m_pentrdecCBPY);#endif // USE_BSFAST } else {#ifdef USE_BSFAST iCBPY = 15 - decodeSymbol_WithFastBS (m_pentrdecCBPY,_BSFastCurrentBits(), &bitsread);#else iCBPY = 15 - decodeSymbol (m_pentrdecCBPY);#endif // USE_BSFAST }#ifdef USE_BSFAST _BSFastSkipBits(bitsread); _BSFastCheckedPreload();#endif#ifndef NO_ASSERTS assert (iCBPY >= 0 && iCBPY <= 15); #endif } else { //skipped pmbmd->m_dctMd = INTER; pmbmd -> m_bhas4MVForward = FALSE; pmbmd -> m_bFieldMV = FALSE;// GMC pmbmd -> m_bMCSEL = FALSE;#ifdef ENABLE_SPRITE// if(g_pVO->m_uiSprite == 2 && g_pVOP->vopPredType == SPRITE) if(g_pVOP->vopPredType == SPRITE) pmbmd -> m_bMCSEL = TRUE;#endif// ~GMC } SETCBPYANDC (pmbmd, iCBPC, iCBPY); pmbmd->m_intStepDelta = 0; if (pmbmd->m_dctMd == INTERQ || pmbmd->m_dctMd == INTRAQ) { Int iQuantMax; Int iDQUANT;#ifndef NO_ASSERTS assert (!pmbmd->m_bSkip);#endif#ifdef USE_BSFAST iDQUANT = _BSFastGetBits (2);#else iDQUANT = getBits (2);#endif switch (iDQUANT)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -