framemng.cpp

来自「JVT-S203 contains the JSVM 6 reference s」· C++ 代码 · 共 1,239 行 · 第 1/3 页

CPP
1,239
字号
  if( rcSH->getSPS().getProfileIdc() == MULTI_VIEW_PROFILE )
  {
    m_iMaxEntriesinDPB= rcSH->getSPS().getMaxDPBSize();
  }
  else
  {
    m_iMaxEntriesinDPB= min( 48, rcSH->getSPS().getMaxDPBSize() + 3 );
  }

  if( ! m_iMaxEntriesinDPB )
  {
    printf("WARNING: Size of Decoded picture buffer is less than 1 frame!");
  }

  if( m_pcRefinementIntFrame )
  {
    RNOK( m_pcRefinementIntFrame->init( false ) );
  }
  if( m_pcRefinementIntFrameSpatial )
  {
    RNOK( m_pcRefinementIntFrameSpatial->init( false ) );
  }
  if( m_pcPredictionIntFrame )
  {
    RNOK( m_pcPredictionIntFrame->init( false ) );
  }

  return Err::m_nOK;
}

ErrVal FrameMng::initSPS( const SequenceParameterSet& rcSPS )
{
  m_uiMaxFrameNumCurr = ( 1 << ( rcSPS.getLog2MaxFrameNum() ) );
  m_uiMaxFrameNumPrev = ( 1 << ( rcSPS.getLog2MaxFrameNum() ) );
  m_uiNumRefFrames    = rcSPS.getNumRefFrames();
  if( rcSPS.getProfileIdc() == MULTI_VIEW_PROFILE )
  {
    m_iMaxEntriesinDPB= rcSPS.getMaxDPBSize();
  }
  else
  {
    m_iMaxEntriesinDPB= min( 48, rcSPS.getMaxDPBSize() + 3 );
  }

  if( ! m_iMaxEntriesinDPB )
  {
    printf("WARNING: Size of Decoded picture buffer is less than 1 frame!");
  }

  if( m_pcRefinementIntFrame )
  {
    RNOK( m_pcRefinementIntFrame->init( false ) );
  }
  if( m_pcRefinementIntFrameSpatial )
  {
    RNOK( m_pcRefinementIntFrameSpatial->init( false ) );
  }
  if( m_pcPredictionIntFrame )
  {
    RNOK( m_pcPredictionIntFrame->init( false ) );
  }

  return Err::m_nOK;
}


ErrVal FrameMng::initPic( SliceHeader& rcSH )
{
  rcSH.setFrameUnit( m_pcCurrentFrameUnit );

  m_pcCurrentFrameUnit->setPoc( rcSH.getPoc() );

  return Err::m_nOK;
}


ErrVal FrameMng::initFrame( SliceHeader& rcSH, PicBuffer* pcPicBuffer )
{
  ROF( m_bInitDone );

  //===== check frame numbers for reference pictures =====
  if( ! rcSH.isIdrNalUnit() )
  {
    RNOK( xCheckMissingFrameNums( rcSH ) );
  }

  RNOK( m_cFrameUnitBuffer.getFrameUnit( m_pcCurrentFrameUnit ) );
  RNOK( m_pcCurrentFrameUnit->init( rcSH, pcPicBuffer ) );

  rcSH.setFrameUnit( m_pcCurrentFrameUnit );

  return Err::m_nOK;
}



ErrVal FrameMng::xCheckMissingFrameNums( SliceHeader& rcSH )
{
  //===== check frame numbers for reference pictures =====
  if( ( ( m_uiPrecedingRefFrameNum + 1 ) % m_uiMaxFrameNumCurr) != rcSH.getFrameNum() )
  {
    UInt  uiNumMissingPictures = rcSH.getFrameNum() - m_uiPrecedingRefFrameNum - 1;
    if( rcSH.getFrameNum() <= m_uiPrecedingRefFrameNum )
    {
      uiNumMissingPictures += m_uiMaxFrameNumCurr;
    }

    if( rcSH.getSPS().getRequiredFrameNumUpdateBehaviourFlag() )
    {
      for( UInt uiIndex = 1; uiIndex <= uiNumMissingPictures; uiIndex++ )
      {
        UInt        uiFrameNum  = ( m_uiPrecedingRefFrameNum + uiIndex ) % m_uiMaxFrameNumCurr;
        FrameUnit*  pcFrameUnit = 0;
        RNOK( m_cFrameUnitBuffer.getFrameUnit( pcFrameUnit ) );
		//JVT-S036 lsj{
		if( !m_pcCurrentFrameUnit->getBaseRep() )
		{
			FUList::iterator iter = m_cShortTermList.begin();
			FUList::iterator end  = m_cShortTermList.end();
			Bool bFlag = false;
			for( ; iter != m_cShortTermList.end(); iter++ )
			{
				if( (*iter)->getBaseRep() && (*iter)->getFrameNumber() == m_pcCurrentFrameUnit->getFrameNumber())
				{
				    bFlag = true;
					break;
				}
			}
			if( bFlag )
			{
					FrameUnit* pcFrameUnitTemp = (*iter);
					RNOK(pcFrameUnit->init( rcSH, *pcFrameUnitTemp ));
			}
			else
			{
				RNOK( pcFrameUnit->init( rcSH, *m_pcCurrentFrameUnit ) );
			}
			
		}
		else
		//JVT-S036 lsj}
		{
			RNOK( pcFrameUnit->init( rcSH, *m_pcCurrentFrameUnit ) ); // HS: decoder robustness
		}

        pcFrameUnit->setFrameNumber( uiFrameNum );
        m_cShortTermList.push_front( pcFrameUnit );
        m_iEntriesInDPB++;

		RNOK( xSlidingWindowUpdate() );

      }
    }
    else
    {
      printf("\n  LOST PICTURES: %d\n", uiNumMissingPictures );
      AF();
    }

    m_uiPrecedingRefFrameNum = ( m_uiPrecedingRefFrameNum + uiNumMissingPictures ) % m_uiMaxFrameNumCurr;
  }
  return Err::m_nOK;
}



