📄 vopmbdec.c
字号:
/************************************************************************* This software module was originally developed by Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation Wei-ge Chen (wchen@microsoft.com), Microsoft Corporation Bruce Lin (blin@microsoft.com), Microsoft Corporation Chuang Gu (chuanggu@microsoft.com), Microsoft Corporation Simon Winder (swinder@microsoft.com), Microsoft Corporation (date: March, 1996) and edited by Yoshihiro Kikuchi (TOSHIBA CORPORATION) Takeshi Nagai (TOSHIBA CORPORATION) Toshiaki Watanabe (TOSHIBA CORPORATION) Noboru Yamaguchi (TOSHIBA CORPORATION) and also edited by David B. Shu (dbshu@hrl.com), Hughes Electronics/HRL Laboratories and edited by Xuemin Chen (xchen@gi.com), General Instrument Corp. 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) and also edited by Fujitsu Laboratories Ltd. (contact: Eishi Morimatsu) and also edited by Takefumi Nagumo (nagumo@av.crl.sony.co.jp) Sony Corporation Sehoon Son (shson@unitel.co.kr) Samsung AIT 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: vopmbdec.c Abstract: Decoder for VOP composed of MB's Revision History: Nov. 26 , 1997: modified for error resilient by Toshiba Nov. 30 , 1997: modified for Spatial Scalable by Takefumi Nagumo (nagumo@av.crl.sony.co.jp) SONY Corporation Dec 20, 1997: Interlaced tools added by GI X. Chen (xchen@gi.com), B. Eifrig (beifrig@gi.com) May. 9 1998: add boundary by Hyundai Electronics Cheol-Soo Park (cspark@super5.hyundai.co.kr) May. 9 1998: add field based MC padding by Hyundai Electronics Cheol-Soo Park (cspark@super5.hyundai.co.kr) Feb.24 1999: GMC added by Y. Suzuki (Hitachi, Ltd.) Aug.24, 1999 : NEWPRED added by Hideaki Kimata (NTT) Sep.06 1999 : RRV added by Eishi Morimatsu (Fujitsu Laboratories Ltd.) Feb.01 2000 : Bug fixed OBSS by Takefumi Nagumo (SONY) May.25 2000 : MB stuffing decoding on the last MB by Hideaki Kimata (NTT) *************************************************************************/#include <stdio.h>#include <math.h>#include <stdlib.h>#include "typeapi.h"#include "mode.h"#include "codehead.h"#ifdef UNDER_CE#include "bitstrm.h"#include "huffman.h"#else#include "entropy/bitstrm.h"#include "entropy/huffman.h"#endif#include "global.h"#include "vopses.h"#include "vopsedec.h"#include "mae_pass_thru.h"#include "mae_fe_mcomp.h"#include <mae_interface.h>INLINE Void motionCompMB (CMotionVector*, CMBMode*);INLINE Int checkStartCode();INLINE Void decodeVideoPacketHeader(Int*);Bool checkGOBMarker();#ifdef UNDER_CE //WinCE compiler doesn't let INLINE functions be called from a different c fileVoid decodeIVOP ();Void decodePVOP ();Void decodeBVOP ();#elseINLINE Void decodeIVOP ();INLINE Void decodePVOP ();INLINE Void decodeBVOP ();#endif#ifdef INLINE_MV_CLIPPINGint MULTIPLY_BY = 16;int LIMIT_FOR_16x16 = -32;int LIMIT_FOR_8x8 = -16;int SHIFT_BY = 1;int iPicWidth_1, iPicHeight_1, iPicWidth_2, iPicHeight_2, iPicWidth_3, iPicHeight_3;int iPicWidthUV_1, iPicHeightUV_1, iPicWidthUV_2, iPicHeightUV_2;int xpos2, ypos2, xposuv_2, yposuv_2, lumaAdjustment;int LumaAdjX1[8] = {0, 16, 0, 16, 0, 16, 0, 16};int LumaAdjY1[8] = {0, 0, 16, 16, 0, 0, 16, 16};int LumaAdjX2[8] = {0, 8, 0, 8, 0, 8, 0, 8};int LumaAdjY2[8] = {0, 0, 8, 8, 0, 0, 8, 8};int LumaAdjX3[8] = {-16, 0, -16, 0, -16, 0, -16, 0};int LumaAdjY3[8] = {-16, -16, 0, 0, -16, -16, 0, 0};int LumaAdjX4[8], LumaAdjY4[8];#define MP4V_CLIP_LUMA_16x16_X()\{\ if ((xpos2 + MVX) < LIMIT_FOR_16x16)\ MVX = LIMIT_FOR_16x16 - xpos2;\\ else if (((xpos2 + MVX)>>SHIFT_BY) > iPicWidth_1)\ MVX = iPicWidth_2 - xpos2;\}#define MP4V_CLIP_LUMA_16x16_Y()\{\ if ((ypos2 + MVY) < LIMIT_FOR_16x16)\ MVY = LIMIT_FOR_16x16 - ypos2;\\ else if (((ypos2 + MVY)>>SHIFT_BY) > iPicHeight_1)\ MVY = iPicHeight_2 - ypos2;\}#define MP4V_CLIP_LUMA_8x8_X()\{\ if (((xpos2 + MVX) + LumaAdjX1[iBlk]) < LIMIT_FOR_8x8)\ MVX = LumaAdjX3[iBlk] - xpos2;\ else \ {\ if ((((xpos2 + MVX) >> SHIFT_BY) + LumaAdjX2[iBlk]) > iPicWidth_1)\ MVX = LumaAdjX4[iBlk] - xpos2;\ }\}#define MP4V_CLIP_LUMA_8x8_Y()\{\ if (((ypos2 + MVY) + LumaAdjY1[iBlk]) < LIMIT_FOR_8x8)\ MVY = LumaAdjY3[iBlk] - ypos2;\ else\ {\ if ((((ypos2 + MVY) >> SHIFT_BY) + LumaAdjY2[iBlk]) > iPicHeight_1)\ MVY = LumaAdjY4[iBlk] - ypos2;\ }\}#define MP4V_CLIP_CHROMA_X()\{\ if ((xposuv_2 + xRefUV) < -16)\ xRefUV = -16 - xposuv_2;\\ else if (((xposuv_2 + xRefUV)>>1) > iPicWidthUV_1)\ xRefUV = iPicWidthUV_2 - xposuv_2;\}#define MP4V_CLIP_CHROMA_Y()\{\ if ((yposuv_2 + yRefUV) < -16)\ yRefUV = -16 - yposuv_2;\\ else if ( ((yposuv_2 + yRefUV)>>1) > iPicHeightUV_1)\ yRefUV = iPicHeightUV_2 - yposuv_2;\}#endif#ifdef MP4V_DEBUGint g_nGlobMB = 0;#endif#ifdef ENABLE_INTERLACINGint nDoPadding = 0;int nNumMBs;// Frame buffers for unsaturated data for wmv9 loopfiltextern "C" int16 *cur_y_unsat;extern "C" int16 *cur_cr_unsat;extern "C" int16 *cur_cb_unsat;#endifCRct m_rctRefVOPY0, m_rctRefVOPUV0;CRct m_rctRefVOPY1, m_rctRefVOPUV1;Bool bResyncMark;int MVX, MVY, iBlk;CMotionVector* pmv8;CoordI xRefUV, yRefUV;#ifdef USE_INTERPOLATED_PTS int g_tempPTS = 0, g_PTSInterval = 0;#endif// Moved from errdec.cpp#define MP4V_CHECKRESYNCMARKER(bRet)\{\ Int nBitsPeeked;\ Int iStuffedBits;\ Int nBitsResyncMarker;\ VOPpredType vopPredType;\ *bRet = FALSE;\ if(main_short_video_header)\ return;\\ iStuffedBits = peekBitsTillByteAlign (&nBitsPeeked);\ nBitsResyncMarker = NUMBITS_VP_RESYNC_MARKER;\ vopPredType = g_pVOP->vopPredType;\\ if(g_pVOL->bShapeOnly==FALSE)\ {\ if(vopPredType == PVOP)\ nBitsResyncMarker += (g_pVOP->mvInfoForward.uiFCode - 1);\ else if(vopPredType == BVOP)\ nBitsResyncMarker += max(g_pVOP->mvInfoForward.uiFCode, g_pVOP->mvInfoBackward.uiFCode) - 1;\ }\ /*assert (nBitsPeeked > 0 && nBitsPeeked <= 8);*/\ if (iStuffedBits == ((1 << (nBitsPeeked - 1)) - 1))\ *bRet = (peekBitsFromByteAlign (nBitsResyncMarker) == RESYNC_MARKER);\}#ifdef NEW_MAE_DRIVER#define MP4V_FILLFRAMEPARAMETERS(nFrameType)\{\ pMAEContext->stream_type = ((g_pVOL->fQuantizer == Q_H263) ? MAE_STREAM_TYPE_H263 : MAE_STREAM_TYPE_MPEG4);\ pMAEContext->frametype[0] = nFrameType;\ pMAEContext->encoded_picture_linesize = iPicWidth;\ pMAEContext->encoded_picture_height = iPicHeight;\ pMAEContext->chopped_picture_height = iChoppedHeight;\ pMAEContext->dummysubmit = 0;\}#else#define MP4V_FILLMAEREGISTERS(nFrameType, bInterlaceMode)\{\ pMAERegs->regmask = 0;\\ pMAERegs->regmask |= PICTURE_SIZE_MASK;\\ pMAERegs->regmask |= CUR_Y_MASK;\ pMAERegs->regmask |= CUR_CB_MASK;\ pMAERegs->regmask |= CUR_CR_MASK;\\ if (nFrameType == PFRAME || nFrameType == BFRAME)\ {\ pMAERegs->regmask |= FWD_Y_TOP_MASK;\ pMAERegs->regmask |= FWD_CB_TOP_MASK;\ pMAERegs->regmask |= FWD_CR_TOP_MASK;\\ }\\ if (nFrameType == BFRAME)\ {\ pMAERegs->regmask |= BWD_Y_TOP_MASK;\ pMAERegs->regmask |= BWD_CB_TOP_MASK;\ pMAERegs->regmask |= BWD_CR_TOP_MASK;\ }\\ pMAERegs->regmask |= CONFIG0_MASK;\ WrapSetRegisters (pMAERegs, 0); \}#endif// When there are B-Frames, its hard to determine the consecutive number of// B-VOPs. So, lets just pass down the time stamp for that frame as the TNum.// As long as its ordered properly, it should work fine (need not be a zero-// indexed number)#define USE_SIMPLIFIED_TNUM_SCHEME#ifdef USE_SIMPLIFIED_TNUM_SCHEME#define MP4V_COMPUTETEMPORALNUMBER(nDispNum, nFrameType)\{\ if (g_iClipType == CLIP_XVID)\ *nDispNum = g_iTNum;\ else\ {\ if (!m_iNumBFrames)\ {\ *nDispNum = m_iTemporalNumber;\ m_iTemporalNumber++;\ }\ else\ {\ *nDispNum = g_pVO->m_t;\ }\ }\ pMAEContext->pts = g_nMP4VPTS;\} // For XviD//*nDispNum = g_pVO->m_t/g_iVOPIncFactor;//pMAEContext->pts = (g_pVO->m_t/g_iVOPIncFactor) * 41;#else#define MP4V_COMPUTETEMPORALNUMBER(nDispNum, nFrameType)\{\ if (!m_iNumBFrames || !m_iTemporalNumber || nFrameType == BFRAME)\ *nDispNum = m_iTemporalNumber;\\ else\ {\ (m_iTemporalNumber == 1) ? m_iTemporalNumber-- : m_iTemporalNumber;\ *nDispNum = (m_iTemporalNumber + m_iNumBFrames + 1);\ }\\ m_iTemporalNumber++;\}#endif#ifdef UNDER_CE Void decodeIVOP () #elseINLINE Void decodeIVOP () #endif{ Int macrotellertje=0; // [FDS] Int iMBX, iMBY, iMBTop; Int iMBXstart, iMBXstop, iMBYstart, iMBYstop; // Added by KPN for short headers UInt uiNumberOfGobs; // Added by KPN UInt uiGobNumber; // Added by KPN Int iCurrentQP, iQP, iQpPred; Int iDcScaler, iDcScalerY, iDcScalerC; Int iVideoPacketNumber; Bool bRestartDelayedQP; CMBMode* pmbmd = g_pVO->m_rgmbmd; MacroBlockMemory** ppmbmTemp; MacroBlockMemory* pmbmLeft = NULL; MacroBlockMemory* pmbmTop = NULL; MacroBlockMemory* pmbmLeftTop = NULL; CMBMode* pmbmdLeft = NULL; CMBMode* pmbmdTop = NULL; CMBMode* pmbmdLeftTop = NULL; BlockMemory blkmPred; pmbmd->m_stepSize = g_pVOP->intStepI; g_NumMVs = 0; // Get the current YUV buffer(s) from the driver#ifndef NEW_MAE_DRIVER pMAERegs->cur_y_frame_ptr = get_cur_buffer(); pMAERegs->cur_cb_frame_ptr = pMAERegs->cur_y_frame_ptr + m_iSizeYPlane; pMAERegs->cur_cr_frame_ptr = pMAERegs->cur_cb_frame_ptr + m_iSizeUVPlane; m_pMAERef1Y = (PixelC*) pMAERegs->cur_y_frame_ptr; #endif pmbmd->m_bFieldDCT = 0; iCurrentQP = g_pVOP->intStepI; iVideoPacketNumber = 0; // added for error resilience mode by Toshiba g_pVO->m_iVPMBnum = 0; // Added for error resilient mode by Toshiba(1997-11-14) if (!main_short_video_header) { uiNumberOfGobs = 1; iMBXstart=0; iMBXstop= g_pVO->m_iNumMBX; iMBYstart=0; iMBYstop= g_pVO->m_iNumMBY; } else // short_header { uiNumberOfGobs = g_pDecoder->uiNumGobsInVop; iMBXstart=0; iMBXstop= 0; iMBYstart=0; iMBYstop= 0; } bRestartDelayedQP = TRUE; // decodeMBTextureHeadOfIVOP sets this to false uiGobNumber=0; while (uiGobNumber < uiNumberOfGobs) { if (!main_short_video_header) uiGobNumber++; else { g_pDecoder->uiGobHeaderEmpty=1; if (uiGobNumber != 0) { SKIPANYSTUFFING(); if (checkGOBMarker()) { UInt uiGobResyncMarker; g_pDecoder->uiGobHeaderEmpty=0; MP4V_FLUSH(0); uiGobResyncMarker= getBits (29); //getBits (17); //UInt uiVopQuant= uiGobResyncMarker & 0x1f; //getBits(5); //UInt uiGobFrameId = uiGobResyncMarker & 0x03; //getBits(2); uiGobResyncMarker>>=7; uiGobNumber = uiGobResyncMarker & 0x1f;//getBits(5); uiGobNumber++; } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -