Skip to content
Snippets Groups Projects
Slice.h 154 KiB
Newer Older
  • Learn to ignore specific revisions
  •   AlfSliceParam&              getAlfSliceParam() { return m_alfSliceParam; }
    
      void                        initMotionLUTs       ();
      void                        destroyMotionLUTs    ();
      void                        resetMotionLUTs();
    
    Yu Han's avatar
    Yu Han committed
    #if JVET_M0483_IBC
    
    Yu Han's avatar
    Yu Han committed
      int                         getAvailableLUTIBCMrgNum() const { return m_MotionCandLut->currCntIBC; }
    #endif
    
    Li's avatar
    Li committed
      int                         getAvailableLUTMrgNum() const  { return m_MotionCandLut->currCnt; }
    
    #if JVET_M0170_MRG_SHARELIST
      int                         getAvailableLUTBkupMrgNum() const  { return m_MotionCandLuTsBkup->currCnt; }
      MotionInfo                  getMotionInfoFromLUTBkup(int MotCandIdx) const;
    #endif
    
      MotionInfo                  getMotionInfoFromLUTs(int MotCandIdx) const;
    
    Li's avatar
    Li committed
      LutMotionCand*              getMotionLUTs() { return m_MotionCandLut; }
    
    Yu Han's avatar
    Yu Han committed
    #if JVET_M0483_IBC
    
    Yu Han's avatar
    Yu Han committed
      void                        addMotionInfoToLUTs(LutMotionCand* lutMC, MotionInfo newMi, bool ibcflag);
    #else
    
    Li's avatar
    Li committed
      void                        addMotionInfoToLUTs(LutMotionCand* lutMC, MotionInfo newMi);
    
    Yu Han's avatar
    Yu Han committed
    #endif
    
    Li's avatar
    Li committed
      void                        updateMotionLUTs(LutMotionCand* lutMC, CodingUnit & cu);
      void                        copyMotionLUTs(LutMotionCand* Src, LutMotionCand* Dst);
    
    Taoran Lu's avatar
    Taoran Lu committed
    #if JVET_M0427_INLOOP_RESHAPER
    
    Taoran Lu's avatar
    Taoran Lu committed
      const SliceReshapeInfo&     getReshapeInfo() const { return m_sliceReshapeInfo; }
            SliceReshapeInfo&     getReshapeInfo()       { return m_sliceReshapeInfo; }
    
    Taoran Lu's avatar
    Taoran Lu committed
    #endif
    
    protected:
      Picture*              xGetRefPic        (PicList& rcListPic, int poc);
      Picture*              xGetLongTermRefPic(PicList& rcListPic, int poc, bool pocHasMsb);
    };// END CLASS DEFINITION Slice
    
    
    
    
    
    void calculateParameterSetChangedFlag(bool &bChanged, const std::vector<uint8_t> *pOldData, const std::vector<uint8_t> *pNewData);
    
    template <class T> class ParameterSetMap
    {
    public:
      template <class Tm>
      struct MapData
      {
        bool                  bChanged;
        std::vector<uint8_t>   *pNaluData; // Can be null
        Tm*                   parameterSet;
      };
    
      ParameterSetMap(int maxId)
      :m_maxId (maxId)
      ,m_activePsId(-1)
      ,m_lastActiveParameterSet(NULL)
      {}
    
      ~ParameterSetMap()
      {
        for (typename std::map<int,MapData<T> >::iterator i = m_paramsetMap.begin(); i!= m_paramsetMap.end(); i++)
        {
          delete (*i).second.pNaluData;
          delete (*i).second.parameterSet;
        }
        delete m_lastActiveParameterSet; m_lastActiveParameterSet = NULL;
      }
    
      T *allocatePS(const int psId)
      {
        CHECK( psId >= m_maxId, "Invalid PS id" );
        if ( m_paramsetMap.find(psId) == m_paramsetMap.end() )
        {
          m_paramsetMap[psId].bChanged = true;
          m_paramsetMap[psId].pNaluData=0;
          m_paramsetMap[psId].parameterSet = new T;
          setID(m_paramsetMap[psId].parameterSet, psId);
        }
        return m_paramsetMap[psId].parameterSet;
      }
    
      void storePS(int psId, T *ps, const std::vector<uint8_t> *pNaluData)
      {
        CHECK( psId >= m_maxId, "Invalid PS id" );
        if ( m_paramsetMap.find(psId) != m_paramsetMap.end() )
        {
          MapData<T> &mapData=m_paramsetMap[psId];
    
          // work out changed flag
          calculateParameterSetChangedFlag(mapData.bChanged, mapData.pNaluData, pNaluData);
    
          if( ! mapData.bChanged )
          {
            // just keep the old one
            delete ps;
            return;
          }
    
          if( m_activePsId == psId )
          {
            std::swap( m_paramsetMap[psId].parameterSet, m_lastActiveParameterSet );
          }
          delete m_paramsetMap[psId].pNaluData;
          delete m_paramsetMap[psId].parameterSet;
    
          m_paramsetMap[psId].parameterSet = ps;
        }
        else
        {
          m_paramsetMap[psId].parameterSet = ps;
          m_paramsetMap[psId].bChanged = false;
        }
        if (pNaluData != 0)
        {
          m_paramsetMap[psId].pNaluData=new std::vector<uint8_t>;
          *(m_paramsetMap[psId].pNaluData) = *pNaluData;
        }
        else
        {
          m_paramsetMap[psId].pNaluData=0;
        }
      }
    
      void setChangedFlag(int psId, bool bChanged=true)
      {
        if ( m_paramsetMap.find(psId) != m_paramsetMap.end() )
        {
          m_paramsetMap[psId].bChanged=bChanged;
        }
      }
    
      void clearChangedFlag(int psId)
      {
        if ( m_paramsetMap.find(psId) != m_paramsetMap.end() )
        {
          m_paramsetMap[psId].bChanged=false;
        }
      }
    
      bool getChangedFlag(int psId) const
      {
        const typename std::map<int,MapData<T> >::const_iterator constit=m_paramsetMap.find(psId);
        if ( constit != m_paramsetMap.end() )
        {
          return constit->second.bChanged;
        }
        return false;
      }
    
      T* getPS(int psId)
      {
        typename std::map<int,MapData<T> >::iterator it=m_paramsetMap.find(psId);
        return ( it == m_paramsetMap.end() ) ? NULL : (it)->second.parameterSet;
      }
    
      const T* getPS(int psId) const
      {
        typename std::map<int,MapData<T> >::const_iterator it=m_paramsetMap.find(psId);
        return ( it == m_paramsetMap.end() ) ? NULL : (it)->second.parameterSet;
      }
    
      T* getFirstPS()
      {
        return (m_paramsetMap.begin() == m_paramsetMap.end() ) ? NULL : m_paramsetMap.begin()->second.parameterSet;
      }
    
      void setActive(int psId ) { m_activePsId = psId;}
    
    private:
      std::map<int,MapData<T> > m_paramsetMap;
      int                       m_maxId;
      int                       m_activePsId;
      T*                        m_lastActiveParameterSet;
      static void setID(T* parameterSet, const int psId);
    };
    
    
    class ParameterSetManager
    {
    public:
                     ParameterSetManager();
      virtual        ~ParameterSetManager();
    
    #if HEVC_VPS
      //! store sequence parameter set and take ownership of it
      void           storeVPS(VPS *vps, const std::vector<uint8_t> &naluData)      { m_vpsMap.storePS( vps->getVPSId(), vps, &naluData); };
      //! get pointer to existing video parameter set
      VPS*           getVPS(int vpsId)                                           { return m_vpsMap.getPS(vpsId); };
      bool           getVPSChangedFlag(int vpsId) const                          { return m_vpsMap.getChangedFlag(vpsId); }
      void           clearVPSChangedFlag(int vpsId)                              { m_vpsMap.clearChangedFlag(vpsId); }
      VPS*           getFirstVPS()                                               { return m_vpsMap.getFirstPS(); };
    #endif
    
      //! store sequence parameter set and take ownership of it
      void           storeSPS(SPS *sps, const std::vector<uint8_t> &naluData) { m_spsMap.storePS( sps->getSPSId(), sps, &naluData); };
      //! get pointer to existing sequence parameter set
      SPS*           getSPS(int spsId)                                           { return m_spsMap.getPS(spsId); };
      bool           getSPSChangedFlag(int spsId) const                          { return m_spsMap.getChangedFlag(spsId); }
      void           clearSPSChangedFlag(int spsId)                              { m_spsMap.clearChangedFlag(spsId); }
      SPS*           getFirstSPS()                                               { return m_spsMap.getFirstPS(); };
    
      //! store picture parameter set and take ownership of it
      void           storePPS(PPS *pps, const std::vector<uint8_t> &naluData) { m_ppsMap.storePS( pps->getPPSId(), pps, &naluData); };
      //! get pointer to existing picture parameter set
      PPS*           getPPS(int ppsId)                                           { return m_ppsMap.getPS(ppsId); };
      bool           getPPSChangedFlag(int ppsId) const                          { return m_ppsMap.getChangedFlag(ppsId); }
      void           clearPPSChangedFlag(int ppsId)                              { m_ppsMap.clearChangedFlag(ppsId); }
      PPS*           getFirstPPS()                                               { return m_ppsMap.getFirstPS(); };
    
      //! activate a SPS from a active parameter sets SEI message
      //! \returns true, if activation is successful
      // bool           activateSPSWithSEI(int SPSId);
    
    #if HEVC_VPS
      //! activate a PPS and depending on isIDR parameter also SPS and VPS
    #else
      //! activate a PPS and depending on isIDR parameter also SPS
    #endif
      //! \returns true, if activation is successful
      bool           activatePPS(int ppsId, bool isIRAP);
    
    #if HEVC_VPS
      const VPS*     getActiveVPS()const                                         { return m_vpsMap.getPS(m_activeVPSId); };
    #endif
      const SPS*     getActiveSPS()const                                         { return m_spsMap.getPS(m_activeSPSId); };
    
    protected:
    #if HEVC_VPS
      ParameterSetMap<VPS> m_vpsMap;
    #endif
      ParameterSetMap<SPS> m_spsMap;
      ParameterSetMap<PPS> m_ppsMap;
    
    #if HEVC_VPS
      int m_activeVPSId; // -1 for nothing active
    #endif
      int m_activeSPSId; // -1 for nothing active
    };
    
    class PreCalcValues
    {
    public:
      PreCalcValues( const SPS& sps, const PPS& pps, bool _isEncoder )
        : chrFormat           ( sps.getChromaFormatIdc() )
    
    Karsten Suehring's avatar
    Karsten Suehring committed
        , multiBlock422       ( false )
    
        , maxCUWidth          ( sps.getMaxCUWidth() )
        , maxCUHeight         ( sps.getMaxCUHeight() )
        , maxCUWidthMask      ( maxCUWidth  - 1 )
        , maxCUHeightMask     ( maxCUHeight - 1 )
        , maxCUWidthLog2      ( g_aucLog2[ maxCUWidth  ] )
        , maxCUHeightLog2     ( g_aucLog2[ maxCUHeight ] )
        , minCUWidth          ( sps.getMaxCUWidth()  >> sps.getMaxCodingDepth() )
        , minCUHeight         ( sps.getMaxCUHeight() >> sps.getMaxCodingDepth() )
        , minCUWidthLog2      ( g_aucLog2[ minCUWidth  ] )
        , minCUHeightLog2     ( g_aucLog2[ minCUHeight ] )
        , partsInCtuWidth     ( 1 << sps.getMaxCodingDepth() )
        , partsInCtuHeight    ( 1 << sps.getMaxCodingDepth() )
        , partsInCtu          ( 1 << (sps.getMaxCodingDepth() << 1) )
        , widthInCtus         ( (sps.getPicWidthInLumaSamples () + sps.getMaxCUWidth () - 1) / sps.getMaxCUWidth () )
        , heightInCtus        ( (sps.getPicHeightInLumaSamples() + sps.getMaxCUHeight() - 1) / sps.getMaxCUHeight() )
        , sizeInCtus          ( widthInCtus * heightInCtus )
        , lumaWidth           ( sps.getPicWidthInLumaSamples() )
        , lumaHeight          ( sps.getPicHeightInLumaSamples() )
        , fastDeltaQPCuMaxSize( Clip3(sps.getMaxCUHeight() >> (sps.getLog2DiffMaxMinCodingBlockSize()), sps.getMaxCUHeight(), 32u) )
    
    Karsten Suehring's avatar
    Karsten Suehring committed
        , noChroma2x2         (  false )
    
        , ISingleTree         ( !sps.getUseDualITree() )
        , maxBtDepth          { sps.getMaxBTDepthI(), sps.getMaxBTDepth(), sps.getMaxBTDepthIChroma() }
        , minBtSize           { MIN_BT_SIZE, MIN_BT_SIZE_INTER, MIN_BT_SIZE_C }
        , maxBtSize           { sps.getMaxBTSizeI(), sps.getMaxBTSize(), sps.getMaxBTSizeIChroma() }
        , minTtSize           { MIN_TT_SIZE, MIN_TT_SIZE_INTER, MIN_TT_SIZE_C }
        , maxTtSize           { sps.getMaxTTSizeI(), sps.getMaxTTSize(), sps.getMaxTTSizeIChroma() }
        , minQtSize           { sps.getMinQTSize(I_SLICE, CHANNEL_TYPE_LUMA), sps.getMinQTSize(B_SLICE, CHANNEL_TYPE_LUMA), sps.getMinQTSize(I_SLICE, CHANNEL_TYPE_CHROMA) }
    
      {}
    
      const ChromaFormat chrFormat;
      const bool         multiBlock422;
      const unsigned     maxCUWidth;
      const unsigned     maxCUHeight;
      // to get CTU position, use (x & maxCUWidthMask) rather than (x % maxCUWidth)
      const unsigned     maxCUWidthMask;
      const unsigned     maxCUHeightMask;
      const unsigned     maxCUWidthLog2;
      const unsigned     maxCUHeightLog2;
      const unsigned     minCUWidth;
      const unsigned     minCUHeight;
      const unsigned     minCUWidthLog2;
      const unsigned     minCUHeightLog2;
      const unsigned     partsInCtuWidth;
      const unsigned     partsInCtuHeight;
      const unsigned     partsInCtu;
      const unsigned     widthInCtus;
      const unsigned     heightInCtus;
      const unsigned     sizeInCtus;
      const unsigned     lumaWidth;
      const unsigned     lumaHeight;
      const unsigned     fastDeltaQPCuMaxSize;
      const bool         noChroma2x2;
      const bool         isEncoder;
      const bool         ISingleTree;
    
    private:
      const unsigned     maxBtDepth[3];
      const unsigned     minBtSize [3];
      const unsigned     maxBtSize [3];
      const unsigned     minTtSize [3];
      const unsigned     maxTtSize [3];
      const unsigned     minQtSize [3];
    
      unsigned getValIdx    ( const Slice &slice, const ChannelType chType ) const;
    
    public:
      unsigned getMaxBtDepth( const Slice &slice, const ChannelType chType ) const;
      unsigned getMinBtSize ( const Slice &slice, const ChannelType chType ) const;
      unsigned getMaxBtSize ( const Slice &slice, const ChannelType chType ) const;
      unsigned getMinTtSize ( const Slice &slice, const ChannelType chType ) const;
      unsigned getMaxTtSize ( const Slice &slice, const ChannelType chType ) const;
      unsigned getMinQtSize ( const Slice &slice, const ChannelType chType ) const;
    };
    
    #if ENABLE_TRACING
    #if HEVC_VPS
    void xTraceVPSHeader();
    #endif
    void xTraceSPSHeader();
    void xTracePPSHeader();
    void xTraceSliceHeader();
    void xTraceAccessUnitDelimiter();
    #endif
    
    #endif // __SLICE__