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

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

Initial integration of VSP into HTM 4.0.1. The version used for JCT3V-B0102 at Shanghai meeting.

  • VC9 project/solution files updated. Other Visual C++ project/solution files are not updated.
  • Linux make file updated.

TODO

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