📄 sys_decoder_vopsedec.cpp
字号:
/*************************************************************************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 Wei Wu (weiwu@stallion.risc.rockwell.com) Rockwell Science Centerand also 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 Laboratoriesand also edited by Dick van Smirren (D.vanSmirren@research.kpn.com), KPN Research Cor Quist (C.P.Quist@research.kpn.com), KPN Research 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 Massimo Ravasi (Massimo.Ravasi@epfl.ch), Swiss Federal Institute of Technology, Lausanne (EPFL)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: vopSeDec.cppAbstract: Decoder for one Video Object.Revision History: Dec 20, 1997: Interlaced tools added by NextLevel Systems X. Chen (xchen@nlvl.com) B. Eifrig (beifrig@nlvl.com) Feb.16, 1999: (use of rgiDefaultInterQMatrixAlpha) Mathias Wien (wien@ient.rwth-aachen.de) Feb.24, 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.) Nov.11 1999 : Fixed Complexity Estimation syntax support, version 2 (Massimo Ravasi, EPFL) Feb.01 2000 : Bug fixed OBSS by Takefumi Nagumo (Sony)*************************************************************************/#include <stdio.h>//#include <fstream.h>//#include <iostream.h>#ifdef __GNUC__//#include <strstream.h>#else#include <strstream>#endif#include <math.h>#include "typeapi.h"#include "codehead.h"#include "bitstrm.hpp"#include "entropy.hpp"#include "huffman.hpp"#include "global.hpp"#include "mode.hpp"#include "vopses.hpp"#include "cae.h" // Added for error resilient mode by Toshiba(1997-11-14)#include "tps_enhcbuf.hpp" // Added by Sharp(1998-02-10)#include "enhcbufdec.hpp" // #include "vopsedec.hpp"#include "idct.hpp" // yrchen// NEWPRED#include "newpred.hpp"// ~NEWPRED#ifndef max#define max MAX#endif#ifdef __MFC_#ifdef _DEBUG#undef THIS_FILEstatic char BASED_CODE THIS_FILE[] = __FILE__;#endif#define new DEBUG_NEW #endif // __MFC_#ifdef __PC_COMPILER_#define IOSBINARY ios::binary#else#define IOSBINARY ios::bin#endif // __PC_COMPILER_#define _FOR_GSSP_#define ASSERT(a) if (!(a)) { printf("iso throw %d\n", __LINE__);throw((int)__LINE__);}CVideoObjectDecoder::~CVideoObjectDecoder (){// NEWPRED if (g_pNewPredDec != NULL) delete g_pNewPredDec;// ~NEWPRED// delete m_pistrm; if (m_pistrm >= 0) close(m_pistrm); delete m_pbitstrmIn; delete m_pentrdecSet; delete m_pvopcRightMB; // HHI Schueuer delete m_pscanSelector; // end HHI if (m_pinvdct) delete m_pinvdct;}Int CVideoObjectDecoder::h263_decode (bool read_header){ if (read_header != FALSE) { while ( m_pbitstrmIn -> peekBits(NUMBITS_SHORT_HEADER_START_CODE) != SHORT_VIDEO_START_MARKER) { if(m_pbitstrmIn->eof()==EOF) // [FDS] return EOF; m_pbitstrmIn -> getBits(1); } // moved outside m_pbitstrmIn -> getBits(22); m_t = video_plane_with_short_header(); } else { m_tPastRef = m_tFutureRef = m_t; } m_bUseGOV=FALSE; m_bLinkisBroken=FALSE; m_vopmd.iRoundingControl=0; m_vopmd.iIntraDcSwitchThr=0; m_vopmd.bInterlace=FALSE; m_vopmd.bAlternateScan=FALSE; m_t = 1; m_vopmd.mvInfoForward.uiFCode=1; m_vopmd.mvInfoForward.uiScaleFactor = 1 << (m_vopmd.mvInfoForward.uiFCode - 1); m_vopmd.mvInfoForward.uiRange = 16 << m_vopmd.mvInfoForward.uiFCode; // Added for error resilient mode by Toshiba(1998-1-16) m_vopmd.mvInfoBackward.uiFCode = 1; // End Toshiba(1998-1-16) m_vopmd.bShapeCodingType=1; m_tPastRef = m_tFutureRef; m_tFutureRef = m_t; m_iBCount = 0; updateAllRefVOPs (); // select reference frames for Base/Temporal-Enhc/Spatial-Enhc Layer End Sharp(1998-02-10) switch(m_vopmd.vopPredType) { case IVOP: // cout << "\tIVOP";/*Added by SONY (98/03/30)*/ if(m_bLinkisBroken == TRUE && m_bUseGOV == TRUE) m_bLinkisBroken = FALSE;/*Added by SONY (98/03/30) END*/ break; case PVOP: //cout << "\tPVOP (reference: t=" << m_tPastRef <<")"; break; default: break; } //cout << "\n"; //cout.flush ();/* Added by SONY (98/03/30)*/ if(m_bLinkisBroken == TRUE && m_bUseGOV == TRUE) fprintf(stderr,"WARNING: broken_link = 1 --- Output image must be broken.\n");/*Added by SONY (98/03/30) End*/ decodeVOP (); CMBMode* pmbmdTmp = m_rgmbmd; m_rgmbmd = m_rgmbmdRef; m_rgmbmdRef = pmbmdTmp; CMotionVector* pmvTmp = m_rgmv; m_rgmv = m_rgmvRef; m_rgmvRef = pmvTmp; m_rgmvBackward = m_rgmv + BVOP_MV_PER_REF_PER_MB * m_iSessNumMB;// ? For Temporal Scalability End Sharp(1998-02-10) m_iBVOPOffsetForPadY = m_iOffsetForPadY; m_iBVOPOffsetForPadUV = m_iOffsetForPadUV; m_rctBVOPPrevNoExpandY = m_rctPrevNoExpandY; m_rctBVOPPrevNoExpandUV = m_rctPrevNoExpandUV; m_rctBVOPRefVOPY1 = m_rctRefVOPY1; m_rctBVOPRefVOPUV1 = m_rctRefVOPUV1; // For Temporal Scalability End Sharp(1998-02-10) repeatPadYOrA ((PixelC*) m_pvopcRefQ1->pixelsY () + m_iOffsetForPadY, m_pvopcRefQ1); repeatPadUV (m_pvopcRefQ1); //reset by in RefQ1 so that no left-over from last frame return TRUE; }UInt CVideoObjectDecoder::video_plane_with_short_header(){ short_video_header = 1; m_pbitstrmIn->getBits(22); // read header UInt uiTemporalReference = m_pbitstrmIn -> getBits (8); m_pbitstrmIn -> getBits(5); UInt uiSourceFormat = m_pbitstrmIn -> getBits (3); if (uiSourceFormat==1) { //fprintf(stderr,"Sub-QCIF, 128x96, 8 macroblocks/gob, 6 gobs in vop\n"); uiNumGobsInVop=6; uiNumMacroblocksInGob=8; m_ivolWidth=128; m_ivolHeight=96; } else if (uiSourceFormat==2) { //fprintf(stderr,"QCIF, 176x144, 11 macroblocks/gob, 9 gobs in vop\n"); uiNumGobsInVop=9; uiNumMacroblocksInGob=11; m_ivolWidth=176; m_ivolHeight=144; } else if (uiSourceFormat==3) { //fprintf(stderr,"CIF, 352x288, 22 macroblocks/gob, 18 gobs in vop\n"); uiNumGobsInVop=18; uiNumMacroblocksInGob=22; m_ivolWidth=352; m_ivolHeight=288; } else if (uiSourceFormat==4) { //fprintf(stderr,"4CIF, 704x576, 88 macroblocks/gob, 18 gobs in vop\n"); uiNumGobsInVop=18; uiNumMacroblocksInGob=88; m_ivolWidth=704; m_ivolHeight=576; } else if (uiSourceFormat==5) { //fprintf(stderr,"16CIF, 1408x1152, 352 macroblocks/gob, 18 gobs in vop\n"); uiNumGobsInVop=18; uiNumMacroblocksInGob=352; m_ivolWidth=1408; m_ivolHeight=1152; } else { fprintf(stderr,"Wrong Source Format in video_plane_with_short_header()\n"); exit (0); } UInt uiPictureCodingType = m_pbitstrmIn -> getBits(1); if (uiPictureCodingType==0) m_vopmd.vopPredType=IVOP; else m_vopmd.vopPredType=PVOP; m_pbitstrmIn -> getBits(4); UInt uiVopQuant = m_pbitstrmIn -> getBits(5); //fprintf(stderr,"vop_quant (0..31) %d\n",uiVopQuant); m_vopmd.intStepI=uiVopQuant; m_vopmd.intStep=uiVopQuant; // idem m_pbitstrmIn -> getBits(1); do { uiPei = m_pbitstrmIn -> getBits(1); //fprintf(stderr,"pei gelezen %d\n",uiPei); if (uiPei==1) { m_pbitstrmIn -> getBits(8); }// [bezig] } while (uiPei==1); m_uiVOId = 1; m_volmd.iClockRate = 30; m_volmd.dFrameHz = 30; m_iNumBitsTimeIncr = 4; m_volmd.bShapeOnly=FALSE; m_volmd.fAUsage = RECTANGLE; m_volmd.bAdvPredDisable = TRUE; m_uiSprite = FALSE; m_volmd.bNot8Bit=FALSE; m_volmd.uiQuantPrecision=5; m_volmd.nBits=8; m_volmd.fQuantizer=Q_H263; m_volmd.bDataPartitioning=FALSE; m_volmd.bReversibleVlc=FALSE; m_volmd.volType=BASE_LAYER; m_volmd.ihor_sampling_factor_n=1; m_volmd.ihor_sampling_factor_m=1; m_volmd.iver_sampling_factor_n=1; m_volmd.iver_sampling_factor_m=1; m_volmd.bDeblockFilterDisable=TRUE; m_volmd.bQuarterSample = 0; m_volmd.bRoundingControlDisable = 0; m_volmd.iInitialRoundingType = 0; m_volmd.bResyncMarkerDisable = 1; m_volmd.bVPBitTh = 0; m_volmd.bSadctDisable = 1; m_volmd.bComplexityEstimationDisable = 1; m_volmd.bTrace = 0; m_volmd.bDumpMB = 0; m_volmd.breduced_resolution_vop_enable = 0;// NEWPRED m_volmd.bNewpredEnable=FALSE;// ~NEWPRED return uiTemporalReference;}void CVideoObjectDecoder::decodeShortHeaderIntraMBDC(Int *rgiCoefQ){ UInt uiIntraDC; uiIntraDC=m_pbitstrmIn->getBits(8); //printf("%d ", uiIntraDC); if (uiIntraDC==128||uiIntraDC==0) fprintf(stderr,"IntraDC = 0 of 128, not allowed in H.263 mode\n"); if (uiIntraDC==255) uiIntraDC=128; rgiCoefQ[0]=uiIntraDC;}CVideoObjectDecoder::CVideoObjectDecoder (void) : CVideoObject(), m_pscanSelector(0){ m_t = m_tPastRef = m_tFutureRef = 0; m_iBCount = 0; m_vopmd.iVopConstantAlphaValue = 255; short_video_header = FALSE; m_pbitstrmIn = new CInBitStream(); m_pentrdecSet = new CEntropyDecoderSet (m_pbitstrmIn);}CVideoObjectDecoder::CVideoObjectDecoder ( const Char* pchStrFile, Int iDisplayWidth, Int iDisplayHeight, Bool *pbSpatialScalability, Bool *p_short_video_header//, //strstreambuf* pistrm ) : CVideoObject (), m_pscanSelector(0) // HHI Schueuer: m_pscanSelector(0) added{#if 0 if (pistrm == NULL) {#endif m_pistrm = open(pchStrFile, O_RDONLY, 0); if(m_pistrm < 0) fatal_error("Can't open bitstream file");#if 0 } else { m_pistrm = (ifstream *)new istream (pistrm); }#endif m_pbitstrmIn = new CInBitStream (m_pistrm); m_pentrdecSet = new CEntropyDecoderSet (m_pbitstrmIn); m_t = m_tPastRef = m_tFutureRef = 0; m_iBCount = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -