source: SHVCSoftware/branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncTop.cpp @ 464

Last change on this file since 464 was 464, checked in by qualcomm, 11 years ago

JCTVC-O0215: a VPS flag to specify the phase alignment between layers (zero or center phase shift) for up-sampling process, from cjianle@…

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