Ignore:
Timestamp:
26 May 2016, 15:03:18 (8 years ago)
Author:
tech
Message:

Initial merge of HM-16.9.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HTM-16.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp

    r1401 r1402  
    108108  m_associatedIRAPType = NAL_UNIT_CODED_SLICE_IDR_N_LP;
    109109  m_associatedIRAPPOC  = 0;
     110#if W0038_DB_OPT
     111  m_pcDeblockingTempPicYuv = NULL;
     112#endif
    110113  return;
    111114}
     
    125128Void  TEncGOP::destroy()
    126129{
     130#if W0038_DB_OPT
     131  if (m_pcDeblockingTempPicYuv)
     132  {
     133    m_pcDeblockingTempPicYuv->destroy();
     134    delete m_pcDeblockingTempPicYuv;
     135    m_pcDeblockingTempPicYuv = NULL;
     136  }
     137#endif
    127138}
    128139
     
    502513    seiMessages.push_back(seiChromaResamplingFilterHint);
    503514  }
     515#if U0033_ALTERNATIVE_TRANSFER_CHARACTERISTICS_SEI
     516  if(m_pcCfg->getSEIAlternativeTransferCharacteristicsSEIEnable())
     517  {
     518    SEIAlternativeTransferCharacteristics *seiAlternativeTransferCharacteristics = new SEIAlternativeTransferCharacteristics;
     519    m_seiEncoder.initSEIAlternativeTransferCharacteristics(seiAlternativeTransferCharacteristics);
     520    seiMessages.push_back(seiAlternativeTransferCharacteristics);
     521  }
     522#endif
    504523}
    505524
     
    17271746        estimatedCpbFullness -= m_pcRateCtrl->getBufferingRate();
    17281747        // prevent underflow
     1748#if V0078_ADAPTIVE_LOWER_BOUND
     1749        if (estimatedCpbFullness - estimatedBits < m_pcRateCtrl->getRCPic()->getLowerBound())
     1750        {
     1751          estimatedBits = max(200, estimatedCpbFullness - m_pcRateCtrl->getRCPic()->getLowerBound());
     1752        }
     1753#else
    17291754        if (estimatedCpbFullness - estimatedBits < (Int)(m_pcRateCtrl->getCpbSize()*0.1f))
    17301755        {
    17311756          estimatedBits = max(200, estimatedCpbFullness - (Int)(m_pcRateCtrl->getCpbSize()*0.1f));
    17321757        }
     1758#endif
    17331759
    17341760        m_pcRateCtrl->getRCPic()->setTargetBits(estimatedBits);
     
    17691795            estimatedCpbFullness -= m_pcRateCtrl->getBufferingRate();
    17701796            // prevent underflow
     1797#if V0078_ADAPTIVE_LOWER_BOUND
     1798            if (estimatedCpbFullness - bits < m_pcRateCtrl->getRCPic()->getLowerBound())
     1799            {
     1800              bits = estimatedCpbFullness - m_pcRateCtrl->getRCPic()->getLowerBound();
     1801            }
     1802#else
    17711803            if (estimatedCpbFullness - bits < (Int)(m_pcRateCtrl->getCpbSize()*0.1f))
    17721804            {
    17731805              bits = estimatedCpbFullness - (Int)(m_pcRateCtrl->getCpbSize()*0.1f);
    17741806            }
     1807#endif
    17751808          }
    17761809#endif
     
    19021935    if ( m_pcCfg->getDeblockingFilterMetric() )
    19031936    {
     1937#if W0038_DB_OPT
     1938      if ( m_pcCfg->getDeblockingFilterMetric()==2 )
     1939      {
     1940        applyDeblockingFilterParameterSelection(pcPic, uiNumSliceSegments, iGOPid);
     1941      }
     1942      else
     1943      {
     1944#endif
    19041945      applyDeblockingFilterMetric(pcPic, uiNumSliceSegments);
     1946#if W0038_DB_OPT
     1947      }
     1948#endif
    19051949    }
    19061950    m_pcLoopFilter->loopFilterPic( pcPic );
     
    19541998      m_pcEncTop->getRDGoOnSbacCoder()->setBitstream(&tempBitCounter);
    19551999      m_pcSAO->initRDOCabacCoder(m_pcEncTop->getRDGoOnSbacCoder(), pcSlice);
     2000#if OPTIONAL_RESET_SAO_ENCODING_AFTER_IRAP
     2001      m_pcSAO->SAOProcess(pcPic, sliceEnabled, pcPic->getSlice(0)->getLambdas(),
     2002                          m_pcCfg->getTestSAODisableAtPictureLevel(),
     2003                          m_pcCfg->getSaoEncodingRate(),
     2004                          m_pcCfg->getSaoEncodingRateChroma(),
     2005                          m_pcCfg->getSaoCtuBoundary(),
     2006                          m_pcCfg->getSaoResetEncoderStateAfterIRAP());
     2007#else
    19562008      m_pcSAO->SAOProcess(pcPic, sliceEnabled, pcPic->getSlice(0)->getLambdas(), m_pcCfg->getTestSAODisableAtPictureLevel(), m_pcCfg->getSaoEncodingRate(), m_pcCfg->getSaoEncodingRateChroma(), m_pcCfg->getSaoCtuBoundary());
     2009#endif
    19572010      m_pcSAO->PCMLFDisableProcess(pcPic);
    19582011      m_pcEncTop->getRDGoOnSbacCoder()->setBitstream(NULL);
     
    21862239  //--CFG_KDY
    21872240  const Int rateMultiplier=(isField?2:1);
    2188   m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier );
    2189   m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier );
    2190   m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier );
    2191   m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier );
     2241  m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier / (Double)m_pcCfg->getTemporalSubsampleRatio());
     2242  m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier / (Double)m_pcCfg->getTemporalSubsampleRatio());
     2243  m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier / (Double)m_pcCfg->getTemporalSubsampleRatio());
     2244  m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier / (Double)m_pcCfg->getTemporalSubsampleRatio());
    21922245  const ChromaFormat chFmt = m_pcCfg->getChromaFormatIdc();
    21932246
     
    22242277  {
    22252278    //-- interlaced summary
     2279#if TEMPORAL_SUBSAMPLE
     2280    m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate() / (Double)m_pcCfg->getTemporalSubsampleRatio());
     2281#else
    22262282    m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate());
     2283#endif
    22272284    m_gcAnalyzeAll_in.setBits(m_gcAnalyzeAll.getBits());
    22282285    // prior to the above statement, the interlace analyser does not contain the correct total number of bits.
     
    29593016  assert(noCol > 1);
    29603017  assert(noRows > 1);
    2961   UInt64 *colSAD = (UInt64*)malloc(noCol*sizeof(UInt64));
    2962   UInt64 *rowSAD = (UInt64*)malloc(noRows*sizeof(UInt64));
     3018  std::vector<UInt64> colSAD(noCol,  UInt64(0));
     3019  std::vector<UInt64> rowSAD(noRows, UInt64(0));
    29633020  UInt colIdx = 0;
    29643021  UInt rowIdx = 0;
     
    29723029  const Int thr1 = 2*bitdepthScale;
    29733030  UInt a = 0;
    2974 
    2975   memset(colSAD, 0, noCol*sizeof(UInt64));
    2976   memset(rowSAD, 0, noRows*sizeof(UInt64));
    29773031
    29783032  if (maxTBsize > minBlockArtSize)
     
    30643118    }
    30653119  }
    3066 
    3067   free(colSAD);
    3068   free(rowSAD);
    3069 }
     3120}
     3121
     3122#if W0038_DB_OPT
     3123Void TEncGOP::applyDeblockingFilterParameterSelection( TComPic* pcPic, const UInt numSlices, const Int gopID )
     3124{
     3125  enum DBFltParam
     3126  {
     3127    DBFLT_PARAM_AVAILABLE = 0,
     3128    DBFLT_DISABLE_FLAG,
     3129    DBFLT_BETA_OFFSETD2,
     3130    DBFLT_TC_OFFSETD2,
     3131    //NUM_DBFLT_PARAMS
     3132  };
     3133  const Int MAX_BETA_OFFSET = 3;
     3134  const Int MIN_BETA_OFFSET = -3;
     3135  const Int MAX_TC_OFFSET = 3;
     3136  const Int MIN_TC_OFFSET = -3;
     3137
     3138  TComPicYuv* pcPicYuvRec = pcPic->getPicYuvRec();
     3139  TComPicYuv* pcPicYuvOrg = pcPic ->getPicYuvOrg();
     3140
     3141  const Int currQualityLayer = (pcPic->getSlice(0)->getSliceType() != I_SLICE) ? m_pcCfg->getGOPEntry(gopID).m_temporalId+1 : 0;
     3142  assert(currQualityLayer <MAX_ENCODER_DEBLOCKING_QUALITY_LAYERS);
     3143
     3144  if(!m_pcDeblockingTempPicYuv)
     3145  {
     3146    m_pcDeblockingTempPicYuv         = new TComPicYuv;
     3147    m_pcDeblockingTempPicYuv->create( m_pcEncTop->getSourceWidth(), m_pcEncTop->getSourceHeight(), m_pcEncTop->getChromaFormatIdc(),  pcPic->getSlice(0)->getSPS()->getMaxCUWidth(), pcPic->getSlice(0)->getSPS()->getMaxCUHeight(), pcPic->getSlice(0)->getSPS()->getMaxTotalCUDepth(),true );
     3148    memset(m_DBParam, 0, sizeof(m_DBParam));
     3149  }
     3150
     3151  //preserve current reconstruction
     3152  pcPicYuvRec->copyToPic(m_pcDeblockingTempPicYuv);
     3153
     3154  const Bool bNoFiltering      = m_DBParam[currQualityLayer][DBFLT_PARAM_AVAILABLE] && m_DBParam[currQualityLayer][DBFLT_DISABLE_FLAG]==false /*&& pcPic->getTLayer()==0*/;
     3155  const Int  maxBetaOffsetDiv2 = bNoFiltering? Clip3(MIN_BETA_OFFSET, MAX_BETA_OFFSET, m_DBParam[currQualityLayer][DBFLT_BETA_OFFSETD2]+1) : MAX_BETA_OFFSET;
     3156  const Int  minBetaOffsetDiv2 = bNoFiltering? Clip3(MIN_BETA_OFFSET, MAX_BETA_OFFSET, m_DBParam[currQualityLayer][DBFLT_BETA_OFFSETD2]-1) : MIN_BETA_OFFSET;
     3157  const Int  maxTcOffsetDiv2   = bNoFiltering? Clip3(MIN_TC_OFFSET, MAX_TC_OFFSET, m_DBParam[currQualityLayer][DBFLT_TC_OFFSETD2]+2)       : MAX_TC_OFFSET;
     3158  const Int  minTcOffsetDiv2   = bNoFiltering? Clip3(MIN_TC_OFFSET, MAX_TC_OFFSET, m_DBParam[currQualityLayer][DBFLT_TC_OFFSETD2]-2)       : MIN_TC_OFFSET;
     3159
     3160  UInt64 distBetaPrevious      = std::numeric_limits<UInt64>::max();
     3161  UInt64 distMin               = std::numeric_limits<UInt64>::max();
     3162  Bool   bDBFilterDisabledBest = true;
     3163  Int    betaOffsetDiv2Best    = 0;
     3164  Int    tcOffsetDiv2Best      = 0;
     3165
     3166  for(Int betaOffsetDiv2=maxBetaOffsetDiv2; betaOffsetDiv2>=minBetaOffsetDiv2; betaOffsetDiv2--)
     3167  {
     3168    UInt64 distTcMin = std::numeric_limits<UInt64>::max();
     3169    for(Int tcOffsetDiv2=maxTcOffsetDiv2; tcOffsetDiv2 >= minTcOffsetDiv2; tcOffsetDiv2--)
     3170    {
     3171      for (Int i=0; i<numSlices; i++)
     3172      {
     3173        pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true);
     3174        pcPic->getSlice(i)->setDeblockingFilterDisable(false);
     3175        pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( betaOffsetDiv2 );
     3176        pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( tcOffsetDiv2 );
     3177      }
     3178      m_pcDeblockingTempPicYuv->copyToPic(pcPicYuvRec); // restore reconstruction
     3179      m_pcLoopFilter->loopFilterPic( pcPic );
     3180      const UInt64 dist = xFindDistortionFrame(pcPicYuvOrg, pcPicYuvRec, pcPic->getPicSym()->getSPS().getBitDepths());
     3181      if(dist < distMin)
     3182      {
     3183        distMin = dist;
     3184        bDBFilterDisabledBest = false;
     3185        betaOffsetDiv2Best  = betaOffsetDiv2;
     3186        tcOffsetDiv2Best = tcOffsetDiv2;
     3187      }
     3188      if(dist < distTcMin)
     3189      {
     3190        distTcMin = dist;
     3191      }
     3192      else if(tcOffsetDiv2 <-2)
     3193      {
     3194        break;
     3195      }
     3196    }
     3197    if(betaOffsetDiv2<-1 && distTcMin >= distBetaPrevious)
     3198    {
     3199      break;
     3200    }
     3201    distBetaPrevious = distTcMin;
     3202  }
     3203
     3204  //update:
     3205  m_DBParam[currQualityLayer][DBFLT_PARAM_AVAILABLE] = 1;
     3206  m_DBParam[currQualityLayer][DBFLT_DISABLE_FLAG]    = bDBFilterDisabledBest;
     3207  m_DBParam[currQualityLayer][DBFLT_BETA_OFFSETD2]   = betaOffsetDiv2Best;
     3208  m_DBParam[currQualityLayer][DBFLT_TC_OFFSETD2]     = tcOffsetDiv2Best;
     3209
     3210  m_pcDeblockingTempPicYuv->copyToPic(pcPicYuvRec); //restore reconstruction
     3211
     3212  if(bDBFilterDisabledBest)
     3213  {
     3214    for (Int i=0; i<numSlices; i++)
     3215    {
     3216      pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true);
     3217      pcPic->getSlice(i)->setDeblockingFilterDisable(true);
     3218    }
     3219  }
     3220  else if(betaOffsetDiv2Best ==pcPic->getSlice(0)->getPPS()->getDeblockingFilterBetaOffsetDiv2() &&  tcOffsetDiv2Best==pcPic->getSlice(0)->getPPS()->getDeblockingFilterTcOffsetDiv2())
     3221  {
     3222    for (Int i=0; i<numSlices; i++)
     3223    {
     3224      pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(false);
     3225      pcPic->getSlice(i)->setDeblockingFilterDisable(        pcPic->getSlice(i)->getPPS()->getPicDisableDeblockingFilterFlag() );
     3226      pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
     3227      pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2(   pcPic->getSlice(i)->getPPS()->getDeblockingFilterTcOffsetDiv2()   );
     3228    }
     3229  }
     3230  else
     3231  {
     3232    for (Int i=0; i<numSlices; i++)
     3233    {
     3234      pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true);
     3235      pcPic->getSlice(i)->setDeblockingFilterDisable( false );
     3236      pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2(betaOffsetDiv2Best);
     3237      pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2(tcOffsetDiv2Best);
     3238    }
     3239  }
     3240}
     3241#endif
    30703242
    30713243#if NH_MV
Note: See TracChangeset for help on using the changeset viewer.