⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vopsedec.cpp

📁 visual c++小波技术和工程实践随书光盘
💻 CPP
📖 第 1 页 / 共 5 页
字号:
 
	{ 

		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 ();

	} 

	short_video_header=*p_short_video_header; 

/* (98/03/30 added by SONY)*/
	m_bLinkisBroken = FALSE;
	m_bUseGOV = FALSE;
/* (98/03/30 added by SONY)*/
	//	Added for error resilient mode by Toshiba(1997-11-14): Moved (1998-1-16)
	g_iMaxHeading = MAXHEADING_ERR;
	g_iMaxMiddle = MAXMIDDLE_ERR;
	g_iMaxTrailing = MAXTRAILING_ERR;
	//	End Toshiba(1997-11-14)

	setClipTab(); // NBIT

	if(m_volmd.volType == ENHN_LAYER){ // check scalability type
//OBSS_SAIT_991015
		m_volmd.bSpatialScalability = FALSE;
		if(pbSpatialScalability != NULL){
			if(m_volmd.iHierarchyType == 0 || m_volmd.bShapeOnly) {
				*pbSpatialScalability = TRUE;
				m_volmd.bSpatialScalability = TRUE;
			}
			else { 	
				*pbSpatialScalability = FALSE;
				m_volmd.bSpatialScalability = FALSE;
			}
		}
//~OBSS_SAIT_991015
	}
	if (m_volmd.fAUsage == RECTANGLE) {
		if (m_volmd.volType == ENHN_LAYER &&
			(m_volmd.ihor_sampling_factor_n != m_volmd.ihor_sampling_factor_m ||
	     	 m_volmd.iver_sampling_factor_n != m_volmd.iver_sampling_factor_m )){
			iDisplayWidth = m_ivolWidth;
			iDisplayHeight= m_ivolHeight;
//OBSS_SAIT_991015
			m_volmd.iFrmWidth_SS = iDisplayWidth;		
			m_volmd.iFrmHeight_SS = iDisplayHeight;		
//~OBSS_SAIT_991015
		}
		else if (iDisplayWidth != m_ivolWidth || iDisplayHeight != m_ivolHeight){
			fprintf(stderr, "\nDecode aborted! This rectangular VOP stream requires display\nwidth and height to be set to %dx%d.\n",
				m_ivolWidth, m_ivolHeight);
			exit(1);
		}
	}
//OBSS_SAIT_991015
	else if (m_volmd.fAUsage == ONE_BIT) {
		if (m_volmd.volType == ENHN_LAYER &&
			(m_volmd.ihor_sampling_factor_n_shape!=m_volmd.ihor_sampling_factor_m_shape  ||
	     	 m_volmd.iver_sampling_factor_n_shape!=m_volmd.iver_sampling_factor_m_shape )){
			m_volmd.iFrmWidth_SS = iDisplayWidth;		
			m_volmd.iFrmHeight_SS = iDisplayHeight;		
			if(pbSpatialScalability!=NULL) {
				*pbSpatialScalability = TRUE;
				m_volmd.bSpatialScalability = TRUE;
			}
		}
		else {
			if(pbSpatialScalability!=NULL) {
				*pbSpatialScalability = FALSE;
				m_volmd.bSpatialScalability = FALSE;
			}
		}
	}
//~OBSS_SAIT_991015
	m_rctDisplayWindow = CRct (0, 0, iDisplayWidth, iDisplayHeight); //same as m_rctOrg? will fixe later
/*
	if (m_volmd.fAUsage == RECTANGLE) {
		if (m_volmd.volType == ENHN_LAYER &&
			(m_volmd.ihor_sampling_factor_n/m_volmd.ihor_sampling_factor_m != 1||
	     	 m_volmd.iver_sampling_factor_n/m_volmd.iver_sampling_factor_m != 1)){
			iDisplayWidth = m_ivolWidth;
			iDisplayHeight= m_ivolHeight;
			if(pbSpatialScalability!=NULL)
				*pbSpatialScalability = TRUE;
			fprintf(stderr,"display size %d %d \n",iDisplayWidth, iDisplayHeight);
		}
		else if (iDisplayWidth != m_ivolWidth || iDisplayHeight != m_ivolHeight){
			fprintf(stderr, "\nDecode aborted! This rectangular VOP stream requires display\nwidth and height to be set to %dx%d.\n",
				m_ivolWidth, m_ivolHeight);
			exit(1);
		}
		else if(pbSpatialScalability!=NULL)
			*pbSpatialScalability = FALSE;
	}
	m_rctDisplayWindow = CRct (0, 0, iDisplayWidth, iDisplayHeight); //same as m_rctOrg? will fixe later
*/
	
	if (m_uiSprite == 1) { // change iDisplay size in order to get the first sprite piece
		iDisplayWidth = (Int) m_rctSpt.width;
		iDisplayHeight = (Int) m_rctSpt.height ();
	}

