source: 3DVCSoftware/branches/HTM-10.1-dev0/source/App/TAppEncoder/TAppEncTop.cpp @ 876

Last change on this file since 876 was 876, checked in by tech, 10 years ago

Cleanups part 1.

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