framemng.cpp

来自「JMVM MPEG MVC/3DAV 测试平台 国际通用标准」· C++ 代码 · 共 1,500 行 · 第 1/3 页

CPP
1,500
字号
    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 uiSV = 0;
  FUList::iterator iter = m_cShortTermList.begin();
  FUList::iterator end  = m_cShortTermList.end();
  //PUrvin
  FUList::iterator temp;
  FrameUnit * pMinFrameUnit = NULL;  
  UInt uiMinFrameNumWrap  = m_uiMaxFrameNumCurr;
  for( ; iter != m_cShortTermList.end(); iter++ )
  {
    if( m_pcCurrentFrameUnit->getFrame().getViewId() == (*iter)->getFrame().getViewId()) // fix
    {
      uiSV++; 
      if ( ((*iter)->getFrameNumber() % m_uiMaxFrameNumCurr) < uiMinFrameNumWrap)
      {
        //uiminFrameNumWrap= (*iter)->getFrameNumber() % m_uiMaxFrameNumCurr;
        pMinFrameUnit=(*iter);
        temp = iter;
      }
      
    }
  }
  if (uiSV >= m_uiNumRefFrames ) 
  {
//    RNOK( xRemove( pMinFrameUnit ) );
    RNOK( xRemoveFromRefList( m_cShortTermList, temp ) );
  }
  return Err::m_nOK;
}

//JVT-S036  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();
				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();
  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( 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  end

ErrVal FrameMng::getRecYuvBuffer( YuvPicBuffer*& rpcRecYuvBuffer )
{
  ROT( NULL == m_pcCurrentFrameUnit );
  rpcRecYuvBuffer = m_pcCurrentFrameUnit->getFrame().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 )
{
  RefPicList<RefPic>& rcList = rcSH.getRefPicList( eListIdx );
  ROTRS( 0 == rcList.bufSize(), Err::m_nOK );

  const RplrBuffer& rcRplrBuffer = rcSH.getRplrBuffer( eListIdx );

  ROTRS( ! rcRplrBuffer.getRefPicListReorderingFlag(), Err::m_nOK );

  UInt      uiPicNumPred  = rcSH.getFrameNum();
  UInt      uiMaxPicNum   = m_uiMaxFrameNumPrev;
  UInt      uiIndex       = 0;
  UInt      uiCommand;
  UInt      uiIdentifier;
// JVT-V043
  UInt      uiPicViewIdx   = 0;
  Bool      bFirstViewRPLR = true;

  while( RPLR_END != ( uiCommand = rcRplrBuffer.get( uiIndex ).getCommand( uiIdentifier ) ) )
  {
    FUIter    iter;
    const Frame* pcFrame = NULL;
    
    if( uiCommand == RPLR_LONG )
    //===== LONG TERM INDEX =====
    {
      AF();
    }
    else if ( uiCommand == RPLR_NEG || uiCommand == RPLR_POS) //JVT-V043 
    //===== 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;
      //---- search for short term picture ----
      iter = m_cShortTermList.findShortTermMVC( uiIdentifier, rcSH.getViewId() ); 

      //---- check ----
      if( iter == m_cShortTermList.end() )
      {
        return Err::m_nDataNotAvailable;
      }
      else
      { // everything is fine
        //---- set frame ----
        if( ! rcSH.getKeyPictureFlag() ) 
        {
			    if((*iter)->getBaseRep()) //JVT-S036 
			    {
				    iter++;
			    }
/*
			    if( (*iter)->getFGSPicBuffer() )
			    {
				    pcFrame = &( (*iter)->getFGSFrame() );
			    }
			    else
*/		    {
				    pcFrame = &( (*iter)->getFrame() );
			    }
			    }
			    else
			    {
				    pcFrame = &((*iter)->getFrame() );
			    }
      }
    }
    else // uiCommand == 4 or 5 JVT-V043
    {
      if( uiCommand == RPLR_VIEW_NEG && uiIdentifier == 0 && bFirstViewRPLR )
        uiPicViewIdx = 0;
      else 
      {
        UInt uiAbsDiff = uiIdentifier + 1;
// JVT-W066
        UInt uiMaxRef = rcSH.getSPS().getSpsMVC()->getNumRefsForListX (rcSH.getViewId(), 
                                                                       eListIdx, 
                                                                       rcSH.getAnchorPicFlag());

          if( uiCommand == RPLR_VIEW_NEG )
          {
            if( uiPicViewIdx < uiAbsDiff )
            {
              uiPicViewIdx -= ( uiAbsDiff - uiMaxRef );
            }
            else
            {
              uiPicViewIdx -=   uiAbsDiff;
            }
          }

          if( uiCommand == RPLR_VIEW_POS)
          {
            if( uiPicViewIdx + uiAbsDiff >= uiMaxRef )
            {
              uiPicViewIdx += ( uiAbsDiff - uiMaxRef );
            }
            else
            {
              uiPicViewIdx +=   uiAbsDiff;
            }
          }
// JVT-W066
      }
      uiIdentifier = uiPicViewIdx; 

      iter = m_cShortTermList.findInterView(rcSH, uiIdentifier, eListIdx);
      if( iter == m_cShortTermList.end()  ) 
      {
        iter = m_cNonRefList.findInterView(rcSH, uiIdentifier, eListIdx);
        //---- check ----
        if( iter == m_cNonRefList.end() )
        {
          return Err::m_nDataNotAvailable;
        }
      }
     //---- set frame ----
       pcFrame = &((*iter)->getFrame() );
       bFirstViewRPLR = false;
    }
    //---- 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 ----- shift
    rcList.getElementAndRemove( uiIndex, uiRemoveIndex ).setFrame( pcFrame );
    uiIndex++;
  }

  return Err::m_nOK;
}

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

  UInt uiOutput = 0;

  for (UInt i = 0; i < uiNumOfViews; i++ )
  {
      //===== 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) && (*iter)->getFrame().getViewId() == i)
          {
              iMinPOCtoOuput = (*iter)->getMaxPOC();
          }
      }

//      ROT( iMinPOCtoOuput == MSYS_INT_MAX );
      if(iMinPOCtoOuput == MSYS_INT_MAX)
          continue;
      
      uiOutput++;

      //===== output =====
      for( iter = m_cOrderedPOCList.begin(); iter != m_cOrderedPOCList.end(); iter++ )
      {
          if( (*iter)->getMaxPOC() <= iMinPOCtoOuput && (*iter)->getFrame().getViewId() == i )
          {
/*              if( (*iter)->getFGSPicBuffer() )
              {
                  (*iter)->getFGSPicBuffer()->setCts( (UInt64)((*iter)->getMaxPOC()) ); // HS: decoder robustness
                  m_cPicBufferOutputList.push_back( (*iter)->getFGSPicBuffer() );
              }
              else 
*/
              if ((*iter)->getPicBuffer() )  //JVT-S036 
              {
                  (*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 ) );
              }
          }
          else
          {
              break;
          }
      }
      m_cOrderedPOCList.erase( m_cOrderedPOCList.begin(), iter );

  }

  ROF(uiOutput);

  return Err::m_nOK;
}






ErrVal
FrameMng::xDumpRefList( ListIdx       eListIdx,
                        SliceHeader& rcSH )
{
#if 0 // NO_DEBUG
  return Err::m_nOK;
#endif
  RefPicList<RefPic>& rcList = rcSH.getRefPicList( eListIdx );

  printf("List %d: ", eListIdx );
  //for( UInt uiIndex = 0; uiIndex < rcList.size(); uiIndex++ )
  for( UInt uiIndex = 0; uiIndex < rcSH.getNumRefIdxActive(eListIdx); uiIndex++ )
  {
    printf("%d/%d ", rcList.get(uiIndex).getFrame()->getViewId(), 
           rcList.get(uiIndex).getFrame()->getPOC() );
  }
  printf("\n");
  return Err::m_nOK;
}

ErrVal FrameMng::xMmcoMarkShortTermAsUnusedMVC( const FrameUnit* pcCurrFrameUnit, 
                                                UInt uiDiffOfPicNums, UInt uiCurrViewId )
{
  UInt  uiCurrPicNum  = pcCurrFrameUnit->getFrameNumber();
  UInt  uiPicNumN     = uiCurrPicNum - uiDiffOfPicNums - 1;

  if( uiCurrPicNum <= uiDiffOfPicNums )
  {
    uiPicNumN += m_uiMaxFrameNumPrev;
  }

  FUIter iter = m_cShortTermList.findShortTermMVC( uiPicNumN, uiCurrViewId );
  if( iter == m_cShortTermList.end() )
  {
    printf("\nMMCO not possible\n" );
    return Err::m_nOK; // HS: decoder robustness
  }

  FrameUnit* pcFrameUnit = (*iter);
  pcFrameUnit->setUnused();
  RNOK( xRemoveFromRefList( m_cShortTermList, iter ) );

  return Err::m_nOK;
}


ErrVal FrameMng::xSetReferenceListsMVC( SliceHeader& rcSH )
{
  if( rcSH.isIntra() )
  {
    return Err::m_nOK;
  }

  if( rcSH.isInterP() )
  {
    xSetPFrameListMVC(rcSH);
  }
  else
  {
    xSetBFrameListMVC(rcSH);
  }
// cleanup 
  return Err::m_nOK;
}

//  {{
ErrVal            
FrameMng::xSetPFrameListMVC ( SliceHeader& rcSH)
{
  RefPicList<RefPic>& rcList0 = rcSH.getRefPicList( LIST_0 );

  UInt  uiInterViewPredRefNumFwd = ( rcSH.getAnchorPicFlag() ? rcSH.getSPS().SpsMVC->getNumAnchorRefsForListX(rcSH.getViewId(), LIST_0) : rcSH.getSPS().SpsMVC->getNumNonAnchorRefsForListX(rcSH.getViewId(), LIST_0));
  if (uiInterViewPredRefNumFwd ==0 ) 
    return Err::m_nOK;

  RefPicList<Frame*>      cTempFrameList0;
//  cTempFrameList0.reset(uiNumRefActive0-uiInterPredRefNumFwd);
    cTempFrameList0.reset(uiInterViewPredRefNumFwd);

  m_cShortTermList.setRefFrameListFGSMVCView( cTempFrameList0, rcSH, LIST_0 );
//  if(cTempFrameList0.size()!=uiNumRefActive0-uiInterPredRefNumFwd)
  if(cTempFrameList0.size()!= uiInterViewPredRefNumFwd )
    m_cNonRefList.setRefFrameListFGSMVCViewNonRef(cTempFrameList0, rcSH, LIST_0);


  UInt uiInterPredSize = rcList0.size();
  for(UInt uiIdx=0; uiIdx< uiInterViewPredRefNumFwd; uiIdx++)
  {
    rcList0.next();
    rcList0.getElementAndRemove(uiIdx + uiInterPredSize , uiIdx+uiInterPredSize ).setFrame( cTempFrameList0.get(uiIdx));
  }

  return Err::m_nOK;
}

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

  UInt  uiInterViewPredRefNumFwd = ( rcSH.getAnchorPicFlag() ? rcSH.getSPS().SpsMVC->getNumAnchorRefsForListX(rcSH.getViewId(), LIST_0) : rcSH.getSPS().SpsMVC->getNumNonAnchorRefsForListX(rcSH.getViewId(), LIST_0));
  UInt  uiInterViewPredRefNumBwd = ( rcSH.getAnchorPicFlag() ? rcSH.getSPS().SpsMVC->getNumAnchorRefsForListX(rcSH.getViewId(), LIST_1) : rcSH.getSPS().SpsMVC->getNumNonAnchorRefsForListX(rcSH.getViewId(), LIST_1));
  
  if ( uiInterViewPredRefNumFwd ==0 && uiInterViewPredRefNumBwd ==0 ) 
    return Err::m_nOK;

  RefPicList<Frame*>     cTempFrameList0;
  RefPicList<Frame*>     cTempFrameList1;

  cTempFrameList0.reset(uiInterViewPredRefNumFwd);
  cTempFrameList1.reset(uiInterViewPredRefNumBwd);
    
  m_cShortTermList.setRefFrameListFGSMVCView( cTempFrameList0, rcSH, LIST_0 );
  m_cShortTermList.setRefFrameListFGSMVCView( cTempFrameList1, rcSH, LIST_1 );
  if(cTempFrameList0.size()!= uiInterViewPredRefNumFwd)
    m_cNonRefList.setRefFrameListFGSMVCViewNonRef(cTempFrameList0, rcSH, LIST_0);
  if(cTempFrameList1.size()!= uiInterViewPredRefNumBwd)
    m_cNonRefList.setRefFrameListFGSMVCViewNonRef(cTempFrameList1, rcSH, LIST_1);
  UInt uiIdx;
  UInt uiInterPredSizeL0 = rcList0.size();
  UInt uiInterPredSizeL1 = rcList1.size();
  
  for( uiIdx=0; uiIdx< uiInterViewPredRefNumFwd; uiIdx++)
  {
    rcList0.next();
    rcList0.getElementAndRemove(uiIdx + uiInterPredSizeL0 , uiIdx+uiInterPredSizeL0 ).setFrame( cTempFrameList0.get(uiIdx));
  }
  
  for( uiIdx=0; uiIdx< uiInterViewPredRefNumBwd; uiIdx++)
  {
    rcList1.next();
    rcList1.getElementAndRemove(uiIdx + uiInterPredSizeL1 , uiIdx+uiInterPredSizeL1 ).setFrame( cTempFrameList1.get(uiIdx));
  }
  
  return Err::m_nOK;
}  
//  }}

H264AVC_NAMESPACE_END

⌨️ 快捷键说明

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