//OBSS_SAIT_991015
	Int iDisplayWidthRound = 0;
	Int iDisplayHeightRound = 0;
//	if (m_volmd.volType == ENHN_LAYER && m_volmd.fAUsage == ONE_BIT) {
		iDisplayWidthRound = iDisplayWidth;
		iDisplayHeightRound = iDisplayHeight;
//	}
//	else {
//		Int iMod = iDisplayWidth % MB_SIZE;
//		iDisplayWidthRound = (iMod > 0) ? iDisplayWidth + MB_SIZE - iMod : iDisplayWidth;
//		iMod = iDisplayHeight % MB_SIZE;
//		iDisplayHeightRound = (iMod > 0) ? iDisplayHeight + MB_SIZE - iMod : iDisplayHeight;
//	}
/*
	Int iMod = iDisplayWidth % MB_SIZE;
	Int iDisplayWidthRound = (iMod > 0) ? iDisplayWidth + MB_SIZE - iMod : iDisplayWidth;
	iMod = iDisplayHeight % MB_SIZE;
	Int iDisplayHeightRound = (iMod > 0) ? iDisplayHeight + MB_SIZE - iMod : iDisplayHeight;
*/
//~OBSS_SAIT_991015

	m_rctRefFrameY = CRct (
		-EXPANDY_REF_FRAME, -EXPANDY_REF_FRAME, 
		EXPANDY_REF_FRAME + iDisplayWidthRound, EXPANDY_REF_FRAME + iDisplayHeightRound
	);
	m_rctRefFrameUV = m_rctRefFrameY.downSampleBy2 ();
	allocateVOLMembers (iDisplayWidth, iDisplayHeight);

	// HHI Schueuer
	if (m_volmd.bSadctDisable)
		m_pscanSelector = new CInvScanSelector;
	else
		m_pscanSelector = new CInvScanSelectorForSADCT(m_rgiCurrMBCoeffWidth);
	// end HHI

// RRV insertion
	Int iScale	= (m_vopmd.RRVmode.iOnOff == 1) ? (2) : (1);
// ~RRV 
	if (m_volmd.fAUsage == RECTANGLE) {

		//wchen: if sprite; set it according to the initial piece instead
		m_rctCurrVOPY = (m_uiSprite == 0 || m_uiSprite == 2) ? CRct (0, 0, iDisplayWidthRound, iDisplayHeightRound) : m_rctSpt; // GMC

		m_rctCurrVOPUV = m_rctCurrVOPY.downSampleBy2 ();

		m_rctRefVOPY0 = m_rctCurrVOPY;
// RRV modification
		m_rctRefVOPY0.expand (EXPANDY_REFVOP *iScale);
//		m_rctRefVOPY0.expand (EXPANDY_REFVOP);
// ~RRV
		m_rctRefVOPUV0 = m_rctRefVOPY0.downSampleBy2 ();
		
		m_rctRefVOPY1 = m_rctRefVOPY0;
		m_rctRefVOPUV1 = m_rctRefVOPUV0;

		computeVOLConstMembers (); // these VOP members are the same for all frames
	}
//OBSS_SAIT_991015
	else if (m_volmd.fAUsage == ONE_BIT) {
		m_rctCurrVOPY = (m_uiSprite == 0) ? CRct (0, 0, iDisplayWidthRound, iDisplayHeightRound) : m_rctSpt;
		m_rctCurrVOPUV = m_rctCurrVOPY.downSampleBy2 ();

		m_rctRefVOPY0 = m_rctCurrVOPY;
		m_rctRefVOPY0.expand (EXPANDY_REFVOP);
		m_rctRefVOPUV0 = m_rctRefVOPY0.downSampleBy2 ();
		
		m_rctRefVOPY1 = m_rctRefVOPY0;
		m_rctRefVOPUV1 = m_rctRefVOPUV0;
	}
