📄 vopses.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 (date: March, 1996)and edited by Wei Wu (weiwu@stallion.risc.rockwell.com) Rockwell Science Centerand also edited by Mathias Wien (wien@ient.rwth-aachen.de) RWTH Aachen / Robert BOSCH GmbHand 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 AITin 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: vopses.cAbstract: Base structure for the encoder for one VOP session.Revision History: December 20, 1997: Interlaced tools added by NextLevel Systems (GI) X.Chen (xchen@nlvl.com), B. Eifrig (beifrig@nlvl.com) May. 9 1998: add boundary by Hyundai Electronics Cheol-Soo Park (cspark@super5.hyundai.co.kr) May. 9 1998: add field based unrestricted MC padding by Hyundai Electronics Cheol-Soo Park (cspark@super5.hyundai.co.kr) Feb. 16 1999: add Quarter Sample Mathias Wien (wien@ient.rwth-aachen.de) Feb. 23 1999: GMC added by Yoshinori Suzuki (Hitachi, Ltd.) Aug.24, 1999 : NEWPRED added by Hideaki Kimata (NTT) Sep.06 1999 : RRV added by Eishi Morimatsu (Fujitsu Laboratories Ltd.) Feb.12 2000 : Bug fix of OBSS by Takefumi Nagumo (SONY)*************************************************************************/#include <stdio.h>#include "typeapi.h"#include "basic.h"#include "header.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"#include "mae_pass_thru.h"#include "driverif.h"// Global VideoObject pointerCVideoObject g_MP4VVideoObject;CVideoObject *g_pVO = &g_MP4VVideoObject;// Global VideoObjectDecoder pointerCVideoObjectDecoder *g_pDecoder;// Frequently used global pointersVOLMode *g_pVOL; // vol modeVOPMode *g_pVOP; // vop mode// Changes for gmc_motion.cCRct m_rctCurrVOPY;own CSiteD* m_rgstDstQ = NULL; // quantized dst sts for sprite warpingUInt m_uiWarpingAccuracy; // accuracy for sprite warpingInt m_iNumOfPnts; // for sprite warping// ~Changes for gmc_motion.c// Referenced here so that we can free the memory at cleanup time.extern PPHUFFMAN_DEC_STRUCT m_pentrdecDCT; // decoder for DCTextern PPHUFFMAN_DEC_STRUCT m_pentrdecDCTIntra; // decoder for Y and A planes of Intra VOP/MBextern PPHUFFMAN_DEC_STRUCT m_pentrdecMV; // decoder for MVextern PPHUFFMAN_DEC_STRUCT m_pentrdecMCBPCintra; // decoder for MCBPC = intra extern PPHUFFMAN_DEC_STRUCT m_pentrdecMCBPCinter; // decoder for MCBPC = inter extern PPHUFFMAN_DEC_STRUCT m_pentrdecCBPY; // decoder for CBPY extern PPHUFFMAN_DEC_STRUCT m_pentrdecIntraDCy; // decoder for IntraDC (mpeg2 mode only)extern PPHUFFMAN_DEC_STRUCT m_pentrdecIntraDCc; // decoder for IntraDC (mpeg2 mode only)extern PPHUFFMAN_DEC_STRUCT m_pentrdecMbTypeBVOP; // decoder for MBtype in B-VOP// Moved from mode.cpp/**********************************************************************************//* REMEMBER TO FREE THE MEMORY IN THE FUNCTION BELOW *//**********************************************************************************//*CMBMode::~CMBMode (){ delete [] m_rgbCodedBlockPattern; // MAC (SB) 26-Nov-99 delete [] m_pbACPredictionAlpha; delete [] m_preddir;//~MAC}*/Void CMBMode_Init (CMBMode *pMBMode){ pMBMode->m_uiNumBlks = 6; pMBMode->m_rgbCodedBlockPattern = (Bool *) malloc (sizeof(Bool) * pMBMode->m_uiNumBlks); memset (pMBMode->m_rgbCodedBlockPattern, FALSE, pMBMode->m_uiNumBlks * sizeof (Bool)); pMBMode->m_preddir = (IntraPredDirection *) malloc (sizeof(IntraPredDirection) * pMBMode->m_uiNumBlks); pMBMode->m_bSkip = FALSE; pMBMode->m_bMCSEL = FALSE; pMBMode->m_dctMd = INTRA; pMBMode->m_mbType = FORWARD; pMBMode->m_intStepDelta = 0; pMBMode->m_bhas4MVForward = FALSE; pMBMode->m_bhas4MVBackward = FALSE; pMBMode->m_bFieldMV = FALSE;#ifdef ENABLE_INTERLACING pMBMode->m_bForwardTop = FALSE; pMBMode->m_bForwardBottom = FALSE; pMBMode->m_bBackwardTop = FALSE; pMBMode->m_bBackwardBottom = FALSE;#endif pMBMode->m_bFieldDCT = FALSE; pMBMode->m_stepSize = 0; pMBMode->m_bACPrediction = FALSE; pMBMode->m_bColocatedMBSkip = FALSE; pMBMode->m_bColocatedMBMCSEL = FALSE; pMBMode->m_iVideoPacketNumber = 0; #ifdef ENABLE_INTERLACING RESET_VECT(pMBMode->m_vctDirectDeltaMV);#endif}// End Of -- Moved from mode.cppVoid MP4V_VideoObject_Init (){#ifdef ENABLE_PRINTS printf("==>MP4V_VideoObject_Init\n");#endif // Initialize some bitstream related params g_bEOFReached=0; nBytesAvailable = 0; nTotalBytes = MAX_BUFFER_SIZE; iChoppedHeight = 0; g_pVO->m_t = 0; g_pVO->m_iBCount = 0; g_pVO->m_tPastRef = 0; g_pVO->m_tFutureRef = 0; g_pVO->m_bCodedFutureRef = FALSE; /* HWG - changed from TRUE, since at init nothing has been decoded */ g_pVO->m_rgmbmd = NULL; g_pVO->m_rgmv = NULL; g_pVO->m_rgmvBackward = NULL; g_pVO->m_rgmvBY = NULL; g_pVO->m_rgmbmdRef = NULL; g_pVO->m_rgmvRef = NULL; g_pVO->m_tModuloBaseDecd = 0; g_pVO->m_tModuloBaseDisp = 0; g_pVO->m_uiSprite = 0; g_pVO->m_iOffsetForPadY = 0; g_pVO->m_iOffsetForPadUV = 0; g_pVO->m_iRRVScale = 1;#ifdef ENABLE_PRINTS printf("<==MP4V_VideoObject_Init\n");#endif}Void MP4V_Decoder_CleanUp (){ Int nBlk = 6, iBlk, iMB;#ifdef ENABLE_PRINTS printf("==>MP4V_VideoObject_CleanUp\n");#endif close_mae_driver(); if(g_pVO->m_rgmbmd!=NULL) { for(iBlk=0; iBlk< g_pVO->m_iSessNumMB; iBlk++) { free( g_pVO->m_rgmbmd[iBlk].m_rgbCodedBlockPattern); free( g_pVO->m_rgmbmd[iBlk].m_preddir); } free(g_pVO->m_rgmbmd); g_pVO->m_rgmbmd=NULL; } if(g_pVO->m_rgmbmdRef!=NULL) { for(iBlk=0; iBlk< g_pVO->m_iSessNumMB; iBlk++) { free( g_pVO->m_rgmbmdRef[iBlk].m_rgbCodedBlockPattern); free( g_pVO->m_rgmbmdRef[iBlk].m_preddir); } free(g_pVO->m_rgmbmdRef); g_pVO->m_rgmbmdRef=NULL; } if(g_pVO->m_rgmv!=NULL) { free(g_pVO->m_rgmv); g_pVO->m_rgmv=NULL; } if(g_pVO->m_rgmvBY!=NULL) { free(g_pVO->m_rgmvBY); g_pVO->m_rgmvBY = NULL; } if(g_pVO->m_rgmvRef!=NULL) { free(g_pVO->m_rgmvRef); g_pVO->m_rgmvRef=NULL; }#ifdef ENABLE_INTERLACING if(nFlipArray!=NULL) { free(nFlipArray); nFlipArray=NULL; }#endif if(g_pVO->m_rgpiCoefQ !=NULL) { for (iBlk = 0; iBlk < nBlk; iBlk++) { if(g_pVO->m_rgpiCoefQ [iBlk] != NULL) free(g_pVO->m_rgpiCoefQ [iBlk]); } free (g_pVO->m_rgpiCoefQ); } if(g_pVO->m_rgiQPpred != NULL) free(g_pVO->m_rgiQPpred); if (g_pVOL->fAUsage == RECTANGLE) { if (g_pVO->m_rgpmbmAbove != NULL) for (iMB = 0; iMB < g_pVO->m_iNumMBX; iMB++) { for (iBlk = 0; iBlk < nBlk; iBlk++) { free ((g_pVO->m_rgpmbmAbove [iMB]->rgblkm) [iBlk]); free ((g_pVO->m_rgpmbmCurr [iMB]->rgblkm) [iBlk]); } free (g_pVO->m_rgpmbmAbove [iMB]->rgblkm); free (g_pVO->m_rgpmbmAbove [iMB]); free (g_pVO->m_rgpmbmCurr [iMB]->rgblkm); free (g_pVO->m_rgpmbmCurr [iMB]); } free (g_pVO->m_rgpmbmAbove); free (g_pVO->m_rgpmbmCurr); } g_pVO->m_rgiClipTab -= g_pVO->m_iOffset; free (g_pVO->m_rgiClipTab); g_pVO->m_rgiClipTab = NULL; // from huffman.c if(m_pentrdecDCT != NULL) { for (iBlk=0; iBlk<MAX_TABLE_SIZE_DCT; iBlk++) free (m_pentrdecDCT[iBlk]); free(m_pentrdecDCT); m_pentrdecDCT = NULL; } if(m_pentrdecDCTIntra != NULL) { for (iBlk=0; iBlk<MAX_TABLE_SIZE_DCT_INTRA; iBlk++) free (m_pentrdecDCTIntra[iBlk]); free(m_pentrdecDCTIntra); m_pentrdecDCTIntra = NULL; } if(m_pentrdecMV != NULL) { for (iBlk=0; iBlk<MAX_TABLE_SIZE_MV; iBlk++) free (m_pentrdecMV[iBlk]); free(m_pentrdecMV); m_pentrdecMV = NULL; } if(m_pentrdecMCBPCintra != NULL) { for (iBlk=0; iBlk<MAX_TABLE_SIZE_MCBPC_INTRA; iBlk++) free (m_pentrdecMCBPCintra[iBlk]); free(m_pentrdecMCBPCintra); m_pentrdecMCBPCintra = NULL; } if(m_pentrdecMCBPCinter != NULL) { for (iBlk=0; iBlk<MAX_TABLE_SIZE_MCBPC_INTER; iBlk++) free (m_pentrdecMCBPCinter[iBlk]); free(m_pentrdecMCBPCinter); m_pentrdecMCBPCinter = NULL; } if(m_pentrdecCBPY != NULL) { for (iBlk=0; iBlk<MAX_TABLE_SIZE_CBPY; iBlk++) free (m_pentrdecCBPY[iBlk]); free(m_pentrdecCBPY); m_pentrdecCBPY = NULL; } if(m_pentrdecIntraDCy != NULL) { for (iBlk=0; iBlk<MAX_TABLE_SIZE_INTRA_DCY; iBlk++) free (m_pentrdecIntraDCy[iBlk]); free(m_pentrdecIntraDCy); m_pentrdecIntraDCy = NULL; } if(m_pentrdecIntraDCc != NULL) { for (iBlk=0; iBlk<MAX_TABLE_SIZE_INTRA_DCC; iBlk++) free (m_pentrdecIntraDCc[iBlk]); free(m_pentrdecIntraDCc); m_pentrdecIntraDCc = NULL; } if(m_pentrdecMbTypeBVOP != NULL) { for (iBlk=0; iBlk<MAX_TABLE_SIZE_MBTYPE_BVOP; iBlk++) free (m_pentrdecMbTypeBVOP[iBlk]); free(m_pentrdecMbTypeBVOP); m_pentrdecMbTypeBVOP = NULL; }#ifdef ENABLE_PRINTS printf("<==MP4V_VideoObject_CleanUp\n");#endif}#ifdef ENABLE_NON_RECTANGLE_USAGE// VOP routinesVoid computeVOPMembers ();Void setRefStartingPointers ();Void resetBYPlane ();Void CVideoObject::computeVOPMembers (){ Int iMB, iBlk, nBlk = 6; m_iVOPWidthY = m_rctCurrVOPY.width; m_iVOPWidthUV = m_rctCurrVOPUV.width; m_iNumMBX = m_iVOPWidthY / MB_SIZE; m_iNumMBY = RCT_HEIGHT((&m_rctCurrVOPY)) / MB_SIZE; m_iNumMB = m_iNumMBX * m_iNumMBY; m_iNumOfTotalMVPerRow = PVOP_MV_PER_REF_PER_MB * m_iNumMBX; m_rgpmbmAbove = new MacroBlockMemory* [m_iNumMBX]; m_rgpmbmCurr = new MacroBlockMemory* [m_iNumMBX]; for (iMB = 0; iMB < m_iNumMBX; iMB++) { m_rgpmbmAbove [iMB] = new MacroBlockMemory; m_rgpmbmAbove [iMB]->rgblkm = new BlockMemory [nBlk]; m_rgpmbmCurr [iMB] = new MacroBlockMemory; m_rgpmbmCurr [iMB]->rgblkm = new BlockMemory [nBlk]; for (iBlk = 0; iBlk < nBlk; iBlk++) { // BLOCK_SIZE*2-1 is 15 Ints for dc/ac prediction of coefficients (m_rgpmbmAbove [iMB]->rgblkm) [iBlk] = new Int [(BLOCK_SIZE << 1) - 1]; (m_rgpmbmCurr [iMB]->rgblkm) [iBlk] = new Int [(BLOCK_SIZE << 1) - 1]; } }}Void CVideoObject::saveShapeMode(){ // called after reference frame encode/decode if(m_rgshpmd == NULL) { // first time m_iRefShpNumMBX = m_iNumMBX; m_iRefShpNumMBY = m_iNumMBY; m_rgshpmd = new ShapeMode [m_iNumMB]; } else { // update if changed if(m_iRefShpNumMBX!=m_iNumMBXRef || m_iRefShpNumMBY != m_iNumMBYRef) { delete [] m_rgshpmd; m_rgshpmd = new ShapeMode [m_iNumMBRef]; m_iRefShpNumMBX = m_iNumMBXRef; m_iRefShpNumMBY = m_iNumMBYRef; } // copy shape mode from previous ref to save Int i; for (i=0; i<m_iNumMBRef; i++ ) m_rgshpmd[i] = m_rgmbmdRef[i].m_shpmd; }}//OBSS_SAIT_991015Void CVideoObject::saveBaseShapeMode(){ // called after reference frame encode/decode if(m_rgBaseshpmd == NULL){ // first time m_iNumMBBaseXRef = m_iNumMBX; m_iNumMBBaseYRef = m_iNumMBY; // save current shape mode for enhancement layer shape mode coding if(m_volmd.volType == BASE_LAYER) { m_rgBaseshpmd = new ShapeMode [m_iNumMB]; // first time m_iRefShpNumMBX = m_iNumMBX; m_iRefShpNumMBY = m_iNumMBY; Int i; Int iMBX, iMBY; for (iMBY=0, i=0; iMBY<m_iNumMBY; iMBY++ ) { for (iMBX=0; iMBX<m_iNumMBX; iMBX++ ) { m_rgBaseshpmd[i] = m_rgmbmd[i].m_shpmd; i++; } } } } else { // update if changed if(m_volmd.volType == BASE_LAYER) { //for save lower layer shape mode if(m_iNumMBBaseXRef!=m_iNumMBX || m_iNumMBBaseYRef != m_iNumMBY){ delete [] m_rgBaseshpmd; m_rgBaseshpmd = new ShapeMode [m_iNumMB]; m_iNumMBBaseXRef = m_iNumMBX; m_iNumMBBaseYRef = m_iNumMBY; } Int i=0; Int iMBX, iMBY; for (iMBY=0, i=0; iMBY<m_iNumMBY; iMBY++ ){ for (iMBX=0; iMBX<m_iNumMBX; iMBX++ ){ m_rgBaseshpmd[i] = m_rgmbmd[i].m_shpmd; i++; } } m_iNumMBBaseXRef = m_iNumMBX; m_iNumMBBaseYRef = m_iNumMBY; //for save lawer layer shape mode } }}//~OBSS_SAIT_991015Void CVideoObject::resetBYPlane (){ if (m_vopmd.vopPredType == PVOP || m_vopmd.vopPredType == IVOP || (m_uiSprite == 2 && m_vopmd.vopPredType == SPRITE)) // GMC { PixelC* ppxlcBY = (PixelC*) m_pvopcRefQ1->pixelsBY (); memset (ppxlcBY, 0, RCT_AREA((&m_pvopcRefQ1->whereY())) * sizeof(PixelC)); } else { PixelC* ppxlcBY = (PixelC*) m_pvopcCurrQ->pixelsBY (); memset (ppxlcBY, 0, RCT_AREA((&m_pvopcCurrQ->whereY())) * sizeof(PixelC)); }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -