📄 vopseenc.cpp
字号:
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;
}
// NEWPRED
if(m_volmd.bNewpredEnable) {
g_pNewPredEnc->SetObject(
m_iNumBitsTimeIncr,
iSessionWidth,
iSessionHeight,
uiVOId,
m_volmd.cNewpredRefName,
m_volmd.cNewpredSlicePoint,
m_volmd.bNewpredSegmentType,
m_volmd.fAUsage,
m_volmd.bShapeOnly,
m_pvopcRefQ0,
m_pvopcRefQ1,
m_rctRefFrameY,
m_rctRefFrameUV
);
}
// ~NEWPRED
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 [3+m_volmd.iAuxCompCount] : 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;
// RRV insertion
Int iScale = (m_vopmd.RRVmode.iOnOff == 1) ? (2) : (1);
// ~RRV
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;
// 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;
m_rctRefVOPZoom0 = m_rctRefVOPY0.upSampleBy2 ();
m_rctRefVOPZoom1 = m_rctRefVOPY1.upSampleBy2 ();
m_pvopcRefOrig0->setBoundRct (m_rctRefVOPY0);
m_pvopcRefOrig1->setBoundRct (m_rctRefVOPY1);
if ((m_uiSprite == 0) || (m_uiSprite == 2) || ((m_uiSprite == 1) && (m_sptMode == BASIC_SPRITE)) ) // GMC
computeVOLConstMembers (); // these VOP members are the same for all frames
}
//OBSS_SAIT_991015
else if(m_volmd.fAUsage == ONE_BIT && m_volmd.volType == ENHN_LAYER) {
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);
}
//~OBSS_SAIT_991015
m_vopmd.SpriteXmitMode = STOP ;
// tentative solution for indicating the first Sprite VOP
// tentativeFirstSpriteVop = 0;
// Open motion vector file if used
m_pchMVFileName = pchMVFileName;
if (m_iMVFileUsage = iMVFileUsage) {
m_fMVFile = fopen(m_pchMVFileName, (m_iMVFileUsage == 1) ? "r" : "w");
assert(m_fMVFile != NULL);
m_iMVLineNo = 0;
}
}
// for back/forward shape
CVideoObjectEncoder::CVideoObjectEncoder (
UInt uiVOId,
VOLMode& volmd,
VOPMode& vopmd,
Int iSessionWidth,
Int iSessionHeight
) :
CVideoObject (),
m_pvopcOrig (NULL),
m_rgiSubBlkIndx16x16 (NULL),
m_rgiSSubBlkIndx16x16 (NULL),
m_rgiSubBlkIndx18x18 (NULL),
m_rgiSubBlkIndx20x20 (NULL),
m_rgiPxlIndx12x12 (NULL),
m_rgiPxlIndx8x8 (NULL),
m_statsVOL(volmd.iAuxCompCount),
m_statsVOP(volmd.iAuxCompCount),
m_statsMB (volmd.iAuxCompCount)
{
// sprite stuff
m_uiSprite = 0; // sprite off
m_pchBitsBuffer = NULL;
m_pbitstrmOut = NULL;
m_pentrencSet = NULL;
// shape cache
m_pchShapeBitsBuffer = NULL;
m_pbitstrmShape = NULL;
m_pbitstrmShapeMBOut = NULL;
m_uiVOId = uiVOId;
m_volmd = volmd;
m_vopmd = vopmd;
// decideMVInfo ();
m_vopmd.iRoundingControl = 0;
m_vopmd.iRoundingControlEncSwitch = 0;
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;
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_volmd.iAuxCompCount);
m_pvopcRefOrig0 = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctRefFrameY, m_volmd.iAuxCompCount);
m_pvopcRefOrig1 = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctRefFrameY, m_volmd.iAuxCompCount);
allocateVOLMembers (iSessionWidth, iSessionHeight);
CRct rctFrameZoom = m_rctRefFrameY.upSampleBy2 ();
m_puciRefQZoom0 = new CU8Image (rctFrameZoom);
m_puciRefQZoom1 = new CU8Image (rctFrameZoom);
// m_pfdct = new CFwdBlockDCT;
// HHI Schueuer: sadct
if (m_volmd.fAUsage != RECTANGLE && (!m_volmd.bSadctDisable)) {
m_pfdct = new CFwdSADCT();
m_pscanSelector = new CScanSelectorForSADCT(m_rgiCurrMBCoeffWidth);
}
else {
m_pfdct = new CFwdBlockDCT();
m_pscanSelector = new CScanSelector;
}
// end HHI
// 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_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_pvopcRefOrig0->setBoundRct (m_rctRefVOPY0);
m_pvopcRefOrig1->setBoundRct (m_rctRefVOPY1);
computeVOLConstMembers (); // these VOP members are the same for all frames
}
}
Bool CVideoObjectEncoder::skipTest(Time t,VOPpredType vopPredType)
{
if (m_uiRateControl==RC_MPEG4) {
if (!m_statRC.firstFrame ()) {// test whether we should skip this frame
if (m_statRC.skipThisFrame ())
return TRUE;
}
else
m_statRC.resetFirstFrame ();
}
return FALSE;
}
Void CVideoObjectEncoder::encode (
Bool bVOPVisible,
Time t,
VOPpredType vopPredType,
const CVOPU8YUVBA* pvopfRefBaseLayer)
{
m_t = t;
m_vopmd.vopPredType = vopPredType;
// RRV insertion
if(m_vopmd.RRVmode.iOnOff == 1)
{
m_vopmd.RRVmode.iQave = 0;
if(m_statsVOP.nQMB != 0)
{
m_vopmd.RRVmode.iQave = m_statsVOP.nQp /m_statsVOP.nQMB;
}
m_vopmd.RRVmode.iNumBits = m_statsVOP.nBitsTotal;
}
m_iRRVScale = 1; // default value
// ~RRV
m_statsVOP.reset ();
Bool bTemporalScalability = m_volmd.bTemporalScalability; // added by Sharp (98/2/10)
Bool bPrevRefVopWasCoded = m_bCodedFutureRef;
//OBSS_SAIT_991015
if (m_volmd.volType == ENHN_LAYER && m_volmd.fAUsage == ONE_BIT && (m_volmd.bSpatialScalability && m_volmd.iHierarchyType==0) && m_volmd.iuseRefShape ==0 ) {
if (!m_bCodedBaseRef || !bPrevRefVopWasCoded )
m_vopmd.vopPredType = PVOP;
}
//~OBSS_SAIT_991015
//__LOW_LATENCY_SPRITE_
if (m_uiSprite == 1 && m_sptMode != BASIC_SPRITE && m_vopmd.SpriteXmitMode != STOP) {
setRefStartingPointers (); // need to compute the starting pointers of the refVOP's (corresponding to the current Rct)
computeVOPMembers ();
m_iNumSptMB = 0;
encodeVOP ();
}
else {
if (m_uiSprite == 1 && m_t>=0)
m_vopmd.vopPredType = SPRITE;
m_pbitstrmOut->reset ();
cout << "\nVOP " << m_uiVOId << "\n";
cout << "\tVOL " << m_volmd.volType << "\n"; // added by Sharp (98/2/10)
if(m_vopmd.vopPredType==IVOP || m_vopmd.vopPredType==PVOP || ((m_uiSprite == 2) && (m_vopmd.vopPredType == SPRITE))) // GMC
m_bCodedFutureRef = bVOPVisible; // flag used by bvop prediction
//OBSS_SAIT_991015
if (m_volmd.volType == ENHN_LAYER && m_volmd.fAUsage == ONE_BIT && (m_volmd.bSpatialScalability && m_volmd.iHierarchyType==0) && m_volmd.iuseRefShape ==0 )
m_bCodedFutureRef = bVOPVisible; // flag used by OBSS bvop prediction
//~OBSS_SAIT_991015
if(!bVOPVisible)
{
#ifdef __TRACE_AND_STATS_
m_pbitstrmOut -> trace (m_t, "VOP_Time");
#endif // __TRACE_AND_STATS_
codeNonCodedVOPHead ();
cout << "\tTime..." << m_t << " (" << m_t/m_volmd.dFrameHz << " sec)"
<< "\n\tNot coded.\n\n";
cout.flush ();
m_statsVOP.nBitsStuffing += m_pbitstrmOut->flush ();
#ifdef __TRACE_AND_STATS_
m_statsVOP.dSNRY = m_statsVOP.dSNRU = m_statsVOP.dSNRV = 0;
m_statsVOP.print (TRUE);
m_statsVOL += m_statsVOP;
#endif // __TRACE_AND_STATS_
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -