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

📄 vopseenc.cpp

📁 此源码是在VC平台下,实现MPEG4编解码的源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			m_statsVOP.nBitsStuffing += 1;
		}

		if ( m_volmd.volType == ENHN_LAYER && m_volmd.iEnhnType == 1 ) {
			m_pbitstrmOut->putBits (1, 1, "Background Composition");
			m_statsVOP.nBitsHead++;
		}
// begin: added by Sharp (98/3/24)
		else if ( m_volmd.volType == ENHN_LAYER && m_volmd.iEnhnType == 2 ) {
			m_pbitstrmOut->putBits (0, 1, "Background Composition");
			m_statsVOP.nBitsHead++;
		}
// end: added by Sharp (98/3/24)

		m_pbitstrmOut->putBits (m_volmd.bNoCrChange, 1, "VOP_CR_Change_Disable");
		m_statsVOP.nBitsHead++;
        // tentative solution for normal sprite bitstream exchange
		m_pbitstrmOut->putBits (0, 1, "VOP_Constant_Alpha");
		m_statsVOP.nBitsHead++;
	}

	// START: Complexity Estimation syntax support - Marc Mongenet (EPFL) - 15 Jun 1998	
	if (! m_volmd.bComplexityEstimationDisable) {
		assert (m_volmd.iEstimationMethod == 0);

		// In real life the following values should be estimated by the encoder,
		// but this is only a syntax support so arbitrary complexity values are assigned.
		m_vopmd.iOpaque = 77;
		m_vopmd.iTransparent = 97;
		m_vopmd.iIntraCAE = 114;
		m_vopmd.iInterCAE = 99;
		m_vopmd.iNoUpdate = 32;
		m_vopmd.iUpsampling = 32;
		m_vopmd.iIntraBlocks = 171;
		m_vopmd.iNotCodedBlocks = 171;
		m_vopmd.iDCTCoefs = 215;
		m_vopmd.iDCTLines = 187;
		m_vopmd.iVLCSymbols = 187;
		m_vopmd.iVLCBits = 10;
		m_vopmd.iInterBlocks = 77;
		m_vopmd.iInter4vBlocks = 111;
		m_vopmd.iAPM = 110;
		m_vopmd.iNPM = 103;
		m_vopmd.iForwBackMCQ = 101;
		m_vopmd.iHalfpel2 = 110;
		m_vopmd.iHalfpel4 = 101;
		m_vopmd.iInterpolateMCQ = 116;

		if (m_vopmd.vopPredType == IVOP ||
			m_vopmd.vopPredType == PVOP ||
			m_vopmd.vopPredType == BVOP)
		{	
			if (m_volmd.bOpaque) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iOpaque, 8), 8, "dcecs_opaque");
				m_statsVOP.nBitsHead += 8;
			}
			if (m_volmd.bTransparent) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iTransparent, 8), 8, "dcecs_transparent");
				m_statsVOP.nBitsHead += 8;
			}
			if (m_volmd.bIntraCAE) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iIntraCAE, 8), 8 , "dcecs_intra_cae");
				m_statsVOP.nBitsHead += 8;
			}
			if (m_volmd.bInterCAE) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iInterCAE, 8), 8 , "dcecs_inter_cae");
				m_statsVOP.nBitsHead += 8;
			}
			if (m_volmd.bNoUpdate) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iNoUpdate, 8), 8 , "dcecs_no_update");
				m_statsVOP.nBitsHead += 8;
			}
			if (m_volmd.bUpsampling) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iUpsampling, 8), 8 , "dcecs_upsampling");
				m_statsVOP.nBitsHead += 8;
			}
		}
		
		if (m_volmd.bIntraBlocks) {
			m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iIntraBlocks, 8), 8 , "dcecs_intra_blocks");
			m_statsVOP.nBitsHead += 8;
		}
		if (m_volmd.bNotCodedBlocks) {
			m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iNotCodedBlocks, 8), 8 , "dcecs_not_coded_blocks");
			m_statsVOP.nBitsHead += 8;
		}
		if (m_volmd.bDCTCoefs) {
			m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iDCTCoefs, 8), 8 , "dcecs_dct_coefs");
			m_statsVOP.nBitsHead += 8;
		}
		if (m_volmd.bDCTLines) {
			m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iDCTLines, 8), 8 , "dcecs_dct_lines");
			m_statsVOP.nBitsHead += 8;
		}
		if (m_volmd.bVLCSymbols) {
			m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iVLCSymbols, 8), 8 , "dcecs_vlc_symbols");
			m_statsVOP.nBitsHead += 8;
		}
		if (m_volmd.bVLCBits) {
			m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iVLCBits, 4), 4, "dcecs_vlc_bits");
			m_statsVOP.nBitsHead += 4;
		}
		
		if (m_vopmd.vopPredType == PVOP ||
			m_vopmd.vopPredType == BVOP ||
			m_vopmd.vopPredType == SPRITE)
		{	
			if (m_volmd.bInterBlocks) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iInterBlocks, 8), 8 , "dcecs_inter_blocks");
				m_statsVOP.nBitsHead += 8;
			}
			if (m_volmd.bInter4vBlocks) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iInter4vBlocks, 8), 8 , "dcecs_inter4v_blocks");
				m_statsVOP.nBitsHead += 8;
			}
			if (m_volmd.bAPM) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iAPM, 8), 8 , "dcecs_apm");
				m_statsVOP.nBitsHead += 8;
			}
			if (m_volmd.bNPM) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iNPM, 8), 8 , "dcecs_npm");
				m_statsVOP.nBitsHead += 8;
			}
			if (m_volmd.bForwBackMCQ) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iForwBackMCQ, 8), 8 , "dcecs_forw_back_mc_q");
				m_statsVOP.nBitsHead += 8;
			}
			if (m_volmd.bHalfpel2) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iHalfpel2, 8), 8 , "dcecs_halfpel2");
				m_statsVOP.nBitsHead += 8;
			}
			if (m_volmd.bHalfpel4) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iHalfpel4, 8), 8 , "dcecs_halfpel4");
				m_statsVOP.nBitsHead += 8;
			}
		}

		if (m_vopmd.vopPredType == BVOP ||
			m_vopmd.vopPredType == SPRITE)
		{	
			if (m_volmd.bInterpolateMCQ) {
				m_pbitstrmOut -> putBits (codedDCECS (m_vopmd.iInterpolateMCQ, 8), 8 , "dcecs_interpolate_mc_q");
				m_statsVOP.nBitsHead += 8;
			}
		}
	}
	// END: Complexity Estimation syntax support

	// Modified for error resilient mode by Toshiba(1998-1-16)
	if(m_volmd.bShapeOnly==TRUE) {
		VideoPacketResetVOP();
		return;
	}

	// End Toshiba(1998-1-16)

	m_pbitstrmOut->putBits (m_vopmd.iIntraDcSwitchThr, 3, "IntraDCSwitchThr");
	m_statsVOP.nBitsHead+=3;

// INTERLACE_
	//m_pbitstrmOut->putBits (m_vopmd.bInterlace, 1, "InterlaceEnable");
	//m_statsVOP.nBitsHead++; 
	if (m_vopmd.bInterlace == TRUE) {
		m_pbitstrmOut->putBits (m_vopmd.bTopFieldFirst, 1, "Top_Field_First");
		m_pbitstrmOut->putBits (m_vopmd.bAlternateScan, 1, "Alternate_Scan");
		m_statsVOP.nBitsHead += 2; 
	} else
        m_vopmd.bAlternateScan = FALSE;

// INTERLACE	


	if (m_vopmd.vopPredType == IVOP) {
		m_pbitstrmOut -> putBits (m_vopmd.intStepI, m_volmd.uiQuantPrecision, "VOP_QUANT");
		m_statsVOP.nBitsHead += m_volmd.uiQuantPrecision;
		if(m_volmd.fAUsage == EIGHT_BIT)
		{
			m_pbitstrmOut -> putBits (m_vopmd.intStepIAlpha, NUMBITS_VOP_ALPHA_QUANTIZER, "VOP_GREY_QUANT");
			m_statsVOP.nBitsHead += NUMBITS_VOP_ALPHA_QUANTIZER;
		}
	}
	else if (m_vopmd.vopPredType == PVOP) {
		m_pbitstrmOut -> putBits (m_vopmd.intStep, m_volmd.uiQuantPrecision, "VOP_QUANT");
		m_statsVOP.nBitsHead += m_volmd.uiQuantPrecision;
		if(m_volmd.fAUsage == EIGHT_BIT)
		{
			m_pbitstrmOut -> putBits (m_vopmd.intStepPAlpha, NUMBITS_VOP_ALPHA_QUANTIZER, "VOP_GREY_QUANT");
			m_statsVOP.nBitsHead += NUMBITS_VOP_ALPHA_QUANTIZER;
		}
		m_pbitstrmOut -> putBits (m_vopmd.mvInfoForward.uiFCode, NUMBITS_VOP_FCODE, "VOP_Fcode_Forward");
		m_statsVOP.nBitsHead += NUMBITS_VOP_FCODE;
	}
	else if (m_vopmd.vopPredType == BVOP) {
		m_pbitstrmOut -> putBits (m_vopmd.intStepB, m_volmd.uiQuantPrecision, "VOP_QUANT");
		m_statsVOP.nBitsHead += m_volmd.uiQuantPrecision;
		if(m_volmd.fAUsage == EIGHT_BIT)
		{
			m_pbitstrmOut -> putBits (m_vopmd.intStepBAlpha, NUMBITS_VOP_ALPHA_QUANTIZER, "VOP_GREY_QUANT");
			m_statsVOP.nBitsHead += NUMBITS_VOP_ALPHA_QUANTIZER;
		}
		m_pbitstrmOut -> putBits (m_vopmd.mvInfoForward.uiFCode, NUMBITS_VOP_FCODE, "VOP_Fcode_Forward");
		m_statsVOP.nBitsHead += NUMBITS_VOP_FCODE;
		m_pbitstrmOut -> putBits (m_vopmd.mvInfoBackward.uiFCode, NUMBITS_VOP_FCODE, "VOP_Fcode_Backward");
		m_statsVOP.nBitsHead += NUMBITS_VOP_FCODE;
	}
	// Added for error resilient mode by Toshiba(1997-11-14)
	if(m_volmd.volType != ENHN_LAYER){
		if (m_volmd.fAUsage != RECTANGLE && m_vopmd.vopPredType != IVOP
				&& m_uiSprite != 1)  
		{  
				m_pbitstrmOut -> putBits (m_vopmd.bShapeCodingType, 1, "VOP_shape_coding_type");
				m_statsVOP.nBitsHead++;
		}
		VideoPacketResetVOP();
	}
	else
	{
///// 97/12/22 start
		if( m_volmd.iEnhnType != 0 ){ // modified by Sharp (98/3/24)
			m_pbitstrmOut->putBits (m_vopmd.iLoadBakShape, 1, "load_backward_shape");
			m_statsVOP.nBitsHead ++;
			if(m_vopmd.iLoadBakShape){
				delete rgpbfShape [1]->m_pvopcRefQ1;	
				// previous backward shape is saved to current forward shape
				rgpbfShape [1]->m_pvopcRefQ1 = new CVOPU8YUVBA (*(rgpbfShape [0]->pvopcReconCurr()));
				rgpbfShape [1]->m_rctCurrVOPY.left   = rgpbfShape [0]->m_rctCurrVOPY.left;
				rgpbfShape [1]->m_rctCurrVOPY.right  = rgpbfShape [0]->m_rctCurrVOPY.right;
				rgpbfShape [1]->m_rctCurrVOPY.top    = rgpbfShape [0]->m_rctCurrVOPY.top;
				rgpbfShape [1]->m_rctCurrVOPY.bottom = rgpbfShape [0]->m_rctCurrVOPY.bottom;

				rgpbfShape [0]->findTightBoundingBox ();
				rgpbfShape [0]->findBestBoundingBox ();
				rgpbfShape [0]->m_rctCurrVOPY  = rgpbfShape [0]->m_pvopcOrig->whereBoundY();
				rgpbfShape [0]->m_rctCurrVOPUV = rgpbfShape [0]->m_pvopcOrig->whereBoundUV ();
				rgpbfShape [0]->setRefStartingPointers ();
				rgpbfShape [0]->compute_bfShapeMembers ();

				// backward shape width/height, hori/vert reference
				m_pbitstrmOut->putBits (rgpbfShape [0]->m_rctCurrVOPY.width, NUMBITS_VOP_WIDTH, "back_Width");
				
				m_pbitstrmOut->putBits ((Int) 1, 1, "Marker"); // marker bit
				m_statsVOP.nBitsStuffing ++;
				
				m_pbitstrmOut->putBits (rgpbfShape [0]->m_rctCurrVOPY.height (), NUMBITS_VOP_HEIGHT, "back_Height");
				
				m_pbitstrmOut->putBits ((Int) 1, 1, "Marker"); // marker bit
				m_statsVOP.nBitsStuffing ++;

				Int iSign = (rgpbfShape [0]->m_rctCurrVOPY.left < 0) ? 1 : 0;
				m_pbitstrmOut->putBits (iSign, 1, "back_Hori_Ref_Sgn");
				m_pbitstrmOut->putBits (abs (rgpbfShape [0]->m_rctCurrVOPY.left), NUMBITS_VOP_HORIZONTAL_SPA_REF - 1, "back_Hori_Ref");
				
				m_pbitstrmOut->putBits ((Int) 1, 1, "Marker"); // marker bit
				m_statsVOP.nBitsStuffing++;

				iSign = (rgpbfShape [0]->m_rctCurrVOPY.top < 0) ? 1 : 0;
				m_pbitstrmOut->putBits (iSign, 1, "back_Vert_Ref_Sgn");
				m_pbitstrmOut->putBits (abs (rgpbfShape [0]->m_rctCurrVOPY.top), NUMBITS_VOP_VERTICAL_SPA_REF - 1, "back_Vert_Ref");
				m_statsVOP.nBitsHead += NUMBITS_VOP_WIDTH + NUMBITS_VOP_HEIGHT 
					+ NUMBITS_VOP_HORIZONTAL_SPA_REF + NUMBITS_VOP_VERTICAL_SPA_REF;
				
				rgpbfShape [0]->resetBYPlane ();

				printf("================ backward shape coding\n");
				rgpbfShape [0]->m_volmd.bShapeOnly = TRUE;
				rgpbfShape [0]->encodeNSForIVOP_WithShape ();

				// backward shape coding

				m_pbitstrmOut->putBits (m_vopmd.iLoadForShape, 1, "load_forward_shape");
				m_statsVOP.nBitsHead++;
				if(m_vopmd.iLoadForShape){
					rgpbfShape [1]->findTightBoundingBox ();
					rgpbfShape [1]->findBestBoundingBox ();
					rgpbfShape [1]->m_rctCurrVOPY  = rgpbfShape [1]->m_pvopcOrig->whereBoundY ();
					rgpbfShape [1]->m_rctCurrVOPUV = rgpbfShape [1]->m_pvopcOrig->whereBoundUV ();
					rgpbfShape [1]->setRefStartingPointers ();
					rgpbfShape [1]->compute_bfShapeMembers ();

					// forward shape width/height, hori/vert reference
					m_pbitstrmOut->putBits (rgpbfShape [1]->m_rctCurrVOPY.width, NUMBITS_VOP_WIDTH, "for_Width"); 
				
					m_pbitstrmOut->putBits ((Int) 1, 1, "Marker"); // marker bit
					m_statsVOP.nBitsStuffing ++;
					
					m_pbitstrmOut->putBits (rgpbfShape [1]->m_rctCurrVOPY.height (), NUMBITS_VOP_HEIGHT, "for_Height");
					
					m_pbitstrmOut->putBits ((Int) 1, 1, "Marker"); // marker bit
					m_statsVOP.nBitsStuffing ++;
					
					Int iSign = (rgpbfShape [1]->m_rctCurrVOPY.left < 0) ? 1 : 0;
					m_pbitstrmOut->putBits (iSign, 1, "for_Hori_Ref_Sgn");
					m_pbitstrmOut->putBits (abs (rgpbfShape [1]->m_rctCurrVOPY.left), NUMBITS_VOP_HORIZONTAL_SPA_REF - 1, "for_Hori_Ref");
					
					m_pbitstrmOut->putBits ((Int) 1, 1, "Marker"); // marker bit
					m_statsVOP.nBitsStuffing++;

					iSign = (rgpbfShape [1]->m_rctCurrVOPY.top < 0) ? 1 : 0;
					m_pbitstrmOut->putBits (iSign, 1, "for_Vert_Ref_Sgn");
					m_pbitstrmOut->putBits (abs (rgpbfShape [1]->m_rctCurrVOPY.top), NUMBITS_VOP_VERTICAL_SPA_REF - 1, "for_Vert_Ref");
					m_statsVOP.nBitsHead += NUMBITS_VOP_WIDTH + NUMBITS_VOP_HEIGHT 
						+ NUMBITS_VOP_HORIZONTAL_SPA_REF + NUMBITS_VOP_VERTICAL_SPA_REF;

					rgpbfShape [1]->resetBYPlane ();

					printf("================ forward shape coding\n");
					rgpbfShape [1]->m_volmd.bShapeOnly = TRUE;
					rgpbfShape [1]->encodeNSForIVOP_WithShape ();
					// forward shape coding
				}
			} // end of "if (m_vopmd.iLoadBakShape)"
		} // end of "if (iEnhnType == 1)"
///// 97/12/22 end
		m_pbitstrmOut->putBits(m_vopmd.iRefSelectCode, 2, "RefSelectCode");
		m_statsVOP.nBitsHead +=2;
	}
	// End Toshiba(1997-11-14)
}

Void CVideoObjectEncoder::decideMVInfo ()
{
	assert (m_vopmd.iSearchRangeForward <= 1024);		//seems a reasonable constraint
	assert (m_vopmd.iSearchRangeBackward <= 1024);		//seems a reasonable constraint

	if(m_vopmd.iSearchRangeForward <= 16)
		m_vopmd.mvInfoForward.uiFCode = 1;
	else if(m_vopmd.iSearchRangeForward <= 32)
		m_vopmd.mvInfoForward.uiFCode = 2;
	else if(m_vopmd.iSearchRangeForward <= 64)
		m_vopmd.mvInfoForward.uiFCode = 3;
	else if(m_vopmd.iSearchRangeForward <= 128)
		m_vopmd.mvInfoForward.uiFCode = 4;
	else if(m_vopmd.iSearchRangeForward <= 256)
		m_vopmd.mvInfoFo

⌨️ 快捷键说明

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