source: 3DVCSoftware/branches/HTM-12.1-MV-draft-1/source/App/TAppEncoder/TAppEncTop.cpp

Last change on this file was 1072, checked in by tech, 11 years ago

Removed 3D-HEVC related integrations.

  • Property svn:eol-style set to native
File size: 64.9 KB
RevLine 
[5]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
[56]4 * granted under this license. 
[5]5 *
[872]6* Copyright (c) 2010-2014, ITU/ISO/IEC
[5]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.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]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 */
[2]33
34/** \file     TAppEncTop.cpp
35    \brief    Encoder application class
36*/
37
38#include <list>
[56]39#include <fstream>
40#include <stdlib.h>
[2]41#include <stdio.h>
42#include <fcntl.h>
43#include <assert.h>
44
45#include "TAppEncTop.h"
[56]46#include "TLibEncoder/AnnexBwrite.h"
[2]47
[56]48using namespace std;
49
50//! \ingroup TAppEncoder
51//! \{
52
[2]53// ====================================================================================================================
54// Constructor / destructor / initialization / destroy
55// ====================================================================================================================
56
57TAppEncTop::TAppEncTop()
58{
[964]59
[976]60#if H_MV
[964]61  m_vps = new TComVPS; 
[976]62#else
[608]63  m_iFrameRcvd = 0;
64#endif
[56]65  m_totalBytes = 0;
66  m_essentialBytes = 0;
[2]67}
68
69TAppEncTop::~TAppEncTop()
70{
[976]71#if H_MV
[964]72  if (m_vps)
73  {
74   delete m_vps; 
75  };
76#endif
77
[2]78}
79
80Void TAppEncTop::xInitLibCfg()
81{
[608]82#if H_MV
[964]83  TComVPS& vps = (*m_vps);   
84#else
[608]85  TComVPS vps;
[210]86#endif
[608]87 
[758]88
[608]89#if H_MV
90  Int maxTempLayer = -1; 
91  for (Int j = 0; j < m_numberOfLayers; j++)
[77]92  {
[608]93    maxTempLayer = max( m_maxTempLayerMvc[ j ], maxTempLayer ); 
[77]94  }
[608]95
96  vps.setMaxTLayers                       ( maxTempLayer );
97  if ( maxTempLayer )
[2]98  {
[608]99    vps.setTemporalNestingFlag(true);
100  }
[622]101  vps.setMaxLayersMinus1( m_numberOfLayers - 1);
[608]102  for(Int i = 0; i < MAX_TLAYER; i++)
103  {
104    Int maxNumReOrderPics  = 0; 
105    Int maxDecPicBuffering = 0;
106    for (Int j = 0; j < m_numberOfLayers; j++)
[56]107    {
[608]108      maxNumReOrderPics  = max( maxNumReOrderPics,  m_numReorderPicsMvc    [ j ][ i ] );     
109      maxDecPicBuffering = max( maxDecPicBuffering, m_maxDecPicBufferingMvc[ j ][ i ] );     
[56]110    }
[2]111
[608]112    vps.setNumReorderPics                 ( maxNumReOrderPics  ,i );
113    vps.setMaxDecPicBuffering             ( maxDecPicBuffering ,i );
114  }
115#else
116  vps.setMaxTLayers                       ( m_maxTempLayer );
117  if (m_maxTempLayer == 1)
118  {
119    vps.setTemporalNestingFlag(true);
120  }
121  vps.setMaxLayers                        ( 1 );
122  for(Int i = 0; i < MAX_TLAYER; i++)
123  {
124    vps.setNumReorderPics                 ( m_numReorderPics[i], i );
125    vps.setMaxDecPicBuffering             ( m_maxDecPicBuffering[i], i );
126  }
[210]127#endif
[608]128#if H_MV
129  xSetLayerIds             ( vps );   
130  xSetDimensionIdAndLength ( vps );
[1066]131  xSetDependencies         ( vps );
132  xSetRepFormat            ( vps ); 
[608]133  xSetProfileTierLevel     ( vps ); 
134  xSetLayerSets            ( vps ); 
[872]135  xSetDpbSize              ( vps ); 
[622]136  xSetVPSVUI               ( vps ); 
[1066]137#if H_MV_HLS10_GEN_FIX
138  if ( m_targetEncLayerIdList.size() == 0 )
139  {
140    for (Int i = 0; i < m_numberOfLayers; i++ )
141    {
142      m_targetEncLayerIdList.push_back( vps.getLayerIdInNuh( i ) );
143    }
144  }
145  for( Int i = (Int) m_targetEncLayerIdList.size()-1 ; i >= 0 ; i--)
146  {
147    Int iNuhLayerId = m_targetEncLayerIdList[i]; 
148    Bool allRefLayersPresent = true; 
149    for( Int j = 0; j < vps.getNumRefLayers( iNuhLayerId ); j++)
150    {
151      allRefLayersPresent = allRefLayersPresent && xLayerIdInTargetEncLayerIdList( vps.getIdRefLayer( iNuhLayerId, j) );
152    }
153    if ( !allRefLayersPresent )
154    {
155      printf("\nCannot encode layer with nuh_layer_id equal to %d since not all reference layers are in TargetEncLayerIdList\n", iNuhLayerId);
156      m_targetEncLayerIdList.erase( m_targetEncLayerIdList.begin() + i  );
157    }
158  }
159#endif
[56]160
[1066]161#if H_MV_HLS10_ADD_LAYERSETS
162  if ( m_outputVpsInfo )
163  { 
164#if H_MV_HLS10_AUX
165    vps.printScalabilityId();
166#endif
167    vps.printLayerDependencies();
168    vps.printLayerSets(); 
169    vps.printPTL(); 
170  }
171#endif
[622]172
173  for(Int layerIdInVps = 0; layerIdInVps < m_numberOfLayers; layerIdInVps++)
[608]174  {
175    m_frameRcvd                 .push_back(0);
176    m_acTEncTopList             .push_back(new TEncTop); 
177    m_acTVideoIOYuvInputFileList.push_back(new TVideoIOYuv);
178    m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv);
179    m_picYuvRec                 .push_back(new TComList<TComPicYuv*>) ;
[622]180    m_ivPicLists.push_back( m_acTEncTopList[ layerIdInVps ]->getListPic()  ); 
181    TEncTop& m_cTEncTop = *m_acTEncTopList[ layerIdInVps ];  // It is not a member, but this name helps avoiding code duplication !!!
[56]182
[622]183    Int layerId = vps.getLayerIdInNuh( layerIdInVps );
184    m_cTEncTop.setLayerIdInVps                 ( layerIdInVps ); 
185    m_cTEncTop.setLayerId                      ( layerId );   
186    m_cTEncTop.setViewId                       ( vps.getViewId      (  layerId ) );
187    m_cTEncTop.setViewIndex                    ( vps.getViewIndex   (  layerId ) );
[2]188
[608]189    m_cTEncTop.setIvPicLists                   ( &m_ivPicLists ); 
[773]190#endif  // H_MV
[608]191  m_cTEncTop.setVPS(&vps);
[2]192
[758]193
[1066]194#if H_MV
195  m_cTEncTop.setProfile(m_profile[0]);
196  m_cTEncTop.setLevel  (m_levelTier[0], m_level[0]);
197#else
[608]198  m_cTEncTop.setProfile(m_profile);
199  m_cTEncTop.setLevel(m_levelTier, m_level);
[1066]200#endif
[608]201  m_cTEncTop.setProgressiveSourceFlag(m_progressiveSourceFlag);
202  m_cTEncTop.setInterlacedSourceFlag(m_interlacedSourceFlag);
203  m_cTEncTop.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
204  m_cTEncTop.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
[56]205 
[608]206  m_cTEncTop.setFrameRate                    ( m_iFrameRate );
207  m_cTEncTop.setFrameSkip                    ( m_FrameSkip );
208  m_cTEncTop.setSourceWidth                  ( m_iSourceWidth );
209  m_cTEncTop.setSourceHeight                 ( m_iSourceHeight );
210  m_cTEncTop.setConformanceWindow            ( m_confLeft, m_confRight, m_confTop, m_confBottom );
211  m_cTEncTop.setFramesToBeEncoded            ( m_framesToBeEncoded );
212 
213  //====== Coding Structure ========
[773]214#if H_MV
[738]215  m_cTEncTop.setIntraPeriod                  ( m_iIntraPeriod[ layerIdInVps ] );
216#else
[608]217  m_cTEncTop.setIntraPeriod                  ( m_iIntraPeriod );
[738]218#endif
[608]219  m_cTEncTop.setDecodingRefreshType          ( m_iDecodingRefreshType );
220  m_cTEncTop.setGOPSize                      ( m_iGOPSize );
221#if H_MV
[622]222m_cTEncTop.setGopList                      ( m_GOPListMvc[layerIdInVps] );
223  m_cTEncTop.setExtraRPSs                    ( m_extraRPSsMvc[layerIdInVps] );
224  for(Int i = 0; i < MAX_TLAYER; i++)
225  {
226    m_cTEncTop.setNumReorderPics             ( m_numReorderPicsMvc[layerIdInVps][i], i );
227    m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBufferingMvc[layerIdInVps][i], i );
228  }
229#else
[608]230  m_cTEncTop.setGopList                      ( m_GOPList );
231  m_cTEncTop.setExtraRPSs                    ( m_extraRPSs );
232  for(Int i = 0; i < MAX_TLAYER; i++)
233  {
234    m_cTEncTop.setNumReorderPics             ( m_numReorderPics[i], i );
235    m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBuffering[i], i );
236  }
[189]237#endif
[608]238  for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
239  {
240    m_cTEncTop.setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
[2]241  }
[608]242#if H_MV
[622]243  m_cTEncTop.setQP                           ( m_iQP[layerIdInVps] );
244#else
[608]245  m_cTEncTop.setQP                           ( m_iQP );
[210]246#endif
247
[608]248  m_cTEncTop.setPad                          ( m_aiPad );
[2]249
[608]250#if H_MV
[622]251  m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayerMvc[layerIdInVps] );
252#else
[608]253  m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayer );
[210]254#endif
[608]255  m_cTEncTop.setUseAMP( m_enableAMP );
256 
257  //===== Slice ========
258 
259  //====== Loop/Deblock Filter ========
260#if H_MV
[622]261  m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable[layerIdInVps]);
262#else
[608]263  m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable       );
[313]264#endif
[608]265  m_cTEncTop.setLoopFilterOffsetInPPS        ( m_loopFilterOffsetInPPS );
266  m_cTEncTop.setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
267  m_cTEncTop.setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
268  m_cTEncTop.setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
269  m_cTEncTop.setDeblockingFilterMetric       ( m_DeblockingFilterMetric );
[2]270
[608]271  //====== Motion search ========
272  m_cTEncTop.setFastSearch                   ( m_iFastSearch  );
273  m_cTEncTop.setSearchRange                  ( m_iSearchRange );
274  m_cTEncTop.setBipredSearchRange            ( m_bipredSearchRange );
[2]275
[608]276  //====== Quality control ========
277  m_cTEncTop.setMaxDeltaQP                   ( m_iMaxDeltaQP  );
278  m_cTEncTop.setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
[2]279
[608]280  m_cTEncTop.setChromaCbQpOffset               ( m_cbQpOffset     );
281  m_cTEncTop.setChromaCrQpOffset            ( m_crQpOffset  );
[56]282
283#if ADAPTIVE_QP_SELECTION
[608]284  m_cTEncTop.setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
[56]285#endif
286
[608]287  m_cTEncTop.setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
288  m_cTEncTop.setQPAdaptationRange            ( m_iQPAdaptationRange );
289 
290  //====== Tool list ========
291  m_cTEncTop.setDeltaQpRD                    ( m_uiDeltaQpRD  );
292  m_cTEncTop.setUseASR                       ( m_bUseASR      );
293  m_cTEncTop.setUseHADME                     ( m_bUseHADME    );
294#if H_MV
[622]295  m_cTEncTop.setdQPs                         ( m_aidQP[layerIdInVps]   );
296#else
[608]297  m_cTEncTop.setdQPs                         ( m_aidQP        );
[5]298#endif
[608]299  m_cTEncTop.setUseRDOQ                      ( m_useRDOQ     );
300  m_cTEncTop.setUseRDOQTS                    ( m_useRDOQTS   );
301  m_cTEncTop.setRDpenalty                 ( m_rdPenalty );
302  m_cTEncTop.setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
303  m_cTEncTop.setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
304  m_cTEncTop.setQuadtreeTUMaxDepthInter      ( m_uiQuadtreeTUMaxDepthInter );
305  m_cTEncTop.setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
306  m_cTEncTop.setUseFastEnc                   ( m_bUseFastEnc  );
307  m_cTEncTop.setUseEarlyCU                   ( m_bUseEarlyCU  ); 
308  m_cTEncTop.setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
309  m_cTEncTop.setUseCbfFastMode            ( m_bUseCbfFastMode  );
310  m_cTEncTop.setUseEarlySkipDetection            ( m_useEarlySkipDetection );
[2]311
[608]312  m_cTEncTop.setUseTransformSkip             ( m_useTransformSkip      );
313  m_cTEncTop.setUseTransformSkipFast         ( m_useTransformSkipFast  );
314  m_cTEncTop.setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
315  m_cTEncTop.setPCMLog2MinSize          ( m_uiPCMLog2MinSize);
316  m_cTEncTop.setUsePCM                       ( m_usePCM );
317  m_cTEncTop.setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
318  m_cTEncTop.setMaxNumMergeCand              ( m_maxNumMergeCand );
319 
[443]320
[608]321  //====== Weighted Prediction ========
322  m_cTEncTop.setUseWP                   ( m_useWeightedPred      );
323  m_cTEncTop.setWPBiPred                ( m_useWeightedBiPred   );
324  //====== Parallel Merge Estimation ========
325  m_cTEncTop.setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 );
[443]326
[608]327  //====== Slice ========
328  m_cTEncTop.setSliceMode               ( m_sliceMode                );
329  m_cTEncTop.setSliceArgument           ( m_sliceArgument            );
[56]330
[608]331  //====== Dependent Slice ========
332  m_cTEncTop.setSliceSegmentMode        ( m_sliceSegmentMode         );
333  m_cTEncTop.setSliceSegmentArgument    ( m_sliceSegmentArgument     );
334  Int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
335  if(m_sliceSegmentMode==FIXED_NUMBER_OF_LCU)
336  {
337    m_cTEncTop.setSliceSegmentArgument ( m_sliceSegmentArgument * iNumPartInCU );
338  }
339  if(m_sliceMode==FIXED_NUMBER_OF_LCU)
340  {
341    m_cTEncTop.setSliceArgument ( m_sliceArgument * iNumPartInCU );
342  }
343  if(m_sliceMode==FIXED_NUMBER_OF_TILES)
344  {
345    m_cTEncTop.setSliceArgument ( m_sliceArgument );
346  }
347 
348  if(m_sliceMode == 0 )
349  {
350    m_bLFCrossSliceBoundaryFlag = true;
351  }
352  m_cTEncTop.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
353#if H_MV
[622]354  m_cTEncTop.setUseSAO ( m_bUseSAO[layerIdInVps] );
355#else
[608]356  m_cTEncTop.setUseSAO ( m_bUseSAO );
[189]357#endif
[608]358  m_cTEncTop.setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
[2]359
[608]360  m_cTEncTop.setSaoLcuBoundary (m_saoLcuBoundary);
361  m_cTEncTop.setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
362  m_cTEncTop.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
[56]363
[608]364  m_cTEncTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
365  m_cTEncTop.setRecoveryPointSEIEnabled( m_recoveryPointSEIEnabled );
366  m_cTEncTop.setBufferingPeriodSEIEnabled( m_bufferingPeriodSEIEnabled );
367  m_cTEncTop.setPictureTimingSEIEnabled( m_pictureTimingSEIEnabled );
368  m_cTEncTop.setToneMappingInfoSEIEnabled                 ( m_toneMappingInfoSEIEnabled );
369  m_cTEncTop.setTMISEIToneMapId                           ( m_toneMapId );
370  m_cTEncTop.setTMISEIToneMapCancelFlag                   ( m_toneMapCancelFlag );
371  m_cTEncTop.setTMISEIToneMapPersistenceFlag              ( m_toneMapPersistenceFlag );
372  m_cTEncTop.setTMISEICodedDataBitDepth                   ( m_toneMapCodedDataBitDepth );
373  m_cTEncTop.setTMISEITargetBitDepth                      ( m_toneMapTargetBitDepth );
374  m_cTEncTop.setTMISEIModelID                             ( m_toneMapModelId );
375  m_cTEncTop.setTMISEIMinValue                            ( m_toneMapMinValue );
376  m_cTEncTop.setTMISEIMaxValue                            ( m_toneMapMaxValue );
377  m_cTEncTop.setTMISEISigmoidMidpoint                     ( m_sigmoidMidpoint );
378  m_cTEncTop.setTMISEISigmoidWidth                        ( m_sigmoidWidth );
379  m_cTEncTop.setTMISEIStartOfCodedInterva                 ( m_startOfCodedInterval );
380  m_cTEncTop.setTMISEINumPivots                           ( m_numPivots );
381  m_cTEncTop.setTMISEICodedPivotValue                     ( m_codedPivotValue );
382  m_cTEncTop.setTMISEITargetPivotValue                    ( m_targetPivotValue );
383  m_cTEncTop.setTMISEICameraIsoSpeedIdc                   ( m_cameraIsoSpeedIdc );
384  m_cTEncTop.setTMISEICameraIsoSpeedValue                 ( m_cameraIsoSpeedValue );
[964]385  m_cTEncTop.setTMISEIExposureIndexIdc                    ( m_exposureIndexIdc );
386  m_cTEncTop.setTMISEIExposureIndexValue                  ( m_exposureIndexValue );
[608]387  m_cTEncTop.setTMISEIExposureCompensationValueSignFlag   ( m_exposureCompensationValueSignFlag );
388  m_cTEncTop.setTMISEIExposureCompensationValueNumerator  ( m_exposureCompensationValueNumerator );
389  m_cTEncTop.setTMISEIExposureCompensationValueDenomIdc   ( m_exposureCompensationValueDenomIdc );
390  m_cTEncTop.setTMISEIRefScreenLuminanceWhite             ( m_refScreenLuminanceWhite );
391  m_cTEncTop.setTMISEIExtendedRangeWhiteLevel             ( m_extendedRangeWhiteLevel );
392  m_cTEncTop.setTMISEINominalBlackLevelLumaCodeValue      ( m_nominalBlackLevelLumaCodeValue );
393  m_cTEncTop.setTMISEINominalWhiteLevelLumaCodeValue      ( m_nominalWhiteLevelLumaCodeValue );
394  m_cTEncTop.setTMISEIExtendedWhiteLevelLumaCodeValue     ( m_extendedWhiteLevelLumaCodeValue );
395  m_cTEncTop.setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled );
396  m_cTEncTop.setFramePackingArrangementSEIType( m_framePackingSEIType );
397  m_cTEncTop.setFramePackingArrangementSEIId( m_framePackingSEIId );
398  m_cTEncTop.setFramePackingArrangementSEIQuincunx( m_framePackingSEIQuincunx );
399  m_cTEncTop.setFramePackingArrangementSEIInterpretation( m_framePackingSEIInterpretation );
400  m_cTEncTop.setDisplayOrientationSEIAngle( m_displayOrientationSEIAngle );
401  m_cTEncTop.setTemporalLevel0IndexSEIEnabled( m_temporalLevel0IndexSEIEnabled );
402  m_cTEncTop.setGradualDecodingRefreshInfoEnabled( m_gradualDecodingRefreshInfoEnabled );
403  m_cTEncTop.setDecodingUnitInfoSEIEnabled( m_decodingUnitInfoSEIEnabled );
404  m_cTEncTop.setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled );
405  m_cTEncTop.setScalableNestingSEIEnabled( m_scalableNestingSEIEnabled );
[884]406#if H_MV
[872]407  m_cTEncTop.setSubBitstreamPropSEIEnabled( m_subBistreamPropSEIEnabled );
408  if( m_subBistreamPropSEIEnabled )
409  {
410    m_cTEncTop.setNumAdditionalSubStreams ( m_sbPropNumAdditionalSubStreams );
411    m_cTEncTop.setSubBitstreamMode        ( m_sbPropSubBitstreamMode );
412    m_cTEncTop.setOutputLayerSetIdxToVps  ( m_sbPropOutputLayerSetIdxToVps );
413    m_cTEncTop.setHighestSublayerId       ( m_sbPropHighestSublayerId );
414    m_cTEncTop.setAvgBitRate              ( m_sbPropAvgBitRate );
415    m_cTEncTop.setMaxBitRate              ( m_sbPropMaxBitRate );
416  }
417#endif
[608]418  m_cTEncTop.setUniformSpacingIdr          ( m_iUniformSpacingIdr );
419  m_cTEncTop.setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
420  m_cTEncTop.setNumRowsMinus1              ( m_iNumRowsMinus1 );
421  if(m_iUniformSpacingIdr==0)
422  {
423    m_cTEncTop.setColumnWidth              ( m_pColumnWidth );
424    m_cTEncTop.setRowHeight                ( m_pRowHeight );
[2]425  }
[608]426  m_cTEncTop.xCheckGSParameters();
427  Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
428  if(uiTilesCount == 1)
[2]429  {
[608]430    m_bLFCrossTileBoundaryFlag = true; 
[2]431  }
[608]432  m_cTEncTop.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
433  m_cTEncTop.setWaveFrontSynchro           ( m_iWaveFrontSynchro );
434  m_cTEncTop.setWaveFrontSubstreams        ( m_iWaveFrontSubstreams );
435  m_cTEncTop.setTMVPModeId ( m_TMVPModeId );
436  m_cTEncTop.setUseScalingListId           ( m_useScalingListId  );
437  m_cTEncTop.setScalingListFile            ( m_scalingListFile   );
438  m_cTEncTop.setSignHideFlag(m_signHideFlag);
[655]439    m_cTEncTop.setUseRateCtrl         ( m_RCEnableRateControl );
[608]440  m_cTEncTop.setTargetBitrate       ( m_RCTargetBitrate );
441  m_cTEncTop.setKeepHierBit         ( m_RCKeepHierarchicalBit );
442  m_cTEncTop.setLCULevelRC          ( m_RCLCULevelRC );
443  m_cTEncTop.setUseLCUSeparateModel ( m_RCUseLCUSeparateModel );
444  m_cTEncTop.setInitialQP           ( m_RCInitialQP );
445  m_cTEncTop.setForceIntraQP        ( m_RCForceIntraQP );
446  m_cTEncTop.setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
[872]447  m_cTEncTop.setCUTransquantBypassFlagForceValue(m_CUTransquantBypassFlagForce);
[608]448  m_cTEncTop.setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
449  m_cTEncTop.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
450  m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); 
451  m_cTEncTop.setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
452  m_cTEncTop.setAspectRatioIdc( m_aspectRatioIdc );
453  m_cTEncTop.setSarWidth( m_sarWidth );
454  m_cTEncTop.setSarHeight( m_sarHeight );
455  m_cTEncTop.setOverscanInfoPresentFlag( m_overscanInfoPresentFlag );
456  m_cTEncTop.setOverscanAppropriateFlag( m_overscanAppropriateFlag );
457  m_cTEncTop.setVideoSignalTypePresentFlag( m_videoSignalTypePresentFlag );
458  m_cTEncTop.setVideoFormat( m_videoFormat );
459  m_cTEncTop.setVideoFullRangeFlag( m_videoFullRangeFlag );
460  m_cTEncTop.setColourDescriptionPresentFlag( m_colourDescriptionPresentFlag );
461  m_cTEncTop.setColourPrimaries( m_colourPrimaries );
462  m_cTEncTop.setTransferCharacteristics( m_transferCharacteristics );
463  m_cTEncTop.setMatrixCoefficients( m_matrixCoefficients );
464  m_cTEncTop.setChromaLocInfoPresentFlag( m_chromaLocInfoPresentFlag );
465  m_cTEncTop.setChromaSampleLocTypeTopField( m_chromaSampleLocTypeTopField );
466  m_cTEncTop.setChromaSampleLocTypeBottomField( m_chromaSampleLocTypeBottomField );
467  m_cTEncTop.setNeutralChromaIndicationFlag( m_neutralChromaIndicationFlag );
468  m_cTEncTop.setDefaultDisplayWindow( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset );
469  m_cTEncTop.setFrameFieldInfoPresentFlag( m_frameFieldInfoPresentFlag );
470  m_cTEncTop.setPocProportionalToTimingFlag( m_pocProportionalToTimingFlag );
471  m_cTEncTop.setNumTicksPocDiffOneMinus1   ( m_numTicksPocDiffOneMinus1    );
472  m_cTEncTop.setBitstreamRestrictionFlag( m_bitstreamRestrictionFlag );
473  m_cTEncTop.setTilesFixedStructureFlag( m_tilesFixedStructureFlag );
474  m_cTEncTop.setMotionVectorsOverPicBoundariesFlag( m_motionVectorsOverPicBoundariesFlag );
475  m_cTEncTop.setMinSpatialSegmentationIdc( m_minSpatialSegmentationIdc );
476  m_cTEncTop.setMaxBytesPerPicDenom( m_maxBytesPerPicDenom );
477  m_cTEncTop.setMaxBitsPerMinCuDenom( m_maxBitsPerMinCuDenom );
478  m_cTEncTop.setLog2MaxMvLengthHorizontal( m_log2MaxMvLengthHorizontal );
479  m_cTEncTop.setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
480#if H_MV
481  }
482#endif
[2]483}
484
485Void TAppEncTop::xCreateLib()
486{
[608]487#if H_MV
488  // initialize global variables
489  initROM();
490
491  for( Int layer=0; layer < m_numberOfLayers; layer++)
[2]492  {
[608]493    m_acTVideoIOYuvInputFileList[layer]->open( m_pchInputFileList[layer],     false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
494    m_acTVideoIOYuvInputFileList[layer]->skipFrames( m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
[2]495
[608]496    if (m_pchReconFileList[layer])
[2]497    {
[608]498      m_acTVideoIOYuvReconFileList[layer]->open( m_pchReconFileList[layer], true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC);  // write mode
499    }
500    m_acTEncTopList[layer]->create();
501  }
502#else
503  // Video I/O
504  m_cTVideoIOYuvInputFile.open( m_pchInputFile,     false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
505  m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
[2]506
[608]507  if (m_pchReconFile)
508    m_cTVideoIOYuvReconFile.open(m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC);  // write mode
509 
510  // Neo Decoder
511  m_cTEncTop.create();
[5]512#endif
[2]513}
514
515Void TAppEncTop::xDestroyLib()
516{
[608]517#if H_MV
518  // destroy ROM
519  destroyROM();
520
521  for(Int layer=0; layer<m_numberOfLayers; layer++)
[2]522  {
[608]523    m_acTVideoIOYuvInputFileList[layer]->close();
524    m_acTVideoIOYuvReconFileList[layer]->close();
525    delete m_acTVideoIOYuvInputFileList[layer] ; 
526    m_acTVideoIOYuvInputFileList[layer] = NULL;
527    delete m_acTVideoIOYuvReconFileList[layer] ; 
528    m_acTVideoIOYuvReconFileList[layer] = NULL;
529    m_acTEncTopList[layer]->deletePicBuffer();
530    m_acTEncTopList[layer]->destroy();
531    delete m_acTEncTopList[layer] ; 
532    m_acTEncTopList[layer] = NULL;
533    delete m_picYuvRec[layer] ; 
534    m_picYuvRec[layer] = NULL;
[2]535  }
[608]536#else
537  // Video I/O
538  m_cTVideoIOYuvInputFile.close();
539  m_cTVideoIOYuvReconFile.close();
540 
541  // Neo Decoder
542  m_cTEncTop.destroy();
543#endif
[2]544}
545
[655]546Void TAppEncTop::xInitLib(Bool isFieldCoding)
[2]547{
[758]548
[608]549#if H_MV
550  for(Int layer=0; layer<m_numberOfLayers; layer++)
[2]551  {
[655]552    m_acTEncTopList[layer]->init( isFieldCoding );
[2]553  }
[608]554#else
[655]555  m_cTEncTop.init( isFieldCoding );
[210]556#endif
[2]557}
558
559// ====================================================================================================================
560// Public member functions
561// ====================================================================================================================
562
563/**
564 - create internal class
565 - initialize internal variable
566 - until the end of input YUV file, call encoding function in TEncTop class
567 - delete allocated buffers
568 - destroy internal class
569 .
570 */
571Void TAppEncTop::encode()
572{
[56]573  fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out);
574  if (!bitstreamFile)
575  {
576    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile);
577    exit(EXIT_FAILURE);
578  }
579
580  TComPicYuv*       pcPicYuvOrg = new TComPicYuv;
581  TComPicYuv*       pcPicYuvRec = NULL;
[608]582 
[2]583  // initialize internal class & member variables
584  xInitLibCfg();
585  xCreateLib();
[655]586  xInitLib(m_isField);
[56]587 
[2]588  // main encoder loop
[608]589#if H_MV
[56]590  Bool  allEos = false;
591  std::vector<Bool>  eos ;
[608]592  std::vector<Bool>  flush ; 
593 
594  Int gopSize    = 1;
[56]595  Int maxGopSize = 0;
[608]596  maxGopSize = (std::max)(maxGopSize, m_acTEncTopList[0]->getGOPSize()); 
[56]597 
[608]598  for(Int layer=0; layer < m_numberOfLayers; layer++ )
[2]599  {
[608]600    eos  .push_back( false );
601    flush.push_back( false );
602  }
603#else
604  Int   iNumEncoded = 0;
605  Bool  bEos = false;
[189]606#endif
[608]607 
608  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
[56]609
[2]610  // allocate original YUV buffer
[655]611  if( m_isField )
612  {
613    pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeightOrg, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
614  }
615  else
616  {
[2]617  pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
[655]618  }
[608]619 
620#if H_MV
[1066]621#if H_MV_HLS10_GEN_FIX
622  while ( (m_targetEncLayerIdList.size() != 0 ) && !allEos )
623#else
[56]624  while ( !allEos )
[1066]625#endif
[2]626  {
[608]627    for(Int layer=0; layer < m_numberOfLayers; layer++ )
[2]628    {
[1066]629#if H_MV_HLS10_GEN_FIX
630      if (!xLayerIdInTargetEncLayerIdList( m_vps->getLayerIdInNuh( layer ) ))
631      {
632        continue; 
633      }
634#endif
635
[56]636      Int frmCnt = 0;
[608]637      while ( !eos[layer] && !(frmCnt == gopSize))
[2]638      {
639        // get buffers
[608]640        xGetBuffer(pcPicYuvRec, layer);
[56]641
[2]642        // read input YUV file
[608]643        m_acTVideoIOYuvInputFileList[layer]->read      ( pcPicYuvOrg, m_aiPad );
644        m_acTEncTopList             [layer]->initNewPic( pcPicYuvOrg );
[2]645
[56]646        // increase number of received frames
[608]647        m_frameRcvd[layer]++;
648       
[56]649        frmCnt++;
650
[608]651        eos[layer] = (m_frameRcvd[layer] == m_framesToBeEncoded);
652        allEos = allEos||eos[layer];
[2]653
[608]654        // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
655        if (m_acTVideoIOYuvInputFileList[layer]->isEof())
656        {
657          flush          [layer] = true;
658          eos            [layer] = true;
659          m_frameRcvd    [layer]--;
660          m_acTEncTopList[layer]->setFramesToBeEncoded(m_frameRcvd[layer]);
[42]661        }
662      }
663    }
[56]664    for ( Int gopId=0; gopId < gopSize; gopId++ )
[42]665    {
[608]666      for(Int layer=0; layer < m_numberOfLayers; layer++ )
[210]667      {
[1066]668#if H_MV_HLS10_GEN_FIX
669        if (!xLayerIdInTargetEncLayerIdList( m_vps->getLayerIdInNuh( layer ) ))
670        {
671          continue; 
672        }
673#endif
674
[833]675
[608]676        Int   iNumEncoded = 0;
[210]677
[608]678        // call encoding function for one frame         
679        m_acTEncTopList[layer]->encode( eos[layer], flush[layer] ? 0 : pcPicYuvOrg, *m_picYuvRec[layer], outputAccessUnits, iNumEncoded, gopId );       
680        xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits, layer);
681        outputAccessUnits.clear();
682      }
683    }
[655]684
[608]685    gopSize = maxGopSize;
686  }
687  for(Int layer=0; layer < m_numberOfLayers; layer++ )
688  {
[1066]689#if H_MV_HLS10_GEN_FIX
690    if (!xLayerIdInTargetEncLayerIdList( m_vps->getLayerIdInNuh( layer ) ))
691    {
692      continue; 
693    }
694#endif
[655]695    m_acTEncTopList[layer]->printSummary( m_acTEncTopList[layer]->getNumAllPicCoded(), m_isField );
[608]696  }
697#else
698  while ( !bEos )
699  {
700    // get buffers
701    xGetBuffer(pcPicYuvRec);
[210]702
[608]703    // read input YUV file
704    m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, m_aiPad );
[313]705
[608]706    // increase number of received frames
707    m_iFrameRcvd++;
[210]708
[655]709    bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) );
[296]710
[608]711    Bool flush = 0;
712    // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
713    if (m_cTVideoIOYuvInputFile.isEof())
714    {
715      flush = true;
716      bEos = true;
717      m_iFrameRcvd--;
718      m_cTEncTop.setFramesToBeEncoded(m_iFrameRcvd);
719    }
[443]720
[608]721    // call encoding function for one frame
[655]722    if ( m_isField )
723    {
724      m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded, m_isTopFieldFirst);
725    }
726    else
727    {
[608]728    m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded );
[655]729    }
[608]730   
731    // write bistream to file if necessary
732    if ( iNumEncoded > 0 )
733    {
734      xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits);
735      outputAccessUnits.clear();
736    }
737  }
[313]738
[655]739  m_cTEncTop.printSummary(m_isField);
[443]740#endif
[296]741
[56]742  // delete original YUV buffer
743  pcPicYuvOrg->destroy();
744  delete pcPicYuvOrg;
745  pcPicYuvOrg = NULL;
746 
[608]747#if !H_MV
748  // delete used buffers in encoder class
749  m_cTEncTop.deletePicBuffer();
[210]750#endif
[2]751
[56]752  // delete buffers & classes
753  xDeleteBuffer();
754  xDestroyLib();
[608]755 
756  printRateSummary();
[2]757
[608]758
[56]759  return;
760}
[2]761
762// ====================================================================================================================
763// Protected member functions
764// ====================================================================================================================
765
766/**
767 - application has picture buffer list with size of GOP
768 - picture buffer list acts as ring buffer
769 - end of the list has the latest picture
770 .
771 */
[608]772#if H_MV
773Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer)
774#else
775Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec)
776#endif
[2]777{
[56]778  assert( m_iGOPSize > 0 );
779 
[608]780  // org. buffer
781#if H_MV
782  if ( m_picYuvRec[layer]->size() == (UInt)m_iGOPSize )
[56]783  {
[608]784    rpcPicYuvRec = m_picYuvRec[layer]->popFront();
785#else
786  if ( m_cListPicYuvRec.size() == (UInt)m_iGOPSize )
787  {
788    rpcPicYuvRec = m_cListPicYuvRec.popFront();
789#endif
790
[56]791  }
792  else
793  {
[608]794    rpcPicYuvRec = new TComPicYuv;
795   
796    rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
797
[56]798  }
[608]799#if H_MV
800  m_picYuvRec[layer]->pushBack( rpcPicYuvRec );
801#else
802  m_cListPicYuvRec.pushBack( rpcPicYuvRec );
803#endif
[2]804}
805
806Void TAppEncTop::xDeleteBuffer( )
807{
[608]808#if H_MV
809  for(Int layer=0; layer<m_picYuvRec.size(); layer++)
[2]810  {
[608]811    if(m_picYuvRec[layer])
[2]812    {
[608]813      TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_picYuvRec[layer]->begin();
814      Int iSize = Int( m_picYuvRec[layer]->size() );
815#else
816  TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvRec.begin();
817 
818  Int iSize = Int( m_cListPicYuvRec.size() );
819#endif
820
821  for ( Int i = 0; i < iSize; i++ )
822  {
823    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
824    pcPicYuvRec->destroy();
825    delete pcPicYuvRec; pcPicYuvRec = NULL;
[2]826  }
[608]827
828#if H_MV
[2]829    }
830  }
[608]831#endif 
[2]832}
833
834/** \param iNumEncoded  number of encoded frames
835 */
[608]836#if H_MV
837Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, std::list<AccessUnit>& accessUnits, UInt layerId)
838#else
839Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
840#endif
[2]841{
[655]842  if (m_isField)
843  {
844    //Reinterlace fields
845    Int i;
[608]846#if H_MV
[655]847    if( iNumEncoded > 0 )
848    {
849      TComList<TComPicYuv*>::iterator iterPicYuvRec = m_picYuvRec[layerId]->end();
[608]850#else
[655]851    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
852    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
[608]853#endif
854
[655]855    for ( i = 0; i < iNumEncoded; i++ )
856    {
857      --iterPicYuvRec;
858    }
859
860    for ( i = 0; i < iNumEncoded/2; i++ )
861    {
862      TComPicYuv*  pcPicYuvRecTop  = *(iterPicYuvRec++);
863      TComPicYuv*  pcPicYuvRecBottom  = *(iterPicYuvRec++);
864
865#if H_MV
866      if (m_pchReconFileList[layerId])
867      {
868        m_acTVideoIOYuvReconFileList[layerId]->write( pcPicYuvRecTop, pcPicYuvRecBottom, m_confLeft, m_confRight, m_confTop, m_confBottom, m_isTopFieldFirst );
869      }
870    }
871  }
872
873  if( ! accessUnits.empty() )
[608]874  {
[655]875    list<AccessUnit>::iterator aUIter;
876    for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ )
877    {
878      const vector<UInt>& stats = writeAnnexB(bitstreamFile, *aUIter);
879      rateStatsAccum(*aUIter, stats);
880    }
[608]881  }
[655]882#else
883      if (m_pchReconFile)
884      {
885        m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, m_confLeft, m_confRight, m_confTop, m_confBottom, m_isTopFieldFirst );
886      }
887
888      const AccessUnit& auTop = *(iterBitstream++);
889      const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
890      rateStatsAccum(auTop, statsTop);
891
892      const AccessUnit& auBottom = *(iterBitstream++);
893      const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom);
894      rateStatsAccum(auBottom, statsBottom);
895    }
896#endif
897  }
898  else
[608]899  {
[655]900    Int i;
[608]901#if H_MV
[655]902    if( iNumEncoded > 0 )
903    {
904      TComList<TComPicYuv*>::iterator iterPicYuvRec = m_picYuvRec[layerId]->end();
905#else
906    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
907    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
908#endif
909
910    for ( i = 0; i < iNumEncoded; i++ )
911    {
912      --iterPicYuvRec;
913    }
914
915    for ( i = 0; i < iNumEncoded; i++ )
916    {
917      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
918#if H_MV
[608]919      if (m_pchReconFileList[layerId])
[56]920      {
[608]921        m_acTVideoIOYuvReconFileList[layerId]->write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
[655]922      }   
[56]923    }
[2]924  }
[56]925  if( ! accessUnits.empty() )
[2]926  {
[56]927    list<AccessUnit>::iterator aUIter;
928    for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ )
[2]929    {
[56]930      const vector<unsigned>& stats = writeAnnexB(bitstreamFile, *aUIter);
931      rateStatsAccum(*aUIter, stats);
[2]932    }
933  }
[608]934#else
[655]935      if (m_pchReconFile)
936      {
937        m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
938      }
939
940      const AccessUnit& au = *(iterBitstream++);
941      const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
942      rateStatsAccum(au, stats);   
[2]943    }
[872]944#endif
[608]945  }
946}
[655]947 
[56]948/**
949 *
950 */
[608]951void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& annexBsizes)
[2]952{
[56]953  AccessUnit::const_iterator it_au = au.begin();
[608]954  vector<UInt>::const_iterator it_stats = annexBsizes.begin();
[2]955
[56]956  for (; it_au != au.end(); it_au++, it_stats++)
[2]957  {
[56]958    switch ((*it_au)->m_nalUnitType)
[2]959    {
[608]960    case NAL_UNIT_CODED_SLICE_TRAIL_R:
961    case NAL_UNIT_CODED_SLICE_TRAIL_N:
[872]962    case NAL_UNIT_CODED_SLICE_TSA_R:
[608]963    case NAL_UNIT_CODED_SLICE_TSA_N:
964    case NAL_UNIT_CODED_SLICE_STSA_R:
965    case NAL_UNIT_CODED_SLICE_STSA_N:
966    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
967    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
968    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
969    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
970    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
[56]971    case NAL_UNIT_CODED_SLICE_CRA:
[608]972    case NAL_UNIT_CODED_SLICE_RADL_N:
973    case NAL_UNIT_CODED_SLICE_RADL_R:
974    case NAL_UNIT_CODED_SLICE_RASL_N:
975    case NAL_UNIT_CODED_SLICE_RASL_R:
976    case NAL_UNIT_VPS:
[56]977    case NAL_UNIT_SPS:
978    case NAL_UNIT_PPS:
979      m_essentialBytes += *it_stats;
980      break;
981    default:
982      break;
[2]983    }
984
[56]985    m_totalBytes += *it_stats;
[2]986  }
987}
988
[608]989void TAppEncTop::printRateSummary()
[2]990{
[608]991#if H_MV
992  Double time = (Double) m_frameRcvd[0] / m_iFrameRate;
993  printf("\n");
994#else
995  Double time = (Double) m_iFrameRcvd / m_iFrameRate;
[5]996#endif
[56]997  printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time);
998#if VERBOSE_RATE
999  printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time);
1000#endif
1001}
1002
1003
[608]1004#if H_MV
1005Void TAppEncTop::xSetDimensionIdAndLength( TComVPS& vps )
1006{   
[622]1007  vps.setScalabilityMaskFlag( m_scalabilityMask ); 
[608]1008  for( Int dim = 0; dim < m_dimIds.size(); dim++ )
1009  {
1010    vps.setDimensionIdLen( dim, m_dimensionIdLen[ dim ] );
[622]1011    for( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ )
1012
[608]1013    {       
1014      vps.setDimensionId( layer, dim, m_dimIds[ dim ][ layer ] );       
1015    } 
1016  }
[622]1017
1018  Int maxViewId = xGetMax( m_viewId ); 
1019
[738]1020  Int viewIdLen = gCeilLog2( maxViewId + 1 ); 
1021  const Int maxViewIdLen = ( 1 << 4 ) - 1; 
1022  assert( viewIdLen <= maxViewIdLen ); 
1023  vps.setViewIdLen( viewIdLen ); 
[622]1024  for (Int i = 0; i < m_iNumberOfViews; i++)
1025  {
1026    vps.setViewIdVal( i, m_viewId[ i] ); 
1027  }
1028
1029  assert( m_iNumberOfViews == vps.getNumViews() ); 
[608]1030}
[443]1031
[608]1032Void TAppEncTop::xSetDependencies( TComVPS& vps )
[296]1033{
[608]1034  // Direct dependency flags + dependency types
1035  for( Int depLayer = 1; depLayer < MAX_NUM_LAYERS; depLayer++ )
1036  {
1037    for( Int refLayer = 0; refLayer < MAX_NUM_LAYERS; refLayer++ )
1038    {
1039      vps.setDirectDependencyFlag( depLayer, refLayer, false); 
1040      vps.setDirectDependencyType( depLayer, refLayer,    -1 ); 
1041    }
1042    }
[738]1043
1044  Int  defaultDirectDependencyType = -1; 
[964]1045  Bool defaultDirectDependencyFlag = false; 
1046
[608]1047  for( Int depLayer = 1; depLayer < m_numberOfLayers; depLayer++ )
1048  {
1049    Int numRefLayers = (Int) m_directRefLayers[depLayer].size(); 
1050    assert(  numRefLayers == (Int) m_dependencyTypes[depLayer].size() ); 
1051    for( Int i = 0; i < numRefLayers; i++ )
1052    {
1053      Int refLayer = m_directRefLayers[depLayer][i]; 
1054      vps.setDirectDependencyFlag( depLayer, refLayer, true); 
[738]1055      Int curDirectDependencyType = m_dependencyTypes[depLayer][i]; 
1056
1057      if ( defaultDirectDependencyType != -1 )   
1058      {
1059        defaultDirectDependencyFlag = defaultDirectDependencyFlag && (curDirectDependencyType == defaultDirectDependencyType );         
1060      }
1061      else
1062      {
1063        defaultDirectDependencyType = curDirectDependencyType; 
[964]1064        defaultDirectDependencyFlag = true; 
[738]1065      }
1066     
1067      vps.setDirectDependencyType( depLayer, refLayer, curDirectDependencyType);       
[608]1068    }
1069  }
[296]1070
[738]1071  vps.setDefaultDirectDependencyFlag( defaultDirectDependencyFlag );       
1072  vps.setDefaultDirectDependencyType( defaultDirectDependencyFlag ? defaultDirectDependencyType : -1 );       
1073
1074  // Max sub layers, + presence flag
1075  Bool subLayersMaxMinus1PresentFlag = false; 
[1066]1076#if !H_MV_FIX_SUB_LAYERS_MAX_MINUS1
[738]1077  Int  subLayersMaxMinus1 = -1; 
[1066]1078#endif
[738]1079  for (Int curLayerIdInVps = 0; curLayerIdInVps < m_numberOfLayers; curLayerIdInVps++ )
[1066]1080  {   
1081    Int curSubLayersMaxMinus1 = 0; 
[738]1082    for( Int i = 0; i < getGOPSize(); i++ ) 
1083    {
1084      GOPEntry geCur =  m_GOPListMvc[curLayerIdInVps][i];
1085      curSubLayersMaxMinus1 = std::max( curSubLayersMaxMinus1, geCur.m_temporalId ); 
1086    } 
1087
1088    vps.setSubLayersVpsMaxMinus1( curLayerIdInVps, curSubLayersMaxMinus1 ); 
[1066]1089#if !H_MV_FIX_SUB_LAYERS_MAX_MINUS1
[738]1090    if ( subLayersMaxMinus1 == -1 )
1091    {
1092      subLayersMaxMinus1 = curSubLayersMaxMinus1; 
1093    }
1094    else
1095    {
1096      subLayersMaxMinus1PresentFlag = subLayersMaxMinus1PresentFlag || ( curSubLayersMaxMinus1 != subLayersMaxMinus1 ); 
1097    }
[1066]1098#else
1099    subLayersMaxMinus1PresentFlag = subLayersMaxMinus1PresentFlag || ( curSubLayersMaxMinus1 != vps.getMaxSubLayersMinus1() );
1100#endif
[738]1101  }
1102
1103  vps.setVpsSubLayersMaxMinus1PresentFlag( subLayersMaxMinus1PresentFlag ); 
1104
1105
[622]1106  // Max temporal id for inter layer reference pictures + presence flag
1107  Bool maxTidRefPresentFlag = false; 
[608]1108  for ( Int refLayerIdInVps = 0; refLayerIdInVps < m_numberOfLayers; refLayerIdInVps++)
[1066]1109  {
1110    for ( Int curLayerIdInVps = 1; curLayerIdInVps < m_numberOfLayers; curLayerIdInVps++)
[608]1111    {
[738]1112      Int maxTid = -1; 
[1066]1113#if H_MV_FIX_LOOP_GOPSIZE
1114      for( Int i = 0; i < ( getGOPSize() + 1); i++ ) 
1115      {       
1116        GOPEntry geCur =  m_GOPListMvc[curLayerIdInVps][( i < getGOPSize()  ? i : MAX_GOP )];
1117        GOPEntry geRef =  m_GOPListMvc[refLayerIdInVps][( i < getGOPSize()  ? i : MAX_GOP )];
1118#else
[608]1119      for( Int i = 0; i < getGOPSize(); i++ ) 
1120      {       
1121        GOPEntry geCur =  m_GOPListMvc[curLayerIdInVps][i];
[1066]1122        GOPEntry geRef =  m_GOPListMvc[refLayerIdInVps][i];     
1123#endif
[608]1124        for (Int j = 0; j < geCur.m_numActiveRefLayerPics; j++)
1125        {       
1126          if ( m_directRefLayers[ curLayerIdInVps ][ geCur.m_interLayerPredLayerIdc[ j ]] == refLayerIdInVps )
1127          {
[1066]1128#if H_MV_FIX_LOOP_GOPSIZE
1129            Bool refAlwaysIntra = ( i == getGOPSize() ) && ( m_iIntraPeriod[ curLayerIdInVps ] % m_iIntraPeriod[ refLayerIdInVps ] == 0 );
1130            Bool refLayerZero   = ( i == getGOPSize() ) && ( refLayerIdInVps == 0 );
1131            maxTid = std::max( maxTid, ( refAlwaysIntra || refLayerZero ) ? 0 : geRef.m_temporalId ); 
1132#else
[608]1133            maxTid = std::max( maxTid, geRef.m_temporalId ); 
[1066]1134#endif
[608]1135          }
1136        }
1137      }
[738]1138      vps.setMaxTidIlRefPicsPlus1( refLayerIdInVps, curLayerIdInVps, maxTid + 1 );
1139      maxTidRefPresentFlag = maxTidRefPresentFlag || ( maxTid != 6 );   
[608]1140    }
1141  }
[296]1142
[622]1143  vps.setMaxTidRefPresentFlag( maxTidRefPresentFlag );
[608]1144  // Max one active ref layer flag
1145  Bool maxOneActiveRefLayerFlag = true; 
[622]1146  for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && maxOneActiveRefLayerFlag; layerIdInVps++)
[296]1147  {
[608]1148    for( Int i = 0; i < ( getGOPSize() + 1) && maxOneActiveRefLayerFlag; i++ ) 
1149    {       
[622]1150      GOPEntry ge =  m_GOPListMvc[layerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]; 
[608]1151      maxOneActiveRefLayerFlag =  maxOneActiveRefLayerFlag && (ge.m_numActiveRefLayerPics <= 1); 
1152    }           
1153}
1154
1155  vps.setMaxOneActiveRefLayerFlag( maxOneActiveRefLayerFlag );
[622]1156 
[738]1157  // Poc Lsb Not Present Flag
1158  for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers; layerIdInVps++)
1159  {
1160    if ( m_directRefLayers[ layerIdInVps ].size() == 0 ) 
1161    {   
1162      vps.setPocLsbNotPresentFlag( layerIdInVps,  true ); 
1163    }
1164  }
[622]1165 
1166  // All Ref layers active flag
1167  Bool allRefLayersActiveFlag = true; 
1168  for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && allRefLayersActiveFlag; layerIdInVps++)
1169  {   
1170    for( Int i = 0; i < ( getGOPSize() + 1) && allRefLayersActiveFlag; i++ ) 
1171    {       
1172      GOPEntry ge =  m_GOPListMvc[layerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]; 
[738]1173      Int tId = ge.m_temporalId;  // Should be equal for all layers.
1174     
1175      // check if all reference layers when allRefLayerActiveFlag is equal to 1 are reference layer pictures specified in the gop entry
1176      for (Int k = 0; k < m_directRefLayers[ layerIdInVps].size() && allRefLayersActiveFlag; k++ )
1177      {
1178        Int refLayerIdInVps = vps.getLayerIdInVps( m_directRefLayers[ layerIdInVps ][ k ] ); 
1179        if ( vps.getMaxTidIlRefPicsPlus1(refLayerIdInVps,layerIdInVps) > tId  && vps.getSubLayersVpsMaxMinus1(refLayerIdInVps) >= tId )
1180        {
1181          Bool gopEntryFoundFlag = false; 
1182          for( Int l = 0; l < ge.m_numActiveRefLayerPics && !gopEntryFoundFlag; l++ )
1183          {
1184            gopEntryFoundFlag = gopEntryFoundFlag || ( ge.m_interLayerPredLayerIdc[l] == k ); 
1185          }         
1186          allRefLayersActiveFlag = allRefLayersActiveFlag && gopEntryFoundFlag; 
1187        }       
1188      }
1189
1190      // check if all inter layer reference pictures specified in the gop entry are valid reference layer pictures when allRefLayerActiveFlag is equal to 1
1191      // (Should actually always be true)
1192      Bool maxTidIlRefAndSubLayerMaxVaildFlag = true; 
1193      for( Int l = 0; l < ge.m_numActiveRefLayerPics; l++ )
1194      {   
1195        Bool referenceLayerFoundFlag = false; 
1196        for (Int k = 0; k < m_directRefLayers[ layerIdInVps].size(); k++ )
1197        {
1198          Int refLayerIdInVps = vps.getLayerIdInVps( m_directRefLayers[ layerIdInVps ][ k ] ); 
1199
1200          if ( vps.getMaxTidIlRefPicsPlus1(refLayerIdInVps,layerIdInVps) > tId  && vps.getSubLayersVpsMaxMinus1(refLayerIdInVps) >= tId )
1201          {         
1202            referenceLayerFoundFlag = referenceLayerFoundFlag || ( ge.m_interLayerPredLayerIdc[l] == k ); 
1203          }         
1204        }
1205       maxTidIlRefAndSubLayerMaxVaildFlag = maxTidIlRefAndSubLayerMaxVaildFlag && referenceLayerFoundFlag; 
1206      }
1207      assert ( maxTidIlRefAndSubLayerMaxVaildFlag ); // Something wrong with MaxTidIlRefPicsPlus1 or SubLayersVpsMaxMinus1
[622]1208    }           
1209  }
1210
1211  vps.setAllRefLayersActiveFlag( allRefLayersActiveFlag );
1212
[608]1213  vps.setRefLayers(); 
1214}; 
1215
[622]1216GOPEntry* TAppEncTop::xGetGopEntry( Int layerIdInVps, Int poc )
1217{
1218  GOPEntry* geFound = NULL; 
1219  for( Int i = 0; i < ( getGOPSize() + 1) && geFound == NULL ; i++ ) 
1220  {
1221    GOPEntry* ge = &(m_GOPListMvc[layerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]);
1222    if ( ge->m_POC == poc )
1223    {
1224      geFound = ge;       
1225    }
1226  }
1227  assert( geFound != NULL ); 
1228  return geFound; 
1229}
1230
[608]1231Void TAppEncTop::xSetLayerIds( TComVPS& vps )
1232{
1233  vps.setSplittingFlag     ( m_splittingFlag );
1234
1235  Bool nuhLayerIdPresentFlag = !( m_layerIdInNuh.size() == 1 ); 
1236  Int  maxNuhLayerId = nuhLayerIdPresentFlag ? xGetMax( m_layerIdInNuh ) : ( m_numberOfLayers - 1 ) ; 
1237
1238  vps.setVpsMaxLayerId( maxNuhLayerId ); 
1239  vps.setVpsNuhLayerIdPresentFlag( nuhLayerIdPresentFlag ); 
1240
1241  for (Int layer = 0; layer < m_numberOfLayers; layer++ )
1242  {
1243    vps.setLayerIdInNuh( layer, nuhLayerIdPresentFlag ? m_layerIdInNuh[ layer ] : layer ); 
1244    vps.setLayerIdInVps( vps.getLayerIdInNuh( layer ), layer ); 
[296]1245  }
[608]1246}
1247
1248Int TAppEncTop::xGetMax( std::vector<Int>& vec )
1249{
1250  Int maxVec = 0; 
1251  for ( Int i = 0; i < vec.size(); i++)   
[622]1252  {
[608]1253    maxVec = max( vec[i], maxVec ); 
[622]1254  }
[608]1255  return maxVec;
1256}
1257
1258Void TAppEncTop::xSetProfileTierLevel( TComVPS& vps )
1259{ 
[1066]1260#if H_MV_HLS10_PTL
1261
1262  // SET PTL
1263  assert( m_profile.size() == m_level.size() && m_profile.size() == m_levelTier.size() ); 
1264  vps.setVpsNumProfileTierLevelMinus1( (Int) m_profile.size() - 1 );
1265  for ( Int ptlIdx = 0; ptlIdx <= vps.getVpsNumProfileTierLevelMinus1(); ptlIdx++ )
1266  {
1267    if ( ptlIdx > 1 )
1268    {
1269      Bool vpsProfilePresentFlag = ( m_profile[ptlIdx] != m_profile[ptlIdx - 1] )
1270        || ( m_inblFlag[ptlIdx ] != m_inblFlag[ptlIdx - 1] ); 
1271      vps.setVpsProfilePresentFlag( ptlIdx, vpsProfilePresentFlag ); 
1272    }
1273
1274    xSetProfileTierLevel( vps, ptlIdx, -1, m_profile[ptlIdx], m_level[ptlIdx], 
1275      m_levelTier[ ptlIdx ], m_progressiveSourceFlag, m_interlacedSourceFlag,
1276      m_nonPackedConstraintFlag, m_frameOnlyConstraintFlag,  m_inblFlag[ptlIdx] );     
1277  } 
1278#else
[608]1279  const Int vpsNumProfileTierLevelMinus1 = 0; //TBD
1280  vps.setVpsNumProfileTierLevelMinus1( vpsNumProfileTierLevelMinus1 ); 
1281 
1282  for (Int i = 0; i <= vps.getVpsNumProfileTierLevelMinus1(); i++ )
[296]1283  {
[608]1284    vps.setVpsProfilePresentFlag( i, true ); 
[296]1285  }
[1066]1286#endif
[608]1287}
[296]1288
[1066]1289#if H_MV_HLS10_PTL
1290Void TAppEncTop::xSetProfileTierLevel(TComVPS& vps, Int profileTierLevelIdx, Int subLayer, Profile::Name profile, Level::Name level, Level::Tier tier, Bool progressiveSourceFlag, Bool interlacedSourceFlag, Bool nonPackedConstraintFlag, Bool frameOnlyConstraintFlag, Bool inbldFlag)
1291{
1292  TComPTL* ptlStruct = vps.getPTL( profileTierLevelIdx );   
1293  assert( ptlStruct != NULL ); 
[608]1294
[1066]1295  ProfileTierLevel* ptl; 
1296  if ( subLayer == -1 )
1297  {
1298    ptl = ptlStruct->getGeneralPTL();
1299  }
1300  else
1301  {
1302    ptl = ptlStruct->getSubLayerPTL(  subLayer );
1303  }
1304
1305  assert( ptl != NULL );
1306
1307  ptl->setProfileIdc( profile );
1308  ptl->setTierFlag  ( tier    );
1309  ptl->setLevelIdc  ( level   );
1310  ptl->setProfileCompatibilityFlag( profile, true );
1311#if H_MV_HLS10_PTL_INBL_FIX
1312  ptl->setInbldFlag( inbldFlag );
1313#endif
1314
1315  switch ( profile )
1316  {
1317  case Profile::MAIN:
1318    break; 
1319  case Profile::MULTIVIEWMAIN:
1320    ptl->setMax12bitConstraintFlag      ( true  ); 
1321    ptl->setMax12bitConstraintFlag      ( true  );
1322    ptl->setMax10bitConstraintFlag      ( true  );
1323    ptl->setMax8bitConstraintFlag       ( true  );
1324    ptl->setMax422chromaConstraintFlag  ( true  );
1325    ptl->setMax420chromaConstraintFlag  ( true  );
1326    ptl->setMaxMonochromeConstraintFlag ( false );
1327    ptl->setIntraConstraintFlag         ( false ); 
1328    ptl->setOnePictureOnlyConstraintFlag( false );
1329    ptl->setLowerBitRateConstraintFlag  ( true  );       
1330    break; 
1331  default:
1332    assert( 0 ); // other profiles currently not supported
1333    break; 
1334  }
1335}
1336#endif
1337
[622]1338Void TAppEncTop::xSetRepFormat( TComVPS& vps )
1339{
[964]1340  vps.setRepFormatIdxPresentFlag( false ); 
[622]1341  vps.setVpsNumRepFormatsMinus1 ( 0    ); 
1342
1343  TComRepFormat* repFormat = new TComRepFormat; 
1344
1345  repFormat->setBitDepthVpsChromaMinus8   ( g_bitDepthC - 8 ); 
1346  repFormat->setBitDepthVpsLumaMinus8     ( g_bitDepthY - 8 );
1347  repFormat->setChromaFormatVpsIdc        ( CHROMA_420      );
1348  repFormat->setPicHeightVpsInLumaSamples ( m_iSourceHeight );
1349  repFormat->setPicWidthVpsInLumaSamples  ( m_iSourceWidth  );   
[738]1350  repFormat->setChromaAndBitDepthVpsPresentFlag( true );   
[622]1351  // ToDo not supported yet.
1352  //repFormat->setSeparateColourPlaneVpsFlag( );
1353
[1066]1354#if H_MV_HLS10_GEN_VSP_CONF_WIN
1355  repFormat->setConformanceWindowVpsFlag( true );
1356  repFormat->setConfWinVpsLeftOffset    ( m_confLeft   / TComSPS::getWinUnitX( repFormat->getChromaFormatVpsIdc() ) );
1357  repFormat->setConfWinVpsRightOffset   ( m_confRight  / TComSPS::getWinUnitX( repFormat->getChromaFormatVpsIdc() )  );
1358  repFormat->setConfWinVpsTopOffset     ( m_confTop    / TComSPS::getWinUnitY( repFormat->getChromaFormatVpsIdc() )  );
1359  repFormat->setConfWinVpsBottomOffset  ( m_confBottom / TComSPS::getWinUnitY( repFormat->getChromaFormatVpsIdc() ) ); 
1360#endif
1361
[622]1362  assert( vps.getRepFormat( 0 ) == NULL ); 
1363  vps.setRepFormat( 0 , repFormat );
1364}
1365
[738]1366Void TAppEncTop::xSetDpbSize                ( TComVPS& vps )
1367{
1368  // These settings need to be verified
1369
1370  TComDpbSize* dpbSize = vps.getDpbSize(); 
1371
1372  assert ( dpbSize != 0 ); 
1373
[964]1374  for( Int i = 0; i < vps.getNumOutputLayerSets(); i++ )
[738]1375  { 
[964]1376    Int currLsIdx = vps.olsIdxToLsIdx( i ); 
[1066]1377#if !H_MV_HLS10_ADD_LAYERSETS
[738]1378    std::vector<Int> targetDecLayerIdList = vps.getTargetDecLayerIdList( i ); 
[1066]1379#endif
[872]1380    Bool subLayerFlagInfoPresentFlag = false; 
1381
[964]1382    for( Int j = 0; j  <=  vps.getMaxSubLayersInLayerSetMinus1( currLsIdx ); j++ )
[872]1383    {   
1384      Bool subLayerDpbInfoPresentFlag = false; 
[1066]1385#if !H_MV_HLS10_ADD_LAYERSETS
[964]1386      assert( vps.getNumLayersInIdList( currLsIdx ) == targetDecLayerIdList.size() ); 
[1066]1387#endif
[964]1388      for( Int k = 0; k < vps.getNumLayersInIdList( currLsIdx ); k++ )   
[872]1389      {
[1066]1390#if H_MV_HLS10_DBP_SIZE
1391        Int layerIdInVps = vps.getLayerIdInVps( vps.getLayerSetLayerIdList( currLsIdx, k ) );
1392        if ( vps.getNecessaryLayerFlag( i,k ) && ( vps.getVpsBaseLayerInternalFlag() || vps.getLayerSetLayerIdList( currLsIdx, k ) != 0 ) )
1393        {       
1394          dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, m_maxDecPicBufferingMvc[ layerIdInVps ][ j ] - 1 );
1395          if ( j > 0 )
1396          {
1397            subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j ) != dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j - 1 ) );
1398          }
1399        }
1400        else
1401        {
1402          if (vps.getNecessaryLayerFlag(i,k) && j == 0 && k == 0 )
1403          {         
1404            dpbSize->setMaxVpsDecPicBufferingMinus1(i, k ,j, 0 ); 
1405          }
1406        }
1407#else
[872]1408        Int layerIdInVps = vps.getLayerIdInVps( targetDecLayerIdList[k] );           
1409        dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, m_maxDecPicBufferingMvc[ layerIdInVps ][ j ] - 1 );
[1066]1410
[872]1411        if ( j > 0 )
1412        {
1413          subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j ) != dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j - 1 ) );
1414        }
[1066]1415#endif
[872]1416      }       
1417
1418      Int maxNumReorderPics = MIN_INT;
[1066]1419#if H_MV_HLS10_DBP_SIZE
1420      for ( Int idx = 0; idx < vps.getNumLayersInIdList( currLsIdx ); idx++ )
1421      {
1422        if (vps.getNecessaryLayerFlag(i, idx ))
1423        {       
1424          Int layerIdInVps = vps.getLayerIdInVps( vps.getLayerSetLayerIdList(currLsIdx, idx) );       
1425          maxNumReorderPics = std::max( maxNumReorderPics, m_numReorderPicsMvc[ layerIdInVps ][ j ] ); 
1426        }
1427      }
1428#else
[872]1429      for ( Int idx = 0; idx < targetDecLayerIdList.size(); idx++ )
1430      {
1431        Int layerIdInVps = vps.getLayerIdInVps( targetDecLayerIdList[ idx ] ); 
1432        maxNumReorderPics = std::max( maxNumReorderPics, m_numReorderPicsMvc[ layerIdInVps ][ j ] ); 
1433      }
[1066]1434#endif
[872]1435      assert( maxNumReorderPics != MIN_INT ); 
1436
1437      dpbSize->setMaxVpsNumReorderPics( i, j, maxNumReorderPics );
1438      if ( j > 0 )
1439      {
1440        subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize->getMaxVpsNumReorderPics( i, j ) != dpbSize->getMaxVpsNumReorderPics( i, j - 1 ) );
1441      }
1442
1443      // To Be Done !
1444      // dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, xx );
1445      if ( j > 0 )
1446      {
1447        subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize->getMaxVpsLatencyIncreasePlus1( i, j ) != dpbSize->getMaxVpsLatencyIncreasePlus1( i, j - 1  ) );
1448      }
1449
1450      if( j > 0 ) 
1451      {
1452        dpbSize->setSubLayerDpbInfoPresentFlag( i, j, subLayerDpbInfoPresentFlag );
1453        subLayerFlagInfoPresentFlag = subLayerFlagInfoPresentFlag || subLayerDpbInfoPresentFlag; 
1454      }       
1455    } 
1456    dpbSize->setSubLayerFlagInfoPresentFlag( i, subLayerFlagInfoPresentFlag ); 
1457  } 
1458}
1459
[608]1460Void TAppEncTop::xSetLayerSets( TComVPS& vps )
1461{   
1462  // Layer sets
1463  vps.setVpsNumLayerSetsMinus1   ( m_vpsNumLayerSets - 1 ); 
1464   
1465  for (Int lsIdx = 0; lsIdx < m_vpsNumLayerSets; lsIdx++ )
1466  {
1467    for( Int layerId = 0; layerId < MAX_NUM_LAYER_IDS; layerId++ )
1468    {
1469      vps.setLayerIdIncludedFlag( false, lsIdx, layerId ); 
1470    }
1471    for ( Int i = 0; i < m_layerIdsInSets[lsIdx].size(); i++)
1472    {       
1473      vps.setLayerIdIncludedFlag( true, lsIdx, vps.getLayerIdInNuh( m_layerIdsInSets[lsIdx][i] ) ); 
1474    } 
1475  }
[738]1476  vps.deriveLayerSetLayerIdList(); 
[608]1477
1478  Int numAddOuputLayerSets = (Int) m_outputLayerSetIdx.size(); 
1479  // Additional output layer sets + profileLevelTierIdx
[964]1480  vps.setDefaultOutputLayerIdc      ( m_defaultOutputLayerIdc );   
[1066]1481#if H_MV_HLS10_ADD_LAYERSETS
1482  if( vps.getNumIndependentLayers() == 0 && m_numAddLayerSets > 0  )
1483  {
1484    fprintf( stderr, "\nWarning: Ignoring additional layer sets since NumIndependentLayers is equal to 0.\n");           
1485  }
1486  else
1487  {
1488    vps.setNumAddLayerSets( m_numAddLayerSets ); 
1489    if ( m_highestLayerIdxPlus1.size() < vps.getNumAddLayerSets() ) 
1490    {
1491      fprintf(stderr, "\nError: Number of highestLayerIdxPlus1 parameters must be greater than or equal to NumAddLayerSets\n");
1492      exit(EXIT_FAILURE);
1493    }
1494
1495    for (Int i = 0; i < vps.getNumAddLayerSets(); i++)
1496    {
1497      if ( m_highestLayerIdxPlus1[ i ].size() < vps.getNumIndependentLayers() ) 
1498      {
1499        fprintf(stderr, "Error: Number of elements in highestLayerIdxPlus1[ %d ] parameters must be greater than or equal to NumIndependentLayers(= %d)\n", i, vps.getNumIndependentLayers());
1500        exit(EXIT_FAILURE);
1501      }
1502
1503      for (Int j = 1; j < vps.getNumIndependentLayers(); j++)
1504      {
1505        if ( m_highestLayerIdxPlus1[ i ][ j ]  < 0 || m_highestLayerIdxPlus1[ i ][ j ] > vps.getNumLayersInTreePartition( j ) ) 
1506        {
1507          fprintf(stderr, "Error: highestLayerIdxPlus1[ %d ][ %d ] shall be in the range of 0 to NumLayersInTreePartition[ %d ] (= %d ), inclusive. \n", i, j, j, vps.getNumLayersInTreePartition( j ) );
1508          exit(EXIT_FAILURE);
1509        }
1510        vps.setHighestLayerIdxPlus1( i, j, m_highestLayerIdxPlus1[ i ][ j ] ); 
1511      }
1512      vps.deriveAddLayerSetLayerIdList( i );
1513    }       
1514  } 
1515#else
[964]1516  vps.setNumAddLayerSets            ( 0                             ); 
[1066]1517#endif
[964]1518  vps.setNumAddOlss                 ( numAddOuputLayerSets          ); 
[872]1519  vps.initTargetLayerIdLists(); 
[608]1520
[1066]1521#if H_MV_HLS10_ADD_LAYERSETS
1522  for (Int olsIdx = 0; olsIdx < vps.getNumLayerSets() + numAddOuputLayerSets; olsIdx++)
1523  {
1524    Int addOutLsIdx = olsIdx - vps.getNumLayerSets();     
1525#else
[872]1526  for (Int olsIdx = 0; olsIdx < m_vpsNumLayerSets + numAddOuputLayerSets; olsIdx++)
1527  {
1528    Int addOutLsIdx = olsIdx - m_vpsNumLayerSets;     
[1066]1529#endif   
[964]1530    vps.setLayerSetIdxForOlsMinus1( olsIdx, ( ( addOutLsIdx < 0 ) ?  olsIdx  : m_outputLayerSetIdx[ addOutLsIdx ] ) - 1 ); 
[738]1531
[1066]1532#if H_MV_HLS10_ADD_LAYERSETS
1533    Int lsIdx = vps.olsIdxToLsIdx( olsIdx );
1534#else
[964]1535    std::vector<Int>& layerIdList    = m_layerIdsInSets[ vps.olsIdxToLsIdx( olsIdx ) ];
[1066]1536#endif
[964]1537    if (vps.getDefaultOutputLayerIdc() == 2 || addOutLsIdx >= 0 )
[872]1538    { 
[1066]1539#if H_MV_HLS10_ADD_LAYERSETS
1540      for ( Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++)
1541#else
[872]1542      for ( Int i = 0; i < layerIdList.size(); i++)
[1066]1543#endif
[872]1544      {
1545        vps.setOutputLayerFlag( olsIdx, i, ( olsIdx == 0 && i == 0 ) ? vps.inferOutputLayerFlag(olsIdx, i ) : false ); // This is a software only fix for a bug in the spec. In spec outputLayerFlag neither present nor inferred for this case !
1546      }
1547
1548      std::vector<Int>& outLayerIdList = ( addOutLsIdx >= 0 ) ? m_layerIdsInAddOutputLayerSet[addOutLsIdx] : m_layerIdsInDefOutputLayerSet[olsIdx]; 
1549
1550      Bool outputLayerInLayerSetFlag = false; 
1551      for (Int j = 0; j < outLayerIdList.size(); j++)
1552      {   
[1066]1553#if H_MV_HLS10_ADD_LAYERSETS
1554        for ( Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++)
1555        {
1556          if ( vps.getLayerSetLayerIdList( lsIdx, i ) == outLayerIdList[ j ] )
1557#else
[872]1558        for (Int i = 0; i < layerIdList.size(); i++ )
1559        {
1560          if ( layerIdList[ i ] == outLayerIdList[ j ] )
[1066]1561#endif
[872]1562          {
1563            vps.setOutputLayerFlag( olsIdx, i, true );       
1564            outputLayerInLayerSetFlag = true; 
1565            break; 
1566          }
1567        }
[1066]1568#if H_MV_HLS10_ADD_LAYERSETS
1569        if ( !outputLayerInLayerSetFlag )
1570        {
1571          fprintf(stderr, "Error: Output layer %d in output layer set %d not in corresponding layer set %d \n", outLayerIdList[ j ], olsIdx , lsIdx );
1572          exit(EXIT_FAILURE);
1573        }
1574#else
1575        assert( outputLayerInLayerSetFlag ); // The output layer is not in the layer set.
1576#endif
[872]1577      }
1578    }
1579    else
1580    {
[1066]1581#if H_MV_HLS10_ADD_LAYERSETS
1582      for ( Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++)
1583#else
[872]1584      for ( Int i = 0; i < layerIdList.size(); i++)
[1066]1585#endif
[872]1586      {
1587        vps.setOutputLayerFlag( olsIdx, i, vps.inferOutputLayerFlag( olsIdx, i ) );       
1588      }
1589    }
1590
[1066]1591#if H_MV_HLS10_NESSECARY_LAYER
1592    vps.deriveNecessaryLayerFlags( olsIdx ); 
1593#endif
[872]1594    vps.deriveTargetLayerIdList(  olsIdx ); 
1595
[1066]1596#if H_MV_HLS10_PTL
1597    // SET profile_tier_level_index.
1598    if ( olsIdx == 0 )
1599    {   
1600      vps.setProfileTierLevelIdx( 0, 0 , vps.getMaxLayersMinus1() > 0 ? 1 : 0 ); 
1601    }
1602    else
1603    {
1604      if( (Int) m_profileTierLevelIdx[ olsIdx ].size() < vps.getNumLayersInIdList( lsIdx ) )
1605      {
1606        fprintf( stderr, "Warning: Not enough profileTierLevelIdx values given for the %d-th OLS. Inferring default values.\n", olsIdx ); 
1607      }
1608      for (Int j = 0; j < vps.getNumLayersInIdList( lsIdx ); j++)
1609      {
1610        if( j < (Int) m_profileTierLevelIdx[ olsIdx ].size() )
1611        {
1612          vps.setProfileTierLevelIdx(olsIdx, j, m_profileTierLevelIdx[olsIdx][j] );
1613#if H_MV_HLS10_PTL_FIX
1614          if( !vps.getNecessaryLayerFlag(olsIdx,j) && m_profileTierLevelIdx[ olsIdx ][ j ] != -1 )
1615          {
1616            fprintf( stderr, "Warning: The %d-th layer in the %d-th OLS is not necessary such that profileTierLevelIdx[%d][%d] will be ignored. Set value to -1 to suppress warning.\n", j,olsIdx,olsIdx,j ); 
1617          }         
1618        }
1619        else if ( vps.getNecessaryLayerFlag(olsIdx,j) )
1620#else
1621        }
1622        else
1623#endif
1624        {
1625          // setting default values
1626          if ( j == 0 || vps.getVpsNumProfileTierLevelMinus1() < 1 )
1627          {
1628            // set base layer as default
1629            vps.setProfileTierLevelIdx(olsIdx, j, 1 );
1630          }
1631          else
1632          {
1633            // set VpsProfileTierLevel[2] as default
1634            vps.setProfileTierLevelIdx(olsIdx, j, 2 ); 
1635          }
1636        }
1637      }
1638    }
1639#else
[872]1640    if ( olsIdx > 0 ) 
1641    {
1642      vps.setProfileLevelTierIdx( olsIdx, m_profileLevelTierIdx[ olsIdx ] ); 
1643    }
[1066]1644#endif
[976]1645   
[964]1646    if ( vps.getNumOutputLayersInOutputLayerSet( olsIdx ) == 1 && 
1647        vps.getNumDirectRefLayers( vps.getOlsHighestOutputLayerId( olsIdx ) ) )
1648    {   
1649      vps.setAltOutputLayerFlag( olsIdx , m_altOutputLayerFlag[ olsIdx ]);
1650    }
1651    else
1652    {
1653      vps.setAltOutputLayerFlag( olsIdx , false );
1654      if ( m_altOutputLayerFlag[ olsIdx ] )
1655      {
1656        printf( "\nWarning: Ignoring AltOutputLayerFlag for output layer set %d, since more than one output layer or no dependent layers.\n", olsIdx );           
1657      }
1658    }
[872]1659  }
[296]1660}
[622]1661
1662Void TAppEncTop::xSetVPSVUI( TComVPS& vps )
1663{
1664  vps.setVpsVuiPresentFlag( m_vpsVuiPresentFlag ); 
1665
[872]1666  TComVPSVUI* pcVPSVUI = vps.getVPSVUI(  ); 
1667  assert( pcVPSVUI ); 
1668
[622]1669  if ( m_vpsVuiPresentFlag )
1670  {
[738]1671    // All this stuff could actually be derived by the encoder,
1672    // however preliminary setting it from input parameters
1673
1674    pcVPSVUI->setCrossLayerPicTypeAlignedFlag( m_crossLayerPicTypeAlignedFlag );
1675    pcVPSVUI->setCrossLayerIrapAlignedFlag   ( m_crossLayerIrapAlignedFlag    );
[872]1676    pcVPSVUI->setAllLayersIdrAlignedFlag     ( m_allLayersIdrAlignedFlag      );
[622]1677    pcVPSVUI->setBitRatePresentVpsFlag( m_bitRatePresentVpsFlag );
1678    pcVPSVUI->setPicRatePresentVpsFlag( m_picRatePresentVpsFlag );
1679
1680    if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
1681    {
[1066]1682#if H_MV_HLS10_VPS_VUI
1683      for( Int i = 0; i  <  vps.getNumLayerSets(); i++ )
1684#else
[872]1685      for( Int i = 0; i  <=  vps.getVpsNumLayerSetsMinus1(); i++ )
[1066]1686#endif
[622]1687      {
1688        for( Int j = 0; j  <=  vps.getMaxTLayers(); j++ ) 
1689        {
1690          if( pcVPSVUI->getBitRatePresentVpsFlag( ) && m_bitRatePresentFlag[i].size() > j )
1691          {
1692            pcVPSVUI->setBitRatePresentFlag( i, j, m_bitRatePresentFlag[i][j] );           
1693          }
1694          if( pcVPSVUI->getPicRatePresentVpsFlag( ) && m_picRatePresentFlag[i].size() > j   )
1695          {
1696            pcVPSVUI->setPicRatePresentFlag( i, j, m_picRatePresentFlag[i][j] );
1697          }
1698          if( pcVPSVUI->getBitRatePresentFlag( i, j )  && m_avgBitRate[i].size() > j )
1699          {
1700            pcVPSVUI->setAvgBitRate( i, j, m_avgBitRate[i][j] );         
1701          }
1702          if( pcVPSVUI->getBitRatePresentFlag( i, j )  && m_maxBitRate[i].size() > j )
1703          {
1704            pcVPSVUI->setMaxBitRate( i, j, m_maxBitRate[i][j] );
1705          }
1706          if( pcVPSVUI->getPicRatePresentFlag( i, j ) && m_constantPicRateIdc[i].size() > j )
1707          {
1708            pcVPSVUI->setConstantPicRateIdc( i, j, m_constantPicRateIdc[i][j] );
1709          }
1710          if( pcVPSVUI->getPicRatePresentFlag( i, j ) && m_avgPicRate[i].size() > j )
1711          {
1712            pcVPSVUI->setAvgPicRate( i, j, m_avgPicRate[i][j] );
1713          }
1714        }
1715      }
1716    }
1717
[738]1718    pcVPSVUI->setTilesNotInUseFlag( m_tilesNotInUseFlag );
1719
1720    if( !pcVPSVUI->getTilesNotInUseFlag() ) 
1721    {     
1722      for( Int i = 0; i  <=  vps.getMaxLayersMinus1(); i++ )
1723      {
1724        pcVPSVUI->setTilesInUseFlag( i, m_tilesInUseFlag[ i ] );
1725        if( pcVPSVUI->getTilesInUseFlag( i ) ) 
1726        {
1727          pcVPSVUI->setLoopFilterNotAcrossTilesFlag( i, m_loopFilterNotAcrossTilesFlag[ i ] );
1728        }
1729      } 
1730
1731      for( Int i = 1; i  <=  vps.getMaxLayersMinus1(); i++ ) 
1732      {
1733        for( Int j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ) ; j++ )
1734        { 
[1066]1735#if H_MV_HLS10_REF_PRED_LAYERS
1736          Int layerIdx = vps.getLayerIdInVps( vps.getIdDirectRefLayer(vps.getLayerIdInNuh( i ) , j  )); 
1737#else
[738]1738          Int layerIdx = vps.getLayerIdInVps( vps.getRefLayerId(vps.getLayerIdInNuh( i ) , j  )); 
[1066]1739#endif
[738]1740          if( pcVPSVUI->getTilesInUseFlag( i )  &&  pcVPSVUI->getTilesInUseFlag( layerIdx ) ) 
1741          {
1742            pcVPSVUI->setTileBoundariesAlignedFlag( i, j, m_tileBoundariesAlignedFlag[i][j] );
1743          }
1744        } 
1745      }
1746    } 
1747
1748    pcVPSVUI->setWppNotInUseFlag( m_wppNotInUseFlag );
1749
1750    if( !pcVPSVUI->getWppNotInUseFlag( ) )
1751    {
1752      for( Int i = 1; i  <=  vps.getMaxLayersMinus1(); i++ ) 
1753      {
1754        pcVPSVUI->setWppInUseFlag( i, m_wppInUseFlag[ i ]);
1755      }
1756    }
[622]1757
[1066]1758#if H_MV_HLS10_VPS_VUI
1759  pcVPSVUI->setSingleLayerForNonIrapFlag( m_singleLayerForNonIrapFlag );
1760  pcVPSVUI->setHigherLayerIrapSkipFlag( m_higherLayerIrapSkipFlag );
1761#endif
1762
[622]1763    pcVPSVUI->setIlpRestrictedRefLayersFlag( m_ilpRestrictedRefLayersFlag );
1764
1765    if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
1766    {
1767      for( Int i = 1; i  <=  vps.getMaxLayersMinus1(); i++ )
1768      {
1769        for( Int j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ); j++ )
1770        {
1771          if ( m_minSpatialSegmentOffsetPlus1[i].size() > j )
1772          {       
1773            pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, m_minSpatialSegmentOffsetPlus1[i][j] );
1774          }
1775          if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
1776          {
1777            if ( m_ctuBasedOffsetEnabledFlag[i].size() > j )
1778            {       
1779              pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, m_ctuBasedOffsetEnabledFlag[i][j] );
1780            }
1781            if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
1782            {
1783              if ( m_minHorizontalCtuOffsetPlus1[i].size() > j )
1784              {
1785                pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, m_minHorizontalCtuOffsetPlus1[i][j] );
1786              }
1787            }
1788          }
1789        }
1790      }
1791    }     
[738]1792    pcVPSVUI->setVideoSignalInfoIdxPresentFlag( true ); 
1793    pcVPSVUI->setVpsNumVideoSignalInfoMinus1  ( 0    ); 
1794
1795    assert ( pcVPSVUI->getVideoSignalInfo( 0 ) == NULL );
1796
1797    TComVideoSignalInfo* videoSignalInfo = new TComVideoSignalInfo; 
1798
1799    videoSignalInfo->setColourPrimariesVps        ( m_colourPrimaries ); 
1800    videoSignalInfo->setMatrixCoeffsVps           ( m_matrixCoefficients ); 
1801    videoSignalInfo->setTransferCharacteristicsVps( m_transferCharacteristics ); 
1802    videoSignalInfo->setVideoVpsFormat            ( m_videoFormat ); 
1803    videoSignalInfo->setVideoFullRangeVpsFlag     ( m_videoFullRangeFlag ); 
1804
1805    pcVPSVUI->setVideoSignalInfo( 0, videoSignalInfo );       
1806
1807    for (Int i = 0; i < m_numberOfLayers; i++)
1808    {     
1809      pcVPSVUI->setVpsVideoSignalInfoIdx( i, 0 ); 
1810    }
1811    pcVPSVUI->setVpsVuiBspHrdPresentFlag( false ); // TBD
[622]1812  }
[872]1813  else
1814  {
1815    pcVPSVUI->setCrossLayerIrapAlignedFlag   ( false   );
1816  }
[622]1817}
[1066]1818#if H_MV_HLS10_GEN_FIX
1819Bool TAppEncTop::xLayerIdInTargetEncLayerIdList(Int nuhLayerId)
1820{
1821  return  ( std::find(m_targetEncLayerIdList.begin(), m_targetEncLayerIdList.end(), nuhLayerId) != m_targetEncLayerIdList.end()) ;
1822}
[296]1823#endif
[1066]1824
1825
1826#endif
1827
1828
[56]1829//! \}
Note: See TracBrowser for help on using the repository browser.