HEVC Test Model (HM)  HM-16.3
TEncSlice.cpp
Go to the documentation of this file.
1 /* The copyright in this software is being made available under the BSD
2  * License, included below. This software may be subject to other third party
3  * and contributor rights, including patent rights, and no such rights are
4  * granted under this license.
5  *
6  * Copyright (c) 2010-2015, ITU/ISO/IEC
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18  * be used to endorse or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
38 #include "TEncTop.h"
39 #include "TEncSlice.h"
40 #include <math.h>
41 
44 
45 // ====================================================================================================================
46 // Constructor / destructor / create / destroy
47 // ====================================================================================================================
48 
50  : m_encCABACTableIdx(I_SLICE)
51 {
54 
56  m_pdRdPicQp = NULL;
57  m_piRdPicQp = NULL;
58 }
59 
61 {
62 }
63 
64 Void TEncSlice::create( Int iWidth, Int iHeight, ChromaFormat chromaFormat, UInt iMaxCUWidth, UInt iMaxCUHeight, UChar uhTotalDepth )
65 {
66  // create prediction picture
67  if ( m_apcPicYuvPred == NULL )
68  {
70  m_apcPicYuvPred->create( iWidth, iHeight, chromaFormat, iMaxCUWidth, iMaxCUHeight, uhTotalDepth );
71  }
72 
73  // create residual picture
74  if( m_apcPicYuvResi == NULL )
75  {
77  m_apcPicYuvResi->create( iWidth, iHeight, chromaFormat, iMaxCUWidth, iMaxCUHeight, uhTotalDepth );
78  }
79 }
80 
82 {
83  // destroy prediction picture
84  if ( m_apcPicYuvPred )
85  {
87  delete m_apcPicYuvPred;
89  }
90 
91  // destroy residual picture
92  if ( m_apcPicYuvResi )
93  {
95  delete m_apcPicYuvResi;
97  }
98 
99  // free lambda and QP arrays
100  if ( m_pdRdPicLambda )
101  {
104  }
105  if ( m_pdRdPicQp )
106  {
107  xFree( m_pdRdPicQp );
108  m_pdRdPicQp = NULL;
109  }
110  if ( m_piRdPicQp )
111  {
112  xFree( m_piRdPicQp );
113  m_piRdPicQp = NULL;
114  }
115 }
116 
118 {
119  m_pcCfg = pcEncTop;
120  m_pcListPic = pcEncTop->getListPic();
121 
122  m_pcGOPEncoder = pcEncTop->getGOPEncoder();
123  m_pcCuEncoder = pcEncTop->getCuEncoder();
124  m_pcPredSearch = pcEncTop->getPredSearch();
125 
126  m_pcEntropyCoder = pcEncTop->getEntropyCoder();
127  m_pcSbacCoder = pcEncTop->getSbacCoder();
128  m_pcBinCABAC = pcEncTop->getBinCABAC();
129  m_pcTrQuant = pcEncTop->getTrQuant();
130 
131  m_pcRdCost = pcEncTop->getRdCost();
132  m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder();
134 
135  // create lambda and QP arrays
138  m_piRdPicQp = (Int* )xMalloc( Int, m_pcCfg->getDeltaQpRD() * 2 + 1 );
139  m_pcRateCtrl = pcEncTop->getRateCtrl();
140 }
141 
142 
143 
144 Void
145 TEncSlice::setUpLambda(TComSlice* slice, const Double dLambda, Int iQP)
146 {
147  // store lambda
148  m_pcRdCost ->setLambda( dLambda );
149 
150  // for RDO
151  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
152  Double dLambdas[MAX_NUM_COMPONENT] = { dLambda };
153  for(UInt compIdx=1; compIdx<MAX_NUM_COMPONENT; compIdx++)
154  {
155  const ComponentID compID=ComponentID(compIdx);
156  Int chromaQPOffset = slice->getPPS()->getQpOffset(compID) + slice->getSliceChromaQpDelta(compID);
157  Int qpc=(iQP + chromaQPOffset < 0) ? iQP : getScaledChromaQP(iQP + chromaQPOffset, m_pcCfg->getChromaFormatIdc());
158  Double tmpWeight = pow( 2.0, (iQP-qpc)/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset
159  m_pcRdCost->setDistortionWeight(compID, tmpWeight);
160  dLambdas[compIdx]=dLambda/tmpWeight;
161  }
162 
163 #if RDOQ_CHROMA_LAMBDA
164 // for RDOQ
165  m_pcTrQuant->setLambdas( dLambdas );
166 #else
167  m_pcTrQuant->setLambda( dLambda );
168 #endif
169 
170 // For SAO
171  slice ->setLambdas( dLambdas );
172 }
173 
174 
175 
193 Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, const TComSPS* pSPS, const TComPPS *pPPS, Bool isField )
194 {
195  Double dQP;
196  Double dLambda;
197 
198  rpcSlice = pcPic->getSlice(0);
199  rpcSlice->setSliceBits(0);
200  rpcSlice->setPic( pcPic );
201  rpcSlice->initSlice();
202  rpcSlice->setPicOutputFlag( true );
203  rpcSlice->setPOC( pocCurr );
204 
205  // depth computation based on GOP size
206  Int depth;
207  {
208  Int poc = rpcSlice->getPOC();
209  if(isField)
210  {
211  poc = (poc/2) % (m_pcCfg->getGOPSize()/2);
212  }
213  else
214  {
215  poc = poc % m_pcCfg->getGOPSize();
216  }
217 
218  if ( poc == 0 )
219  {
220  depth = 0;
221  }
222  else
223  {
224  Int step = m_pcCfg->getGOPSize();
225  depth = 0;
226  for( Int i=step>>1; i>=1; i>>=1 )
227  {
228  for ( Int j=i; j<m_pcCfg->getGOPSize(); j+=step )
229  {
230  if ( j == poc )
231  {
232  i=0;
233  break;
234  }
235  }
236  step >>= 1;
237  depth++;
238  }
239  }
240 
241 #if HARMONIZE_GOP_FIRST_FIELD_COUPLE
242  if(poc != 0)
243  {
244 #endif
245  if (isField && ((rpcSlice->getPOC() % 2) == 1))
246  {
247  depth ++;
248  }
249 #if HARMONIZE_GOP_FIRST_FIELD_COUPLE
250  }
251 #endif
252  }
253 
254  // slice type
255  SliceType eSliceType;
256 
257  eSliceType=B_SLICE;
258 #if EFFICIENT_FIELD_IRAP
259  if(!(isField && pocLast == 1))
260  {
261 #endif // EFFICIENT_FIELD_IRAP
262 #if ALLOW_RECOVERY_POINT_AS_RAP
263  if(m_pcCfg->getDecodingRefreshType() == 3)
264  {
265  eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
266  }
267  else
268  {
269 #endif
270  eSliceType = (pocLast == 0 || (pocCurr - (isField ? 1 : 0)) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
271 #if ALLOW_RECOVERY_POINT_AS_RAP
272  }
273 #endif
274 #if EFFICIENT_FIELD_IRAP
275  }
276 #endif
277 
278  rpcSlice->setSliceType ( eSliceType );
279 
280  // ------------------------------------------------------------------------------------------------------------------
281  // Non-referenced frame marking
282  // ------------------------------------------------------------------------------------------------------------------
283 
284  if(pocLast == 0)
285  {
286  rpcSlice->setTemporalLayerNonReferenceFlag(false);
287  }
288  else
289  {
291  }
292  rpcSlice->setReferenced(true);
293 
294  // ------------------------------------------------------------------------------------------------------------------
295  // QP setting
296  // ------------------------------------------------------------------------------------------------------------------
297 
298  dQP = m_pcCfg->getQP();
299  if(eSliceType!=I_SLICE)
300  {
301  if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA) ) && (rpcSlice->getPPS()->getTransquantBypassEnableFlag())))
302  {
303  dQP += m_pcCfg->getGOPEntry(iGOPid).m_QPOffset;
304  }
305  }
306 
307  // modify QP
308  Int* pdQPs = m_pcCfg->getdQPs();
309  if ( pdQPs )
310  {
311  dQP += pdQPs[ rpcSlice->getPOC() ];
312  }
313 
315  {
317  m_pcCfg->setDeltaQpRD(0);
318  }
319 
320  // ------------------------------------------------------------------------------------------------------------------
321  // Lambda computation
322  // ------------------------------------------------------------------------------------------------------------------
323 
324  Int iQP;
325  Double dOrigQP = dQP;
326 
327  // pre-compute lambda and QP values for all possible QP candidates
328  for ( Int iDQpIdx = 0; iDQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; iDQpIdx++ )
329  {
330  // compute QP value
331  dQP = dOrigQP + ((iDQpIdx+1)>>1)*(iDQpIdx%2 ? -1 : 1);
332 
333  // compute lambda value
334  Int NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
335  Int SHIFT_QP = 12;
336 
337  Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)(isField ? NumberBFrames/2 : NumberBFrames) );
338 
339 #if FULL_NBIT
340  Int bitdepth_luma_qp_scale = 6 * (g_bitDepth[CHANNEL_TYPE_LUMA] - 8);
341 #else
342  Int bitdepth_luma_qp_scale = 0;
343 #endif
344  Double qp_temp = (Double) dQP + bitdepth_luma_qp_scale - SHIFT_QP;
345 #if FULL_NBIT
346  Double qp_temp_orig = (Double) dQP - SHIFT_QP;
347 #endif
348  // Case #1: I or P-slices (key-frame)
349  Double dQPFactor = m_pcCfg->getGOPEntry(iGOPid).m_QPFactor;
350  if ( eSliceType==I_SLICE )
351  {
352  dQPFactor=0.57*dLambda_scale;
353  }
354  dLambda = dQPFactor*pow( 2.0, qp_temp/3.0 );
355 
356  if ( depth>0 )
357  {
358 #if FULL_NBIT
359  dLambda *= Clip3( 2.00, 4.00, (qp_temp_orig / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
360 #else
361  dLambda *= Clip3( 2.00, 4.00, (qp_temp / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
362 #endif
363  }
364 
365  // if hadamard is used in ME process
366  if ( !m_pcCfg->getUseHADME() && rpcSlice->getSliceType( ) != I_SLICE )
367  {
368  dLambda *= 0.95;
369  }
370 
371  iQP = max( -pSPS->getQpBDOffset(CHANNEL_TYPE_LUMA), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
372 
373  m_pdRdPicLambda[iDQpIdx] = dLambda;
374  m_pdRdPicQp [iDQpIdx] = dQP;
375  m_piRdPicQp [iDQpIdx] = iQP;
376  }
377 
378  // obtain dQP = 0 case
379  dLambda = m_pdRdPicLambda[0];
380  dQP = m_pdRdPicQp [0];
381  iQP = m_piRdPicQp [0];
382 
383  if( rpcSlice->getSliceType( ) != I_SLICE )
384  {
385  dLambda *= m_pcCfg->getLambdaModifier( m_pcCfg->getGOPEntry(iGOPid).m_temporalId );
386  }
387 
388  setUpLambda(rpcSlice, dLambda, iQP);
389 
390 #if HB_LAMBDA_FOR_LDC
391  // restore original slice type
392 
393 #if EFFICIENT_FIELD_IRAP
394  if(!(isField && pocLast == 1))
395  {
396 #endif // EFFICIENT_FIELD_IRAP
397 #if ALLOW_RECOVERY_POINT_AS_RAP
398  if(m_pcCfg->getDecodingRefreshType() == 3)
399  {
400  eSliceType = (pocLast == 0 || (pocCurr) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
401  }
402  else
403  {
404 #endif
405  eSliceType = (pocLast == 0 || (pocCurr - (isField ? 1 : 0)) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
406 #if ALLOW_RECOVERY_POINT_AS_RAP
407  }
408 #endif
409 #if EFFICIENT_FIELD_IRAP
410  }
411 #endif // EFFICIENT_FIELD_IRAP
412 
413  rpcSlice->setSliceType ( eSliceType );
414 #endif
415 
417  {
418  dQP = xGetQPValueAccordingToLambda( dLambda );
419  iQP = max( -pSPS->getQpBDOffset(CHANNEL_TYPE_LUMA), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
420  }
421 
422  rpcSlice->setSliceQp ( iQP );
423 #if ADAPTIVE_QP_SELECTION
424  rpcSlice->setSliceQpBase ( iQP );
425 #endif
426  rpcSlice->setSliceQpDelta ( 0 );
427  rpcSlice->setSliceChromaQpDelta( COMPONENT_Cb, 0 );
428  rpcSlice->setSliceChromaQpDelta( COMPONENT_Cr, 0 );
429  rpcSlice->setUseChromaQpAdj( pPPS->getChromaQpAdjTableSize() > 0 );
432 
434  {
435  rpcSlice->setDeblockingFilterOverrideFlag(true);
436  rpcSlice->setDeblockingFilterDisable(false);
437  rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
438  rpcSlice->setDeblockingFilterTcOffsetDiv2( 0 );
439  }
440  else if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
441  {
444  if ( !rpcSlice->getDeblockingFilterDisable())
445  {
446  if ( rpcSlice->getDeblockingFilterOverrideFlag() && eSliceType!=I_SLICE)
447  {
450  }
451  else
452  {
455  }
456  }
457  }
458  else
459  {
460  rpcSlice->setDeblockingFilterOverrideFlag( false );
461  rpcSlice->setDeblockingFilterDisable( false );
462  rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
463  rpcSlice->setDeblockingFilterTcOffsetDiv2( 0 );
464  }
465 
466  rpcSlice->setDepth ( depth );
467 
468  pcPic->setTLayer( m_pcCfg->getGOPEntry(iGOPid).m_temporalId );
469  if(eSliceType==I_SLICE)
470  {
471  pcPic->setTLayer(0);
472  }
473  rpcSlice->setTLayer( pcPic->getTLayer() );
474 
475  assert( m_apcPicYuvPred );
476  assert( m_apcPicYuvResi );
477 
478  pcPic->setPicYuvPred( m_apcPicYuvPred );
479  pcPic->setPicYuvResi( m_apcPicYuvResi );
480  rpcSlice->setSliceMode ( m_pcCfg->getSliceMode() );
481  rpcSlice->setSliceArgument ( m_pcCfg->getSliceArgument() );
485 }
486 
487 Void TEncSlice::resetQP( TComPic* pic, Int sliceQP, Double lambda )
488 {
489  TComSlice* slice = pic->getSlice(0);
490 
491  // store lambda
492  slice->setSliceQp( sliceQP );
493 #if ADAPTIVE_QP_SELECTION
494  slice->setSliceQpBase ( sliceQP );
495 #endif
496  setUpLambda(slice, lambda, sliceQP);
497 }
498 
499 // ====================================================================================================================
500 // Public member functions
501 // ====================================================================================================================
502 
504 {
505  Int iCurrPOC = pcSlice->getPOC();
506  Int iRefPOC;
507  Int iGOPSize = m_pcCfg->getGOPSize();
508  Int iOffset = (iGOPSize >> 1);
509  Int iMaxSR = m_pcCfg->getSearchRange();
510  Int iNumPredDir = pcSlice->isInterP() ? 1 : 2;
511 
512  for (Int iDir = 0; iDir <= iNumPredDir; iDir++)
513  {
514  //RefPicList e = (RefPicList)iDir;
515  RefPicList e = ( iDir ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
516  for (Int iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(e); iRefIdx++)
517  {
518  iRefPOC = pcSlice->getRefPic(e, iRefIdx)->getPOC();
519  Int iNewSR = Clip3(8, iMaxSR, (iMaxSR*ADAPT_SR_SCALE*abs(iCurrPOC - iRefPOC)+iOffset)/iGOPSize);
520  m_pcPredSearch->setAdaptiveSearchRange(iDir, iRefIdx, iNewSR);
521  }
522  }
523 }
524 
531 {
532  // if deltaQP RD is not used, simply return
533  if ( m_pcCfg->getDeltaQpRD() == 0 )
534  {
535  return;
536  }
537 
538  if ( m_pcCfg->getUseRateCtrl() )
539  {
540  printf( "\nMultiple QP optimization is not allowed when rate control is enabled." );
541  assert(0);
542  }
543 
544  TComSlice* pcSlice = pcPic->getSlice(getSliceIdx());
545  Double dPicRdCostBest = MAX_DOUBLE;
546  UInt uiQpIdxBest = 0;
547 
548  Double dFrameLambda;
549 #if FULL_NBIT
550  Int SHIFT_QP = 12 + 6 * (g_bitDepth[CHANNEL_TYPE_LUMA] - 8);
551 #else
552  Int SHIFT_QP = 12;
553 #endif
554 
555  // set frame lambda
556  if (m_pcCfg->getGOPSize() > 1)
557  {
558  dFrameLambda = 0.68 * pow (2, (m_piRdPicQp[0] - SHIFT_QP) / 3.0) * (pcSlice->isInterB()? 2 : 1);
559  }
560  else
561  {
562  dFrameLambda = 0.68 * pow (2, (m_piRdPicQp[0] - SHIFT_QP) / 3.0);
563  }
564  m_pcRdCost ->setFrameLambda(dFrameLambda);
565 
566  const UInt initialSliceQp=pcSlice->getSliceQp();
567  // for each QP candidate
568  for ( UInt uiQpIdx = 0; uiQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; uiQpIdx++ )
569  {
570  pcSlice ->setSliceQp ( m_piRdPicQp [uiQpIdx] );
571 #if ADAPTIVE_QP_SELECTION
572  pcSlice ->setSliceQpBase ( m_piRdPicQp [uiQpIdx] );
573 #endif
574  setUpLambda(pcSlice, m_pdRdPicLambda[uiQpIdx], m_piRdPicQp [uiQpIdx]);
575 
576  // try compress
577  compressSlice ( pcPic );
578 
579  Double dPicRdCost;
580  UInt64 uiPicDist = m_uiPicDist;
581  // TODO: will this work if multiple slices are being used? There may not be any reconstruction data yet.
582  // Will this also be ideal if a byte-restriction is placed on the slice?
583  // - what if the last CTU was sometimes included, sometimes not, and that had all the distortion?
584  m_pcGOPEncoder->preLoopFilterPicAll( pcPic, uiPicDist );
585 
586  // compute RD cost and choose the best
587  dPicRdCost = m_pcRdCost->calcRdCost64( m_uiPicTotalBits, uiPicDist, true, DF_SSE_FRAME);
588 
589  if ( dPicRdCost < dPicRdCostBest )
590  {
591  uiQpIdxBest = uiQpIdx;
592  dPicRdCostBest = dPicRdCost;
593  }
594  }
595 
596  if (pcSlice->getDependentSliceSegmentFlag() && initialSliceQp!=m_piRdPicQp[uiQpIdxBest] )
597  {
598  // TODO: this won't work with dependent slices: they do not have their own QP.
599  fprintf(stderr,"ERROR - attempt to change QP for a dependent slice-segment, having already coded the slice\n");
600  assert(pcSlice->getDependentSliceSegmentFlag()==false || initialSliceQp==m_piRdPicQp[uiQpIdxBest]);
601  }
602  // set best values
603  pcSlice ->setSliceQp ( m_piRdPicQp [uiQpIdxBest] );
604 #if ADAPTIVE_QP_SELECTION
605  pcSlice ->setSliceQpBase ( m_piRdPicQp [uiQpIdxBest] );
606 #endif
607  setUpLambda(pcSlice, m_pdRdPicLambda[uiQpIdxBest], m_piRdPicQp [uiQpIdxBest]);
608 }
609 
611 {
612  UInt ctuRsAddr;
613  UInt startCtuTsAddr;
614  UInt boundingCtuTsAddr;
615  Int iSumHad, shift = g_bitDepth[CHANNEL_TYPE_LUMA]-8, offset = (shift>0)?(1<<(shift-1)):0;;
616  Double iSumHadSlice = 0;
617 
619  TComSlice* pcSlice = pcPic->getSlice(getSliceIdx());
620  xDetermineStartAndBoundingCtuTsAddr ( startCtuTsAddr, boundingCtuTsAddr, pcPic, false );
621 
622  UInt ctuTsAddr;
623  ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap( startCtuTsAddr);
624  for( ctuTsAddr = startCtuTsAddr; ctuTsAddr < boundingCtuTsAddr; ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(++ctuTsAddr) )
625  {
626  // initialize CU encoder
627  TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr );
628  pCtu->initCtu( pcPic, ctuRsAddr );
629 
630  Int height = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - ctuRsAddr / pcPic->getFrameWidthInCtus() * pcSlice->getSPS()->getMaxCUHeight() );
631  Int width = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - ctuRsAddr % pcPic->getFrameWidthInCtus() * pcSlice->getSPS()->getMaxCUWidth() );
632 
633  iSumHad = m_pcCuEncoder->updateCtuDataISlice(pCtu, width, height);
634 
635  (m_pcRateCtrl->getRCPic()->getLCU(ctuRsAddr)).m_costIntra=(iSumHad+offset)>>shift;
636  iSumHadSlice += (m_pcRateCtrl->getRCPic()->getLCU(ctuRsAddr)).m_costIntra;
637 
638  }
639  m_pcRateCtrl->getRCPic()->setTotalIntraCost(iSumHadSlice);
640 }
641 
645 {
646  UInt startCtuTsAddr;
647  UInt boundingCtuTsAddr;
648  TComSlice* pcSlice = pcPic->getSlice(getSliceIdx());
649  pcSlice->setSliceSegmentBits(0);
650  xDetermineStartAndBoundingCtuTsAddr ( startCtuTsAddr, boundingCtuTsAddr, pcPic, false );
651 
652  // initialize cost values - these are used by precompressSlice (they should be parameters).
653  m_uiPicTotalBits = 0;
654  m_dPicRdCost = 0; // NOTE: This is a write-only variable!
655  m_uiPicDist = 0;
656 
659 
660  TEncBinCABAC* pRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf();
661  pRDSbacCoder->setBinCountingEnableFlag( false );
662  pRDSbacCoder->setBinsCoded( 0 );
663 
664  TComBitCounter tempBitCounter;
665  const UInt frameWidthInCtus = pcPic->getPicSym()->getFrameWidthInCtus();
666 
667  //------------------------------------------------------------------------------
668  // Weighted Prediction parameters estimation.
669  //------------------------------------------------------------------------------
670  // calculate AC/DC values for current picture
671  if( pcSlice->getPPS()->getUseWP() || pcSlice->getPPS()->getWPBiPred() )
672  {
673  xCalcACDCParamSlice(pcSlice);
674  }
675 
676  const Bool bWp_explicit = (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPred());
677 
678  if ( bWp_explicit )
679  {
680  //------------------------------------------------------------------------------
681  // Weighted Prediction implemented at Slice level. SliceMode=2 is not supported yet.
682  //------------------------------------------------------------------------------
684  {
685  printf("Weighted Prediction is not supported with slice mode determined by max number of bins.\n"); exit(0);
686  }
687 
688  xEstimateWPParamSlice( pcSlice );
689  pcSlice->initWpScaling(pcSlice->getSPS());
690 
691  // check WP on/off
692  xCheckWPEnable( pcSlice );
693  }
694 
695 #if ADAPTIVE_QP_SELECTION
697  {
698  // TODO: this won't work with dependent slices: they do not have their own QP. Check fix to mask clause execution with && !(pcSlice->getDependentSliceSegmentFlag())
700  if(pcSlice->getSliceType()!=I_SLICE)
701  {
702  Int qpBase = pcSlice->getSliceQpBase();
703  pcSlice->setSliceQp(qpBase + m_pcTrQuant->getQpDelta(qpBase));
704  }
705  }
706 #endif
707 
708 
709 
710  // Adjust initial state if this is the start of a dependent slice.
711  {
712  const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap( startCtuTsAddr);
713  const UInt currentTileIdx = pcPic->getPicSym()->getTileIdxMap(ctuRsAddr);
714  const TComTile *pCurrentTile = pcPic->getPicSym()->getTComTile(currentTileIdx);
715  const UInt firstCtuRsAddrOfTile = pCurrentTile->getFirstCtuRsAddr();
716  if( pcSlice->getDependentSliceSegmentFlag() && ctuRsAddr != firstCtuRsAddrOfTile )
717  {
718  // This will only occur if dependent slice-segments (m_entropyCodingSyncContextState=true) are being used.
719  if( pCurrentTile->getTileWidthInCtus() >= 2 || !m_pcCfg->getWaveFrontsynchro() )
720  {
722  }
723  }
724  }
725 
726  // for every CTU in the slice segment (may terminate sooner if there is a byte limit on the slice-segment)
727 
728  for( UInt ctuTsAddr = startCtuTsAddr; ctuTsAddr < boundingCtuTsAddr; ++ctuTsAddr )
729  {
730  const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddr);
731  // initialize CTU encoder
732  TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr );
733  pCtu->initCtu( pcPic, ctuRsAddr );
734 
735  // update CABAC state
736  const UInt firstCtuRsAddrOfTile = pcPic->getPicSym()->getTComTile(pcPic->getPicSym()->getTileIdxMap(ctuRsAddr))->getFirstCtuRsAddr();
737  const UInt tileXPosInCtus = firstCtuRsAddrOfTile % frameWidthInCtus;
738  const UInt ctuXPosInCtus = ctuRsAddr % frameWidthInCtus;
739 
740  if (ctuRsAddr == firstCtuRsAddrOfTile)
741  {
743  }
744  else if ( ctuXPosInCtus == tileXPosInCtus && m_pcCfg->getWaveFrontsynchro())
745  {
746  // reset and then update contexts to the state at the end of the top-right CTU (if within current slice and tile).
748  // Sync if the Top-Right is available.
749  TComDataCU *pCtuUp = pCtu->getCtuAbove();
750  if ( pCtuUp && ((ctuRsAddr%frameWidthInCtus+1) < frameWidthInCtus) )
751  {
752  TComDataCU *pCtuTR = pcPic->getCtu( ctuRsAddr - frameWidthInCtus + 1 );
753  if ( pCtu->CUIsFromSameSliceAndTile(pCtuTR) )
754  {
755  // Top-Right is available, we use it.
757  }
758  }
759  }
760 
761  // set go-on entropy coder (used for all trial encodings - the cu encoder and encoder search also have a copy of the same pointer)
763  m_pcEntropyCoder->setBitstream( &tempBitCounter );
764  tempBitCounter.resetBits();
765  m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] ); // this copy is not strictly necessary here, but indicates that the GoOnSbacCoder
766  // is reset to a known state before every decision process.
767 
768  ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true);
769 
770  Double oldLambda = m_pcRdCost->getLambda();
771  if ( m_pcCfg->getUseRateCtrl() )
772  {
773  Int estQP = pcSlice->getSliceQp();
774  Double estLambda = -1.0;
775  Double bpp = -1.0;
776 
777  if ( ( pcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() )
778  {
779  estQP = pcSlice->getSliceQp();
780  }
781  else
782  {
783  bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType());
784  if ( pcPic->getSlice( 0 )->getSliceType() == I_SLICE)
785  {
786  estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambdaAndQP(bpp, pcSlice->getSliceQp(), &estQP);
787  }
788  else
789  {
790  estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
791  estQP = m_pcRateCtrl->getRCPic()->getLCUEstQP ( estLambda, pcSlice->getSliceQp() );
792  }
793 
794  estQP = Clip3( -pcSlice->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, estQP );
795 
796  m_pcRdCost->setLambda(estLambda);
797 
798 #if RDOQ_CHROMA_LAMBDA
799  // set lambda for RDOQ
800  const Double chromaLambda = estLambda / m_pcRdCost->getChromaWeight();
801  const Double lambdaArray[MAX_NUM_COMPONENT] = { estLambda, chromaLambda, chromaLambda };
802  m_pcTrQuant->setLambdas( lambdaArray );
803 #else
804  m_pcTrQuant->setLambda( estLambda );
805 #endif
806  }
807 
808  m_pcRateCtrl->setRCQP( estQP );
809 #if ADAPTIVE_QP_SELECTION
810  pCtu->getSlice()->setSliceQpBase( estQP );
811 #endif
812  }
813 
814  // run CTU trial encoder
815  m_pcCuEncoder->compressCtu( pCtu );
816 
817 
818  // All CTU decisions have now been made. Restore entropy coder to an initial stage, ready to make a true encode,
819  // which will result in the state of the contexts being correct. It will also count up the number of bits coded,
820  // which is used if there is a limit of the number of bytes per slice-segment.
821 
822  m_pcEntropyCoder->setEntropyCoder ( m_pppcRDSbacCoder[0][CI_CURR_BEST], pcSlice );
823  m_pcEntropyCoder->setBitstream( &tempBitCounter );
824  pRDSbacCoder->setBinCountingEnableFlag( true );
826  pRDSbacCoder->setBinsCoded( 0 );
827 
828  // encode CTU and calculate the true bit counters.
829  m_pcCuEncoder->encodeCtu( pCtu );
830 
831 
832  pRDSbacCoder->setBinCountingEnableFlag( false );
833 
834  const Int numberOfWrittenBits = m_pcEntropyCoder->getNumberOfWrittenBits();
835 
836  // Calculate if this CTU puts us over slice bit size.
837  // cannot terminate if current slice/slice-segment would be 0 Ctu in size,
838  const UInt validEndOfSliceCtuTsAddr = ctuTsAddr + (ctuTsAddr == startCtuTsAddr ? 1 : 0);
839  // Set slice end parameter
840  if(pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceBits()+numberOfWrittenBits > (pcSlice->getSliceArgument()<<3))
841  {
842  pcSlice->setSliceSegmentCurEndCtuTsAddr(validEndOfSliceCtuTsAddr);
843  pcSlice->setSliceCurEndCtuTsAddr(validEndOfSliceCtuTsAddr);
844  boundingCtuTsAddr=validEndOfSliceCtuTsAddr;
845  }
846  else if(pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+numberOfWrittenBits > (pcSlice->getSliceSegmentArgument()<<3))
847  {
848  pcSlice->setSliceSegmentCurEndCtuTsAddr(validEndOfSliceCtuTsAddr);
849  boundingCtuTsAddr=validEndOfSliceCtuTsAddr;
850  }
851 
852  if (boundingCtuTsAddr <= ctuTsAddr)
853  {
854  break;
855  }
856 
857  pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) );
858  pcSlice->setSliceSegmentBits(pcSlice->getSliceSegmentBits()+numberOfWrittenBits);
859 
860  // Store probabilities of second CTU in line into buffer - used only if wavefront-parallel-processing is enabled.
861  if ( ctuXPosInCtus == tileXPosInCtus+1 && m_pcCfg->getWaveFrontsynchro())
862  {
864  }
865 
866 
867  if ( m_pcCfg->getUseRateCtrl() )
868  {
869  Int actualQP = g_RCInvalidQPValue;
870  Double actualLambda = m_pcRdCost->getLambda();
871  Int actualBits = pCtu->getTotalBits();
872  Int numberOfEffectivePixels = 0;
873  for ( Int idx = 0; idx < pcPic->getNumPartitionsInCtu(); idx++ )
874  {
875  if ( pCtu->getPredictionMode( idx ) != NUMBER_OF_PREDICTION_MODES && ( !pCtu->isSkipped( idx ) ) )
876  {
877  numberOfEffectivePixels = numberOfEffectivePixels + 16;
878  break;
879  }
880  }
881 
882  if ( numberOfEffectivePixels == 0 )
883  {
884  actualQP = g_RCInvalidQPValue;
885  }
886  else
887  {
888  actualQP = pCtu->getQP( 0 );
889  }
890  m_pcRdCost->setLambda(oldLambda);
891  m_pcRateCtrl->getRCPic()->updateAfterCTU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
892  pCtu->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
893  }
894 
895  m_uiPicTotalBits += pCtu->getTotalBits();
896  m_dPicRdCost += pCtu->getTotalCost();
897  m_uiPicDist += pCtu->getTotalDistortion();
898  }
899 
900  // store context state at the end of this slice-segment, in case the next slice is a dependent slice and continues using the CABAC contexts.
901  if( pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag() )
902  {
903  m_lastSliceSegmentEndContextState.loadContexts( m_pppcRDSbacCoder[0][CI_CURR_BEST] );//ctx end of dep.slice
904  }
905 
906  // stop use of temporary bit counter object.
908  m_pcRDGoOnSbacCoder->setBitstream(NULL); // stop use of tempBitCounter.
909 
910  // TODO: optimise cabac_init during compress slice to improve multi-slice operation
911  //if (pcSlice->getPPS()->getCabacInitPresentFlag() && !pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag())
912  //{
913  // m_encCABACTableIdx = m_pcEntropyCoder->determineCabacInitIdx();
914  //}
915  //else
916  //{
917  // m_encCABACTableIdx = pcSlice->getSliceType();
918  //}
919 }
920 
921 Void TEncSlice::encodeSlice ( TComPic* pcPic, TComOutputBitstream* pcSubstreams, UInt &numBinsCoded )
922 {
923  TComSlice* pcSlice = pcPic->getSlice(getSliceIdx());
924 
925  const UInt startCtuTsAddr = pcSlice->getSliceSegmentCurStartCtuTsAddr();
926  const UInt boundingCtuTsAddr = pcSlice->getSliceSegmentCurEndCtuTsAddr();
927 
928  const UInt frameWidthInCtus = pcPic->getPicSym()->getFrameWidthInCtus();
929  const Bool depSliceSegmentsEnabled = pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag();
930  const Bool wavefrontsEnabled = pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag();
931 
932  // initialise entropy coder for the slice
936 
937  numBinsCoded = 0;
940 
941 #if ENC_DEC_TRACE
943 #endif
945  DTRACE_CABAC_T( "\tPOC: " );
946  DTRACE_CABAC_V( pcPic->getPOC() );
947  DTRACE_CABAC_T( "\n" );
948 #if ENC_DEC_TRACE
950 #endif
951 
952 
953  if (depSliceSegmentsEnabled)
954  {
955  // modify initial contexts with previous slice segment if this is a dependent slice.
956  const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap( startCtuTsAddr );
957  const UInt currentTileIdx=pcPic->getPicSym()->getTileIdxMap(ctuRsAddr);
958  const TComTile *pCurrentTile=pcPic->getPicSym()->getTComTile(currentTileIdx);
959  const UInt firstCtuRsAddrOfTile = pCurrentTile->getFirstCtuRsAddr();
960 
961  if( pcSlice->getDependentSliceSegmentFlag() && ctuRsAddr != firstCtuRsAddrOfTile )
962  {
963  if( pCurrentTile->getTileWidthInCtus() >= 2 || !wavefrontsEnabled )
964  {
966  }
967  }
968  }
969 
970  // for every CTU in the slice segment...
971 
972  for( UInt ctuTsAddr = startCtuTsAddr; ctuTsAddr < boundingCtuTsAddr; ++ctuTsAddr )
973  {
974  const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddr);
975  const TComTile &currentTile = *(pcPic->getPicSym()->getTComTile(pcPic->getPicSym()->getTileIdxMap(ctuRsAddr)));
976  const UInt firstCtuRsAddrOfTile = currentTile.getFirstCtuRsAddr();
977  const UInt tileXPosInCtus = firstCtuRsAddrOfTile % frameWidthInCtus;
978  const UInt tileYPosInCtus = firstCtuRsAddrOfTile / frameWidthInCtus;
979  const UInt ctuXPosInCtus = ctuRsAddr % frameWidthInCtus;
980  const UInt ctuYPosInCtus = ctuRsAddr / frameWidthInCtus;
981  const UInt uiSubStrm=pcPic->getSubstreamForCtuAddr(ctuRsAddr, true, pcSlice);
982  TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr );
983 
984  m_pcEntropyCoder->setBitstream( &pcSubstreams[uiSubStrm] );
985 
986  // set up CABAC contexts' state for this CTU
987  if (ctuRsAddr == firstCtuRsAddrOfTile)
988  {
989  if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
990  {
992  }
993  }
994  else if (ctuXPosInCtus == tileXPosInCtus && wavefrontsEnabled)
995  {
996  // Synchronize cabac probabilities with upper-right CTU if it's available and at the start of a line.
997  if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
998  {
1000  }
1001  TComDataCU *pCtuUp = pCtu->getCtuAbove();
1002  if ( pCtuUp && ((ctuRsAddr%frameWidthInCtus+1) < frameWidthInCtus) )
1003  {
1004  TComDataCU *pCtuTR = pcPic->getCtu( ctuRsAddr - frameWidthInCtus + 1 );
1005  if ( pCtu->CUIsFromSameSliceAndTile(pCtuTR) )
1006  {
1007  // Top-right is available, so use it.
1009  }
1010  }
1011  }
1012 
1013 
1014  if ( pcSlice->getSPS()->getUseSAO() )
1015  {
1016  Bool bIsSAOSliceEnabled = false;
1017  Bool sliceEnabled[MAX_NUM_COMPONENT];
1018  for(Int comp=0; comp < MAX_NUM_COMPONENT; comp++)
1019  {
1020  ComponentID compId=ComponentID(comp);
1021  sliceEnabled[compId] = pcSlice->getSaoEnabledFlag(toChannelType(compId)) && (comp < pcPic->getNumberValidComponents());
1022  if (sliceEnabled[compId])
1023  {
1024  bIsSAOSliceEnabled=true;
1025  }
1026  }
1027  if (bIsSAOSliceEnabled)
1028  {
1029  SAOBlkParam& saoblkParam = (pcPic->getPicSym()->getSAOBlkParam())[ctuRsAddr];
1030 
1031  Bool leftMergeAvail = false;
1032  Bool aboveMergeAvail= false;
1033  //merge left condition
1034  Int rx = (ctuRsAddr % frameWidthInCtus);
1035  if(rx > 0)
1036  {
1037  leftMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-1);
1038  }
1039 
1040  //merge up condition
1041  Int ry = (ctuRsAddr / frameWidthInCtus);
1042  if(ry > 0)
1043  {
1044  aboveMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-frameWidthInCtus);
1045  }
1046 
1047  m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail);
1048  }
1049  }
1050 
1051 #if ENC_DEC_TRACE
1053 #endif
1054  m_pcCuEncoder->encodeCtu( pCtu );
1055 #if ENC_DEC_TRACE
1057 #endif
1058 
1059  //Store probabilities of second CTU in line into buffer
1060  if ( ctuXPosInCtus == tileXPosInCtus+1 && wavefrontsEnabled)
1061  {
1063  }
1064 
1065  // terminate the sub-stream, if required (end of slice-segment, end of tile, end of wavefront-CTU-row):
1066  if (ctuTsAddr+1 == boundingCtuTsAddr ||
1067  ( ctuXPosInCtus + 1 == tileXPosInCtus + currentTile.getTileWidthInCtus() &&
1068  ( ctuYPosInCtus + 1 == tileYPosInCtus + currentTile.getTileHeightInCtus() || wavefrontsEnabled)
1069  )
1070  )
1071  {
1074  // Byte-alignment in slice_data() when new tile
1075  pcSubstreams[uiSubStrm].writeByteAlignment();
1076 
1077  // write sub-stream size
1078  if (ctuTsAddr+1 != boundingCtuTsAddr)
1079  {
1080  pcSlice->addSubstreamSize( (pcSubstreams[uiSubStrm].getNumberOfWrittenBits() >> 3) + pcSubstreams[uiSubStrm].countStartCodeEmulations() );
1081  }
1082  }
1083  } // CTU-loop
1084 
1085  if( depSliceSegmentsEnabled )
1086  {
1088  }
1089 
1090 #if ADAPTIVE_QP_SELECTION
1091  if( m_pcCfg->getUseAdaptQpSelect() )
1092  {
1093  m_pcTrQuant->storeSliceQpNext(pcSlice);
1094  }
1095 #endif
1096 
1097  if (pcSlice->getPPS()->getCabacInitPresentFlag() && !pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag())
1098  {
1100  }
1101  else
1102  {
1103  m_encCABACTableIdx = pcSlice->getSliceType();
1104  }
1105 
1106  numBinsCoded = m_pcBinCABAC->getBinsCoded();
1107 }
1108 
1109 Void TEncSlice::calculateBoundingCtuTsAddrForSlice(UInt &startCtuTSAddrSlice, UInt &boundingCtuTSAddrSlice, Bool &haveReachedTileBoundary,
1110  TComPic* pcPic, const Bool encodingSlice, const Int sliceMode, const Int sliceArgument, const UInt sliceCurEndCtuTSAddr)
1111 {
1112  TComSlice* pcSlice = pcPic->getSlice(getSliceIdx());
1113  const UInt numberOfCtusInFrame = pcPic->getNumberOfCtusInFrame();
1114  boundingCtuTSAddrSlice=0;
1115  haveReachedTileBoundary=false;
1116 
1117  switch (sliceMode)
1118  {
1119  case FIXED_NUMBER_OF_CTU:
1120  {
1121  UInt ctuAddrIncrement = sliceArgument;
1122  boundingCtuTSAddrSlice = ((startCtuTSAddrSlice + ctuAddrIncrement) < numberOfCtusInFrame) ? (startCtuTSAddrSlice + ctuAddrIncrement) : numberOfCtusInFrame;
1123  }
1124  break;
1125  case FIXED_NUMBER_OF_BYTES:
1126  boundingCtuTSAddrSlice = (encodingSlice) ? sliceCurEndCtuTSAddr : numberOfCtusInFrame;
1127  break;
1128  case FIXED_NUMBER_OF_TILES:
1129  {
1130  const UInt tileIdx = pcPic->getPicSym()->getTileIdxMap( pcPic->getPicSym()->getCtuTsToRsAddrMap(startCtuTSAddrSlice) );
1131  const UInt tileTotalCount = (pcPic->getPicSym()->getNumTileColumnsMinus1()+1) * (pcPic->getPicSym()->getNumTileRowsMinus1()+1);
1132  UInt ctuAddrIncrement = 0;
1133 
1134  for(UInt tileIdxIncrement = 0; tileIdxIncrement < sliceArgument; tileIdxIncrement++)
1135  {
1136  if((tileIdx + tileIdxIncrement) < tileTotalCount)
1137  {
1138  UInt tileWidthInCtus = pcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileWidthInCtus();
1139  UInt tileHeightInCtus = pcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileHeightInCtus();
1140  ctuAddrIncrement += (tileWidthInCtus * tileHeightInCtus);
1141  }
1142  }
1143 
1144  boundingCtuTSAddrSlice = ((startCtuTSAddrSlice + ctuAddrIncrement) < numberOfCtusInFrame) ? (startCtuTSAddrSlice + ctuAddrIncrement) : numberOfCtusInFrame;
1145  }
1146  break;
1147  default:
1148  boundingCtuTSAddrSlice = numberOfCtusInFrame;
1149  break;
1150  }
1151 
1152  // Adjust for tiles and wavefronts.
1153  if ((sliceMode == FIXED_NUMBER_OF_CTU || sliceMode == FIXED_NUMBER_OF_BYTES) &&
1155  {
1156  const UInt ctuRSAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(startCtuTSAddrSlice);
1157  const UInt startTileIdx = pcPic->getPicSym()->getTileIdxMap(ctuRSAddr);
1158  const Bool wavefrontsAreEnabled = m_pcCfg->getWaveFrontsynchro();
1159 
1160  const TComTile *pStartingTile = pcPic->getPicSym()->getTComTile(startTileIdx);
1161  const UInt tileStartTsAddr = pcPic->getPicSym()->getCtuRsToTsAddrMap(pStartingTile->getFirstCtuRsAddr());
1162  const UInt tileStartWidth = pStartingTile->getTileWidthInCtus();
1163  const UInt tileStartHeight = pStartingTile->getTileHeightInCtus();
1164  const UInt tileLastTsAddr_excl = tileStartTsAddr + tileStartWidth*tileStartHeight;
1165  const UInt tileBoundingCtuTsAddrSlice = tileLastTsAddr_excl;
1166 
1167  const UInt ctuColumnOfStartingTile = ((startCtuTSAddrSlice-tileStartTsAddr)%tileStartWidth);
1168  if (wavefrontsAreEnabled && ctuColumnOfStartingTile!=0)
1169  {
1170  // WPP: if a slice does not start at the beginning of a CTB row, it must end within the same CTB row
1171  const UInt numberOfCTUsToEndOfRow = tileStartWidth - ctuColumnOfStartingTile;
1172  const UInt wavefrontTileBoundingCtuAddrSlice = startCtuTSAddrSlice + numberOfCTUsToEndOfRow;
1173  if (wavefrontTileBoundingCtuAddrSlice < boundingCtuTSAddrSlice)
1174  {
1175  boundingCtuTSAddrSlice = wavefrontTileBoundingCtuAddrSlice;
1176  }
1177  }
1178 
1179  if (tileBoundingCtuTsAddrSlice < boundingCtuTSAddrSlice)
1180  {
1181  boundingCtuTSAddrSlice = tileBoundingCtuTsAddrSlice;
1182  haveReachedTileBoundary = true;
1183  }
1184  }
1185  else if ((sliceMode == FIXED_NUMBER_OF_CTU || sliceMode == FIXED_NUMBER_OF_BYTES) && pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag() && ((startCtuTSAddrSlice % pcPic->getFrameWidthInCtus()) != 0))
1186  {
1187  // Adjust for wavefronts (no tiles).
1188  // WPP: if a slice does not start at the beginning of a CTB row, it must end within the same CTB row
1189  boundingCtuTSAddrSlice = min(boundingCtuTSAddrSlice, startCtuTSAddrSlice - (startCtuTSAddrSlice % pcPic->getFrameWidthInCtus()) + (pcPic->getFrameWidthInCtus()));
1190  }
1191 }
1192 
1201 Void TEncSlice::xDetermineStartAndBoundingCtuTsAddr ( UInt& startCtuTsAddr, UInt& boundingCtuTsAddr, TComPic* pcPic, const Bool encodingSlice ) // TODO: this is now only ever called with encodingSlice=false
1202 {
1203  TComSlice* pcSlice = pcPic->getSlice(getSliceIdx());
1204 
1205  // Non-dependent slice
1206  UInt startCtuTsAddrSlice = pcSlice->getSliceCurStartCtuTsAddr();
1207  Bool haveReachedTileBoundarySlice = false;
1208  UInt boundingCtuTsAddrSlice;
1209  calculateBoundingCtuTsAddrForSlice(startCtuTsAddrSlice, boundingCtuTsAddrSlice, haveReachedTileBoundarySlice, pcPic,
1210  encodingSlice, m_pcCfg->getSliceMode(), m_pcCfg->getSliceArgument(), pcSlice->getSliceCurEndCtuTsAddr());
1211  pcSlice->setSliceCurEndCtuTsAddr( boundingCtuTsAddrSlice );
1212  pcSlice->setSliceCurStartCtuTsAddr( startCtuTsAddrSlice );
1213 
1214  // Dependent slice
1215  UInt startCtuTsAddrSliceSegment = pcSlice->getSliceSegmentCurStartCtuTsAddr();
1216  Bool haveReachedTileBoundarySliceSegment = false;
1217  UInt boundingCtuTsAddrSliceSegment;
1218  calculateBoundingCtuTsAddrForSlice(startCtuTsAddrSliceSegment, boundingCtuTsAddrSliceSegment, haveReachedTileBoundarySliceSegment, pcPic,
1220  if (boundingCtuTsAddrSliceSegment>boundingCtuTsAddrSlice)
1221  {
1222  boundingCtuTsAddrSliceSegment = boundingCtuTsAddrSlice;
1223  }
1224  pcSlice->setSliceSegmentCurEndCtuTsAddr( boundingCtuTsAddrSliceSegment );
1225  pcSlice->setSliceSegmentCurStartCtuTsAddr(startCtuTsAddrSliceSegment);
1226 
1227  // Make a joint decision based on reconstruction and dependent slice bounds
1228  startCtuTsAddr = max(startCtuTsAddrSlice , startCtuTsAddrSliceSegment );
1229  boundingCtuTsAddr = boundingCtuTsAddrSliceSegment;
1230 }
1231 
1233 {
1234  return 4.2005*log(lambda) + 13.7122;
1235 }
1236 
Void setDistortionWeight(const ComponentID compID, const Double distortionWeight)
Definition: TComRdCost.h:139
Double getLambda()
Definition: TComRdCost.h:145
TComPicYuv * m_apcPicYuvPred
prediction picture buffer
Definition: TEncSlice.h:70
Void init(TEncBinIf *p)
Definition: TEncSbac.h:72
Void setSliceSegmentCurEndCtuTsAddr(UInt ctuTsAddr)
Definition: TComSlice.h:1479
UInt getIntraPeriod()
Definition: TEncCfg.h:473
Void setSliceSegmentMode(SliceConstraint mode)
Definition: TComSlice.h:1473
Void encodeSlice(TComPic *pcPic, TComOutputBitstream *pcSubstreams, UInt &numBinsCoded)
Definition: TEncSlice.cpp:921
SliceType
supported slice type
Definition: TypeDef.h:343
Char * getQP()
Definition: TComDataCU.h:255
Void resetEntropy()
Definition: TEncSbac.cpp:106
UInt getFirstCtuRsAddr() const
Definition: TComPicSym.h:79
Void setDeblockingFilterTcOffsetDiv2(Int i)
Definition: TComSlice.h:1389
Int m_betaOffsetDiv2
Definition: TEncCfg.h:55
TEncSbac *** getRDSbacCoder()
Definition: TEncTop.h:152
static Int getScaledChromaQP(Int unscaledChromaQP, const ChromaFormat chFmt)
Void create(const Int iPicWidth, const Int iPicHeight, const ChromaFormat chromaFormatIDC, const UInt uiMaxCUWidth, const UInt uiMaxCUHeight, const UInt uiMaxCUDepth)
Definition: TComPicYuv.cpp:81
TRCLCU * getLCU()
Definition: TEncRateCtrl.h:264
Double getChromaWeight()
Definition: TComRdCost.h:146
UInt getCtuTsToRsAddrMap(Int ctuTsAddr) const
Definition: TComPicSym.h:150
Double * m_pdRdPicQp
array of picture QP candidates (double-type for lambda)
Definition: TEncSlice.h:94
picture YUV buffer class
Definition: TComPicYuv.h:55
SliceType getSliceType() const
Definition: TComSlice.h:1337
TEncGOP * m_pcGOPEncoder
GOP encoder.
Definition: TEncSlice.h:74
CU data structure class.
Definition: TComDataCU.h:64
Void setUpLambda(TComSlice *slice, const Double dLambda, Int iQP)
Definition: TEncSlice.cpp:145
Void encodeCtu(TComDataCU *pCtu)
CTU encoding function.
Definition: TEncCu.cpp:252
TEncRateCtrl * getRateCtrl()
Definition: TEncTop.h:154
Void setPicYuvResi(TComPicYuv *pcPicYuv)
Definition: TComPic.h:114
Int updateCtuDataISlice(TComDataCU *pCtu, Int width, Int height)
Definition: TEncCu.cpp:1128
Bool getUseRecalculateQPAccordingToLambda()
Definition: TEncCfg.h:771
UInt getNumberOfCtusInFrame() const
Definition: TComPic.h:116
Bool getUseHADME()
Definition: TEncCfg.h:526
SliceConstraint getSliceMode() const
Definition: TComSlice.h:1463
picture class (symbol + YUV buffers)
Definition: TComPic.h:56
TEncSbac * m_pcRDGoOnSbacCoder
go-on SBAC encoder
Definition: TEncSlice.h:89
void Void
Definition: TypeDef.h:285
Void init(TEncTop *pcEncTop)
Definition: TEncSlice.cpp:117
TEncGOP * getGOPEncoder()
Definition: TEncTop.h:143
best mode index
Definition: TypeDef.h:479
Void preLoopFilterPicAll(TComPic *pcPic, UInt64 &ruiDist)
Definition: TEncGOP.cpp:2055
Void setDeblockingFilterBetaOffsetDiv2(Int i)
Definition: TComSlice.h:1388
Int getNumTileColumnsMinus1() const
Definition: TComPicSym.h:145
#define NULL
Definition: CommonDef.h:100
UInt64 m_uiPicTotalBits
total bits for the picture
Definition: TEncSlice.h:90
Bool isSkipped(UInt uiPartIdx)
returns true, if the partiton is skipped
TComSlice * getSlice(Int i)
Definition: TComPic.h:103
Void setPicYuvPred(TComPicYuv *pcPicYuv)
Definition: TComPic.h:113
Void addSubstreamSize(UInt size)
Definition: TComSlice.h:1511
TEncSbac *** m_pppcRDSbacCoder
storage for SBAC-based RD optimization
Definition: TEncSlice.h:88
Bool getCabacInitPresentFlag() const
Definition: TComSlice.h:1147
unsigned int UInt
Definition: TypeDef.h:297
SliceConstraint getSliceSegmentMode() const
Definition: TComSlice.h:1474
UInt getNumPartitionsInCtu() const
Definition: TComPic.h:119
Bool getUseSAO() const
Definition: TComSlice.h:893
Int getSliceSegmentArgument()
Definition: TEncCfg.h:579
Bool getPicDisableDeblockingFilterFlag() const
get offset for deblocking filter disabled
Definition: TComSlice.h:1153
Int getGOPSize()
Definition: TEncGOP.h:137
Bool getForceIntraQP()
Definition: TEncCfg.h:759
SliceType m_encCABACTableIdx
Definition: TEncSlice.h:100
Void setEntropyCoder(TEncEntropyIf *e, TComSlice *pcSlice)
Definition: TEncEntropy.cpp:51
Void initCtu(TComPic *pcPic, UInt ctuRsAddr)
Definition: TComDataCU.cpp:448
Int getLCUCoded()
Definition: TEncRateCtrl.h:263
UInt getMaxCUHeight() const
Definition: TComSlice.h:847
Double * m_pdRdPicLambda
array of lambda candidates
Definition: TEncSlice.h:93
Int getLoopFilterTcOffset()
Definition: TEncCfg.h:492
Int getNumberValidComponents() const
Definition: TComPic.h:129
const Int g_RCInvalidQPValue
Definition: TEncRateCtrl.h:61
TEncCu * m_pcCuEncoder
CU encoder.
Definition: TEncSlice.h:75
Void setSliceCurStartCtuTsAddr(UInt ctuTsAddr)
Definition: TComSlice.h:1466
UInt64 g_nSymbolCounter
Definition: TComRom.cpp:566
TEncEntropy * getEntropyCoder()
Definition: TEncTop.h:146
TEncSbac * m_pcSbacCoder
SBAC encoder.
Definition: TEncSlice.h:82
Void initWpScaling(const TComSPS *sps)
init WP table
Definition: TComSlice.cpp:1492
Double calcRdCost64(UInt64 uiBits, UInt64 uiDistortion, Bool bFlag=false, DFunc eDFunc=DF_DEFAULT)
Definition: TComRdCost.cpp:125
Void setTLayer(UInt uiTLayer)
Definition: TComPic.h:93
TEncRCPic * getRCPic()
Definition: TEncRateCtrl.h:322
#define MAX_QP
Definition: CommonDef.h:127
Int getNumRefIdx(RefPicList e) const
Definition: TComSlice.h:1353
CostMode getCostMode()
Definition: TEncCfg.h:765
UInt getCtuRsToTsAddrMap(Int ctuRsAddr) const
Definition: TComPicSym.h:152
TComPicYuv * m_apcPicYuvResi
residual picture buffer
Definition: TEncSlice.h:71
class for counting bits
Bool getSaoEnabledFlag(ChannelType chType) const
Definition: TComSlice.h:1322
TEncSearch * m_pcPredSearch
encoder search class
Definition: TEncSlice.h:78
Int * getdQPs()
Definition: TEncCfg.h:567
Void setPic(TComPic *p)
Definition: TComSlice.h:1394
TEncBinCABAC * m_pcBinCABAC
Bin encoder CABAC.
Definition: TEncSlice.h:83
Void xEstimateWPParamSlice(TComSlice *const slice)
estimate wp tables for explicit wp
Void setSliceBits(UInt uiVal)
Definition: TComSlice.h:1481
UInt getFrameWidthInCtus() const
Definition: TComPicSym.h:128
Bool isInterB() const
Definition: TComSlice.h:1405
Int getNumTileRowsMinus1() const
Definition: TComPicSym.h:146
Void xCheckWPEnable(TComSlice *const slice)
check weighted pred or non-weighted pred
Void setSliceSegmentArgument(UInt uiArgument)
Definition: TComSlice.h:1475
Distortion & getTotalDistortion()
Definition: TComDataCU.h:473
UInt getSliceIdx()
Definition: TEncSlice.h:128
Void precompressSlice(TComPic *pcPic)
precompress slice for multi-loop opt.
Definition: TEncSlice.cpp:530
Bool getTransquantBypassEnableFlag() const
Definition: TComSlice.h:1116
Void calCostSliceI(TComPic *pcPic)
Definition: TEncSlice.cpp:610
Void setAdaptiveSearchRange(Int iDir, Int iRefIdx, Int iSearchRange)
set ME search range
Definition: TEncSearch.h:208
TEncSbac * getRDGoOnSbacCoder()
Definition: TEncTop.h:153
ChromaFormat getChromaFormatIdc()
Definition: TEncCfg.h:447
Void create(Int iWidth, Int iHeight, ChromaFormat chromaFormat, UInt iMaxCUWidth, UInt iMaxCUHeight, UChar uhTotalDepth)
Definition: TEncSlice.cpp:64
Bool getDependentSliceSegmentFlag() const
Definition: TComSlice.h:1340
Void loadContexts(const TEncSbac *pSrc)
Definition: TEncSbac.cpp:1969
Void storeSliceQpNext(TComSlice *pcSlice)
UInt getTileWidthInCtus() const
Definition: TComPicSym.h:71
Bool getUseAdaptQpSelect()
Definition: TEncCfg.h:451
Double & getTotalCost()
Definition: TComDataCU.h:472
Limit maximum number of bytes in a slice / slice segment.
Definition: TypeDef.h:566
Bool getLCULevelRC()
Definition: TEncCfg.h:753
Void setSliceType(SliceType e)
Definition: TComSlice.h:1378
TEncSbac * getSbacCoder()
Definition: TEncTop.h:148
TComList< TComPic * > * getListPic()
Definition: TEncTop.h:137
const Bool g_bEncDecTraceEnable
Definition: TComRom.cpp:562
Int m_tcOffsetDiv2
Definition: TEncCfg.h:54
Void setTemporalLayerNonReferenceFlag(Bool x)
Definition: TComSlice.h:1517
GOPEntry getGOPEntry(Int i)
Definition: TEncCfg.h:401
#define DTRACE_CABAC_T(x)
Definition: TComRom.h:197
Int getQpDelta(Int qp)
Definition: TComTrQuant.h:193
Int m_QPOffset
Definition: TEncCfg.h:52
Void setTotalIntraCost(Double cost)
Definition: TEncRateCtrl.h:268
UInt getTileIdxMap(Int ctuRsAddr) const
Definition: TComPicSym.h:151
Int getQpBDOffset(ChannelType type) const
Definition: TComSlice.h:885
Bool getSAOMergeAvailability(Int currAddr, Int mergeAddr)
Definition: TComPic.cpp:118
bool Bool
Definition: TypeDef.h:286
Void setSliceSegmentBits(UInt uiVal)
Definition: TComSlice.h:1483
UInt getSubstreamForCtuAddr(const UInt ctuAddr, const Bool bAddressInRaster, TComSlice *pcSlice)
Definition: TComPic.cpp:125
Void setBitstream(TComBitIf *p)
Definition: TEncSbac.h:78
TComRdCost * m_pcRdCost
RD cost computation.
Definition: TEncSlice.h:87
Void setDeltaQpRD(UInt u)
Definition: TEncCfg.h:524
Void encodeSliceFinish()
Definition: TEncEntropy.cpp:75
Bool g_bJustDoIt
Definition: TComRom.cpp:565
Void setSliceQpDelta(Int i)
Definition: TComSlice.h:1383
UInt64 m_uiPicDist
total distortion for the picture
Definition: TEncSlice.h:91
PPS class.
Definition: TComSlice.h:977
Int getWaveFrontsynchro()
Definition: TEncCfg.h:603
UInt getDeltaQpRD()
Definition: TEncCfg.h:568
UInt getPicHeightInLumaSamples() const
Definition: TComSlice.h:824
Void load(const TEncSbac *pSrc)
Definition: TEncSbac.cpp:397
UInt getSliceBits() const
Definition: TComSlice.h:1482
TComTrQuant * getTrQuant()
Definition: TEncTop.h:140
Double getLambdaModifier(UInt uiIndex) const
Definition: TEncCfg.h:470
static ChannelType toChannelType(const ComponentID id)
UInt getSliceSegmentBits() const
Definition: TComSlice.h:1484
T Clip3(const T minVal, const T maxVal, const T a)
general min/max clip
Definition: CommonDef.h:137
TEncEntropy * m_pcEntropyCoder
entropy encoder
Definition: TEncSlice.h:81
Int getSliceArgument()
Definition: TEncCfg.h:574
Void setDepth(Int iDepth)
Definition: TComSlice.h:1395
Double getLCUTargetBpp(SliceType eSliceType)
reference list 0
Definition: TypeDef.h:417
Void initEncSlice(TComPic *pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice *&rpcSlice, const TComSPS *pSPS, const TComPPS *pPPS, Bool isField)
preparation of slice encoding (reference marking, QP and lambda)
Definition: TEncSlice.cpp:193
Void setDeblockingFilterOverrideFlag(Bool b)
Definition: TComSlice.h:1387
slice encoder class (header)
Void compressCtu(TComDataCU *pCtu)
CTU analysis function.
Definition: TEncCu.cpp:228
RefPicList
reference list index
Definition: TypeDef.h:415
Void setSliceCurEndCtuTsAddr(UInt ctuTsAddr)
Definition: TComSlice.h:1468
Int getSliceQpBase() const
Definition: TComSlice.h:1343
TComPicSym * getPicSym()
Definition: TComPic.h:102
Void setSliceQpBase(Int i)
Definition: TComSlice.h:1381
SliceType determineCabacInitIdx()
Definition: TEncEntropy.h:129
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Definition: TypeDef.h:352
#define xFree(ptr)
Definition: CommonDef.h:157
unsigned char UChar
Definition: TypeDef.h:293
virtual ~TEncSlice()
Definition: TEncSlice.cpp:60
Void encodeSAOBlkParam(SAOBlkParam &saoBlkParam, Bool *sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail)
Definition: TEncEntropy.h:181
UInt getSliceSegmentCurStartCtuTsAddr() const
Definition: TComSlice.h:1478
Limit maximum number of largest coding tree units in a slice / slice segments.
Definition: TypeDef.h:565
TEncSbac m_lastSliceSegmentEndContextState
context storage for state at the end of the previous slice-segment (used for dependent slices only)...
Definition: TEncSlice.h:98
const TComPPS * getPPS() const
Definition: TComSlice.h:1309
UInt getPicWidthInLumaSamples() const
Definition: TComSlice.h:822
Int getSearchRange()
Definition: TEncCfg.h:498
Void setSliceChromaQpDelta(ComponentID compID, Int i)
Definition: TComSlice.h:1384
Void setMaxNumMergeCand(UInt val)
Definition: TComSlice.h:1450
UInt & getTotalBits()
Definition: TComDataCU.h:474
Int getChromaQpAdjTableSize() const
Definition: TComSlice.h:1081
#define DTRACE_CABAC_V(x)
Definition: TComRom.h:195
Bool CUIsFromSameSliceAndTile(const TComDataCU *pCU) const
Definition: TComDataCU.cpp:403
UInt getSliceArgument() const
Definition: TComSlice.h:1465
Int getMaxDeltaQP()
Definition: TEncCfg.h:501
UInt getSliceSegmentArgument() const
Definition: TComSlice.h:1476
Bool getUseWP() const
Definition: TComSlice.h:1102
#define xMalloc(type, len)
Definition: CommonDef.h:156
reference list 1
Definition: TypeDef.h:418
Void setBinsCoded(UInt uiVal)
UInt getTileHeightInCtus() const
Definition: TComPicSym.h:73
Int getLCUEstQP(Double lambda, Int clipPicQP)
Int getPOC() const
Definition: TComSlice.h:1338
encoder class (header)
Void calculateBoundingCtuTsAddrForSlice(UInt &startCtuTSAddrSlice, UInt &boundingCtuTSAddrSlice, Bool &haveReachedTileBoundary, TComPic *pcPic, const Bool encodingSlice, const Int sliceMode, const Int sliceArgument, const UInt uiSliceCurEndCtuTSAddr)
Definition: TEncSlice.cpp:1109
Bool getDeblockingFilterControlPresentFlag() const
Definition: TComSlice.h:1149
Void updateAfterCTU(Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter=true)
Void setLambda(Double dLambda)
Definition: TComRdCost.cpp:194
Bool getEntropyCodingSyncEnabledFlag() const
Definition: TComSlice.h:1127
Int getPOC() const
Definition: TComPic.h:104
Bool isInterP() const
Definition: TComSlice.h:1406
Int getNumRowsMinus1()
Definition: TEncCfg.h:598
UInt getSliceCurStartCtuTsAddr() const
Definition: TComSlice.h:1467
Int getQP()
Definition: TEncCfg.h:478
unsigned long long UInt64
Definition: TypeDef.h:318
Int g_bitDepth[MAX_NUM_CHANNEL_TYPE]
Definition: TComRom.cpp:548
TComRdCost * getRdCost()
Definition: TEncTop.h:151
TComDataCU * getCtu(UInt ctuRsAddr)
Definition: TComPic.h:105
TEncBinIf * getEncBinIf()
Definition: TEncSbac.h:175
Void setPOC(Int i)
Definition: TComSlice.h:1370
Double getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP)
Void setFrameLambda(Double dLambda)
Definition: TComRdCost.h:141
Int m_numRefPicsActive
Definition: TEncCfg.h:58
#define DTRACE_CABAC_VL(x)
Definition: TComRom.h:196
Void setSliceMode(SliceConstraint mode)
Definition: TComSlice.h:1462
Char * getPredictionMode()
Definition: TComDataCU.h:234
TComDataCU * getCtuAbove()
Definition: TComDataCU.h:396
Bool getDependentSliceSegmentsEnabledFlag() const
Definition: TComSlice.h:1125
Int getQpOffset(ComponentID compID) const
Definition: TComSlice.h:1073
Int getNumColumnsMinus1()
Definition: TEncCfg.h:594
UInt getTLayer() const
Definition: TComPic.h:92
Void setSearchRange(TComSlice *pcSlice)
set ME range adaptively
Definition: TEncSlice.cpp:503
Void setRCQP(Int QP)
Definition: TEncRateCtrl.h:318
TComTile * getTComTile(UInt tileIdx)
Definition: TComPicSym.h:148
TComTrQuant * m_pcTrQuant
transform & quantization
Definition: TEncSlice.h:84
Void resetEntropy()
Definition: TEncEntropy.h:128
Void destroy()
Definition: TEncSlice.cpp:81
Void resetBits()
Definition: TEncSbac.h:85
Bool getUseRateCtrl()
Definition: TEncCfg.h:747
Void setSliceArgument(UInt uiArgument)
Definition: TComSlice.h:1464
Void clearSliceARLCnt()
Bool getDeblockingFilterMetric()
Definition: TEncCfg.h:494
UInt getSliceSegmentCurEndCtuTsAddr() const
Definition: TComSlice.h:1480
Void xCalcACDCParamSlice(TComSlice *const slice)
calculate AC and DC values for current original image
Void setBinCountingEnableFlag(Bool bFlag)
Void setTLayer(UInt uiTLayer)
Definition: TComSlice.h:1435
Bool m_refPic
Definition: TEncCfg.h:57
int Int
Definition: TypeDef.h:296
Void setBitstream(TComBitIf *p)
Definition: TEncEntropy.h:125
Void setSliceSegmentCurStartCtuTsAddr(UInt ctuTsAddr)
Definition: TComSlice.h:1477
encoder class
Definition: TEncTop.h:68
Void xDetermineStartAndBoundingCtuTsAddr(UInt &startCtuTsAddr, UInt &boundingCtuTsAddr, TComPic *pcPic, const Bool encodingSlice)
Definition: TEncSlice.cpp:1201
ComponentID
Definition: TypeDef.h:368
Int getSliceChromaQpDelta(ComponentID compID) const
Definition: TComSlice.h:1346
UInt getMaxNumMergeCand()
Definition: TEncCfg.h:738
Int getSliceQp() const
Definition: TComSlice.h:1339
const Bool g_bEncDecTraceDisable
Definition: TComRom.cpp:563
#define LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP
QP to use for lossless coding.
Definition: TypeDef.h:227
TEncCfg * m_pcCfg
encoder configuration class
Definition: TEncSlice.h:66
Int * m_piRdPicQp
array of picture QP candidates (Int-type)
Definition: TEncSlice.h:95
Frame-based SSE.
Definition: TypeDef.h:468
TEncSearch * getPredSearch()
Definition: TEncTop.h:138
#define MAX_DOUBLE
max. value of Double-type value
Definition: CommonDef.h:124
Void setLambdas(const Double lambdas[MAX_NUM_COMPONENT])
Definition: TComSlice.h:1408
UInt getDecodingRefreshType()
Definition: TEncCfg.h:474
SliceConstraint getSliceMode() const
Definition: TEncCfg.h:573
Bool getDeblockingFilterOverrideFlag() const
Definition: TComSlice.h:1349
SliceConstraint getSliceSegmentMode() const
Definition: TEncCfg.h:578
slices / slice segments span an integer number of tiles
Definition: TypeDef.h:567
Void resetQP(TComPic *pic, Int sliceQP, Double lambda)
Definition: TEncSlice.cpp:487
Double m_dPicRdCost
picture-level RD cost
Definition: TEncSlice.h:92
#define ADAPT_SR_SCALE
division factor for adaptive search range
Definition: CommonDef.h:205
Void encodeTerminatingBit(UInt uiIsLast)
Definition: TEncEntropy.cpp:68
Void setUseChromaQpAdj(Bool b)
Definition: TComSlice.h:1385
TEncCu * getCuEncoder()
Definition: TEncTop.h:145
Void setDeblockingFilterDisable(Bool b)
Definition: TComSlice.h:1386
Int m_temporalId
Definition: TEncCfg.h:56
double Double
Definition: TypeDef.h:298
Bool getDeblockingFilterDisable() const
Definition: TComSlice.h:1348
slice header class
Definition: TComSlice.h:1198
Void setNumRefIdx(RefPicList e, Int i)
Definition: TComSlice.h:1393
Bool getWPBiPred() const
Definition: TComSlice.h:1103
TEncBinCABAC * getBinCABAC()
Definition: TEncTop.h:149
Int getGOPSize()
Definition: TEncCfg.h:475
Void setPicOutputFlag(Bool b)
Definition: TComSlice.h:1319
Void initSlice()
Definition: TComSlice.cpp:155
Int getLoopFilterBetaOffset()
Definition: TEncCfg.h:491
Void setReferenced(Bool b)
Definition: TComSlice.h:1367
Void destroy()
Definition: TComPicYuv.cpp:146
TEncRateCtrl * m_pcRateCtrl
Rate control manager.
Definition: TEncSlice.h:96
Void setSliceQp(Int i)
Definition: TComSlice.h:1379
UInt getFrameWidthInCtus() const
Definition: TComPic.h:120
TComPic * getRefPic(RefPicList e, Int iRefIdx)
Definition: TComSlice.h:1355
Bool getDeblockingFilterOverrideEnabledFlag() const
Definition: TComSlice.h:1151
TEncSbac m_entropyCodingSyncContextState
context storate for state of contexts at the wavefront/WPP/entropy-coding-sync second CTU of tile-row...
Definition: TEncSlice.h:99
Void compressSlice(TComPic *pcPic)
analysis stage of slice
Definition: TEncSlice.cpp:644
Double m_QPFactor
Definition: TEncCfg.h:53
UInt getSliceCurEndCtuTsAddr() const
Definition: TComSlice.h:1469
TComList< TComPic * > * m_pcListPic
list of pictures
Definition: TEncSlice.h:69
Double getLCUEstLambda(Double bpp)
UInt getMaxCUWidth() const
Definition: TComSlice.h:845
TComSlice * getSlice()
Definition: TComDataCU.h:205
const TComSPS * getSPS() const
Definition: TComSlice.h:1306
Double xGetQPValueAccordingToLambda(Double lambda)
Definition: TEncSlice.cpp:1232
SPS class.
Definition: TComSlice.h:722
Void setLambdas(const Double lambdas[MAX_NUM_COMPONENT])
Definition: TComTrQuant.h:147
UInt getNumberOfWrittenBits()
Definition: TEncEntropy.h:127
SAOBlkParam * getSAOBlkParam()
Definition: TComPicSym.h:153