source: SHVCSoftware/branches/SHM-5.1-dev/source/App/TAppEncoder/TAppEncTop.cpp @ 824

Last change on this file since 824 was 648, checked in by seregin, 11 years ago

set VPS VUI parameters for AVC BL

  • Property svn:eol-style set to native
File size: 89.2 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-2014, 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     TAppEncTop.cpp
35    \brief    Encoder application class
36*/
37
38#include <list>
39#include <fstream>
40#include <stdlib.h>
41#include <stdio.h>
42#include <fcntl.h>
43#include <assert.h>
44
45#include "TAppEncTop.h"
46#include "TLibEncoder/AnnexBwrite.h"
47
48using namespace std;
49
50//! \ingroup TAppEncoder
51//! \{
52
53// ====================================================================================================================
54// Constructor / destructor / initialization / destroy
55// ====================================================================================================================
56
57TAppEncTop::TAppEncTop()
58{
59  m_iFrameRcvd = 0;
60  m_totalBytes = 0;
61  m_essentialBytes = 0;
62#if SVC_EXTENSION
63  for(UInt layer=0; layer < MAX_LAYERS; layer++)
64  {
65    m_apcTEncTop[layer] = &m_acTEncTop[layer];
66  }
67#endif
68}
69
70TAppEncTop::~TAppEncTop()
71{
72}
73
74#if SVC_EXTENSION
75Void TAppEncTop::xInitLibCfg()
76{
77  TComVPS* vps = m_acTEncTop[0].getVPS();
78
79  vps->setMaxTLayers                       ( m_maxTempLayer );
80  if (m_maxTempLayer == 1)
81  {
82    vps->setTemporalNestingFlag(true);
83  }
84#if !VPS_RENAME
85  vps.setMaxLayers                        ( 1 );
86#endif
87  for(Int i = 0; i < MAX_TLAYER; i++)
88  {
89    vps->setNumReorderPics                 ( m_numReorderPics[i], i );
90    vps->setMaxDecPicBuffering             ( m_maxDecPicBuffering[i], i );
91  }
92
93#if REPN_FORMAT_IN_VPS
94  vps->setRepFormatIdxPresentFlag( true );   // Could be disabled to optimize in some cases.
95  Int maxRepFormatIdx = -1;
96  Int formatIdx = -1;
97  for(UInt layer=0; layer < m_numLayers; layer++)
98  {
99    // Auto generation of the format index
100    if( m_acLayerCfg[layer].getRepFormatIdx() == -1 )
101    {     
102      Bool found = false;
103      for( UInt idx = 0; idx < layer; idx++ )
104      {
105        if( m_acLayerCfg[layer].getSourceWidth() == m_acLayerCfg[idx].getSourceWidth() && m_acLayerCfg[layer].getSourceHeight() == m_acLayerCfg[idx].getSourceHeight()
106#if AUXILIARY_PICTURES
107          && m_acLayerCfg[layer].getChromaFormatIDC() == m_acLayerCfg[idx].getChromaFormatIDC()
108#endif
109#if O0194_DIFFERENT_BITDEPTH_EL_BL
110          && m_acLayerCfg[layer].m_internalBitDepthY == m_acLayerCfg[idx].m_internalBitDepthY && m_acLayerCfg[layer].m_internalBitDepthC == m_acLayerCfg[idx].m_internalBitDepthC
111#endif
112          )
113        {
114          found = true;
115          break;
116        }
117      }
118      if( !found )
119      {
120        formatIdx++;
121      }
122
123      m_acLayerCfg[layer].setRepFormatIdx( formatIdx );
124    }
125
126    assert( m_acLayerCfg[layer].getRepFormatIdx() != -1 && "RepFormatIdx not assigned for a layer" );
127    vps->setVpsRepFormatIdx( layer, m_acLayerCfg[layer].getRepFormatIdx() );
128    maxRepFormatIdx = std::max( m_acLayerCfg[layer].getRepFormatIdx(), maxRepFormatIdx );
129  }
130  assert( vps->getVpsRepFormatIdx( 0 ) == 0 );  // Base layer should point to the first one.
131  Int* mapIdxToLayer = new Int[maxRepFormatIdx + 1];
132  // Check that all the indices from 0 to maxRepFormatIdx are used in the VPS
133  for(Int i = 0; i <= maxRepFormatIdx; i++)
134  {
135    mapIdxToLayer[i] = -1;
136    UInt layer;
137    for(layer=0; layer < m_numLayers; layer++)
138    {
139      if( vps->getVpsRepFormatIdx(layer) == i )
140      {
141        mapIdxToLayer[i] = layer;
142        break;
143      }
144    }
145    assert( layer != m_numLayers );   // One of the VPS Rep format indices not set
146  }
147  vps->setVpsNumRepFormats( maxRepFormatIdx + 1 );
148  for(UInt idx=0; idx < vps->getVpsNumRepFormats(); idx++)
149  {
150    RepFormat *repFormat = vps->getVpsRepFormat( idx );
151#if REPN_FORMAT_CONTROL_FLAG
152    repFormat->setChromaAndBitDepthVpsPresentFlag( true ); 
153    if (idx==0)
154    {
155      assert(repFormat->getChromaAndBitDepthVpsPresentFlag() == true); 
156    }
157#endif
158    repFormat->setPicWidthVpsInLumaSamples  ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceWidth()   );
159    repFormat->setPicHeightVpsInLumaSamples ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceHeight()  );
160#if AUXILIARY_PICTURES
161    repFormat->setChromaFormatVpsIdc        ( m_acLayerCfg[mapIdxToLayer[idx]].getChromaFormatIDC() );
162#else
163    repFormat->setChromaFormatVpsIdc        ( 1                                             );  // Need modification to change for each layer - corresponds to 420
164#endif
165    repFormat->setSeparateColourPlaneVpsFlag( 0                                             );  // Need modification to change for each layer
166#if O0194_DIFFERENT_BITDEPTH_EL_BL
167    repFormat->setBitDepthVpsLuma           ( getInternalBitDepthY(mapIdxToLayer[idx])      );  // Need modification to change for each layer
168    repFormat->setBitDepthVpsChroma         ( getInternalBitDepthC(mapIdxToLayer[idx])      );  // Need modification to change for each layer
169#else
170    repFormat->setBitDepthVpsLuma           ( getInternalBitDepthY()                        );  // Need modification to change for each layer
171    repFormat->setBitDepthVpsChroma         ( getInternalBitDepthC()                        );  // Need modification to change for each layer
172#endif
173#if HIGHER_LAYER_IRAP_SKIP_FLAG
174    m_acTEncTop[mapIdxToLayer[idx]].setSkipPictureAtArcSwitch( m_skipPictureAtArcSwitch );
175#endif
176  }
177  delete [] mapIdxToLayer;
178#endif
179
180  for(UInt layer=0; layer<m_numLayers; layer++)
181  {
182#if O0194_DIFFERENT_BITDEPTH_EL_BL
183    //1
184    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
185    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
186
187    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
188    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
189
190    // Set this to be used in Upsampling filter in function "TComUpsampleFilter::upsampleBasePic"
191    g_bitDepthYLayer[layer] = g_bitDepthY;
192    g_bitDepthCLayer[layer] = g_bitDepthC;
193
194#if O0194_WEIGHTED_PREDICTION_CGS
195    m_acTEncTop[layer].setInterLayerWeightedPredFlag( m_useInterLayerWeightedPred );
196#endif
197#endif
198    //m_acTEncTop[layer].setVPS(&vps);
199    m_acTEncTop[layer].setFrameRate                    ( m_acLayerCfg[layer].getFrameRate() );
200    m_acTEncTop[layer].setFrameSkip                    ( m_FrameSkip );
201    m_acTEncTop[layer].setSourceWidth                  ( m_acLayerCfg[layer].getSourceWidth() );
202    m_acTEncTop[layer].setSourceHeight                 ( m_acLayerCfg[layer].getSourceHeight() );
203    m_acTEncTop[layer].setConformanceMode              ( m_acLayerCfg[layer].getConformanceMode() );
204    m_acTEncTop[layer].setConformanceWindow            ( m_acLayerCfg[layer].m_confLeft, m_acLayerCfg[layer].m_confRight, m_acLayerCfg[layer].m_confTop, m_acLayerCfg[layer].m_confBottom );
205    m_acTEncTop[layer].setFramesToBeEncoded            ( m_framesToBeEncoded );
206
207    m_acTEncTop[layer].setProfile(m_profile);
208    m_acTEncTop[layer].setLevel(m_levelTier, m_level);
209    m_acTEncTop[layer].setProgressiveSourceFlag(m_progressiveSourceFlag);
210    m_acTEncTop[layer].setInterlacedSourceFlag(m_interlacedSourceFlag);
211    m_acTEncTop[layer].setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
212    m_acTEncTop[layer].setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
213
214#if REF_IDX_MFM
215#if AVC_BASE
216    m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : ( m_avcBaseLayerFlag ? AVC_SYNTAX : true ) && m_acLayerCfg[layer].getNumMotionPredRefLayers());
217#else
218    m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : ( m_acLayerCfg[layer].getNumMotionPredRefLayers() > 0 ) );
219#endif
220#endif
221    // set layer ID
222    m_acTEncTop[layer].setLayerId ( layer );
223    m_acTEncTop[layer].setNumLayer ( m_numLayers );
224    m_acTEncTop[layer].setLayerEnc(m_apcTEncTop);
225
226    //====== Coding Structure ========
227    m_acTEncTop[layer].setIntraPeriod                  ( m_acLayerCfg[layer].m_iIntraPeriod );
228    m_acTEncTop[layer].setDecodingRefreshType          ( m_iDecodingRefreshType );
229    m_acTEncTop[layer].setGOPSize                      ( m_iGOPSize );
230    m_acTEncTop[layer].setGopList                      ( m_GOPList );
231
232    m_acTEncTop[layer].setExtraRPSs                    ( m_extraRPSs );
233    for(Int i = 0; i < MAX_TLAYER; i++)
234    {
235      m_acTEncTop[layer].setNumReorderPics             ( m_numReorderPics[i], i );
236      m_acTEncTop[layer].setMaxDecPicBuffering         ( m_maxDecPicBuffering[i], i );
237    }
238    for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
239    {
240      m_acTEncTop[layer].setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
241    }
242    m_acTEncTop[layer].setQP                           ( m_acLayerCfg[layer].getIntQP() );
243
244    m_acTEncTop[layer].setPad                          ( m_acLayerCfg[layer].getPad() );
245
246    m_acTEncTop[layer].setMaxTempLayer                 ( m_maxTempLayer );
247    m_acTEncTop[layer].setUseAMP( m_enableAMP );
248#if N0120_MAX_TID_REF_CFG
249    if (layer<m_numLayers-1)
250    {
251       m_acTEncTop[layer].setMaxTidIlRefPicsPlus1 ( m_acLayerCfg[layer].getMaxTidIlRefPicsPlus1());
252    }
253#endif
254#if VPS_EXTN_DIRECT_REF_LAYERS
255    if(layer)
256    {
257      for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++)
258      {
259        m_acTEncTop[layer].setSamplePredEnabledFlag(i, false);
260        m_acTEncTop[layer].setMotionPredEnabledFlag(i, false);
261      }
262      if(m_acLayerCfg[layer].getNumSamplePredRefLayers() == -1)
263      {
264        // Not included in the configuration file; assume that each layer depends on previous layer
265        m_acTEncTop[layer].setNumSamplePredRefLayers   (1);      // One sample pred ref. layer
266        m_acTEncTop[layer].setSamplePredRefLayerId     (0, layer - 1);   // Previous layer
267        m_acTEncTop[layer].setSamplePredEnabledFlag    (layer - 1, true);
268      }
269      else
270      {
271        m_acTEncTop[layer].setNumSamplePredRefLayers   ( m_acLayerCfg[layer].getNumSamplePredRefLayers() );
272        for(Int i = 0; i < m_acTEncTop[layer].getNumSamplePredRefLayers(); i++)
273        {
274          m_acTEncTop[layer].setSamplePredRefLayerId   ( i, m_acLayerCfg[layer].getSamplePredRefLayerId(i));
275          m_acTEncTop[layer].setSamplePredEnabledFlag  (m_acLayerCfg[layer].getSamplePredRefLayerId(i), true);
276        }
277      }
278      if(m_acLayerCfg[layer].getNumMotionPredRefLayers() == -1)
279      {
280        // Not included in the configuration file; assume that each layer depends on previous layer
281        m_acTEncTop[layer].setNumMotionPredRefLayers   (1);      // One motion pred ref. layer
282        m_acTEncTop[layer].setMotionPredRefLayerId     (0, layer - 1);   // Previous layer
283        m_acTEncTop[layer].setMotionPredEnabledFlag    (layer - 1, true);
284      }
285      else
286      {
287        m_acTEncTop[layer].setNumMotionPredRefLayers   ( m_acLayerCfg[layer].getNumMotionPredRefLayers() );
288        for(Int i = 0; i < m_acTEncTop[layer].getNumMotionPredRefLayers(); i++)
289        {
290          m_acTEncTop[layer].setMotionPredRefLayerId   ( i, m_acLayerCfg[layer].getMotionPredRefLayerId(i));
291          m_acTEncTop[layer].setMotionPredEnabledFlag  (m_acLayerCfg[layer].getMotionPredRefLayerId(i), true);
292        }
293      }
294      Int numDirectRefLayers = 0;
295      for (Int i = 0; i < layer; i++)
296      {
297        if (m_acTEncTop[layer].getSamplePredEnabledFlag(i) || m_acTEncTop[layer].getMotionPredEnabledFlag(i))
298        {
299          m_acTEncTop[layer].setRefLayerId(numDirectRefLayers, i);
300          numDirectRefLayers++;
301        }
302      }
303      m_acTEncTop[layer].setNumDirectRefLayers(numDirectRefLayers);
304
305      if(m_acLayerCfg[layer].getNumActiveRefLayers() == -1)
306      {
307        m_acTEncTop[layer].setNumActiveRefLayers( m_acTEncTop[layer].getNumDirectRefLayers() );
308        for( Int i = 0; i < m_acTEncTop[layer].getNumActiveRefLayers(); i++ )
309        {
310          m_acTEncTop[layer].setPredLayerId(i, i);
311        }
312      }
313      else
314      {
315        m_acTEncTop[layer].setNumActiveRefLayers       ( m_acLayerCfg[layer].getNumActiveRefLayers() );
316        for(Int i = 0; i < m_acTEncTop[layer].getNumActiveRefLayers(); i++)
317        {
318          m_acTEncTop[layer].setPredLayerId             ( i, m_acLayerCfg[layer].getPredLayerId(i));
319        }
320      }
321    }
322#endif //VPS_EXTN_DIRECT_REF_LAYERS
323    //===== Slice ========
324
325    //====== Loop/Deblock Filter ========
326    m_acTEncTop[layer].setLoopFilterDisable            ( m_bLoopFilterDisable       );
327    m_acTEncTop[layer].setLoopFilterOffsetInPPS        ( m_loopFilterOffsetInPPS );
328    m_acTEncTop[layer].setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
329    m_acTEncTop[layer].setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
330    m_acTEncTop[layer].setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
331    m_acTEncTop[layer].setDeblockingFilterMetric       ( m_DeblockingFilterMetric );
332
333    //====== Motion search ========
334    m_acTEncTop[layer].setFastSearch                   ( m_iFastSearch  );
335    m_acTEncTop[layer].setSearchRange                  ( m_iSearchRange );
336    m_acTEncTop[layer].setBipredSearchRange            ( m_bipredSearchRange );
337
338    //====== Quality control ========
339    m_acTEncTop[layer].setMaxDeltaQP                   ( m_iMaxDeltaQP  );
340    m_acTEncTop[layer].setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
341
342    m_acTEncTop[layer].setChromaCbQpOffset             ( m_cbQpOffset     );
343    m_acTEncTop[layer].setChromaCrQpOffset             ( m_crQpOffset  );
344
345#if ADAPTIVE_QP_SELECTION
346    m_acTEncTop[layer].setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
347#endif
348   
349    m_acTEncTop[layer].setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
350    m_acTEncTop[layer].setQPAdaptationRange            ( m_iQPAdaptationRange );
351
352    //====== Tool list ========   
353    m_acTEncTop[layer].setDeltaQpRD                    ( m_uiDeltaQpRD  );
354    m_acTEncTop[layer].setUseASR                       ( m_bUseASR      );
355    m_acTEncTop[layer].setUseHADME                     ( m_bUseHADME    );   
356    m_acTEncTop[layer].setdQPs                         ( m_acLayerCfg[layer].getdQPs() );
357    m_acTEncTop[layer].setUseRDOQ                      ( m_useRDOQ     );
358    m_acTEncTop[layer].setUseRDOQTS                    ( m_useRDOQTS   );
359    m_acTEncTop[layer].setRDpenalty                    ( m_rdPenalty );
360#if LAYER_CTB
361    m_acTEncTop[layer].setQuadtreeTULog2MaxSize        ( m_acLayerCfg[layer].m_uiQuadtreeTULog2MaxSize );
362    m_acTEncTop[layer].setQuadtreeTULog2MinSize        ( m_acLayerCfg[layer].m_uiQuadtreeTULog2MinSize );
363    m_acTEncTop[layer].setQuadtreeTUMaxDepthInter      ( m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthInter );
364    m_acTEncTop[layer].setQuadtreeTUMaxDepthIntra      ( m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthIntra );
365#else
366    m_acTEncTop[layer].setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
367    m_acTEncTop[layer].setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
368    m_acTEncTop[layer].setQuadtreeTUMaxDepthInter      ( m_uiQuadtreeTUMaxDepthInter );
369    m_acTEncTop[layer].setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
370#endif
371    m_acTEncTop[layer].setUseFastEnc                   ( m_bUseFastEnc  );
372    m_acTEncTop[layer].setUseEarlyCU                   ( m_bUseEarlyCU  );
373    m_acTEncTop[layer].setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
374    m_acTEncTop[layer].setUseCbfFastMode               ( m_bUseCbfFastMode  );
375    m_acTEncTop[layer].setUseEarlySkipDetection        ( m_useEarlySkipDetection );
376#if FAST_INTRA_SHVC
377    m_acTEncTop[layer].setUseFastIntraScalable         ( m_useFastIntraScalable );
378#endif
379
380    m_acTEncTop[layer].setUseTransformSkip             ( m_useTransformSkip      );
381    m_acTEncTop[layer].setUseTransformSkipFast         ( m_useTransformSkipFast  );
382    m_acTEncTop[layer].setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
383    m_acTEncTop[layer].setPCMLog2MinSize               ( m_uiPCMLog2MinSize);
384    m_acTEncTop[layer].setUsePCM                       ( m_usePCM );
385    m_acTEncTop[layer].setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
386    m_acTEncTop[layer].setMaxNumMergeCand              ( m_maxNumMergeCand );
387
388
389    //====== Weighted Prediction ========
390    m_acTEncTop[layer].setUseWP                   ( m_useWeightedPred      );
391    m_acTEncTop[layer].setWPBiPred                ( m_useWeightedBiPred   );
392#if O0194_WEIGHTED_PREDICTION_CGS
393    if( layer != 0 && m_useInterLayerWeightedPred )
394    {
395      // Enable weighted prediction for enhancement layer
396      m_acTEncTop[layer].setUseWP                 ( true   );
397      m_acTEncTop[layer].setWPBiPred              ( true   );
398    }
399#endif
400    //====== Parallel Merge Estimation ========
401    m_acTEncTop[layer].setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 );
402
403    //====== Slice ========
404    m_acTEncTop[layer].setSliceMode               ( m_sliceMode                );
405    m_acTEncTop[layer].setSliceArgument           ( m_sliceArgument            );
406
407    //====== Dependent Slice ========
408    m_acTEncTop[layer].setSliceSegmentMode        ( m_sliceSegmentMode         );
409    m_acTEncTop[layer].setSliceSegmentArgument    ( m_sliceSegmentArgument     );
410#if LAYER_CTB
411    Int iNumPartInCU = 1<<(m_acLayerCfg[layer].m_uiMaxCUDepth<<1);
412#else
413    Int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
414#endif
415    if(m_sliceSegmentMode==FIXED_NUMBER_OF_LCU)
416    {
417      m_acTEncTop[layer].setSliceSegmentArgument ( m_sliceSegmentArgument * iNumPartInCU );
418    }
419    if(m_sliceMode==FIXED_NUMBER_OF_LCU)
420    {
421      m_acTEncTop[layer].setSliceArgument ( m_sliceArgument * iNumPartInCU );
422    }
423    if(m_sliceMode==FIXED_NUMBER_OF_TILES)
424    {
425      m_acTEncTop[layer].setSliceArgument ( m_sliceArgument );
426    }
427
428    if(m_sliceMode == 0 )
429    {
430      m_bLFCrossSliceBoundaryFlag = true;
431    }
432    m_acTEncTop[layer].setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
433    m_acTEncTop[layer].setUseSAO ( m_bUseSAO );
434    m_acTEncTop[layer].setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
435
436    m_acTEncTop[layer].setSaoLcuBoundary (m_saoLcuBoundary);
437    m_acTEncTop[layer].setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
438    m_acTEncTop[layer].setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
439
440    m_acTEncTop[layer].setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
441    m_acTEncTop[layer].setRecoveryPointSEIEnabled( m_recoveryPointSEIEnabled );
442    m_acTEncTop[layer].setBufferingPeriodSEIEnabled( m_bufferingPeriodSEIEnabled );
443    m_acTEncTop[layer].setPictureTimingSEIEnabled( m_pictureTimingSEIEnabled );
444    m_acTEncTop[layer].setToneMappingInfoSEIEnabled                 ( m_toneMappingInfoSEIEnabled );
445    m_acTEncTop[layer].setTMISEIToneMapId                           ( m_toneMapId );
446    m_acTEncTop[layer].setTMISEIToneMapCancelFlag                   ( m_toneMapCancelFlag );
447    m_acTEncTop[layer].setTMISEIToneMapPersistenceFlag              ( m_toneMapPersistenceFlag );
448    m_acTEncTop[layer].setTMISEICodedDataBitDepth                   ( m_toneMapCodedDataBitDepth );
449    m_acTEncTop[layer].setTMISEITargetBitDepth                      ( m_toneMapTargetBitDepth );
450    m_acTEncTop[layer].setTMISEIModelID                             ( m_toneMapModelId );
451    m_acTEncTop[layer].setTMISEIMinValue                            ( m_toneMapMinValue );
452    m_acTEncTop[layer].setTMISEIMaxValue                            ( m_toneMapMaxValue );
453    m_acTEncTop[layer].setTMISEISigmoidMidpoint                     ( m_sigmoidMidpoint );
454    m_acTEncTop[layer].setTMISEISigmoidWidth                        ( m_sigmoidWidth );
455    m_acTEncTop[layer].setTMISEIStartOfCodedInterva                 ( m_startOfCodedInterval );
456    m_acTEncTop[layer].setTMISEINumPivots                           ( m_numPivots );
457    m_acTEncTop[layer].setTMISEICodedPivotValue                     ( m_codedPivotValue );
458    m_acTEncTop[layer].setTMISEITargetPivotValue                    ( m_targetPivotValue );
459    m_acTEncTop[layer].setTMISEICameraIsoSpeedIdc                   ( m_cameraIsoSpeedIdc );
460    m_acTEncTop[layer].setTMISEICameraIsoSpeedValue                 ( m_cameraIsoSpeedValue );
461    m_acTEncTop[layer].setTMISEIExposureCompensationValueSignFlag   ( m_exposureCompensationValueSignFlag );
462    m_acTEncTop[layer].setTMISEIExposureCompensationValueNumerator  ( m_exposureCompensationValueNumerator );
463    m_acTEncTop[layer].setTMISEIExposureCompensationValueDenomIdc   ( m_exposureCompensationValueDenomIdc );
464    m_acTEncTop[layer].setTMISEIRefScreenLuminanceWhite             ( m_refScreenLuminanceWhite );
465    m_acTEncTop[layer].setTMISEIExtendedRangeWhiteLevel             ( m_extendedRangeWhiteLevel );
466    m_acTEncTop[layer].setTMISEINominalBlackLevelLumaCodeValue      ( m_nominalBlackLevelLumaCodeValue );
467    m_acTEncTop[layer].setTMISEINominalWhiteLevelLumaCodeValue      ( m_nominalWhiteLevelLumaCodeValue );
468    m_acTEncTop[layer].setTMISEIExtendedWhiteLevelLumaCodeValue     ( m_extendedWhiteLevelLumaCodeValue );
469    m_acTEncTop[layer].setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled );
470    m_acTEncTop[layer].setFramePackingArrangementSEIType( m_framePackingSEIType );
471    m_acTEncTop[layer].setFramePackingArrangementSEIId( m_framePackingSEIId );
472    m_acTEncTop[layer].setFramePackingArrangementSEIQuincunx( m_framePackingSEIQuincunx );
473    m_acTEncTop[layer].setFramePackingArrangementSEIInterpretation( m_framePackingSEIInterpretation );
474    m_acTEncTop[layer].setDisplayOrientationSEIAngle( m_displayOrientationSEIAngle );
475    m_acTEncTop[layer].setTemporalLevel0IndexSEIEnabled( m_temporalLevel0IndexSEIEnabled );
476    m_acTEncTop[layer].setGradualDecodingRefreshInfoEnabled( m_gradualDecodingRefreshInfoEnabled );
477    m_acTEncTop[layer].setDecodingUnitInfoSEIEnabled( m_decodingUnitInfoSEIEnabled );
478#if LAYERS_NOT_PRESENT_SEI
479    m_acTEncTop[layer].setLayersNotPresentSEIEnabled( m_layersNotPresentSEIEnabled );
480#endif
481    m_acTEncTop[layer].setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled );
482    m_acTEncTop[layer].setScalableNestingSEIEnabled( m_scalableNestingSEIEnabled );
483#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
484    m_acTEncTop[layer].setInterLayerConstrainedTileSetsSEIEnabled( m_interLayerConstrainedTileSetsSEIEnabled );
485    m_acTEncTop[layer].setIlNumSetsInMessage( m_ilNumSetsInMessage );
486    m_acTEncTop[layer].setSkippedTileSetPresentFlag( m_skippedTileSetPresentFlag );
487    m_acTEncTop[layer].setTopLeftTileIndex( m_topLeftTileIndex );
488    m_acTEncTop[layer].setBottomRightTileIndex( m_bottomRightTileIndex );
489    m_acTEncTop[layer].setIlcIdc( m_ilcIdc );
490#endif
491    m_acTEncTop[layer].setUniformSpacingIdr          ( m_iUniformSpacingIdr );
492    m_acTEncTop[layer].setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
493    m_acTEncTop[layer].setNumRowsMinus1              ( m_iNumRowsMinus1 );
494    if(m_iUniformSpacingIdr==0)
495    {
496      m_acTEncTop[layer].setColumnWidth              ( m_pColumnWidth );
497      m_acTEncTop[layer].setRowHeight                ( m_pRowHeight );
498    }
499    m_acTEncTop[layer].xCheckGSParameters();
500    Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
501    if(uiTilesCount == 1)
502    {
503      m_bLFCrossTileBoundaryFlag = true;
504    }
505    m_acTEncTop[layer].setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
506    m_acTEncTop[layer].setWaveFrontSynchro           ( m_iWaveFrontSynchro );
507    m_acTEncTop[layer].setWaveFrontSubstreams        ( m_acLayerCfg[layer].m_iWaveFrontSubstreams );
508    m_acTEncTop[layer].setTMVPModeId ( m_TMVPModeId );
509    m_acTEncTop[layer].setUseScalingListId           ( m_useScalingListId  );
510    m_acTEncTop[layer].setScalingListFile            ( m_scalingListFile   );
511    m_acTEncTop[layer].setSignHideFlag(m_signHideFlag);
512#if RC_SHVC_HARMONIZATION
513    m_acTEncTop[layer].setUseRateCtrl     (m_acLayerCfg[layer].getRCEnableRateControl());
514    m_acTEncTop[layer].setTargetBitrate   (m_acLayerCfg[layer].getRCTargetBitrate());
515    m_acTEncTop[layer].setKeepHierBit     (m_acLayerCfg[layer].getRCKeepHierarchicalBit());
516    m_acTEncTop[layer].setLCULevelRC      (m_acLayerCfg[layer].getRCLCULevelRC());
517    m_acTEncTop[layer].setUseLCUSeparateModel (m_acLayerCfg[layer].getRCUseLCUSeparateModel());
518    m_acTEncTop[layer].setInitialQP           (m_acLayerCfg[layer].getRCInitialQP());
519    m_acTEncTop[layer].setForceIntraQP        (m_acLayerCfg[layer].getRCForceIntraQP());
520#else
521    m_acTEncTop[layer].setUseRateCtrl         ( m_RCEnableRateControl );
522    m_acTEncTop[layer].setTargetBitrate       ( m_RCTargetBitrate );
523    m_acTEncTop[layer].setKeepHierBit         ( m_RCKeepHierarchicalBit );
524    m_acTEncTop[layer].setLCULevelRC          ( m_RCLCULevelRC );
525    m_acTEncTop[layer].setUseLCUSeparateModel ( m_RCUseLCUSeparateModel );
526    m_acTEncTop[layer].setInitialQP           ( m_RCInitialQP );
527    m_acTEncTop[layer].setForceIntraQP        ( m_RCForceIntraQP );
528#endif
529    m_acTEncTop[layer].setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
530    m_acTEncTop[layer].setCUTransquantBypassFlagForceValue(m_CUTransquantBypassFlagForce);
531    m_acTEncTop[layer].setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
532    m_acTEncTop[layer].setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
533    m_acTEncTop[layer].setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled );
534    m_acTEncTop[layer].setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
535    m_acTEncTop[layer].setAspectRatioIdc( m_aspectRatioIdc );
536    m_acTEncTop[layer].setSarWidth( m_sarWidth );
537    m_acTEncTop[layer].setSarHeight( m_sarHeight );
538    m_acTEncTop[layer].setOverscanInfoPresentFlag( m_overscanInfoPresentFlag );
539    m_acTEncTop[layer].setOverscanAppropriateFlag( m_overscanAppropriateFlag );
540    m_acTEncTop[layer].setVideoSignalTypePresentFlag( m_videoSignalTypePresentFlag );
541    m_acTEncTop[layer].setVideoFormat( m_videoFormat );
542    m_acTEncTop[layer].setVideoFullRangeFlag( m_videoFullRangeFlag );
543    m_acTEncTop[layer].setColourDescriptionPresentFlag( m_colourDescriptionPresentFlag );
544    m_acTEncTop[layer].setColourPrimaries( m_colourPrimaries );
545    m_acTEncTop[layer].setTransferCharacteristics( m_transferCharacteristics );
546    m_acTEncTop[layer].setMatrixCoefficients( m_matrixCoefficients );
547    m_acTEncTop[layer].setChromaLocInfoPresentFlag( m_chromaLocInfoPresentFlag );
548    m_acTEncTop[layer].setChromaSampleLocTypeTopField( m_chromaSampleLocTypeTopField );
549    m_acTEncTop[layer].setChromaSampleLocTypeBottomField( m_chromaSampleLocTypeBottomField );
550    m_acTEncTop[layer].setNeutralChromaIndicationFlag( m_neutralChromaIndicationFlag );
551    m_acTEncTop[layer].setDefaultDisplayWindow( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset );
552    m_acTEncTop[layer].setFrameFieldInfoPresentFlag( m_frameFieldInfoPresentFlag );
553    m_acTEncTop[layer].setPocProportionalToTimingFlag( m_pocProportionalToTimingFlag );
554    m_acTEncTop[layer].setNumTicksPocDiffOneMinus1   ( m_numTicksPocDiffOneMinus1    );
555    m_acTEncTop[layer].setBitstreamRestrictionFlag( m_bitstreamRestrictionFlag );
556    m_acTEncTop[layer].setTilesFixedStructureFlag( m_tilesFixedStructureFlag );
557    m_acTEncTop[layer].setMotionVectorsOverPicBoundariesFlag( m_motionVectorsOverPicBoundariesFlag );
558    m_acTEncTop[layer].setMinSpatialSegmentationIdc( m_minSpatialSegmentationIdc );
559    m_acTEncTop[layer].setMaxBytesPerPicDenom( m_maxBytesPerPicDenom );
560    m_acTEncTop[layer].setMaxBitsPerMinCuDenom( m_maxBitsPerMinCuDenom );
561    m_acTEncTop[layer].setLog2MaxMvLengthHorizontal( m_log2MaxMvLengthHorizontal );
562    m_acTEncTop[layer].setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
563    m_acTEncTop[layer].setElRapSliceTypeB(layer == 0? 0 : m_elRapSliceBEnabled);
564    if( layer > 0 )
565    {
566      m_acTEncTop[layer].setNumScaledRefLayerOffsets( m_acLayerCfg[layer].m_numScaledRefLayerOffsets );
567      for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
568      {
569#if O0098_SCALED_REF_LAYER_ID
570        m_acTEncTop[layer].setScaledRefLayerId(i, m_acLayerCfg[layer].m_scaledRefLayerId[i]);
571#endif
572#if P0312_VERT_PHASE_ADJ
573        m_acTEncTop[layer].setVertPhasePositionEnableFlag( i, m_acLayerCfg[layer].m_vertPhasePositionEnableFlag[i] );
574        m_acTEncTop[layer].getScaledRefLayerWindow(i).setWindow( 2*m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i],
575                                                  2*m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i], m_acLayerCfg[layer].m_vertPhasePositionEnableFlag[i] );
576#else
577        m_acTEncTop[layer].getScaledRefLayerWindow(i).setWindow( 2*m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i],
578                                                  2*m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i]);
579#endif
580      }
581    }
582#if M0040_ADAPTIVE_RESOLUTION_CHANGE
583    m_acTEncTop[layer].setAdaptiveResolutionChange( m_adaptiveResolutionChange );
584#endif
585#if AUXILIARY_PICTURES
586    m_acTEncTop[layer].setChromaFormatIDC( m_acLayerCfg[layer].m_chromaFormatIDC );
587#endif
588#if O0153_ALT_OUTPUT_LAYER_FLAG
589    m_acTEncTop[layer].setAltOuputLayerFlag( m_altOutputLayerFlag );
590#endif
591#if O0149_CROSS_LAYER_BLA_FLAG
592    m_acTEncTop[layer].setCrossLayerBLAFlag( m_crossLayerBLAFlag );
593#endif
594  }
595}
596#else //SVC_EXTENSION
597Void TAppEncTop::xInitLibCfg()
598{
599  TComVPS vps;
600
601  vps.setMaxTLayers                       ( m_maxTempLayer );
602  if (m_maxTempLayer == 1)
603  {
604    vps.setTemporalNestingFlag(true);
605  }
606  vps.setMaxLayers                        ( 1 );
607  for(Int i = 0; i < MAX_TLAYER; i++)
608  {
609    vps.setNumReorderPics                 ( m_numReorderPics[i], i );
610    vps.setMaxDecPicBuffering             ( m_maxDecPicBuffering[i], i );
611  }
612  m_cTEncTop.setVPS(&vps);
613
614  m_cTEncTop.setProfile(m_profile);
615  m_cTEncTop.setLevel(m_levelTier, m_level);
616  m_cTEncTop.setProgressiveSourceFlag(m_progressiveSourceFlag);
617  m_cTEncTop.setInterlacedSourceFlag(m_interlacedSourceFlag);
618  m_cTEncTop.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
619  m_cTEncTop.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
620
621  m_cTEncTop.setFrameRate                    ( m_iFrameRate );
622  m_cTEncTop.setFrameSkip                    ( m_FrameSkip );
623  m_cTEncTop.setSourceWidth                  ( m_iSourceWidth );
624  m_cTEncTop.setSourceHeight                 ( m_iSourceHeight );
625  m_cTEncTop.setConformanceWindow            ( m_confLeft, m_confRight, m_confTop, m_confBottom );
626  m_cTEncTop.setFramesToBeEncoded            ( m_framesToBeEncoded );
627
628  //====== Coding Structure ========
629  m_cTEncTop.setIntraPeriod                  ( m_iIntraPeriod );
630  m_cTEncTop.setDecodingRefreshType          ( m_iDecodingRefreshType );
631  m_cTEncTop.setGOPSize                      ( m_iGOPSize );
632  m_cTEncTop.setGopList                      ( m_GOPList );
633  m_cTEncTop.setExtraRPSs                    ( m_extraRPSs );
634  for(Int i = 0; i < MAX_TLAYER; i++)
635  {
636    m_cTEncTop.setNumReorderPics             ( m_numReorderPics[i], i );
637    m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBuffering[i], i );
638  }
639  for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
640  {
641    m_cTEncTop.setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
642  }
643  m_cTEncTop.setQP                           ( m_iQP );
644
645  m_cTEncTop.setPad                          ( m_aiPad );
646
647  m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayer );
648  m_cTEncTop.setUseAMP( m_enableAMP );
649
650  //===== Slice ========
651
652  //====== Loop/Deblock Filter ========
653  m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable       );
654  m_cTEncTop.setLoopFilterOffsetInPPS        ( m_loopFilterOffsetInPPS );
655  m_cTEncTop.setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
656  m_cTEncTop.setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
657  m_cTEncTop.setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
658  m_cTEncTop.setDeblockingFilterMetric       ( m_DeblockingFilterMetric );
659
660  //====== Motion search ========
661  m_cTEncTop.setFastSearch                   ( m_iFastSearch  );
662  m_cTEncTop.setSearchRange                  ( m_iSearchRange );
663  m_cTEncTop.setBipredSearchRange            ( m_bipredSearchRange );
664
665  //====== Quality control ========
666  m_cTEncTop.setMaxDeltaQP                   ( m_iMaxDeltaQP  );
667  m_cTEncTop.setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
668
669  m_cTEncTop.setChromaCbQpOffset               ( m_cbQpOffset     );
670  m_cTEncTop.setChromaCrQpOffset            ( m_crQpOffset  );
671
672#if ADAPTIVE_QP_SELECTION
673  m_cTEncTop.setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
674#endif
675
676  m_cTEncTop.setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
677  m_cTEncTop.setQPAdaptationRange            ( m_iQPAdaptationRange );
678
679  //====== Tool list ========
680  m_cTEncTop.setDeltaQpRD                    ( m_uiDeltaQpRD  );
681  m_cTEncTop.setUseASR                       ( m_bUseASR      );
682  m_cTEncTop.setUseHADME                     ( m_bUseHADME    );
683  m_cTEncTop.setdQPs                         ( m_aidQP        );
684  m_cTEncTop.setUseRDOQ                      ( m_useRDOQ     );
685  m_cTEncTop.setUseRDOQTS                    ( m_useRDOQTS   );
686  m_cTEncTop.setRDpenalty                 ( m_rdPenalty );
687  m_cTEncTop.setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
688  m_cTEncTop.setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
689  m_cTEncTop.setQuadtreeTUMaxDepthInter      ( m_uiQuadtreeTUMaxDepthInter );
690  m_cTEncTop.setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
691  m_cTEncTop.setUseFastEnc                   ( m_bUseFastEnc  );
692  m_cTEncTop.setUseEarlyCU                   ( m_bUseEarlyCU  );
693  m_cTEncTop.setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
694  m_cTEncTop.setUseCbfFastMode            ( m_bUseCbfFastMode  );
695  m_cTEncTop.setUseEarlySkipDetection            ( m_useEarlySkipDetection );
696#if FAST_INTRA_SHVC
697  m_cTEncTop.setUseFastIntraScalable            ( m_useFastIntraScalable );
698#endif
699
700  m_cTEncTop.setUseTransformSkip             ( m_useTransformSkip      );
701  m_cTEncTop.setUseTransformSkipFast         ( m_useTransformSkipFast  );
702  m_cTEncTop.setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
703  m_cTEncTop.setPCMLog2MinSize          ( m_uiPCMLog2MinSize);
704  m_cTEncTop.setUsePCM                       ( m_usePCM );
705  m_cTEncTop.setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
706  m_cTEncTop.setMaxNumMergeCand              ( m_maxNumMergeCand );
707
708
709  //====== Weighted Prediction ========
710  m_cTEncTop.setUseWP                   ( m_useWeightedPred      );
711  m_cTEncTop.setWPBiPred                ( m_useWeightedBiPred   );
712  //====== Parallel Merge Estimation ========
713  m_cTEncTop.setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 );
714
715  //====== Slice ========
716  m_cTEncTop.setSliceMode               ( m_sliceMode                );
717  m_cTEncTop.setSliceArgument           ( m_sliceArgument            );
718
719  //====== Dependent Slice ========
720  m_cTEncTop.setSliceSegmentMode        ( m_sliceSegmentMode         );
721  m_cTEncTop.setSliceSegmentArgument    ( m_sliceSegmentArgument     );
722  Int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
723  if(m_sliceSegmentMode==FIXED_NUMBER_OF_LCU)
724  {
725    m_cTEncTop.setSliceSegmentArgument ( m_sliceSegmentArgument * iNumPartInCU );
726  }
727  if(m_sliceMode==FIXED_NUMBER_OF_LCU)
728  {
729    m_cTEncTop.setSliceArgument ( m_sliceArgument * iNumPartInCU );
730  }
731  if(m_sliceMode==FIXED_NUMBER_OF_TILES)
732  {
733    m_cTEncTop.setSliceArgument ( m_sliceArgument );
734  }
735
736  if(m_sliceMode == 0 )
737  {
738    m_bLFCrossSliceBoundaryFlag = true;
739  }
740  m_cTEncTop.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
741  m_cTEncTop.setUseSAO ( m_bUseSAO );
742  m_cTEncTop.setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
743
744  m_cTEncTop.setSaoLcuBoundary (m_saoLcuBoundary);
745  m_cTEncTop.setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
746  m_cTEncTop.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
747
748  m_cTEncTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
749  m_cTEncTop.setRecoveryPointSEIEnabled( m_recoveryPointSEIEnabled );
750  m_cTEncTop.setBufferingPeriodSEIEnabled( m_bufferingPeriodSEIEnabled );
751  m_cTEncTop.setPictureTimingSEIEnabled( m_pictureTimingSEIEnabled );
752  m_cTEncTop.setToneMappingInfoSEIEnabled                 ( m_toneMappingInfoSEIEnabled );
753  m_cTEncTop.setTMISEIToneMapId                           ( m_toneMapId );
754  m_cTEncTop.setTMISEIToneMapCancelFlag                   ( m_toneMapCancelFlag );
755  m_cTEncTop.setTMISEIToneMapPersistenceFlag              ( m_toneMapPersistenceFlag );
756  m_cTEncTop.setTMISEICodedDataBitDepth                   ( m_toneMapCodedDataBitDepth );
757  m_cTEncTop.setTMISEITargetBitDepth                      ( m_toneMapTargetBitDepth );
758  m_cTEncTop.setTMISEIModelID                             ( m_toneMapModelId );
759  m_cTEncTop.setTMISEIMinValue                            ( m_toneMapMinValue );
760  m_cTEncTop.setTMISEIMaxValue                            ( m_toneMapMaxValue );
761  m_cTEncTop.setTMISEISigmoidMidpoint                     ( m_sigmoidMidpoint );
762  m_cTEncTop.setTMISEISigmoidWidth                        ( m_sigmoidWidth );
763  m_cTEncTop.setTMISEIStartOfCodedInterva                 ( m_startOfCodedInterval );
764  m_cTEncTop.setTMISEINumPivots                           ( m_numPivots );
765  m_cTEncTop.setTMISEICodedPivotValue                     ( m_codedPivotValue );
766  m_cTEncTop.setTMISEITargetPivotValue                    ( m_targetPivotValue );
767  m_cTEncTop.setTMISEICameraIsoSpeedIdc                   ( m_cameraIsoSpeedIdc );
768  m_cTEncTop.setTMISEICameraIsoSpeedValue                 ( m_cameraIsoSpeedValue );
769  m_cTEncTop.setTMISEIExposureCompensationValueSignFlag   ( m_exposureCompensationValueSignFlag );
770  m_cTEncTop.setTMISEIExposureCompensationValueNumerator  ( m_exposureCompensationValueNumerator );
771  m_cTEncTop.setTMISEIExposureCompensationValueDenomIdc   ( m_exposureCompensationValueDenomIdc );
772  m_cTEncTop.setTMISEIRefScreenLuminanceWhite             ( m_refScreenLuminanceWhite );
773  m_cTEncTop.setTMISEIExtendedRangeWhiteLevel             ( m_extendedRangeWhiteLevel );
774  m_cTEncTop.setTMISEINominalBlackLevelLumaCodeValue      ( m_nominalBlackLevelLumaCodeValue );
775  m_cTEncTop.setTMISEINominalWhiteLevelLumaCodeValue      ( m_nominalWhiteLevelLumaCodeValue );
776  m_cTEncTop.setTMISEIExtendedWhiteLevelLumaCodeValue     ( m_extendedWhiteLevelLumaCodeValue );
777  m_cTEncTop.setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled );
778  m_cTEncTop.setFramePackingArrangementSEIType( m_framePackingSEIType );
779  m_cTEncTop.setFramePackingArrangementSEIId( m_framePackingSEIId );
780  m_cTEncTop.setFramePackingArrangementSEIQuincunx( m_framePackingSEIQuincunx );
781  m_cTEncTop.setFramePackingArrangementSEIInterpretation( m_framePackingSEIInterpretation );
782  m_cTEncTop.setDisplayOrientationSEIAngle( m_displayOrientationSEIAngle );
783  m_cTEncTop.setTemporalLevel0IndexSEIEnabled( m_temporalLevel0IndexSEIEnabled );
784  m_cTEncTop.setGradualDecodingRefreshInfoEnabled( m_gradualDecodingRefreshInfoEnabled );
785  m_cTEncTop.setDecodingUnitInfoSEIEnabled( m_decodingUnitInfoSEIEnabled );
786#if LAYERS_NOT_PRESENT_SEI
787  m_cTEncTop.setLayersNotPresentSEIEnabled( m_layersNotPresentSEIEnabled );
788#endif
789  m_cTEncTop.setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled );
790  m_cTEncTop.setScalableNestingSEIEnabled( m_scalableNestingSEIEnabled );
791  m_cTEncTop.setUniformSpacingIdr          ( m_iUniformSpacingIdr );
792  m_cTEncTop.setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
793  m_cTEncTop.setNumRowsMinus1              ( m_iNumRowsMinus1 );
794  if(m_iUniformSpacingIdr==0)
795  {
796    m_cTEncTop.setColumnWidth              ( m_pColumnWidth );
797    m_cTEncTop.setRowHeight                ( m_pRowHeight );
798  }
799  m_cTEncTop.xCheckGSParameters();
800  Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
801  if(uiTilesCount == 1)
802  {
803    m_bLFCrossTileBoundaryFlag = true;
804  }
805  m_cTEncTop.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
806  m_cTEncTop.setWaveFrontSynchro           ( m_iWaveFrontSynchro );
807  m_cTEncTop.setWaveFrontSubstreams        ( m_iWaveFrontSubstreams );
808  m_cTEncTop.setTMVPModeId ( m_TMVPModeId );
809  m_cTEncTop.setUseScalingListId           ( m_useScalingListId  );
810  m_cTEncTop.setScalingListFile            ( m_scalingListFile   );
811  m_cTEncTop.setSignHideFlag(m_signHideFlag);
812  m_cTEncTop.setUseRateCtrl         ( m_RCEnableRateControl );
813  m_cTEncTop.setTargetBitrate       ( m_RCTargetBitrate );
814  m_cTEncTop.setKeepHierBit         ( m_RCKeepHierarchicalBit );
815  m_cTEncTop.setLCULevelRC          ( m_RCLCULevelRC );
816  m_cTEncTop.setUseLCUSeparateModel ( m_RCUseLCUSeparateModel );
817  m_cTEncTop.setInitialQP           ( m_RCInitialQP );
818  m_cTEncTop.setForceIntraQP        ( m_RCForceIntraQP );
819  m_cTEncTop.setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
820  m_cTEncTop.setCUTransquantBypassFlagForceValue(m_CUTransquantBypassFlagForce);
821  m_cTEncTop.setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
822  m_cTEncTop.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
823  m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled );
824  m_cTEncTop.setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
825  m_cTEncTop.setAspectRatioIdc( m_aspectRatioIdc );
826  m_cTEncTop.setSarWidth( m_sarWidth );
827  m_cTEncTop.setSarHeight( m_sarHeight );
828  m_cTEncTop.setOverscanInfoPresentFlag( m_overscanInfoPresentFlag );
829  m_cTEncTop.setOverscanAppropriateFlag( m_overscanAppropriateFlag );
830  m_cTEncTop.setVideoSignalTypePresentFlag( m_videoSignalTypePresentFlag );
831  m_cTEncTop.setVideoFormat( m_videoFormat );
832  m_cTEncTop.setVideoFullRangeFlag( m_videoFullRangeFlag );
833  m_cTEncTop.setColourDescriptionPresentFlag( m_colourDescriptionPresentFlag );
834  m_cTEncTop.setColourPrimaries( m_colourPrimaries );
835  m_cTEncTop.setTransferCharacteristics( m_transferCharacteristics );
836  m_cTEncTop.setMatrixCoefficients( m_matrixCoefficients );
837  m_cTEncTop.setChromaLocInfoPresentFlag( m_chromaLocInfoPresentFlag );
838  m_cTEncTop.setChromaSampleLocTypeTopField( m_chromaSampleLocTypeTopField );
839  m_cTEncTop.setChromaSampleLocTypeBottomField( m_chromaSampleLocTypeBottomField );
840  m_cTEncTop.setNeutralChromaIndicationFlag( m_neutralChromaIndicationFlag );
841  m_cTEncTop.setDefaultDisplayWindow( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset );
842  m_cTEncTop.setFrameFieldInfoPresentFlag( m_frameFieldInfoPresentFlag );
843  m_cTEncTop.setPocProportionalToTimingFlag( m_pocProportionalToTimingFlag );
844  m_cTEncTop.setNumTicksPocDiffOneMinus1   ( m_numTicksPocDiffOneMinus1    );
845  m_cTEncTop.setBitstreamRestrictionFlag( m_bitstreamRestrictionFlag );
846  m_cTEncTop.setTilesFixedStructureFlag( m_tilesFixedStructureFlag );
847  m_cTEncTop.setMotionVectorsOverPicBoundariesFlag( m_motionVectorsOverPicBoundariesFlag );
848  m_cTEncTop.setMinSpatialSegmentationIdc( m_minSpatialSegmentationIdc );
849  m_cTEncTop.setMaxBytesPerPicDenom( m_maxBytesPerPicDenom );
850  m_cTEncTop.setMaxBitsPerMinCuDenom( m_maxBitsPerMinCuDenom );
851  m_cTEncTop.setLog2MaxMvLengthHorizontal( m_log2MaxMvLengthHorizontal );
852  m_cTEncTop.setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
853}
854#endif //SVC_EXTENSION
855
856Void TAppEncTop::xCreateLib()
857{
858  // Video I/O
859#if SVC_EXTENSION
860  // initialize global variables
861  initROM();
862
863  for(UInt layer=0; layer<m_numLayers; layer++)
864  {
865#if O0194_DIFFERENT_BITDEPTH_EL_BL
866    //2
867    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
868    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
869
870    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
871    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
872#endif
873#if LAYER_CTB
874    g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
875    g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
876    g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
877    g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
878#endif
879#if O0194_DIFFERENT_BITDEPTH_EL_BL
880    m_acTVideoIOYuvInputFile[layer].open( (Char *)m_acLayerCfg[layer].getInputFile().c_str(),  false, m_acLayerCfg[layer].m_inputBitDepthY, m_acLayerCfg[layer].m_inputBitDepthC, m_acLayerCfg[layer].m_internalBitDepthY, m_acLayerCfg[layer].m_internalBitDepthC );  // read  mode
881#else
882    m_acTVideoIOYuvInputFile[layer].open( (Char *)m_acLayerCfg[layer].getInputFile().c_str(),  false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
883#endif
884    m_acTVideoIOYuvInputFile[layer].skipFrames(m_FrameSkip, m_acLayerCfg[layer].getSourceWidth() - m_acLayerCfg[layer].getPad()[0], m_acLayerCfg[layer].getSourceHeight() - m_acLayerCfg[layer].getPad()[1]);
885
886    if (!m_acLayerCfg[layer].getReconFile().empty())
887    {
888#if O0194_DIFFERENT_BITDEPTH_EL_BL
889      m_acTVideoIOYuvReconFile[layer].open((Char *)m_acLayerCfg[layer].getReconFile().c_str(), true, m_acLayerCfg[layer].m_outputBitDepthY, m_acLayerCfg[layer].m_outputBitDepthC, m_acLayerCfg[layer].m_internalBitDepthY, m_acLayerCfg[layer].m_internalBitDepthC );  // write mode
890#else
891      m_acTVideoIOYuvReconFile[layer].open((Char *)m_acLayerCfg[layer].getReconFile().c_str(), true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // write mode
892#endif
893    }
894
895    m_acTEncTop[layer].create();
896  }
897#else //SVC_EXTENSION
898  m_cTVideoIOYuvInputFile.open( m_pchInputFile,     false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
899  m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
900
901  if (m_pchReconFile)
902    m_cTVideoIOYuvReconFile.open(m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC);  // write mode
903
904  // Neo Decoder
905  m_cTEncTop.create();
906#endif //SVC_EXTENSION
907}
908
909Void TAppEncTop::xDestroyLib()
910{
911  // Video I/O
912#if SVC_EXTENSION
913  // destroy ROM
914  destroyROM();
915
916  for(UInt layer=0; layer<m_numLayers; layer++)
917  {
918#if LAYER_CTB
919    g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
920    g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
921    g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
922    g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
923#endif
924
925    m_acTVideoIOYuvInputFile[layer].close();
926    m_acTVideoIOYuvReconFile[layer].close();
927
928    m_acTEncTop[layer].destroy();
929  }
930#else //SVC_EXTENSION
931  m_cTVideoIOYuvInputFile.close();
932  m_cTVideoIOYuvReconFile.close();
933
934  // Neo Decoder
935  m_cTEncTop.destroy();
936#endif //SVC_EXTENSION
937}
938
939Void TAppEncTop::xInitLib(Bool isFieldCoding)
940{
941#if SVC_EXTENSION
942  for(UInt layer=0; layer<m_numLayers; layer++)
943  {
944#if O0194_DIFFERENT_BITDEPTH_EL_BL
945    //3
946    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
947    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
948
949    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
950    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
951#endif
952#if LAYER_CTB
953    g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
954    g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
955    g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
956    g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
957
958    memcpy( g_auiZscanToRaster, g_auiLayerZscanToRaster[layer], sizeof( g_auiZscanToRaster ) );
959    memcpy( g_auiRasterToZscan, g_auiLayerRasterToZscan[layer], sizeof( g_auiRasterToZscan ) );
960    memcpy( g_auiRasterToPelX,  g_auiLayerRasterToPelX[layer],  sizeof( g_auiRasterToPelX ) );
961    memcpy( g_auiRasterToPelY,  g_auiLayerRasterToPelY[layer],  sizeof( g_auiRasterToPelY ) );
962#endif
963    m_acTEncTop[layer].init(isFieldCoding);
964#if P0182_VPS_VUI_PS_FLAG
965    m_acTEncTop[layer].getVPS()->setSPSId(layer, m_acTEncTop[layer].getSPS()->getSPSId());
966    m_acTEncTop[layer].getVPS()->setPPSId(layer, m_acTEncTop[layer].getPPS()->getPPSId());
967#endif
968  }
969#if VPS_RENAME
970  m_acTEncTop[0].getVPS()->setMaxLayers( m_numLayers );
971#endif
972#if VPS_EXTN_OP_LAYER_SETS
973  TComVPS* vps = m_acTEncTop[0].getVPS();
974  vps->setMaxLayerId(m_numLayers - 1);    // Set max-layer ID
975
976  vps->setNumLayerSets(m_numLayers);
977  for(Int setId = 1; setId < vps->getNumLayerSets(); setId++)
978  {
979    for(Int layerId = 0; layerId <= vps->getMaxLayerId(); layerId++)
980    {
981#if O0194_DIFFERENT_BITDEPTH_EL_BL
982      //4
983      g_bitDepthY = m_acLayerCfg[layerId].m_internalBitDepthY;
984      g_bitDepthC = m_acLayerCfg[layerId].m_internalBitDepthC;
985
986      g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthY : m_acLayerCfg[layerId].m_internalBitDepthY;
987      g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthC : m_acLayerCfg[layerId].m_internalBitDepthC;
988#endif
989      if( layerId <= setId )
990      {
991        vps->setLayerIdIncludedFlag(true, setId, layerId);
992      }
993      else
994      {
995        vps->setLayerIdIncludedFlag(false, setId, layerId);
996      }
997    }
998  }
999#if VPS_EXTN_MASK_AND_DIM_INFO
1000  UInt i = 0, dimIdLen = 0;
1001#if AVC_BASE
1002  vps->setAvcBaseLayerFlag(m_avcBaseLayerFlag);
1003#else
1004  vps->setAvcBaseLayerFlag(false);
1005#endif
1006  vps->setSplittingFlag(false);
1007  for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++)
1008  {
1009    vps->setScalabilityMask(i, false);
1010  }
1011  if(m_numLayers > 1)
1012  {
1013    Int scalabilityTypes = 0;
1014    for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++)
1015    {
1016      vps->setScalabilityMask(i, m_scalabilityMask[i]);
1017      scalabilityTypes += m_scalabilityMask[i];
1018    }
1019#if AUXILIARY_PICTURES
1020    assert( scalabilityTypes <= 2 );
1021#else
1022    assert( scalabilityTypes == 1 );
1023#endif
1024    vps->setNumScalabilityTypes(scalabilityTypes);
1025  }
1026  else
1027  {
1028    vps->setNumScalabilityTypes(0);
1029  }
1030  while((1 << dimIdLen) < m_numLayers)
1031  {
1032    dimIdLen++;
1033  }
1034  vps->setDimensionIdLen(0, dimIdLen);
1035  vps->setNuhLayerIdPresentFlag(false);
1036  vps->setLayerIdInNuh(0, 0);
1037  vps->setLayerIdInVps(0, 0);
1038  for(i = 1; i < vps->getMaxLayers(); i++)
1039  {
1040    vps->setLayerIdInNuh(i, i);
1041    vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
1042    vps->setDimensionId(i, 0, i);
1043  }
1044#if AUXILIARY_PICTURES
1045  if (m_scalabilityMask[3])
1046  {
1047    UInt maxAuxId = 0;
1048    UInt auxDimIdLen = 1;
1049    for(i = 1; i < vps->getMaxLayers(); i++)
1050    {
1051      if (m_acLayerCfg[i].getAuxId() > maxAuxId)
1052      {
1053        maxAuxId = m_acLayerCfg[i].getAuxId();
1054      }
1055    }
1056    while((1 << auxDimIdLen) < (maxAuxId + 1))
1057    {
1058      auxDimIdLen++;
1059    }
1060    vps->setDimensionIdLen(1, auxDimIdLen);
1061    for(i = 1; i < vps->getMaxLayers(); i++)
1062    {
1063      vps->setDimensionId(i, 1, m_acLayerCfg[i].getAuxId());
1064    }
1065  }
1066#endif
1067#endif
1068#if VPS_TSLAYERS
1069    vps->setMaxTSLayersPresentFlag(true);
1070    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
1071    {
1072        vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
1073    }
1074#endif
1075#if N0120_MAX_TID_REF_PRESENT_FLAG
1076#if N0120_MAX_TID_REF_CFG
1077  vps->setMaxTidRefPresentFlag(m_maxTidRefPresentFlag);
1078#else
1079  vps->setMaxTidRefPresentFlag(true);
1080#endif
1081  if (vps->getMaxTidRefPresentFlag())
1082  {
1083    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
1084    {
1085#if N0120_MAX_TID_REF_CFG
1086#if O0225_MAX_TID_FOR_REF_LAYERS
1087      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
1088      {
1089        vps->setMaxTidIlRefPicsPlus1(i, j, m_acTEncTop[i].getMaxTidIlRefPicsPlus1());
1090      }
1091#else
1092      vps->setMaxTidIlRefPicsPlus1(i, m_acTEncTop[i].getMaxTidIlRefPicsPlus1());
1093#endif
1094#else
1095#if O0225_MAX_TID_FOR_REF_LAYERS
1096      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
1097      {
1098        vps->setMaxTidIlRefPicsPlus1(i, j, vps->getMaxTLayers()+1);
1099      }
1100#else
1101      vps->setMaxTidIlRefPicsPlus1(i, vps->getMaxTLayers()+1);
1102#endif
1103#endif
1104    }
1105  }
1106  else
1107  {
1108    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
1109    {
1110#if O0225_MAX_TID_FOR_REF_LAYERS
1111      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
1112      {
1113        vps->setMaxTidIlRefPicsPlus1(i, j, 7);
1114      }
1115#else
1116      vps->setMaxTidIlRefPicsPlus1(i, 7);
1117#endif
1118    }
1119  }
1120#endif
1121#if ILP_SSH_SIG
1122#if ILP_SSH_SIG_FIX
1123    vps->setIlpSshSignalingEnabledFlag(false);
1124#else
1125    vps->setIlpSshSignalingEnabledFlag(true);
1126#endif
1127#endif
1128#if VPS_EXTN_PROFILE_INFO
1129  vps->getPTLForExtnPtr()->resize(vps->getNumLayerSets());
1130  for(Int setId = 1; setId < vps->getNumLayerSets(); setId++)
1131  {
1132    vps->setProfilePresentFlag(setId, true);
1133    // Note - may need to be changed for other layer structures.
1134    *(vps->getPTLForExtn(setId)) = *(m_acTEncTop[setId].getSPS()->getPTL());
1135  }
1136#endif
1137  // Target output layer
1138  vps->setNumOutputLayerSets(vps->getNumLayerSets());
1139  vps->setNumProfileTierLevel(vps->getNumLayerSets());
1140#if P0295_DEFAULT_OUT_LAYER_IDC
1141  vps->setDefaultTargetOutputLayerIdc(1);
1142#else
1143#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
1144  vps->setDefaultOneTargetOutputLayerIdc(1);
1145#else
1146  vps->setDefaultOneTargetOutputLayerFlag(true);
1147#endif
1148#endif
1149  for(i = 1; i < vps->getNumLayerSets(); i++)
1150  {
1151    vps->setProfileLevelTierIdx(i, i);
1152    vps->setOutputLayerSetIdx(i, i);
1153  } 
1154#endif
1155 #if VPS_DPB_SIZE_TABLE
1156  // The Layer ID List variables can be derived here. 
1157#if DERIVE_LAYER_ID_LIST_VARIABLES
1158  vps->deriveLayerIdListVariables();
1159#endif
1160#if RESOLUTION_BASED_DPB
1161  vps->assignSubDpbIndices();
1162#else
1163  vps->deriveNumberOfSubDpbs();
1164#endif
1165
1166  // derive OutputLayerFlag[i][j]
1167  if( vps->getDefaultTargetOutputLayerIdc() == 1 )
1168  {
1169    // default_target_output_layer_idc equal to 1 specifies that only the layer with the highest value of nuh_layer_id such that nuh_layer_id equal to nuhLayerIdA and
1170    // AuxId[ nuhLayerIdA ] equal to 0 in each of the output layer sets with index in the range of 1 to vps_num_layer_sets_minus1, inclusive, is an output layer of its output layer set.
1171
1172    // Include the highest layer as output layer for each layer set
1173    for(Int lsIdx = 1; lsIdx < vps->getNumLayerSets(); lsIdx++)
1174    {
1175      for( UInt layer = 0; layer < vps->getNumLayersInIdList(lsIdx); layer++ )
1176      {
1177        if( vps->getLayerIdIncludedFlag(lsIdx, layer) )     
1178        {       
1179          vps->setOutputLayerFlag( lsIdx, layer, layer == vps->getNumLayersInIdList(lsIdx) - 1 );
1180        }
1181      }
1182    }
1183  }
1184  else
1185  {
1186    // cases when default_target_output_layer_idc is not equal to 1
1187    assert(!"default_target_output_layer_idc not equal to 1 is not yet supported");
1188  }
1189
1190  // Initialize dpb_size_table() for all ouput layer sets in the VPS extension
1191  for(i = 1; i < vps->getNumOutputLayerSets(); i++)
1192  {
1193#if CHANGE_NUMSUBDPB_IDX
1194    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
1195#endif
1196    Int layerSetId = vps->getOutputLayerSetIdx(i);
1197
1198    for(Int j = 0; j < vps->getMaxTLayers(); j++)
1199    {
1200
1201      Int maxNumReorderPics = -1;
1202#if CHANGE_NUMSUBDPB_IDX
1203#if RESOLUTION_BASED_DPB
1204      for(Int k = 0; k < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); k++)
1205#else
1206      for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
1207#endif
1208#else
1209      for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
1210#endif
1211      {
1212        Int layerId = vps->getLayerSetLayerIdList(layerSetId, k); // k-th layer in the output layer set
1213#if RESOLUTION_BASED_DPB
1214        vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, m_acTEncTop[layerId].getMaxDecPicBuffering(j) - 1 );
1215        // Add sub-DPB sizes of layers belonging to a sub-DPB. If a different sub-DPB size is calculated
1216        // at the encoder, modify below
1217        Int oldValue = vps->getMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j );
1218        oldValue += vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j ) + 1;
1219        vps->setMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j, oldValue );
1220#else
1221        vps->setMaxVpsDecPicBufferingMinus1( i, k, j,  m_acTEncTop[layerId].getMaxDecPicBuffering(j) - 1 );
1222#endif
1223        maxNumReorderPics       = std::max( maxNumReorderPics, m_acTEncTop[layerId].getNumReorderPics(j));
1224      }
1225#if RESOLUTION_BASED_DPB
1226      for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
1227      {
1228        // Decrement m_maxVpsDecPicBufferingMinus1
1229        Int oldValue = vps->getMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j );
1230        vps->setMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j, oldValue - 1 );
1231      }
1232#endif
1233      vps->setMaxVpsNumReorderPics(i, j, maxNumReorderPics);
1234      vps->determineSubDpbInfoFlags();
1235    }
1236  }
1237#endif
1238#if VPS_EXTN_DIRECT_REF_LAYERS
1239  // Direct reference layers
1240  UInt maxDirectRefLayers = 0;
1241#if O0096_DEFAULT_DEPENDENCY_TYPE
1242  Bool isDefaultDirectDependencyTypeSet = false;
1243#endif
1244  for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
1245  {
1246    vps->setNumDirectRefLayers( layerCtr, m_acTEncTop[layerCtr].getNumDirectRefLayers() );
1247    maxDirectRefLayers = max<UInt>( maxDirectRefLayers, vps->getNumDirectRefLayers( layerCtr ) );
1248
1249    for(i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
1250    {
1251      vps->setRefLayerId( layerCtr, i, m_acTEncTop[layerCtr].getRefLayerId(i) );
1252    }
1253    // Set direct dependency flag
1254    // Initialize flag to 0
1255    for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
1256    {
1257      vps->setDirectDependencyFlag( layerCtr, refLayerCtr, false );
1258    }
1259    for(i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
1260    {
1261      vps->setDirectDependencyFlag( layerCtr, vps->getLayerIdInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true);
1262    }
1263    // prediction indications
1264    vps->setDirectDepTypeLen(2); // sample and motion types are encoded
1265    for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
1266    {
1267      if (vps->getDirectDependencyFlag( layerCtr, refLayerCtr))
1268      {
1269        assert(m_acTEncTop[layerCtr].getSamplePredEnabledFlag(refLayerCtr) || m_acTEncTop[layerCtr].getMotionPredEnabledFlag(refLayerCtr));
1270        vps->setDirectDependencyType( layerCtr, refLayerCtr, ((m_acTEncTop[layerCtr].getSamplePredEnabledFlag(refLayerCtr) ? 1 : 0) |
1271                                                              (m_acTEncTop[layerCtr].getMotionPredEnabledFlag(refLayerCtr) ? 2 : 0)) - 1);
1272#if O0096_DEFAULT_DEPENDENCY_TYPE
1273        if (!isDefaultDirectDependencyTypeSet)
1274        {
1275          vps->setDefaultDirectDependecyTypeFlag(1);
1276          vps->setDefaultDirectDependecyType(vps->getDirectDependencyType(layerCtr, refLayerCtr));
1277          isDefaultDirectDependencyTypeSet = true;
1278        }
1279        else if (vps->getDirectDependencyType(layerCtr, refLayerCtr) != vps->getDefaultDirectDependencyType())
1280        {
1281          vps->setDefaultDirectDependecyTypeFlag(0);
1282        }
1283#endif
1284      }
1285      else
1286      {
1287        vps->setDirectDependencyType( layerCtr, refLayerCtr, 0 );
1288      }
1289    }
1290  }
1291
1292#if O0092_0094_DEPENDENCY_CONSTRAINT
1293  for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
1294  {
1295    vps->setNumRefLayers(vps->getLayerIdInNuh(layerCtr));   // identify the number of direct and indirect reference layers of current layer and set recursiveRefLayersFlags
1296  }
1297  if(vps->getMaxLayers() > MAX_REF_LAYERS)
1298  {
1299    for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
1300    {
1301      assert( vps->getNumRefLayers(vps->getLayerIdInNuh(layerCtr)) <= MAX_REF_LAYERS);
1302    }
1303  }
1304#endif
1305#endif
1306    vps->setMaxOneActiveRefLayerFlag(maxDirectRefLayers > 1 ? false : true);
1307#if O0062_POC_LSB_NOT_PRESENT_FLAG
1308    for(i = 1; i< vps->getMaxLayers(); i++)
1309    {
1310      if( vps->getNumDirectRefLayers( vps->getLayerIdInNuh(i) ) == 0  )
1311      {
1312        vps->setPocLsbNotPresentFlag(i, false);
1313      }
1314    }
1315#endif
1316#if O0223_PICTURE_TYPES_ALIGN_FLAG
1317    vps->setCrossLayerPictureTypeAlignFlag( m_crossLayerPictureTypeAlignFlag );
1318#endif
1319#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
1320    vps->setCrossLayerAlignedIdrOnlyFlag( m_crossLayerAlignedIdrOnlyFlag );
1321#endif
1322#if N0147_IRAP_ALIGN_FLAG
1323    vps->setCrossLayerIrapAlignFlag( m_crossLayerIrapAlignFlag );
1324    for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
1325    {
1326      for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
1327      {
1328        if (vps->getDirectDependencyFlag( layerCtr, refLayerCtr))
1329        {
1330          if(m_acTEncTop[layerCtr].getIntraPeriod() !=  m_acTEncTop[refLayerCtr].getIntraPeriod())
1331          {
1332            vps->setCrossLayerIrapAlignFlag(false);
1333            break;
1334          }
1335        }
1336      }
1337    }
1338#endif
1339#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1340  vps->setSingleLayerForNonIrapFlag(m_adaptiveResolutionChange > 0 ? true : false);
1341#endif
1342#if HIGHER_LAYER_IRAP_SKIP_FLAG
1343  vps->setHigherLayerIrapSkipFlag(m_skipPictureAtArcSwitch);
1344#endif
1345#if !P0125_REVERT_VPS_EXTN_OFFSET_TO_RESERVED
1346#if !VPS_EXTN_OFFSET_CALC
1347#if VPS_EXTN_OFFSET
1348  // to be updated according to the current semantics
1349  vps->setExtensionOffset( 0xffff );
1350#endif
1351#endif
1352#endif
1353
1354#if O0215_PHASE_ALIGNMENT
1355  vps->setPhaseAlignFlag( m_phaseAlignFlag );
1356#endif
1357
1358#if P0300_ALT_OUTPUT_LAYER_FLAG
1359  for (Int k = 0; k < MAX_VPS_LAYER_SETS_PLUS1; k++)
1360  {
1361    vps->setAltOuputLayerFlag( k, m_altOutputLayerFlag );
1362  }
1363#else
1364#if O0153_ALT_OUTPUT_LAYER_FLAG
1365  vps->setAltOuputLayerFlag( m_altOutputLayerFlag );
1366#endif
1367#endif
1368
1369#if P0312_VERT_PHASE_ADJ
1370  Bool vpsVuiVertPhaseInUseFlag = false;
1371  for( UInt layerId = 1; layerId < m_numLayers; layerId++ )
1372  {
1373    for( i = 0; i < m_acLayerCfg[layerId].m_numScaledRefLayerOffsets; i++ )
1374    {
1375      if( m_acTEncTop[layerId].getVertPhasePositionEnableFlag(i) )
1376      {
1377        vpsVuiVertPhaseInUseFlag = true;
1378        break;
1379      }
1380    }
1381  }
1382  vps->setVpsVuiVertPhaseInUseFlag( vpsVuiVertPhaseInUseFlag );
1383#endif
1384
1385#if O0164_MULTI_LAYER_HRD
1386  vps->setVpsVuiBspHrdPresentFlag(false);
1387  TEncTop *pcCfg = &m_acTEncTop[0];
1388  if( pcCfg->getBufferingPeriodSEIEnabled() )
1389  {
1390    vps->setVpsVuiBspHrdPresentFlag(true);
1391    vps->setVpsNumBspHrdParametersMinus1(vps->getNumLayerSets() - 2); 
1392    vps->createBspHrdParamBuffer(vps->getVpsNumBspHrdParametersMinus1() + 1);
1393    for ( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
1394    {
1395      vps->setBspCprmsPresentFlag(i, true);
1396
1397      UInt layerId = i + 1;
1398      TEncTop *pcCfgLayer = &m_acTEncTop[layerId];
1399
1400      Int iPicWidth         = pcCfgLayer->getSourceWidth();
1401      Int iPicHeight        = pcCfgLayer->getSourceHeight();
1402      UInt uiWidthInCU       = ( iPicWidth %m_uiMaxCUWidth  ) ? iPicWidth /m_uiMaxCUWidth  + 1 : iPicWidth /m_uiMaxCUWidth;
1403      UInt uiHeightInCU      = ( iPicHeight%m_uiMaxCUHeight ) ? iPicHeight/m_uiMaxCUHeight + 1 : iPicHeight/m_uiMaxCUHeight;
1404      UInt uiNumCUsInFrame   = uiWidthInCU * uiHeightInCU;
1405
1406      UInt maxCU = pcCfgLayer->getSliceArgument() >> ( m_uiMaxCUDepth << 1);
1407      UInt numDU = ( pcCfgLayer->getSliceMode() == 1 ) ? ( uiNumCUsInFrame / maxCU ) : ( 0 );
1408      if( uiNumCUsInFrame % maxCU != 0 || numDU == 0 )
1409      {
1410        numDU ++;
1411      }
1412      vps->getBspHrd(i)->setNumDU( numDU );
1413      vps->setBspHrdParameters( i, pcCfgLayer->getFrameRate(), numDU, pcCfgLayer->getTargetBitrate(), ( pcCfgLayer->getIntraPeriod() > 0 ) );
1414    }
1415    for(UInt h = 1; h <= (vps->getNumLayerSets()-1); h++)
1416    {
1417      vps->setNumBitstreamPartitions(h, 1);
1418      for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
1419      {
1420        for( UInt j = 0; j <= (vps->getMaxLayers()-1); j++ )
1421        {
1422          if (vps->getLayerIdIncludedFlag(h, j) && h == j)
1423          {
1424            vps->setLayerInBspFlag(h, i, j, true);
1425          }
1426        }
1427      }
1428      vps->setNumBspSchedCombinations(h, 1);
1429      for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
1430      {
1431        for( UInt j = 0; j < vps->getNumBitstreamPartitions(h); j++ )
1432        {
1433          vps->setBspCombHrdIdx(h, i, j, 0);
1434          vps->setBspCombSchedIdx(h, i, j, 0);
1435        }
1436      }
1437    }
1438  }
1439#endif
1440
1441#else //SVC_EXTENSION
1442  m_cTEncTop.init(isFieldCoding);
1443#endif //SVC_EXTENSION
1444}
1445
1446// ====================================================================================================================
1447// Public member functions
1448// ====================================================================================================================
1449
1450/**
1451 - create internal class
1452 - initialize internal variable
1453 - until the end of input YUV file, call encoding function in TEncTop class
1454 - delete allocated buffers
1455 - destroy internal class
1456 .
1457 */
1458#if SVC_EXTENSION
1459Void TAppEncTop::encode()
1460{
1461  fstream bitstreamFile(m_pBitstreamFile, fstream::binary | fstream::out);
1462  if (!bitstreamFile)
1463  {
1464    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pBitstreamFile);
1465    exit(EXIT_FAILURE);
1466  }
1467
1468  TComPicYuv*       pcPicYuvOrg [MAX_LAYERS];
1469  TComPicYuv*       pcPicYuvRec = NULL;
1470
1471  // initialize internal class & member variables
1472  xInitLibCfg();
1473  xCreateLib();
1474  xInitLib(m_isField);
1475
1476  // main encoder loop
1477  Int   iNumEncoded = 0, iTotalNumEncoded = 0;
1478  Bool  bEos = false;
1479
1480  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
1481
1482  for(UInt layer=0; layer<m_numLayers; layer++)
1483  {
1484#if O0194_DIFFERENT_BITDEPTH_EL_BL
1485    //5
1486    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
1487    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
1488
1489    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
1490    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
1491#endif
1492    // allocate original YUV buffer
1493    pcPicYuvOrg[layer] = new TComPicYuv;
1494    if( m_isField )
1495    {
1496#if SVC_UPSAMPLING
1497#if LAYER_CTB
1498#if AUXILIARY_PICTURES
1499      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
1500#else
1501      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
1502#endif
1503#else
1504#if AUXILIARY_PICTURES
1505      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].getChromaFormatIDC(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
1506#else
1507      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
1508#endif
1509#endif
1510#else
1511      pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1512#endif
1513    }
1514    else
1515    {
1516#if SVC_UPSAMPLING
1517#if LAYER_CTB
1518#if AUXILIARY_PICTURES
1519      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
1520#else
1521      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
1522#endif
1523#else
1524#if AUXILIARY_PICTURES
1525      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
1526#else
1527      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
1528#endif
1529#endif
1530#else
1531      pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1532#endif
1533    }
1534  }
1535
1536#if AVC_SYNTAX
1537  fstream streamSyntaxFile;
1538  if( m_acTEncTop[0].getVPS()->getAvcBaseLayerFlag() )
1539  {
1540    if( !m_BLSyntaxFile )
1541    {
1542      printf( "Wrong base layer syntax input file\n" );
1543      exit(EXIT_FAILURE);
1544    }
1545    streamSyntaxFile.open( m_BLSyntaxFile, fstream::in | fstream::binary );
1546    if( !streamSyntaxFile.good() )
1547    {
1548      printf( "Base layer syntax input reading error\n" );
1549      exit(EXIT_FAILURE);
1550    }
1551    m_acTEncTop[0].setBLSyntaxFile( &streamSyntaxFile );
1552  }
1553#endif
1554
1555  Bool bFirstFrame = true;
1556  while ( !bEos )
1557  {
1558    // Read enough frames
1559    Bool bFramesReadyToCode = false;
1560    while(!bFramesReadyToCode)
1561    {
1562      for(UInt layer=0; layer<m_numLayers; layer++)
1563      {
1564#if O0194_DIFFERENT_BITDEPTH_EL_BL
1565        //6
1566        g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
1567        g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
1568
1569        g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
1570        g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
1571#endif
1572#if LAYER_CTB
1573        g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
1574        g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
1575        g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
1576        g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
1577#endif
1578
1579        // get buffers
1580        xGetBuffer(pcPicYuvRec, layer);
1581
1582        // read input YUV file
1583        m_acTVideoIOYuvInputFile[layer].read( pcPicYuvOrg[layer], m_acLayerCfg[layer].getPad() );
1584
1585#if AUXILIARY_PICTURES
1586        if (m_acLayerCfg[layer].getChromaFormatIDC() == CHROMA_400)
1587        {
1588          pcPicYuvOrg[layer]->convertToMonochrome();
1589        }
1590#endif
1591
1592        if(layer == m_numLayers-1)
1593        {
1594          // increase number of received frames
1595          m_iFrameRcvd++;
1596          // check end of file
1597          bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) );
1598        }
1599
1600        if ( m_isField )
1601        {
1602          m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer], m_isTopFieldFirst );
1603        }
1604        else
1605        {
1606          m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer] );
1607        }
1608      }
1609
1610      bFramesReadyToCode = !(!bFirstFrame && ( m_acTEncTop[m_numLayers-1].getNumPicRcvd() != m_iGOPSize && m_iGOPSize ) && !bEos );
1611    }
1612    Bool flush = 0;
1613    // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
1614    if (m_acTVideoIOYuvInputFile[m_numLayers-1].isEof())
1615    {
1616      flush = true;
1617      bEos = true;
1618      m_iFrameRcvd--;
1619      m_acTEncTop[m_numLayers-1].setFramesToBeEncoded(m_iFrameRcvd);
1620    }
1621
1622#if RC_SHVC_HARMONIZATION
1623    for(UInt layer=0; layer<m_numLayers; layer++)
1624    {
1625      if ( m_acTEncTop[layer].getUseRateCtrl() )
1626      {
1627        (m_acTEncTop[layer].getRateCtrl())->initRCGOP(m_acTEncTop[layer].getNumPicRcvd());
1628      }
1629    }
1630#endif
1631
1632#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1633    if (m_adaptiveResolutionChange)
1634    {
1635      for(UInt layer = 0; layer < m_numLayers; layer++)
1636      {
1637        TComList<TComPicYuv*>::iterator iterPicYuvRec;
1638        for (iterPicYuvRec = m_acListPicYuvRec[layer].begin(); iterPicYuvRec != m_acListPicYuvRec[layer].end(); iterPicYuvRec++)
1639        {
1640          TComPicYuv* recPic = *(iterPicYuvRec);
1641          recPic->setReconstructed(false);
1642        }
1643      }
1644    }
1645#endif
1646
1647    // loop through frames in one GOP
1648    for ( UInt iPicIdInGOP=0; iPicIdInGOP < (bFirstFrame? 1:m_iGOPSize); iPicIdInGOP++ )
1649    {
1650      // layer by layer for each frame
1651      for(UInt layer=0; layer<m_numLayers; layer++)
1652      {
1653#if O0194_DIFFERENT_BITDEPTH_EL_BL
1654        //7
1655        g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
1656        g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
1657
1658        g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
1659        g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
1660#endif
1661#if LAYER_CTB
1662        g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
1663        g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
1664        g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
1665        g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
1666
1667        memcpy( g_auiZscanToRaster, g_auiLayerZscanToRaster[layer], sizeof( g_auiZscanToRaster ) );
1668        memcpy( g_auiRasterToZscan, g_auiLayerRasterToZscan[layer], sizeof( g_auiRasterToZscan ) );
1669        memcpy( g_auiRasterToPelX,  g_auiLayerRasterToPelX[layer],  sizeof( g_auiRasterToPelX ) );
1670        memcpy( g_auiRasterToPelY,  g_auiLayerRasterToPelY[layer],  sizeof( g_auiRasterToPelY ) );
1671#endif
1672        // call encoding function for one frame
1673        if ( m_isField )
1674        {
1675          m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP, m_isTopFieldFirst );
1676        }
1677        else
1678        {
1679          m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP );
1680        }
1681      }
1682    }
1683
1684#if RC_SHVC_HARMONIZATION
1685    for(UInt layer=0; layer<m_numLayers; layer++)
1686    {
1687      if ( m_acTEncTop[layer].getUseRateCtrl() )
1688      {
1689        (m_acTEncTop[layer].getRateCtrl())->destroyRCGOP();
1690      }
1691    }
1692#endif
1693
1694    iTotalNumEncoded = 0;
1695    for(UInt layer=0; layer<m_numLayers; layer++)
1696    {
1697#if O0194_DIFFERENT_BITDEPTH_EL_BL
1698      //8
1699      g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
1700      g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
1701
1702      g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
1703      g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
1704#endif
1705      // write bistream to file if necessary
1706      iNumEncoded = m_acTEncTop[layer].getNumPicRcvd();
1707      if ( iNumEncoded > 0 )
1708      {
1709        xWriteRecon(layer, iNumEncoded);
1710        iTotalNumEncoded += iNumEncoded;
1711      }
1712      m_acTEncTop[layer].setNumPicRcvd( 0 );
1713    }
1714
1715    // write bitstream out
1716    if(iTotalNumEncoded)
1717    {
1718#if P0130_EOB
1719      if( bEos )
1720      {
1721        OutputNALUnit nalu(NAL_UNIT_EOB);
1722        nalu.m_layerId = 0;
1723
1724        AccessUnit& accessUnit = outputAccessUnits.back();
1725        nalu.m_temporalId = accessUnit.front()->m_temporalId;
1726        accessUnit.push_back(new NALUnitEBSP(nalu));
1727      }
1728#endif
1729      xWriteStream(bitstreamFile, iTotalNumEncoded, outputAccessUnits);
1730      outputAccessUnits.clear();
1731    }
1732
1733    // print out summary
1734    if (bEos)
1735    {
1736      printOutSummary(m_isTopFieldFirst);
1737    }
1738
1739    bFirstFrame = false;
1740  }
1741  // delete original YUV buffer
1742  for(UInt layer=0; layer<m_numLayers; layer++)
1743  {
1744    pcPicYuvOrg[layer]->destroy();
1745    delete pcPicYuvOrg[layer];
1746    pcPicYuvOrg[layer] = NULL;
1747
1748    // delete used buffers in encoder class
1749    m_acTEncTop[layer].deletePicBuffer();
1750  }
1751
1752#if AVC_SYNTAX
1753  if( streamSyntaxFile.is_open() )
1754  {
1755    streamSyntaxFile.close();
1756  }
1757#endif
1758
1759  // delete buffers & classes
1760  xDeleteBuffer();
1761  xDestroyLib();
1762
1763  printRateSummary();
1764
1765  return;
1766}
1767
1768Void TAppEncTop::printOutSummary(Bool isField)
1769{
1770  UInt layer;
1771
1772  // set frame rate
1773  for(layer = 0; layer < m_numLayers; layer++)
1774  {
1775    if(isField)
1776    {
1777      m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2);
1778      m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2 );
1779      m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2 );
1780      m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2 );
1781    }
1782    else
1783    {
1784      m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate());
1785      m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
1786      m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
1787      m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
1788    }
1789  }
1790
1791  //-- all
1792  printf( "\n\nSUMMARY --------------------------------------------------------\n" );
1793  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
1794  for(layer = 0; layer < m_numLayers; layer++)
1795  {
1796    m_gcAnalyzeAll[layer].printOut('a', layer);
1797  }
1798
1799  printf( "\n\nI Slices--------------------------------------------------------\n" );
1800  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
1801  for(layer = 0; layer < m_numLayers; layer++)
1802  {
1803    m_gcAnalyzeI[layer].printOut('i', layer);
1804  }
1805
1806  printf( "\n\nP Slices--------------------------------------------------------\n" );
1807  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
1808  for(layer = 0; layer < m_numLayers; layer++)
1809  {
1810    m_gcAnalyzeP[layer].printOut('p', layer);
1811  }
1812
1813  printf( "\n\nB Slices--------------------------------------------------------\n" );
1814  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
1815  for(layer = 0; layer < m_numLayers; layer++)
1816  {
1817    m_gcAnalyzeB[layer].printOut('b', layer);
1818  }
1819
1820  if(isField)
1821  {
1822    for(layer = 0; layer < m_numLayers; layer++)
1823    {
1824      //-- interlaced summary
1825      m_gcAnalyzeAll_in.setFrmRate( m_acLayerCfg[layer].getFrameRate());
1826      printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" );
1827      m_gcAnalyzeAll_in.printOutInterlaced('a',  m_gcAnalyzeAll[layer].getBits());
1828
1829#if _SUMMARY_OUT_
1830      m_gcAnalyzeAll_in.printSummaryOutInterlaced();
1831#endif
1832    }
1833  }
1834}
1835
1836#else
1837Void TAppEncTop::encode()
1838{
1839  fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out);
1840  if (!bitstreamFile)
1841  {
1842    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile);
1843    exit(EXIT_FAILURE);
1844  }
1845
1846  TComPicYuv*       pcPicYuvOrg = new TComPicYuv;
1847  TComPicYuv*       pcPicYuvRec = NULL;
1848
1849  // initialize internal class & member variables
1850  xInitLibCfg();
1851  xCreateLib();
1852  xInitLib(m_isField);
1853
1854  // main encoder loop
1855  Int   iNumEncoded = 0;
1856  Bool  bEos = false;
1857
1858  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
1859
1860  // allocate original YUV buffer
1861  if( m_isField )
1862  {
1863    pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeightOrg, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1864  }
1865  else
1866  {
1867    pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1868  }
1869
1870  while ( !bEos )
1871  {
1872    // get buffers
1873    xGetBuffer(pcPicYuvRec);
1874
1875    // read input YUV file
1876    m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, m_aiPad );
1877
1878    // increase number of received frames
1879    m_iFrameRcvd++;
1880
1881    bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) );
1882    Bool flush = 0;
1883    // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
1884    if (m_cTVideoIOYuvInputFile.isEof())
1885    {
1886      flush = true;
1887      bEos = true;
1888      m_iFrameRcvd--;
1889      m_cTEncTop.setFramesToBeEncoded(m_iFrameRcvd);
1890    }
1891
1892    // call encoding function for one frame
1893    if ( m_isField )
1894    {
1895      m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded, m_isTopFieldFirst);
1896    }
1897    else
1898    {
1899    m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded );
1900    }
1901
1902    // write bistream to file if necessary
1903    if ( iNumEncoded > 0 )
1904    {
1905      xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits);
1906      outputAccessUnits.clear();
1907    }
1908  }
1909
1910  m_cTEncTop.printSummary(m_isField);
1911
1912  // delete original YUV buffer
1913  pcPicYuvOrg->destroy();
1914  delete pcPicYuvOrg;
1915  pcPicYuvOrg = NULL;
1916
1917  // delete used buffers in encoder class
1918  m_cTEncTop.deletePicBuffer();
1919
1920  // delete buffers & classes
1921  xDeleteBuffer();
1922  xDestroyLib();
1923
1924  printRateSummary();
1925
1926  return;
1927}
1928#endif
1929
1930// ====================================================================================================================
1931// Protected member functions
1932// ====================================================================================================================
1933
1934/**
1935 - application has picture buffer list with size of GOP
1936 - picture buffer list acts as ring buffer
1937 - end of the list has the latest picture
1938 .
1939 */
1940#if SVC_EXTENSION
1941Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer)
1942{
1943  assert( m_iGOPSize > 0 );
1944
1945  // org. buffer
1946  if ( m_acListPicYuvRec[layer].size() == (UInt)m_iGOPSize )
1947  {
1948    rpcPicYuvRec = m_acListPicYuvRec[layer].popFront();
1949
1950  }
1951  else
1952  {
1953    rpcPicYuvRec = new TComPicYuv;
1954
1955#if SVC_UPSAMPLING
1956#if LAYER_CTB
1957#if AUXILIARY_PICTURES
1958    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
1959#else
1960    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
1961#endif
1962#else
1963#if AUXILIARY_PICTURES
1964    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
1965#else
1966    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
1967#endif
1968#endif
1969#else
1970    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1971#endif
1972
1973  }
1974  m_acListPicYuvRec[layer].pushBack( rpcPicYuvRec );
1975}
1976
1977Void TAppEncTop::xDeleteBuffer( )
1978{
1979  for(UInt layer=0; layer<m_numLayers; layer++)
1980  {
1981    TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_acListPicYuvRec[layer].begin();
1982
1983    Int iSize = Int( m_acListPicYuvRec[layer].size() );
1984
1985    for ( Int i = 0; i < iSize; i++ )
1986    {
1987      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1988      pcPicYuvRec->destroy();
1989      delete pcPicYuvRec; pcPicYuvRec = NULL;
1990    }
1991  }
1992}
1993
1994Void TAppEncTop::xWriteRecon(UInt layer, Int iNumEncoded)
1995{
1996  if (m_isField)
1997  {
1998    //Reinterlace fields
1999    Int i;
2000    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end();
2001
2002    for ( i = 0; i < iNumEncoded; i++ )
2003    {
2004      --iterPicYuvRec;
2005    }
2006
2007    for ( i = 0; i < iNumEncoded/2; i++ )
2008    {
2009      TComPicYuv*  pcPicYuvRecTop  = *(iterPicYuvRec++);
2010      TComPicYuv*  pcPicYuvRecBottom  = *(iterPicYuvRec++);
2011
2012#if M0040_ADAPTIVE_RESOLUTION_CHANGE
2013      if (!m_acLayerCfg[layer].getReconFile().empty() && pcPicYuvRecTop->isReconstructed() && pcPicYuvRecBottom->isReconstructed())
2014#else
2015      if (!m_acLayerCfg[layer].getReconFile().empty())
2016#endif
2017      {
2018        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRecTop, pcPicYuvRecBottom, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(), m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom(), m_isTopFieldFirst );
2019      }
2020    }
2021  }
2022  else
2023  {
2024    Int i;
2025
2026    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end();
2027
2028    for ( i = 0; i < iNumEncoded; i++ )
2029    {
2030      --iterPicYuvRec;
2031    }
2032
2033    for ( i = 0; i < iNumEncoded; i++ )
2034    {
2035      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
2036#if M0040_ADAPTIVE_RESOLUTION_CHANGE
2037      if (!m_acLayerCfg[layer].getReconFile().empty() && pcPicYuvRec->isReconstructed())
2038#else
2039      if (!m_acLayerCfg[layer].getReconFile().empty())
2040#endif
2041      {
2042        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(),
2043          m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom() );
2044      }
2045    }
2046  }
2047}
2048
2049Void TAppEncTop::xWriteStream(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
2050{
2051  if (m_isField)
2052  {
2053    //Reinterlace fields
2054    Int i;
2055    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
2056
2057#if M0040_ADAPTIVE_RESOLUTION_CHANGE
2058    for ( i = 0; i < iNumEncoded/2 && iterBitstream != accessUnits.end(); i++ )
2059#else
2060    for ( i = 0; i < iNumEncoded/2; i++ )
2061#endif
2062    {
2063      const AccessUnit& auTop = *(iterBitstream++);
2064      const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
2065      rateStatsAccum(auTop, statsTop);
2066
2067      const AccessUnit& auBottom = *(iterBitstream++);
2068      const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom);
2069      rateStatsAccum(auBottom, statsBottom);
2070    }
2071  }
2072  else
2073  {
2074    Int i;
2075
2076    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
2077
2078#if M0040_ADAPTIVE_RESOLUTION_CHANGE
2079    for ( i = 0; i < iNumEncoded && iterBitstream != accessUnits.end(); i++ )
2080#else
2081    for ( i = 0; i < iNumEncoded; i++ )
2082#endif
2083    {
2084      const AccessUnit& au = *(iterBitstream++);
2085      const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
2086      rateStatsAccum(au, stats);
2087    }
2088  }
2089}
2090
2091#else // SVC_EXTENSION
2092Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec)
2093{
2094  assert( m_iGOPSize > 0 );
2095
2096  // org. buffer
2097  if ( m_cListPicYuvRec.size() == (UInt)m_iGOPSize )
2098  {
2099    rpcPicYuvRec = m_cListPicYuvRec.popFront();
2100
2101  }
2102  else
2103  {
2104    rpcPicYuvRec = new TComPicYuv;
2105
2106    rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
2107
2108  }
2109  m_cListPicYuvRec.pushBack( rpcPicYuvRec );
2110}
2111
2112Void TAppEncTop::xDeleteBuffer( )
2113{
2114  TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvRec.begin();
2115
2116  Int iSize = Int( m_cListPicYuvRec.size() );
2117
2118  for ( Int i = 0; i < iSize; i++ )
2119  {
2120    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
2121    pcPicYuvRec->destroy();
2122    delete pcPicYuvRec; pcPicYuvRec = NULL;
2123  }
2124
2125}
2126
2127/** \param iNumEncoded  number of encoded frames
2128 */
2129Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
2130{
2131  if (m_isField)
2132  {
2133    //Reinterlace fields
2134    Int i;
2135    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
2136    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
2137
2138    for ( i = 0; i < iNumEncoded; i++ )
2139    {
2140      --iterPicYuvRec;
2141    }
2142
2143    for ( i = 0; i < iNumEncoded/2; i++ )
2144    {
2145      TComPicYuv*  pcPicYuvRecTop  = *(iterPicYuvRec++);
2146      TComPicYuv*  pcPicYuvRecBottom  = *(iterPicYuvRec++);
2147
2148      if (m_pchReconFile)
2149      {
2150        m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, m_confLeft, m_confRight, m_confTop, m_confBottom, m_isTopFieldFirst );
2151      }
2152
2153      const AccessUnit& auTop = *(iterBitstream++);
2154      const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
2155      rateStatsAccum(auTop, statsTop);
2156
2157      const AccessUnit& auBottom = *(iterBitstream++);
2158      const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom);
2159      rateStatsAccum(auBottom, statsBottom);
2160    }
2161  }
2162  else
2163  {
2164    Int i;
2165
2166    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
2167    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
2168
2169    for ( i = 0; i < iNumEncoded; i++ )
2170    {
2171      --iterPicYuvRec;
2172    }
2173
2174    for ( i = 0; i < iNumEncoded; i++ )
2175    {
2176      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
2177      if (m_pchReconFile)
2178      {
2179#if SYNTAX_OUTPUT
2180        m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
2181#endif
2182      }
2183
2184      const AccessUnit& au = *(iterBitstream++);
2185      const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
2186      rateStatsAccum(au, stats);
2187    }
2188  }
2189}
2190#endif
2191
2192/**
2193 *
2194 */
2195void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& annexBsizes)
2196{
2197  AccessUnit::const_iterator it_au = au.begin();
2198  vector<UInt>::const_iterator it_stats = annexBsizes.begin();
2199
2200  for (; it_au != au.end(); it_au++, it_stats++)
2201  {
2202    switch ((*it_au)->m_nalUnitType)
2203    {
2204    case NAL_UNIT_CODED_SLICE_TRAIL_R:
2205    case NAL_UNIT_CODED_SLICE_TRAIL_N:
2206    case NAL_UNIT_CODED_SLICE_TSA_R:
2207    case NAL_UNIT_CODED_SLICE_TSA_N:
2208    case NAL_UNIT_CODED_SLICE_STSA_R:
2209    case NAL_UNIT_CODED_SLICE_STSA_N:
2210    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
2211    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
2212    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
2213    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
2214    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
2215    case NAL_UNIT_CODED_SLICE_CRA:
2216    case NAL_UNIT_CODED_SLICE_RADL_N:
2217    case NAL_UNIT_CODED_SLICE_RADL_R:
2218    case NAL_UNIT_CODED_SLICE_RASL_N:
2219    case NAL_UNIT_CODED_SLICE_RASL_R:
2220    case NAL_UNIT_VPS:
2221    case NAL_UNIT_SPS:
2222    case NAL_UNIT_PPS:
2223      m_essentialBytes += *it_stats;
2224      break;
2225    default:
2226      break;
2227    }
2228
2229    m_totalBytes += *it_stats;
2230  }
2231}
2232
2233void TAppEncTop::printRateSummary()
2234{
2235#if SVC_EXTENSION
2236  Double time = (Double) m_iFrameRcvd / m_acLayerCfg[m_numLayers-1].getFrameRate();
2237#else
2238  Double time = (Double) m_iFrameRcvd / m_iFrameRate;
2239#endif
2240  printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time);
2241#if VERBOSE_RATE
2242  printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time);
2243#endif
2244}
2245
2246//! \}
Note: See TracBrowser for help on using the repository browser.