ErrVal FrameMng::setPicBufferLists( PicBufferList& rcPicBufferOutputList, PicBufferList& rcPicBufferUnusedList )
{
  rcPicBufferUnusedList += m_cPicBufferUnusedList;
  m_cPicBufferUnusedList.clear();

  rcPicBufferOutputList += m_cPicBufferOutputList;
  m_cPicBufferOutputList.clear();

  return Err::m_nOK;
}


ErrVal FrameMng::storePicture( const SliceHeader& rcSH )
{
  //===== memory managment =====
  if( rcSH.isIdrNalUnit() )
  {
    RNOK( xClearListsIDR( rcSH ) );
  }
  RNOK( xManageMemory( rcSH ) );

  //===== store current picture =====
  RNOK( xStoreCurrentPicture( rcSH ) );

  //===== set pictures for output =====
  RNOK( xSetOutputList( m_pcCurrentFrameUnit ) );

  if( rcSH.getNalRefIdc() )
  {
    m_uiPrecedingRefFrameNum = m_pcCurrentFrameUnit->getFrameNumber();
  }

  return Err::m_nOK;
}



UInt FrameMng::xSortPocOrderedList()
{
  UInt  uiFirstPosWithGreaterPoc;
  Int   iCurrPoc = m_pcCurrentFrameUnit->getFrame().getPOC();

  std::sort( m_cPocOrderedFrameList.begin(), m_cPocOrderedFrameList.end(), PocOrder() );
  for( uiFirstPosWithGreaterPoc = 0; uiFirstPosWithGreaterPoc < m_cPocOrderedFrameList.size(); uiFirstPosWithGreaterPoc++ )
  {
    if( m_cPocOrderedFrameList.get( uiFirstPosWithGreaterPoc )->getPOC() > iCurrPoc )
    {
      break;
    }
  }
  return uiFirstPosWithGreaterPoc;
}


ErrVal FrameMng::xSetInitialReferenceListPFrame( SliceHeader& rcSH )
{
  RefPicList<RefPic>& rcList = rcSH.getRefPicList( LIST_0 );

  if( ! rcSH.getKeyPictureFlag() ) 
    m_cShortTermList.setRefPicListFGS( rcList );
  else
    m_cShortTermList.setRefPicList( rcList );
  return Err::m_nOK;
}


ErrVal FrameMng::xSetInitialReferenceListBFrame( SliceHeader& rcSH )
{
  RefPicList<RefPic>& rcList0 = rcSH.getRefPicList( LIST_0 );
  RefPicList<RefPic>& rcList1 = rcSH.getRefPicList( LIST_1 );
  UInt                uiFirstPosWithGreaterPoc, uiPos;
  FUIter              iter;

  //====== set Poc ordered short-term list and get index with smallest Poc greater than current ======
  m_cPocOrderedFrameList.reset();
  if( ! rcSH.getKeyPictureFlag() ) 
    m_cShortTermList.setRefFrameListFGS( m_cPocOrderedFrameList );
  else
    m_cShortTermList.setRefFrameList( m_cPocOrderedFrameList );
  uiFirstPosWithGreaterPoc = xSortPocOrderedList();

  //===== set short term reference frames =====
  for( uiPos = uiFirstPosWithGreaterPoc - 1; uiPos != MSYS_UINT_MAX; uiPos-- )
  {
    rcList0.next().setFrame( m_cPocOrderedFrameList.get( uiPos ) );
  }
  for( uiPos = uiFirstPosWithGreaterPoc; uiPos != m_cPocOrderedFrameList.size(); uiPos++ )
  {
    rcList0.next().setFrame( m_cPocOrderedFrameList.get( uiPos ) );
    rcList1.next().setFrame( m_cPocOrderedFrameList.get( uiPos ) );
  }
  for( uiPos = uiFirstPosWithGreaterPoc - 1; uiPos != MSYS_UINT_MAX; uiPos-- )
  {
    rcList1.next().setFrame( m_cPocOrderedFrameList.get( uiPos ) );
  }

  return Err::m_nOK;
}



ErrVal FrameMng::xCheckReferenceListSwitching( SliceHeader& rcSH )
{
  RefPicList<RefPic>& rcList0 = rcSH.getRefPicList( LIST_0 );
  RefPicList<RefPic>& rcList1 = rcSH.getRefPicList( LIST_1 );

  ROTRS( rcList1.size() < 2 || rcList0.size() != rcList1.size(), Err::m_nOK );

  for( UInt uiPos = 0; uiPos < rcList1.size(); uiPos++ )
  {
    if( rcList1.get( uiPos ) != rcList0.get( uiPos ) )
    {
      return Err::m_nOK;
    }
  }
  rcList1.switchFirstEntries();
  return Err::m_nOK;
}



ErrVal FrameMng::setRefPicLists( SliceHeader& rcSH, Bool bDoNotRemap )
{
  RNOK( xSetReferenceLists( rcSH) );

  if( ! bDoNotRemap )
  {
    //===== remapping =====
    RNOK( xReferenceListRemapping( rcSH, LIST_0 ) );
    RNOK( xReferenceListRemapping( rcSH, LIST_1 ) );
  }

  return Err::m_nOK;
}


ErrVal FrameMng::xSetReferenceLists( SliceHeader& rcSH )
{
  rcSH.getRefPicList( LIST_0 ).reset( 0 );
  rcSH.getRefPicList( LIST_1 ).reset( 0 );

  if( rcSH.isIntra() )
  {
    return Err::m_nOK;
  }

  rcSH.getRefPicList( LIST_0 ).reset();
  if( rcSH.isInterB() )
  {
    rcSH.getRefPicList( LIST_1 ).reset();
  }

  //===== initial lists =====
  if( ! rcSH.isInterB() )
  {
    RNOK( xSetInitialReferenceListPFrame( rcSH ) );
  }
  else
  {
    RNOK( xSetInitialReferenceListBFrame( rcSH ) );
    RNOK( xCheckReferenceListSwitching( rcSH ) )
  }

  return Err::m_nOK;
}



ErrVal FrameMng::xClearListsIDR( const SliceHeader& rcSH  )
{
  //===== output =====
  for( FUIter iter = m_cOrderedPOCList.begin(); iter != m_cOrderedPOCList.end(); iter++ )
  {
    if( ! rcSH.getNoOutputOfPriorPicsFlag() )
    {
      if( (*iter)->getFGSPicBuffer() )
      {
        (*iter)->getFGSPicBuffer()->setCts( (UInt64)((*iter)->getMaxPOC()) ); // HS: decoder robustness
        m_cPicBufferOutputList.push_back( (*iter)->getFGSPicBuffer() );
      }
      else if ((*iter)->getPicBuffer() )  //JVT-S036 lsj
      {
        (*iter)->getPicBuffer()->setCts( (UInt64)((*iter)->getMaxPOC()) ); // HS: decoder robustness
        m_cPicBufferOutputList.push_back( (*iter)->getPicBuffer() );
      }
    }


    (*iter)->setOutputDone();

    if( xFindAndErase( m_cNonRefList, *iter ) )
    {
       RNOK( xAddToFreeList( (*iter) ) );
    }
  }
  m_cOrderedPOCList.clear();
  return Err::m_nOK;
}


UInt FrameMng::MaxRefFrames( UInt uiLevel, UInt uiNumMbs )
{
  return m_uiDBPMemory[ uiLevel ] / ( 384 * uiNumMbs );
}



ErrVal FrameMng::outputAll()
{
  FUIter  iter;
  //===== output =====
  for( iter = m_cOrderedPOCList.begin(); iter != m_cOrderedPOCList.end(); iter++ )
  {
    if( (*iter)->getFGSPicBuffer() )
    {
      (*iter)->getFGSPicBuffer()->setCts( (UInt64)((*iter)->getMaxPOC()) ); // HS: decoder robustness
      m_cPicBufferOutputList.push_back( (*iter)->getFGSPicBuffer() );
    }
    else if ((*iter)->getPicBuffer() )  //JVT-S036 lsj
    {
      (*iter)->getPicBuffer()->setCts( (UInt64)((*iter)->getMaxPOC()) ); // HS: decoder robustness
      m_cPicBufferOutputList.push_back( (*iter)->getPicBuffer() );
    }
    (*iter)->setOutputDone();
  }
  m_cOrderedPOCList.erase( m_cOrderedPOCList.begin(), iter );

  RNOK( xAddToFreeList( m_cShortTermList ) );
  RNOK( xAddToFreeList( m_cNonRefList ) );

  return Err::m_nOK;
}



ErrVal FrameMng::xSetOutputList( FrameUnit* pcFrameUnit )
{
  ROTRS( m_iEntriesInDPB <= m_iMaxEntriesinDPB, Err::m_nOK );

  //===== get minimum POC for output =====
  Int     iMinPOCtoOuput = MSYS_INT_MAX;
  FUIter  iter;
  for( iter = m_cNonRefList.begin(); iter != m_cNonRefList.end(); iter++ )
  {
    if( (*iter)->getMaxPOC() < iMinPOCtoOuput && ( (*iter) != pcFrameUnit) )
    {
      iMinPOCtoOuput = (*iter)->getMaxPOC();

⌨️ 快捷键说明

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