source: SHVCSoftware/branches/SHM-4.1-dev/source/App/TAppEncoder/TAppEncTop.cpp @ 601

Last change on this file since 601 was 544, checked in by seregin, 11 years ago

JCTVC-O0109. Patch was provided by Yongjin Cho <choyongjin@…>

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