📄 vopses.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
(date: March, 1996)
and edited by
Wei Wu (weiwu@stallion.risc.rockwell.com) Rockwell Science Center
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:
vopSes.cpp
Abstract:
Base class for the encoder for one VOP session.
Revision History:
December 20, 1997: Interlaced tools added by NextLevel Systems (GI)
X.Chen (xchen@nlvl.com), B. Eifrig (beifrig@nlvl.com)
May. 9 1998: add boundary by Hyundai Electronics
Cheol-Soo Park (cspark@super5.hyundai.co.kr)
May. 9 1998: add field based unrestricted MC padding by Hyundai Electronics
Cheol-Soo Park (cspark@super5.hyundai.co.kr)
*************************************************************************/
#include <stdio.h>
#include "typeapi.h"
#include "basic.hpp"
#include "header.h"
#include "codehead.h"
#include "mode.hpp"
#include "dct.hpp"
#include "cae.h"
#include "vopses.hpp"
#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
#endif // __MFC_
CVideoObject::~CVideoObject ()
{
delete m_pvopcCurrQ;
delete m_pvopcRefQ0;
delete m_pvopcRefQ1; // modified by Shu 12/12/97
// wchen: unmodified 12/16/97
delete m_pvopcCurrMB;
delete m_pvopcPredMB;
delete m_pvopiErrorMB;
delete [] m_rgmbmd;
delete [] m_rgmv;
delete [] m_rgmvBY;
delete [] m_rgmvRef;
delete m_pidct;
Int nBlk = (m_volmd.fAUsage == EIGHT_BIT) ? 10 : 6;
Int iBlk;
for (iBlk = 0; iBlk < nBlk; iBlk++)
delete [] m_rgpiCoefQ [iBlk];
delete [] m_rgpiCoefQ;
// delete m_pvopfCurrFilteredQ;
// delete m_pdrtmdRef1;
delete [] m_rgiQPpred;
if (m_volmd.fAUsage == RECTANGLE) {
Int nBlk = (m_volmd.fAUsage == EIGHT_BIT) ? 10 : 6;
delete [] m_rgblkmCurrMB;
if (m_rgpmbmAbove != NULL)
for (Int iMB = 0; iMB < m_iNumMBX; iMB++) {
for (iBlk = 0; iBlk < nBlk; iBlk++) {
delete [] (m_rgpmbmAbove [iMB]->rgblkm) [iBlk];
delete [] (m_rgpmbmCurr [iMB]->rgblkm) [iBlk];
}
delete [] m_rgpmbmAbove [iMB]->rgblkm;
delete m_rgpmbmAbove [iMB];
delete [] m_rgpmbmCurr [iMB]->rgblkm;
delete m_rgpmbmCurr [iMB];
}
delete [] m_rgpmbmAbove;
delete [] m_rgpmbmCurr;
}
// sprite
if (m_uiSprite == 1) {
delete [] m_rgstSrcQ;
delete [] m_rgstDstQ;
if (m_sptMode == BASIC_SPRITE)
delete m_pvopcSptQ;
}
delete m_pbEmptyRowArray;
/* NBIT: change
m_rgiClipTab -= 400;
*/
m_rgiClipTab -= m_iOffset;
delete [] m_rgiClipTab;
m_rgiClipTab = NULL;
// shape
if(m_rgshpmd!=NULL)
delete m_rgshpmd;
delete m_puciPredBAB;
delete m_parcodec;
delete [] m_ppxlcCurrMBBYDown4;
delete [] m_ppxlcCurrMBBYDown2;
delete [] m_ppxlcReconCurrBAB;
delete [] m_ppxlcPredBABDown2;
delete [] m_ppxlcPredBABDown4;
}
CVideoObject::CVideoObject ()
{
m_t = 0;
m_iBCount = 0;
m_tPastRef = 0;
m_tFutureRef = 0;
m_bCodedFutureRef = TRUE;
m_rgmbmd = NULL;
m_rgmv = NULL;
m_rgmvBackward = NULL;
m_rgmvBY = NULL;
m_rgmbmdRef = NULL;
m_rgmvRef = NULL;
m_tModuloBaseDecd = 0;
m_tModuloBaseDisp = 0;
m_pvopcCurrQ = NULL;
m_pvopcRefQ0 = NULL;
m_pvopcRefQ1 = NULL;
m_puciPredBAB = NULL;
m_ppxlcReconCurrBAB = NULL;
m_parcodec = NULL;
m_ppxlcCurrMBBYDown4 = NULL;
m_ppxlcCurrMBBYDown2 = NULL;
m_ppxlcPredBABDown4 = NULL;
m_ppxlcPredBABDown2 = NULL;
m_pvopcSptQ = NULL;
m_uiSprite = 0;
m_rgstSrcQ = NULL;
m_rgstDstQ = NULL;
m_iOffsetForPadY = 0;
m_iOffsetForPadUV = 0;
m_rgshpmd = NULL;
m_pbEmptyRowArray = new Bool [MB_SIZE];
/* NBIT: replaced by setClipTab() function
m_rgiClipTab = new U8 [1024];
m_rgiClipTab += 400;
Int i;
for (i = -400; i < 624; i++)
m_rgiClipTab [i] = (i < 0) ? 0 : (i > 255) ? 255 : i;
*/
}
// NBIT: added function
Void CVideoObject::setClipTab()
{
Int TabSize = 1<<(m_volmd.nBits+2);
Int maxVal = (1<<m_volmd.nBits)-1;
m_iOffset = TabSize/2;
m_rgiClipTab = new PixelC [TabSize];
m_rgiClipTab += m_iOffset;
Int i;
for (i = -m_iOffset; i < m_iOffset; i++)
m_rgiClipTab [i] = (i < 0) ? 0 : (i > maxVal) ? maxVal : i;
}
Void CVideoObject::allocateVOLMembers (Int iSessionWidth, Int iSessionHeight)
{
m_pvopcCurrMB = new CVOPU8YUVBA (m_volmd.fAUsage, CRct (0, 0, MB_SIZE, MB_SIZE));
m_ppxlcCurrMBY = (PixelC*) m_pvopcCurrMB->pixelsY ();
m_ppxlcCurrMBU = (PixelC*) m_pvopcCurrMB->pixelsU ();
m_ppxlcCurrMBV = (PixelC*) m_pvopcCurrMB->pixelsV ();
m_ppxlcCurrMBBY = (PixelC*) m_pvopcCurrMB->pixelsBY ();
m_ppxlcCurrMBBUV = (PixelC*) m_pvopcCurrMB->pixelsBUV ();
m_ppxlcCurrMBA = (PixelC*) m_pvopcCurrMB->pixelsA ();
m_pvopcPredMB = new CVOPU8YUVBA (m_volmd.fAUsage, CRct (0, 0, MB_SIZE, MB_SIZE));
m_ppxlcPredMBY = (PixelC*) m_pvopcPredMB->pixelsY ();
m_ppxlcPredMBU = (PixelC*) m_pvopcPredMB->pixelsU ();
m_ppxlcPredMBV = (PixelC*) m_pvopcPredMB->pixelsV ();
m_ppxlcPredMBA = (PixelC*) m_pvopcPredMB->pixelsA ();
// B-VOP MB buffer data
m_pvopcPredMBBack = new CVOPU8YUVBA (m_volmd.fAUsage, CRct (0, 0, MB_SIZE, MB_SIZE));
m_ppxlcPredMBBackY = (PixelC*) m_pvopcPredMBBack->pixelsY ();
m_ppxlcPredMBBackU = (PixelC*) m_pvopcPredMBBack->pixelsU ();
m_ppxlcPredMBBackV = (PixelC*) m_pvopcPredMBBack->pixelsV ();
m_ppxlcPredMBBackA = (PixelC*) m_pvopcPredMBBack->pixelsA ();
m_pvopiErrorMB = new CVOPIntYUVBA (m_volmd.fAUsage, CRct (0, 0, MB_SIZE, MB_SIZE));
m_ppxliErrorMBY = (PixelI*) m_pvopiErrorMB->getPlane (Y_PLANE)->pixels ();
m_ppxliErrorMBU = (PixelI*) m_pvopiErrorMB->getPlane (U_PLANE)->pixels ();
m_ppxliErrorMBV = (PixelI*) m_pvopiErrorMB->getPlane (V_PLANE)->pixels ();
m_ppxliErrorMBA = (PixelI*) m_pvopiErrorMB->getPlane (A_PLANE)->pixels ();
if (m_uiSprite == 0)
m_pvopcCurrQ = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctRefFrameY);
else //for sprite m_rctRefFrameY is for whole sprite, m_rctOrg is the display window
// dshu: begin of modification
// m_pvopcCurrQ = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctDisplayWindow);
{
CRct rctCurrQ = CRct (
-EXPANDY_REF_FRAME, -EXPANDY_REF_FRAME,
EXPANDY_REF_FRAME + m_rctDisplayWindow.width, EXPANDY_REF_FRAME + m_rctDisplayWindow.height()
);
m_pvopcCurrQ = new CVOPU8YUVBA (m_volmd.fAUsage, rctCurrQ);
}
// dshu: end of modification
assert (m_pvopcCurrQ != NULL);
m_pvopcRefQ0 = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctRefFrameY);
assert (m_pvopcRefQ0 != NULL);
m_pvopcRefQ1 = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctRefFrameY);
assert (m_pvopcRefQ1 != NULL);
m_iFrameWidthY = m_pvopcRefQ0->whereY ().width;
m_iFrameWidthUV = m_pvopcRefQ0->whereUV ().width;
m_iFrameWidthYxMBSize = MB_SIZE * m_pvopcRefQ0->whereY ().width;
m_iFrameWidthYxBlkSize = BLOCK_SIZE * m_pvopcRefQ0->whereY ().width;
m_iFrameWidthUVxBlkSize = BLOCK_SIZE * m_pvopcRefQ0->whereUV ().width;
// MB data
Int nBlk = (m_volmd.fAUsage == EIGHT_BIT) ? 10 : 6;
m_rgpiCoefQ = new Int* [nBlk];
m_rgiQPpred = new Int [nBlk];
Int iBlk;
for (iBlk = 0; iBlk < nBlk; iBlk++)
m_rgpiCoefQ [iBlk] = new Int [BLOCK_SQUARE_SIZE];
/* NBIT: change
m_pidct = new CInvBlockDCT;
*/
m_pidct = new CInvBlockDCT(m_volmd.nBits);
// motion vectors and MBMode
Int iNumMBX = iSessionWidth / MB_SIZE;
if (iSessionWidth % MB_SIZE != 0) //round up
iNumMBX++;
Int iNumMBY = iSessionHeight / MB_SIZE;
if (iSessionHeight % MB_SIZE != 0) //deal with frational MB
iNumMBY++;
Int iNumMB = m_iSessNumMB = iNumMBX * iNumMBY;
m_rgmbmd = new CMBMode [iNumMB];
m_rgmv = new CMotionVector [max(PVOP_MV_PER_REF_PER_MB, 2*BVOP_MV_PER_REF_PER_MB) * iNumMB];
m_rgmvBackward = m_rgmv + BVOP_MV_PER_REF_PER_MB * m_iSessNumMB;
m_rgmvRef = new CMotionVector [max(PVOP_MV_PER_REF_PER_MB, 2*BVOP_MV_PER_REF_PER_MB) * iNumMB];
m_rgmvBY = new CMotionVector [iNumMB]; // for shape
m_rgmbmdRef = new CMBMode [iNumMB];
if (m_volmd.volType == ENHN_LAYER)
m_rgshpmd = new ShapeMode [iNumMB];
// shape data
if (m_volmd.fAUsage != RECTANGLE) {
m_puciPredBAB = new CU8Image (CRct (0, 0, MC_BAB_SIZE, MC_BAB_SIZE));
m_ppxlcReconCurrBAB = new PixelC [BAB_SIZE * BAB_SIZE];
m_parcodec = new ArCodec;
m_ppxlcCurrMBBYDown4 = new PixelC [8 * 8];
m_ppxlcCurrMBBYDown2 = new PixelC [12 * 12];
m_ppxlcPredBABDown4 = new PixelC [6*6];
m_ppxlcPredBABDown2 = new PixelC [10*10];
}
}
Void CVideoObject::computeVOLConstMembers ()
{
m_iOffsetForPadY = m_rctRefFrameY.offset (m_rctCurrVOPY.left, m_rctCurrVOPY.top);
m_iOffsetForPadUV = m_rctRefFrameUV.offset (m_rctCurrVOPUV.left, m_rctCurrVOPUV.top);
m_rctPrevNoExpandY = m_rctCurrVOPY;
m_rctPrevNoExpandUV = m_rctCurrVOPUV;
m_iVOPWidthY = m_rctCurrVOPY.width;
m_iVOPWidthUV = m_rctCurrVOPUV.width;
m_iNumMBX = m_iNumMBXRef = m_iVOPWidthY / MB_SIZE;
m_iNumMBY = m_iNumMBYRef = m_rctCurrVOPY.height () / MB_SIZE;
m_iNumMB = m_iNumMBRef = m_iNumMBX * m_iNumMBY;
m_iNumOfTotalMVPerRow = PVOP_MV_PER_REF_PER_MB * m_iNumMBX;
setRefStartingPointers ();
m_pvopcCurrQ->setBoundRct (m_rctCurrVOPY);
m_pvopcRefQ0->setBoundRct (m_rctRefVOPY0);
m_pvopcRefQ1->setBoundRct (m_rctRefVOPY1);
Int iMB, iBlk;
Int nBlk = (m_volmd.fAUsage == EIGHT_BIT) ? 10 : 6;
m_rgblkmCurrMB = new BlockMemory [nBlk];
m_rgpmbmAbove = new MacroBlockMemory* [m_iNumMBX];
m_rgpmbmCurr = new MacroBlockMemory* [m_iNumMBX];
for (iMB = 0; iMB < m_iNumMBX; iMB++) {
m_rgpmbmAbove [iMB] = new MacroBlockMemory;
m_rgpmbmAbove [iMB]->rgblkm = new BlockMemory [nBlk];
m_rgpmbmCurr [iMB] = new MacroBlockMemory;
m_rgpmbmCurr [iMB]->rgblkm = new BlockMemory [nBlk];
for (iBlk = 0; iBlk < nBlk; iBlk++) {
(m_rgpmbmAbove [iMB]->rgblkm) [iBlk] = new Int [(BLOCK_SIZE << 1) - 1];
(m_rgpmbmCurr [iMB]->rgblkm) [iBlk] = new Int [(BLOCK_SIZE << 1) - 1];
}
}
}
Void CVideoObject::computeVOPMembers ()
{
m_iVOPWidthY = m_rctCurrVOPY.width;
m_iVOPWidthUV = m_rctCurrVOPUV.width;
m_iNumMBX = m_iVOPWidthY / MB_SIZE;
m_iNumMBY = m_rctCurrVOPY.height () / MB_SIZE;
m_iNumMB = m_iNumMBX * m_iNumMBY;
m_iNumOfTotalMVPerRow = PVOP_MV_PER_REF_PER_MB * m_iNumMBX;
Int iMB, iBlk;
Int nBlk = (m_volmd.fAUsage == EIGHT_BIT) ? 10 : 6;
m_rgblkmCurrMB = new BlockMemory [nBlk];
m_rgpmbmAbove = new MacroBlockMemory* [m_iNumMBX];
m_rgpmbmCurr = new MacroBlockMemory* [m_iNumMBX];
for (iMB = 0; iMB < m_iNumMBX; iMB++) {
m_rgpmbmAbove [iMB] = new MacroBlockMemory;
m_rgpmbmAbove [iMB]->rgblkm = new BlockMemory [nBlk];
m_rgpmbmCurr [iMB] = new MacroBlockMemory;
m_rgpmbmCurr [iMB]->rgblkm = new BlockMemory [nBlk];
for (iBlk = 0; iBlk < nBlk; iBlk++) {
// BLOCK_SIZE*2-1 is 15 Ints for dc/ac prediction of coefficients
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -