HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2017, 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 {
52 }
53 
55 {
56  destroy();
57 }
58 
59 Void TEncSlice::create( Int iWidth, Int iHeight, ChromaFormat chromaFormat, UInt iMaxCUWidth, UInt iMaxCUHeight, UChar uhTotalDepth )
60 {
61  // create prediction picture
62  m_picYuvPred.create( iWidth, iHeight, chromaFormat, iMaxCUWidth, iMaxCUHeight, uhTotalDepth, true );
63 
64  // create residual picture
65  m_picYuvResi.create( iWidth, iHeight, chromaFormat, iMaxCUWidth, iMaxCUHeight, uhTotalDepth, true );
66 }
67 
69 {
72 
73  // free lambda and QP arrays
74  m_vdRdPicLambda.clear();
75  m_vdRdPicQp.clear();
76  m_viRdPicQp.clear();
77 }
78 
80 {
81  m_pcCfg = pcEncTop;
82  m_pcListPic = pcEncTop->getListPic();
83 
84  m_pcGOPEncoder = pcEncTop->getGOPEncoder();
85  m_pcCuEncoder = pcEncTop->getCuEncoder();
86  m_pcPredSearch = pcEncTop->getPredSearch();
87 
88  m_pcEntropyCoder = pcEncTop->getEntropyCoder();
89  m_pcSbacCoder = pcEncTop->getSbacCoder();
90  m_pcBinCABAC = pcEncTop->getBinCABAC();
91  m_pcTrQuant = pcEncTop->getTrQuant();
92 
93  m_pcRdCost = pcEncTop->getRdCost();
94  m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder();
96 
97  // create lambda and QP arrays
98  m_vdRdPicLambda.resize(m_pcCfg->getDeltaQpRD() * 2 + 1 );
99  m_vdRdPicQp.resize( m_pcCfg->getDeltaQpRD() * 2 + 1 );
100  m_viRdPicQp.resize( m_pcCfg->getDeltaQpRD() * 2 + 1 );
101  m_pcRateCtrl = pcEncTop->getRateCtrl();
102 }
103 
105 {
106  Int iQP = (Int)dQP;
107  Double dLambda = calculateLambda(pSlice, m_gopID, pSlice->getDepth(), pSlice->getSliceQp(), dQP, iQP);
108 
109  setUpLambda(pSlice, dLambda, iQP);
110 }
111 
112 Void
113 TEncSlice::setUpLambda(TComSlice* slice, const Double dLambda, Int iQP)
114 {
115  // store lambda
116  m_pcRdCost ->setLambda( dLambda, slice->getSPS()->getBitDepths() );
117 
118  // for RDO
119  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
120  Double dLambdas[MAX_NUM_COMPONENT] = { dLambda };
121  for(UInt compIdx=1; compIdx<MAX_NUM_COMPONENT; compIdx++)
122  {
123  const ComponentID compID=ComponentID(compIdx);
124  Int chromaQPOffset = slice->getPPS()->getQpOffset(compID) + slice->getSliceChromaQpDelta(compID);
125  Int qpc=(iQP + chromaQPOffset < 0) ? iQP : getScaledChromaQP(iQP + chromaQPOffset, m_pcCfg->getChromaFormatIdc());
126  Double tmpWeight = pow( 2.0, (iQP-qpc)/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset
127  m_pcRdCost->setDistortionWeight(compID, tmpWeight);
128  dLambdas[compIdx]=dLambda/tmpWeight;
129  }
130 
131 #if RDOQ_CHROMA_LAMBDA
132 // for RDOQ
133  m_pcTrQuant->setLambdas( dLambdas );
134 #else
135  m_pcTrQuant->setLambda( dLambda );
136 #endif
137 
138 // For SAO
139  slice->setLambdas( dLambdas );
140 }
141 
142 
143 
159 Void TEncSlice::initEncSlice( TComPic* pcPic, const Int pocLast, const Int pocCurr, const Int iGOPid, TComSlice*& rpcSlice, const Bool isField )
160 {
161  Double dQP;
162  Double dLambda;
163 
164  rpcSlice = pcPic->getSlice(0);
165  rpcSlice->setSliceBits(0);
166  rpcSlice->setPic( pcPic );
167  rpcSlice->initSlice();
168  rpcSlice->setPicOutputFlag( true );
169  rpcSlice->setPOC( pocCurr );
170  pcPic->setField(isField);
171  m_gopID = iGOPid;
172 
173  // depth computation based on GOP size
174  Int depth;
175  {
176  Int poc = rpcSlice->getPOC();
177  if(isField)
178  {
179  poc = (poc/2) % (m_pcCfg->getGOPSize()/2);
180  }
181  else
182  {
183  poc = poc % m_pcCfg->getGOPSize();
184  }
185 
186  if ( poc == 0 )
187  {
188  depth = 0;
189  }
190  else
191  {
192  Int step = m_pcCfg->getGOPSize();
193  depth = 0;
194  for( Int i=step>>1; i>=1; i>>=1 )
195  {
196  for ( Int j=i; j<m_pcCfg->getGOPSize(); j+=step )
197  {
198  if ( j == poc )
199  {
200  i=0;
201  break;
202  }
203  }
204  step >>= 1;
205  depth++;
206  }
207  }
208 
210  {
211  if (isField && ((rpcSlice->getPOC() % 2) == 1))
212  {
213  depth ++;
214  }
215  }
216  }
217 
218  // slice type
219  SliceType eSliceType;
220 
221  eSliceType=B_SLICE;
222  if(!(isField && pocLast == 1) || !m_pcCfg->getEfficientFieldIRAPEnabled())
223  {
224  if(m_pcCfg->getDecodingRefreshType() == 3)
225  {
226  eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
227  }
228  else
229  {
230  eSliceType = (pocLast == 0 || (pocCurr - (isField ? 1 : 0)) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
231  }
232  }
233 
234  rpcSlice->setSliceType ( eSliceType );
235 
236  // ------------------------------------------------------------------------------------------------------------------
237  // Non-referenced frame marking
238  // ------------------------------------------------------------------------------------------------------------------
239 
240  if(pocLast == 0)
241  {
242  rpcSlice->setTemporalLayerNonReferenceFlag(false);
243  }
244  else
245  {
247  }
248  rpcSlice->setReferenced(true);
249 
250  // ------------------------------------------------------------------------------------------------------------------
251  // QP setting
252  // ------------------------------------------------------------------------------------------------------------------
253 
254 #if X0038_LAMBDA_FROM_QP_CAPABILITY
255  dQP = m_pcCfg->getQPForPicture(iGOPid, rpcSlice);
256 #else
257  dQP = m_pcCfg->getQP();
258  if(eSliceType!=I_SLICE)
259  {
260  if (!(( m_pcCfg->getMaxDeltaQP() == 0) && (!m_pcCfg->getLumaLevelToDeltaQPMapping().isEnabled()) && (dQP == -rpcSlice->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA) ) && (rpcSlice->getPPS()->getTransquantBypassEnabledFlag())))
261  {
262  dQP += m_pcCfg->getGOPEntry(iGOPid).m_QPOffset;
263  }
264  }
265 
266  // modify QP
267  const Int* pdQPs = m_pcCfg->getdQPs();
268  if ( pdQPs )
269  {
270  dQP += pdQPs[ rpcSlice->getPOC() ];
271  }
272 
274  {
276  m_pcCfg->setDeltaQpRD(0);
277  }
278 #endif
279 
280  // ------------------------------------------------------------------------------------------------------------------
281  // Lambda computation
282  // ------------------------------------------------------------------------------------------------------------------
283 
284 #if X0038_LAMBDA_FROM_QP_CAPABILITY
285  const Int temporalId=m_pcCfg->getGOPEntry(iGOPid).m_temporalId;
286 #endif
287  Int iQP;
288  Double dOrigQP = dQP;
289 
290  // pre-compute lambda and QP values for all possible QP candidates
291  for ( Int iDQpIdx = 0; iDQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; iDQpIdx++ )
292  {
293  // compute QP value
294  dQP = dOrigQP + ((iDQpIdx+1)>>1)*(iDQpIdx%2 ? -1 : 1);
295  dLambda = calculateLambda(rpcSlice, iGOPid, depth, dQP, dQP, iQP );
296 
297  m_vdRdPicLambda[iDQpIdx] = dLambda;
298  m_vdRdPicQp [iDQpIdx] = dQP;
299  m_viRdPicQp [iDQpIdx] = iQP;
300  }
301 
302  // obtain dQP = 0 case
303  dLambda = m_vdRdPicLambda[0];
304  dQP = m_vdRdPicQp [0];
305  iQP = m_viRdPicQp [0];
306 
307 #if !X0038_LAMBDA_FROM_QP_CAPABILITY
308  const Int temporalId=m_pcCfg->getGOPEntry(iGOPid).m_temporalId;
309  const std::vector<Double> &intraLambdaModifiers=m_pcCfg->getIntraLambdaModifier();
310 #endif
311 
312  if(rpcSlice->getPPS()->getSliceChromaQpFlag())
313  {
314  const Bool bUseIntraOrPeriodicOffset = rpcSlice->getSliceType()==I_SLICE || (m_pcCfg->getSliceChromaOffsetQpPeriodicity()!=0 && (rpcSlice->getPOC()%m_pcCfg->getSliceChromaOffsetQpPeriodicity())==0);
315  Int cbQP = bUseIntraOrPeriodicOffset? m_pcCfg->getSliceChromaOffsetQpIntraOrPeriodic(false) : m_pcCfg->getGOPEntry(iGOPid).m_CbQPoffset;
316  Int crQP = bUseIntraOrPeriodicOffset? m_pcCfg->getSliceChromaOffsetQpIntraOrPeriodic(true) : m_pcCfg->getGOPEntry(iGOPid).m_CrQPoffset;
317 
318  cbQP = Clip3( -12, 12, cbQP + rpcSlice->getPPS()->getQpOffset(COMPONENT_Cb) ) - rpcSlice->getPPS()->getQpOffset(COMPONENT_Cb);
319  crQP = Clip3( -12, 12, crQP + rpcSlice->getPPS()->getQpOffset(COMPONENT_Cr) ) - rpcSlice->getPPS()->getQpOffset(COMPONENT_Cr);
320  rpcSlice->setSliceChromaQpDelta(COMPONENT_Cb, Clip3( -12, 12, cbQP));
321  assert(rpcSlice->getSliceChromaQpDelta(COMPONENT_Cb)+rpcSlice->getPPS()->getQpOffset(COMPONENT_Cb)<=12 && rpcSlice->getSliceChromaQpDelta(COMPONENT_Cb)+rpcSlice->getPPS()->getQpOffset(COMPONENT_Cb)>=-12);
322  rpcSlice->setSliceChromaQpDelta(COMPONENT_Cr, Clip3( -12, 12, crQP));
323  assert(rpcSlice->getSliceChromaQpDelta(COMPONENT_Cr)+rpcSlice->getPPS()->getQpOffset(COMPONENT_Cr)<=12 && rpcSlice->getSliceChromaQpDelta(COMPONENT_Cr)+rpcSlice->getPPS()->getQpOffset(COMPONENT_Cr)>=-12);
324  }
325  else
326  {
327  rpcSlice->setSliceChromaQpDelta( COMPONENT_Cb, 0 );
328  rpcSlice->setSliceChromaQpDelta( COMPONENT_Cr, 0 );
329  }
330 
331 #if !X0038_LAMBDA_FROM_QP_CAPABILITY
332  Double lambdaModifier;
333  if( rpcSlice->getSliceType( ) != I_SLICE || intraLambdaModifiers.empty())
334  {
335  lambdaModifier = m_pcCfg->getLambdaModifier( temporalId );
336  }
337  else
338  {
339  lambdaModifier = intraLambdaModifiers[ (temporalId < intraLambdaModifiers.size()) ? temporalId : (intraLambdaModifiers.size()-1) ];
340  }
341 
342  dLambda *= lambdaModifier;
343 #endif
344 
345  setUpLambda(rpcSlice, dLambda, iQP);
346 
348  {
349  // restore original slice type
350 
351  if(!(isField && pocLast == 1) || !m_pcCfg->getEfficientFieldIRAPEnabled())
352  {
353  if(m_pcCfg->getDecodingRefreshType() == 3)
354  {
355  eSliceType = (pocLast == 0 || (pocCurr) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
356  }
357  else
358  {
359  eSliceType = (pocLast == 0 || (pocCurr - (isField ? 1 : 0)) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
360  }
361  }
362 
363  rpcSlice->setSliceType ( eSliceType );
364  }
365 
367  {
368  dQP = xGetQPValueAccordingToLambda( dLambda );
369  iQP = max( -rpcSlice->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
370  }
371 
372  rpcSlice->setSliceQp ( iQP );
373 #if ADAPTIVE_QP_SELECTION
374  rpcSlice->setSliceQpBase ( iQP );
375 #endif
376  rpcSlice->setSliceQpDelta ( 0 );
380 
382  {
383  rpcSlice->setDeblockingFilterOverrideFlag(true);
384  rpcSlice->setDeblockingFilterDisable(false);
385  rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
386  rpcSlice->setDeblockingFilterTcOffsetDiv2( 0 );
387  }
388  else if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
389  {
392  if ( !rpcSlice->getDeblockingFilterDisable())
393  {
394  if ( rpcSlice->getDeblockingFilterOverrideFlag() && eSliceType!=I_SLICE)
395  {
398  }
399  else
400  {
403  }
404  }
405  }
406  else
407  {
408  rpcSlice->setDeblockingFilterOverrideFlag( false );
409  rpcSlice->setDeblockingFilterDisable( false );
410  rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
411  rpcSlice->setDeblockingFilterTcOffsetDiv2( 0 );
412  }
413 
414  rpcSlice->setDepth ( depth );
415 
416  pcPic->setTLayer( temporalId );
417  if(eSliceType==I_SLICE)
418  {
419  pcPic->setTLayer(0);
420  }
421  rpcSlice->setTLayer( pcPic->getTLayer() );
422 
423  pcPic->setPicYuvPred( &m_picYuvPred );
424  pcPic->setPicYuvResi( &m_picYuvResi );
425  rpcSlice->setSliceMode ( m_pcCfg->getSliceMode() );
426  rpcSlice->setSliceArgument ( m_pcCfg->getSliceArgument() );
430 }
431 
432 
434  const Int GOPid, // entry in the GOP table
435  const Int depth, // slice GOP hierarchical depth.
436  const Double refQP, // initial slice-level QP
437  const Double dQP, // initial double-precision QP
438  Int &iQP ) // returned integer QP.
439 {
440  enum SliceType eSliceType = slice->getSliceType();
441  const Bool isField = slice->getPic()->isField();
442  const Int NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
443  const Int SHIFT_QP = 12;
444 #if X0038_LAMBDA_FROM_QP_CAPABILITY
445  const Int temporalId=m_pcCfg->getGOPEntry(GOPid).m_temporalId;
446  const std::vector<Double> &intraLambdaModifiers=m_pcCfg->getIntraLambdaModifier();
447 #endif
448 
449 #if FULL_NBIT
450  Int bitdepth_luma_qp_scale = 6 * (slice->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) - 8);
451 #else
452  Int bitdepth_luma_qp_scale = 0;
453 #endif
454  Double qp_temp = dQP + bitdepth_luma_qp_scale - SHIFT_QP;
455  // Case #1: I or P-slices (key-frame)
456  Double dQPFactor = m_pcCfg->getGOPEntry(GOPid).m_QPFactor;
457  if ( eSliceType==I_SLICE )
458  {
460  {
461  dQPFactor=m_pcCfg->getIntraQpFactor();
462  }
463  else
464  {
465 #if X0038_LAMBDA_FROM_QP_CAPABILITY
467  {
468  dQPFactor=0.57;
469  }
470  else
471  {
472 #endif
473  Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)(isField ? NumberBFrames/2 : NumberBFrames) );
474  dQPFactor=0.57*dLambda_scale;
475 #if X0038_LAMBDA_FROM_QP_CAPABILITY
476  }
477 #endif
478  }
479  }
480 #if X0038_LAMBDA_FROM_QP_CAPABILITY
481  else if( m_pcCfg->getLambdaFromQPEnable() )
482  {
483  dQPFactor=0.57;
484  }
485 #endif
486 
487  Double dLambda = dQPFactor*pow( 2.0, qp_temp/3.0 );
488 
489 #if X0038_LAMBDA_FROM_QP_CAPABILITY
490  if( !(m_pcCfg->getLambdaFromQPEnable()) && depth>0 )
491 #else
492  if ( depth>0 )
493 #endif
494  {
495 #if FULL_NBIT
496  Double qp_temp_ref_orig = refQP - SHIFT_QP;
497  dLambda *= Clip3( 2.00, 4.00, (qp_temp_ref_orig / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
498 #else
499  Double qp_temp_ref = refQP + bitdepth_luma_qp_scale - SHIFT_QP;
500  dLambda *= Clip3( 2.00, 4.00, (qp_temp_ref / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
501 #endif
502  }
503 
504  // if hadamard is used in ME process
505  if ( !m_pcCfg->getUseHADME() && slice->getSliceType( ) != I_SLICE )
506  {
507  dLambda *= 0.95;
508  }
509 
510 #if X0038_LAMBDA_FROM_QP_CAPABILITY
511  Double lambdaModifier;
512  if( eSliceType != I_SLICE || intraLambdaModifiers.empty())
513  {
514  lambdaModifier = m_pcCfg->getLambdaModifier( temporalId );
515  }
516  else
517  {
518  lambdaModifier = intraLambdaModifiers[ (temporalId < intraLambdaModifiers.size()) ? temporalId : (intraLambdaModifiers.size()-1) ];
519  }
520  dLambda *= lambdaModifier;
521 #endif
522 
523  iQP = max( -slice->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
524 
525  // NOTE: the lambda modifiers that are sometimes applied later might be best always applied in here.
526  return dLambda;
527 }
528 
529 Void TEncSlice::resetQP( TComPic* pic, Int sliceQP, Double lambda )
530 {
531  TComSlice* slice = pic->getSlice(0);
532 
533  // store lambda
534  slice->setSliceQp( sliceQP );
535 #if ADAPTIVE_QP_SELECTION
536  slice->setSliceQpBase ( sliceQP );
537 #endif
538  setUpLambda(slice, lambda, sliceQP);
539 }
540 
541 // ====================================================================================================================
542 // Public member functions
543 // ====================================================================================================================
544 
547 {
548  Int iCurrPOC = pcSlice->getPOC();
549  Int iRefPOC;
550  Int iGOPSize = m_pcCfg->getGOPSize();
551  Int iOffset = (iGOPSize >> 1);
552  Int iMaxSR = m_pcCfg->getSearchRange();
553  Int iNumPredDir = pcSlice->isInterP() ? 1 : 2;
554 
555  for (Int iDir = 0; iDir < iNumPredDir; iDir++)
556  {
557  RefPicList e = ( iDir ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
558  for (Int iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(e); iRefIdx++)
559  {
560  iRefPOC = pcSlice->getRefPic(e, iRefIdx)->getPOC();
561  Int newSearchRange = Clip3(m_pcCfg->getMinSearchWindow(), iMaxSR, (iMaxSR*ADAPT_SR_SCALE*abs(iCurrPOC - iRefPOC)+iOffset)/iGOPSize);
562  m_pcPredSearch->setAdaptiveSearchRange(iDir, iRefIdx, newSearchRange);
563  }
564  }
565 }
566 
573 {
574  // if deltaQP RD is not used, simply return
575  if ( m_pcCfg->getDeltaQpRD() == 0 )
576  {
577  return;
578  }
579 
580  if ( m_pcCfg->getUseRateCtrl() )
581  {
582  printf( "\nMultiple QP optimization is not allowed when rate control is enabled." );
583  assert(0);
584  return;
585  }
586 
587  TComSlice* pcSlice = pcPic->getSlice(getSliceIdx());
588 
589  if (pcSlice->getDependentSliceSegmentFlag())
590  {
591  // if this is a dependent slice segment, then it was optimised
592  // when analysing the entire slice.
593  return;
594  }
595 
596  if (pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES)
597  {
598  // TODO: investigate use of average cost per CTU so that this Slice Mode can be used.
599  printf( "\nUnable to optimise Slice-level QP if Slice Mode is set to FIXED_NUMBER_OF_BYTES\n" );
600  assert(0);
601  return;
602  }
603 
604  Double dPicRdCostBest = MAX_DOUBLE;
605  UInt uiQpIdxBest = 0;
606 
607  Double dFrameLambda;
608 #if FULL_NBIT
609  Int SHIFT_QP = 12 + 6 * (pcSlice->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) - 8);
610 #else
611  Int SHIFT_QP = 12;
612 #endif
613 
614  // set frame lambda
615  if (m_pcCfg->getGOPSize() > 1)
616  {
617  dFrameLambda = 0.68 * pow (2, (m_viRdPicQp[0] - SHIFT_QP) / 3.0) * (pcSlice->isInterB()? 2 : 1);
618  }
619  else
620  {
621  dFrameLambda = 0.68 * pow (2, (m_viRdPicQp[0] - SHIFT_QP) / 3.0);
622  }
623  m_pcRdCost ->setFrameLambda(dFrameLambda);
624 
625  // for each QP candidate
626  for ( UInt uiQpIdx = 0; uiQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; uiQpIdx++ )
627  {
628  pcSlice ->setSliceQp ( m_viRdPicQp [uiQpIdx] );
629 #if ADAPTIVE_QP_SELECTION
630  pcSlice ->setSliceQpBase ( m_viRdPicQp [uiQpIdx] );
631 #endif
632  setUpLambda(pcSlice, m_vdRdPicLambda[uiQpIdx], m_viRdPicQp [uiQpIdx]);
633 
634  // try compress
635  compressSlice ( pcPic, true, m_pcCfg->getFastDeltaQp());
636 
637  UInt64 uiPicDist = m_uiPicDist; // Distortion, as calculated by compressSlice.
638  // NOTE: This distortion is the chroma-weighted SSE distortion for the slice.
639  // Previously a standard SSE distortion was calculated (for the entire frame).
640  // Which is correct?
641 
642  // TODO: Update loop filter, SAO and distortion calculation to work on one slice only.
643  // m_pcGOPEncoder->preLoopFilterPicAll( pcPic, uiPicDist );
644 
645  // compute RD cost and choose the best
646  Double dPicRdCost = m_pcRdCost->calcRdCost( (Double)m_uiPicTotalBits, (Double)uiPicDist, DF_SSE_FRAME);
647 
648  if ( dPicRdCost < dPicRdCostBest )
649  {
650  uiQpIdxBest = uiQpIdx;
651  dPicRdCostBest = dPicRdCost;
652  }
653  }
654 
655  // set best values
656  pcSlice ->setSliceQp ( m_viRdPicQp [uiQpIdxBest] );
657 #if ADAPTIVE_QP_SELECTION
658  pcSlice ->setSliceQpBase ( m_viRdPicQp [uiQpIdxBest] );
659 #endif
660  setUpLambda(pcSlice, m_vdRdPicLambda[uiQpIdxBest], m_viRdPicQp [uiQpIdxBest]);
661 }
662 
663 Void TEncSlice::calCostSliceI(TComPic* pcPic) // TODO: this only analyses the first slice segment. What about the others?
664 {
665  Double iSumHadSlice = 0;
666  TComSlice * const pcSlice = pcPic->getSlice(getSliceIdx());
667  const TComSPS &sps = *(pcSlice->getSPS());
668  const Int shift = sps.getBitDepth(CHANNEL_TYPE_LUMA)-8;
669  const Int offset = (shift>0)?(1<<(shift-1)):0;
670 
671  pcSlice->setSliceSegmentBits(0);
672 
673  UInt startCtuTsAddr, boundingCtuTsAddr;
674  xDetermineStartAndBoundingCtuTsAddr ( startCtuTsAddr, boundingCtuTsAddr, pcPic );
675 
676  for( UInt ctuTsAddr = startCtuTsAddr, ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap( startCtuTsAddr);
677  ctuTsAddr < boundingCtuTsAddr;
678  ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(++ctuTsAddr) )
679  {
680  // initialize CU encoder
681  TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr );
682  pCtu->initCtu( pcPic, ctuRsAddr );
683 
684  Int height = min( sps.getMaxCUHeight(),sps.getPicHeightInLumaSamples() - ctuRsAddr / pcPic->getFrameWidthInCtus() * sps.getMaxCUHeight() );
685  Int width = min( sps.getMaxCUWidth(), sps.getPicWidthInLumaSamples() - ctuRsAddr % pcPic->getFrameWidthInCtus() * sps.getMaxCUWidth() );
686 
687  Int iSumHad = m_pcCuEncoder->updateCtuDataISlice(pCtu, width, height);
688 
689  (m_pcRateCtrl->getRCPic()->getLCU(ctuRsAddr)).m_costIntra=(iSumHad+offset)>>shift;
690  iSumHadSlice += (m_pcRateCtrl->getRCPic()->getLCU(ctuRsAddr)).m_costIntra;
691 
692  }
693  m_pcRateCtrl->getRCPic()->setTotalIntraCost(iSumHadSlice);
694 }
695 
698 Void TEncSlice::compressSlice( TComPic* pcPic, const Bool bCompressEntireSlice, const Bool bFastDeltaQP )
699 {
700  // if bCompressEntireSlice is true, then the entire slice (not slice segment) is compressed,
701  // effectively disabling the slice-segment-mode.
702 
703  UInt startCtuTsAddr;
704  UInt boundingCtuTsAddr;
705  TComSlice* const pcSlice = pcPic->getSlice(getSliceIdx());
706  pcSlice->setSliceSegmentBits(0);
707  xDetermineStartAndBoundingCtuTsAddr ( startCtuTsAddr, boundingCtuTsAddr, pcPic );
708  if (bCompressEntireSlice)
709  {
710  boundingCtuTsAddr = pcSlice->getSliceCurEndCtuTsAddr();
711  pcSlice->setSliceSegmentCurEndCtuTsAddr(boundingCtuTsAddr);
712  }
713 
714  // initialize cost values - these are used by precompressSlice (they should be parameters).
715  m_uiPicTotalBits = 0;
716  m_dPicRdCost = 0; // NOTE: This is a write-only variable!
717  m_uiPicDist = 0;
718 
720  m_pcEntropyCoder->resetEntropy ( pcSlice );
721 
722  TEncBinCABAC* pRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf();
723  pRDSbacCoder->setBinCountingEnableFlag( false );
724  pRDSbacCoder->setBinsCoded( 0 );
725 
726  TComBitCounter tempBitCounter;
727  const UInt frameWidthInCtus = pcPic->getPicSym()->getFrameWidthInCtus();
728 
729  m_pcCuEncoder->setFastDeltaQp(bFastDeltaQP);
730 
731  //------------------------------------------------------------------------------
732  // Weighted Prediction parameters estimation.
733  //------------------------------------------------------------------------------
734  // calculate AC/DC values for current picture
735  if( pcSlice->getPPS()->getUseWP() || pcSlice->getPPS()->getWPBiPred() )
736  {
737  xCalcACDCParamSlice(pcSlice);
738  }
739 
740  const Bool bWp_explicit = (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPred());
741 
742  if ( bWp_explicit )
743  {
744  //------------------------------------------------------------------------------
745  // Weighted Prediction implemented at Slice level. SliceMode=2 is not supported yet.
746  //------------------------------------------------------------------------------
748  {
749  printf("Weighted Prediction is not supported with slice mode determined by max number of bins.\n"); exit(0);
750  }
751 
753  pcSlice->initWpScaling(pcSlice->getSPS());
754 
755  // check WP on/off
756  xCheckWPEnable( pcSlice );
757  }
758 
759 #if ADAPTIVE_QP_SELECTION
761  {
762  // TODO: this won't work with dependent slices: they do not have their own QP. Check fix to mask clause execution with && !(pcSlice->getDependentSliceSegmentFlag())
763  m_pcTrQuant->clearSliceARLCnt(); // TODO: this looks wrong for multiple slices - the results of all but the last slice will be cleared before they are used (all slices compressed, and then all slices encoded)
764  if(pcSlice->getSliceType()!=I_SLICE)
765  {
766  Int qpBase = pcSlice->getSliceQpBase();
767  pcSlice->setSliceQp(qpBase + m_pcTrQuant->getQpDelta(qpBase));
768  }
769  }
770 #endif
771 
772 
773 
774  // Adjust initial state if this is the start of a dependent slice.
775  {
776  const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap( startCtuTsAddr);
777  const UInt currentTileIdx = pcPic->getPicSym()->getTileIdxMap(ctuRsAddr);
778  const TComTile *pCurrentTile = pcPic->getPicSym()->getTComTile(currentTileIdx);
779  const UInt firstCtuRsAddrOfTile = pCurrentTile->getFirstCtuRsAddr();
780  if( pcSlice->getDependentSliceSegmentFlag() && ctuRsAddr != firstCtuRsAddrOfTile )
781  {
782  // This will only occur if dependent slice-segments (m_entropyCodingSyncContextState=true) are being used.
783  if( pCurrentTile->getTileWidthInCtus() >= 2 || !m_pcCfg->getEntropyCodingSyncEnabledFlag() )
784  {
786  }
787  }
788  }
789 
790  // for every CTU in the slice segment (may terminate sooner if there is a byte limit on the slice-segment)
791 
792  for( UInt ctuTsAddr = startCtuTsAddr; ctuTsAddr < boundingCtuTsAddr; ++ctuTsAddr )
793  {
794  const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddr);
795  // initialize CTU encoder
796  TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr );
797  pCtu->initCtu( pcPic, ctuRsAddr );
798 
799  // update CABAC state
800  const UInt firstCtuRsAddrOfTile = pcPic->getPicSym()->getTComTile(pcPic->getPicSym()->getTileIdxMap(ctuRsAddr))->getFirstCtuRsAddr();
801  const UInt tileXPosInCtus = firstCtuRsAddrOfTile % frameWidthInCtus;
802  const UInt ctuXPosInCtus = ctuRsAddr % frameWidthInCtus;
803 
804  if (ctuRsAddr == firstCtuRsAddrOfTile)
805  {
807  }
808  else if ( ctuXPosInCtus == tileXPosInCtus && m_pcCfg->getEntropyCodingSyncEnabledFlag())
809  {
810  // reset and then update contexts to the state at the end of the top-right CTU (if within current slice and tile).
812  // Sync if the Top-Right is available.
813  TComDataCU *pCtuUp = pCtu->getCtuAbove();
814  if ( pCtuUp && ((ctuRsAddr%frameWidthInCtus+1) < frameWidthInCtus) )
815  {
816  TComDataCU *pCtuTR = pcPic->getCtu( ctuRsAddr - frameWidthInCtus + 1 );
817  if ( pCtu->CUIsFromSameSliceAndTile(pCtuTR) )
818  {
819  // Top-Right is available, we use it.
821  }
822  }
823  }
824 
825  // set go-on entropy coder (used for all trial encodings - the cu encoder and encoder search also have a copy of the same pointer)
827  m_pcEntropyCoder->setBitstream( &tempBitCounter );
828  tempBitCounter.resetBits();
829  m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] ); // this copy is not strictly necessary here, but indicates that the GoOnSbacCoder
830  // is reset to a known state before every decision process.
831 
832  ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true);
833 
834  Double oldLambda = m_pcRdCost->getLambda();
835  if ( m_pcCfg->getUseRateCtrl() )
836  {
837  Int estQP = pcSlice->getSliceQp();
838  Double estLambda = -1.0;
839  Double bpp = -1.0;
840 
841  if ( ( pcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() )
842  {
843  estQP = pcSlice->getSliceQp();
844  }
845  else
846  {
847  bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType());
848  if ( pcPic->getSlice( 0 )->getSliceType() == I_SLICE)
849  {
850  estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambdaAndQP(bpp, pcSlice->getSliceQp(), &estQP);
851  }
852  else
853  {
854  estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
855  estQP = m_pcRateCtrl->getRCPic()->getLCUEstQP ( estLambda, pcSlice->getSliceQp() );
856  }
857 
858  estQP = Clip3( -pcSlice->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, estQP );
859 
860  m_pcRdCost->setLambda(estLambda, pcSlice->getSPS()->getBitDepths());
861 
862 #if RDOQ_CHROMA_LAMBDA
863  // set lambda for RDOQ
864  const Double chromaLambda = estLambda / m_pcRdCost->getChromaWeight();
865  const Double lambdaArray[MAX_NUM_COMPONENT] = { estLambda, chromaLambda, chromaLambda };
866  m_pcTrQuant->setLambdas( lambdaArray );
867 #else
868  m_pcTrQuant->setLambda( estLambda );
869 #endif
870  }
871 
872  m_pcRateCtrl->setRCQP( estQP );
873 #if ADAPTIVE_QP_SELECTION
874  pCtu->getSlice()->setSliceQpBase( estQP );
875 #endif
876  }
877 
878  // run CTU trial encoder
879  m_pcCuEncoder->compressCtu( pCtu );
880 
881 
882  // All CTU decisions have now been made. Restore entropy coder to an initial stage, ready to make a true encode,
883  // which will result in the state of the contexts being correct. It will also count up the number of bits coded,
884  // which is used if there is a limit of the number of bytes per slice-segment.
885 
886  m_pcEntropyCoder->setEntropyCoder ( m_pppcRDSbacCoder[0][CI_CURR_BEST] );
887  m_pcEntropyCoder->setBitstream( &tempBitCounter );
888  pRDSbacCoder->setBinCountingEnableFlag( true );
890  pRDSbacCoder->setBinsCoded( 0 );
891 
892  // encode CTU and calculate the true bit counters.
893  m_pcCuEncoder->encodeCtu( pCtu );
894 
895 
896  pRDSbacCoder->setBinCountingEnableFlag( false );
897 
898  const Int numberOfWrittenBits = m_pcEntropyCoder->getNumberOfWrittenBits();
899 
900  // Calculate if this CTU puts us over slice bit size.
901  // cannot terminate if current slice/slice-segment would be 0 Ctu in size,
902  const UInt validEndOfSliceCtuTsAddr = ctuTsAddr + (ctuTsAddr == startCtuTsAddr ? 1 : 0);
903  // Set slice end parameter
904  if(pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceBits()+numberOfWrittenBits > (pcSlice->getSliceArgument()<<3))
905  {
906  pcSlice->setSliceSegmentCurEndCtuTsAddr(validEndOfSliceCtuTsAddr);
907  pcSlice->setSliceCurEndCtuTsAddr(validEndOfSliceCtuTsAddr);
908  boundingCtuTsAddr=validEndOfSliceCtuTsAddr;
909  }
910  else if((!bCompressEntireSlice) && pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+numberOfWrittenBits > (pcSlice->getSliceSegmentArgument()<<3))
911  {
912  pcSlice->setSliceSegmentCurEndCtuTsAddr(validEndOfSliceCtuTsAddr);
913  boundingCtuTsAddr=validEndOfSliceCtuTsAddr;
914  }
915 
916  if (boundingCtuTsAddr <= ctuTsAddr)
917  {
918  break;
919  }
920 
921  pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) );
922  pcSlice->setSliceSegmentBits(pcSlice->getSliceSegmentBits()+numberOfWrittenBits);
923 
924  // Store probabilities of second CTU in line into buffer - used only if wavefront-parallel-processing is enabled.
925  if ( ctuXPosInCtus == tileXPosInCtus+1 && m_pcCfg->getEntropyCodingSyncEnabledFlag())
926  {
928  }
929 
930 
931  if ( m_pcCfg->getUseRateCtrl() )
932  {
933  Int actualQP = g_RCInvalidQPValue;
934  Double actualLambda = m_pcRdCost->getLambda();
935  Int actualBits = pCtu->getTotalBits();
936  Int numberOfEffectivePixels = 0;
937  for ( Int idx = 0; idx < pcPic->getNumPartitionsInCtu(); idx++ )
938  {
939  if ( pCtu->getPredictionMode( idx ) != NUMBER_OF_PREDICTION_MODES && ( !pCtu->isSkipped( idx ) ) )
940  {
941  numberOfEffectivePixels = numberOfEffectivePixels + 16;
942  break;
943  }
944  }
945 
946  if ( numberOfEffectivePixels == 0 )
947  {
948  actualQP = g_RCInvalidQPValue;
949  }
950  else
951  {
952  actualQP = pCtu->getQP( 0 );
953  }
954  m_pcRdCost->setLambda(oldLambda, pcSlice->getSPS()->getBitDepths());
955  m_pcRateCtrl->getRCPic()->updateAfterCTU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
956  pCtu->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
957  }
958 
959  m_uiPicTotalBits += pCtu->getTotalBits();
960  m_dPicRdCost += pCtu->getTotalCost();
961  m_uiPicDist += pCtu->getTotalDistortion();
962  }
963 
964  // 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.
965  if( pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag() )
966  {
967  m_lastSliceSegmentEndContextState.loadContexts( m_pppcRDSbacCoder[0][CI_CURR_BEST] );//ctx end of dep.slice
968  }
969 
970  // stop use of temporary bit counter object.
972  m_pcRDGoOnSbacCoder->setBitstream(NULL); // stop use of tempBitCounter.
973 
974  // TODO: optimise cabac_init during compress slice to improve multi-slice operation
975  //if (pcSlice->getPPS()->getCabacInitPresentFlag() && !pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag())
976  //{
977  // m_encCABACTableIdx = m_pcEntropyCoder->determineCabacInitIdx();
978  //}
979  //else
980  //{
981  // m_encCABACTableIdx = pcSlice->getSliceType();
982  //}
983 }
984 
985 Void TEncSlice::encodeSlice ( TComPic* pcPic, TComOutputBitstream* pcSubstreams, UInt &numBinsCoded )
986 {
987  TComSlice *const pcSlice = pcPic->getSlice(getSliceIdx());
988 
989  const UInt startCtuTsAddr = pcSlice->getSliceSegmentCurStartCtuTsAddr();
990  const UInt boundingCtuTsAddr = pcSlice->getSliceSegmentCurEndCtuTsAddr();
991 
992  const UInt frameWidthInCtus = pcPic->getPicSym()->getFrameWidthInCtus();
993  const Bool depSliceSegmentsEnabled = pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag();
994  const Bool wavefrontsEnabled = pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag();
995 
996  // initialise entropy coder for the slice
999  m_pcEntropyCoder->resetEntropy ( pcSlice );
1000 
1001  numBinsCoded = 0;
1004 
1005 #if ENC_DEC_TRACE
1006  g_bJustDoIt = g_bEncDecTraceEnable;
1007 #endif
1008  DTRACE_CABAC_VL( g_nSymbolCounter++ );
1009  DTRACE_CABAC_T( "\tPOC: " );
1010  DTRACE_CABAC_V( pcPic->getPOC() );
1011  DTRACE_CABAC_T( "\n" );
1012 #if ENC_DEC_TRACE
1013  g_bJustDoIt = g_bEncDecTraceDisable;
1014 #endif
1015 
1016 
1017  if (depSliceSegmentsEnabled)
1018  {
1019  // modify initial contexts with previous slice segment if this is a dependent slice.
1020  const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap( startCtuTsAddr );
1021  const UInt currentTileIdx=pcPic->getPicSym()->getTileIdxMap(ctuRsAddr);
1022  const TComTile *pCurrentTile=pcPic->getPicSym()->getTComTile(currentTileIdx);
1023  const UInt firstCtuRsAddrOfTile = pCurrentTile->getFirstCtuRsAddr();
1024 
1025  if( pcSlice->getDependentSliceSegmentFlag() && ctuRsAddr != firstCtuRsAddrOfTile )
1026  {
1027  if( pCurrentTile->getTileWidthInCtus() >= 2 || !wavefrontsEnabled )
1028  {
1030  }
1031  }
1032  }
1033 
1034  // for every CTU in the slice segment...
1035 
1036  for( UInt ctuTsAddr = startCtuTsAddr; ctuTsAddr < boundingCtuTsAddr; ++ctuTsAddr )
1037  {
1038  const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddr);
1039  const TComTile &currentTile = *(pcPic->getPicSym()->getTComTile(pcPic->getPicSym()->getTileIdxMap(ctuRsAddr)));
1040  const UInt firstCtuRsAddrOfTile = currentTile.getFirstCtuRsAddr();
1041  const UInt tileXPosInCtus = firstCtuRsAddrOfTile % frameWidthInCtus;
1042  const UInt tileYPosInCtus = firstCtuRsAddrOfTile / frameWidthInCtus;
1043  const UInt ctuXPosInCtus = ctuRsAddr % frameWidthInCtus;
1044  const UInt ctuYPosInCtus = ctuRsAddr / frameWidthInCtus;
1045  const UInt uiSubStrm=pcPic->getSubstreamForCtuAddr(ctuRsAddr, true, pcSlice);
1046  TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr );
1047 
1048  m_pcEntropyCoder->setBitstream( &pcSubstreams[uiSubStrm] );
1049 
1050  // set up CABAC contexts' state for this CTU
1051  if (ctuRsAddr == firstCtuRsAddrOfTile)
1052  {
1053  if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
1054  {
1055  m_pcEntropyCoder->resetEntropy(pcSlice);
1056  }
1057  }
1058  else if (ctuXPosInCtus == tileXPosInCtus && wavefrontsEnabled)
1059  {
1060  // Synchronize cabac probabilities with upper-right CTU if it's available and at the start of a line.
1061  if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
1062  {
1063  m_pcEntropyCoder->resetEntropy(pcSlice);
1064  }
1065  TComDataCU *pCtuUp = pCtu->getCtuAbove();
1066  if ( pCtuUp && ((ctuRsAddr%frameWidthInCtus+1) < frameWidthInCtus) )
1067  {
1068  TComDataCU *pCtuTR = pcPic->getCtu( ctuRsAddr - frameWidthInCtus + 1 );
1069  if ( pCtu->CUIsFromSameSliceAndTile(pCtuTR) )
1070  {
1071  // Top-right is available, so use it.
1073  }
1074  }
1075  }
1076 
1077 
1078  if ( pcSlice->getSPS()->getUseSAO() )
1079  {
1080  Bool bIsSAOSliceEnabled = false;
1081  Bool sliceEnabled[MAX_NUM_COMPONENT];
1082  for(Int comp=0; comp < MAX_NUM_COMPONENT; comp++)
1083  {
1084  ComponentID compId=ComponentID(comp);
1085  sliceEnabled[compId] = pcSlice->getSaoEnabledFlag(toChannelType(compId)) && (comp < pcPic->getNumberValidComponents());
1086  if (sliceEnabled[compId])
1087  {
1088  bIsSAOSliceEnabled=true;
1089  }
1090  }
1091  if (bIsSAOSliceEnabled)
1092  {
1093  SAOBlkParam& saoblkParam = (pcPic->getPicSym()->getSAOBlkParam())[ctuRsAddr];
1094 
1095  Bool leftMergeAvail = false;
1096  Bool aboveMergeAvail= false;
1097  //merge left condition
1098  Int rx = (ctuRsAddr % frameWidthInCtus);
1099  if(rx > 0)
1100  {
1101  leftMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-1);
1102  }
1103 
1104  //merge up condition
1105  Int ry = (ctuRsAddr / frameWidthInCtus);
1106  if(ry > 0)
1107  {
1108  aboveMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-frameWidthInCtus);
1109  }
1110 
1111  m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam, pcPic->getPicSym()->getSPS().getBitDepths(), sliceEnabled, leftMergeAvail, aboveMergeAvail);
1112  }
1113  }
1114 
1115 #if ENC_DEC_TRACE
1116  g_bJustDoIt = g_bEncDecTraceEnable;
1117 #endif
1118  m_pcCuEncoder->encodeCtu( pCtu );
1119 #if ENC_DEC_TRACE
1120  g_bJustDoIt = g_bEncDecTraceDisable;
1121 #endif
1122 
1123  //Store probabilities of second CTU in line into buffer
1124  if ( ctuXPosInCtus == tileXPosInCtus+1 && wavefrontsEnabled)
1125  {
1127  }
1128 
1129  // terminate the sub-stream, if required (end of slice-segment, end of tile, end of wavefront-CTU-row):
1130  if (ctuTsAddr+1 == boundingCtuTsAddr ||
1131  ( ctuXPosInCtus + 1 == tileXPosInCtus + currentTile.getTileWidthInCtus() &&
1132  ( ctuYPosInCtus + 1 == tileYPosInCtus + currentTile.getTileHeightInCtus() || wavefrontsEnabled)
1133  )
1134  )
1135  {
1138  // Byte-alignment in slice_data() when new tile
1139  pcSubstreams[uiSubStrm].writeByteAlignment();
1140 
1141  // write sub-stream size
1142  if (ctuTsAddr+1 != boundingCtuTsAddr)
1143  {
1144  pcSlice->addSubstreamSize( (pcSubstreams[uiSubStrm].getNumberOfWrittenBits() >> 3) + pcSubstreams[uiSubStrm].countStartCodeEmulations() );
1145  }
1146  }
1147  } // CTU-loop
1148 
1149  if( depSliceSegmentsEnabled )
1150  {
1152  }
1153 
1154 #if ADAPTIVE_QP_SELECTION
1155  if( m_pcCfg->getUseAdaptQpSelect() )
1156  {
1157  m_pcTrQuant->storeSliceQpNext(pcSlice); // TODO: this will only be storing the adaptive QP state of the very last slice-segment that is not dependent in the frame... Perhaps this should be moved to the compress slice loop.
1158  }
1159 #endif
1160 
1161  if (pcSlice->getPPS()->getCabacInitPresentFlag() && !pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag())
1162  {
1164  }
1165  else
1166  {
1167  m_encCABACTableIdx = pcSlice->getSliceType();
1168  }
1169 
1170  numBinsCoded = m_pcBinCABAC->getBinsCoded();
1171 }
1172 
1173 Void TEncSlice::calculateBoundingCtuTsAddrForSlice(UInt &startCtuTSAddrSlice, UInt &boundingCtuTSAddrSlice, Bool &haveReachedTileBoundary,
1174  TComPic* pcPic, const Int sliceMode, const Int sliceArgument)
1175 {
1176  TComSlice* pcSlice = pcPic->getSlice(getSliceIdx());
1177  const UInt numberOfCtusInFrame = pcPic->getNumberOfCtusInFrame();
1178  const TComPPS &pps=*(pcSlice->getPPS());
1179  boundingCtuTSAddrSlice=0;
1180  haveReachedTileBoundary=false;
1181 
1182  switch (sliceMode)
1183  {
1184  case FIXED_NUMBER_OF_CTU:
1185  {
1186  UInt ctuAddrIncrement = sliceArgument;
1187  boundingCtuTSAddrSlice = ((startCtuTSAddrSlice + ctuAddrIncrement) < numberOfCtusInFrame) ? (startCtuTSAddrSlice + ctuAddrIncrement) : numberOfCtusInFrame;
1188  }
1189  break;
1190  case FIXED_NUMBER_OF_BYTES:
1191  boundingCtuTSAddrSlice = numberOfCtusInFrame; // This will be adjusted later if required.
1192  break;
1193  case FIXED_NUMBER_OF_TILES:
1194  {
1195  const UInt tileIdx = pcPic->getPicSym()->getTileIdxMap( pcPic->getPicSym()->getCtuTsToRsAddrMap(startCtuTSAddrSlice) );
1196  const UInt tileTotalCount = (pcPic->getPicSym()->getNumTileColumnsMinus1()+1) * (pcPic->getPicSym()->getNumTileRowsMinus1()+1);
1197  UInt ctuAddrIncrement = 0;
1198 
1199  for(UInt tileIdxIncrement = 0; tileIdxIncrement < sliceArgument; tileIdxIncrement++)
1200  {
1201  if((tileIdx + tileIdxIncrement) < tileTotalCount)
1202  {
1203  UInt tileWidthInCtus = pcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileWidthInCtus();
1204  UInt tileHeightInCtus = pcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileHeightInCtus();
1205  ctuAddrIncrement += (tileWidthInCtus * tileHeightInCtus);
1206  }
1207  }
1208 
1209  boundingCtuTSAddrSlice = ((startCtuTSAddrSlice + ctuAddrIncrement) < numberOfCtusInFrame) ? (startCtuTSAddrSlice + ctuAddrIncrement) : numberOfCtusInFrame;
1210  }
1211  break;
1212  default:
1213  boundingCtuTSAddrSlice = numberOfCtusInFrame;
1214  break;
1215  }
1216 
1217  // Adjust for tiles and wavefronts.
1218  const Bool wavefrontsAreEnabled = pps.getEntropyCodingSyncEnabledFlag();
1219 
1220  if ((sliceMode == FIXED_NUMBER_OF_CTU || sliceMode == FIXED_NUMBER_OF_BYTES) &&
1221  (pps.getNumTileRowsMinus1() > 0 || pps.getNumTileColumnsMinus1() > 0))
1222  {
1223  const UInt ctuRSAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(startCtuTSAddrSlice);
1224  const UInt startTileIdx = pcPic->getPicSym()->getTileIdxMap(ctuRSAddr);
1225 
1226  const TComTile *pStartingTile = pcPic->getPicSym()->getTComTile(startTileIdx);
1227  const UInt tileStartTsAddr = pcPic->getPicSym()->getCtuRsToTsAddrMap(pStartingTile->getFirstCtuRsAddr());
1228  const UInt tileStartWidth = pStartingTile->getTileWidthInCtus();
1229  const UInt tileStartHeight = pStartingTile->getTileHeightInCtus();
1230  const UInt tileLastTsAddr_excl = tileStartTsAddr + tileStartWidth*tileStartHeight;
1231  const UInt tileBoundingCtuTsAddrSlice = tileLastTsAddr_excl;
1232 
1233  const UInt ctuColumnOfStartingTile = ((startCtuTSAddrSlice-tileStartTsAddr)%tileStartWidth);
1234  if (wavefrontsAreEnabled && ctuColumnOfStartingTile!=0)
1235  {
1236  // WPP: if a slice does not start at the beginning of a CTB row, it must end within the same CTB row
1237  const UInt numberOfCTUsToEndOfRow = tileStartWidth - ctuColumnOfStartingTile;
1238  const UInt wavefrontTileBoundingCtuAddrSlice = startCtuTSAddrSlice + numberOfCTUsToEndOfRow;
1239  if (wavefrontTileBoundingCtuAddrSlice < boundingCtuTSAddrSlice)
1240  {
1241  boundingCtuTSAddrSlice = wavefrontTileBoundingCtuAddrSlice;
1242  }
1243  }
1244 
1245  if (tileBoundingCtuTsAddrSlice < boundingCtuTSAddrSlice)
1246  {
1247  boundingCtuTSAddrSlice = tileBoundingCtuTsAddrSlice;
1248  haveReachedTileBoundary = true;
1249  }
1250  }
1251  else if ((sliceMode == FIXED_NUMBER_OF_CTU || sliceMode == FIXED_NUMBER_OF_BYTES) && wavefrontsAreEnabled && ((startCtuTSAddrSlice % pcPic->getFrameWidthInCtus()) != 0))
1252  {
1253  // Adjust for wavefronts (no tiles).
1254  // WPP: if a slice does not start at the beginning of a CTB row, it must end within the same CTB row
1255  boundingCtuTSAddrSlice = min(boundingCtuTSAddrSlice, startCtuTSAddrSlice - (startCtuTSAddrSlice % pcPic->getFrameWidthInCtus()) + (pcPic->getFrameWidthInCtus()));
1256  }
1257 }
1258 
1266 Void TEncSlice::xDetermineStartAndBoundingCtuTsAddr ( UInt& startCtuTsAddr, UInt& boundingCtuTsAddr, TComPic* pcPic )
1267 {
1268  TComSlice* pcSlice = pcPic->getSlice(getSliceIdx());
1269 
1270  // Non-dependent slice
1271  UInt startCtuTsAddrSlice = pcSlice->getSliceCurStartCtuTsAddr();
1272  Bool haveReachedTileBoundarySlice = false;
1273  UInt boundingCtuTsAddrSlice;
1274  calculateBoundingCtuTsAddrForSlice(startCtuTsAddrSlice, boundingCtuTsAddrSlice, haveReachedTileBoundarySlice, pcPic,
1276  pcSlice->setSliceCurEndCtuTsAddr( boundingCtuTsAddrSlice );
1277  pcSlice->setSliceCurStartCtuTsAddr( startCtuTsAddrSlice );
1278 
1279  // Dependent slice
1280  UInt startCtuTsAddrSliceSegment = pcSlice->getSliceSegmentCurStartCtuTsAddr();
1281  Bool haveReachedTileBoundarySliceSegment = false;
1282  UInt boundingCtuTsAddrSliceSegment;
1283  calculateBoundingCtuTsAddrForSlice(startCtuTsAddrSliceSegment, boundingCtuTsAddrSliceSegment, haveReachedTileBoundarySliceSegment, pcPic,
1285  if (boundingCtuTsAddrSliceSegment>boundingCtuTsAddrSlice)
1286  {
1287  boundingCtuTsAddrSliceSegment = boundingCtuTsAddrSlice;
1288  }
1289  pcSlice->setSliceSegmentCurEndCtuTsAddr( boundingCtuTsAddrSliceSegment );
1290  pcSlice->setSliceSegmentCurStartCtuTsAddr(startCtuTsAddrSliceSegment);
1291 
1292  // Make a joint decision based on reconstruction and dependent slice bounds
1293  startCtuTsAddr = max(startCtuTsAddrSlice , startCtuTsAddrSliceSegment );
1294  boundingCtuTsAddr = boundingCtuTsAddrSliceSegment;
1295 }
1296 
1298 {
1299  return 4.2005*log(lambda) + 13.7122;
1300 }
1301 
Void setDistortionWeight(const ComponentID compID, const Double distortionWeight)
Definition: TComRdCost.h:136
Int getNumTileRowsMinus1() const
Definition: TComSlice.h:1163
Double getLambda()
Definition: TComRdCost.h:142
Void init(TEncBinIf *p)
Definition: TEncSbac.h:72
Void setSliceSegmentCurEndCtuTsAddr(UInt ctuTsAddr)
Definition: TComSlice.h:1493
UInt getIntraPeriod()
Definition: TEncCfg.h:665
Void encodeSAOBlkParam(SAOBlkParam &saoBlkParam, const BitDepths &bitDepths, Bool *sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail)
Definition: TEncEntropy.h:176
Void setSliceSegmentMode(SliceConstraint mode)
Definition: TComSlice.h:1487
Void encodeSlice(TComPic *pcPic, TComOutputBitstream *pcSubstreams, UInt &numBinsCoded)
Definition: TEncSlice.cpp:985
SliceType
supported slice type
Definition: TypeDef.h:283
UInt getFirstCtuRsAddr() const
Definition: TComPicSym.h:79
Void setDeblockingFilterTcOffsetDiv2(Int i)
Definition: TComSlice.h:1408
Int m_betaOffsetDiv2
Definition: TEncCfg.h:61
TEncSbac *** getRDSbacCoder()
Definition: TEncTop.h:153
Bool isField() const
Definition: TComPic.h:166
static Int getScaledChromaQP(Int unscaledChromaQP, const ChromaFormat chFmt)
TRCLCU * getLCU()
Definition: TEncRateCtrl.h:266
Bool getEfficientFieldIRAPEnabled() const
Definition: TEncCfg.h:1156
Double getChromaWeight()
Definition: TComRdCost.h:143
UInt getCtuTsToRsAddrMap(Int ctuTsAddr) const
Definition: TComPicSym.h:183
SliceType getSliceType() const
Definition: TComSlice.h:1353
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:113
Void encodeCtu(TComDataCU *pCtu)
CTU encoding function.
Definition: TEncCu.cpp:255
TEncRateCtrl * getRateCtrl()
Definition: TEncTop.h:155
static const Int LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP
QP to use for lossless coding.
Definition: CommonDef.h:210
Int getNumTileColumnsMinus1() const
Definition: TComSlice.h:1159
Void setPicYuvResi(TComPicYuv *pcPicYuv)
Definition: TComPic.h:125
Int updateCtuDataISlice(TComDataCU *pCtu, Int width, Int height)
Definition: TEncCu.cpp:1267
Bool getUseRecalculateQPAccordingToLambda()
Definition: TEncCfg.h:1150
UInt getNumberOfCtusInFrame() const
Definition: TComPic.h:127
Bool getUseHADME()
Definition: TEncCfg.h:744
SliceConstraint getSliceMode() const
Definition: TComSlice.h:1477
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:203
Void init(TEncTop *pcEncTop)
Definition: TEncSlice.cpp:79
const TComPPSRExt & getPpsRangeExtension() const
Definition: TComSlice.h:1197
Int m_CbQPoffset
Definition: TEncCfg.h:57
Bool getSliceChromaQpFlag() const
Definition: TComSlice.h:1103
TEncGOP * getGOPEncoder()
Definition: TEncTop.h:144
best mode index
Definition: TypeDef.h:429
Void setDeblockingFilterBetaOffsetDiv2(Int i)
Definition: TComSlice.h:1407
Bool getFastMEForGenBLowDelayEnabled()
Definition: TEncCfg.h:756
Int getNumTileColumnsMinus1() const
Definition: TComPicSym.h:178
#define NULL
Definition: CommonDef.h:107
UInt64 m_uiPicTotalBits
total bits for the picture
Definition: TEncSlice.h:90
Void initCtu(TComPic *pcPic, UInt ctuRsAddr)
Definition: TComDataCU.cpp:422
TComSlice * getSlice(Int i)
Definition: TComPic.h:113
Void setPicYuvPred(TComPicYuv *pcPicYuv)
Definition: TComPic.h:124
Void addSubstreamSize(UInt size)
Definition: TComSlice.h:1525
TEncSbac *** m_pppcRDSbacCoder
storage for SBAC-based RD optimization
Definition: TEncSlice.h:88
Bool getCabacInitPresentFlag() const
Definition: TComSlice.h:1171
SliceType determineCabacInitIdx(const TComSlice *pSlice)
Definition: TEncEntropy.h:124
unsigned int UInt
Definition: TypeDef.h:212
SliceConstraint getSliceSegmentMode() const
Definition: TComSlice.h:1488
SChar * getPredictionMode()
Definition: TComDataCU.h:237
UInt getNumPartitionsInCtu() const
Definition: TComPic.h:130
Bool getUseSAO() const
Definition: TComSlice.h:908
Int getSliceSegmentArgument()
Definition: TEncCfg.h:802
Int getGOPSize()
Definition: TEncGOP.h:166
Void initEncSlice(TComPic *pcPic, const Int pocLast, const Int pocCurr, const Int iGOPid, TComSlice *&rpcSlice, const Bool isField)
preparation of slice encoding (reference marking, QP and lambda)
Definition: TEncSlice.cpp:159
Bool getForceIntraQP()
Definition: TEncCfg.h:1132
SliceType m_encCABACTableIdx
Definition: TEncSlice.h:100
Int getLCUCoded()
Definition: TEncRateCtrl.h:264
UInt getMaxCUHeight() const
Definition: TComSlice.h:859
Int getLoopFilterTcOffset()
Definition: TEncCfg.h:698
Int getNumberValidComponents() const
Definition: TComPic.h:140
Bool getPPSDeblockingFilterDisabledFlag() const
get offset for deblocking filter disabled
Definition: TComSlice.h:1177
const Int g_RCInvalidQPValue
Definition: TEncRateCtrl.h:61
Double calculateLambda(const TComSlice *pSlice, const Int GOPid, const Int depth, const Double refQP, const Double dQP, Int &iQP)
Definition: TEncSlice.cpp:433
TEncCu * m_pcCuEncoder
CU encoder.
Definition: TEncSlice.h:75
Void setSliceCurStartCtuTsAddr(UInt ctuTsAddr)
Definition: TComSlice.h:1480
TEncEntropy * getEntropyCoder()
Definition: TEncTop.h:147
TEncSbac * m_pcSbacCoder
SBAC encoder.
Definition: TEncSlice.h:82
Void setField(Bool b)
Definition: TComPic.h:165
Void setTLayer(UInt uiTLayer)
Definition: TComPic.h:102
TEncRCPic * getRCPic()
Definition: TEncRateCtrl.h:326
Bool getTransquantBypassEnabledFlag() const
Definition: TComSlice.h:1142
Int getNumRefIdx(RefPicList e) const
Definition: TComSlice.h:1370
UInt getCtuRsToTsAddrMap(Int ctuRsAddr) const
Definition: TComPicSym.h:185
class for counting bits
Bool getSaoEnabledFlag(ChannelType chType) const
Definition: TComSlice.h:1339
TEncSearch * m_pcPredSearch
encoder search class
Definition: TEncSlice.h:78
Void setPic(TComPic *p)
Definition: TComSlice.h:1413
TEncBinCABAC * m_pcBinCABAC
Bin encoder CABAC.
Definition: TEncSlice.h:83
Void setSliceBits(UInt uiVal)
Definition: TComSlice.h:1495
UInt getFrameWidthInCtus() const
Definition: TComPicSym.h:156
Bool isInterB() const
Definition: TComSlice.h:1424
Int getNumTileRowsMinus1() const
Definition: TComPicSym.h:179
Void xCheckWPEnable(TComSlice *const slice)
check weighted pred or non-weighted pred
Void setSliceSegmentArgument(UInt uiArgument)
Definition: TComSlice.h:1489
Distortion & getTotalDistortion()
Definition: TComDataCU.h:480
UInt getSliceIdx()
Definition: TEncSlice.h:134
UInt getSliceChromaOffsetQpPeriodicity() const
Definition: TEncCfg.h:626
Void precompressSlice(TComPic *pcPic)
precompress slice for multi-loop slice-level QP opt.
Definition: TEncSlice.cpp:572
Void calCostSliceI(TComPic *pcPic)
Definition: TEncSlice.cpp:663
Void setAdaptiveSearchRange(Int iDir, Int iRefIdx, Int iSearchRange)
set ME search range
Definition: TEncSearch.h:209
TEncSbac * getRDGoOnSbacCoder()
Definition: TEncTop.h:154
ChromaFormat getChromaFormatIdc()
Definition: TEncCfg.h:629
Void create(Int iWidth, Int iHeight, ChromaFormat chromaFormat, UInt iMaxCUWidth, UInt iMaxCUHeight, UChar uhTotalDepth)
Definition: TEncSlice.cpp:59
Bool getDependentSliceSegmentFlag() const
Definition: TComSlice.h:1357
Void calculateBoundingCtuTsAddrForSlice(UInt &startCtuTSAddrSlice, UInt &boundingCtuTSAddrSlice, Bool &haveReachedTileBoundary, TComPic *pcPic, const Int sliceMode, const Int sliceArgument)
Definition: TEncSlice.cpp:1173
Void loadContexts(const TEncSbac *pSrc)
Definition: TEncSbac.cpp:1978
Void storeSliceQpNext(TComSlice *pcSlice)
UInt getTileWidthInCtus() const
Definition: TComPicSym.h:71
std::vector< Int > m_viRdPicQp
array of picture QP candidates (Int-type)
Definition: TEncSlice.h:95
Bool getUseAdaptQpSelect()
Definition: TEncCfg.h:636
Double & getTotalCost()
Definition: TComDataCU.h:479
Limit maximum number of bytes in a slice / slice segment.
Definition: TypeDef.h:518
Bool getLCULevelRC()
Definition: TEncCfg.h:1126
Void setSliceType(SliceType e)
Definition: TComSlice.h:1397
TEncSbac * getSbacCoder()
Definition: TEncTop.h:149
TComList< TComPic * > * getListPic()
Definition: TEncTop.h:138
Int m_tcOffsetDiv2
Definition: TEncCfg.h:60
Void setTemporalLayerNonReferenceFlag(Bool x)
Definition: TComSlice.h:1531
Int getQpDelta(Int qp)
Definition: TComTrQuant.h:194
Int m_QPOffset
Definition: TEncCfg.h:52
Void setTotalIntraCost(Double cost)
Definition: TEncRateCtrl.h:271
UInt getTileIdxMap(Int ctuRsAddr) const
Definition: TComPicSym.h:184
Int getQpBDOffset(ChannelType type) const
Definition: TComSlice.h:904
Double getIntraQpFactor() const
Definition: TEncCfg.h:662
Bool getFastDeltaQp() const
Definition: TEncCfg.h:791
Bool getSAOMergeAvailability(Int currAddr, Int mergeAddr)
Definition: TComPic.cpp:216
bool Bool
Definition: TypeDef.h:204
Void setSliceSegmentBits(UInt uiVal)
Definition: TComSlice.h:1497
UInt getSubstreamForCtuAddr(const UInt ctuAddr, const Bool bAddressInRaster, TComSlice *pcSlice)
Definition: TComPic.cpp:223
Void setBitstream(TComBitIf *p)
Definition: TEncSbac.h:78
Double calcRdCost(Double numBits, Double distortion, DFunc eDFunc=DF_DEFAULT)
Definition: TComRdCost.cpp:62
TComRdCost * m_pcRdCost
RD cost computation.
Definition: TEncSlice.h:87
Void setDeltaQpRD(UInt u)
Definition: TEncCfg.h:741
Void encodeSliceFinish()
Definition: TEncEntropy.cpp:74
Void setSliceQpDelta(Int i)
Definition: TComSlice.h:1402
Int getSearchRange() const
Definition: TEncCfg.h:704
UInt64 m_uiPicDist
total distortion for the picture
Definition: TEncSlice.h:91
static const Int ADAPT_SR_SCALE
division factor for adaptive search range
Definition: CommonDef.h:136
PPS class.
Definition: TComSlice.h:1034
Void setLambda(Double dLambda, const BitDepths &bitDepths)
Definition: TComRdCost.cpp:109
UInt getPicHeightInLumaSamples() const
Definition: TComSlice.h:836
Void load(const TEncSbac *pSrc)
Definition: TEncSbac.cpp:396
SChar m_sliceType
Definition: TEncCfg.h:65
UInt getSliceBits() const
Definition: TComSlice.h:1496
Int getQPForPicture(const UInt gopIndex, const TComSlice *pSlice) const
Definition: TEncTop.cpp:1401
TComTrQuant * getTrQuant()
Definition: TEncTop.h:141
Int getMaxDeltaQP() const
Definition: TEncCfg.h:711
Double getLambdaModifier(UInt uiIndex) const
Definition: TEncCfg.h:658
static ChannelType toChannelType(const ComponentID id)
UInt getSliceSegmentBits() const
Definition: TComSlice.h:1498
T Clip3(const T minVal, const T maxVal, const T a)
general min/max clip
Definition: CommonDef.h:252
TEncEntropy * m_pcEntropyCoder
entropy encoder
Definition: TEncSlice.h:81
Int getSliceArgument()
Definition: TEncCfg.h:797
CostMode getCostMode() const
Definition: TEncCfg.h:1144
const std::vector< Double > & getIntraLambdaModifier() const
Definition: TEncCfg.h:660
Void setDepth(Int iDepth)
Definition: TComSlice.h:1414
Double getLCUTargetBpp(SliceType eSliceType)
reference list 0
Definition: TypeDef.h:372
Int getBitDepth(ChannelType type) const
Definition: TComSlice.h:894
TComPicYuv m_picYuvPred
prediction picture buffer
Definition: TEncSlice.h:70
Void setDeblockingFilterOverrideFlag(Bool b)
Definition: TComSlice.h:1406
slice encoder class (header)
Void compressCtu(TComDataCU *pCtu)
CTU analysis function.
Definition: TEncCu.cpp:231
Void setFastDeltaQp(Bool b)
Definition: TEncCu.h:127
RefPicList
reference list index
Definition: TypeDef.h:370
Void setSliceCurEndCtuTsAddr(UInt ctuTsAddr)
Definition: TComSlice.h:1482
Int getSliceQpBase() const
Definition: TComSlice.h:1360
TComPicSym * getPicSym()
Definition: TComPic.h:111
Void setSliceQpBase(Int i)
Definition: TComSlice.h:1400
Int getSliceChromaOffsetQpIntraOrPeriodic(Bool bIsCr) const
Definition: TEncCfg.h:625
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Definition: TypeDef.h:292
#define DTRACE_CABAC_VL(x)
Definition: TComRom.h:153
Void updateLambda(TComSlice *pSlice, Double dQP)
Definition: TEncSlice.cpp:104
unsigned char UChar
Definition: TypeDef.h:208
const BitDepths & getBitDepths() const
Definition: TComSlice.h:900
virtual ~TEncSlice()
Definition: TEncSlice.cpp:54
UInt getSliceSegmentCurStartCtuTsAddr() const
Definition: TComSlice.h:1492
Limit maximum number of largest coding tree units in a slice / slice segments.
Definition: TypeDef.h:517
TEncSbac m_lastSliceSegmentEndContextState
context storage for state at the end of the previous slice-segment (used for dependent slices only)...
Definition: TEncSlice.h:98
Bool isSkipped(UInt uiPartIdx) const
returns true, if the partiton is skipped
WeightedPredictionMethod getWeightedPredictionMethod() const
Definition: TEncCfg.h:1116
const TComPPS * getPPS() const
Definition: TComSlice.h:1332
UInt getPicWidthInLumaSamples() const
Definition: TComSlice.h:834
Void setSliceChromaQpDelta(ComponentID compID, Int i)
Definition: TComSlice.h:1403
Void setMaxNumMergeCand(UInt val)
Definition: TComSlice.h:1464
UInt & getTotalBits()
Definition: TComDataCU.h:481
std::vector< Double > m_vdRdPicQp
array of picture QP candidates (double-type for lambda)
Definition: TEncSlice.h:94
UInt getSliceArgument() const
Definition: TComSlice.h:1479
Int m_CrQPoffset
Definition: TEncCfg.h:58
Int getDepth() const
Definition: TComSlice.h:1376
Int getLambdaFromQPEnable() const
Definition: TEncCfg.h:675
UInt getSliceSegmentArgument() const
Definition: TComSlice.h:1490
Bool getUseWP() const
Definition: TComSlice.h:1134
#define DTRACE_CABAC_T(x)
Definition: TComRom.h:154
Void initWpScaling(const TComSPS *sps)
init WP table
Definition: TComSlice.cpp:1432
reference list 1
Definition: TypeDef.h:373
Void setBinsCoded(UInt uiVal)
UInt getTileHeightInCtus() const
Definition: TComPicSym.h:73
Int getLCUEstQP(Double lambda, Int clipPicQP)
Int getPOC() const
Definition: TComSlice.h:1354
const TComSPS & getSPS() const
Definition: TComPicSym.h:163
encoder class (header)
Bool getDeblockingFilterControlPresentFlag() const
Definition: TComSlice.h:1173
Void updateAfterCTU(Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter=true)
Bool getEntropyCodingSyncEnabledFlag() const
Definition: TComSlice.h:1151
Int getPOC() const
Definition: TComPic.h:115
Void xEstimateWPParamSlice(TComSlice *const slice, const WeightedPredictionMethod method)
estimate wp tables for explicit wp
Bool isInterP() const
Definition: TComSlice.h:1425
UInt getSliceCurStartCtuTsAddr() const
Definition: TComSlice.h:1481
unsigned long long UInt64
Definition: TypeDef.h:233
const GOPEntry & getGOPEntry(Int i) const
Definition: TEncCfg.h:566
TComRdCost * getRdCost()
Definition: TEncTop.h:152
TComDataCU * getCtu(UInt ctuRsAddr)
Definition: TComPic.h:116
Void setEntropyCoder(TEncEntropyIf *e)
Definition: TEncEntropy.cpp:51
TEncBinIf * getEncBinIf()
Definition: TEncSbac.h:170
Void setPOC(Int i)
Definition: TComSlice.h:1389
TComPic * getPic()
Definition: TComSlice.h:1371
const LumaLevelToDeltaQPMapping & getLumaLevelToDeltaQPMapping() const
Definition: TEncCfg.h:632
Void initSlice()
Definition: TComSlice.cpp:152
Double getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP)
Void setFrameLambda(Double dLambda)
Definition: TComRdCost.h:138
Int m_numRefPicsActive
Definition: TEncCfg.h:64
Void resetEntropy(const TComSlice *pSlice)
Definition: TEncSbac.cpp:105
Void setSliceMode(SliceConstraint mode)
Definition: TComSlice.h:1476
const Int * getdQPs() const
Definition: TEncCfg.h:789
TComDataCU * getCtuAbove()
Definition: TComDataCU.h:400
Bool getDependentSliceSegmentsEnabledFlag() const
Definition: TComSlice.h:1149
Int getQpOffset(ComponentID compID) const
Definition: TComSlice.h:1124
static const Double MAX_DOUBLE
max. value of Double-type value
Definition: CommonDef.h:116
UInt getTLayer() const
Definition: TComPic.h:101
Void setSearchRange(TComSlice *pcSlice)
set ME range adaptively
Definition: TEncSlice.cpp:546
Void setRCQP(Int QP)
Definition: TEncRateCtrl.h:322
Int m_gopID
Definition: TEncSlice.h:101
TComTile * getTComTile(UInt tileIdx)
Definition: TComPicSym.h:181
TComTrQuant * m_pcTrQuant
transform &amp; quantization
Definition: TEncSlice.h:84
Void destroy()
Definition: TEncSlice.cpp:68
Void resetBits()
Definition: TEncSbac.h:84
Bool getUseRateCtrl()
Definition: TEncCfg.h:1120
Bool getEntropyCodingSyncEnabledFlag() const
Definition: TEncCfg.h:835
Void setSliceArgument(UInt uiArgument)
Definition: TComSlice.h:1478
Void clearSliceARLCnt()
UInt getSliceSegmentCurEndCtuTsAddr() const
Definition: TComSlice.h:1494
Void create(const Int picWidth, const Int picHeight, const ChromaFormat chromaFormatIDC, const UInt maxCUWidth, const UInt maxCUHeight, const UInt maxCUDepth, const Bool bUseMargin)
if true, then a margin of uiMaxCUWidth+16 and uiMaxCUHeight+16 is created around the image...
Definition: TComPicYuv.cpp:121
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:1454
#define DTRACE_CABAC_V(x)
Definition: TComRom.h:152
Bool m_refPic
Definition: TEncCfg.h:63
int Int
Definition: TypeDef.h:211
Void setBitstream(TComBitIf *p)
Definition: TEncEntropy.h:120
Void setSliceSegmentCurStartCtuTsAddr(UInt ctuTsAddr)
Definition: TComSlice.h:1491
Bool CUIsFromSameSliceAndTile(const TComDataCU *pCU) const
Definition: TComDataCU.cpp:378
Int getMinSearchWindow() const
Definition: TEncCfg.h:707
encoder class
Definition: TEncTop.h:68
ComponentID
Definition: TypeDef.h:308
Int getSliceChromaQpDelta(ComponentID compID) const
Definition: TComSlice.h:1363
UInt getMaxNumMergeCand()
Definition: TEncCfg.h:1109
Int getSliceQp() const
Definition: TComSlice.h:1355
TEncCfg * m_pcCfg
encoder configuration class
Definition: TEncSlice.h:66
Frame-based SSE.
Definition: TypeDef.h:422
Bool isEnabled() const
Definition: TypeDef.h:894
TEncSearch * getPredSearch()
Definition: TEncTop.h:139
Void setLambdas(const Double lambdas[MAX_NUM_COMPONENT])
Definition: TComSlice.h:1427
UInt getDecodingRefreshType()
Definition: TEncCfg.h:666
SChar * getQP()
Definition: TComDataCU.h:258
SliceConstraint getSliceMode() const
Definition: TEncCfg.h:796
Bool getDeblockingFilterOverrideFlag() const
Definition: TComSlice.h:1366
SliceConstraint getSliceSegmentMode() const
Definition: TEncCfg.h:801
slices / slice segments span an integer number of tiles
Definition: TypeDef.h:519
Void xDetermineStartAndBoundingCtuTsAddr(UInt &startCtuTsAddr, UInt &boundingCtuTsAddr, TComPic *pcPic)
Definition: TEncSlice.cpp:1266
Void resetQP(TComPic *pic, Int sliceQP, Double lambda)
Definition: TEncSlice.cpp:529
Double m_dPicRdCost
picture-level RD cost
Definition: TEncSlice.h:92
Void encodeTerminatingBit(UInt uiIsLast)
Definition: TEncEntropy.cpp:67
Void setUseChromaQpAdj(Bool b)
Definition: TComSlice.h:1404
TEncCu * getCuEncoder()
Definition: TEncTop.h:146
Bool getChromaQpOffsetListEnabledFlag() const
Definition: TComSlice.h:1009
Void setDeblockingFilterDisable(Bool b)
Definition: TComSlice.h:1405
Int m_temporalId
Definition: TEncCfg.h:62
double Double
Definition: TypeDef.h:213
Bool getDeblockingFilterDisable() const
Definition: TComSlice.h:1365
std::vector< Double > m_vdRdPicLambda
array of lambda candidates
Definition: TEncSlice.h:93
Void compressSlice(TComPic *pcPic, const Bool bCompressEntireSlice, const Bool bFastDeltaQP)
analysis stage of slice
Definition: TEncSlice.cpp:698
slice header class
Definition: TComSlice.h:1225
Void setNumRefIdx(RefPicList e, Int i)
Definition: TComSlice.h:1412
Bool getWPBiPred() const
Definition: TComSlice.h:1135
TEncBinCABAC * getBinCABAC()
Definition: TEncTop.h:150
UInt getDeltaQpRD() const
Definition: TEncCfg.h:790
static const Int MAX_QP
Definition: CommonDef.h:126
Int getGOPSize()
Definition: TEncCfg.h:670
Void setPicOutputFlag(Bool b)
Definition: TComSlice.h:1336
Bool getHarmonizeGopFirstFieldCoupleEnabled() const
Definition: TEncCfg.h:1159
Int getLoopFilterBetaOffset()
Definition: TEncCfg.h:697
Void setReferenced(Bool b)
Definition: TComSlice.h:1386
Void destroy()
Definition: TComPicYuv.cpp:168
TEncRateCtrl * m_pcRateCtrl
Rate control manager.
Definition: TEncSlice.h:96
Void setSliceQp(Int i)
Definition: TComSlice.h:1398
Int getDeblockingFilterMetric()
Definition: TEncCfg.h:699
UInt getFrameWidthInCtus() const
Definition: TComPic.h:131
TComPic * getRefPic(RefPicList e, Int iRefIdx)
Definition: TComSlice.h:1373
TComPicYuv m_picYuvResi
residual picture buffer
Definition: TEncSlice.h:71
Bool getDeblockingFilterOverrideEnabledFlag() const
Definition: TComSlice.h:1175
Void resetEntropy(const TComSlice *pSlice)
Definition: TEncEntropy.h:123
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
Double m_QPFactor
Definition: TEncCfg.h:59
UInt getSliceCurEndCtuTsAddr() const
Definition: TComSlice.h:1483
TComList< TComPic * > * m_pcListPic
list of pictures
Definition: TEncSlice.h:69
Double getLCUEstLambda(Double bpp)
UInt getMaxCUWidth() const
Definition: TComSlice.h:857
TComSlice * getSlice()
Definition: TComDataCU.h:202
const TComSPS * getSPS() const
Definition: TComSlice.h:1329
Double xGetQPValueAccordingToLambda(Double lambda)
Definition: TEncSlice.cpp:1297
SPS class.
Definition: TComSlice.h:740
Void setLambdas(const Double lambdas[MAX_NUM_COMPONENT])
Definition: TComTrQuant.h:148
UInt getNumberOfWrittenBits()
Definition: TEncEntropy.h:122
SAOBlkParam * getSAOBlkParam()
Definition: TComPicSym.h:186