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

📄 vopseenc.cpp

📁 网络MPEG4IP流媒体开发源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*************************************************************************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 Laboratories	Marc Mongenet (Marc.Mongenet@epfl.ch), Swiss Federal Institute of Technology, Lausanne (EPFL)and also edited by	Yoshinori Suzuki (Hitachi, Ltd.)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:	vopSeEnc.hppAbstract:	Encoder for one VO.Revision History:	Sept. 30, 1997: Error resilient tools added by Toshiba	Dec.  11, 1997:	Interlaced tools added by NextLevel Systems					X. Chen, xchen@nlvl.com B. Eifrig, beifrig@nlvl.com	Jun.  16, 1998: add Complexity Estimation syntax support					Marc Mongenet (Marc.Mongenet@epfl.ch) - EPFL	Jan.  28, 1999: Rounding control parameters added by Hitachi, Ltd.	May    9, 1999:	tm5 rate control by DemoGraFX, duhoff@mediaone.net*************************************************************************/#include <stdio.h>#include <iostream.h>#include <fstream.h>#include <math.h>#include <stdlib.h>#include "typeapi.h"#include "codehead.h"#include "global.hpp"#include "entropy/bitstrm.hpp"#include "entropy/entropy.hpp"#include "entropy/huffman.hpp"#include "mode.hpp"#include "dct.hpp"#include "tps_enhcbuf.hpp" // added by Sharp (98/2/12)#include "vopses.hpp"#include "vopseenc.hpp"#include "enhcbufenc.hpp" // added by Sharp (98/2/12)#include "cae.h" // Added for error resilient mode by Toshiba(1997-11-14)#ifdef __MFC_#ifdef _DEBUG#undef THIS_FILEstatic char BASED_CODE THIS_FILE[] = __FILE__;#endif#define new DEBUG_NEW				   #endif // __MFC_CVideoObjectEncoder::~CVideoObjectEncoder (){	delete m_pvopcOrig;	delete m_pvopcRefOrig1;	delete m_pvopcRefOrig0;	delete m_puciRefQZoom0;	delete m_puciRefQZoom1;	delete m_pfdct;	delete [] m_rgdSNR;	// bitstream stuff	delete [] m_pchBitsBuffer; 	delete m_pbitstrmOut;	delete m_pentrencSet;	delete [] m_pchShapeBitsBuffer;	delete m_pbitstrmShape;//	Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)	delete [] *m_pchShapeBitsBuffer_DP;	delete [] *m_pbitstrmShape_DP;	delete m_pchShapeBitsBuffer_DP;	delete m_pbitstrmShape_DP;//	End Toshiba(1998-1-16)	// shape	delete [] m_rgiSubBlkIndx16x16;	delete [] m_rgiSSubBlkIndx16x16;	delete [] m_rgiSubBlkIndx18x18;	delete [] m_rgiSubBlkIndx20x20;	delete [] m_rgiPxlIndx12x12;	delete [] m_rgiPxlIndx8x8;	// B-VOP MB buffer	delete m_puciDirectPredMB;	delete m_puciInterpPredMB;	delete m_piiDirectErrorMB; 	delete m_piiInterpErrorMB; }CVideoObjectEncoder::CVideoObjectEncoder (	UInt uiVOId, 	VOLMode& volmd, 	VOPMode& vopmd, 	UInt nFirstFrame,	UInt nLastFrame,	Int iSessionWidth,	Int iSessionHeight,	UInt uiRateControl,	UInt uiBudget,	ostream* pstrmTrace, // trace outstream	UInt uiWarpingAccuracy, // for sprite warping	Int iNumOfPnts, // for sprite warping	CSiteD** rgstDest, // for sprite warping destination	SptMode SpriteMode,					// sprite reconstruction mode	CRct rctFrame,						// sprite warping source    CRct rctSpt,     	// rct sprite	Int iMVFileUsage,	Char* pchMVFileName) :	CVideoObject (),	m_nFirstFrame (nFirstFrame), m_nLastFrame (nLastFrame), 	m_iBufferSize (uiBudget), m_uiRateControl (uiRateControl),	m_pvopcOrig (NULL),	m_rgiSubBlkIndx16x16 (NULL),	m_rgiSSubBlkIndx16x16 (NULL),	m_rgiSubBlkIndx18x18 (NULL),	m_rgiSubBlkIndx20x20 (NULL),	m_rgiPxlIndx12x12 (NULL),	m_rgiPxlIndx8x8 (NULL){	m_ivolWidth = iSessionWidth;	m_ivolHeight = iSessionHeight;					// sprite stuff	if (iNumOfPnts >= 0) {		m_uiSprite = 1;		m_uiWarpingAccuracy = uiWarpingAccuracy;		m_iNumOfPnts = iNumOfPnts;		m_rgstSrcQ = new CSiteD [m_iNumOfPnts];		m_rgstDstQ = new CSiteD [m_iNumOfPnts];		m_rctSpt = rctSpt;		//#ifdef __LOW_LATENCY_SPRITE_		m_pprgstDest = rgstDest;		m_sptMode = SpriteMode ;		m_rctOrg = 	rctFrame;		m_rctDisplayWindow = m_rctOrg;	//only used for sprite, will be combined with Org later	}	else 		m_uiSprite = 0;	m_pchBitsBuffer = new Char [iSessionWidth * iSessionHeight * 2];	//we think this is enof for 4:2:0; if crushes, increase the buffer	m_pbitstrmOut = new COutBitStream (m_pchBitsBuffer, 0, pstrmTrace);	m_pentrencSet = new CEntropyEncoderSet (*m_pbitstrmOut);	// shape cache	m_pchShapeBitsBuffer = new Char [MB_SIZE * MB_SIZE * 2]; // same as above	m_pbitstrmShape = new COutBitStream (m_pchShapeBitsBuffer, 0, pstrmTrace);	m_pbitstrmShapeMBOut = m_pbitstrmOut; // initially the output stream (only changes for inter)	m_uiVOId = uiVOId;	m_volmd = volmd;	// NBIT: set right clip table	setClipTab();	Int iClockRate = m_volmd.iClockRate;	assert (iClockRate >= 1 && iClockRate < 65536);	for (m_iNumBitsTimeIncr = 1; m_iNumBitsTimeIncr < NUMBITS_TIME_RESOLUTION; m_iNumBitsTimeIncr++)	{			if (iClockRate == 1)						break;		iClockRate = (iClockRate >> 1);	}	m_vopmd = vopmd;//	decideMVInfo ();                // MV search radius now varys with GOP	m_vopmd.iRoundingControlEncSwitch = m_volmd.iInitialRoundingType;	if(!m_volmd.bRoundingControlDisable)		m_vopmd.iRoundingControlEncSwitch ^= 0x00000001;	m_vopmd.iRoundingControl = m_vopmd.iRoundingControlEncSwitch;	Int iMod = iSessionWidth % MB_SIZE;	Int iSessionWidthRound = (iMod > 0) ? iSessionWidth + MB_SIZE - iMod : iSessionWidth;	iMod = iSessionHeight % MB_SIZE;	Int iSessionHeightRound = (iMod > 0) ? iSessionHeight + MB_SIZE - iMod : iSessionHeight;//	Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)	Int iMB;	Int iMBN = (iSessionWidthRound/MB_SIZE)*(iSessionHeightRound/MB_SIZE);	m_pchShapeBitsBuffer_DP = new Char* [iMBN];	m_pbitstrmShape_DP = new COutBitStream* [iMBN];	for (iMB = 0; iMB < iMBN; iMB++) {		m_pchShapeBitsBuffer_DP[iMB] = new Char [MB_SIZE * MB_SIZE * 2]; // same as above		m_pbitstrmShape_DP[iMB] = new COutBitStream (m_pchShapeBitsBuffer_DP[iMB], 0, pstrmTrace);	}// End Toshiba(1998-1-16:DP+RVLC)	m_rctRefFrameY = CRct (		-EXPANDY_REF_FRAME, -EXPANDY_REF_FRAME, 		EXPANDY_REF_FRAME + iSessionWidthRound, EXPANDY_REF_FRAME + iSessionHeightRound	);	m_rctRefFrameUV = m_rctRefFrameY.downSampleBy2 ();	m_pvopcOrig = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctRefFrameY);	m_pvopcRefOrig0 = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctRefFrameY);	m_pvopcRefOrig1 = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctRefFrameY);	allocateVOLMembers (iSessionWidthRound, iSessionHeightRound);    //#ifdef __LOW_LATENCY_SPRITE_	// identify initial sprite piece	if ((m_uiSprite == 1) && (m_sptMode != BASIC_SPRITE) ){		initialSpritePiece (iSessionWidthRound, iSessionHeightRound);	}    CRct rctFrameZoom = m_rctRefFrameY.upSampleBy2 ();	m_puciRefQZoom0 = new CU8Image (rctFrameZoom);	m_puciRefQZoom1 = new CU8Image (rctFrameZoom);	m_pfdct = new CFwdBlockDCT(volmd.nBits);	// B-VOP MB buffer	m_puciDirectPredMB = new CU8Image (CRct (0, 0, MB_SIZE, MB_SIZE));	m_puciInterpPredMB = new CU8Image (CRct (0, 0, MB_SIZE, MB_SIZE));	m_ppxlcDirectPredMBY = (PixelC*) m_puciDirectPredMB->pixels (); 	m_ppxlcInterpPredMBY = (PixelC*) m_puciInterpPredMB->pixels (); 	m_piiDirectErrorMB = new CIntImage (CRct (0, 0, MB_SIZE, MB_SIZE)); 	m_piiInterpErrorMB = new CIntImage (CRct (0, 0, MB_SIZE, MB_SIZE)); 	m_ppxliDirectErrorMBY = (PixelI*) m_piiDirectErrorMB->pixels (); 	m_ppxliInterpErrorMBY = (PixelI*) m_piiInterpErrorMB->pixels (); 	// with shape	if (m_volmd.fAUsage != RECTANGLE) {		m_rgiSubBlkIndx16x16 = computeShapeSubBlkIndex (4, 16);		m_rgiSSubBlkIndx16x16 = computeShapeSubBlkIndex (2, 16);		m_rgiSubBlkIndx18x18 = computeShapeSubBlkIndex (4, 18);		m_rgiSubBlkIndx20x20 = computeShapeSubBlkIndex (4, 20);		m_rgiPxlIndx12x12 = new Int [8 * 8];				Int* piPxl = m_rgiPxlIndx12x12;		UInt i, j;		for (i = 2; i < 10; i++)			for (j = 2; j < 10; j++)				*piPxl++ = i * 12 + j;		m_rgiPxlIndx8x8 = new Int [4 * 4];				piPxl = m_rgiPxlIndx8x8;		for (i = 2; i < 6; i++)			for (j = 2; j < 6; j++)				*piPxl++ = i * 8 + j;	}	m_statsVOL.reset ();	codeVOHead ();	codeVOLHead (iSessionWidth, iSessionHeight);//, rctSprite);	// 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)	m_statsVOL.nBitsStuffing += m_pbitstrmOut->flush ();	m_statRC.resetSkipMode ();	m_rgdSNR = (m_volmd.fAUsage == EIGHT_BIT) ? new Double [4] : new Double [3];	// some fixed variables		m_iFrameWidthZoomY = m_iFrameWidthY * 2;	m_iFrameWidthZoomUV = m_iFrameWidthUV * 2;	m_iFrameWidthZoomYx2Minus2MB = m_iFrameWidthY * 2 * 2 - 2 * MB_SIZE;	m_iFrameWidthZoomYx2Minus2Blk = m_iFrameWidthY * 2 * 2 - 2 * BLOCK_SIZE;	if (m_volmd.fAUsage == RECTANGLE) {		m_rctCurrVOPY = CRct (0, 0, iSessionWidthRound, iSessionHeightRound);		m_pvopcOrig->setBoundRct (m_rctCurrVOPY);		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;				m_rctRefVOPZoom0 = m_rctRefVOPY0.upSampleBy2 ();		m_rctRefVOPZoom1 = m_rctRefVOPY1.upSampleBy2 ();		m_pvopcRefOrig0->setBoundRct (m_rctRefVOPY0);		m_pvopcRefOrig1->setBoundRct (m_rctRefVOPY1);// dshu: begin of modification	if ((m_uiSprite == 0) || ((m_uiSprite == 1) && (m_sptMode == BASIC_SPRITE)) )	// dshu: end of modification		computeVOLConstMembers (); // these VOP members are the same for all frames	}	m_vopmd.SpriteXmitMode = STOP ;	    // tentative solution for indicating the first Sprite VOP    tentativeFirstSpriteVop = 0;	// Open motion vector file if used	m_pchMVFileName = pchMVFileName;	m_iMVFileUsage = iMVFileUsage;	if (m_iMVFileUsage != 0) { // wmay - changed from =		m_fMVFile = fopen(m_pchMVFileName, (m_iMVFileUsage == 1) ? "r" : "w");		assert(m_fMVFile != NULL);		m_iMVLineNo = 0;	}}// for back/forward shapeCVideoObjectEncoder::CVideoObjectEncoder (	UInt uiVOId, 	VOLMode& volmd, 	VOPMode& vopmd,	Int iSessionWidth,	Int iSessionHeight

⌨️ 快捷键说明

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