source: 3DVCSoftware/branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncTop.cpp @ 213

Last change on this file since 213 was 213, checked in by mitsubishi-htm, 12 years ago

A final release, as planned

  • Migrate to HTM 5.1
  • For VC project files, only VC9 file is updated
  • To be used as an additional anchor for CE1.h for 3rd JCTVC meeting at Geneva
  • Property svn:eol-style set to native
File size: 38.9 KB
Line 
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-2012, 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
34/** \file     TEncTop.cpp
35    \brief    encoder class
36*/
37
38#include "TLibCommon/CommonDef.h"
39#include "TEncTop.h"
40#include "TEncPic.h"
41#include "../../App/TAppEncoder/TAppEncTop.h"
42#if FAST_BIT_EST
43#include "TLibCommon/ContextModel.h"
44#endif
45
46//! \ingroup TLibEncoder
47//! \{
48
49// ====================================================================================================================
50// Constructor / destructor / create / destroy
51// ====================================================================================================================
52
53TEncTop::TEncTop()
54{
55  m_iPOCLast          = -1;
56  m_iNumPicRcvd       =  0;
57  m_uiNumAllPicCoded  =  0;
58  m_pppcRDSbacCoder   =  NULL;
59  m_pppcBinCoderCABAC =  NULL;
60  m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC );
61#if ENC_DEC_TRACE
62  g_hTrace = fopen( "TraceEnc.txt", "wb" );
63  g_bJustDoIt = g_bEncDecTraceDisable;
64  g_nSymbolCounter = 0;
65#endif
66
67  m_iMaxRefPicNum     = 0;
68
69#if FAST_BIT_EST
70  ContextModel::buildNextStateTable();
71#endif
72
73  m_pcSbacCoders           = NULL;
74  m_pcBinCoderCABACs       = NULL;
75  m_ppppcRDSbacCoders      = NULL;
76  m_ppppcBinCodersCABAC    = NULL;
77  m_pcRDGoOnSbacCoders     = NULL;
78  m_pcRDGoOnBinCodersCABAC = NULL;
79  m_pcBitCounters          = NULL;
80  m_pcRdCosts              = NULL;
81
82#if VSP_N
83  m_pcPicVSP = NULL;
84  m_pcPicAvail = NULL;
85#endif
86
87#if VSP_SLICE_HEADER
88  m_bUseVSP = false;
89  m_bVSPDepthDisable = false;
90  m_bIsFirstInView = false;
91#endif
92}
93
94TEncTop::~TEncTop()
95{
96#if ENC_DEC_TRACE
97  fclose( g_hTrace );
98#endif
99}
100
101Void TEncTop::create ()
102{
103  // initialize global variables
104  if( m_viewId == 0 && m_isDepth == false )
105  {
106    initROM();
107  }
108
109
110  // create processing unit classes
111  m_cGOPEncoder.        create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight );
112  m_cSliceEncoder.      create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
113  m_cCuEncoder.         create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
114  if (m_bUseSAO)
115  {
116#if SAO_UNIT_INTERLEAVING
117    m_cEncSAO.setSaoInterleavingFlag(getSaoInterleavingFlag());
118    m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic());
119#endif
120    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
121    m_cEncSAO.createEncBuffer();
122  }
123#if ADAPTIVE_QP_SELECTION
124  if (m_bUseAdaptQpSelect)
125  {
126    m_cTrQuant.initSliceQpDelta();
127  }
128#endif
129  m_cAdaptiveLoopFilter.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
130  m_cLoopFilter.        create( g_uiMaxCUDepth );
131 
132#if DEPTH_MAP_GENERATION
133  m_cDepthMapGenerator. create( false, getSourceWidth(), getSourceHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(m_uiPredDepthMapGeneration), PDM_SUB_SAMP_EXP_Y(m_uiPredDepthMapGeneration) );
134#endif
135#if HHI_INTER_VIEW_RESIDUAL_PRED
136  m_cResidualGenerator. create( false, getSourceWidth(), getSourceHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
137#endif
138
139  if(m_bUseALF)
140  {
141#if LCU_SYNTAX_ALF
142    m_cAdaptiveLoopFilter.setAlfCoefInSlice(m_bALFParamInSlice);
143    m_cAdaptiveLoopFilter.createAlfGlobalBuffers();
144#else
145    m_cAdaptiveLoopFilter.setGOPSize( getGOPSize() );
146    m_cAdaptiveLoopFilter.createAlfGlobalBuffers(m_iALFEncodePassReduction);
147#endif
148  }
149
150  if(m_bUseSAO || m_bUseALF)
151  {
152    m_vAPS.reserve(MAX_NUM_SUPPORTED_APS);
153  }
154
155  // if SBAC-based RD optimization is used
156  if( m_bUseSBACRD )
157  {
158    m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1];
159#if FAST_BIT_EST
160    m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1];
161#else
162    m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1];
163#endif
164   
165    for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
166    {
167      m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
168#if FAST_BIT_EST
169      m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
170#else
171      m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
172#endif
173     
174      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
175      {
176        m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
177#if FAST_BIT_EST
178        m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
179#else
180        m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
181#endif
182        m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
183      }
184    }
185  }
186  m_pcTAppEncTop = NULL;
187#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
188  if( g_aacWedgeLists.empty() && m_bUseDMM )
189  {
190    initWedgeLists();
191  }
192#endif
193
194#if VSP_N
195  m_pcPicVSP = new TComPic;
196  m_pcPicVSP->create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
197  m_pcPicVSP->getCurrSlice()->setViewOrderIdx( m_iViewOrderIdx );
198
199  m_pcPicAvail = new TComPic;
200  m_pcPicAvail->create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
201  m_pcPicAvail->getCurrSlice()->setViewOrderIdx( m_iViewOrderIdx );
202#endif
203}
204
205/**
206 - Allocate coders required for wavefront for the nominated number of substreams.
207 .
208 \param iNumSubstreams Determines how much information to allocate.
209 */
210Void TEncTop::createWPPCoders(Int iNumSubstreams)
211{
212  if (m_pcSbacCoders != NULL)
213    return; // already generated.
214
215  m_iNumSubstreams         = iNumSubstreams;
216  m_pcSbacCoders           = new TEncSbac       [iNumSubstreams];
217  m_pcBinCoderCABACs       = new TEncBinCABAC   [iNumSubstreams];
218  m_pcRDGoOnSbacCoders     = new TEncSbac       [iNumSubstreams];
219  m_pcRDGoOnBinCodersCABAC = new TEncBinCABAC   [iNumSubstreams];
220  m_pcBitCounters          = new TComBitCounter [iNumSubstreams];
221  m_pcRdCosts              = new TComRdCost     [iNumSubstreams];
222
223  for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ )
224  {
225    m_pcRDGoOnSbacCoders[ui].init( &m_pcRDGoOnBinCodersCABAC[ui] );
226    m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] );
227  }
228  if( m_bUseSBACRD )
229  {
230    m_ppppcRDSbacCoders      = new TEncSbac***    [iNumSubstreams];
231    m_ppppcBinCodersCABAC    = new TEncBinCABAC***[iNumSubstreams];
232    for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ )
233    {
234      m_ppppcRDSbacCoders[ui]  = new TEncSbac** [g_uiMaxCUDepth+1];
235      m_ppppcBinCodersCABAC[ui]= new TEncBinCABAC** [g_uiMaxCUDepth+1];
236     
237      for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
238      {
239        m_ppppcRDSbacCoders[ui][iDepth]  = new TEncSbac*     [CI_NUM];
240        m_ppppcBinCodersCABAC[ui][iDepth]= new TEncBinCABAC* [CI_NUM];
241
242        for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
243        {
244          m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx] = new TEncSbac;
245          m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] = new TEncBinCABAC;
246          m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx]->init( m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] );
247        }
248      }
249    }
250  }
251}
252
253Void TEncTop::destroy ()
254{
255  if(m_bUseALF)
256  {
257    m_cAdaptiveLoopFilter.destroyAlfGlobalBuffers();
258  }
259
260  for(Int i=0; i< m_vAPS.size(); i++)
261  {
262    TComAPS& cAPS = m_vAPS[i];
263    m_cGOPEncoder.freeAPS(&cAPS, &m_cSPS);
264  }
265
266  // destroy processing unit classes
267  m_cGOPEncoder.        destroy();
268  m_cSliceEncoder.      destroy();
269  m_cCuEncoder.         destroy();
270  if (m_cSPS.getUseSAO())
271  {
272    m_cEncSAO.destroy();
273    m_cEncSAO.destroyEncBuffer();
274  }
275  m_cAdaptiveLoopFilter.destroy();
276  m_cLoopFilter.        destroy();
277
278#if DEPTH_MAP_GENERATION
279  m_cDepthMapGenerator. destroy();
280#endif
281#if HHI_INTER_VIEW_RESIDUAL_PRED
282  m_cResidualGenerator. destroy();
283#endif
284
285  m_RPSList.            destroy();
286 
287  // SBAC RD
288  if( m_bUseSBACRD )
289  {
290    Int iDepth;
291    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
292    {
293      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
294      {
295        delete m_pppcRDSbacCoder[iDepth][iCIIdx];
296        delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
297      }
298    }
299   
300    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
301    {
302      delete [] m_pppcRDSbacCoder[iDepth];
303      delete [] m_pppcBinCoderCABAC[iDepth];
304    }
305   
306    delete [] m_pppcRDSbacCoder;
307    delete [] m_pppcBinCoderCABAC;
308
309    for ( UInt ui = 0; ui < m_iNumSubstreams; ui++ )
310    {
311      for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
312      {
313        for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
314        {
315          delete m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx];
316          delete m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx];
317        }
318      }
319
320      for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
321      {
322        delete [] m_ppppcRDSbacCoders  [ui][iDepth];
323        delete [] m_ppppcBinCodersCABAC[ui][iDepth];
324      }
325      delete[] m_ppppcRDSbacCoders  [ui];
326      delete[] m_ppppcBinCodersCABAC[ui];
327    }
328    delete[] m_ppppcRDSbacCoders;
329    delete[] m_ppppcBinCodersCABAC;
330  }
331  delete[] m_pcSbacCoders;
332  delete[] m_pcBinCoderCABACs;
333  delete[] m_pcRDGoOnSbacCoders; 
334  delete[] m_pcRDGoOnBinCodersCABAC;
335  delete[] m_pcBitCounters;
336  delete[] m_pcRdCosts;
337 
338  // destroy ROM
339  if(m_viewId == 0 && m_isDepth == false)
340  {
341  destroyROM();
342  }
343 
344#if VSP_N
345  if( m_pcPicVSP )
346  {
347    m_pcPicVSP->destroy();
348    delete m_pcPicVSP;
349    m_pcPicVSP = NULL;
350  }
351  if( m_pcPicAvail )
352  {
353    m_pcPicAvail->destroy();
354    delete m_pcPicAvail;
355    m_pcPicAvail = NULL;
356  }
357#endif
358
359  return;
360}
361
362Void TEncTop::init( TAppEncTop* pcTAppEncTop )
363{
364  UInt *aTable4=NULL, *aTable8=NULL;
365  UInt* aTableLastPosVlcIndex=NULL; 
366  // initialize SPS
367  xInitSPS();
368 
369  // initialize PPS
370  m_cPPS.setSPS(&m_cSPS);
371#if RPS_IN_SPS
372  m_cSPS.setRPSList(&m_RPSList);
373#else
374  m_cPPS.setRPSList(&m_RPSList);
375#endif
376  xInitPPS();
377  xInitRPS();
378
379  xInitSPSforInterViewRefs();
380  xInitPPSforTiles();
381
382  // initialize processing unit classes
383  m_cGOPEncoder.  init( this );
384  m_cSliceEncoder.init( this );
385  m_cCuEncoder.   init( this );
386 
387  m_pcTAppEncTop = pcTAppEncTop;
388
389#if DEPTH_MAP_GENERATION
390#if VIDYO_VPS_INTEGRATION
391  m_cDepthMapGenerator.init( (TComPrediction*)this->getPredSearch(), m_pcTAppEncTop->getVPSAccess(), m_pcTAppEncTop->getSPSAccess(), m_pcTAppEncTop->getAUPicAccess() );
392#else
393  m_cDepthMapGenerator.init( (TComPrediction*)this->getPredSearch(), m_pcTAppEncTop->getSPSAccess(), m_pcTAppEncTop->getAUPicAccess() );
394#endif
395#endif
396#if HHI_INTER_VIEW_RESIDUAL_PRED
397  m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator );
398#endif
399
400  // initialize transform & quantization class
401  m_pcCavlcCoder = getCavlcCoder();
402 
403  m_cTrQuant.init( g_uiMaxCUWidth, g_uiMaxCUHeight, 1 << m_uiQuadtreeTULog2MaxSize,
404                  0,
405                  aTable4, aTable8, 
406                  aTableLastPosVlcIndex, m_bUseRDOQ, true 
407#if ADAPTIVE_QP_SELECTION                 
408                  , m_bUseAdaptQpSelect
409#endif
410                  );
411 
412  // initialize encoder search class
413#if DV_V_RESTRICTION_B0037
414  m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_bUseDisparitySearchRangeRestriction, m_iVerticalDisparitySearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() );
415#else
416  m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() );
417#endif
418  if(m_bUseALF)
419  {
420    m_cAdaptiveLoopFilter.setALFEncodePassReduction( m_iALFEncodePassReduction );
421    m_cAdaptiveLoopFilter.setALFMaxNumberFilters( m_iALFMaxNumberFilters );
422#if LCU_SYNTAX_ALF
423    m_cAdaptiveLoopFilter.initPicQuadTreePartition(m_bALFPicBasedEncode );   
424#endif
425  }
426
427  m_iMaxRefPicNum = 0;
428
429#if VSP_N
430  m_pcPicVSP->setIsVsp( true );
431  m_pcPicVSP->setCurrSliceIdx( 0 );
432  m_pcPicVSP->getCurrSlice()->setSPS( this->getSPS() );
433  m_pcPicVSP->getCurrSlice()->setPPS( this->getPPS() );
434  m_pcPicVSP->getCurrSlice()->setPPSId( this->getPPS()->getPPSId() );
435  //initialize the motion vector field with zeros - How about the RefIdx ????
436  //IS THIS REALLY NECESSARY ????
437  for ( int i=0; i<m_pcPicVSP->getPicSym()->getNumberOfCUsInFrame(); i++ )
438  {
439    m_pcPicVSP->getPicSym()->getCU(i)->getCUMvField(RefPicList(0))->clearMvField();
440    m_pcPicVSP->getPicSym()->getCU(i)->getCUMvField(RefPicList(1))->clearMvField();
441  }
442#if DEPTH_MAP_GENERATION
443#if !QC_MULTI_DIS_CAN_A0097
444  // add extra pic buffers
445  Bool  bNeedPrdDepthMapBuf = ( m_uiPredDepthMapGeneration > 0 );
446  if( bNeedPrdDepthMapBuf && !m_pcPicVSP->getPredDepthMap() )
447  {
448    m_pcPicVSP->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(m_uiPredDepthMapGeneration), PDM_SUB_SAMP_EXP_Y(m_uiPredDepthMapGeneration) );
449    m_cDepthMapGenerator.clearDepthMap( m_pcPicVSP );
450  }
451#endif
452#endif
453  m_pcPicAvail->setIsVsp( true );
454  m_pcPicAvail->setCurrSliceIdx( 0 );
455  m_pcPicAvail->getCurrSlice()->setSPS( this->getSPS() );
456  m_pcPicAvail->getCurrSlice()->setPPS( this->getPPS() );
457  m_pcPicAvail->getCurrSlice()->setPPSId( this->getPPS()->getPPSId() );
458  //initialize the motion vector field with zeros - How about the RefIdx ????
459  //IS THIS REALLY NECESSARY ????
460  for ( int i=0; i<m_pcPicAvail->getPicSym()->getNumberOfCUsInFrame(); i++ )
461  {
462    m_pcPicAvail->getPicSym()->getCU(i)->getCUMvField(RefPicList(0))->clearMvField();
463    m_pcPicAvail->getPicSym()->getCU(i)->getCUMvField(RefPicList(1))->clearMvField();
464  }
465#if DEPTH_MAP_GENERATION
466#if !QC_MULTI_DIS_CAN_A0097
467  // add extra pic buffers
468  bNeedPrdDepthMapBuf = ( m_uiPredDepthMapGeneration > 0 );
469  if( bNeedPrdDepthMapBuf && !m_pcPicVSP->getPredDepthMap() )
470  {
471    m_pcPicAvail->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(m_uiPredDepthMapGeneration), PDM_SUB_SAMP_EXP_Y(m_uiPredDepthMapGeneration) );
472    m_cDepthMapGenerator.clearDepthMap( m_pcPicAvail );
473  }
474#endif
475#endif
476#endif
477}
478
479// ====================================================================================================================
480// Public member functions
481// ====================================================================================================================
482
483Void TEncTop::initNewPic( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcOrgPdmDepth )
484{
485  TComPic* pcPicCurr = NULL;
486
487  // get original YUV
488  xGetNewPicBuffer( pcPicCurr );
489  pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
490
491#if SONY_COLPIC_AVAILABILITY
492  pcPicCurr->setViewOrderIdx(m_iViewOrderIdx);
493#endif
494  pcPicCurr->setScaleOffset( m_aaiCodedScale, m_aaiCodedOffset );
495
496#if HHI_INTER_VIEW_MOTION_PRED
497  if( m_uiMultiviewMvRegMode )
498  {
499    AOF( pcOrgPdmDepth );
500    AOF( pcPicCurr->getOrgDepthMap() );
501    pcOrgPdmDepth->copyToPic( pcPicCurr->getOrgDepthMap() );
502  }
503  else
504  {
505    AOT( pcOrgPdmDepth );
506    AOT( pcPicCurr->getOrgDepthMap() );
507  }
508#endif
509
510#if DEPTH_MAP_GENERATION
511  // add extra pic buffers
512  Bool  bNeedPrdDepthMapBuf = ( m_uiPredDepthMapGeneration > 0 );
513  if( bNeedPrdDepthMapBuf && !pcPicCurr->getPredDepthMap() )
514  {
515    pcPicCurr->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(m_uiPredDepthMapGeneration), PDM_SUB_SAMP_EXP_Y(m_uiPredDepthMapGeneration) );
516  }
517#endif
518
519  // compute image characteristics
520  if ( getUseAdaptiveQP() )
521  {
522    m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
523  }
524}
525
526Void TEncTop::deletePicBuffer()
527{
528  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
529  Int iSize = Int( m_cListPic.size() );
530 
531  for ( Int i = 0; i < iSize; i++ )
532  {
533    TComPic* pcPic = *(iterPic++);
534   
535    pcPic->destroy();
536    delete pcPic;
537    pcPic = NULL;
538  }
539}
540
541/**
542 - Application has picture buffer list with size of GOP + 1
543 - Picture buffer list acts like as ring buffer
544 - End of the list has the latest picture
545 .
546 \param   bEos                true if end-of-sequence is reached
547 \param   pcPicYuvOrg         original YUV picture
548 \retval  rcListPicYuvRecOut  list of reconstruction YUV pictures
549 \retval  rcListBitstreamOut  list of output bitstreams
550 \retval  iNumEncoded         number of encoded pictures
551 */
552Void TEncTop::encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Int gopId )
553{ 
554
555  if( gopId == 0)
556  {
557    m_cGOPEncoder.initGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut); 
558  }
559
560  {
561    m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, gopId );
562  }
563 
564  if( gopId + 1 == m_cGOPEncoder.getGOPSize() )
565  {
566    iNumEncoded         = m_iNumPicRcvd;
567    m_iNumPicRcvd       = 0;
568    m_uiNumAllPicCoded += iNumEncoded;
569  }
570}
571
572
573#if HHI_INTERVIEW_SKIP || HHI_INTER_VIEW_MOTION_PRED || HHI_INTER_VIEW_RESIDUAL_PRED
574Void
575TEncTop::deleteExtraPicBuffers( Int iPoc )
576{
577  TComPic*                      pcPic = 0;
578  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
579  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
580  for( ; cIter != cEnd; cIter++ )
581  {
582    if( (*cIter)->getPOC() == iPoc )
583    {
584      pcPic = *cIter;
585      break;
586    }
587  }
588  AOF( pcPic );
589  if ( pcPic )
590  {
591#if HHI_INTER_VIEW_MOTION_PRED
592    pcPic->removeOrgDepthMapBuffer();
593#endif
594#if HHI_INTER_VIEW_RESIDUAL_PRED
595    pcPic->removeResidualBuffer   ();
596#endif
597#if HHI_INTERVIEW_SKIP
598    pcPic->removeUsedPelsMapBuffer();
599#endif
600  }
601}
602#endif
603
604Void
605TEncTop::compressMotion( Int iPoc )
606{
607  TComPic*                      pcPic = 0;
608  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
609  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
610  for( ; cIter != cEnd; cIter++ )
611  {
612    if( (*cIter)->getPOC() == iPoc )
613    {
614      pcPic = *cIter;
615      break;
616    }
617  }
618  AOF( pcPic );
619  if ( pcPic )
620  {
621    pcPic->compressMotion();
622  }
623}
624
625// ====================================================================================================================
626// Protected member functions
627// ====================================================================================================================
628
629/**
630 - Application has picture buffer list with size of GOP + 1
631 - Picture buffer list acts like as ring buffer
632 - End of the list has the latest picture
633 .
634 \retval rpcPic obtained picture buffer
635 */
636Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic )
637{
638  TComSlice::sortPicList(m_cListPic);
639 
640#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
641  if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
642#else
643  if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxNumberOfReferencePictures() + 2) )
644#endif
645  {
646    TComList<TComPic*>::iterator iterPic  = m_cListPic.begin();
647    Int iSize = Int( m_cListPic.size() );
648    for ( Int i = 0; i < iSize; i++ )
649    {
650      rpcPic = *(++iterPic);
651      if(rpcPic->getSlice(0)->isReferenced() == false)
652         break;
653    }
654  }
655  else
656  {
657        if ( getUseAdaptiveQP() )
658        {
659          TEncPic* pcEPic = new TEncPic;
660          pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 );
661          rpcPic = pcEPic;
662        }
663        else
664        {
665          rpcPic = new TComPic;
666          rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
667        }
668    m_cListPic.pushBack( rpcPic );
669  }
670#if HHI_INTERVIEW_SKIP
671  if( m_bInterViewSkip )
672  {
673    rpcPic->addUsedPelsMapBuffer();
674  }
675#endif
676  rpcPic->setReconMark (false);
677 
678  m_iPOCLast++;
679  m_iNumPicRcvd++;
680 
681#if HHI_INTER_VIEW_MOTION_PRED
682  if( m_uiMultiviewMvRegMode )
683  {
684    rpcPic->addOrgDepthMapBuffer();
685  }
686#endif
687 
688  rpcPic->getSlice(0)->setPOC( m_iPOCLast );
689  // mark it should be extended
690  rpcPic->getPicYuvRec()->setBorderExtension(false);
691  rpcPic->getPicYuvOrg()->setBorderExtension(false); 
692}
693
694Void TEncTop::xInitSPS()
695{
696  m_cSPS.setPicWidthInLumaSamples         ( m_iSourceWidth      );
697  m_cSPS.setPicHeightInLumaSamples        ( m_iSourceHeight     );
698#if PIC_CROPPING
699  m_cSPS.setPicCroppingFlag( m_croppingMode!= 0 );
700  if (m_croppingMode != 0)
701  {
702    m_cSPS.setPicCropLeftOffset( m_cropLeft );
703    m_cSPS.setPicCropRightOffset( m_cropRight );
704    m_cSPS.setPicCropTopOffset( m_cropTop );
705    m_cSPS.setPicCropBottomOffset( m_cropBottom );
706  }
707#else
708  m_cSPS.setPad           ( m_aiPad             );
709#endif
710  m_cSPS.setMaxCUWidth    ( g_uiMaxCUWidth      );
711  m_cSPS.setMaxCUHeight   ( g_uiMaxCUHeight     );
712  m_cSPS.setMaxCUDepth    ( g_uiMaxCUDepth      );
713  m_cSPS.setMinTrDepth    ( 0                   );
714  m_cSPS.setMaxTrDepth    ( 1                   );
715 
716#if !H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
717  m_cSPS.setMaxNumberOfReferencePictures(m_maxNumberOfReferencePictures);
718  m_cSPS.setNumReorderFrames(m_numReorderFrames);
719#endif
720  m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
721  m_cSPS.setUsePCM        ( m_usePCM           );
722  m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize  );
723
724  m_cSPS.setUseALF        ( m_bUseALF           );
725#if LCU_SYNTAX_ALF
726  if(m_bUseALF)
727  {
728    m_cSPS.setUseALFCoefInSlice(m_bALFParamInSlice);
729  }
730#endif
731 
732#if RWTH_SDC_DLT_B0036
733  m_cSPS.setUseDLT        ( m_bUseDLT );
734#endif
735 
736  m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize );
737  m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize );
738  m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter    );
739  m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra    );
740 
741#if LOSSLESS_CODING
742  m_cSPS.setUseLossless   ( m_useLossless  );
743#endif
744#if !PIC_CROPPING
745  m_cSPS.setUsePAD        ( m_bUsePAD           );
746#endif
747  m_cSPS.setUseLMChroma   ( m_bUseLMChroma           ); 
748 
749  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
750 
751  m_cSPS.setUseLComb    ( m_bUseLComb           );
752  m_cSPS.setLCMod       ( m_bLCMod   );
753  m_cSPS.setUseNSQT( m_useNSQT );
754 
755  Int i;
756#if HHI_AMVP_OFF
757  for ( i = 0; i < g_uiMaxCUDepth; i++ )
758  {
759    m_cSPS.setAMVPMode( i, AM_NONE );
760  }
761#else
762  for ( i = 0; i < g_uiMaxCUDepth; i++ )
763  {
764    m_cSPS.setAMVPMode( i, AM_EXPL );
765  }
766#endif
767 
768  for (i = 0; i < g_uiMaxCUDepth-1; i++ )
769  {
770    m_cSPS.setAMPAcc( i, m_useAMP );
771    //m_cSPS.setAMPAcc( i, 1 );
772  }
773
774  m_cSPS.setUseAMP ( m_useAMP );
775
776  for (i = g_uiMaxCUDepth-1; i < g_uiMaxCUDepth; i++ )
777  {
778    m_cSPS.setAMPAcc(i, 0);
779  }
780
781  m_cSPS.setBitDepth    ( g_uiBitDepth        );
782  m_cSPS.setBitIncrement( g_uiBitIncrement    );
783#if H0736_AVC_STYLE_QP_RANGE
784  m_cSPS.setQpBDOffsetY ( (Int)(6*(g_uiBitDepth + g_uiBitIncrement - 8)) );
785  m_cSPS.setQpBDOffsetC ( (Int)(6*(g_uiBitDepth + g_uiBitIncrement - 8)) );
786#endif
787
788  m_cSPS.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
789  m_cSPS.setUseSAO( m_bUseSAO );
790
791#if !H0566_TLA
792  if ( m_bTLayering )
793  {
794    Int iMaxTLayers = 1;
795    for ( i = 1; ; i++)
796    {
797      iMaxTLayers = i;
798      if ( (m_iGOPSize >> i) == 0 ) 
799      {
800        break;
801      }
802    }
803 
804    m_cSPS.setMaxTLayers( (UInt)iMaxTLayers );
805
806    Bool bTemporalIdNestingFlag = true;
807    for ( i = 0; i < m_cSPS.getMaxTLayers()-1; i++ )
808    {
809      if ( !m_abTLayerSwitchingFlag[i] )
810      {
811        bTemporalIdNestingFlag = false;
812        break;
813      }
814    }
815
816    m_cSPS.setTemporalIdNestingFlag( bTemporalIdNestingFlag );
817  }
818  else
819  {
820    m_cSPS.setMaxTLayers( 1 );
821    m_cSPS.setTemporalIdNestingFlag( false );
822  }
823#else
824  m_cSPS.setMaxTLayers( m_maxTempLayer );
825  m_cSPS.setTemporalIdNestingFlag( false );
826#endif
827#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
828  for ( i = 0; i < m_cSPS.getMaxTLayers(); i++ )
829  {
830    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
831    m_cSPS.setNumReorderPics(m_numReorderPics[i], i);
832  }
833#endif
834  m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma);
835  m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma);
836  m_cSPS.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag );
837
838  m_cSPS.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
839  m_cSPS.setUniformSpacingIdr( m_iUniformSpacingIdr );
840#if !REMOVE_TILE_DEPENDENCE
841  m_cSPS.setTileBoundaryIndependenceIdr( m_iTileBoundaryIndependenceIdr );
842#endif
843  m_cSPS.setNumColumnsMinus1( m_iNumColumnsMinus1 );
844  m_cSPS.setNumRowsMinus1( m_iNumRowsMinus1 );
845  if( m_iUniformSpacingIdr == 0 )
846  {
847    m_cSPS.setColumnWidth( m_puiColumnWidth );
848    m_cSPS.setRowHeight( m_puiRowHeight );
849  }
850  m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 );
851  m_cSPS.setUseDF( m_loopFilterOffsetInAPS );
852
853#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
854  m_cSPS.setUseDMM( m_bUseDMM );
855#endif
856
857#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER_M23723
858  m_cSPS.setUseDMM34( m_bUseDMM34 );
859#endif
860
861#if OL_QTLIMIT_PREDCODING_B0068
862  m_cSPS.setUseQTLPC( m_bUseQTLPC );
863#endif
864#if HHI_MPI
865  m_cSPS.setUseMVI( m_bUseMVI );
866#endif
867
868#if VSP_N
869  m_cSPS.setIsFirstInView( m_bIsFirstInView );
870#endif
871
872  if( m_isDepth )
873  {
874#if VSP_N
875    if( m_cSPS.getIsFirstInView() )
876      m_cSPS.initMultiviewSPSFlex     ( m_viewId, m_iViewOrderIdx, true, m_cSPS.getIsFirstInView(), m_uiCamParPrecision, m_bCamParInSliceHeader, m_aaiCodedScale, m_aaiCodedOffset );
877    else
878      m_cSPS.initMultiviewSPSDepth    ( m_viewId, m_iViewOrderIdx );
879#else
880    m_cSPS.initMultiviewSPSDepth    ( m_viewId, m_iViewOrderIdx );
881#endif
882#if DEPTH_MAP_GENERATION
883    m_cSPS.setPredDepthMapGeneration( m_viewId, true );
884#endif
885#if HHI_INTER_VIEW_RESIDUAL_PRED
886    m_cSPS.setMultiviewResPredMode  ( 0 );
887#endif
888  }
889  else
890  {
891#if QC_MVHEVC_B0046
892    m_cSPS.initMultiviewSPS   ( m_viewId);
893#else
894    m_cSPS.initMultiviewSPS           ( m_viewId, m_iViewOrderIdx, m_uiCamParPrecision, m_bCamParInSliceHeader, m_aaiCodedScale, m_aaiCodedOffset );
895#endif
896    if( m_viewId )
897    {
898#if DEPTH_MAP_GENERATION
899#if HHI_INTER_VIEW_MOTION_PRED
900      m_cSPS.setPredDepthMapGeneration( m_viewId, false, m_uiPredDepthMapGeneration, m_uiMultiviewMvPredMode, m_uiPdmPrecision, m_aaiPdmScaleNomDelta, m_aaiPdmOffset );
901#else
902      m_cSPS.setPredDepthMapGeneration( m_viewId, false, m_uiPredDepthMapGeneration, 0, m_uiPdmPrecision, m_aaiPdmScaleNomDelta, m_aaiPdmOffset );
903#endif
904#endif
905#if HHI_INTER_VIEW_RESIDUAL_PRED
906      m_cSPS.setMultiviewResPredMode  ( m_uiMultiviewResPredMode );
907#endif
908    }
909    else
910    {
911#if DEPTH_MAP_GENERATION
912      m_cSPS.setPredDepthMapGeneration( m_viewId, false );
913#endif
914#if HHI_INTER_VIEW_RESIDUAL_PRED
915      m_cSPS.setMultiviewResPredMode  ( 0 );
916#endif
917    }
918  }
919#if VSP_N
920  m_cSPS.setVspPresentFlag( m_bUseVSP );
921#if VSP_CFG
922  m_cSPS.setVspDepthPresentFlag( m_bVSPDepthDisable ? false : true );
923#endif
924#endif
925}
926
927Void TEncTop::xInitPPS()
928{
929  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
930  m_cPPS.setSliceGranularity(m_iSliceGranularity);
931#if !H0566_TLA
932  if ( m_cSPS.getTemporalIdNestingFlag() ) 
933  {
934    m_cPPS.setNumTLayerSwitchingFlags( 0 );
935    for ( UInt i = 0; i < m_cSPS.getMaxTLayers() - 1; i++ )
936    {
937      m_cPPS.setTLayerSwitchingFlag( i, true );
938    }
939  }
940  else
941  {
942    m_cPPS.setNumTLayerSwitchingFlags( m_cSPS.getMaxTLayers() - 1 );
943    for ( UInt i = 0; i < m_cPPS.getNumTLayerSwitchingFlags(); i++ )
944    {
945      m_cPPS.setTLayerSwitchingFlag( i, m_abTLayerSwitchingFlag[i] );
946    }
947  }   
948#endif
949  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
950
951#if LOSSLESS_CODING
952#if H0736_AVC_STYLE_QP_RANGE
953  Int lowestQP = - m_cSPS.getQpBDOffsetY();
954#else
955  Int lowestQP = 0;
956#endif
957
958  if(getUseLossless())
959  {
960    if ((getMaxCuDQPDepth() == 0) && (getMaxDeltaQP() == 0 ) && (getQP() == lowestQP) )
961    {
962      bUseDQP = false;
963    }
964    else
965    {
966      bUseDQP = true;
967    }
968  }
969  else
970  {
971    if(bUseDQP == false)
972    {
973      if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
974      {
975        bUseDQP = true;
976      }
977    }
978  }
979
980#else
981  if(bUseDQP == false)
982  {
983    if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
984    {
985      bUseDQP = true;
986    }
987  }
988#endif
989
990  if(bUseDQP)
991  {
992    m_cPPS.setUseDQP(true);
993    m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth );
994    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
995  }
996  else
997  {
998    m_cPPS.setUseDQP(false);
999    m_cPPS.setMaxCuDQPDepth( 0 );
1000    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
1001  }
1002
1003  m_cPPS.setChromaQpOffset   ( m_iChromaQpOffset    );
1004  m_cPPS.setChromaQpOffset2nd( m_iChromaQpOffset2nd );
1005
1006  m_cPPS.setEntropyCodingMode( 1 ); // In the PPS now, but also remains in slice header!
1007#if !WPP_SIMPLIFICATION
1008  m_cPPS.setEntropyCodingSynchro(m_iWaveFrontSynchro);
1009  m_cPPS.setCabacIstateReset(m_iWaveFrontFlush != 0);
1010#endif
1011  m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams);
1012  m_cPPS.setUseWP( m_bUseWeightPred );
1013  m_cPPS.setWPBiPredIdc( m_uiBiPredIdc );
1014  m_cPPS.setEnableTMVPFlag( m_bEnableTMVP );
1015#if H0388
1016  m_cPPS.setOutputFlagPresentFlag( false );
1017#endif
1018#if MULTIBITS_DATA_HIDING
1019  m_cPPS.setSignHideFlag(getSignHideFlag());
1020  m_cPPS.setTSIG(getTSIG());
1021#endif
1022#if DBL_CONTROL
1023  m_cPPS.setDeblockingFilterControlPresent (m_DeblockingFilterControlPresent );
1024#endif
1025#if PARALLEL_MERGE
1026  m_cPPS.setLog2ParallelMergeLevelMinus2      (LOG2_PARALLEL_MERGE_LEVEL_MINUS2);
1027#endif
1028#if CABAC_INIT_FLAG
1029  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
1030#endif
1031}
1032
1033//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
1034Void TEncTop::xInitRPS()
1035{
1036  TComReferencePictureSet*      rps;
1037 
1038  m_RPSList.create(getGOPSize()+m_extraRPSs);
1039  for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) 
1040  {
1041    GOPEntryMvc ge = getGOPEntry(i);
1042    rps = m_RPSList.getReferencePictureSet(i);
1043    rps->setNumberOfPictures(ge.m_numRefPics);
1044    rps->setNumRefIdc(ge.m_numRefIdc);
1045    Int numNeg = 0;
1046    Int numPos = 0;
1047    for( Int j = 0; j < ge.m_numRefPics; j++)
1048    {
1049      rps->setDeltaPOC(j,ge.m_referencePics[j]);
1050      rps->setUsed(j,ge.m_usedByCurrPic[j]);
1051      if(ge.m_referencePics[j]>0)
1052      {
1053        numPos++;
1054      }
1055      else
1056      {
1057        numNeg++;
1058      }
1059    }
1060    rps->setNumberOfNegativePictures(numNeg);
1061    rps->setNumberOfPositivePictures(numPos);
1062    rps->setInterRPSPrediction(ge.m_interRPSPrediction);
1063    if (ge.m_interRPSPrediction)
1064    {
1065      rps->setDeltaRIdxMinus1(ge.m_deltaRIdxMinus1);
1066      rps->setDeltaRPS(ge.m_deltaRPS);
1067      rps->setNumRefIdc(ge.m_numRefIdc);
1068      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1069      {
1070        rps->setRefIdc(j, ge.m_refIdc[j]);
1071      }
1072#if WRITE_BACK
1073      // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones
1074      // computed from the RefIdc.  This is not necessary if both are identical. Currently there is no check to see if they are identical.
1075      numNeg = 0;
1076      numPos = 0;
1077      TComReferencePictureSet*     RPSRef = m_RPSList.getReferencePictureSet(i-(ge.m_deltaRIdxMinus1+1));
1078      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1079      {
1080        if (ge.m_refIdc[j])
1081        {
1082          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
1083          rps->setDeltaPOC((numNeg+numPos),deltaPOC);
1084          rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
1085          if (deltaPOC<0)
1086          {
1087            numNeg++;
1088          }
1089          else
1090          {
1091            numPos++;
1092          }
1093        }
1094      }
1095      rps->setNumberOfNegativePictures(numNeg);
1096      rps->setNumberOfPositivePictures(numPos);
1097      rps->sortDeltaPOC();
1098#endif
1099    }
1100  }
1101 
1102}
1103
1104   // This is a function that
1105   // determines what Reference Picture Set to use
1106   // for a specific slice (with POC = POCCurr)
1107Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid,TComList<TComPic*>& listPic )
1108{
1109#if QC_REM_IDV_B0046
1110  if( (slice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR ||slice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA) && slice->getSPS()->getViewId() && POCCurr == 0 )
1111#else
1112  if( slice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDV && POCCurr == 0 )
1113#endif
1114  {
1115    TComReferencePictureSet* rps = slice->getLocalRPS();
1116    rps->setNumberOfNegativePictures(0);
1117    rps->setNumberOfPositivePictures(0);
1118    rps->setNumberOfLongtermPictures(0);
1119    rps->setNumberOfPictures(0);
1120    slice->setRPS(rps);
1121  }
1122  else
1123  {
1124    slice->setRPSidx(GOPid);
1125
1126    for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1127    {   
1128      if(m_uiIntraPeriod > 0)
1129      {
1130        if(POCCurr%m_uiIntraPeriod==m_GOPList[extraNum].m_POC)
1131        {
1132          slice->setRPSidx(extraNum);
1133        }
1134      }
1135      else
1136      {
1137        if(POCCurr==m_GOPList[extraNum].m_POC)
1138        {
1139          slice->setRPSidx(extraNum);
1140        }
1141      }
1142    }
1143
1144    slice->setRPS(getRPSList()->getReferencePictureSet(slice->getRPSidx()));
1145    slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
1146  }
1147}
1148
1149Void TEncTop::xInitSPSforInterViewRefs()
1150{
1151  // base view
1152  if( getGOPEntry( MAX_GOP ).m_POC == -1 )
1153  { 
1154    m_cSPS.setNumberOfUsableInterViewRefs( 0 );
1155    m_cSPS.setListsModificationPresentFlag( false );
1156    return;
1157  }
1158
1159  Int numberUsableInterViewRefs = 0;
1160  for( Int i = 0; i < getGOPSize()+1 && numberUsableInterViewRefs < MAX_VIEW_NUM; i++ ) 
1161  {
1162    GOPEntryMvc ge = ( i < getGOPSize() ) ? getGOPEntry( i ) : getGOPEntry( MAX_GOP );
1163    for( Int j = 0; j < ge.m_numInterViewRefPics; j++ )
1164    {
1165      // add ref view to list
1166      Bool onList = false;
1167      for( Int k = 0; k < numberUsableInterViewRefs; k++ )
1168      {
1169        if( ge.m_interViewRefs[j] == m_cSPS.getUsableInterViewRef( k ) )
1170        {
1171          onList = true;
1172          break;
1173        }
1174      }
1175      if( !onList )
1176      {
1177        m_cSPS.setUsableInterViewRef( (UInt)numberUsableInterViewRefs, ge.m_interViewRefs[j] );
1178        numberUsableInterViewRefs++;
1179      }
1180    }
1181  }
1182  m_cSPS.setNumberOfUsableInterViewRefs( numberUsableInterViewRefs );
1183
1184  // sort inter view refs
1185  for( Int j = 1; j < m_cSPS.getNumberOfUsableInterViewRefs(); j++ )
1186  { 
1187    Int deltaViewId = m_cSPS.getUsableInterViewRef( j );
1188    for( Int k = j-1; k >= 0; k-- )
1189    {
1190      Int temp = m_cSPS.getUsableInterViewRef( k );
1191      if( deltaViewId > temp )
1192      {
1193        m_cSPS.setUsableInterViewRef( k+1, temp );
1194        m_cSPS.setUsableInterViewRef( k, deltaViewId );
1195      }
1196    }
1197  }
1198
1199  m_cSPS.setListsModificationPresentFlag( true );
1200}
1201
1202Void  TEncTop::xInitPPSforTiles()
1203{
1204    m_cPPS.setColumnRowInfoPresent( m_iColumnRowInfoPresent );
1205    m_cPPS.setUniformSpacingIdr( m_iUniformSpacingIdr );
1206#if !REMOVE_TILE_DEPENDENCE
1207    m_cPPS.setTileBoundaryIndependenceIdr( m_iTileBoundaryIndependenceIdr );
1208#endif
1209    m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 );
1210    m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 );
1211    if( m_iUniformSpacingIdr == 0 )
1212    {
1213      m_cPPS.setColumnWidth( m_puiColumnWidth );
1214      m_cPPS.setRowHeight( m_puiRowHeight );
1215    }
1216    m_cPPS.setTileBehaviorControlPresentFlag( m_iTileBehaviorControlPresentFlag );
1217    m_cPPS.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
1218
1219    // # substreams is "per tile" when tiles are independent.
1220    if ( m_iWaveFrontSynchro )
1221    {
1222      m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1));
1223    }
1224}
1225
1226Void  TEncCfg::xCheckGSParameters()
1227{
1228  Int   iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth;
1229  Int   iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight;
1230  UInt  uiCummulativeColumnWidth = 0;
1231  UInt  uiCummulativeRowHeight = 0;
1232
1233  //check the column relative parameters
1234  if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) )
1235  {
1236    printf( "The number of columns is larger than the maximum allowed number of columns.\n" );
1237    exit( EXIT_FAILURE );
1238  }
1239
1240  if( m_iNumColumnsMinus1 >= iWidthInCU )
1241  {
1242    printf( "The current picture can not have so many columns.\n" );
1243    exit( EXIT_FAILURE );
1244  }
1245
1246  if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 )
1247  {
1248    for(Int i=0; i<m_iNumColumnsMinus1; i++)
1249      uiCummulativeColumnWidth += m_puiColumnWidth[i];
1250
1251    if( uiCummulativeColumnWidth >= iWidthInCU )
1252    {
1253      printf( "The width of the column is too large.\n" );
1254      exit( EXIT_FAILURE );
1255    }
1256  }
1257
1258  //check the row relative parameters
1259  if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) )
1260  {
1261    printf( "The number of rows is larger than the maximum allowed number of rows.\n" );
1262    exit( EXIT_FAILURE );
1263  }
1264
1265  if( m_iNumRowsMinus1 >= iHeightInCU )
1266  {
1267    printf( "The current picture can not have so many rows.\n" );
1268    exit( EXIT_FAILURE );
1269  }
1270
1271  if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 )
1272  {
1273    for(Int i=0; i<m_iNumRowsMinus1; i++)
1274      uiCummulativeRowHeight += m_puiRowHeight[i];
1275
1276    if( uiCummulativeRowHeight >= iHeightInCU )
1277    {
1278      printf( "The height of the row is too large.\n" );
1279      exit( EXIT_FAILURE );
1280    }
1281  }
1282}
1283
1284Void TEncTop::setTEncTopList(std::vector<TEncTop*>* pacTEncTopList )
1285{
1286  assert(m_viewId!=-1); // not to be set for single view coding
1287
1288  m_pacTEncTopList=pacTEncTopList;
1289
1290}
1291
1292Void TEncTop::printOutSummary(UInt uiNumAllPicCoded)
1293{
1294  assert (uiNumAllPicCoded == m_cAnalyzeAll.getNumPic());
1295
1296  //--CFG_KDY
1297  m_cAnalyzeAll.setFrmRate( getFrameRate() );
1298  m_cAnalyzeI.setFrmRate( getFrameRate() );
1299  m_cAnalyzeP.setFrmRate( getFrameRate() );
1300  m_cAnalyzeB.setFrmRate( getFrameRate() );
1301
1302  //-- all
1303  if(m_viewId==-1)
1304    printf( "\n\nSUMMARY --------------------------------------------------------\n" );
1305  else {
1306    if ( m_isDepth )
1307    {
1308      printf( "\n\nSUMMARY ---------------------------------------------- DEPTH %2d\n", m_viewId );
1309    }
1310    else
1311    {
1312      printf( "\n\nSUMMARY ---------------------------------------------- VIDEO %2d\n", m_viewId );
1313    }
1314  };
1315  m_cAnalyzeAll.printOut('a');
1316
1317  printf( "\n\nI Slices--------------------------------------------------------\n" );
1318  m_cAnalyzeI.printOut('i');
1319
1320  printf( "\n\nP Slices--------------------------------------------------------\n" );
1321  m_cAnalyzeP.printOut('p');
1322
1323  printf( "\n\nB Slices--------------------------------------------------------\n" );
1324  m_cAnalyzeB.printOut('b');
1325
1326//  m_cAnalyzeAll.printSummaryOut();
1327//  m_cAnalyzeI.printSummary('I');
1328//  m_cAnalyzeP.printSummary('P');
1329//  m_cAnalyzeB.printSummary('B');
1330}
1331
1332//! \}
Note: See TracBrowser for help on using the repository browser.