📄 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 Center
and 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 Laboratories
and also edited by
Dick van Smirren (D.vanSmirren@research.kpn.com), KPN Research
Cor Quist (C.P.Quist@research.kpn.com), KPN Research
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:
vopSeDec.cpp
Abstract:
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)
*************************************************************************/
#include <stdio.h>
#ifdef __GNUC__
#include <strstream.h>
#else
#include <strstrea.h>
#endif
#include <math.h>
#include "typeapi.h"
#include "codehead.h"
#include "entropy/bitstrm.hpp"
#include "entropy/entropy.hpp"
#include "entropy/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"
#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
#endif // __MFC_
#define _FOR_GSSP_
#undef assert
#define assert(a) if (!(a)) { printf("iso throw %d\n", __LINE__);throw((int)0);}
CVideoObjectDecoder::~CVideoObjectDecoder ()
{
// delete m_pistrm;
if (m_pistrm >= 0) close(m_pistrm);
delete m_pbitstrmIn;
delete m_pentrdecSet;
delete m_pvopcRightMB;
}
Int CVideoObjectDecoder::h263_decode ()
{
static Bool first_time = TRUE;
if (!first_time)
{
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);
}
m_pbitstrmIn -> getBits(22);
video_plane_with_short_header();
}
else
first_time = FALSE;
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;
// set time stamps for Base/Temporal-Enhc/Spatial-Enhc Layer Modified by Sharp(1998-02-10)
if(m_volmd.volType == BASE_LAYER) {
if(m_vopmd.vopPredType==IVOP || m_vopmd.vopPredType==PVOP) {
m_tPastRef = m_tFutureRef;
m_tFutureRef = m_t;
m_iBCount = 0;
}
}
// set time stamps for Base/Temporal-Enhc/Spatial-Enhc Layer End Sharp(1998-02-10)
// select reference frames for Base/Temporal-Enhc/Spatial-Enhc Layer Modified by Sharp(1998-02-10)
if(m_volmd.volType == BASE_LAYER) {
updateAllRefVOPs (); // update all reconstructed VOP'sm_pvopcRefQ1->vdlDump ("c:\\refq1.vdl");
}
// select reference frames for Base/Temporal-Enhc/Spatial-Enhc Layer End Sharp(1998-02-10)
switch(m_vopmd.vopPredType)
{
case IVOP:
#ifdef DEBUG_OUTPUT
cout << "\tIVOP";
#endif
/*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:
#ifdef DEBUG_OUTPUT
cout << "\tPVOP (reference: t=" << m_tPastRef <<")";
#endif
break;
default:
break;
}
#ifdef DEBUG_OUTPUT
cout << "\n";
cout.flush ();
#endif
/* 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;
}
Void CVideoObjectDecoder::video_plane_with_short_header()
{
/* UInt uiTemporalReference = wmay */ 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_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;
}
void CVideoObjectDecoder::decodeShortHeaderIntraMBDC(Int *rgiCoefQ)
{
UInt uiIntraDC;
uiIntraDC=m_pbitstrmIn->getBits(8);
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 () : CVideoObject()
{
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 ()
{
#if 0
if (pistrm == NULL) {
#endif
m_pistrm = open(pchStrFile, O_RDONLY);
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;
m_vopmd.iVopConstantAlphaValue = 255;
*p_short_video_header=FALSE; // Added by KPN for short headers
if (m_pbitstrmIn->peekBits(NUMBITS_SHORT_HEADER_START_CODE) == SHORT_VIDEO_START_MARKER)
{
fprintf(stderr, "\nBitstream with short header format detected\n");
*p_short_video_header=TRUE;
m_pbitstrmIn -> getBits(22);
video_plane_with_short_header();
}
else {
fprintf(stderr,"\nBitstream without short headers detected\n");
decodeVOHead ();
printf ("VO %d...\n", m_uiVOId);
decodeVOLHead ();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -