📄 sys_encoder_errenc.cpp
字号:
Int*** iCoefQ_DP = new Int** [m_iNumMB]; // 09/19/99 HHI Schueuer: buffer for rowlength needed by sadct Int*** iRowLength_DP; if (!m_volmd.bSadctDisable) iRowLength_DP = new Int** [m_iNumMB]; else iRowLength_DP = NULL; // end HHI PixelC* ppxlcRefY = (PixelC*) m_pvopcRefQ1->pixelsY () + m_iStartInRefToCurrRctY; PixelC* ppxlcRefU = (PixelC*) m_pvopcRefQ1->pixelsU () + m_iStartInRefToCurrRctUV; PixelC* ppxlcRefV = (PixelC*) m_pvopcRefQ1->pixelsV () + m_iStartInRefToCurrRctUV; PixelC* ppxlcRefBY = (PixelC*) m_pvopcRefQ1->pixelsBY () + m_iStartInRefToCurrRctY; PixelC* ppxlcRefBUV = (PixelC*) m_pvopcRefQ1->pixelsBUV () + m_iStartInRefToCurrRctUV; PixelC* ppxlcOrigY = (PixelC*) m_pvopcOrig->pixelsBoundY (); PixelC* ppxlcOrigU = (PixelC*) m_pvopcOrig->pixelsBoundU (); PixelC* ppxlcOrigV = (PixelC*) m_pvopcOrig->pixelsBoundV (); PixelC* ppxlcOrigBY = (PixelC*) m_pvopcOrig->pixelsBoundBY ();// Added for error resilient mode by Toshiba(1997-11-14) Bool bCodeVPHeaderNext = FALSE; // needed only for OBMC Int iTempVPMBnum = 0; Int iCounter;// End Toshiba(1997-11-14) Bool bRestartDelayedQP = TRUE; Int iMB = 0; for (iMBY = 0; iMBY < m_iNumMBY; iMBY++, y += MB_SIZE) { PixelC* ppxlcRefMBY = ppxlcRefY; PixelC* ppxlcRefMBU = ppxlcRefU; PixelC* ppxlcRefMBV = ppxlcRefV; PixelC* ppxlcRefMBBY = ppxlcRefBY; PixelC* ppxlcRefMBBUV = ppxlcRefBUV; PixelC* ppxlcOrigMBY = ppxlcOrigY; PixelC* ppxlcOrigMBU = ppxlcOrigU; PixelC* ppxlcOrigMBV = ppxlcOrigV; PixelC* ppxlcOrigMBBY = ppxlcOrigBY; CoordI x = m_rctCurrVOPY.left;#ifdef __TRACE_AND_STATS_ m_statsMB.reset ();#endif // __TRACE_AND_STATS_ // initiate advance shape coding // shape bitstream is set to shape cache m_pbitstrmShapeMBOut = m_pbitstrmShape_DP[iMBY * m_iNumMBX]; copyToCurrBuffJustShape (ppxlcOrigMBBY, m_iFrameWidthY); // Modified for error resilient mode by Toshiba(1997-11-14) ShapeMode shpmdColocatedMB; if(m_vopmd.bShapeCodingType) { shpmdColocatedMB = m_rgmbmdRef [ min (max (0, iMBY), m_iNumMBYRef - 1) * m_iNumMBXRef].m_shpmd; encodePVOPMBJustShape(ppxlcRefMBBY, pmbmd, shpmdColocatedMB, pmv, pmvBY, x, y, 0, iMBY); } else { m_statsMB.nBitsShape += codeIntraShape (ppxlcRefMBBY, pmbmd, 0, iMBY); decideTransparencyStatus (pmbmd, m_ppxlcCurrMBBY); } if(pmbmd->m_bhas4MVForward) padMotionVectors(pmbmd,pmv); for (iMBX = 0; iMBX < m_iNumMBX; iMBX++, x += MB_SIZE, iMB++) {#ifdef __TRACE_AND_STATS_ m_pbitstrmOut->trace (CSite (iMBX, iMBY), "MB_X_Y (Texture)"); // shape quantization part m_statsMB.reset ();#endif // __TRACE_AND_STATS_ Int iVPlastMBnum = iMBY * m_iNumMBX + iMBX; pmbmd->m_bPadded=FALSE; // MB level rate control section // here is where we calculate the delta QP if (m_uiRateControl>=RC_TM5) { // TM5 rate control updateQP(pmbmd, iQPPrev, m_tm5rc.tm5rc_calc_mquant(iMB, m_statsVOP.total()) ); } else {#ifdef _MBQP_CHANGE_ Int iDQuant = (rand() % 5) - 2; updateQP(pmbmd, iQPPrev, iQPPrev + iDQuant);#else // no change in step size, but still need to call... updateQP(pmbmd, iQPPrev, iQPPrev);#endif //_MBQP_CHANGE_ } if(iMBX<m_iNumMBX-1) { // shape bitstream is set to shape cache m_pbitstrmShapeMBOut = m_pbitstrmShape_DP[iMBY * m_iNumMBX + iMBX + 1]; // The following operation is needed only for OBMC if( bCodeVPHeaderNext ) { iTempVPMBnum = m_iVPMBnum; m_iVPMBnum = VPMBnum(iMBX+1, iMBY); } // code shape 1mb in advance copyToCurrBuffJustShape (ppxlcOrigMBBY+MB_SIZE,m_iFrameWidthY); // Modified for error resilient mode by Toshiba(1997-11-14) if(m_vopmd.bShapeCodingType) { shpmdColocatedMB = m_rgmbmdRef [ min (max (0, iMBX+1), m_iNumMBXRef-1) + min (max (0, iMBY), m_iNumMBYRef-1) * m_iNumMBXRef ].m_shpmd; encodePVOPMBJustShape( ppxlcRefMBBY+MB_SIZE, pmbmd+1, shpmdColocatedMB, pmv+PVOP_MV_PER_REF_PER_MB, pmvBY+1, x+MB_SIZE, y, iMBX+1, iMBY ); } else { m_statsMB.nBitsShape += codeIntraShape ( ppxlcRefMBBY+MB_SIZE, pmbmd+1, iMBX+1, iMBY ); decideTransparencyStatus (pmbmd+1, m_ppxlcCurrMBBY); } // The following operation is needed only for OBMC if( bCodeVPHeaderNext ) m_iVPMBnum = iTempVPMBnum; if((pmbmd+1)->m_bhas4MVForward) padMotionVectors(pmbmd+1, pmv+PVOP_MV_PER_REF_PER_MB); } // Set not to output but count bitstream m_pbitstrmOut->SetDontSendBits(TRUE); // copy DCT coefficient to buffer iCoefQ_DP[iVPlastMBnum] = new Int* [6]; Int iBlk; for (iBlk = 0; iBlk < 6; iBlk++) { iCoefQ_DP [iVPlastMBnum] [iBlk] = new Int [BLOCK_SQUARE_SIZE]; } // 09/19/99 HHI Schueuer: copy rowlength for sadct if (!m_volmd.bSadctDisable) { iRowLength_DP[iVPlastMBnum] = new Int* [11]; Int iBlk; for (iBlk = ALL_Y_BLOCKS; iBlk < ALL_A_BLOCKS; iBlk++) iRowLength_DP[iVPlastMBnum][iBlk] = 0; } // end HHI if (pmbmd -> m_rgTranspStatus [0] != ALL) { // need to copy binary shape too since curr buff is future shape copyToCurrBuffWithShape(ppxlcOrigMBY, ppxlcOrigMBU, ppxlcOrigMBV, ppxlcRefMBBY, NULL, m_iFrameWidthY, m_iFrameWidthUV); //Changed HHI 2000-04-11 downSampleBY (m_ppxlcCurrMBBY, m_ppxlcCurrMBBUV, pmbmd); // 09/19/99 HHI Schueuer: sadct if (!m_volmd.bSadctDisable){ deriveSADCTRowLengths (m_rgiCurrMBCoeffWidth, m_ppxlcCurrMBBY, m_ppxlcCurrMBBUV, pmbmd->m_rgTranspStatus); encodePVOPMBTextureWithShape(ppxlcRefMBY, ppxlcRefMBU, ppxlcRefMBV, NULL, pmbmd, pmv, iMBX, iMBY, x, y, &bRestartDelayedQP, m_ppxlcCurrMBBY, m_ppxlcCurrMBBUV); } else encodePVOPMBTextureWithShape(ppxlcRefMBY, ppxlcRefMBU, ppxlcRefMBV, NULL, pmbmd, pmv, iMBX, iMBY, x, y, &bRestartDelayedQP); // copy DCT coefficient to buffer for (iBlk = 0; iBlk < 6; iBlk++) { for( Int t = 0; t < BLOCK_SQUARE_SIZE; t++ ) iCoefQ_DP[iVPlastMBnum][iBlk][t] = m_rgpiCoefQ[iBlk][t]; } // 09/19/99 HHI Schueuer: copy rowlength for sadct if (!m_volmd.bSadctDisable) { for (iBlk = Y_BLOCK1; iBlk <= A_BLOCK4; iBlk++) { iRowLength_DP [iVPlastMBnum][iBlk] = new Int [BLOCK_SIZE]; for ( Int t = 0; t < BLOCK_SIZE; t++) iRowLength_DP [iVPlastMBnum][iBlk][t] = m_rgiCurrMBCoeffWidth[iBlk][t]; } } // end HHI if (pmbmd -> m_rgTranspStatus [0] == PARTIAL) mcPadCurrMB (ppxlcRefMBY, ppxlcRefMBU, ppxlcRefMBV, NULL); padNeighborTranspMBs ( iMBX, iMBY, pmbmd, ppxlcRefMBY, ppxlcRefMBU, ppxlcRefMBV, NULL ); } else { cancelQPUpdate(pmbmd); padCurrAndTopTranspMBFromNeighbor ( iMBX, iMBY, pmbmd, ppxlcRefMBY, ppxlcRefMBU, ppxlcRefMBV, NULL ); } // Set to output bitstream m_pbitstrmOut->SetDontSendBits(FALSE); iQPPrev = pmbmd->m_stepSize; pmbmd++; pmv += PVOP_MV_PER_REF_PER_MB; pmvBY++; ppxlcRefMBBY += MB_SIZE; ppxlcRefMBBUV += BLOCK_SIZE; ppxlcOrigMBBY += MB_SIZE;#ifdef __TRACE_AND_STATS_ m_statsVOP += m_statsMB;#endif // __TRACE_AND_STATS_ ppxlcRefMBY += MB_SIZE; ppxlcRefMBU += BLOCK_SIZE; ppxlcRefMBV += BLOCK_SIZE; ppxlcOrigMBY += MB_SIZE; ppxlcOrigMBU += BLOCK_SIZE; ppxlcOrigMBV += BLOCK_SIZE; iVPtotal = (int) m_statsVOP.total() - iVPCounter; if( bCodeVPHeaderNext || iVPlastMBnum == m_iNumMB-1 /* last MB in a VOP */) { // Set to output bitstream m_pbitstrmOut->SetDontSendBits(FALSE); // encode video packet iVPCounter = m_statsVOP.total(); m_statsVP.reset(); if( m_iVPMBnum > 0 ) { m_statsVP.nBitsHead = codeVideoPacketHeader (m_rgmbmd[m_iVPMBnum].m_stepSize - m_rgmbmd[m_iVPMBnum].m_intStepDelta); } bRestartDelayedQP = TRUE; DataPartitioningMotionCoding(m_iVPMBnum, iVPlastMBnum, &m_statsVP, iCoefQ_DP); m_pbitstrmOut -> putBits (MOTION_MARKER, NUMBITS_DP_MOTION_MARKER, "motion_marker"); m_statsVP.nBitsHead += NUMBITS_DP_MOTION_MARKER; if (!m_volmd.bSadctDisable) DataPartitioningTextureCoding(m_iVPMBnum, iVPlastMBnum, &m_statsVP, iCoefQ_DP, iRowLength_DP); else DataPartitioningTextureCoding(m_iVPMBnum, iVPlastMBnum, &m_statsVP, iCoefQ_DP); m_iVPMBnum = iVPlastMBnum + 1; } // The following operation is needed only for OBMC iCounter = m_statsVOP.total(); bCodeVPHeaderNext = iCounter - iVPCounter > m_volmd.bVPBitTh; } MacroBlockMemory** ppmbmTemp = m_rgpmbmAbove; m_rgpmbmAbove = m_rgpmbmCurr; m_rgpmbmCurr = ppmbmTemp; ppxlcRefY += m_iFrameWidthYxMBSize; ppxlcRefU += m_iFrameWidthUVxBlkSize; ppxlcRefV += m_iFrameWidthUVxBlkSize; ppxlcRefBY += m_iFrameWidthYxMBSize; ppxlcRefBUV += m_iFrameWidthUVxBlkSize; ppxlcOrigY += m_iFrameWidthYxMBSize; ppxlcOrigBY += m_iFrameWidthYxMBSize; ppxlcOrigU += m_iFrameWidthUVxBlkSize; ppxlcOrigV += m_iFrameWidthUVxBlkSize; } // delete CoefQ_DP for(iMB = 0; iMB < m_iNumMB; iMB++ ) { for (Int iBlk = 0; iBlk < 6; iBlk++) { delete [] iCoefQ_DP [iMB] [iBlk]; } delete [] iCoefQ_DP[iMB]; } delete [] iCoefQ_DP; // 09/19/99 HHI Schueuer: delete iRowLength _DP sadct if (!m_volmd.bSadctDisable) { for (iMB = 0; iMB < m_iNumMB; iMB++) { for (Int iBlk = 0; iBlk < 11; iBlk++) delete [] iRowLength_DP[iMB][iBlk]; delete [] iRowLength_DP[iMB]; } delete [] iRowLength_DP; } else { delete [] iRowLength_DP; } // end HHI; // restore normal output stream m_pbitstrmShapeMBOut = m_pbitstrmOut; // Set to output bitstream m_pbitstrmOut->SetDontSendBits(FALSE); m_vopmd.intStep = newQStep;}////////////////////////////////////////////////////////////// The following functions are for Reversible VLC //////////////////////////////////////////////////////////////UInt CVideoObjectEncoder::sendTCOEFIntraRVLC (const Int* rgiCoefQ, Int iStart, Int* rgiZigzag, Bool bDontSendBits){ assert( m_volmd.bDataPartitioning && m_volmd.bReversibleVlc ); Bool bIsFirstRun = TRUE; Bool bIsLastRun = FALSE; UInt uiCurrRun = 0; UInt uiPrevRun = 0; // Int iCurrLevel = 0; Int iPrevLevel = 0; // UInt uiCoefToStart = 0; UInt numBits = 0; for (Int j = iStart; j < BLOCK_SQUARE_SIZE; j++) { if (rgiCoefQ [rgiZigzag [j]] == 0) // zigzag here uiCurrRun++; // counting zeros else { if (!bIsFirstRun) numBits += putBitsOfTCOEFIntraRVLC (uiPrevRun, iPrevLevel, bIsLastRun, bDontSendBits); uiPrevRun = uiCurrRun; // reset for next run iPrevLevel = rgiCoefQ [rgiZigzag [j]]; uiCurrRun = 0; bIsFirstRun = FALSE; } } assert (uiPrevRun <= (BLOCK_SQUARE_SIZE - 1) - 1); // Some AC must be non-zero; at least for inter bIsLastRun = TRUE; numBits += putBitsOfTCOEFIntraRVLC (uiPrevRun, iPrevLevel, bIsLastRun, bDontSendBits); return numBits;}UInt CVideoObjectEncoder::putBitsOfTCOEFIntraRVLC (UInt uiRun, Int iLevel, Bool bIsLastRun, Bool bDontSendBits){ assert(m_volmd.bDataPartitioning && m_volmd.bReversibleVlc ); UInt nBits = 0; Long lVLCtableIndex; if (bIsLastRun == FALSE) { lVLCtableIndex = findVLCtableIndexOfNonLastEventIntraRVLC (bIsLastRun, uiRun, abs(iLevel)); if (lVLCtableIndex != NOT_IN_TABLE) { nBits += m_pentrencSet->m_pentrencDCTIntraRVLC->encodeSymbol(lVLCtableIndex, "Vlc_TCOEF_RVLC", bDontSendBits); // huffman encode if( !bDontSendBits ) m_pentrencSet->m_pentrencDCTIntraRVLC->bitstream()->putBits ((Char) invSignOf (iLevel), 1, "Sign_TCOEF_RVLC"); nBits++; } else escapeEncodeRVLC (uiRun, iLevel, bIsLastRun, bDontSendBits); } else { lVLCtableIndex = findVLCtableIndexOfLastEventIntraRVLC (bIsLastRun, uiRun, abs(iLevel)); if (lVLCtableIndex != NOT_IN_TABLE) { nBits += m_pentrencSet->m_pentrencDCTIntraRVLC->encodeSymbol(lVLCtableIndex, "Vlc_TCOEF_Last_RVLC", bDontSendBits); // huffman encode if( !bDontSendBits ) m_pentrencSet->m_pentrencDCTIntraRVLC->bitstream()->putBits ((Char) invSignOf (iLevel), 1, "Sign_TCOEF_Last_RVLC"); nBits++; } else escapeEncodeRVLC (uiRun, iLevel, bIsLastRun, bDontSendBits); } return nBits;}Int CVideoObjectEncoder::findVLCtableIndexOfNonLastEventIntraRVLC (Bool bIsLastRun, UInt uiRun, UInt uiLevel){ assert( m_volmd.bDataPartitioning && m_volmd.bReversibleVlc ); assert (uiRun >= 0); if (uiRun > 19 || (uiLevel > grgIfNotLastNumOfLevelAtRunIntraRVLC [uiRun])) return NOT_IN_TABLE; else { UInt uiTableIndex = 0; for (UInt i = 0; i < uiRun; i++) uiTableIndex += grgIfNotLastNumOfLevelAtRunIntraRVLC [i]; uiTableIndex += uiLevel; uiTableIndex--; // make it zero-based; see Table H13/H.263 return uiTableIndex;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -