Changeset 1413 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncSlice.cpp


Ignore:
Timestamp:
11 Jul 2018, 15:19:49 (6 years ago)
Author:
tech
Message:

Merged HTM-16.2-dev@1412

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibEncoder/TEncSlice.cpp

    r1405 r1413  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2016, ITU/ISO/IEC
     6 * Copyright (c) 2010-2017, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    113113}
    114114
     115Void TEncSlice::updateLambda(TComSlice* pSlice, Double dQP)
     116{
     117  Int iQP = (Int)dQP;
     118  Double dLambda = calculateLambda(pSlice, m_gopID, pSlice->getDepth(), pSlice->getSliceQp(), dQP, iQP);
     119
     120  setUpLambda(pSlice, dLambda, iQP);
     121}
    115122
    116123
     
    188195  rpcSlice->setPicOutputFlag( true );
    189196  rpcSlice->setPOC( pocCurr );
    190 #if NH_3D_IC
     197  pcPic->setField(isField);
     198  m_gopID = iGOPid;
     199
     200#if NH_3D
    191201  rpcSlice->setApplyIC( false );
    192202#endif
     
    252262    eSliceType = B_SLICE;
    253263  }
     264  m_eSliceTypeBaseView = eSliceTypeBaseView;
    254265#else
    255266  SliceType eSliceType;
     
    296307  // ------------------------------------------------------------------------------------------------------------------
    297308
     309#if X0038_LAMBDA_FROM_QP_CAPABILITY
     310  dQP = m_pcCfg->getQPForPicture(iGOPid, rpcSlice);
     311#else
    298312  dQP = m_pcCfg->getQP();
    299313  if(eSliceType!=I_SLICE)
    300314  {
    301     if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA) ) && (rpcSlice->getPPS()->getTransquantBypassEnableFlag())))
     315    if (!(( m_pcCfg->getMaxDeltaQP() == 0) && (!m_pcCfg->getLumaLevelToDeltaQPMapping().isEnabled()) && (dQP == -rpcSlice->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA) ) && (rpcSlice->getPPS()->getTransquantBypassEnabledFlag())))
    302316    {
    303317#if NH_MV
     
    310324
    311325  // modify QP
    312   Int* pdQPs = m_pcCfg->getdQPs();
     326  const Int* pdQPs = m_pcCfg->getdQPs();
    313327  if ( pdQPs )
    314328  {
     
    321335    m_pcCfg->setDeltaQpRD(0);
    322336  }
     337#endif
    323338
    324339  // ------------------------------------------------------------------------------------------------------------------
     
    326341  // ------------------------------------------------------------------------------------------------------------------
    327342
     343#if X0038_LAMBDA_FROM_QP_CAPABILITY
     344#if NH_MV
     345  const Int temporalId=m_pcCfg->getGOPEntry((eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid).m_temporalId;
     346#else
     347  const Int temporalId=m_pcCfg->getGOPEntry(iGOPid).m_temporalId;
     348#endif
     349#endif
     350
    328351  Int iQP;
    329352  Double dOrigQP = dQP;
     
    335358    dQP = dOrigQP + ((iDQpIdx+1)>>1)*(iDQpIdx%2 ? -1 : 1);
    336359
    337     // compute lambda value
    338     Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
    339     Int    SHIFT_QP = 12;
    340 
    341 #if FULL_NBIT
    342     Int    bitdepth_luma_qp_scale = 6 * (rpcSlice->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) - 8);
    343 #else
    344     Int    bitdepth_luma_qp_scale = 0;
    345 #endif
    346     Double qp_temp = (Double) dQP + bitdepth_luma_qp_scale - SHIFT_QP;
    347 #if FULL_NBIT
    348     Double qp_temp_orig = (Double) dQP - SHIFT_QP;
    349 #endif
    350     // Case #1: I or P-slices (key-frame)
    351 #if NH_MV
    352     Double dQPFactor;
    353     if( eSliceType != I_SLICE )
    354     {
    355       dQPFactor = m_pcCfg->getGOPEntry( (eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid ).m_QPFactor;
    356     }
    357     else
    358 #else
    359     Double dQPFactor = m_pcCfg->getGOPEntry(iGOPid).m_QPFactor;
    360     if ( eSliceType==I_SLICE )
    361 #endif
    362     {
    363       if (m_pcCfg->getIntraQpFactor()>=0.0 && m_pcCfg->getGOPEntry(iGOPid).m_sliceType != I_SLICE)
    364       {
    365         dQPFactor=m_pcCfg->getIntraQpFactor();
    366       }
    367       else
    368       {
    369         Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)(isField ? NumberBFrames/2 : NumberBFrames) );
    370        
    371         dQPFactor=0.57*dLambda_scale;
    372       }
    373     }
    374     dLambda = dQPFactor*pow( 2.0, qp_temp/3.0 );
    375 
    376     if ( depth>0 )
    377     {
    378 #if FULL_NBIT
    379         dLambda *= Clip3( 2.00, 4.00, (qp_temp_orig / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
    380 #else
    381         dLambda *= Clip3( 2.00, 4.00, (qp_temp / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
    382 #endif
    383     }
    384 
    385     // if hadamard is used in ME process
    386     if ( !m_pcCfg->getUseHADME() && rpcSlice->getSliceType( ) != I_SLICE )
    387     {
    388       dLambda *= 0.95;
    389     }
    390 
    391 #if W0062_RECALCULATE_QP_TO_ALIGN_WITH_LAMBDA
    392     Double lambdaRef = 0.57*pow(2.0, qp_temp/3.0);
    393     // QP correction due to modified lambda
    394     Double qpOffset = floor((3.0*log(dLambda/lambdaRef)/log(2.0)) +0.5);
    395     dQP += qpOffset;
    396 #endif
    397 
    398     iQP = max( -rpcSlice->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
     360    dLambda = calculateLambda(rpcSlice, iGOPid, depth, dQP, dQP, iQP );
    399361
    400362    m_vdRdPicLambda[iDQpIdx] = dLambda;
     
    409371
    410372
     373#if !X0038_LAMBDA_FROM_QP_CAPABILITY
    411374#if NH_MV
    412375  const Int temporalId=m_pcCfg->getGOPEntry((eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid).m_temporalId;
     
    415378#endif
    416379  const std::vector<Double> &intraLambdaModifiers=m_pcCfg->getIntraLambdaModifier();
    417 
    418 #if W0038_CQP_ADJ
     380#endif
     381
    419382  if(rpcSlice->getPPS()->getSliceChromaQpFlag())
    420383  {
     
    435398    rpcSlice->setSliceChromaQpDelta( COMPONENT_Cr, 0 );
    436399  }
    437 #endif
    438 
     400
     401#if !X0038_LAMBDA_FROM_QP_CAPABILITY
    439402  Double lambdaModifier;
    440403  if( rpcSlice->getSliceType( ) != I_SLICE || intraLambdaModifiers.empty())
     
    448411
    449412  dLambda *= lambdaModifier;
     413#endif
     414
    450415  setUpLambda(rpcSlice, dLambda, iQP);
    451416
     
    507472#endif
    508473  rpcSlice->setSliceQpDelta      ( 0 );
    509 #if !W0038_CQP_ADJ
    510   rpcSlice->setSliceChromaQpDelta( COMPONENT_Cb, 0 );
    511   rpcSlice->setSliceChromaQpDelta( COMPONENT_Cr, 0 );
    512 #endif
    513474  rpcSlice->setUseChromaQpAdj( rpcSlice->getPPS()->getPpsRangeExtension().getChromaQpOffsetListEnabledFlag() );
    514475#if NH_MV
     
    530491  {
    531492    rpcSlice->setDeblockingFilterOverrideFlag( rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag() );
    532     rpcSlice->setDeblockingFilterDisable( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
     493    rpcSlice->setDeblockingFilterDisable( rpcSlice->getPPS()->getPPSDeblockingFilterDisabledFlag() );
    533494    if ( !rpcSlice->getDeblockingFilterDisable())
    534495    {
     
    573534  rpcSlice->setSliceSegmentMode     ( m_pcCfg->getSliceSegmentMode()     );
    574535  rpcSlice->setSliceSegmentArgument ( m_pcCfg->getSliceSegmentArgument() );
    575 #if NH_3D_IV_MERGE
     536#if NH_3D
    576537#else
    577538  rpcSlice->setMaxNumMergeCand        ( m_pcCfg->getMaxNumMergeCand()        );
    578539#endif
    579540}
     541
     542Double TEncSlice::calculateLambda( const TComSlice* slice,
     543                                   const Int        GOPid, // entry in the GOP table
     544                                   const Int        depth, // slice GOP hierarchical depth.
     545                                   const Double     refQP, // initial slice-level QP
     546                                   const Double     dQP,   // initial double-precision QP
     547                                         Int        &iQP )  // returned integer QP.
     548{
     549  enum   SliceType eSliceType    = slice->getSliceType();
     550  const  Bool      isField       = slice->getPic()->isField();
     551  const  Int       NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
     552  const  Int       SHIFT_QP      = 12;
     553#if X0038_LAMBDA_FROM_QP_CAPABILITY
     554  const Int temporalId=m_pcCfg->getGOPEntry(GOPid).m_temporalId;
     555  const std::vector<Double> &intraLambdaModifiers=m_pcCfg->getIntraLambdaModifier();
     556#endif
     557
     558#if FULL_NBIT
     559  Int    bitdepth_luma_qp_scale = 6 * (slice->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) - 8);
     560#else
     561  Int    bitdepth_luma_qp_scale = 0;
     562#endif
     563  Double qp_temp = dQP + bitdepth_luma_qp_scale - SHIFT_QP;
     564  // Case #1: I or P-slices (key-frame)
     565#if NH_MV
     566  Double dQPFactor = m_pcCfg->getGOPEntry( (m_eSliceTypeBaseView == I_SLICE) ? MAX_GOP : GOPid ).m_QPFactor;
     567#else
     568  Double dQPFactor = m_pcCfg->getGOPEntry(GOPid).m_QPFactor;
     569#endif
     570  if ( eSliceType==I_SLICE )
     571  {
     572    if (m_pcCfg->getIntraQpFactor()>=0.0 && m_pcCfg->getGOPEntry(GOPid).m_sliceType != I_SLICE)
     573    {
     574      dQPFactor=m_pcCfg->getIntraQpFactor();
     575    }
     576    else
     577    {
     578#if X0038_LAMBDA_FROM_QP_CAPABILITY
     579      if(m_pcCfg->getLambdaFromQPEnable())
     580      {
     581        dQPFactor=0.57;
     582      }
     583      else
     584      {
     585#endif
     586        Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)(isField ? NumberBFrames/2 : NumberBFrames) );
     587        dQPFactor=0.57*dLambda_scale;
     588#if X0038_LAMBDA_FROM_QP_CAPABILITY
     589      }
     590#endif
     591    }
     592  }
     593#if X0038_LAMBDA_FROM_QP_CAPABILITY
     594  else if( m_pcCfg->getLambdaFromQPEnable() )
     595  {
     596    dQPFactor=0.57;
     597  }
     598#endif
     599
     600  Double dLambda = dQPFactor*pow( 2.0, qp_temp/3.0 );
     601
     602#if X0038_LAMBDA_FROM_QP_CAPABILITY
     603  if( !(m_pcCfg->getLambdaFromQPEnable()) && depth>0 )
     604#else
     605  if ( depth>0 )
     606#endif
     607  {
     608#if FULL_NBIT
     609    Double qp_temp_ref_orig = refQP - SHIFT_QP;
     610    dLambda *= Clip3( 2.00, 4.00, (qp_temp_ref_orig / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
     611#else
     612    Double qp_temp_ref = refQP + bitdepth_luma_qp_scale - SHIFT_QP;
     613    dLambda *= Clip3( 2.00, 4.00, (qp_temp_ref / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
     614#endif
     615  }
     616
     617  // if hadamard is used in ME process
     618  if ( !m_pcCfg->getUseHADME() && slice->getSliceType( ) != I_SLICE )
     619  {
     620    dLambda *= 0.95;
     621  }
     622
     623#if X0038_LAMBDA_FROM_QP_CAPABILITY
     624  Double lambdaModifier;
     625  if( eSliceType != I_SLICE || intraLambdaModifiers.empty())
     626  {
     627    lambdaModifier = m_pcCfg->getLambdaModifier( temporalId );
     628  }
     629  else
     630  {
     631    lambdaModifier = intraLambdaModifiers[ (temporalId < intraLambdaModifiers.size()) ? temporalId : (intraLambdaModifiers.size()-1) ];
     632  }
     633  dLambda *= lambdaModifier;
     634#endif
     635
     636  iQP = max( -slice->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
     637
     638  // NOTE: the lambda modifiers that are sometimes applied later might be best always applied in here.
     639  return dLambda;
     640}
     641
    580642
    581643Void TEncSlice::resetQP( TComPic* pic, Int sliceQP, Double lambda )
     
    835897#endif
    836898
    837 #if NH_3D_IC
     899#if NH_3D
    838900  if ( m_pcCfg->getViewIndex() && m_pcCfg->getUseIC() &&
    839901       !( ( pcSlice->getSliceType() == P_SLICE && pcSlice->getPPS()->getUseWP() ) || ( pcSlice->getSliceType() == B_SLICE && pcSlice->getPPS()->getWPBiPred() ) )
     
    12131275    }
    12141276
    1215 #if NH_3D_QTLPC
     1277#if NH_3D
    12161278    pcPic->setReduceBitsFlag(true);
    12171279#endif
     
    12851347      }
    12861348    }
    1287 #if NH_3D_QTLPC
     1349#if NH_3D
    12881350    pcPic->setReduceBitsFlag(false);
    12891351#endif
Note: See TracChangeset for help on using the changeset viewer.