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


Ignore:
Timestamp:
11 May 2012, 21:20:17 (12 years ago)
Author:
hschwarz
Message:

updated trunk (move to HM6.1)

File:
1 edited

Legend:

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

    r42 r56  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license.
     4 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2011, ISO/IEC
     6 * Copyright (c) 2010-2012, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    1515 *    this list of conditions and the following disclaimer in the documentation
    1616 *    and/or other materials provided with the distribution.
    17  *  * Neither the name of the ISO/IEC nor the names of its contributors may
     17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
    1818 *    be used to endorse or promote products derived from this software without
    1919 *    specific prior written permission.
     
    3232 */
    3333
    34 
    35 
    3634/** \file     TEncSlice.cpp
    3735    \brief    slice encoder class
     
    4038#include "TEncTop.h"
    4139#include "TEncSlice.h"
     40#include <math.h>
     41
     42//! \ingroup TLibEncoder
     43//! \{
    4244
    4345// ====================================================================================================================
     
    4951  m_apcPicYuvPred = NULL;
    5052  m_apcPicYuvResi = NULL;
    51 
     53 
    5254  m_pdRdPicLambda = NULL;
    5355  m_pdRdPicQp     = NULL;
    5456  m_piRdPicQp     = NULL;
     57  m_pcBufferSbacCoders    = NULL;
     58  m_pcBufferBinCoderCABACs  = NULL;
     59  m_pcBufferLowLatSbacCoders    = NULL;
     60  m_pcBufferLowLatBinCoderCABACs  = NULL;
    5561}
    5662
     
    6773    m_apcPicYuvPred->create( iWidth, iHeight, iMaxCUWidth, iMaxCUHeight, uhTotalDepth );
    6874  }
    69 
     75 
    7076  // create residual picture
    7177  if( m_apcPicYuvResi == NULL )
     
    8591    m_apcPicYuvPred  = NULL;
    8692  }
    87 
     93 
    8894  // destroy residual picture
    8995  if ( m_apcPicYuvResi )
     
    9399    m_apcPicYuvResi  = NULL;
    94100  }
    95 
     101 
    96102  // free lambda and QP arrays
    97103  if ( m_pdRdPicLambda ) { xFree( m_pdRdPicLambda ); m_pdRdPicLambda = NULL; }
    98104  if ( m_pdRdPicQp     ) { xFree( m_pdRdPicQp     ); m_pdRdPicQp     = NULL; }
    99105  if ( m_piRdPicQp     ) { xFree( m_piRdPicQp     ); m_piRdPicQp     = NULL; }
     106
     107  if ( m_pcBufferSbacCoders )
     108  {
     109    delete[] m_pcBufferSbacCoders;
     110  }
     111  if ( m_pcBufferBinCoderCABACs )
     112  {
     113    delete[] m_pcBufferBinCoderCABACs;
     114  }
     115  if ( m_pcBufferLowLatSbacCoders )
     116    delete[] m_pcBufferLowLatSbacCoders;
     117  if ( m_pcBufferLowLatBinCoderCABACs )
     118    delete[] m_pcBufferLowLatBinCoderCABACs;
    100119}
    101120
     
    104123  m_pcCfg             = pcEncTop;
    105124  m_pcListPic         = pcEncTop->getListPic();
    106 
    107   m_pcPicEncoder      = pcEncTop->getPicEncoder();
     125 
     126  m_pcGOPEncoder      = pcEncTop->getGOPEncoder();
    108127  m_pcCuEncoder       = pcEncTop->getCuEncoder();
    109128  m_pcPredSearch      = pcEncTop->getPredSearch();
    110 
     129 
    111130  m_pcEntropyCoder    = pcEncTop->getEntropyCoder();
    112131  m_pcCavlcCoder      = pcEncTop->getCavlcCoder();
     
    114133  m_pcBinCABAC        = pcEncTop->getBinCABAC();
    115134  m_pcTrQuant         = pcEncTop->getTrQuant();
    116 
     135 
    117136  m_pcBitCounter      = pcEncTop->getBitCounter();
    118137  m_pcRdCost          = pcEncTop->getRdCost();
    119138  m_pppcRDSbacCoder   = pcEncTop->getRDSbacCoder();
    120139  m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder();
    121 
     140 
    122141  // create lambda and QP arrays
    123142  m_pdRdPicLambda     = (Double*)xMalloc( Double, m_pcCfg->getDeltaQpRD() * 2 + 1 );
     
    130149 - QP computation based on temporal structure
    131150 - lambda computation based on QP
     151 - set temporal layer ID and the parameter sets
    132152 .
    133153 \param pcPic         picture class
     
    138158 \param iDepth        temporal layer depth
    139159 \param rpcSlice      slice header class
     160 \param pSPS          SPS associated with the slice
     161 \param pPPS          PPS associated with the slice
    140162 */
    141 Void TEncSlice::initEncSlice( TComPic* pcPic, TComSlice*& rpcSlice )
     163Void TEncSlice::initEncSlice( TComPic* pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
    142164{
    143165  Double dQP;
    144166  Double dLambda;
    145 
     167 
    146168  rpcSlice = pcPic->getSlice(0);
     169  rpcSlice->setSPS( pSPS );
     170  rpcSlice->setPPS( pPPS );
    147171  rpcSlice->setSliceBits(0);
    148172  rpcSlice->setPic( pcPic );
    149173  rpcSlice->initSlice();
    150   rpcSlice->setPOC( pcPic->getPOC() );
    151 #if BITSTREAM_EXTRACTION
    152   rpcSlice->setLayerId( m_pcCfg->getLayerId() );
    153 #endif
     174  rpcSlice->initTiles();
     175#if H0388
     176  rpcSlice->setPicOutputFlag( true );
     177#endif
     178  rpcSlice->setPOC( uiPOCCurr );
     179 
    154180#if SONY_COLPIC_AVAILABILITY
    155181  rpcSlice->setViewOrderIdx(m_pcCfg->getViewOrderIdx());
    156182#endif
    157183
     184  // set mutliview parameters
     185  rpcSlice->initMultiviewSlice( pcPic->getCodedScale(), pcPic->getCodedOffset() );
     186
     187  // depth computation based on GOP size
     188  int iDepth;
     189  {
     190    Int i, j;
     191    Int iPOC = rpcSlice->getPOC()%m_pcCfg->getGOPSize();
     192    if ( iPOC == 0 )
     193    {
     194      iDepth = 0;
     195    }
     196    else
     197    {
     198      Int iStep = m_pcCfg->getGOPSize();
     199      iDepth    = 0;
     200      for( i=iStep>>1; i>=1; i>>=1 )
     201      {
     202        for ( j=i; j<m_pcCfg->getGOPSize(); j+=iStep )
     203        {
     204          if ( j == iPOC )
     205          {
     206            i=0;
     207            break;
     208          }
     209        }
     210        iStep>>=1;
     211        iDepth++;
     212      }
     213    }
     214  }
     215 
    158216  // slice type
    159   SliceType eSliceType  = pcPic->getSliceType()  ;
    160   rpcSlice->setSliceType    ( eSliceType );
    161 
     217  SliceType eSliceTypeBaseView;
     218  if( iPOCLast == 0 || uiPOCCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0 )
     219  {
     220    eSliceTypeBaseView = I_SLICE;
     221  }
     222  else
     223  {
     224    eSliceTypeBaseView = B_SLICE;
     225  }
     226  SliceType eSliceType = eSliceTypeBaseView;
     227  if( eSliceTypeBaseView == I_SLICE && m_pcCfg->getGOPEntry(MAX_GOP).m_POC == 0 && m_pcCfg->getGOPEntry(MAX_GOP).m_sliceType != 'I' )
     228  {
     229    eSliceType = B_SLICE;
     230  }
     231  rpcSlice->setSliceType( eSliceType );
     232 
    162233  // ------------------------------------------------------------------------------------------------------------------
    163234  // Non-referenced frame marking
    164235  // ------------------------------------------------------------------------------------------------------------------
    165 
    166   rpcSlice->setReferenced(pcPic->getReferenced()) ;
    167 
     236  rpcSlice->setReferenced( m_pcCfg->getGOPEntry(iGOPid).m_refPic );
     237  if( eSliceTypeBaseView == I_SLICE )
     238  {
     239    rpcSlice->setReferenced(true);
     240  }
     241 
    168242  // ------------------------------------------------------------------------------------------------------------------
    169243  // QP setting
    170244  // ------------------------------------------------------------------------------------------------------------------
    171 
    172   Double dOrigQP = double(pcPic->getQP());
    173 
     245 
     246  dQP = m_pcCfg->getQP();
     247  if( eSliceType != I_SLICE )
     248  {
     249#if LOSSLESS_CODING
     250#if H0736_AVC_STYLE_QP_RANGE
     251    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless())))
     252#else
     253    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == 0 ) && (rpcSlice->getSPS()->getUseLossless())))
     254#endif
     255#endif
     256    {
     257    dQP += m_pcCfg->getGOPEntry( (eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid ).m_QPOffset;
     258    }
     259  }
     260 
     261  // modify QP
     262  Int* pdQPs = m_pcCfg->getdQPs();
     263  if ( pdQPs )
     264  {
     265    dQP += pdQPs[ rpcSlice->getPOC() ];
     266  }
     267 
    174268  // ------------------------------------------------------------------------------------------------------------------
    175269  // Lambda computation
    176270  // ------------------------------------------------------------------------------------------------------------------
    177 
     271 
    178272  Int iQP;
     273  Double dOrigQP = dQP;
    179274
    180275  // pre-compute lambda and QP values for all possible QP candidates
    181 #if QC_MOD_LCEC_RDOQ
    182   m_pcTrQuant->setRDOQOffset(1);
    183 #endif
    184 
    185276  for ( Int iDQpIdx = 0; iDQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; iDQpIdx++ )
    186277  {
    187278    // compute QP value
    188279    dQP = dOrigQP + ((iDQpIdx+1)>>1)*(iDQpIdx%2 ? -1 : 1);
    189 
     280   
    190281    // compute lambda value
    191     Int    NumberBFrames = ( m_pcCfg->getRateGOPSize() - 1 );
     282    Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
    192283    Int    SHIFT_QP = 12;
    193284    Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
     
    197288    Int    bitdepth_luma_qp_scale = 0;
    198289#endif
    199     Double qp_temp = (double) dQP + bitdepth_luma_qp_scale - SHIFT_QP;
     290    Double qp_temp = (Double) dQP + bitdepth_luma_qp_scale - SHIFT_QP;
    200291#if FULL_NBIT
    201     Double qp_temp_orig = (double) dQP - SHIFT_QP;
     292    Double qp_temp_orig = (Double) dQP - SHIFT_QP;
    202293#endif
    203294    // Case #1: I or P-slices (key-frame)
    204     if(eSliceType == I_SLICE || eSliceType == P_SLICE )
    205     {
    206       if ( m_pcCfg->getUseRDOQ() && rpcSlice->isIntra() && dQP == dOrigQP )
    207       {
    208         dLambda = 0.57 * pow( 2.0, qp_temp/3.0 );
    209       }
    210       else
    211       {
    212         if ( NumberBFrames > 0 ) // HB structure or HP structure
    213         {
    214           dLambda = 0.68 * pow( 2.0, qp_temp/3.0 );
    215         }
    216         else                     // IPP structure
    217         {
    218           dLambda = 0.85 * pow( 2.0, qp_temp/3.0 );
    219         }
    220       }
    221       dLambda *= dLambda_scale;
    222     }
    223     else // P or B slices for HB or HP structure
    224     {
    225       dLambda = 0.68 * pow( 2.0, qp_temp/3.0 );
    226       if ( pcPic->getSlice(0)->isInterB () )
    227       {
     295    Double dQPFactor;
     296    if( eSliceType != I_SLICE )
     297    {
     298      dQPFactor = m_pcCfg->getGOPEntry( (eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid ).m_QPFactor;
     299    }
     300    else
     301    {
     302      dQPFactor = 0.57 * dLambda_scale;
     303    }
     304
     305    dLambda = dQPFactor*pow( 2.0, qp_temp/3.0 );
     306
     307    if ( iDepth>0 )
     308    {
    228309#if FULL_NBIT
    229310        dLambda *= Clip3( 2.00, 4.00, (qp_temp_orig / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
     
    231312        dLambda *= Clip3( 2.00, 4.00, (qp_temp / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
    232313#endif
    233         if ( rpcSlice->isReferenced() ) // HB structure and referenced
    234         {
    235           dLambda *= 0.80;
    236           dLambda *= dLambda_scale;
    237         }
    238       }
    239       else
    240       {
    241         dLambda *= dLambda_scale;
    242       }
    243     }
     314    }
     315   
    244316    // if hadamard is used in ME process
    245     if ( !m_pcCfg->getUseHADME() ) dLambda *= 0.95;
    246 
    247     iQP = Max( MIN_QP, Min( MAX_QP, (Int)floor( dQP + 0.5 ) ) );
     317    if ( !m_pcCfg->getUseHADME() )
     318    {
     319      dLambda *= 0.95;
     320    }
     321   
     322#if H0736_AVC_STYLE_QP_RANGE
     323    iQP = max( -pSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
     324#else
     325    iQP = max( MIN_QP, min( MAX_QP, (Int)floor( dQP + 0.5 ) ) );
     326#endif
    248327
    249328    m_pdRdPicLambda[iDQpIdx] = dLambda;
     
    251330    m_piRdPicQp    [iDQpIdx] = iQP;
    252331  }
    253 
     332 
    254333  // obtain dQP = 0 case
    255334  dLambda = m_pdRdPicLambda[0];
    256335  dQP     = m_pdRdPicQp    [0];
    257336  iQP     = m_piRdPicQp    [0];
     337 
     338  if( rpcSlice->getSliceType( ) != I_SLICE )
     339  {
     340    dLambda *= m_pcCfg->getLambdaModifier( iDepth );
     341  }
    258342
    259343  // store lambda
     344  m_pcRdCost ->setLambda( dLambda );
     345#if WEIGHTED_CHROMA_DISTORTION
     346// for RDO
     347  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
     348#if H0736_AVC_STYLE_QP_RANGE
     349  Double weight = 1.0;
     350  if(iQP >= 0)
     351  {
     352    weight = pow( 2.0, (iQP-g_aucChromaScale[iQP])/3.0 );  // takes into account of the chroma qp mapping without chroma qp Offset
     353  }
     354#else
     355  Double weight = pow( 2.0, (iQP-g_aucChromaScale[iQP])/3.0 );  // takes into account of the chroma qp mapping without chroma qp Offset
     356#endif
     357  m_pcRdCost ->setChromaDistortionWeight( weight );     
     358#endif
     359
    260360#if HHI_VSO
    261361  m_pcRdCost->setUseLambdaScaleVSO  ( (m_pcCfg->getUseVSO() ||  m_pcCfg->getForceLambdaScaleVSO()) && m_pcCfg->isDepthCoder()  );
     
    263363#endif
    264364
    265   m_pcRdCost ->setLambda      ( dLambda );
    266   m_pcTrQuant->setLambda      ( dLambda );
    267   rpcSlice   ->setLambda      ( dLambda );
     365#if RDOQ_CHROMA_LAMBDA
     366// for RDOQ
     367  m_pcTrQuant->setLambda( dLambda, dLambda / weight );   
     368#else
     369  m_pcTrQuant->setLambda( dLambda );
     370#endif
     371
     372#if ALF_CHROMA_LAMBDA || SAO_CHROMA_LAMBDA
     373// For ALF or SAO
     374  rpcSlice   ->setLambda( dLambda, dLambda / weight ); 
     375#else
     376  rpcSlice   ->setLambda( dLambda );
     377#endif
     378 
    268379#if HHI_INTER_VIEW_MOTION_PRED
    269380  m_pcRdCost ->setLambdaMVReg ( dLambda * m_pcCfg->getMultiviewMvRegLambdaScale() );
    270381#endif
    271 
    272 //#if HB_LAMBDA_FOR_LDC
    273 //  // restore original slice type
    274 //  if ( m_pcCfg->getUseLDC() )
    275 //  {
    276 //    eSliceType = P_SLICE;
    277 //  }
    278 //  eSliceType = (iPOCLast == 0 || uiPOCCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
    279 //
    280 //  rpcSlice->setSliceType        ( eSliceType );
    281 //#endif
    282 
     382 
     383#if HB_LAMBDA_FOR_LDC
     384  // restore original slice type
     385  eSliceType = eSliceTypeBaseView;
     386  if( eSliceTypeBaseView == I_SLICE && m_pcCfg->getGOPEntry(MAX_GOP).m_POC == 0 && m_pcCfg->getGOPEntry(MAX_GOP).m_sliceType != 'I' )
     387  {
     388    eSliceType = B_SLICE;
     389  }
     390  rpcSlice->setSliceType( eSliceType );
     391#endif
     392 
    283393  rpcSlice->setSliceQp          ( iQP );
     394#if ADAPTIVE_QP_SELECTION
     395  rpcSlice->setSliceQpBase      ( iQP );
     396#endif
    284397  rpcSlice->setSliceQpDelta     ( 0 );
    285   rpcSlice->setNumRefIdx        ( REF_PIC_LIST_0, eSliceType == I_SLICE ? 0 : pcPic->getNumRefs(REF_PIC_LIST_0) ) ;
    286   rpcSlice->setNumRefIdx        ( REF_PIC_LIST_1, eSliceType == I_SLICE ? 0 : pcPic->getNumRefs(REF_PIC_LIST_1) ) ;
    287 
    288   rpcSlice->setSymbolMode       ( m_pcCfg->getSymbolMode());
    289   rpcSlice->setLoopFilterDisable( m_pcCfg->getLoopFilterDisable() );
    290 
    291   rpcSlice->setDepth            ( 0 );
    292   rpcSlice->setViewIdx          ( pcPic->getViewIdx() );
    293 
    294   rpcSlice->setColDir( pcPic->getColDir());
     398  rpcSlice->setNumRefIdx(REF_PIC_LIST_0,m_pcCfg->getGOPEntry( (eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid ).m_numRefPicsActive);
     399  rpcSlice->setNumRefIdx(REF_PIC_LIST_1,m_pcCfg->getGOPEntry( (eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid ).m_numRefPicsActive);
     400 
     401  rpcSlice->setLoopFilterOffsetInAPS( m_pcCfg->getLoopFilterOffsetInAPS() );
     402#if DBL_CONTROL
     403  if (rpcSlice->getPPS()->getDeblockingFilterControlPresent())
     404  {
     405#endif
     406    rpcSlice->setInheritDblParamFromAPS( m_pcCfg->getLoopFilterOffsetInAPS() ? 1 : 0 );
     407    rpcSlice->setLoopFilterDisable( m_pcCfg->getLoopFilterDisable() );
     408    if ( !rpcSlice->getLoopFilterDisable())
     409    {
     410      rpcSlice->setLoopFilterBetaOffset( m_pcCfg->getLoopFilterBetaOffset() );
     411      rpcSlice->setLoopFilterTcOffset( m_pcCfg->getLoopFilterTcOffset() );
     412    }
     413#if DBL_CONTROL
     414  }
     415#endif
     416
     417  rpcSlice->setDepth            ( iDepth );
     418 
     419  pcPic->setTLayer( m_pcCfg->getGOPEntry( (eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid ).m_temporalId );
     420  if( eSliceType == I_SLICE )
     421  {
     422    pcPic->setTLayer(0);
     423  }
     424  rpcSlice->setTLayer( pcPic->getTLayer() );
     425#if !H0566_TLA
     426  rpcSlice->setTLayerSwitchingFlag( pPPS->getTLayerSwitchingFlag( pcPic->getTLayer() ) );
     427#endif
    295428
    296429  assert( m_apcPicYuvPred );
    297430  assert( m_apcPicYuvResi );
    298 
     431 
    299432  pcPic->setPicYuvPred( m_apcPicYuvPred );
    300433  pcPic->setPicYuvResi( m_apcPicYuvResi );
     
    303436  rpcSlice->setEntropySliceMode     ( m_pcCfg->getEntropySliceMode()     );
    304437  rpcSlice->setEntropySliceArgument ( m_pcCfg->getEntropySliceArgument() );
     438
     439#if ( HHI_MPI || HHI_INTER_VIEW_MOTION_PRED )
     440  #if ( HHI_MPI && HHI_INTER_VIEW_MOTION_PRED )
     441  const int iExtraMergeCandidates = ( pSPS->getUseMVI() || pSPS->getMultiviewMvPredMode() ) ? 1 : 0;
     442  #elif HHI_MPI
     443  const int iExtraMergeCandidates = pSPS->getUseMVI() ? 1 : 0;
     444  #else
     445  const int iExtraMergeCandidates = pSPS->getMultiviewMvPredMode() ? 1 : 0;
     446  #endif
     447  rpcSlice->setMaxNumMergeCand      (MRG_MAX_NUM_CANDS_SIGNALED+iExtraMergeCandidates);
     448#else
     449  rpcSlice->setMaxNumMergeCand      (MRG_MAX_NUM_CANDS_SIGNALED);
     450#endif
     451  xStoreWPparam( pPPS->getUseWP(), pPPS->getWPBiPredIdc() );
    305452}
    306453
     
    313460  Int iCurrPOC = pcSlice->getPOC();
    314461  Int iRefPOC;
    315   Int iRateGOPSize = m_pcCfg->getRateGOPSize();
    316   Int iOffset = (iRateGOPSize >> 1);
     462  Int iGOPSize = m_pcCfg->getGOPSize();
     463  Int iOffset = (iGOPSize >> 1);
    317464  Int iMaxSR = m_pcCfg->getSearchRange();
    318465  Int iNumPredDir = pcSlice->isInterP() ? 1 : 2;
    319 
     466 
    320467  for (Int iDir = 0; iDir <= iNumPredDir; iDir++)
    321468  {
     
    324471    {
    325472      iRefPOC = pcSlice->getRefPic(e, iRefIdx)->getPOC();
    326       Int iNewSR = Clip3(8, iMaxSR, (iMaxSR*ADAPT_SR_SCALE*abs(iCurrPOC - iRefPOC)+iOffset)/iRateGOPSize);
     473      Int iNewSR = Clip3(8, iMaxSR, (iMaxSR*ADAPT_SR_SCALE*abs(iCurrPOC - iRefPOC)+iOffset)/iGOPSize);
    327474      m_pcPredSearch->setAdaptiveSearchRange(iDir, iRefIdx, iNewSR);
    328475    }
     
    338485{
    339486  // if deltaQP RD is not used, simply return
    340   if ( m_pcCfg->getDeltaQpRD() == 0 ) return;
    341 
     487  if ( m_pcCfg->getDeltaQpRD() == 0 )
     488  {
     489    return;
     490  }
     491 
    342492  TComSlice* pcSlice        = rpcPic->getSlice(getSliceIdx());
    343493  Double     dPicRdCostBest = MAX_DOUBLE;
    344   Double dSumCURdCostBest;
    345   UInt64     uiPicDistBest;
    346   UInt64     uiPicBitsBest;
    347494  UInt       uiQpIdxBest = 0;
    348 
     495 
    349496  Double dFrameLambda;
    350497#if FULL_NBIT
     
    353500  Int    SHIFT_QP = 12;
    354501#endif
    355 
     502 
    356503  // set frame lambda
    357504  if (m_pcCfg->getGOPSize() > 1)
     
    364511  }
    365512  m_pcRdCost      ->setFrameLambda(dFrameLambda);
    366 #if HHI_VSO
    367   m_pcRdCost      ->setFrameLambdaVSO( dFrameLambda * m_pcCfg->getLambdaScaleVSO() );
    368 #endif
    369 
     513 
    370514  // for each QP candidate
    371515  for ( UInt uiQpIdx = 0; uiQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; uiQpIdx++ )
    372516  {
    373517    pcSlice       ->setSliceQp             ( m_piRdPicQp    [uiQpIdx] );
     518#if ADAPTIVE_QP_SELECTION
     519    pcSlice       ->setSliceQpBase         ( m_piRdPicQp    [uiQpIdx] );
     520#endif
    374521    m_pcRdCost    ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
     522#if WEIGHTED_CHROMA_DISTORTION
     523    // for RDO
     524    // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
     525    int iQP = m_piRdPicQp    [uiQpIdx];
     526#if H0736_AVC_STYLE_QP_RANGE
     527    Double weight = 1.0;
     528    if(iQP >= 0)
     529    {
     530      weight = pow( 2.0, (iQP-g_aucChromaScale[iQP])/3.0 );  // takes into account of the chroma qp mapping without chroma qp Offset
     531    }
     532#else
     533    Double weight = pow( 2.0, (iQP-g_aucChromaScale[iQP])/3.0 );  // takes into account of the chroma qp mapping without chroma qp Offset
     534#endif
     535    m_pcRdCost    ->setChromaDistortionWeight( weight );     
     536#endif
     537
     538#if RDOQ_CHROMA_LAMBDA
     539    // for RDOQ
     540    m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
     541#else
    375542    m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
     543#endif
     544#if ALF_CHROMA_LAMBDA || SAO_CHROMA_LAMBDA
     545    // For ALF or SAO
     546    pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
     547#else
    376548    pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
     549#endif
    377550#if HHI_INTER_VIEW_MOTION_PRED
    378551    m_pcRdCost    ->setLambdaMVReg         ( m_pdRdPicLambda[uiQpIdx] * m_pcCfg->getMultiviewMvRegLambdaScale() );
    379552#endif
    380 
     553   
    381554    // try compress
    382555    compressSlice   ( rpcPic );
    383 
     556   
    384557    Double dPicRdCost;
    385558    UInt64 uiPicDist        = m_uiPicDist;
    386559    UInt64 uiALFBits        = 0;
    387 
    388     m_pcPicEncoder->preLoopFilterPicAll( rpcPic, uiPicDist, uiALFBits );
    389 
     560   
     561    m_pcGOPEncoder->preLoopFilterPicAll( rpcPic, uiPicDist, uiALFBits );
     562   
    390563    // compute RD cost and choose the best
    391564    dPicRdCost = m_pcRdCost->calcRdCost64( m_uiPicTotalBits + uiALFBits, uiPicDist, true, DF_SSE_FRAME);
    392 
     565   
    393566    if ( dPicRdCost < dPicRdCostBest )
    394567    {
    395568      uiQpIdxBest    = uiQpIdx;
    396569      dPicRdCostBest = dPicRdCost;
    397       dSumCURdCostBest = m_dPicRdCost;
    398 
    399       uiPicBitsBest = m_uiPicTotalBits + uiALFBits;
    400       uiPicDistBest = uiPicDist;
    401     }
    402   }
    403 
     570    }
     571  }
     572 
    404573  // set best values
    405574  pcSlice       ->setSliceQp             ( m_piRdPicQp    [uiQpIdxBest] );
     575#if ADAPTIVE_QP_SELECTION
     576  pcSlice       ->setSliceQpBase         ( m_piRdPicQp    [uiQpIdxBest] );
     577#endif
    406578  m_pcRdCost    ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
     579#if WEIGHTED_CHROMA_DISTORTION
     580  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
     581  int iQP = m_piRdPicQp    [uiQpIdxBest];
     582#if H0736_AVC_STYLE_QP_RANGE
     583  Double weight = 1.0;
     584  if(iQP >= 0)
     585  {
     586    weight = pow( 2.0, (iQP-g_aucChromaScale[iQP])/3.0 );  // takes into account of the chroma qp mapping without chroma qp Offset
     587  }
     588#else
     589  Double weight = pow( 2.0, (iQP-g_aucChromaScale[iQP])/3.0 );  // takes into account of the chroma qp mapping without chroma qp Offset
     590#endif
     591  m_pcRdCost ->setChromaDistortionWeight( weight );     
     592#endif
     593
     594#if RDOQ_CHROMA_LAMBDA
     595  // for RDOQ
     596  m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
     597#else
    407598  m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
     599#endif
     600#if ALF_CHROMA_LAMBDA || SAO_CHROMA_LAMBDA
     601  // For ALF or SAO
     602  pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
     603#else
    408604  pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
     605#endif
    409606#if HHI_INTER_VIEW_MOTION_PRED
    410607  m_pcRdCost    ->setLambdaMVReg         ( m_pdRdPicLambda[uiQpIdxBest] * m_pcCfg->getMultiviewMvRegLambdaScale() );
     
    419616  UInt   uiStartCUAddr;
    420617  UInt   uiBoundingCUAddr;
    421   UInt64 uiBitsCoded            = 0;
     618  rpcPic->getSlice(getSliceIdx())->setEntropySliceCounter(0);
    422619  TEncBinCABAC* pppcRDSbacCoder = NULL;
    423620  TComSlice* pcSlice            = rpcPic->getSlice(getSliceIdx());
    424621  xDetermineStartAndBoundingCUAddr ( uiStartCUAddr, uiBoundingCUAddr, rpcPic, false );
    425 
    426 #ifdef WEIGHT_PRED
    427   //------------------------------------------------------------------------------
    428   //  Weighted Prediction parameters estimation.
    429   //------------------------------------------------------------------------------
    430   // calculate AC/DC values for current picture
    431   if( pcSlice->getPPS()->getUseWP() || pcSlice->getPPS()->getWPBiPredIdc() )
    432     xCalcACDCParamSlice(pcSlice);
    433 
    434   Bool  wp_Explicit =  (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==1);
    435   Bool  wp_Implicit = (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==2);
    436 
    437   if ( wp_Explicit || wp_Implicit )
    438   {
    439         //------------------------------------------------------------------------------
    440         //  Weighted Prediction implemented at Slice level, sliceMode=2 only.
    441         //------------------------------------------------------------------------------
    442     if ( pcSlice->getSliceMode()==2 || pcSlice->getEntropySliceMode()==2 )
    443     {
    444       printf("Weighted Prediction not implemented with slice mode determined by max number of bins.\n"); exit(0);
    445     }
    446 
    447     if( wp_Explicit )
    448       xEstimateWPParamSlice(pcSlice);
    449 
    450     pcSlice->initWpScaling();
    451     pcSlice->displayWpScaling();
    452   }
    453 #endif
    454 
     622 
    455623  // initialize cost values
    456624  m_uiPicTotalBits  = 0;
    457625  m_dPicRdCost      = 0;
    458626  m_uiPicDist       = 0;
    459 
     627 
    460628  // set entropy coder
    461629  if( m_pcCfg->getUseSBACRD() )
     
    471639  else
    472640  {
    473     m_pcCavlcCoder  ->setAdaptFlag    ( false );
    474641    m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );
    475642    m_pcEntropyCoder->resetEntropy      ();
    476643    m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
    477644  }
    478 
     645 
     646  //------------------------------------------------------------------------------
     647  //  Weighted Prediction parameters estimation.
     648  //------------------------------------------------------------------------------
     649  // calculate AC/DC values for current picture
     650  if( pcSlice->getPPS()->getUseWP() || pcSlice->getPPS()->getWPBiPredIdc() )
     651  {
     652    xCalcACDCParamSlice(pcSlice);
     653  }
     654
     655  Bool bWp_explicit = (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==1);
     656  Bool bWp_implicit = (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==2);
     657
     658  if ( bWp_explicit || bWp_implicit )
     659  {
     660    //------------------------------------------------------------------------------
     661    //  Weighted Prediction implemented at Slice level. SliceMode=2 is not supported yet.
     662    //------------------------------------------------------------------------------
     663    if ( pcSlice->getSliceMode()==2 || pcSlice->getEntropySliceMode()==2 )
     664    {
     665      printf("Weighted Prediction is not supported with slice mode determined by max number of bins.\n"); exit(0);
     666    }
     667
     668    if( bWp_explicit )
     669    {
     670      xEstimateWPParamSlice( pcSlice );
     671    }
     672   
     673    pcSlice->initWpScaling();
     674
     675    // check WP on/off
     676    if( bWp_explicit )
     677    {
     678      xCheckWPEnable( pcSlice );
     679    }
     680  }
     681
     682#if ADAPTIVE_QP_SELECTION
     683  if( m_pcCfg->getUseAdaptQpSelect() )
     684  {
     685    m_pcTrQuant->clearSliceARLCnt();
     686    if(pcSlice->getSliceType()!=I_SLICE)
     687    {
     688      Int qpBase = pcSlice->getSliceQpBase();
     689      pcSlice->setSliceQp(qpBase + m_pcTrQuant->getQpDelta(qpBase));
     690    }
     691  }
     692#endif
    479693  // initialize ALF parameters
    480694  m_pcEntropyCoder->setAlfCtrl(false);
    481695  m_pcEntropyCoder->setMaxAlfCtrlDepth(0); //unnecessary
     696 
     697  TEncTop* pcEncTop = (TEncTop*) m_pcCfg;
     698  TEncSbac**** ppppcRDSbacCoders    = pcEncTop->getRDSbacCoders();
     699  TComBitCounter* pcBitCounters     = pcEncTop->getBitCounters();
     700  Int  iNumSubstreams = 1;
     701  UInt uiTilesAcross  = 0;
     702
     703  if( m_pcCfg->getUseSBACRD() )
     704  {
     705    iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
     706    uiTilesAcross = rpcPic->getPicSym()->getNumColumnsMinus1()+1;
     707    delete[] m_pcBufferSbacCoders;
     708    delete[] m_pcBufferBinCoderCABACs;
     709    m_pcBufferSbacCoders     = new TEncSbac    [uiTilesAcross];
     710    m_pcBufferBinCoderCABACs = new TEncBinCABAC[uiTilesAcross];
     711    for (int ui = 0; ui < uiTilesAcross; ui++)
     712    {
     713      m_pcBufferSbacCoders[ui].init( &m_pcBufferBinCoderCABACs[ui] );
     714    }
     715    for (UInt ui = 0; ui < uiTilesAcross; ui++)
     716    {
     717      m_pcBufferSbacCoders[ui].load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);  //init. state
     718    }
     719
     720    for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ ) //init all sbac coders for RD optimization
     721    {
     722      ppppcRDSbacCoders[ui][0][CI_CURR_BEST]->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
     723    }
     724  }
     725  //if( m_pcCfg->getUseSBACRD() )
     726  {
     727    delete[] m_pcBufferLowLatSbacCoders;
     728    delete[] m_pcBufferLowLatBinCoderCABACs;
     729    m_pcBufferLowLatSbacCoders     = new TEncSbac    [uiTilesAcross];
     730    m_pcBufferLowLatBinCoderCABACs = new TEncBinCABAC[uiTilesAcross];
     731    for (int ui = 0; ui < uiTilesAcross; ui++)
     732    {
     733      m_pcBufferLowLatSbacCoders[ui].init( &m_pcBufferLowLatBinCoderCABACs[ui] );
     734    }
     735    for (UInt ui = 0; ui < uiTilesAcross; ui++)
     736      m_pcBufferLowLatSbacCoders[ui].load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);  //init. state
     737  }
     738  UInt uiWidthInLCUs  = rpcPic->getPicSym()->getFrameWidthInCU();
     739  //UInt uiHeightInLCUs = rpcPic->getPicSym()->getFrameHeightInCU();
     740  UInt uiCol=0, uiLin=0, uiSubStrm=0;
     741#if !REMOVE_TILE_DEPENDENCE
     742  Int  iBreakDep      = 0;
     743#endif
     744  UInt uiTileCol      = 0;
     745  UInt uiTileStartLCU = 0;
     746  UInt uiTileLCUX     = 0;
    482747
    483748  // for every CU in slice
    484   for(  uiCUAddr = uiStartCUAddr; uiCUAddr < uiBoundingCUAddr; uiCUAddr++  )
    485   {
    486     // set QP
    487     m_pcCuEncoder->setQpLast( pcSlice->getSliceQp() );
     749  UInt uiEncCUOrder;
     750  uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
     751  for( uiEncCUOrder = uiStartCUAddr/rpcPic->getNumPartInCU();
     752       uiEncCUOrder < (uiBoundingCUAddr+(rpcPic->getNumPartInCU()-1))/rpcPic->getNumPartInCU();
     753       uiCUAddr = rpcPic->getPicSym()->getCUOrderMap(++uiEncCUOrder) )
     754  {
    488755    // initialize CU encoder
    489756    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
    490757    pcCU->initCU( rpcPic, uiCUAddr );
    491758
     759    // inherit from TR if necessary, select substream to use.
     760    if( m_pcCfg->getUseSBACRD() )
     761    {
     762#if !REMOVE_TILE_DEPENDENCE
     763      iBreakDep = rpcPic->getPicSym()->getTileBoundaryIndependenceIdr();
     764#endif
     765      uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in?
     766      uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
     767      uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
     768      //UInt uiSliceStartLCU = pcSlice->getSliceCurStartCUAddr();
     769      uiCol     = uiCUAddr % uiWidthInLCUs;
     770      uiLin     = uiCUAddr / uiWidthInLCUs;
     771#if !REMOVE_TILE_DEPENDENCE
     772#if WPP_SIMPLIFICATION
     773      if (iBreakDep && pcSlice->getPPS()->getNumSubstreams() > 1)
     774#else
     775      if (iBreakDep && pcSlice->getPPS()->getEntropyCodingSynchro())
     776#endif
     777#else
     778#if WPP_SIMPLIFICATION
     779      if (pcSlice->getPPS()->getNumSubstreams() > 1)
     780#else
     781      if (pcSlice->getPPS()->getEntropyCodingSynchro())
     782#endif
     783#endif
     784      {
     785        // independent tiles => substreams are "per tile".  iNumSubstreams has already been multiplied.
     786        Int iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
     787        uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)*iNumSubstreamsPerTile
     788                      + uiLin%iNumSubstreamsPerTile;
     789      }
     790      else
     791      {
     792        // dependent tiles => substreams are "per frame".
     793        uiSubStrm = uiLin % iNumSubstreams;
     794      }
     795#if WPP_SIMPLIFICATION
     796      if ( pcSlice->getPPS()->getNumSubstreams() > 1 && (uiCol == uiTileLCUX) )
     797#else
     798      if ( pcSlice->getPPS()->getEntropyCodingSynchro() && (uiCol == uiTileLCUX) )
     799#endif
     800      {
     801        // We'll sync if the TR is available.
     802        TComDataCU *pcCUUp = pcCU->getCUAbove();
     803        UInt uiWidthInCU = rpcPic->getFrameWidthInCU();
     804        UInt uiMaxParts = 1<<(pcSlice->getSPS()->getMaxCUDepth()<<1);
     805        TComDataCU *pcCUTR = NULL;
     806#if WPP_SIMPLIFICATION
     807        if ( pcCUUp && ((uiCUAddr%uiWidthInCU+1) < uiWidthInCU)  )
     808        {
     809          pcCUTR = rpcPic->getCU( uiCUAddr - uiWidthInCU + 1 );
     810        }
     811#else
     812        if ( pcCUUp && ((uiCUAddr%uiWidthInCU+pcSlice->getPPS()->getEntropyCodingSynchro()) < uiWidthInCU)  )
     813        {
     814          pcCUTR = rpcPic->getCU( uiCUAddr - uiWidthInCU + pcSlice->getPPS()->getEntropyCodingSynchro() );
     815        }
     816#endif
     817        if ( ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
     818             (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getSliceCurStartCUAddr()) ||
     819#if !REMOVE_TILE_DEPENDENCE
     820             (rpcPic->getPicSym()->getTileBoundaryIndependenceIdr() && (rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
     821#else
     822             ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
     823#endif
     824             )||
     825             ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
     826             (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getEntropySliceCurStartCUAddr()) ||
     827#if !REMOVE_TILE_DEPENDENCE
     828             (rpcPic->getPicSym()->getTileBoundaryIndependenceIdr() && (rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
     829#else
     830             ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
     831#endif
     832             )
     833           )
     834        {
     835          // TR not available.
     836        }
     837        else
     838        {
     839          // TR is available, we use it.
     840          ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->loadContexts( &m_pcBufferSbacCoders[uiTileCol] );
     841        }
     842      }
     843      m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST] ); //this load is used to simplify the code
     844    }
     845
     846    // reset the entropy coder
     847    if( uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr() &&                                   // must be first CU of tile
     848        uiCUAddr!=0 &&                                                                                                                                    // cannot be first CU of picture
     849        uiCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceCurStartCUAddr())/rpcPic->getNumPartInCU())     // cannot be first CU of slice
     850    {
     851#if CABAC_INIT_FLAG
     852      SliceType sliceType = pcSlice->getSliceType();
     853      if (!pcSlice->isIntra() && pcSlice->getPPS()->getCabacInitPresentFlag() && pcSlice->getPPS()->getEncCABACTableIdx()!=0)
     854      {
     855        sliceType = (SliceType) pcSlice->getPPS()->getEncCABACTableIdx();
     856      }
     857      m_pcEntropyCoder->updateContextTables ( sliceType, pcSlice->getSliceQp(), false );
     858      m_pcEntropyCoder->setEntropyCoder     ( m_pppcRDSbacCoder[0][CI_CURR_BEST], pcSlice );
     859      m_pcEntropyCoder->updateContextTables ( sliceType, pcSlice->getSliceQp() );
     860      m_pcEntropyCoder->setEntropyCoder     ( m_pcSbacCoder, pcSlice );
     861#else
     862      m_pcEntropyCoder->updateContextTables ( pcSlice->getSliceType(), pcSlice->getSliceQp(), false );
     863      m_pcEntropyCoder->setEntropyCoder     ( m_pppcRDSbacCoder[0][CI_CURR_BEST], pcSlice );
     864      m_pcEntropyCoder->updateContextTables ( pcSlice->getSliceType(), pcSlice->getSliceQp() );
     865      m_pcEntropyCoder->setEntropyCoder     ( m_pcSbacCoder, pcSlice );
     866#endif
     867    }
     868#if !REMOVE_TILE_DEPENDENCE
     869    if( (rpcPic->getPicSym()->getTileBoundaryIndependenceIdr()==0) && (rpcPic->getPicSym()->getNumColumnsMinus1()!=0) )
     870    {
     871      // Synchronize cabac probabilities with LCU among Tiles
     872      if( (uiTileLCUX != 0) &&
     873          (uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr()) )
     874      {
     875        TComDataCU *pcCULeft = pcCU->getCULeft();
     876        UInt uiMaxParts = 1<<(pcSlice->getSPS()->getMaxCUDepth()<<1);
     877
     878        if ( (true/*bEnforceSliceRestriction*/ &&
     879              ((pcCULeft==NULL) || (pcCULeft->getSlice()==NULL) ||
     880               ((pcCULeft->getSCUAddr()+uiMaxParts-1) < pcSlice->getSliceCurStartCUAddr())
     881              )
     882             )||
     883             (true/*bEnforceEntropySliceRestriction*/ &&
     884              ((pcCULeft==NULL) || (pcCULeft->getSlice()==NULL) ||
     885               ((pcCULeft->getSCUAddr()+uiMaxParts-1) < pcSlice->getEntropySliceCurStartCUAddr())
     886              )
     887             )
     888           )
     889        {
     890          // Left not available.
     891        }
     892        else
     893        {
     894          // Left is available, we use it.
     895          ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->loadContexts( &m_pcBufferLowLatSbacCoders[uiTileCol-1] );
     896          m_pppcRDSbacCoder[0][CI_CURR_BEST]->loadContexts( ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST] ); //this load is used to simplify the code
     897        }
     898      }
     899    }
     900#endif
    492901    // if RD based on SBAC is used
    493902    if( m_pcCfg->getUseSBACRD() )
     
    495904      // set go-on entropy coder
    496905      m_pcEntropyCoder->setEntropyCoder ( m_pcRDGoOnSbacCoder, pcSlice );
    497       m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
    498 
     906      m_pcEntropyCoder->setBitstream( &pcBitCounters[uiSubStrm] );
     907     
     908      ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true);
    499909      // run CU encoder
    500910      m_pcCuEncoder->compressCU( pcCU );
    501 
     911     
    502912      // restore entropy coder to an initial stage
    503913      m_pcEntropyCoder->setEntropyCoder ( m_pppcRDSbacCoder[0][CI_CURR_BEST], pcSlice );
    504       m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
     914      m_pcEntropyCoder->setBitstream( &pcBitCounters[uiSubStrm] );
     915      m_pcCuEncoder->setBitCounter( &pcBitCounters[uiSubStrm] );
     916      m_pcBitCounter = &pcBitCounters[uiSubStrm];
    505917      pppcRDSbacCoder->setBinCountingEnableFlag( true );
    506 
     918      m_pcBitCounter->resetBits();
     919      pppcRDSbacCoder->setBinsCoded( 0 );
    507920      m_pcCuEncoder->encodeCU( pcCU );
    508921
    509922      pppcRDSbacCoder->setBinCountingEnableFlag( false );
    510       uiBitsCoded += m_pcBitCounter->getNumberOfWrittenBits();
    511       if (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE && ( ( pcSlice->getSliceBits() + uiBitsCoded ) >> 3 ) > m_pcCfg->getSliceArgument())
    512       {
    513         if (uiCUAddr==uiStartCUAddr && pcSlice->getSliceBits()==0)
    514         {
    515           // Could not fit even a single LCU within the slice under the defined byte-constraint. Display a warning message and code 1 LCU in the slice.
    516           fprintf(stdout,"\nSlice overflow warning! codedBits=%6d, limitBytes=%6d", m_pcBitCounter->getNumberOfWrittenBits(), m_pcCfg->getSliceArgument() );
    517           uiCUAddr = uiCUAddr + 1;
    518         }
     923      if (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE && ( ( pcSlice->getSliceBits() + m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)
     924      {
    519925        pcSlice->setNextSlice( true );
    520926        break;
    521927      }
    522 
    523       UInt uiBinsCoded = pppcRDSbacCoder->getBinsCoded();
    524       if (m_pcCfg->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE && uiBinsCoded > m_pcCfg->getEntropySliceArgument())
    525       {
    526         if (uiCUAddr == uiStartCUAddr)
    527         {
    528           // Could not fit even a single LCU within the entropy slice under the defined byte-constraint. Display a warning message and code 1 LCU in the entropy slice.
    529           fprintf(stdout,"\nEntropy Slice overflow warning! codedBins=%6d, limitBins=%6d", uiBinsCoded, m_pcCfg->getEntropySliceArgument() );
    530           uiCUAddr = uiCUAddr + 1;
    531         }
     928      if (m_pcCfg->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE && pcSlice->getEntropySliceCounter()+pppcRDSbacCoder->getBinsCoded() > m_pcCfg->getEntropySliceArgument()&&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getEntropySliceCurEndCUAddr())
     929      {
    532930        pcSlice->setNextEntropySlice( true );
    533931        break;
    534932      }
     933      if( m_pcCfg->getUseSBACRD() )
     934      {
     935         ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] );
     936       
     937         //Store probabilties of second LCU in line into buffer
     938#if WPP_SIMPLIFICATION
     939        if (pcSlice->getPPS()->getNumSubstreams() > 1 && uiCol == uiTileLCUX+1)
     940#else
     941        if (pcSlice->getPPS()->getEntropyCodingSynchro() && uiCol == uiTileLCUX+pcSlice->getPPS()->getEntropyCodingSynchro())
     942#endif
     943        {
     944          m_pcBufferSbacCoders[uiTileCol].loadContexts(ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]);
     945        }
     946      }
     947#if !REMOVE_TILE_DEPENDENCE
     948      if( (rpcPic->getPicSym()->getTileBoundaryIndependenceIdr()==0) && (rpcPic->getPicSym()->getNumColumnsMinus1()!=0) )
     949      {
     950         //Store probabilties for next tile
     951        if( (uiLin == (rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr() / uiWidthInLCUs )) &&
     952            (uiCol == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getRightEdgePosInCU()) )
     953        {
     954          m_pcBufferLowLatSbacCoders[uiTileCol].loadContexts(ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]);
     955        }
     956      }
     957#endif
    535958    }
    536959    // other case: encodeCU is not called
     
    538961    {
    539962      m_pcCuEncoder->compressCU( pcCU );
    540       m_pcCavlcCoder ->setAdaptFlag(true);
    541963      m_pcCuEncoder->encodeCU( pcCU );
    542 
    543       uiBitsCoded += m_pcBitCounter->getNumberOfWrittenBits();
    544       if (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE && ( ( pcSlice->getSliceBits() + uiBitsCoded ) >> 3 ) > m_pcCfg->getSliceArgument())
    545       {
    546         if (uiCUAddr==uiStartCUAddr && pcSlice->getSliceBits()==0)
    547         {
    548           // Could not fit even a single LCU within the slice under the defined byte-constraint. Display a warning message and code 1 LCU in the slice.
    549           fprintf(stdout,"\nSlice overflow warning! codedBits=%6d, limitBytes=%6d", m_pcBitCounter->getNumberOfWrittenBits(), m_pcCfg->getSliceArgument() );
    550           uiCUAddr = uiCUAddr + 1;
    551         }
     964      if (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE && ( ( pcSlice->getSliceBits()+ m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)
     965      {
    552966        pcSlice->setNextSlice( true );
    553967        break;
    554968      }
    555 
    556       if (m_pcCfg->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE && uiBitsCoded > m_pcCfg->getEntropySliceArgument())
    557       {
    558         if (uiCUAddr == uiStartCUAddr)
    559         {
    560           // Could not fit even a single LCU within the entropy slice under the defined bit/bin-constraint. Display a warning message and code 1 LCU in the entropy slice.
    561           fprintf(stdout,"\nEntropy Slice overflow warning! codedBits=%6d, limitBits=%6d", m_pcBitCounter->getNumberOfWrittenBits(), m_pcCfg->getEntropySliceArgument() );
    562           uiCUAddr = uiCUAddr + 1;
    563         }
     969      if (m_pcCfg->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE && pcSlice->getEntropySliceCounter()+ m_pcEntropyCoder->getNumberOfWrittenBits()> m_pcCfg->getEntropySliceArgument()&&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getEntropySliceCurEndCUAddr())
     970      {
    564971        pcSlice->setNextEntropySlice( true );
    565972        break;
    566973      }
    567       m_pcCavlcCoder ->setAdaptFlag(false);
    568     }
    569 
     974    }
     975   
    570976    m_uiPicTotalBits += pcCU->getTotalBits();
    571977    m_dPicRdCost     += pcCU->getTotalCost();
    572978    m_uiPicDist      += pcCU->getTotalDistortion();
    573979  }
    574   pcSlice->setSliceCurEndCUAddr( uiCUAddr );
    575   pcSlice->setEntropySliceCurEndCUAddr( uiCUAddr );
    576   pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + uiBitsCoded) );
     980  xRestoreWPparam( pcSlice );
    577981}
    578982
     
    581985 \retval rpcBitstream  bitstream class
    582986 */
    583 Void TEncSlice::encodeSlice   ( TComPic*& rpcPic, TComBitstream*& rpcBitstream )
     987Void TEncSlice::encodeSlice   ( TComPic*& rpcPic, TComOutputBitstream* pcBitstream, TComOutputBitstream* pcSubstreams )
    584988{
    585989  UInt       uiCUAddr;
    586990  UInt       uiStartCUAddr;
    587991  UInt       uiBoundingCUAddr;
    588   xDetermineStartAndBoundingCUAddr  ( uiStartCUAddr, uiBoundingCUAddr, rpcPic, true );
    589992  TComSlice* pcSlice = rpcPic->getSlice(getSliceIdx());
    590993
     994  uiStartCUAddr=pcSlice->getEntropySliceCurStartCUAddr();
     995  uiBoundingCUAddr=pcSlice->getEntropySliceCurEndCUAddr();
    591996  // choose entropy coder
    592   Int iSymbolMode = pcSlice->getSymbolMode();
    593   if (iSymbolMode)
    594997  {
    595998    m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC );
    596999    m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice );
    5971000  }
    598   else
    599   {
    600     m_pcCavlcCoder  ->setAdaptFlag( true );
    601     m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );
    602     m_pcEntropyCoder->resetEntropy();
    603   }
    604 
    605   // set bitstream
    606   m_pcEntropyCoder->setBitstream( rpcBitstream );
     1001 
     1002  m_pcCuEncoder->setBitCounter( NULL );
     1003  m_pcBitCounter = NULL;
     1004  // Appropriate substream bitstream is switched later.
    6071005  // for every CU
    6081006#if ENC_DEC_TRACE
    6091007  g_bJustDoIt = g_bEncDecTraceEnable;
    6101008#endif
    611   DTRACE_CABAC_V( g_nSymbolCounter++ );
     1009  DTRACE_CABAC_VL( g_nSymbolCounter++ );
    6121010  DTRACE_CABAC_T( "\tPOC: " );
    6131011  DTRACE_CABAC_V( rpcPic->getPOC() );
     
    6171015#endif
    6181016
    619   for(  uiCUAddr = uiStartCUAddr; uiCUAddr<uiBoundingCUAddr; uiCUAddr++  )
    620   {
    621     m_pcCuEncoder->setQpLast( pcSlice->getSliceQp() );
    622     TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
     1017  TEncTop* pcEncTop = (TEncTop*) m_pcCfg;
     1018  TEncSbac* pcSbacCoders = pcEncTop->getSbacCoders(); //coder for each substream
     1019  Int iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
     1020  UInt uiBitsOriginallyInSubstreams = 0;
     1021  {
     1022    UInt uiTilesAcross = rpcPic->getPicSym()->getNumColumnsMinus1()+1;
     1023    for (UInt ui = 0; ui < uiTilesAcross; ui++)
     1024    {
     1025      m_pcBufferSbacCoders[ui].load(m_pcSbacCoder); //init. state
     1026    }
     1027   
     1028    for (Int iSubstrmIdx=0; iSubstrmIdx < iNumSubstreams; iSubstrmIdx++)
     1029    {
     1030      uiBitsOriginallyInSubstreams += pcSubstreams[iSubstrmIdx].getNumberOfWrittenBits();
     1031    }
     1032
     1033    for (UInt ui = 0; ui < uiTilesAcross; ui++)
     1034    {
     1035      m_pcBufferLowLatSbacCoders[ui].load(m_pcSbacCoder);  //init. state
     1036    }
     1037  }
     1038
     1039  UInt uiWidthInLCUs  = rpcPic->getPicSym()->getFrameWidthInCU();
     1040  UInt uiCol=0, uiLin=0, uiSubStrm=0;
     1041#if !REMOVE_TILE_DEPENDENCE
     1042  Int  iBreakDep      = 0;
     1043#endif
     1044  UInt uiTileCol      = 0;
     1045  UInt uiTileStartLCU = 0;
     1046  UInt uiTileLCUX     = 0;
     1047
     1048  UInt uiEncCUOrder;
     1049  uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());  /*for tiles, uiStartCUAddr is NOT the real raster scan address, it is actually
     1050                                                                                              an encoding order index, so we need to convert the index (uiStartCUAddr)
     1051                                                                                              into the real raster scan address (uiCUAddr) via the CUOrderMap*/
     1052  for( uiEncCUOrder = uiStartCUAddr /rpcPic->getNumPartInCU();
     1053       uiEncCUOrder < (uiBoundingCUAddr+rpcPic->getNumPartInCU()-1)/rpcPic->getNumPartInCU();
     1054       uiCUAddr = rpcPic->getPicSym()->getCUOrderMap(++uiEncCUOrder) )
     1055  {
     1056    if( m_pcCfg->getUseSBACRD() )
     1057    {
     1058#if !REMOVE_TILE_DEPENDENCE
     1059      iBreakDep = rpcPic->getPicSym()->getTileBoundaryIndependenceIdr();
     1060#endif
     1061      uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in?
     1062      uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
     1063      uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
     1064      //UInt uiSliceStartLCU = pcSlice->getSliceCurStartCUAddr();
     1065      uiCol     = uiCUAddr % uiWidthInLCUs;
     1066      uiLin     = uiCUAddr / uiWidthInLCUs;
     1067#if !REMOVE_TILE_DEPENDENCE
     1068#if WPP_SIMPLIFICATION
     1069      if (iBreakDep && pcSlice->getPPS()->getNumSubstreams() > 1)
     1070#else
     1071      if (iBreakDep && pcSlice->getPPS()->getEntropyCodingSynchro())
     1072#endif
     1073#else
     1074#if WPP_SIMPLIFICATION
     1075      if (pcSlice->getPPS()->getNumSubstreams() > 1)
     1076#else
     1077      if (pcSlice->getPPS()->getEntropyCodingSynchro())
     1078#endif
     1079#endif
     1080      {
     1081        // independent tiles => substreams are "per tile".  iNumSubstreams has already been multiplied.
     1082        Int iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
     1083        uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)*iNumSubstreamsPerTile
     1084                      + uiLin%iNumSubstreamsPerTile;
     1085      }
     1086      else
     1087      {
     1088        // dependent tiles => substreams are "per frame".
     1089        uiSubStrm = uiLin % iNumSubstreams;
     1090      }
     1091
     1092      m_pcEntropyCoder->setBitstream( &pcSubstreams[uiSubStrm] );
     1093
     1094      // Synchronize cabac probabilities with upper-right LCU if it's available and we're at the start of a line.
     1095#if WPP_SIMPLIFICATION
     1096      if (pcSlice->getPPS()->getNumSubstreams() > 1 && (uiCol == uiTileLCUX))
     1097#else
     1098      if (pcSlice->getPPS()->getEntropyCodingSynchro() && (uiCol == uiTileLCUX))
     1099#endif
     1100      {
     1101        // We'll sync if the TR is available.
     1102        TComDataCU *pcCUUp = rpcPic->getCU( uiCUAddr )->getCUAbove();
     1103        UInt uiWidthInCU = rpcPic->getFrameWidthInCU();
     1104        UInt uiMaxParts = 1<<(pcSlice->getSPS()->getMaxCUDepth()<<1);
     1105        TComDataCU *pcCUTR = NULL;
     1106#if WPP_SIMPLIFICATION
     1107        if ( pcCUUp && ((uiCUAddr%uiWidthInCU+1) < uiWidthInCU)  )
     1108        {
     1109          pcCUTR = rpcPic->getCU( uiCUAddr - uiWidthInCU + 1 );
     1110        }
     1111#else
     1112        if ( pcCUUp && ((uiCUAddr%uiWidthInCU+pcSlice->getPPS()->getEntropyCodingSynchro()) < uiWidthInCU)  )
     1113        {
     1114          pcCUTR = rpcPic->getCU( uiCUAddr - uiWidthInCU + pcSlice->getPPS()->getEntropyCodingSynchro() );
     1115        }
     1116#endif
     1117        if ( (true/*bEnforceSliceRestriction*/ &&
     1118             ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
     1119             (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getSliceCurStartCUAddr()) ||
     1120#if !REMOVE_TILE_DEPENDENCE
     1121             (rpcPic->getPicSym()->getTileBoundaryIndependenceIdr() && (rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
     1122#else
     1123             ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
     1124#endif
     1125             ))||
     1126             (true/*bEnforceEntropySliceRestriction*/ &&
     1127             ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
     1128             (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getEntropySliceCurStartCUAddr()) ||
     1129#if !REMOVE_TILE_DEPENDENCE
     1130             (rpcPic->getPicSym()->getTileBoundaryIndependenceIdr() && (rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
     1131#else
     1132             ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
     1133#endif
     1134             ))
     1135           )
     1136        {
     1137          // TR not available.
     1138        }
     1139        else
     1140        {
     1141          // TR is available, we use it.
     1142          pcSbacCoders[uiSubStrm].loadContexts( &m_pcBufferSbacCoders[uiTileCol] );
     1143        }
     1144      }
     1145      m_pcSbacCoder->load(&pcSbacCoders[uiSubStrm]);  //this load is used to simplify the code (avoid to change all the call to m_pcSbacCoder)
     1146    }
     1147    // reset the entropy coder
     1148    if( uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr() &&                                   // must be first CU of tile
     1149        uiCUAddr!=0 &&                                                                                                                                    // cannot be first CU of picture
     1150        uiCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceCurStartCUAddr())/rpcPic->getNumPartInCU())     // cannot be first CU of slice
     1151    {
     1152      Int iTileIdx            = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr);
     1153      Bool bWriteTileMarker   = false;
     1154      // check if current iTileIdx should have a marker
     1155      for (Int iEntryIdx=0; iEntryIdx<m_pcCfg->getMaxTileMarkerEntryPoints()-1; iEntryIdx++)
     1156      {
     1157        bWriteTileMarker = ( (((Int)((iEntryIdx+1)*m_pcCfg->getMaxTileMarkerOffset()+0.5)) == iTileIdx ) && iEntryIdx < (m_pcCfg->getMaxTileMarkerEntryPoints()-1)) ? true : false;
     1158        if (bWriteTileMarker)
     1159        {
     1160          break;
     1161        }
     1162      }
     1163      {
     1164        // We're crossing into another tile, tiles are independent.
     1165        // When tiles are independent, we have "substreams per tile".  Each substream has already been terminated, and we no longer
     1166        // have to perform it here.
     1167#if WPP_SIMPLIFICATION
     1168        if (pcSlice->getPPS()->getNumSubstreams() > 1)
     1169#else
     1170        if (pcSlice->getPPS()->getEntropyCodingSynchro())
     1171#endif
     1172        {
     1173          ; // do nothing.
     1174        }
     1175        else
     1176        {
     1177#if CABAC_INIT_FLAG
     1178          SliceType sliceType  = pcSlice->getSliceType();
     1179          if (!pcSlice->isIntra() && pcSlice->getPPS()->getCabacInitPresentFlag() && pcSlice->getPPS()->getEncCABACTableIdx()!=0)
     1180          {
     1181            sliceType = (SliceType) pcSlice->getPPS()->getEncCABACTableIdx();
     1182          }
     1183          m_pcEntropyCoder->updateContextTables( sliceType, pcSlice->getSliceQp() );
     1184#else
     1185          m_pcEntropyCoder->updateContextTables( pcSlice->getSliceType(), pcSlice->getSliceQp() );
     1186#endif
     1187          pcSubstreams[uiSubStrm].write( 1, 1 );
     1188          pcSubstreams[uiSubStrm].writeAlignZero();
     1189        }
     1190      }
     1191      {
     1192        // Write TileMarker into the appropriate substream (nothing has been written to it yet).
     1193        if (m_pcCfg->getTileMarkerFlag() && bWriteTileMarker)
     1194        {
     1195          // Log locations where tile markers are to be inserted during emulation prevention
     1196          UInt uiMarkerCount = pcSubstreams[uiSubStrm].getTileMarkerLocationCount();
     1197          pcSubstreams[uiSubStrm].setTileMarkerLocation     ( uiMarkerCount, pcSubstreams[uiSubStrm].getNumberOfWrittenBits() >> 3 );
     1198          pcSubstreams[uiSubStrm].setTileMarkerLocationCount( uiMarkerCount + 1 );
     1199          // Write tile index
     1200          m_pcEntropyCoder->writeTileMarker(iTileIdx, rpcPic->getPicSym()->getBitsUsedByTileIdx()); // Tile index
     1201        }
     1202
     1203       
     1204        UInt uiAccumulatedSubstreamLength = 0;
     1205        for (Int iSubstrmIdx=0; iSubstrmIdx < iNumSubstreams; iSubstrmIdx++)
     1206        {
     1207          uiAccumulatedSubstreamLength += pcSubstreams[iSubstrmIdx].getNumberOfWrittenBits();
     1208        }
     1209        UInt uiLocationCount = pcSlice->getTileLocationCount();
     1210        // add bits coded in previous entropy slices + bits coded so far
     1211        pcSlice->setTileLocation( uiLocationCount, (pcSlice->getTileOffstForMultES() + uiAccumulatedSubstreamLength - uiBitsOriginallyInSubstreams) >> 3 );
     1212        pcSlice->setTileLocationCount( uiLocationCount + 1 );
     1213      }
     1214    }
     1215
     1216    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );   
     1217#if !REMOVE_TILE_DEPENDENCE
     1218    if( (rpcPic->getPicSym()->getTileBoundaryIndependenceIdr()==0) && (rpcPic->getPicSym()->getNumColumnsMinus1()!=0) )
     1219    {   
     1220      // Synchronize cabac probabilities with LCU among Tiles
     1221      if( (uiTileLCUX != 0) &&
     1222          (uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr()) )
     1223      {
     1224        TComDataCU *pcCULeft = pcCU->getCULeft();
     1225        UInt uiMaxParts = 1<<(pcSlice->getSPS()->getMaxCUDepth()<<1);
     1226
     1227        if ( (true/*bEnforceSliceRestriction*/ &&
     1228              ((pcCULeft==NULL) || (pcCULeft->getSlice()==NULL) ||
     1229               ((pcCULeft->getSCUAddr()+uiMaxParts-1) < pcSlice->getSliceCurStartCUAddr())
     1230              )
     1231             )||
     1232             (true/*bEnforceEntropySliceRestriction*/ &&
     1233              ((pcCULeft==NULL) || (pcCULeft->getSlice()==NULL) ||
     1234               ((pcCULeft->getSCUAddr()+uiMaxParts-1) < pcSlice->getEntropySliceCurStartCUAddr())
     1235              )
     1236             )
     1237           )
     1238        {
     1239          // Left not available.
     1240        }
     1241        else
     1242        {
     1243          // Left is available, we use it.
     1244          pcSbacCoders[uiSubStrm].loadContexts( &m_pcBufferLowLatSbacCoders[uiTileCol-1] );
     1245          m_pcSbacCoder->loadContexts(&pcSbacCoders[uiSubStrm]);  //this load is used to simplify the code (avoid to change all the call to m_pcSbacCoder)
     1246        }
     1247      }
     1248    }
     1249#endif
     1250
     1251#if SAO_UNIT_INTERLEAVING
     1252    if ( pcSlice->getSPS()->getUseSAO() && pcSlice->getAPS()->getSaoInterleavingFlag() && pcSlice->getSaoEnabledFlag() )
     1253    {
     1254      Int iNumCuInWidth     = pcSlice->getAPS()->getSaoParam()->numCuInWidth;
     1255      Int iCUAddrInSlice    = uiCUAddr - (pcSlice->getSliceCurStartCUAddr() /rpcPic->getNumPartInCU());
     1256      Int iCUAddrUpInSlice  = iCUAddrInSlice - iNumCuInWidth;
     1257      Int rx = uiCUAddr % iNumCuInWidth;
     1258      Int ry = uiCUAddr / iNumCuInWidth;
     1259      m_pcEntropyCoder->encodeSaoUnitInterleaving( rx, ry, pcSlice->getAPS()->getSaoParam(),pcCU, iCUAddrInSlice, iCUAddrUpInSlice, pcSlice->getSPS()->getLFCrossSliceBoundaryFlag());
     1260    }
     1261#endif
    6231262#if ENC_DEC_TRACE
    6241263    g_bJustDoIt = g_bEncDecTraceEnable;
    6251264#endif
    626     if ( (m_pcCfg->getSliceMode()!=0 || m_pcCfg->getEntropySliceMode()!=0) && uiCUAddr==uiBoundingCUAddr-1 )
     1265    if ( (m_pcCfg->getSliceMode()!=0 || m_pcCfg->getEntropySliceMode()!=0) &&
     1266      uiCUAddr == rpcPic->getPicSym()->getCUOrderMap((uiBoundingCUAddr+rpcPic->getNumPartInCU()-1)/rpcPic->getNumPartInCU()-1) )
    6271267    {
    6281268      m_pcCuEncoder->encodeCU( pcCU, true );
     
    6341274#if ENC_DEC_TRACE
    6351275    g_bJustDoIt = g_bEncDecTraceDisable;
    636 #endif
    637   }
     1276#endif   
     1277    if( m_pcCfg->getUseSBACRD() )
     1278    {
     1279       pcSbacCoders[uiSubStrm].load(m_pcSbacCoder);   //load back status of the entropy coder after encoding the LCU into relevant bitstream entropy coder
     1280       
     1281
     1282       //Store probabilties of second LCU in line into buffer
     1283#if WPP_SIMPLIFICATION
     1284      if (pcSlice->getPPS()->getNumSubstreams() > 1 && (uiCol == uiTileLCUX+1))
     1285#else
     1286      if (pcSlice->getPPS()->getEntropyCodingSynchro() && (uiCol == uiTileLCUX+pcSlice->getPPS()->getEntropyCodingSynchro()))
     1287#endif
     1288      {
     1289        m_pcBufferSbacCoders[uiTileCol].loadContexts( &pcSbacCoders[uiSubStrm] );
     1290      }
     1291    }
     1292#if !REMOVE_TILE_DEPENDENCE
     1293    if( (rpcPic->getPicSym()->getTileBoundaryIndependenceIdr()==0) && (rpcPic->getPicSym()->getNumColumnsMinus1()!=0) )
     1294    {
     1295      pcSbacCoders[uiSubStrm].load(m_pcSbacCoder);   //load back status of the entropy coder after encoding the LCU into relevant bitstream entropy coder
     1296       //Store probabilties for next tile
     1297      if( (uiLin == (rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr() / uiWidthInLCUs )) &&
     1298          (uiCol == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getRightEdgePosInCU()) )
     1299      {
     1300        m_pcBufferLowLatSbacCoders[uiTileCol].loadContexts( &pcSbacCoders[uiSubStrm] );
     1301      }
     1302    }
     1303#endif
     1304  }
     1305
     1306#if ADAPTIVE_QP_SELECTION
     1307  if( m_pcCfg->getUseAdaptQpSelect() )
     1308  {
     1309    m_pcTrQuant->storeSliceQpNext(pcSlice);
     1310  }
     1311#endif
     1312#if CABAC_INIT_FLAG
     1313  if (pcSlice->getPPS()->getCabacInitPresentFlag())
     1314  {
     1315    m_pcEntropyCoder->determineCabacInitIdx();
     1316  }
     1317#endif
    6381318}
    6391319
     
    6461326  TComSlice* pcSlice = rpcPic->getSlice(getSliceIdx());
    6471327  UInt uiStartCUAddrSlice, uiBoundingCUAddrSlice;
     1328#if FIXED_NUMBER_OF_TILES_SLICE_MODE
     1329  UInt tileIdxIncrement;
     1330  UInt tileIdx;
     1331  UInt tileWidthInLcu;
     1332  UInt tileHeightInLcu;
     1333  UInt tileTotalCount;
     1334#endif
     1335
    6481336  uiStartCUAddrSlice        = pcSlice->getSliceCurStartCUAddr();
    6491337  UInt uiNumberOfCUsInFrame = rpcPic->getNumCUsInFrame();
    6501338  uiBoundingCUAddrSlice     = uiNumberOfCUsInFrame;
    651   if (bEncodeSlice)
     1339  if (bEncodeSlice) 
    6521340  {
    6531341    UInt uiCUAddrIncrement;
     
    6561344    case AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE:
    6571345      uiCUAddrIncrement        = m_pcCfg->getSliceArgument();
    658       uiBoundingCUAddrSlice    = ((uiStartCUAddrSlice + uiCUAddrIncrement     ) < uiNumberOfCUsInFrame ) ? (uiStartCUAddrSlice + uiCUAddrIncrement     ) : uiNumberOfCUsInFrame;
     1346      uiBoundingCUAddrSlice    = ((uiStartCUAddrSlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU()) ? (uiStartCUAddrSlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    6591347      break;
    6601348    case AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE:
     
    6621350      uiBoundingCUAddrSlice    = pcSlice->getSliceCurEndCUAddr();
    6631351      break;
     1352#if FIXED_NUMBER_OF_TILES_SLICE_MODE
     1353    case AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE:
     1354      tileIdx                = rpcPic->getPicSym()->getTileIdxMap(
     1355        rpcPic->getPicSym()->getCUOrderMap(uiStartCUAddrSlice/rpcPic->getNumPartInCU())
     1356        );
     1357      uiCUAddrIncrement        = 0;
     1358      tileTotalCount         = (rpcPic->getPicSym()->getNumColumnsMinus1()+1) * (rpcPic->getPicSym()->getNumRowsMinus1()+1);
     1359
     1360      for(tileIdxIncrement = 0; tileIdxIncrement < m_pcCfg->getSliceArgument(); tileIdxIncrement++)
     1361      {
     1362        if((tileIdx + tileIdxIncrement) < tileTotalCount)
     1363        {
     1364          tileWidthInLcu   = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileWidth();
     1365          tileHeightInLcu  = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileHeight();
     1366          uiCUAddrIncrement += (tileWidthInLcu * tileHeightInLcu * rpcPic->getNumPartInCU()) >> (m_pcCfg->getSliceGranularity() << 1);
     1367        }
     1368      }
     1369
     1370      uiBoundingCUAddrSlice    = ((uiStartCUAddrSlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU()) ? (uiStartCUAddrSlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
     1371      break;
     1372#endif
    6641373    default:
    6651374      uiCUAddrIncrement        = rpcPic->getNumCUsInFrame();
    666       uiBoundingCUAddrSlice    = uiNumberOfCUsInFrame;
     1375      uiBoundingCUAddrSlice    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    6671376      break;
    668     }
     1377    } 
    6691378    pcSlice->setSliceCurEndCUAddr( uiBoundingCUAddrSlice );
    6701379  }
     
    6761385    case AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE:
    6771386      uiCUAddrIncrement        = m_pcCfg->getSliceArgument();
    678       uiBoundingCUAddrSlice    = ((uiStartCUAddrSlice + uiCUAddrIncrement     ) < uiNumberOfCUsInFrame ) ? (uiStartCUAddrSlice + uiCUAddrIncrement     ) : uiNumberOfCUsInFrame;
     1387      uiBoundingCUAddrSlice    = ((uiStartCUAddrSlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU()) ? (uiStartCUAddrSlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    6791388      break;
     1389#if FIXED_NUMBER_OF_TILES_SLICE_MODE
     1390    case AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE:
     1391      tileIdx                = rpcPic->getPicSym()->getTileIdxMap(
     1392        rpcPic->getPicSym()->getCUOrderMap(uiStartCUAddrSlice/rpcPic->getNumPartInCU())
     1393        );
     1394      uiCUAddrIncrement        = 0;
     1395      tileTotalCount         = (rpcPic->getPicSym()->getNumColumnsMinus1()+1) * (rpcPic->getPicSym()->getNumRowsMinus1()+1);
     1396
     1397      for(tileIdxIncrement = 0; tileIdxIncrement < m_pcCfg->getSliceArgument(); tileIdxIncrement++)
     1398      {
     1399        if((tileIdx + tileIdxIncrement) < tileTotalCount)
     1400        {
     1401          tileWidthInLcu   = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileWidth();
     1402          tileHeightInLcu  = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileHeight();
     1403          uiCUAddrIncrement += (tileWidthInLcu * tileHeightInLcu * rpcPic->getNumPartInCU()) >> (m_pcCfg->getSliceGranularity() << 1);
     1404        }
     1405      }
     1406
     1407      uiBoundingCUAddrSlice    = ((uiStartCUAddrSlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU()) ? (uiStartCUAddrSlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
     1408      break;
     1409#endif
    6801410    default:
    6811411      uiCUAddrIncrement        = rpcPic->getNumCUsInFrame();
    682       uiBoundingCUAddrSlice    = uiNumberOfCUsInFrame;
     1412      uiBoundingCUAddrSlice    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    6831413      break;
    684     }
     1414    } 
    6851415    pcSlice->setSliceCurEndCUAddr( uiBoundingCUAddrSlice );
    6861416  }
     1417
     1418#if COMPLETE_SLICES_IN_TILE
     1419  Bool tileBoundary = false;
     1420  if ((m_pcCfg->getSliceMode() == AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE || m_pcCfg->getSliceMode() == AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE) &&
     1421      (m_pcCfg->getNumRowsMinus1() > 0 || m_pcCfg->getNumColumnsMinus1() > 0))
     1422  {
     1423    UInt lcuEncAddr = (uiStartCUAddrSlice+rpcPic->getNumPartInCU()-1)/rpcPic->getNumPartInCU();
     1424    UInt lcuAddr = rpcPic->getPicSym()->getCUOrderMap(lcuEncAddr);
     1425    UInt startTileIdx = rpcPic->getPicSym()->getTileIdxMap(lcuAddr);
     1426    UInt tileBoundingCUAddrSlice = 0;
     1427    while (lcuEncAddr < uiNumberOfCUsInFrame && rpcPic->getPicSym()->getTileIdxMap(lcuAddr) == startTileIdx)
     1428    {
     1429      lcuEncAddr++;
     1430      lcuAddr = rpcPic->getPicSym()->getCUOrderMap(lcuEncAddr);
     1431    }
     1432    tileBoundingCUAddrSlice = lcuEncAddr*rpcPic->getNumPartInCU();
     1433   
     1434    if (tileBoundingCUAddrSlice < uiBoundingCUAddrSlice)
     1435    {
     1436      uiBoundingCUAddrSlice = tileBoundingCUAddrSlice;
     1437      pcSlice->setSliceCurEndCUAddr( uiBoundingCUAddrSlice );
     1438      tileBoundary = true;
     1439    }
     1440  }
     1441#endif
    6871442
    6881443  // Entropy slice
     
    6901445  uiStartCUAddrEntropySlice    = pcSlice->getEntropySliceCurStartCUAddr();
    6911446  uiBoundingCUAddrEntropySlice = uiNumberOfCUsInFrame;
    692   if (bEncodeSlice)
     1447  if (bEncodeSlice) 
    6931448  {
    6941449    UInt uiCUAddrIncrement;
     
    6971452    case SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE:
    6981453      uiCUAddrIncrement               = m_pcCfg->getEntropySliceArgument();
    699       uiBoundingCUAddrEntropySlice    = ((uiStartCUAddrEntropySlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame ) ? (uiStartCUAddrEntropySlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame;
     1454      uiBoundingCUAddrEntropySlice    = ((uiStartCUAddrEntropySlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU() ) ? (uiStartCUAddrEntropySlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    7001455      break;
    7011456    case SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE:
     
    7051460    default:
    7061461      uiCUAddrIncrement               = rpcPic->getNumCUsInFrame();
    707       uiBoundingCUAddrEntropySlice    = uiNumberOfCUsInFrame;
     1462      uiBoundingCUAddrEntropySlice    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    7081463      break;
    709     }
     1464    } 
    7101465    pcSlice->setEntropySliceCurEndCUAddr( uiBoundingCUAddrEntropySlice );
    7111466  }
     
    7171472    case SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE:
    7181473      uiCUAddrIncrement               = m_pcCfg->getEntropySliceArgument();
    719       uiBoundingCUAddrEntropySlice    = ((uiStartCUAddrEntropySlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame ) ? (uiStartCUAddrEntropySlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame;
     1474      uiBoundingCUAddrEntropySlice    = ((uiStartCUAddrEntropySlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU() ) ? (uiStartCUAddrEntropySlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    7201475      break;
    7211476    default:
    7221477      uiCUAddrIncrement               = rpcPic->getNumCUsInFrame();
    723       uiBoundingCUAddrEntropySlice    = uiNumberOfCUsInFrame;
     1478      uiBoundingCUAddrEntropySlice    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    7241479      break;
    725     }
     1480    } 
    7261481    pcSlice->setEntropySliceCurEndCUAddr( uiBoundingCUAddrEntropySlice );
    7271482  }
    728 
     1483  if(uiBoundingCUAddrEntropySlice>uiBoundingCUAddrSlice)
     1484  {
     1485    uiBoundingCUAddrEntropySlice = uiBoundingCUAddrSlice;
     1486    pcSlice->setEntropySliceCurEndCUAddr(uiBoundingCUAddrSlice);
     1487  }
     1488  //calculate real entropy slice start address
     1489  UInt uiInternalAddress = rpcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurStartCUAddr()) % rpcPic->getNumPartInCU();
     1490  UInt uiExternalAddress = rpcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurStartCUAddr()) / rpcPic->getNumPartInCU();
     1491  UInt uiPosX = ( uiExternalAddress % rpcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
     1492  UInt uiPosY = ( uiExternalAddress / rpcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
     1493  UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
     1494  UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
     1495  while((uiPosX>=uiWidth||uiPosY>=uiHeight)&&!(uiPosX>=uiWidth&&uiPosY>=uiHeight))
     1496  {
     1497    uiInternalAddress++;
     1498    if(uiInternalAddress>=rpcPic->getNumPartInCU())
     1499    {
     1500      uiInternalAddress=0;
     1501      uiExternalAddress = rpcPic->getPicSym()->getCUOrderMap(rpcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1);
     1502    }
     1503    uiPosX = ( uiExternalAddress % rpcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
     1504    uiPosY = ( uiExternalAddress / rpcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
     1505  }
     1506  UInt uiRealStartAddress = rpcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*rpcPic->getNumPartInCU()+uiInternalAddress);
     1507 
     1508  pcSlice->setEntropySliceCurStartCUAddr(uiRealStartAddress);
     1509  uiStartCUAddrEntropySlice=uiRealStartAddress;
     1510 
     1511  //calculate real slice start address
     1512  uiInternalAddress = rpcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceCurStartCUAddr()) % rpcPic->getNumPartInCU();
     1513  uiExternalAddress = rpcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceCurStartCUAddr()) / rpcPic->getNumPartInCU();
     1514  uiPosX = ( uiExternalAddress % rpcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
     1515  uiPosY = ( uiExternalAddress / rpcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
     1516  uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
     1517  uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
     1518  while((uiPosX>=uiWidth||uiPosY>=uiHeight)&&!(uiPosX>=uiWidth&&uiPosY>=uiHeight))
     1519  {
     1520    uiInternalAddress++;
     1521    if(uiInternalAddress>=rpcPic->getNumPartInCU())
     1522    {
     1523      uiInternalAddress=0;
     1524      uiExternalAddress = rpcPic->getPicSym()->getCUOrderMap(rpcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1);
     1525    }
     1526    uiPosX = ( uiExternalAddress % rpcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
     1527    uiPosY = ( uiExternalAddress / rpcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
     1528  }
     1529  uiRealStartAddress = rpcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*rpcPic->getNumPartInCU()+uiInternalAddress);
     1530 
     1531  pcSlice->setSliceCurStartCUAddr(uiRealStartAddress);
     1532  uiStartCUAddrSlice=uiRealStartAddress;
     1533 
    7291534  // Make a joint decision based on reconstruction and entropy slice bounds
    7301535  uiStartCUAddr    = max(uiStartCUAddrSlice   , uiStartCUAddrEntropySlice   );
     
    7381543    if ( (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE && m_pcCfg->getEntropySliceMode()==SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE)
    7391544      || (m_pcCfg->getSliceMode()==0 && m_pcCfg->getEntropySliceMode()==SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE)
    740       || (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE && m_pcCfg->getEntropySliceMode()==0) )
     1545      || (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE && m_pcCfg->getEntropySliceMode()==0)
     1546#if FIXED_NUMBER_OF_TILES_SLICE_MODE
     1547      || (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE && m_pcCfg->getEntropySliceMode()==SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE)
     1548      || (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE && m_pcCfg->getEntropySliceMode()==0)
     1549#endif
     1550#if COMPLETE_SLICES_IN_TILE
     1551      || tileBoundary
     1552#endif
     1553)
    7411554    {
    7421555      if (uiBoundingCUAddrSlice < uiBoundingCUAddrEntropySlice)
     
    7631576  }
    7641577}
     1578//! \}
Note: See TracChangeset for help on using the changeset viewer.