Ignore:
Timestamp:
13 Feb 2014, 22:34:17 (11 years ago)
Author:
tech
Message:

Update HM-12.0 -> HM-13.0.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncSlice.cpp

    r773 r852  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6* Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    266266 
    267267  eSliceType=B_SLICE;
    268   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
     268  eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
    269269 
    270270  rpcSlice->setSliceType    ( eSliceType );
     
    296296  if(eSliceType!=I_SLICE)
    297297  {
    298     if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless())))
     298    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getPPS()->getTransquantBypassEnableFlag())))
    299299    {
    300300#if H_MV
     
    312312    dQP += pdQPs[ rpcSlice->getPOC() ];
    313313  }
    314 #if !RATE_CONTROL_LAMBDA_DOMAIN
    315   if ( m_pcCfg->getUseRateCtrl())
    316   {
    317     dQP = m_pcRateCtrl->getFrameQP(rpcSlice->isReferenced(), rpcSlice->getPOC());
    318   }
    319 #endif
    320314  // ------------------------------------------------------------------------------------------------------------------
    321315  // Lambda computation
     
    419413#endif
    420414
    421 #if WEIGHTED_CHROMA_DISTORTION
    422415// for RDO
    423416  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    424   Double weight = 1.0;
     417  Double weight[2] = { 1.0, 1.0 };
    425418  Int qpc;
    426419  Int chromaQPOffset;
     
    428421  chromaQPOffset = rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb();
    429422  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    430   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    431   m_pcRdCost->setCbDistortionWeight(weight);
     423  weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     424  m_pcRdCost->setCbDistortionWeight(weight[0]);
    432425
    433426  chromaQPOffset = rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr();
    434427  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    435   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    436   m_pcRdCost->setCrDistortionWeight(weight);
    437 #endif
     428  weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     429  m_pcRdCost->setCrDistortionWeight(weight[1]);
     430
     431  const Double lambdaArray[3] = {dLambda, (dLambda / weight[0]), (dLambda / weight[1])};
    438432
    439433#if RDOQ_CHROMA_LAMBDA
    440434// for RDOQ
    441   m_pcTrQuant->setLambda( dLambda, dLambda / weight );   
     435  m_pcTrQuant->setLambdas( lambdaArray );
    442436#else
    443437  m_pcTrQuant->setLambda( dLambda );
    444438#endif
    445439
    446 #if SAO_CHROMA_LAMBDA
    447440// For SAO
    448   rpcSlice   ->setLambda( dLambda, dLambda / weight ); 
    449 #else
    450   rpcSlice   ->setLambda( dLambda );
    451 #endif
     441  rpcSlice->setLambdas( lambdaArray );
    452442 
    453443#if HB_LAMBDA_FOR_LDC
     
    460450  }
    461451#else
    462   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
     452eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
    463453#endif
    464454
     
    570560}
    571561
    572 #if RATE_CONTROL_LAMBDA_DOMAIN
    573562Void TEncSlice::resetQP( TComPic* pic, Int sliceQP, Double lambda )
    574563{
     
    579568  slice->setSliceQpBase ( sliceQP );
    580569  m_pcRdCost ->setLambda( lambda );
    581 #if WEIGHTED_CHROMA_DISTORTION
    582570  // for RDO
    583571  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    584   Double weight;
     572  Double weight[2] = { 1.0, 1.0 };
    585573  Int qpc;
    586574  Int chromaQPOffset;
     
    588576  chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb();
    589577  qpc = Clip3( 0, 57, sliceQP + chromaQPOffset);
    590   weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    591   m_pcRdCost->setCbDistortionWeight(weight);
     578  weight[0] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     579  m_pcRdCost->setCbDistortionWeight(weight[0]);
    592580
    593581  chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr();
    594582  qpc = Clip3( 0, 57, sliceQP + chromaQPOffset);
    595   weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    596   m_pcRdCost->setCrDistortionWeight(weight);
    597 #endif
     583  weight[1] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     584  m_pcRdCost->setCrDistortionWeight(weight[1]);
     585
     586  const Double lambdaArray[3] = {lambda, (lambda / weight[0]), (lambda / weight[1])};
    598587
    599588#if RDOQ_CHROMA_LAMBDA
    600589  // for RDOQ
    601   m_pcTrQuant->setLambda( lambda, lambda / weight );
     590  m_pcTrQuant->setLambdas( lambdaArray );
    602591#else
    603592  m_pcTrQuant->setLambda( lambda );
    604593#endif
    605594
    606 #if SAO_CHROMA_LAMBDA
    607595  // For SAO
    608   slice   ->setLambda( lambda, lambda / weight );
    609 #else
    610   slice   ->setLambda( lambda );
    611 #endif
     596  slice->setLambdas( lambdaArray );
    612597}
    613 #else
    614 /**
    615  - lambda re-computation based on rate control QP
    616  */
    617 Void TEncSlice::xLamdaRecalculation(Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice)
    618 {
    619   Int qp;
    620   Double recalQP= (Double)changeQP;
    621   Double origQP = (Double)recalQP;
    622   Double lambda;
    623 
    624   // pre-compute lambda and QP values for all possible QP candidates
    625   for ( Int deltqQpIdx = 0; deltqQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; deltqQpIdx++ )
    626   {
    627     // compute QP value
    628     recalQP = origQP + ((deltqQpIdx+1)>>1)*(deltqQpIdx%2 ? -1 : 1);
    629 
    630     // compute lambda value
    631     Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
    632     Int    SHIFT_QP = 12;
    633     Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
    634 #if FULL_NBIT
    635     Int    bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);
    636 #else
    637     Int    bitdepth_luma_qp_scale = 0;
    638 #endif
    639     Double qp_temp = (Double) recalQP + bitdepth_luma_qp_scale - SHIFT_QP;
    640 #if FULL_NBIT
    641     Double qp_temp_orig = (Double) recalQP - SHIFT_QP;
    642 #endif
    643     // Case #1: I or P-slices (key-frame)
    644     Double dQPFactor = m_pcCfg->getGOPEntry(idGOP).m_QPFactor;
    645     if ( eSliceType==I_SLICE )
    646     {
    647       dQPFactor=0.57*dLambda_scale;
    648     }
    649     lambda = dQPFactor*pow( 2.0, qp_temp/3.0 );
    650 
    651     if ( depth>0 )
    652     {
    653 #if FULL_NBIT
    654       lambda *= Clip3( 2.00, 4.00, (qp_temp_orig / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
    655 #else
    656       lambda *= Clip3( 2.00, 4.00, (qp_temp / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
    657 #endif
    658     }
    659 
    660     // if hadamard is used in ME process
    661     if ( !m_pcCfg->getUseHADME() )
    662     {
    663       lambda *= 0.95;
    664     }
    665 
    666     qp = max( -pcSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );
    667 
    668     m_pdRdPicLambda[deltqQpIdx] = lambda;
    669     m_pdRdPicQp    [deltqQpIdx] = recalQP;
    670     m_piRdPicQp    [deltqQpIdx] = qp;
    671   }
    672 
    673   // obtain dQP = 0 case
    674   lambda  = m_pdRdPicLambda[0];
    675   recalQP = m_pdRdPicQp    [0];
    676   qp      = m_piRdPicQp    [0];
    677 
    678   if( pcSlice->getSliceType( ) != I_SLICE )
    679   {
    680     lambda *= m_pcCfg->getLambdaModifier( depth );
    681   }
    682 
    683   // store lambda
    684   m_pcRdCost ->setLambda( lambda );
    685 #if WEIGHTED_CHROMA_DISTORTION
    686   // for RDO
    687   // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    688   Double weight = 1.0;
    689   Int qpc;
    690   Int chromaQPOffset;
    691 
    692   chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
    693   qpc = Clip3( 0, 57, qp + chromaQPOffset);
    694   weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    695   m_pcRdCost->setCbDistortionWeight(weight);
    696 
    697   chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
    698   qpc = Clip3( 0, 57, qp + chromaQPOffset);
    699   weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    700   m_pcRdCost->setCrDistortionWeight(weight);
    701 #endif
    702 
    703 #if RDOQ_CHROMA_LAMBDA
    704   // for RDOQ
    705   m_pcTrQuant->setLambda( lambda, lambda / weight );   
    706 #else
    707   m_pcTrQuant->setLambda( lambda );
    708 #endif
    709 
    710 #if SAO_CHROMA_LAMBDA
    711   // For SAO
    712   pcSlice   ->setLambda( lambda, lambda / weight ); 
    713 #else
    714   pcSlice   ->setLambda( lambda );
    715 #endif
    716 }
    717 #endif
    718598// ====================================================================================================================
    719599// Public member functions
     
    755635  }
    756636
    757 #if RATE_CONTROL_LAMBDA_DOMAIN
    758637  if ( m_pcCfg->getUseRateCtrl() )
    759638  {
     
    761640    assert(0);
    762641  }
    763 #endif
    764642 
    765643  TComSlice* pcSlice        = rpcPic->getSlice(getSliceIdx());
     
    793671#endif
    794672    m_pcRdCost    ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
    795 #if WEIGHTED_CHROMA_DISTORTION
    796673    // for RDO
    797674    // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    798675    Int iQP = m_piRdPicQp    [uiQpIdx];
    799     Double weight = 1.0;
     676    Double weight[2] = { 1.0, 1.0 };
    800677    Int qpc;
    801678    Int chromaQPOffset;
     
    803680    chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
    804681    qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    805     weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    806     m_pcRdCost->setCbDistortionWeight(weight);
     682    weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     683    m_pcRdCost->setCbDistortionWeight(weight[0]);
    807684
    808685    chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
    809686    qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    810     weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    811     m_pcRdCost->setCrDistortionWeight(weight);
    812 #endif
    813 
     687    weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     688    m_pcRdCost->setCrDistortionWeight(weight[1]);
     689
     690    const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdx], (m_pdRdPicLambda[uiQpIdx] / weight[0]), (m_pdRdPicLambda[uiQpIdx] / weight[1])};
    814691#if RDOQ_CHROMA_LAMBDA
    815692    // for RDOQ
    816     m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
     693    m_pcTrQuant->setLambdas( lambdaArray );
    817694#else
    818695    m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
    819696#endif
    820 #if SAO_CHROMA_LAMBDA
    821697    // For SAO
    822     pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
    823 #else
    824     pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
    825 #endif
     698    pcSlice->setLambdas( lambdaArray );
    826699   
    827700    // try compress
     
    857730#endif
    858731  m_pcRdCost    ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
    859 #if WEIGHTED_CHROMA_DISTORTION
    860732  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    861733  Int iQP = m_piRdPicQp    [uiQpIdxBest];
    862   Double weight = 1.0;
     734  Double weight[2] = { 1.0, 1.0 };
    863735  Int qpc;
    864736  Int chromaQPOffset;
     
    866738  chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
    867739  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    868   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    869   m_pcRdCost->setCbDistortionWeight(weight);
     740  weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     741  m_pcRdCost->setCbDistortionWeight(weight[0]);
    870742
    871743  chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
    872744  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    873   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    874   m_pcRdCost->setCrDistortionWeight(weight);
    875 #endif
    876 
     745  weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     746  m_pcRdCost->setCrDistortionWeight(weight[1]);
     747
     748  const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdxBest], (m_pdRdPicLambda[uiQpIdxBest] / weight[0]), (m_pdRdPicLambda[uiQpIdxBest] / weight[1])};
    877749#if RDOQ_CHROMA_LAMBDA
    878750  // for RDOQ
    879   m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
     751  m_pcTrQuant->setLambdas( lambdaArray );
    880752#else
    881753  m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
    882754#endif
    883 #if SAO_CHROMA_LAMBDA
    884755  // For SAO
    885   pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
    886 #else
    887   pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
    888 #endif
     756  pcSlice->setLambdas( lambdaArray );
    889757}
    890758
    891759/** \param rpcPic   picture class
    892760 */
    893 #if RATE_CONTROL_INTRA
    894761Void TEncSlice::calCostSliceI(TComPic*& rpcPic)
    895762{
     
    925792  m_pcRateCtrl->getRCPic()->setTotalIntraCost(iSumHadSlice);
    926793}
    927 #endif
    928794
    929795Void TEncSlice::compressSlice( TComPic*& rpcPic )
     
    943809 
    944810  // set entropy coder
    945   if( m_pcCfg->getUseSBACRD() )
    946   {
    947811    m_pcSbacCoder->init( m_pcBinCABAC );
    948812    m_pcEntropyCoder->setEntropyCoder   ( m_pcSbacCoder, pcSlice );
     
    952816    pppcRDSbacCoder->setBinCountingEnableFlag( false );
    953817    pppcRDSbacCoder->setBinsCoded( 0 );
    954   }
    955   else
    956   {
    957     m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );
    958     m_pcEntropyCoder->resetEntropy      ();
    959     m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
    960   }
    961818 
    962819  //------------------------------------------------------------------------------
     
    1016873  }
    1017874#endif
    1018   if( m_pcCfg->getUseSBACRD() )
    1019   {
    1020875    iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
    1021876    uiTilesAcross = rpcPic->getPicSym()->getNumColumnsMinus1()+1;
     
    1037892      ppppcRDSbacCoders[ui][0][CI_CURR_BEST]->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
    1038893    }
    1039   }
    1040   //if( m_pcCfg->getUseSBACRD() )
    1041   {
    1042894    delete[] m_pcBufferLowLatSbacCoders;
    1043895    delete[] m_pcBufferLowLatBinCoderCABACs;
     
    1050902    for (UInt ui = 0; ui < uiTilesAcross; ui++)
    1051903      m_pcBufferLowLatSbacCoders[ui].load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);  //init. state
    1052   }
     904
    1053905  UInt uiWidthInLCUs  = rpcPic->getPicSym()->getFrameWidthInCU();
    1054906  //UInt uiHeightInLCUs = rpcPic->getPicSym()->getFrameHeightInCU();
     
    1121973    }
    1122974#endif
    1123 #if !RATE_CONTROL_LAMBDA_DOMAIN
    1124     if(m_pcCfg->getUseRateCtrl())
    1125     {
    1126 #if KWU_RC_MADPRED_E0227
    1127       if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())
    1128       {
    1129         Double zn, zf, focallength, position, camshift;
    1130         Double basepos;
    1131         Bool bInterpolated;
    1132         Int direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
    1133 
    1134         pcEncTop->getCamParam()->xGetZNearZFar(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), zn, zf);
    1135         pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[0], pcSlice->getPOC(), focallength, basepos, camshift, bInterpolated);
    1136         pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), focallength, position, camshift, bInterpolated);
    1137 
    1138         m_pcRateCtrl->updateLCUDataEnhancedView(pcCU, pcCU->getTotalBits(), pcCU->getQP(0), basepos, position, focallength, zn, zf, (direction > 0 ? 1 : -1));
    1139       }
    1140 #endif
    1141       if(m_pcRateCtrl->calculateUnitQP())
    1142       {
    1143         xLamdaRecalculation(m_pcRateCtrl->getUnitQP(), m_pcRateCtrl->getGOPId(), pcSlice->getDepth(), pcSlice->getSliceType(), pcSlice->getSPS(), pcSlice );
    1144       }
    1145     }
    1146 #endif
    1147975    // inherit from TR if necessary, select substream to use.
    1148     if( m_pcCfg->getUseSBACRD() )
    1149     {
    1150976      uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in?
    1151977      uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
     
    11921018      }
    11931019      m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST] ); //this load is used to simplify the code
    1194     }
    11951020
    11961021    // reset the entropy coder
     
    12101035      m_pcEntropyCoder->setEntropyCoder     ( m_pcSbacCoder, pcSlice );
    12111036    }
    1212     // if RD based on SBAC is used
    1213     if( m_pcCfg->getUseSBACRD() )
    1214     {
     1037
    12151038      // set go-on entropy coder
    12161039      m_pcEntropyCoder->setEntropyCoder ( m_pcRDGoOnSbacCoder, pcSlice );
     
    12191042      ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true);
    12201043
    1221 #if RATE_CONTROL_LAMBDA_DOMAIN
    12221044      Double oldLambda = m_pcRdCost->getLambda();
    12231045      if ( m_pcCfg->getUseRateCtrl() )
     
    12271049        Double bpp       = -1.0;
    12281050
    1229 #if M0036_RC_IMPROVEMENT
    12301051        if ( ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() )
    1231 #else
    1232         if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE || !m_pcCfg->getLCULevelRC() )
    1233 #endif
    12341052        {
    12351053          estQP = pcSlice->getSliceQp();
     
    12551073          {
    12561074#endif
    1257 #if RATE_CONTROL_INTRA
    12581075          bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType());
    12591076          if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE)
     
    12661083            estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
    12671084          }
    1268 #else
    1269           bpp       = m_pcRateCtrl->getRCPic()->getLCUTargetBpp();
    1270           estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
    1271           estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
    1272 #endif
    1273 #if KWU_RC_MADPRED_E0227
    1274           }
    1275 #endif
    12761085#if KWU_RC_MADPRED_E0227
    12771086          estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
     
    12811090
    12821091          m_pcRdCost->setLambda(estLambda);
    1283 #if M0036_RC_IMPROVEMENT
    12841092#if RDOQ_CHROMA_LAMBDA
    12851093          // set lambda for RDOQ
    12861094          Double weight=m_pcRdCost->getChromaWeight();
    1287           m_pcTrQuant->setLambda( estLambda, estLambda / weight );
     1095        const Double lambdaArray[3] = { estLambda, (estLambda / weight), (estLambda / weight) };
     1096        m_pcTrQuant->setLambdas( lambdaArray );
    12881097#else
    12891098          m_pcTrQuant->setLambda( estLambda );
    1290 #endif
    12911099#endif
    12921100        }
     
    12951103        pcCU->getSlice()->setSliceQpBase( estQP );
    12961104      }
    1297 #endif
    12981105
    12991106      // run CU encoder
    13001107      m_pcCuEncoder->compressCU( pcCU );
    13011108
    1302 #if !TICKET_1090_FIX
    1303 #if RATE_CONTROL_LAMBDA_DOMAIN
    1304       if ( m_pcCfg->getUseRateCtrl() )
    1305       {
    1306 #if !M0036_RC_IMPROVEMENT
    1307         UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
    1308         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
    1309         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
    1310         Double MAD = (Double)SAD / (Double)(height * width);
    1311         MAD = MAD * MAD;
    1312         ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;
    1313 #endif
    1314 
    1315         Int actualQP        = g_RCInvalidQPValue;
    1316         Double actualLambda = m_pcRdCost->getLambda();
    1317         Int actualBits      = pcCU->getTotalBits();
    1318         Int numberOfEffectivePixels    = 0;
    1319         for ( Int idx = 0; idx < rpcPic->getNumPartInCU(); idx++ )
    1320         {
    1321           if ( pcCU->getPredictionMode( idx ) != MODE_NONE && ( !pcCU->isSkipped( idx ) ) )
    1322           {
    1323             numberOfEffectivePixels = numberOfEffectivePixels + 16;
    1324             break;
    1325           }
    1326         }
    1327 
    1328         if ( numberOfEffectivePixels == 0 )
    1329         {
    1330           actualQP = g_RCInvalidQPValue;
    1331         }
    1332         else
    1333         {
    1334           actualQP = pcCU->getQP( 0 );
    1335         }
    1336         m_pcRdCost->setLambda(oldLambda);
    1337 #if RATE_CONTROL_INTRA
    1338         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
    1339           pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
    1340 #else
    1341         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );
    1342 #endif
    1343       }
    1344 #endif
    1345 #endif
    1346      
    13471109      // restore entropy coder to an initial stage
    13481110      m_pcEntropyCoder->setEntropyCoder ( m_pppcRDSbacCoder[0][CI_CURR_BEST], pcSlice );
     
    13661128        break;
    13671129      }
    1368       if( m_pcCfg->getUseSBACRD() )
    1369       {
    1370          ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] );
    13711130       
     1131    ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] );
    13721132         //Store probabilties of second LCU in line into buffer
    13731133         if ( ( uiCol == uiTileLCUX+1) && (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && m_pcCfg->getWaveFrontsynchro())
     
    13751135          m_pcBufferSbacCoders[uiTileCol].loadContexts(ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]);
    13761136        }
    1377       }
    1378 
    1379 #if TICKET_1090_FIX
    1380 #if RATE_CONTROL_LAMBDA_DOMAIN
     1137
    13811138      if ( m_pcCfg->getUseRateCtrl() )
    13821139      {
    1383 #if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227
     1140#if KWU_RC_MADPRED_E0227
    13841141        UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
    13851142        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
     
    14131170        m_pcRdCost->setLambda(oldLambda);
    14141171
    1415 #if RATE_CONTROL_INTRA
    14161172        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
    14171173          pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
    1418 #else
    1419         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );
    1420 #endif
    1421       }
    1422 #endif
    1423 #endif
    1424     }
    1425     // other case: encodeCU is not called
    1426     else
    1427     {
    1428       m_pcCuEncoder->compressCU( pcCU );
    1429       m_pcCuEncoder->encodeCU( pcCU );
    1430       if (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES && ( ( pcSlice->getSliceBits()+ m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)
    1431       {
    1432         pcSlice->setNextSlice( true );
    1433         break;
    1434       }
    1435       if (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+ m_pcEntropyCoder->getNumberOfWrittenBits()> m_pcCfg->getSliceSegmentArgument()<<3 &&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getSliceSegmentCurEndCUAddr())
    1436       {
    1437         pcSlice->setNextSliceSegment( true );
    1438         break;
    1439       }
    14401174    }
    14411175   
     
    14431177    m_dPicRdCost     += pcCU->getTotalCost();
    14441178    m_uiPicDist      += pcCU->getTotalDistortion();
    1445 #if !RATE_CONTROL_LAMBDA_DOMAIN
    1446     if(m_pcCfg->getUseRateCtrl())
    1447     {
    1448       m_pcRateCtrl->updateLCUData(pcCU, pcCU->getTotalBits(), pcCU->getQP(0));
    1449       m_pcRateCtrl->updataRCUnitStatus();
    1450     }
    1451 #endif
    14521179  }
    14531180  if ((pcSlice->getPPS()->getNumSubstreams() > 1) && !depSliceSegmentsEnabled)
     
    14551182    pcSlice->setNextSlice( true );
    14561183  }
     1184  if(m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES || m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES)
     1185  {
     1186    if(pcSlice->getSliceCurEndCUAddr()<=pcSlice->getSliceSegmentCurEndCUAddr())
     1187    {
     1188       pcSlice->setNextSlice( true );
     1189    }
     1190    else
     1191    {
     1192       pcSlice->setNextSliceSegment( true );
     1193    }
     1194  }
    14571195  if( depSliceSegmentsEnabled )
    14581196  {
     
    14641202  }
    14651203  xRestoreWPparam( pcSlice );
    1466 #if !RATE_CONTROL_LAMBDA_DOMAIN
    1467   if(m_pcCfg->getUseRateCtrl())
    1468   {
    1469     m_pcRateCtrl->updateFrameData(m_uiPicTotalBits);
    1470   }
    1471 #endif
    14721204}
    14731205
     
    15821314       uiCUAddr = rpcPic->getPicSym()->getCUOrderMap(++uiEncCUOrder) )
    15831315  {
    1584     if( m_pcCfg->getUseSBACRD() )
    1585     {
    15861316      uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in?
    15871317      uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
     
    16321362      }
    16331363      m_pcSbacCoder->load(&pcSbacCoders[uiSubStrm]);  //this load is used to simplify the code (avoid to change all the call to m_pcSbacCoder)
    1634     }
     1364
    16351365    // reset the entropy coder
    16361366    if( uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr() &&                                   // must be first CU of tile
     
    16761406#endif
    16771407    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );   
    1678     if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
    1679     {
    1680       SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    1681       Int iNumCuInWidth     = saoParam->numCuInWidth;
    1682       Int iCUAddrInSlice    = uiCUAddr - rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU());
    1683       Int iCUAddrUpInSlice  = iCUAddrInSlice - iNumCuInWidth;
    1684       Int rx = uiCUAddr % iNumCuInWidth;
    1685       Int ry = uiCUAddr / iNumCuInWidth;
    1686       Int allowMergeLeft = 1;
    1687       Int allowMergeUp   = 1;
    1688       if (rx!=0)
    1689       {
    1690         if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-1) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))
    1691         {
    1692           allowMergeLeft = 0;
    1693         }
    1694       }
    1695       if (ry!=0)
    1696       {
    1697         if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-iNumCuInWidth) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))
    1698         {
    1699           allowMergeUp = 0;
    1700         }
    1701       }
    1702       Int addr = pcCU->getAddr();
    1703       allowMergeLeft = allowMergeLeft && (rx>0) && (iCUAddrInSlice!=0);
    1704       allowMergeUp = allowMergeUp && (ry>0) && (iCUAddrUpInSlice>=0);
    1705       if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] )
    1706       {
    1707         Int mergeLeft = saoParam->saoLcuParam[0][addr].mergeLeftFlag;
    1708         Int mergeUp = saoParam->saoLcuParam[0][addr].mergeUpFlag;
    1709         if (allowMergeLeft)
    1710         {
    1711           m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeLeft);
    1712         }
    1713         else
    1714         {
    1715           mergeLeft = 0;
    1716         }
    1717         if(mergeLeft == 0)
    1718         {
    1719           if (allowMergeUp)
    1720           {
    1721             m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeUp);
    1722           }
    1723           else
    1724           {
    1725             mergeUp = 0;
    1726           }
    1727           if(mergeUp == 0)
    1728           {
    1729             for (Int compIdx=0;compIdx<3;compIdx++)
    1730             {
    1731             if( (compIdx == 0 && saoParam->bSaoFlag[0]) || (compIdx > 0 && saoParam->bSaoFlag[1]))
    1732               {
    1733                 m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx);
    1734               }
    1735             }
    1736           }
    1737         }
    1738       }
    1739     }
    1740     else if (pcSlice->getSPS()->getUseSAO())
    1741     {
    1742       Int addr = pcCU->getAddr();
    1743       SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    1744       for (Int cIdx=0; cIdx<3; cIdx++)
    1745       {
    1746         SaoLcuParam *saoLcuParam = &(saoParam->saoLcuParam[cIdx][addr]);
    1747         if ( ((cIdx == 0) && !pcSlice->getSaoEnabledFlag()) || ((cIdx == 1 || cIdx == 2) && !pcSlice->getSaoEnabledFlagChroma()))
    1748         {
    1749           saoLcuParam->mergeUpFlag   = 0;
    1750           saoLcuParam->mergeLeftFlag = 0;
    1751           saoLcuParam->subTypeIdx    = 0;
    1752           saoLcuParam->typeIdx       = -1;
    1753           saoLcuParam->offset[0]     = 0;
    1754           saoLcuParam->offset[1]     = 0;
    1755           saoLcuParam->offset[2]     = 0;
    1756           saoLcuParam->offset[3]     = 0;
    1757         }
     1408    if ( pcSlice->getSPS()->getUseSAO() )
     1409    {
     1410      if (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma())
     1411      {
     1412        SAOBlkParam& saoblkParam = (rpcPic->getPicSym()->getSAOBlkParam())[uiCUAddr];
     1413        Bool sliceEnabled[NUM_SAO_COMPONENTS];
     1414        sliceEnabled[SAO_Y] = pcSlice->getSaoEnabledFlag();
     1415        sliceEnabled[SAO_Cb]= sliceEnabled[SAO_Cr]= pcSlice->getSaoEnabledFlagChroma();
     1416
     1417        Bool leftMergeAvail = false;
     1418        Bool aboveMergeAvail= false;
     1419        //merge left condition
     1420        Int rx = (uiCUAddr % uiWidthInLCUs);
     1421        if(rx > 0)
     1422        {
     1423          leftMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-1);
     1424        }
     1425
     1426        //merge up condition
     1427        Int ry = (uiCUAddr / uiWidthInLCUs);
     1428        if(ry > 0)
     1429      {
     1430          aboveMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-uiWidthInLCUs);
     1431        }
     1432
     1433        m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam,sliceEnabled, leftMergeAvail, aboveMergeAvail);
    17581434      }
    17591435    }
     
    17731449    g_bJustDoIt = g_bEncDecTraceDisable;
    17741450#endif   
    1775     if( m_pcCfg->getUseSBACRD() )
    1776     {
    17771451       pcSbacCoders[uiSubStrm].load(m_pcSbacCoder);   //load back status of the entropy coder after encoding the LCU into relevant bitstream entropy coder
    17781452       
     
    17831457        m_pcBufferSbacCoders[uiTileCol].loadContexts( &pcSbacCoders[uiSubStrm] );
    17841458      }
    1785     }
    17861459#if H_3D_QTLPC
    17871460    rpcPic->setReduceBitsFlag(false);
Note: See TracChangeset for help on using the changeset viewer.