source: SHVCSoftware/branches/SHM-2.0-dev/source/App/TAppEncoder/TAppEncTop.cpp @ 1505

Last change on this file since 1505 was 184, checked in by qualcomm, 12 years ago

Configuration file support related to r175.

Added configuation file support for specifying scaled reference layer offsets for more than one enhancement layer.

From: Adarsh K. Ramasubramonian <aramasub@…>

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