Skip to content
Snippets Groups Projects
EncCu.cpp 173 KiB
Newer Older
  • Learn to ignore specific revisions
  •         m_bestGbiCost[1] = m_bestGbiCost[0];
            m_bestGbiCost[0] = tempCS->cost;
            m_bestGbiIdx[1] = m_bestGbiIdx[0];
            m_bestGbiIdx[0] = cu->GBiIdx;
          }
          else
          {
            m_bestGbiCost[1] = tempCS->cost;
            m_bestGbiIdx[1] = cu->GBiIdx;
          }
        }
      }
    #endif
    
    }
    
    
    void EncCu::xEncodeDontSplit( CodingStructure &cs, Partitioner &partitioner )
    {
      m_CABACEstimator->resetBits();
    
    
    Adam Wieckowski's avatar
    Adam Wieckowski committed
    #if JVET_M0421_SPLIT_SIG
      m_CABACEstimator->split_cu_mode( CU_DONT_SPLIT, cs, partitioner );
    #else
    
      {
        if( partitioner.canSplit( CU_QUAD_SPLIT, cs ) )
        {
          m_CABACEstimator->split_cu_flag( false, cs, partitioner );
        }
        if( partitioner.canSplit( CU_MT_SPLIT, cs ) )
        {
          m_CABACEstimator->split_cu_mode_mt( CU_DONT_SPLIT, cs, partitioner );
        }
      }
    
    Adam Wieckowski's avatar
    Adam Wieckowski committed
    #endif
    
    
      cs.fracBits += m_CABACEstimator->getEstFracBits(); // split bits
      cs.cost      = m_pcRdCost->calcRdCost( cs.fracBits, cs.dist );
    
    }
    
    #if REUSE_CU_RESULTS
    void EncCu::xReuseCachedResult( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner )
    {
      BestEncInfoCache* bestEncCache = dynamic_cast<BestEncInfoCache*>( m_modeCtrl );
      CHECK( !bestEncCache, "If this mode is chosen, mode controller has to implement the mode caching capabilities" );
      EncTestMode cachedMode;
    
      if( bestEncCache->setCsFrom( *tempCS, cachedMode, partitioner ) )
      {
        CodingUnit& cu = *tempCS->cus.front();
    
    #if JVET_M0170_MRG_SHARELIST
        cu.shareParentPos = tempCS->sharedBndPos;
        cu.shareParentSize = tempCS->sharedBndSize;
    #endif
    
        partitioner.setCUData( cu );
    
        if( CU::isIntra( cu ) )
        {
          xReconIntraQT( cu );
        }
        else
        {
          xDeriveCUMV( cu );
          xReconInter( cu );
        }
    
    
    Nan Hu's avatar
    Nan Hu committed
        Distortion finalDistortion = 0;
    
    Nan Hu's avatar
    Nan Hu committed
    #if JVET_M0428_ENC_DB_OPT
        tempCS->useDbCost = m_pcEncCfg->getUseEncDbOpt();
    
    Nan Hu's avatar
    Nan Hu committed
        if ( m_pcEncCfg->getUseEncDbOpt() )
        {
          xCalDebCost( *tempCS, partitioner, true );
          finalDistortion = tempCS->dist;
        }
        else
        {
    #endif
    
    Nan Hu's avatar
    Nan Hu committed
        const SPS &sps = *tempCS->sps;
    
        const int  numValidComponents = getNumberValidComponents( tempCS->area.chromaFormat );
    
        for( int comp = 0; comp < numValidComponents; comp++ )
        {
          const ComponentID compID = ComponentID( comp );
    
          if( CS::isDualITree( *tempCS ) && toChannelType( compID ) != partitioner.chType )
          {
            continue;
          }
    
          CPelBuf reco = tempCS->getRecoBuf( compID );
          CPelBuf org  = tempCS->getOrgBuf ( compID );
    
    #if WCG_EXT
    
    Taoran Lu's avatar
    Taoran Lu committed
    #if JVET_M0427_INLOOP_RESHAPER
          if (m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() || (
            m_pcEncCfg->getReshaper() && (tempCS->slice->getReshapeInfo().getUseSliceReshaper() && m_pcReshape->getCTUFlag())))
    #else
    
          if( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() )
    
    Taoran Lu's avatar
    Taoran Lu committed
    #endif
    
          {
            const CPelBuf orgLuma = tempCS->getOrgBuf(tempCS->area.blocks[COMPONENT_Y]);
    
    Taoran Lu's avatar
    Taoran Lu committed
    #if JVET_M0427_INLOOP_RESHAPER
    
    Taoran Lu's avatar
    Taoran Lu committed
            if (compID == COMPONENT_Y && !(m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled()))
    
    Taoran Lu's avatar
    Taoran Lu committed
            {
              const CompArea &area = cu.blocks[COMPONENT_Y];
              CompArea    tmpArea(COMPONENT_Y, area.chromaFormat, Position(0, 0), area.size());
              PelBuf tmpRecLuma = m_tmpStorageLCU->getBuf(tmpArea);
              tmpRecLuma.copyFrom(reco);
              tmpRecLuma.rspSignal(m_pcReshape->getInvLUT());
              finalDistortion += m_pcRdCost->getDistPart(org, tmpRecLuma, sps.getBitDepth(toChannelType(compID)), compID, DF_SSE_WTD, &orgLuma);
            }
            else
    #endif
    
            finalDistortion += m_pcRdCost->getDistPart( org, reco, sps.getBitDepth( toChannelType( compID ) ), compID, DF_SSE_WTD, &orgLuma );
          }
          else
    #endif
          finalDistortion += m_pcRdCost->getDistPart( org, reco, sps.getBitDepth( toChannelType( compID ) ), compID, DF_SSE );
        }
    
    Nan Hu's avatar
    Nan Hu committed
    #if JVET_M0428_ENC_DB_OPT
        }
    
    Nan Hu's avatar
    Nan Hu committed
    #endif
    
    
        m_CABACEstimator->getCtx() = m_CurrCtx->start;
        m_CABACEstimator->resetBits();
    
        CUCtx cuCtx;
        cuCtx.isDQPCoded = true;
        cuCtx.isChromaQpAdjCoded = true;
        m_CABACEstimator->coding_unit( cu, partitioner, cuCtx );
    
    
    Nan Hu's avatar
    Nan Hu committed
    
    
        tempCS->dist     = finalDistortion;
        tempCS->fracBits = m_CABACEstimator->getEstFracBits();
        tempCS->cost     = m_pcRdCost->calcRdCost( tempCS->fracBits, tempCS->dist );
    
        xEncodeDontSplit( *tempCS,         partitioner );
        xCheckDQP       ( *tempCS,         partitioner );
        xCheckBestMode  (  tempCS, bestCS, partitioner, cachedMode );
      }
      else
      {
        THROW( "Should never happen!" );
      }
    }
    #endif