//~OBSS_SAIT_991015
	// buffer for shape decoding
	m_pvopcRightMB = new CVOPU8YUVBA (m_volmd.fAUsage, CRct (0, 0, MB_SIZE, MB_SIZE), m_volmd.iAuxCompCount);
	m_ppxlcRightMBBY = (PixelC*) m_pvopcRightMB->pixelsBY ();
	m_ppxlcRightMBBUV = (PixelC*) m_pvopcRightMB->pixelsBUV ();

// NEWPRED
	if (m_volmd.bNewpredEnable) {
		g_pNewPredDec->SetObject(
			m_iNumBitsTimeIncr,
			iDisplayWidth,
			iDisplayHeight,
			"",
			m_volmd.bNewpredSegmentType,
			m_volmd.fAUsage,
			m_volmd.bShapeOnly,
			m_pvopcRefQ0,
			m_pvopcRefQ1,
			m_rctRefFrameY,
			m_rctRefFrameUV
		);
		m_vopmd.m_iNumBitsVopID = m_iNumBitsTimeIncr + NUMBITS_VOP_ID_PLUS;
	}
// ~NEWPRED

	// buffers for Temporal Scalabe Decoding	Added by Sharp(1998-02-10)
	if (m_volmd.volType == ENHN_LAYER) {
		m_pBuffP1 = new CEnhcBufferDecoder (m_rctRefFrameY.width, m_rctRefFrameY.height ());
		m_pBuffP2 = new CEnhcBufferDecoder (m_rctRefFrameY.width, m_rctRefFrameY.height ());
		m_pBuffB1 = new CEnhcBufferDecoder (m_rctRefFrameY.width, m_rctRefFrameY.height ());
		m_pBuffB2 = new CEnhcBufferDecoder (m_rctRefFrameY.width, m_rctRefFrameY.height ());
		m_pBuffE  = new CEnhcBufferDecoder (m_rctRefFrameY.width, m_rctRefFrameY.height ());
	}
	// buffers for Temporal Scalabe Decoding	End	 Sharp(1998-02-10)
	m_iClockRateScale = 1; // added by Sharp (98/6/26)

	// Set sprite_transmit_mode to STOP	for the duration of VOL if (fSptUsage () == 0),
	// and later set to PIECE by decode_init_sprite () if (fSptUsage () == 1)
	m_vopmd.SpriteXmitMode = STOP;	  
}

// for back/forward shape	Added by Sharp(1998-02-10)
CVideoObjectDecoder::CVideoObjectDecoder (
	Int iDisplayWidth, Int iDisplayHeight
) : CVideoObject ()
{
	m_pistrm = NULL;
	m_pbitstrmIn = NULL;
	m_pentrdecSet = NULL;

	m_uiVOId = 0;
	Void set_modes(VOLMode* volmd, VOPMode* vopmd);
	set_modes(&m_volmd, &m_vopmd); // set VOL modes, VOP modes

	m_vopmd.iVopConstantAlphaValue = 255;

	Int iMod = iDisplayWidth % MB_SIZE;
	Int iDisplayWidthRound = (iMod > 0) ? iDisplayWidth + MB_SIZE - iMod : iDisplayWidth;
	iMod = iDisplayHeight % MB_SIZE;
	Int iDisplayHeightRound = (iMod > 0) ? iDisplayHeight + MB_SIZE - iMod : iDisplayHeight;
	m_rctRefFrameY = CRct (
		-EXPANDY_REF_FRAME, -EXPANDY_REF_FRAME,
		EXPANDY_REF_FRAME + iDisplayWidthRound, EXPANDY_REF_FRAME + iDisplayHeightRound
	);
	m_rctRefFrameUV = m_rctRefFrameY.downSampleBy2 ();
	allocateVOLMembers (iDisplayWidth, iDisplayHeight);

	// HHI Schueuer
	if (m_volmd.bSadctDisable)
		m_pscanSelector = new CInvScanSelector;
	else
		m_pscanSelector = new CInvScanSelectorForSADCT(m_rgiCurrMBCoeffWidth);
	//end HHI

	// buffer for shape decoding
	m_pvopcRightMB = new CVOPU8YUVBA (m_volmd.fAUsage, CRct (0, 0, MB_SIZE, MB_SIZE));
	m_ppxlcRightMBBY = (PixelC*) m_pvopcRightMB->pixelsBY ();
	m_ppxlcRightMBBUV = (PixelC*) m_pvopcRightMB->pixelsBUV ();
}
// for back/forward shape	End	 Sharp(1998-02-10)

Int CVideoObjectDecoder::decode (const CVOPU8YUVBA* pvopcBVOPQuant, strstreambuf* pistrm)
{
	if (pistrm != NULL) {
		delete (istream *)m_pistrm;
		delete m_pbitstrmIn;
		delete m_pentrdecSet;
		m_pistrm = (ifstream *)new istream (pistrm);
		m_pbitstrmIn = new CInBitStream (*m_pistrm);
		m_pentrdecSet = new CEntropyDecoderSet (*m_pbitstrmIn);
	}

// RRV
	m_iRRVScale	= 1;	// default value
// ~RRV

	//sprite piece should not come here
	assert ((m_vopmd.SpriteXmitMode == STOP) || ( m_vopmd.SpriteXmitMode == PAUSE));

	if (findStartCode () == EOF)
		return EOF;

	Bool bCoded = decodeVOPHead (); // set the bounding box here
	cout << "\t" << "Time..." << m_t << " (" << m_t / (double)m_volmd.iClockRate << " sec)\n";
	if(bCoded == FALSE)
		cout << "\tNot coded.\n";
	cout.flush ();

	Bool bPrevRefVopWasCoded = m_bCodedFutureRef;
	if(m_vopmd.vopPredType==IVOP || m_vopmd.vopPredType==PVOP || (m_uiSprite == 2 && m_vopmd.vopPredType==SPRITE)) // GMC
		m_bCodedFutureRef = bCoded; // flag used by bvop prediction

	if (m_vopmd.vopPredType == SPRITE && m_uiSprite == 1)   { // GMC
		decodeSpt ();
		return TRUE;
	}

	// 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_uiSprite == 2 && m_vopmd.vopPredType==SPRITE)) { // GMC
			if(bPrevRefVopWasCoded)
				m_tPastRef = m_tFutureRef;
			m_tFutureRef = m_t;
			m_iBCount = 0;
		}
		// count B-VOPs
		if(m_vopmd.vopPredType==BVOP)
			m_iBCount++;
	}
	else if (pvopcBVOPQuant != NULL) {	// Spatial Scalability Enhancement Layer
/* (98/03/30) modified by SONY */
		if(m_vopmd.vopPredType == BVOP && m_vopmd.iRefSelectCode == 0) {
			if(bPrevRefVopWasCoded)
				m_tPastRef = m_tFutureRef;
			m_tFutureRef = m_t;
			m_iBCount = 0;
		} if(m_vopmd.vopPredType == PVOP && m_vopmd.iRefSelectCode == 3) {
			m_tPastRef = m_t;
			m_tFutureRef = m_t;
			m_iBCount = 0;
		}
/* (98/03/30) modified by SONY */

		// count B-VOPs
		if(m_vopmd.vopPredType==BVOP)
			m_iBCount++;
	}
	// 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(bPrevRefVopWasCoded)
	{
		if(m_volmd.volType == BASE_LAYER) {
			updateAllRefVOPs ();            // update all reconstructed VOP's
		}
		else {
//OBSS_SAIT_991015
			if (pvopcBVOPQuant == NULL && !m_volmd.bSpatialScalability)		// Temporal Scalability Enhancement Layer
				updateRefVOPsEnhc ();
			else {					// Spatial Scalability Enhancement Layer
				if (pvopcBVOPQuant != NULL && m_volmd.bSpatialScalability)	
					updateAllRefVOPs (pvopcBVOPQuant);
			}
//~OBSS_SAIT_991015
		}
	}
//OBSS_SAIT_991015
	else if(m_volmd.volType == ENHN_LAYER && m_volmd.bSpatialScalability && pvopcBVOPQuant != NULL)	// Spatial Scalability Enhancement Layer
		updateAllRefVOPs (pvopcBVOPQuant);
//~OBSS_SAIT_991015
	// 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;
// GMC
	case SPRITE:
		cout << "\tSVOP(GMC) (reference: t=" << m_tPastRef <<")";
		break;
// ~GMC
	case BVOP:
		cout << "\tBVOP (past ref: t=" << m_tPastRef
			<< ", future ref: t=" << m_tFutureRef <<")";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -