⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gopdecoder.cpp

📁 jsvm开发代码包括抽样,编码,抽取,解码等一系列功能,可以做工具或研究用
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  while( m_cUsedDPBUnitList.size() )
  {
    DPBUnit* pcDPBUnit = m_cUsedDPBUnitList.popFront();
    RNOK( pcDPBUnit->uninit() );
    AOT( pcDPBUnit == NULL)
    m_cFreeDPBUnitList.push_back( pcDPBUnit );
  }

  ROTRS( ! bFinal , Err::m_nOK );

  // release remaining buffers
  while( m_cPicBufferList.size() )
  {
    rcUnusedList.push_back( m_cPicBufferList.popFront() );
  }
  return Err::m_nOK;
}
//JVT-T054{
ErrVal DecodedPicBuffer::xUpdateDPBUnitList(DPBUnit *pcDPBUnit)
{
  ROF( pcDPBUnit == m_pcCurrDPBUnit ); // check
  DPBUnit*  pcElemToReplace  = 0;
  DPBUnitList::iterator iter =  m_cUsedDPBUnitList.begin();
  DPBUnitList::iterator end  =  m_cUsedDPBUnitList.end  ();
  for( ; iter != end; iter++ )
  {
    if( !(*iter)->isBaseRep() && (*iter)->getFrame()->getPoc() == pcDPBUnit->getFrame()->getPoc() 
      && (*iter)->getQualityLevel()+1 == pcDPBUnit->getQualityLevel() )
    {
      pcElemToReplace  = (*iter);
      m_cUsedDPBUnitList.remove(pcElemToReplace);
      m_cFreeDPBUnitList.push_back(pcElemToReplace);
      m_cUsedDPBUnitList.push_back(pcDPBUnit);   
      break;
    }
  }
  return Err::m_nOK;
}
//JVT-T054}

ErrVal
DecodedPicBuffer::xStorePicture( DPBUnit*       pcDPBUnit,
                                 PicBufferList& rcOutputList,
                                 PicBufferList& rcUnusedList,
                                 Bool           bTreatAsIdr,
                                 Bool           bFrameMbsOnlyFlag ,//TMM_INTERLACE
                                 Bool           bRef)  //JVT-T054
                                 
{
  ROF( pcDPBUnit == m_pcCurrDPBUnit );

  //---- fill border ----
  RNOK( m_pcYuvBufferCtrl->initMb() );
//JVT-T054{
  if(!bRef)
  {
    //JVT-T054}
    const PicType ePicType          = pcDPBUnit->getFrame()->getPicType(); //TMM_INTERLACE
    
    RNOK( pcDPBUnit->getFrame()->extendFrame( NULL, ePicType, bFrameMbsOnlyFlag ) );
    
    if( bTreatAsIdr )
    {
      //===== IDR pictures =====
   /* // JVT-Q065 EIDR
      Int iDummy;
      RNOK( xClearOutputAll( rcOutputList, rcUnusedList, iDummy ) ); // clear and output all pictures
   */ 
      m_cUsedDPBUnitList.push_back( pcDPBUnit );                                    // store current picture
    }
    else
    {
      //===== non-IDR picture =====
      m_cUsedDPBUnitList.push_back( pcDPBUnit );                                    // store current picture
      RNOK( xUpdateMemory( pcDPBUnit->getCtrlData().getSliceHeader() ) );        // memory update 
      RNOK( xOutput( rcOutputList, rcUnusedList ) );         // output
    }
    RNOK( xDumpDPB() );

    m_pcCurrDPBUnit = m_cFreeDPBUnitList.popFront();                                // new current DPB unit
//JVT-T054{
  }
  else
  {
    //replace previous version of current frame in usedDPBUnit by the new version
    RNOK( xUpdateDPBUnitList(pcDPBUnit));
    RNOK( xUpdateMemory( pcDPBUnit->getCtrlData().getSliceHeader() ) );        // memory update 
    RNOK( xOutput( rcOutputList, rcUnusedList ) );         // output
    m_pcCurrDPBUnit = m_cFreeDPBUnitList.popBack();      
  }
//JVT-T054}
  m_pcCurrDPBUnit->getCtrlData().setSliceHeader( 0 );
  m_pcCurrDPBUnit->getCtrlData().getMbDataCtrl()->reset();
  m_pcCurrDPBUnit->getCtrlData().getMbDataCtrl()->clear();

  return Err::m_nOK;
}



ErrVal
DecodedPicBuffer::xCheckMissingPics( SliceHeader*   pcSliceHeader,
                                     PicBufferList& rcOutputList,
                                     PicBufferList& rcUnusedList )
{
  ROTRS( pcSliceHeader->isIdrNalUnit(), Err::m_nOK );
  ROTRS( ( ( m_uiLastRefFrameNum + 1 ) % m_uiMaxFrameNum ) == pcSliceHeader->getFrameNum(), Err::m_nOK );

  UInt  uiMissingFrames = pcSliceHeader->getFrameNum() - m_uiLastRefFrameNum - 1;
  if( pcSliceHeader->getFrameNum() <= m_uiLastRefFrameNum )
  {
    uiMissingFrames += m_uiMaxFrameNum;
  }

  if( ! pcSliceHeader->getSPS().getGapsInFrameNumValueAllowedFlag() )
  {
    printf("\nLOST PICTURES = %d\n", uiMissingFrames );
    RERR();
  }
  else
  {
    for( UInt uiIndex = 1; uiIndex <= uiMissingFrames; uiIndex++ )
    {
      const Bool  bTreatAsIdr = ( m_cUsedDPBUnitList.empty() );
      const Int   iPoc        = ( bTreatAsIdr ? 0 : m_cUsedDPBUnitList.back()->getFrame()->getPoc() );
      const UInt  uiFrameNum  = ( m_uiLastRefFrameNum + uiIndex ) % m_uiMaxFrameNum;

      RNOK( m_pcCurrDPBUnit->initNonEx( iPoc, uiFrameNum ) );
      RNOK( xStorePicture( m_pcCurrDPBUnit, rcOutputList, rcUnusedList, bTreatAsIdr, pcSliceHeader->getSPS().getFrameMbsOnlyFlag() ) ); 
    }
  }

  m_uiLastRefFrameNum = ( m_uiLastRefFrameNum + uiMissingFrames ) % m_uiMaxFrameNum;
  return Err::m_nOK;
}



ErrVal
DecodedPicBuffer::xDumpDPB()
{
#if 1 // NO_DEBUG 
  return Err::m_nOK;
#endif

  printf("\nDECODED PICTURE BUFFER (Layer %d)\n", m_uiLayer );
  DPBUnitList::iterator iter  = m_cUsedDPBUnitList.begin();
  DPBUnitList::iterator end   = m_cUsedDPBUnitList.end  ();
  for( Int iIndex = 0; iter != end; iter++, iIndex++ )
  {
    printf("\tPOS=%d:\tFN=%d\tPoc=%d\t%s\t", iIndex, (*iter)->getFrameNum(), (*iter)->getFrame()->getPoc(), ((*iter)->isNeededForRef()?"REF":"   ") );
    
    if(  (*iter)->isOutputted() )   printf("Outputted  ");
    if( !(*iter)->isExisting () )   printf("NotExisting   ");
    if(  (*iter)->isBaseRep  () )   printf("BasRep   ");

    printf("\n");
  }
  printf("\n");
  return Err::m_nOK;
}




ErrVal
DecodedPicBuffer::xInitPrdListPSlice( RefFrameList& rcList0,
                                      IntFrame*     pcCurrentFrame,
																		  PicType       ePicType,
																			SliceType     eSliceType )
{
  rcList0.reset();

  const Bool  bBaseRep        = m_pcCurrDPBUnit->useBasePred ();
  const UInt  uiCurrFrameNum  = m_pcCurrDPBUnit->getFrameNum();

  if( ePicType==BOT_FIELD )
  {
		RNOK( rcList0.add( m_pcCurrDPBUnit->getFrame() ) );
  }

  //----- generate decreasing POC list -----
  for( Int iMaxPicNum = (Int)uiCurrFrameNum; true; )
  {
    DPBUnit*              pNext = NULL;
    DPBUnitList::iterator iter  = m_cUsedDPBUnitList.begin();
    DPBUnitList::iterator end   = m_cUsedDPBUnitList.end  ();
    for( ; iter != end; iter++ )
    {
      if( (*iter)->isNeededForRef() &&
          (*iter)->getPicNum(uiCurrFrameNum,m_uiMaxFrameNum) < iMaxPicNum &&
          ( !pNext || (*iter)->getPicNum(uiCurrFrameNum,m_uiMaxFrameNum)  > pNext->getPicNum(uiCurrFrameNum,m_uiMaxFrameNum) 
                   ||((*iter)->getPicNum(uiCurrFrameNum,m_uiMaxFrameNum) == pNext->getPicNum(uiCurrFrameNum,m_uiMaxFrameNum) && 
                   (*iter)->isBaseRep() == bBaseRep) ) )
      {
        pNext = (*iter);
      }
    }
    if( !pNext )
    {
      break;
    }
    iMaxPicNum = pNext->getPicNum(uiCurrFrameNum,m_uiMaxFrameNum);
    RNOK( rcList0.add( pNext->getFrame() ) );
  }

  if( ePicType!=FRAME )
  {
    RNOK( xSetInitialRefFieldList( rcList0, pcCurrentFrame, ePicType, eSliceType ) ) ;
  }

  return Err::m_nOK;
}

Void DecodedPicBuffer::xSetIdentifier( UInt& uiNum, PicType& rePicType, const PicType eCurrentPicType )
{
  if( eCurrentPicType==FRAME )
  {
    rePicType = FRAME;
  }
  else
  {
    if( uiNum % 2 ) 
    {
      rePicType = eCurrentPicType;
    }
    else if( eCurrentPicType==TOP_FIELD )
    {
      rePicType = BOT_FIELD;
    }
    else
    {
      rePicType = TOP_FIELD;
    }
    uiNum /= 2;
  }
}

ErrVal DecodedPicBuffer::xSetInitialRefFieldList( RefFrameList& rcList, IntFrame* pcCurrentFrame, PicType eCurrentPicType, SliceType eSliceType ) 
{
  RefFrameList cTempList = rcList; 
  rcList.reset();

  const PicType eOppositePicType  = ( eCurrentPicType==TOP_FIELD ? BOT_FIELD : TOP_FIELD );

  //----- initialize field list for short term pictures -----
  UInt uiCurrentParityIndex  = 0;
  UInt uiOppositeParityIndex = 0;

  while( uiCurrentParityIndex < cTempList.getSize() || uiOppositeParityIndex < cTempList.getSize() )
  {
    //--- current parity ---
    while( uiCurrentParityIndex < cTempList.getSize() )
    {
      IntFrame* pcFrame = cTempList.getEntry( uiCurrentParityIndex++ );

      // assume there are no dangling fields in the DPB except the current first field
      if( ( eSliceType==P_SLICE && pcFrame != pcCurrentFrame ) ||
				    eSliceType==B_SLICE )
      {
        RNOK( rcList.add( pcFrame->getPic( eCurrentPicType ) ) );
        break;
      }
    }
    //--- opposite parity ---
    if( uiOppositeParityIndex < cTempList.getSize() )
    {
      IntFrame* pcFrame = cTempList.getEntry( uiOppositeParityIndex++ );
			RNOK( rcList.add( pcFrame->getPic( eOppositePicType ) ) );
    }
  }

  return Err::m_nOK;
}

ErrVal
DecodedPicBuffer::xInitPrdListsBSlice( RefFrameList&  rcList0,
                                       RefFrameList&  rcList1,
                                       IntFrame*     pcCurrentFrame,
																			 PicType       eCurrentPicType,
																			 SliceType     eSliceType )
{
  rcList0.reset();
  rcList1.reset();

  RefFrameList  cDecreasingPocList;
  RefFrameList  cIncreasingPocList;
  const Bool  bBaseRep    = m_pcCurrDPBUnit->useBasePred();
  const Int   iCurrPoc    = m_pcCurrDPBUnit->getFrame()->getPic( eCurrentPicType )->getPoc();

  //----- generate decreasing POC list -----
  for( Int iMaxPoc = iCurrPoc; true; )
  {
    DPBUnit*              pNext = NULL;
    DPBUnitList::iterator iter  = m_cUsedDPBUnitList.begin();
    DPBUnitList::iterator end   = m_cUsedDPBUnitList.end  ();
    for( ; iter != end; iter++ )
    {
      if( (*iter)->isNeededForRef() &&
          (*iter)->getFrame()->getPoc() < iMaxPoc && 
          ( !pNext || (*iter)->getFrame()->getPoc() > pNext->getFrame()->getPoc() ) &&
          (*iter)->isBaseRep() == bBaseRep )
      {
        pNext = (*iter);
      }
    }
    if( !pNext )
    {
      break;
    }
    iMaxPoc = pNext->getFrame()->getPoc();
    RNOK( cDecreasingPocList.add( pNext->getFrame() ) );
  }

  //----- generate increasing POC list -----
  for( Int iMinPoc = iCurrPoc; true; )
  {
    DPBUnit*              pNext = NULL;
    DPBUnitList::iterator iter  = m_cUsedDPBUnitList.begin();
    DPBUnitList::iterator end   = m_cUsedDPBUnitList.end  ();
    for( ; iter != end; iter++ )
    {
      if( (*iter)->isNeededForRef() &&
          (*iter)->getFrame()->getPoc() > iMinPoc && 
          ( ! pNext || (*iter)->getFrame()->getPoc() < pNext->getFrame()->getPoc() ) &&
          (*iter)->isBaseRep() == bBaseRep )
      {
        pNext = (*iter);
      }
    }
    if( !pNext )
    {
      break;
    }
    iMinPoc = pNext->getFrame()->getPoc();
    RNOK( cIncreasingPocList.add( pNext->getFrame() ) );
  }

  //----- list 0 and list 1 -----
  UInt uiPos;
  for( uiPos = 0; uiPos < cDecreasingPocList.getSize(); uiPos++ )
  {
    RNOK( rcList0.add( cDecreasingPocList.getEntry( uiPos ) ) );
  }
  for( uiPos = 0; uiPos < cIncreasingPocList.getSize(); uiPos++ )
  {
    RNOK( rcList0.add( cIncreasingPocList.getEntry( uiPos ) ) );
    RNOK( rcList1.add( cIncreasingPocList.getEntry( uiPos ) ) );
  }
  for( uiPos = 0; uiPos < cDecreasingPocList.getSize(); uiPos++ )
  {
    RNOK( rcList1.add( cDecreasingPocList.getEntry(uiPos) ) );
  }

  if( eCurrentPicType!=FRAME )
  {
		RNOK( xSetInitialRefFieldList( rcList0, pcCurrentFrame, eCurrentPicType, eSliceType ) );
    RNOK( xSetInitialRefFieldList( rcList1, pcCurrentFrame, eCurrentPicType, eSliceType ) );
  }

  //----- check for element switching -----
  if( rcList1.getActive() >= 2 && rcList0.getActive() == rcList1.getActive() )
  {
    Bool bSwitch = true;
    for( uiPos = 0; uiPos < rcList1.getActive(); uiPos++ )
    {
      if( rcList0.getEntry(uiPos) != rcList1.getEntry(uiPos) )
      {
        bSwitch = false;
        break;
      }
    }
    if( bSwitch )
    {
      rcList1.switchFirst();
    }
  }

  return Err::m_nOK;
}



ErrVal
DecodedPicBuffer::xPrdListRemapping ( RefFrameList&   rcList,
                                      ListIdx         eListIdx,
                                      SliceHeader*    pcSliceHeader )
{
  ROTRS( 0 == rcList.getSize(), Err::m_nOK );

  ROF( pcSliceHeader );
  const RplrBuffer& rcRplrBuffer = pcSliceHeader->getRplrBuffer( eListIdx );

  //===== re-odering =====
  if( rcRplrBuffer.getRefPicListReorderingFlag() )
  {
    const PicType eCurrentPicType = pcSliceHeader->getPicType();
    UInt    uiPicNumPred          = ( eCurrentPicType==FRAME ? pcSliceHeader->getFrameNum() : 
                                                               pcSliceHeader->getFrameNum()*2+1 );
    UInt    uiMaxPicNum           = ( eCurrentPicType==FRAME ? m_uiMaxFrameNum : 2*m_uiMaxFrameNum );

    Bool  bBaseRep          = pcSliceHeader->getUseBasePredictionFlag();
    UInt  uiIndex           = 0;
    RplrOp  uiCommand;
    UInt  uiIdentifier      = 0;

    while( RPLR_END != ( uiCommand = rcRplrBuffer.get(uiIndex).getCommand(uiIdentifier) ) )
    {
      IntFrame* pcFrame = NULL;

      if( uiCommand == RPLR_LONG )
      {
        //===== long term index =====
        RERR(); // long-term indices are currently not supported by the software
      }
      else
      {
        //===== short term index =====
        UInt  uiAbsDiff = uiIdentifier + 1;
        
        //----- set short-term index (pic num) -----
        if( uiCommand == RPLR_NEG )
        {
          if( uiPicNumPred < uiAbsDiff )
          {
            uiPicNumPred -= ( uiAbsDiff - uiMaxPicNum );
          }

⌨️ 快捷键说明

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