source: SHVCSoftware/branches/SHM-2.1-multilayers-dev/source/App/TAppEncoder/TAppEncTop.cpp @ 1547

Last change on this file since 1547 was 269, checked in by seregin, 12 years ago

add config parameter for NumActiveRefLayers

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