source: SHVCSoftware/branches/SHM-3.0-dev/source/App/TAppEncoder/TAppEncTop.cpp @ 582

Last change on this file since 582 was 339, checked in by seregin, 11 years ago

fix compilation warnings

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