📄 framemng.cpp
字号:
return Err::m_nOK;
}
ErrVal FrameMng::xStoreCurrentPicture( const SliceHeader& rcSH )
{
const PicType ePicType = rcSH.getPicType();
Frame* pcBaseFrame = m_pcCurrentFrameUnit->getPic( ePicType );
PicBuffer cTempPicBuffer( pcBaseFrame->getFullPelYuvBuffer()->getBuffer() );
// Base layer
m_pcCurrentFrameUnit->getFGSReconstruction(0)->load(& cTempPicBuffer);
m_pcCurrentFrameUnit->setFGSReconCount(1);
const Bool bFieldCoded = rcSH.getFieldPicFlag()? true : rcSH.isMbAff();
m_pcCurrentFrameUnit->addPic( ePicType, bFieldCoded, rcSH.getIdrPicId() );
if( rcSH.getNalRefIdc() )
{
RNOK( m_pcCurrentFrameUnit->getPic( ePicType )->extendFrame( m_pcQuarterPelFilter, rcSH.getSPS().getFrameMbsOnlyFlag(), false ) );
//===== store as short term picture =====
m_pcCurrentFrameUnit->setFrameNumber( rcSH.getFrameNum() );
m_pcCurrentFrameUnit->setShortTerm ( ePicType );
RNOK( xStoreShortTerm( m_pcCurrentFrameUnit ) );
}
else
{
RNOK( xStoreNonRef( m_pcCurrentFrameUnit ) );
}
return Err::m_nOK;
}
ErrVal FrameMng::xMmcoMarkShortTermAsUnused( const PicType eCurrentPicType, const FrameUnit* pcCurrFrameUnit, UInt uiDiffOfPicNums )
{
UInt uiCurrPicNum = ( eCurrentPicType==FRAME ? pcCurrFrameUnit->getFrameNumber()
: pcCurrFrameUnit->getFrameNumber() * 2 + 1 );
UInt uiPicNumN = uiCurrPicNum - uiDiffOfPicNums - 1;
if( uiCurrPicNum <= uiDiffOfPicNums )
{
uiPicNumN += ( eCurrentPicType==FRAME ? m_uiMaxFrameNumPrev : 2 * m_uiMaxFrameNumPrev );
}
PicType ePicType;
xSetIdentifier( uiPicNumN, ePicType, eCurrentPicType );
FUIter iter = m_cShortTermList.findShortTerm( uiPicNumN );
if( iter == m_cShortTermList.end() )
{
printf("\nMMCO not possible\n" );
return Err::m_nOK; // HS: decoder robustness
}
FrameUnit* pcFrameUnit = (*iter);
pcFrameUnit->setUnused( ePicType );
if( ! pcFrameUnit->isUsed( FRAME ) )
{
RNOK( xRemoveFromRefList( m_cShortTermList, iter ) )
}
return Err::m_nOK;
}
//JVT-S036 lsj start
ErrVal FrameMng::xMmcoMarkShortTermAsUnusedBase( const PicType eCurrentPicType, const FrameUnit* pcCurrFrameUnit, UInt uiDiffOfPicNums ) // TMM_INTERLACE
{
UInt uiCurrPicNum = ( eCurrentPicType==FRAME ? pcCurrFrameUnit->getFrameNumber()
: pcCurrFrameUnit->getFrameNumber() * 2 + 1 );
UInt uiPicNumN = uiCurrPicNum - uiDiffOfPicNums - 1;
if( uiCurrPicNum <= uiDiffOfPicNums )
{
uiPicNumN += ( eCurrentPicType==FRAME ? m_uiMaxFrameNumPrev : 2 * m_uiMaxFrameNumPrev );
}
PicType ePicType;
xSetIdentifier( uiPicNumN, ePicType, eCurrentPicType );
FUIter iter = m_cShortTermList.findShortTerm( uiPicNumN );
if( iter == m_cShortTermList.end() )
{
printf("\nMMCO not possible\n" );
return Err::m_nOK; // HS: decoder robustness
}
FrameUnit* pcFrameUnit = (*iter);
if(pcFrameUnit->getBaseRep() )
{
pcFrameUnit->setUnused(ePicType);
RNOK( xRemoveFromRefList( m_cShortTermList, iter ) );
}
return Err::m_nOK;
}
//JVT-S036 lsj end
ErrVal FrameMng::xManageMemory( const SliceHeader& rcSH )
{
ROTRS( ! rcSH.getNalRefIdc(), Err::m_nOK );
if( ! rcSH.getAdaptiveRefPicBufferingFlag() )
{
if( ! getCurrentFrameUnit()->isRefPic() )
RNOK( xSlidingWindowUpdate() );
return Err::m_nOK;
}
const PicType ePicType = rcSH.getPicType();
MmcoOp eMmcoOp;
const MmcoBuffer& rcMmcoBuffer = rcSH.getMmcoBuffer();
UInt uiVal1, uiVal2;
Int iIndex = 0;
while( MMCO_END != (eMmcoOp = rcMmcoBuffer.get( iIndex++ ).getCommand( uiVal1, uiVal2)) )
{
switch (eMmcoOp)
{
case MMCO_SHORT_TERM_UNUSED:
RNOK( xMmcoMarkShortTermAsUnused( ePicType, m_pcCurrentFrameUnit, uiVal1 ) );
break;
case MMCO_RESET:
case MMCO_MAX_LONG_TERM_IDX:
case MMCO_ASSIGN_LONG_TERM:
case MMCO_LONG_TERM_UNUSED:
case MMCO_SET_LONG_TERM:
default:AF();
break;
}
}
return Err::m_nOK;
}
ErrVal FrameMng::xSlidingWindowUpdate()
{
UInt uiS = m_cShortTermList.size();
//bug-fix suffix{{
FUList::iterator iter = m_cShortTermList.begin();
for( ; iter != m_cShortTermList.end(); iter++ )
{
if( (*iter)->getBaseRep() ) uiS--;
}
//bug-fix suffix}}
//ROT( uiS > m_uiNumRefFrames );
//if( uiS == m_uiNumRefFrames )
while( uiS >= m_uiNumRefFrames ) // HS: decoder robustness
{
RNOK( xRemove( m_cShortTermList.popBack() ) );
uiS--; // HS: decoder robustness
}
return Err::m_nOK;
}
//JVT-S036 lsj start
ErrVal FrameMng::xSlidingWindowUpdateBase( UInt mCurrFrameNum )
{
FUList::iterator iter = m_cShortTermList.begin();
FUList::iterator end = m_cShortTermList.end();
FUList::iterator iiter;
for( ; iter != m_cShortTermList.end(); iter++ )
{
if( (*iter)->getBaseRep() && (*iter)->getFrameNumber() != mCurrFrameNum )
{
for( iiter = m_cShortTermList.begin(); iiter != m_cShortTermList.end(); iiter++ )
{
if ( (*iiter)->getFrameNumber() == (*iter)->getFrameNumber() && !(*iiter)->getBaseRep() )
{
(*iter)->setUnused(FRAME);// TMM_INTERLACE (to be checked ?)
RNOK( xRemoveFromRefList( m_cShortTermList, iter ) );
return Err::m_nOK;
}
}
}
}
return Err::m_nOK;
}
ErrVal FrameMng::xMMCOUpdateBase( SliceHeader* rcSH )
{
MmcoOp eMmcoOp;
const MmcoBuffer& rcMmcoBaseBuffer = rcSH->getMmcoBaseBuffer();
const PicType ePicType = rcSH->getPicType();
Int iIndex = 0;
UInt uiVal1, uiVal2;
while( MMCO_END != (eMmcoOp = rcMmcoBaseBuffer.get( iIndex++ ).getCommand( uiVal1, uiVal2 ) ) )
{
switch( eMmcoOp )
{
case MMCO_SHORT_TERM_UNUSED:
RNOK( xMmcoMarkShortTermAsUnusedBase(ePicType, m_pcCurrentFrameUnit, uiVal1 ) );
break;
case MMCO_RESET:
case MMCO_MAX_LONG_TERM_IDX:
case MMCO_ASSIGN_LONG_TERM:
case MMCO_LONG_TERM_UNUSED:
case MMCO_SET_LONG_TERM:
default:
fprintf( stderr,"\nERROR: MMCO COMMAND currently not supported in the software\n\n" );
RERR();
}
}
return Err::m_nOK;
}
//JVT-S036 lsj end
ErrVal FrameMng::getRecYuvBuffer( YuvPicBuffer*& rpcRecYuvBuffer, PicType ePicType )
{
ROT( NULL == m_pcCurrentFrameUnit );
rpcRecYuvBuffer = m_pcCurrentFrameUnit->getPic( ePicType )->getFullPelYuvBuffer();
return Err::m_nOK;
}
FrameUnit*
FrameMng::getReconstructedFrameUnit( Int iPoc )
{
for( FUIter iter = m_cOrderedPocList.begin(); iter != m_cOrderedPocList.end(); iter++ )
{
if( (*iter)->getMaxPoc() == iPoc )
{
return *iter;
}
}
return 0;
}
ErrVal FrameMng::xReferenceListRemapping( SliceHeader& rcSH, ListIdx eListIdx )
{
const PicType eCurrentPicType = rcSH.getPicType();
RefPicList<RefPic>& rcList = rcSH.getRefPicList( eCurrentPicType, eListIdx );
ROTRS( 0 == rcList.bufSize(), Err::m_nOK );
const RplrBuffer& rcRplrBuffer = rcSH.getRplrBuffer( eListIdx );
ROTRS( ! rcRplrBuffer.getRefPicListReorderingFlag(), Err::m_nOK );
UInt uiPicNumPred = ( eCurrentPicType==FRAME ? rcSH.getFrameNum()
: rcSH.getFrameNum()*2+1 );
UInt uiMaxPicNum = ( eCurrentPicType==FRAME ? m_uiMaxFrameNumPrev : 2 * m_uiMaxFrameNumPrev );
UInt uiIndex = 0;
RplrOp uiCommand;
UInt uiIdentifier;
while( RPLR_END != ( uiCommand = (RplrOp) rcRplrBuffer.get( uiIndex ).getCommand( uiIdentifier ) ) )
{
PicType ePicType;
FUIter iter;
Frame* pcFrame = NULL;
if( uiCommand == RPLR_LONG )
//===== LONG TERM INDEX =====
{
AF();
}
else
//===== SHORT TERM INDEX =====
{
UInt uiAbsDiff = uiIdentifier + 1;
//---- set short term index ----
if( uiCommand == RPLR_NEG )
{
if( uiPicNumPred < uiAbsDiff )
{
uiPicNumPred -= ( uiAbsDiff - uiMaxPicNum );
}
else
{
uiPicNumPred -= uiAbsDiff;
}
}
else
{
if( uiPicNumPred + uiAbsDiff > uiMaxPicNum - 1 )
{
uiPicNumPred += ( uiAbsDiff - uiMaxPicNum );
}
else
{
uiPicNumPred += uiAbsDiff;
}
}
uiIdentifier = uiPicNumPred;
xSetIdentifier( uiIdentifier, ePicType, eCurrentPicType );
//---- search for short term picture ----
iter = m_cShortTermList.findShortTerm( uiIdentifier );
//---- check ----
if( iter == m_cShortTermList.end() || ! (*iter)->isShortTerm( ePicType ) )
{
printf( "RPLR : Short Term Picture Not Available\n");
return Err::m_nDataNotAvailable;
}
else
{ // everything is fine
//---- set frame ----
if( ! rcSH.getUseBasePredictionFlag() )
{
if((*iter)->getBaseRep()) //JVT-S036 lsj
{
iter++;
}
if( (*iter)->getFGSPicBuffer() )
{
pcFrame = (*iter)->getFGSPic( ePicType ) ;
}
else
{
pcFrame = (*iter)->getPic( ePicType ) ;
}
}
else
{
pcFrame = (*iter)->getPic( ePicType ) ;
}
}
}
//---- find picture in reference list -----
UInt uiRemoveIndex = MSYS_UINT_MAX;
if( NULL != pcFrame )
{
for( UInt uiPos = uiIndex; uiPos < rcList.size(); uiPos++ )
{
if( rcList.get( uiPos ).getFrame() == pcFrame )
{
uiRemoveIndex = uiPos;
break;
}
}
}
//----- reference list reordering -----
rcList.getElementAndRemove( uiIndex, uiRemoveIndex ).setFrame( pcFrame );
uiIndex++;
}
return Err::m_nOK;
}
ErrVal FrameMng::xOutputPicture( FrameUnit* pcFrameUnit )
{
ROT( NULL == pcFrameUnit );
pcFrameUnit->setOutputDone();
PicBuffer* pcPicBuffer = pcFrameUnit->getPicBuffer();
ROTRS( NULL == pcPicBuffer, Err::m_nOK );
pcPicBuffer->setPicStruct( pcFrameUnit->getPicStruct() );
pcPicBuffer->setTopPoc ( pcFrameUnit->getPic( TOP_FIELD )->getPoc() );
pcPicBuffer->setBotPoc ( pcFrameUnit->getPic( BOT_FIELD )->getPoc() );
pcPicBuffer->setFramePoc( pcFrameUnit->getPic( FRAME )->getPoc() );
pcPicBuffer->setFieldCoding( pcFrameUnit->isFieldCoded() );
m_cPicBufferOutputList.push_back( pcPicBuffer );
ROTRS( pcFrameUnit->isBothFields(), Err::m_nOK );
return Err::m_nOK;
}
ErrVal FrameMng::xDumpRefList( RefPicList<RefPic,32>& rcList,
ListIdx eListIdx )
{
printf("LIST_%d={", eListIdx );
for( UInt uiPos = 0; uiPos < rcList.size(); uiPos++ )
{
const PicType ePicType = rcList.get( uiPos ).getFrame()->getPicType();
printf(" %s POC=%4d,", ePicType==FRAME ? "FRAME" : ( ePicType==TOP_FIELD ? "TOP_FIELD" : "BOT_FIELD" ), rcList.get( uiPos ).getFrame()->getPoc() );
}
printf(" }\n");
return Err::m_nOK;
}
H264AVC_NAMESPACE_END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -