Ticket #1126: Suggested_fix_for_#1126.patch

File Suggested_fix_for_#1126.patch, 14.2 KB (added by rickard, 11 years ago)

A patch that checks some leading picture restrictions

  • source/Lib/TLibCommon/TComSlice.cpp

     
    519519  }
    520520}
    521521
    522 Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic)
     522Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic)
    523523{
    524524  for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++)
    525525  {
     
    545545  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found
    546546  {
    547547    pocCRA = getPOC();
    548     prevRAPisBLA = false;
     548    associatedIRAPType = getNalUnitType();
    549549  }
    550550  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
    551551  {
    552552    pocCRA = getPOC();
    553     prevRAPisBLA = false;
     553    associatedIRAPType = getNalUnitType();
    554554  }
    555555  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
    556556         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
    557557         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) // BLA picture found
    558558  {
    559559    pocCRA = getPOC();
    560     prevRAPisBLA = true;
     560    associatedIRAPType = getNalUnitType();
    561561  }
    562562}
    563563
     
    795795  return true;
    796796}
    797797
     798
     799Void TComSlice::checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic)
     800{
     801  TComPic* rpcPic;
     802
     803  Int nalUnitType = this->getNalUnitType();
     804
     805  // When a picture is a leading picture, it shall be a RADL or RASL picture.
     806  if(this->getAssociatedIRAPPOC() > this->getPOC())
     807  {
     808    // Do not check IRAP pictures since they may get a POC lower than their associated IRAP
     809    if(nalUnitType < NAL_UNIT_CODED_SLICE_BLA_W_LP ||
     810       nalUnitType > NAL_UNIT_RESERVED_IRAP_VCL23)
     811    {
     812      assert(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
     813             nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
     814             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
     815             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R);
     816    }
     817  }
     818
     819  // When a picture is a trailing picture, it shall not be a RADL or RASL picture.
     820  if(this->getAssociatedIRAPPOC() < this->getPOC())
     821  {
     822    assert(nalUnitType != NAL_UNIT_CODED_SLICE_RASL_N &&
     823           nalUnitType != NAL_UNIT_CODED_SLICE_RASL_R &&
     824           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_N &&
     825           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_R);
     826  }
     827
     828  // No RASL pictures shall be present in the bitstream that are associated
     829  // with a BLA picture having nal_unit_type equal to BLA_W_RADL or BLA_N_LP.
     830  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
     831     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
     832  {
     833    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_W_RADL &&
     834           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP);
     835  }
     836
     837  // No RASL pictures shall be present in the bitstream that are associated with
     838  // an IDR picture.
     839  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
     840     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
     841  {
     842    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP   &&
     843           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL);
     844  }
     845
     846  // No RADL pictures shall be present in the bitstream that are associated with
     847  // a BLA picture having nal_unit_type equal to BLA_N_LP or that are associated
     848  // with an IDR picture having nal_unit_type equal to IDR_N_LP.
     849  if(nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
     850     nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
     851  {
     852    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP   &&
     853           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP);
     854  }
     855
     856  // loop through all pictures in the reference picture buffer
     857  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
     858  while ( iterPic != rcListPic.end())
     859  {
     860    rpcPic = *(iterPic++);
     861
     862    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
     863    // in decoding order shall precede the IRAP picture in output order.
     864    // (Note that any picture following in output order would be present in the DPB)
     865    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
     866    {
     867      if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP    ||
     868         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP    ||
     869         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL  ||
     870         nalUnitType == NAL_UNIT_CODED_SLICE_CRA         ||
     871         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP    ||
     872         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
     873      {
     874        assert(rpcPic->getPOC() < this->getPOC());
     875      }
     876    }
     877
     878    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
     879    // in decoding order shall precede any RADL picture associated with the IRAP
     880    // picture in output order.
     881    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
     882    {
     883      if((nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
     884          nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R))
     885      {
     886        // rpcPic precedes the IRAP in decoding order
     887        if(this->getAssociatedIRAPPOC() > rpcPic->getSlice(0)->getAssociatedIRAPPOC())
     888        {
     889          // rpcPic must not be the IRAP picture
     890          if(this->getAssociatedIRAPPOC() != rpcPic->getPOC())
     891          {
     892            assert(rpcPic->getPOC() < this->getPOC());
     893          }
     894        }
     895      }
     896    }
     897
     898    // When a picture is a leading picture, it shall precede, in decoding order,
     899    // all trailing pictures that are associated with the same IRAP picture.
     900    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
     901       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
     902       nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
     903       nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
     904    {
     905      if(rpcPic->getSlice(0)->getAssociatedIRAPPOC() == this->getAssociatedIRAPPOC())
     906      {
     907        // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB
     908        // rpcPic would violate the constraint if it was a trailing picture
     909        assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC());
     910      }
     911    }
     912
     913    // Any RASL picture associated with a CRA or BLA picture shall precede any
     914    // RADL picture associated with the CRA or BLA picture in output order
     915    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
     916       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
     917    {
     918      if((this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
     919          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
     920          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
     921          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)       &&
     922          this->getAssociatedIRAPPOC() == rpcPic->getSlice(0)->getAssociatedIRAPPOC())
     923      {
     924        if(rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N ||
     925           rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R)
     926        {
     927          assert(rpcPic->getPOC() > this->getPOC());
     928        }
     929      }
     930    }
     931
     932    // Any RASL picture associated with a CRA picture shall follow, in output
     933    // order, any IRAP picture that precedes the CRA picture in decoding order.
     934    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
     935       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
     936    {
     937      if(this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)
     938      {
     939        if(rpcPic->getSlice(0)->getPOC() < this->getAssociatedIRAPPOC() &&
     940           (rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
     941            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
     942            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
     943            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP   ||
     944            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL ||
     945            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
     946        {
     947          assert(this->getPOC() > rpcPic->getSlice(0)->getPOC());
     948        }
     949      }
     950    }
     951  }
     952}
     953
     954
     955
    798956/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
    799957*/
    800958Void TComSlice::applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
     
    802960  TComPic* rpcPic;
    803961  Int i, isReference;
    804962
     963  checkLeadingPictureRestrictions(rcListPic);
     964
    805965  // loop through all pictures in the reference picture buffer
    806966  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
    807967  while ( iterPic != rcListPic.end())
  • source/Lib/TLibCommon/TComSlice.h

     
    11171117  Bool        m_PicOutputFlag;        ///< pic_output_flag
    11181118  Int         m_iPOC;
    11191119  Int         m_iLastIDR;
     1120  Int         m_iAssociatedIRAP;
     1121  NalUnitType m_iAssociatedIRAPType;
    11201122  static Int  m_prevTid0POC;
    11211123  TComReferencePictureSet *m_pcRPS;
    11221124  TComReferencePictureSet m_LocalRPS;
     
    12421244  TComRefPicListModification* getRefPicListModification() { return &m_RefPicListModification; }
    12431245  Void      setLastIDR(Int iIDRPOC)                       { m_iLastIDR = iIDRPOC; }
    12441246  Int       getLastIDR()                                  { return m_iLastIDR; }
     1247  Void      setAssociatedIRAPPOC(Int iAssociatedIRAPPOC)             { m_iAssociatedIRAP = iAssociatedIRAPPOC; }
     1248  Int       getAssociatedIRAPPOC()                        { return m_iAssociatedIRAP; }
     1249  Void      setAssociatedIRAPType(NalUnitType associatedIRAPType)    { m_iAssociatedIRAPType = associatedIRAPType; }
     1250  NalUnitType getAssociatedIRAPType()                        { return m_iAssociatedIRAPType; }
    12451251  SliceType getSliceType    ()                          { return  m_eSliceType;         }
    12461252  Int       getPOC          ()                          { return  m_iPOC;           }
    12471253  Int       getSliceQp      ()                          { return  m_iSliceQp;           }
     
    12801286  Bool      getRapPicFlag       (); 
    12811287  Bool      getIdrPicFlag       ()                              { return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP; }
    12821288  Bool      isIRAP              () const                        { return (getNalUnitType() >= 16) && (getNalUnitType() <= 23); } 
    1283   Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic);
     1289  Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic);
    12841290  Void      decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic);
    12851291  Void      setSliceType        ( SliceType e )                 { m_eSliceType        = e;      }
    12861292  Void      setSliceQp          ( Int i )                       { m_iSliceQp          = i;      }
     
    13451351
    13461352  Void setTLayerInfo( UInt uiTLayer );
    13471353  Void decodingMarking( TComList<TComPic*>& rcListPic, Int iGOPSIze, Int& iMaxRefPicNum );
     1354  Void checkLeadingPictureRestrictions( TComList<TComPic*>& rcListPic );
    13481355  Void applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *RPSList);
    13491356  Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
    13501357  Bool isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic );
  • source/Lib/TLibDecoder/TDecTop.cpp

     
    5050  g_bJustDoIt = g_bEncDecTraceDisable;
    5151  g_nSymbolCounter = 0;
    5252#endif
     53  m_associatedIRAPType = NAL_UNIT_INVALID;
    5354  m_pocCRA = 0;
    54   m_prevRAPisBLA = false;
    5555  m_pocRandomAccess = MAX_INT;         
    5656  m_prevPOC                = MAX_INT;
    5757  m_bFirstSliceInPicture    = true;
     
    334334
    335335  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
    336336
     337  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
     338  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
     339
    337340  // Skip pictures due to random access
    338341  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
    339342  {
     
    512515
    513516  if (bNextSlice)
    514517  {
    515     pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
     518    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
    516519    // Set reference list
    517520#if FIX1071
    518521    pcSlice->setRefPicList( m_cListPic, true );
     
    697700 */
    698701Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
    699702{
    700   if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
     703  if ((m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_N_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_RADL) &&
     704       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
    701705  {
    702706    iPOCLastDisplay++;
    703707    return true;
  • source/Lib/TLibDecoder/TDecTop.h

     
    6666private:
    6767  Int                     m_iMaxRefPicNum;
    6868 
     69  NalUnitType             m_associatedIRAPType; ///< NAL unit type of the associated IRAP picture
    6970  Int                     m_pocCRA;            ///< POC number of the latest CRA picture
    70   Bool                    m_prevRAPisBLA;      ///< true if the previous RAP (CRA/CRANT/BLA/BLANT/IDR) picture is a BLA/BLANT picture
    7171  Int                     m_pocRandomAccess;   ///< POC number of the random access point (the first IDR or CRA picture)
    7272
    7373  TComList<TComPic*>      m_cListPic;         //  Dynamic buffer