source: 3DVCSoftware/branches/HTM-15.2-dev/source/App/TAppEncoder/TAppEncTop.cpp @ 1370

Last change on this file since 1370 was 1360, checked in by tech, 9 years ago

Update to HM-16.7.

  • Property svn:eol-style set to native
File size: 99.7 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-2015, 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#include <iomanip>
45
46#include "TAppEncTop.h"
47#include "TLibEncoder/AnnexBwrite.h"
48
49using namespace std;
50
51//! \ingroup TAppEncoder
52//! \{
53
54// ====================================================================================================================
55// Constructor / destructor / initialization / destroy
56// ====================================================================================================================
57
58TAppEncTop::TAppEncTop()
59{
60
61#if NH_MV
62  m_vps = new TComVPS; 
63#else
64  m_iFrameRcvd = 0;
65#endif
66  m_totalBytes = 0;
67  m_essentialBytes = 0;
68}
69
70TAppEncTop::~TAppEncTop()
71{
72#if NH_MV
73  if (m_vps)
74  {
75   delete m_vps; 
76  };
77#endif
78
79}
80
81Void TAppEncTop::xInitLibCfg()
82{
83#if NH_MV
84  TComVPS& vps = (*m_vps);   
85#else
86  TComVPS vps;
87#endif
88 
89#if NH_3D
90  vps.createCamPars(m_iNumberOfViews); 
91#endif
92
93#if NH_3D_DLT
94  TComDLT dlt = TComDLT();
95#endif
96
97#if NH_MV
98  Int maxTempLayer = -1; 
99  for (Int j = 0; j < m_numberOfLayers; j++)
100  {
101    maxTempLayer = max( m_maxTempLayerMvc[ j ], maxTempLayer ); 
102  }
103
104  vps.setMaxTLayers                       ( maxTempLayer );
105  if ( maxTempLayer )
106  {
107    vps.setTemporalNestingFlag(true);
108  }
109  vps.setMaxLayersMinus1( m_numberOfLayers - 1);
110  for(Int i = 0; i < MAX_TLAYER; i++)
111  {
112    Int maxNumReOrderPics  = 0; 
113    Int maxDecPicBuffering = 0;
114    for (Int j = 0; j < m_numberOfLayers; j++)
115    {
116      maxNumReOrderPics  = max( maxNumReOrderPics,  m_numReorderPicsMvc    [ j ][ i ] );     
117      maxDecPicBuffering = max( maxDecPicBuffering, m_maxDecPicBufferingMvc[ j ][ i ] );     
118    }
119
120    vps.setNumReorderPics                 ( maxNumReOrderPics  ,i );
121    vps.setMaxDecPicBuffering             ( maxDecPicBuffering ,i );
122  }
123#else
124  vps.setMaxTLayers                                               ( m_maxTempLayer );
125  if (m_maxTempLayer == 1)
126  {
127    vps.setTemporalNestingFlag(true);
128  }
129  vps.setMaxLayers                                                ( 1 );
130  for(Int i = 0; i < MAX_TLAYER; i++)
131  {
132    vps.setNumReorderPics                                         ( m_numReorderPics[i], i );
133    vps.setMaxDecPicBuffering                                     ( m_maxDecPicBuffering[i], i );
134  }
135#endif
136#if NH_MV
137  xSetTimingInfo           ( vps );
138  xSetHrdParameters        ( vps ); 
139  xSetLayerIds             ( vps );   
140  xSetDimensionIdAndLength ( vps );
141  xSetDependencies         ( vps );
142  xSetRepFormat            ( vps ); 
143  xSetProfileTierLevel     ( vps ); 
144  xSetLayerSets            ( vps ); 
145  xSetDpbSize              ( vps ); 
146  xSetVPSVUI               ( vps ); 
147#if NH_3D
148  xSetCamPara              ( vps ); 
149  m_ivPicLists.setVPS      ( &vps );
150#endif
151#if NH_3D_DLT
152  xDeriveDltArray          ( vps, &dlt );
153#endif
154  if ( m_targetEncLayerIdList.size() == 0 )
155  {
156    for (Int i = 0; i < m_numberOfLayers; i++ )
157    {
158      m_targetEncLayerIdList.push_back( vps.getLayerIdInNuh( i ) );
159    }
160  }
161  for( Int i = (Int) m_targetEncLayerIdList.size()-1 ; i >= 0 ; i--)
162  {
163    Int iNuhLayerId = m_targetEncLayerIdList[i]; 
164    Bool allRefLayersPresent = true; 
165    for( Int j = 0; j < vps.getNumRefLayers( iNuhLayerId ); j++)
166    {
167      allRefLayersPresent = allRefLayersPresent && xLayerIdInTargetEncLayerIdList( vps.getIdRefLayer( iNuhLayerId, j) );
168    }
169    if ( !allRefLayersPresent )
170    {
171      printf("\nCannot encode layer with nuh_layer_id equal to %d since not all reference layers are in TargetEncLayerIdList\n", iNuhLayerId);
172      m_targetEncLayerIdList.erase( m_targetEncLayerIdList.begin() + i  );
173    }
174  }
175
176  if ( m_outputVpsInfo )
177  { 
178    vps.printScalabilityId();
179    vps.printLayerDependencies();
180    vps.printLayerSets(); 
181    vps.printPTL(); 
182  }
183
184#if NH_3D
185  // Set 3d tool parameters
186  for (Int d = 0; d < 2; d++)
187  { 
188    m_sps3dExtension.setIvMvPredFlag          ( d, m_ivMvPredFlag[d]       );
189    m_sps3dExtension.setIvMvScalingFlag       ( d, m_ivMvScalingFlag[d]    );
190    if (d == 0 )
191    {   
192      m_sps3dExtension.setLog2SubPbSizeMinus3   ( d, m_log2SubPbSizeMinus3   );
193      m_sps3dExtension.setIvResPredFlag         ( d, m_ivResPredFlag         );
194      m_sps3dExtension.setDepthRefinementFlag   ( d, m_depthRefinementFlag   );
195      m_sps3dExtension.setViewSynthesisPredFlag ( d, m_viewSynthesisPredFlag );
196      m_sps3dExtension.setDepthBasedBlkPartFlag ( d, m_depthBasedBlkPartFlag );
197    }
198    else
199    {   
200      m_sps3dExtension.setMpiFlag               ( d, m_mpiFlag               );
201      m_sps3dExtension.setLog2MpiSubPbSizeMinus3( d, m_log2MpiSubPbSizeMinus3);
202      m_sps3dExtension.setIntraContourFlag      ( d, m_intraContourFlag      );
203      m_sps3dExtension.setIntraSdcWedgeFlag     ( d, m_intraSdcFlag || m_intraWedgeFlag     );
204      m_sps3dExtension.setQtPredFlag            ( d, m_qtPredFlag            );
205      m_sps3dExtension.setInterSdcFlag          ( d, m_interSdcFlag          );
206      m_sps3dExtension.setDepthIntraSkipFlag    ( d, m_depthIntraSkipFlag    ); 
207    }
208  }
209#endif
210
211
212  /// Create encoders and set profiles profiles
213  for(Int layerIdInVps = 0; layerIdInVps < m_numberOfLayers; layerIdInVps++)
214  {
215    m_frameRcvd                 .push_back(0);
216    m_acTEncTopList             .push_back(new TEncTop); 
217    m_acTVideoIOYuvInputFileList.push_back(new TVideoIOYuv);
218    m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv);
219#if NH_3D   
220    Int profileIdc = -1; 
221    for (Int olsIdx = 0; olsIdx < vps.getNumOutputLayerSets(); olsIdx++ )
222    {   
223      Int lsIdx = vps.olsIdxToLsIdx( olsIdx );
224      for(Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++ )
225      {
226        if( vps.getLayerIdInNuh( layerIdInVps) == vps.getLayerSetLayerIdList(lsIdx, i) )
227        {
228          Int ptlIdx = vps.getProfileTierLevelIdx( olsIdx, i );
229          if ( ptlIdx != -1 )
230          {
231            Int curProfileIdc = vps.getPTL(ptlIdx)->getGeneralPTL()->getProfileIdc(); 
232            if (profileIdc == -1)   
233            {
234              profileIdc = curProfileIdc; 
235            }
236            else
237            {   
238              if ( profileIdc != curProfileIdc )
239              {             
240                fprintf(stderr, "Error: ProfileIdc for layer with index %d in VPS not equal in all OLSs. \n", layerIdInVps );
241                exit(EXIT_FAILURE);
242              }
243            }
244          }
245        }
246      }
247    }
248
249    if (profileIdc == -1 )
250    {
251      fprintf(stderr, "Error: No profile given for layer with index %d in VPS not equal in all OLS. \n", layerIdInVps );
252      exit(EXIT_FAILURE);
253    }
254    m_acTEncTopList[ layerIdInVps ]->setProfileIdc( profileIdc ); 
255#endif
256  }
257
258
259  for(Int layerIdInVps = 0; layerIdInVps < m_numberOfLayers; layerIdInVps++)
260  {
261    m_cListPicYuvRec            .push_back(new TComList<TComPicYuv*>) ;
262
263#if !NH_MV
264    m_ivPicLists.push_back( m_acTEncTopList[ layerIdInVps ]->getListPic()  ); 
265#endif
266
267    TEncTop& m_cTEncTop = *m_acTEncTopList[ layerIdInVps ];  // It is not a member, but this name helps avoiding code duplication !!!
268
269    Int layerId = vps.getLayerIdInNuh          ( layerIdInVps );
270#if NH_MV
271    m_ivPicLists.getSubDpb( layerId, true ); 
272#endif
273
274    m_cTEncTop.setLayerIdInVps                 ( layerIdInVps ); 
275    m_cTEncTop.setLayerId                      ( layerId );   
276    m_cTEncTop.setViewId                       ( vps.getViewId      (  layerId ) );
277    m_cTEncTop.setViewIndex                    ( vps.getViewIndex   (  layerId ) );
278#if NH_3D
279    Bool isDepth = ( vps.getDepthId     ( layerId ) != 0 ) ;
280    m_cTEncTop.setIsDepth                      ( isDepth );
281    //====== Camera Parameters =========
282    m_cTEncTop.setCameraParameters             ( &m_cCameraData );     
283#if NH_3D_VSO
284    //====== VSO =========
285    m_cTEncTop.setRenderModelParameters        ( &m_cRenModStrParser ); 
286    m_cTEncTop.setForceLambdaScaleVSO          ( isDepth ? m_bForceLambdaScaleVSO : false );
287    m_cTEncTop.setLambdaScaleVSO               ( isDepth ? m_dLambdaScaleVSO      : 1     );
288    m_cTEncTop.setVSOMode                      ( isDepth ? m_uiVSOMode            : 0     );
289
290    m_cTEncTop.setAllowNegDist                 ( isDepth ? m_bAllowNegDist        : false );
291
292    // SAIT_VSO_EST_A0033
293    m_cTEncTop.setUseEstimatedVSD              ( isDepth ? m_bUseEstimatedVSD     : false );
294
295    // LGE_WVSO_A0119
296    m_cTEncTop.setUseWVSO                      ( isDepth ? m_bUseWVSO             : false );   
297    m_cTEncTop.setVSOWeight                    ( isDepth ? m_iVSOWeight           : 0     );
298    m_cTEncTop.setVSDWeight                    ( isDepth ? m_iVSDWeight           : 0     );
299    m_cTEncTop.setDWeight                      ( isDepth ? m_iDWeight             : 0     );
300#endif // H_3D_VSO
301#if NH_3D_IC
302    m_cTEncTop.setUseIC                        ( vps.getViewIndex( layerId ) == 0 || isDepth ? false : m_abUseIC );
303    m_cTEncTop.setUseICLowLatencyEnc           ( m_bUseLowLatencyICEnc );
304#endif
305
306   
307    m_cTEncTop.setUseDMM                       ( isDepth ? m_intraWedgeFlag   : false );
308    m_cTEncTop.setUseSDC                       ( isDepth ? m_intraSdcFlag     : false );
309    m_cTEncTop.setUseDLT                       ( isDepth ? m_useDLT   : false );
310    m_cTEncTop.setUseQTL                       ( isDepth ? m_bUseQTL  : false );
311    m_cTEncTop.setSps3dExtension               ( m_sps3dExtension );
312#endif // NH_3D
313
314    m_cTEncTop.setIvPicLists                   ( &m_ivPicLists ); 
315#endif  // NH_MV
316  m_cTEncTop.setVPS(&vps);
317
318#if NH_3D_DLT
319  m_cTEncTop.setDLT(dlt);
320#endif
321
322#if NH_MV
323  m_cTEncTop.setProfile                                           ( m_profiles[0]);
324  m_cTEncTop.setLevel                                             ( m_levelTier[0], m_level[0] );
325#else
326  m_cTEncTop.setProfile                                           ( m_profile);
327  m_cTEncTop.setLevel                                             ( m_levelTier, m_level);
328#endif
329  m_cTEncTop.setProgressiveSourceFlag                             ( m_progressiveSourceFlag);
330  m_cTEncTop.setInterlacedSourceFlag                              ( m_interlacedSourceFlag);
331  m_cTEncTop.setNonPackedConstraintFlag                           ( m_nonPackedConstraintFlag);
332  m_cTEncTop.setFrameOnlyConstraintFlag                           ( m_frameOnlyConstraintFlag);
333  m_cTEncTop.setBitDepthConstraintValue                           ( m_bitDepthConstraint );
334  m_cTEncTop.setChromaFormatConstraintValue                       ( m_chromaFormatConstraint );
335  m_cTEncTop.setIntraConstraintFlag                               ( m_intraConstraintFlag );
336  m_cTEncTop.setOnePictureOnlyConstraintFlag                      ( m_onePictureOnlyConstraintFlag );
337  m_cTEncTop.setLowerBitRateConstraintFlag                        ( m_lowerBitRateConstraintFlag );
338
339  m_cTEncTop.setPrintMSEBasedSequencePSNR                         ( m_printMSEBasedSequencePSNR);
340  m_cTEncTop.setPrintFrameMSE                                     ( m_printFrameMSE);
341  m_cTEncTop.setPrintSequenceMSE                                  ( m_printSequenceMSE);
342  m_cTEncTop.setCabacZeroWordPaddingEnabled                       ( m_cabacZeroWordPaddingEnabled );
343
344  m_cTEncTop.setFrameRate                                         ( m_iFrameRate );
345  m_cTEncTop.setFrameSkip                                         ( m_FrameSkip );
346  m_cTEncTop.setSourceWidth                                       ( m_iSourceWidth );
347  m_cTEncTop.setSourceHeight                                      ( m_iSourceHeight );
348  m_cTEncTop.setConformanceWindow                                 ( m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom );
349  m_cTEncTop.setFramesToBeEncoded                                 ( m_framesToBeEncoded );
350
351  //====== Coding Structure ========
352#if NH_MV
353  m_cTEncTop.setIntraPeriod                                       ( m_iIntraPeriod[ layerIdInVps ] );
354#else
355  m_cTEncTop.setIntraPeriod                                       ( m_iIntraPeriod );
356#endif
357  m_cTEncTop.setDecodingRefreshType                               ( m_iDecodingRefreshType );
358  m_cTEncTop.setGOPSize                                           ( m_iGOPSize );
359#if NH_MV
360  m_cTEncTop.setGopList                                           ( m_GOPListMvc[layerIdInVps] );
361  m_cTEncTop.setExtraRPSs                                         ( m_extraRPSsMvc[layerIdInVps] );
362  for(Int i = 0; i < MAX_TLAYER; i++)
363  {
364    m_cTEncTop.setNumReorderPics                                  ( m_numReorderPicsMvc[layerIdInVps][i], i );
365    m_cTEncTop.setMaxDecPicBuffering                              ( m_maxDecPicBufferingMvc[layerIdInVps][i], i );
366  }
367#else
368  m_cTEncTop.setGopList                                           ( m_GOPList );
369  m_cTEncTop.setExtraRPSs                                         ( m_extraRPSs );
370  for(Int i = 0; i < MAX_TLAYER; i++)
371  {
372    m_cTEncTop.setNumReorderPics                                  ( m_numReorderPics[i], i );
373    m_cTEncTop.setMaxDecPicBuffering                              ( m_maxDecPicBuffering[i], i );
374  }
375#endif
376  for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
377  {
378    m_cTEncTop.setLambdaModifier                                  ( uiLoop, m_adLambdaModifier[ uiLoop ] );
379  }
380  m_cTEncTop.setIntraLambdaModifier                               ( m_adIntraLambdaModifier );
381  m_cTEncTop.setIntraQpFactor                                     ( m_dIntraQpFactor );
382
383#if NH_MV
384  m_cTEncTop.setQP                                                ( m_iQP[layerIdInVps] );
385#else
386  m_cTEncTop.setQP                                                ( m_iQP );
387#endif
388
389  m_cTEncTop.setPad                                               ( m_aiPad );
390  m_cTEncTop.setAccessUnitDelimiter                               ( m_AccessUnitDelimiter );
391#if NH_MV
392  m_cTEncTop.setMaxTempLayer                                      ( m_maxTempLayerMvc[layerIdInVps] );
393#else
394  m_cTEncTop.setMaxTempLayer                                      ( m_maxTempLayer );
395#endif
396  m_cTEncTop.setUseAMP( m_enableAMP );
397
398  //===== Slice ========
399
400  //====== Loop/Deblock Filter ========
401#if NH_MV
402  m_cTEncTop.setLoopFilterDisable                                 ( m_bLoopFilterDisable[layerIdInVps]);
403#else
404  m_cTEncTop.setLoopFilterDisable                                 ( m_bLoopFilterDisable       );
405#endif
406  m_cTEncTop.setLoopFilterOffsetInPPS                             ( m_loopFilterOffsetInPPS );
407  m_cTEncTop.setLoopFilterBetaOffset                              ( m_loopFilterBetaOffsetDiv2  );
408  m_cTEncTop.setLoopFilterTcOffset                                ( m_loopFilterTcOffsetDiv2    );
409  m_cTEncTop.setDeblockingFilterMetric                            ( m_DeblockingFilterMetric );
410
411  //====== Motion search ========
412  m_cTEncTop.setDisableIntraPUsInInterSlices                      ( m_bDisableIntraPUsInInterSlices );
413  m_cTEncTop.setMotionEstimationSearchMethod                      ( m_motionEstimationSearchMethod  );
414  m_cTEncTop.setSearchRange                                       ( m_iSearchRange );
415  m_cTEncTop.setBipredSearchRange                                 ( m_bipredSearchRange );
416  m_cTEncTop.setClipForBiPredMeEnabled                            ( m_bClipForBiPredMeEnabled );
417  m_cTEncTop.setFastMEAssumingSmootherMVEnabled                   ( m_bFastMEAssumingSmootherMVEnabled );
418  m_cTEncTop.setMinSearchWindow                                   ( m_minSearchWindow );
419  m_cTEncTop.setRestrictMESampling                                ( m_bRestrictMESampling );
420
421#if NH_MV
422  m_cTEncTop.setUseDisparitySearchRangeRestriction                ( m_bUseDisparitySearchRangeRestriction );
423  m_cTEncTop.setVerticalDisparitySearchRange                      ( m_iVerticalDisparitySearchRange );
424#endif
425  //====== Quality control ========
426  m_cTEncTop.setMaxDeltaQP                                        ( m_iMaxDeltaQP  );
427  m_cTEncTop.setMaxCuDQPDepth                                     ( m_iMaxCuDQPDepth  );
428  m_cTEncTop.setDiffCuChromaQpOffsetDepth                         ( m_diffCuChromaQpOffsetDepth );
429  m_cTEncTop.setChromaCbQpOffset                                  ( m_cbQpOffset     );
430  m_cTEncTop.setChromaCrQpOffset                                  ( m_crQpOffset  );
431
432#if NH_3D
433  m_cTEncTop.setChromaFormatIdc                                   ( isDepth ? CHROMA_400 : m_chromaFormatIDC );
434#else
435  m_cTEncTop.setChromaFormatIdc                                   ( m_chromaFormatIDC  );
436#endif
437
438#if ADAPTIVE_QP_SELECTION
439  m_cTEncTop.setUseAdaptQpSelect                                  ( m_bUseAdaptQpSelect   );
440#endif
441
442  m_cTEncTop.setUseAdaptiveQP                                     ( m_bUseAdaptiveQP  );
443  m_cTEncTop.setQPAdaptationRange                                 ( m_iQPAdaptationRange );
444  m_cTEncTop.setExtendedPrecisionProcessingFlag                   ( m_extendedPrecisionProcessingFlag );
445  m_cTEncTop.setHighPrecisionOffsetsEnabledFlag                   ( m_highPrecisionOffsetsEnabledFlag );
446
447  m_cTEncTop.setWeightedPredictionMethod( m_weightedPredictionMethod );
448
449  //====== Tool list ========
450  m_cTEncTop.setDeltaQpRD                                         ( m_uiDeltaQpRD  );
451  m_cTEncTop.setFastDeltaQp                                       ( m_bFastDeltaQP  );
452  m_cTEncTop.setUseASR                                            ( m_bUseASR      );
453  m_cTEncTop.setUseHADME                                          ( m_bUseHADME    );
454#if NH_MV
455  m_cTEncTop.setdQPs                                              ( m_aidQP[layerIdInVps]   );
456#else
457  m_cTEncTop.setdQPs                                              ( m_aidQP        );
458#endif
459  m_cTEncTop.setUseRDOQ                                           ( m_useRDOQ     );
460  m_cTEncTop.setUseRDOQTS                                         ( m_useRDOQTS   );
461#if T0196_SELECTIVE_RDOQ
462  m_cTEncTop.setUseSelectiveRDOQ                                  ( m_useSelectiveRDOQ );
463#endif
464  m_cTEncTop.setRDpenalty                                         ( m_rdPenalty );
465  m_cTEncTop.setMaxCUWidth                                        ( m_uiMaxCUWidth );
466  m_cTEncTop.setMaxCUHeight                                       ( m_uiMaxCUHeight );
467  m_cTEncTop.setMaxTotalCUDepth                                   ( m_uiMaxTotalCUDepth );
468  m_cTEncTop.setLog2DiffMaxMinCodingBlockSize                     ( m_uiLog2DiffMaxMinCodingBlockSize );
469  m_cTEncTop.setQuadtreeTULog2MaxSize                             ( m_uiQuadtreeTULog2MaxSize );
470  m_cTEncTop.setQuadtreeTULog2MinSize                             ( m_uiQuadtreeTULog2MinSize );
471  m_cTEncTop.setQuadtreeTUMaxDepthInter                           ( m_uiQuadtreeTUMaxDepthInter );
472  m_cTEncTop.setQuadtreeTUMaxDepthIntra                           ( m_uiQuadtreeTUMaxDepthIntra );
473  m_cTEncTop.setFastInterSearchMode                               ( m_fastInterSearchMode );
474  m_cTEncTop.setUseEarlyCU                                        ( m_bUseEarlyCU  );
475  m_cTEncTop.setUseFastDecisionForMerge                           ( m_useFastDecisionForMerge  );
476  m_cTEncTop.setUseCbfFastMode                                    ( m_bUseCbfFastMode  );
477  m_cTEncTop.setUseEarlySkipDetection                             ( m_useEarlySkipDetection );
478  m_cTEncTop.setCrossComponentPredictionEnabledFlag               ( m_crossComponentPredictionEnabledFlag );
479  m_cTEncTop.setUseReconBasedCrossCPredictionEstimate             ( m_reconBasedCrossCPredictionEstimate );
480#if NH_MV
481  m_cTEncTop.setLog2SaoOffsetScale                                ( CHANNEL_TYPE_LUMA  , m_log2SaoOffsetScale[layerIdInVps][CHANNEL_TYPE_LUMA]   );
482  m_cTEncTop.setLog2SaoOffsetScale                                ( CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[layerIdInVps][CHANNEL_TYPE_CHROMA] );
483#else
484  m_cTEncTop.setLog2SaoOffsetScale                                ( CHANNEL_TYPE_LUMA  , m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA]   );
485  m_cTEncTop.setLog2SaoOffsetScale                                ( CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA] );
486#endif
487  m_cTEncTop.setUseTransformSkip                                  ( m_useTransformSkip      );
488  m_cTEncTop.setUseTransformSkipFast                              ( m_useTransformSkipFast  );
489  m_cTEncTop.setTransformSkipRotationEnabledFlag                  ( m_transformSkipRotationEnabledFlag );
490  m_cTEncTop.setTransformSkipContextEnabledFlag                   ( m_transformSkipContextEnabledFlag   );
491  m_cTEncTop.setPersistentRiceAdaptationEnabledFlag               ( m_persistentRiceAdaptationEnabledFlag );
492  m_cTEncTop.setCabacBypassAlignmentEnabledFlag                   ( m_cabacBypassAlignmentEnabledFlag );
493  m_cTEncTop.setLog2MaxTransformSkipBlockSize                     ( m_log2MaxTransformSkipBlockSize  );
494  for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++)
495  {
496    m_cTEncTop.setRdpcmEnabledFlag                                ( RDPCMSignallingMode(signallingModeIndex), m_rdpcmEnabledFlag[signallingModeIndex]);
497  }
498  m_cTEncTop.setUseConstrainedIntraPred                           ( m_bUseConstrainedIntraPred );
499  m_cTEncTop.setFastUDIUseMPMEnabled                              ( m_bFastUDIUseMPMEnabled );
500  m_cTEncTop.setFastMEForGenBLowDelayEnabled                      ( m_bFastMEForGenBLowDelayEnabled );
501  m_cTEncTop.setUseBLambdaForNonKeyLowDelayPictures               ( m_bUseBLambdaForNonKeyLowDelayPictures );
502  m_cTEncTop.setPCMLog2MinSize                                    ( m_uiPCMLog2MinSize);
503  m_cTEncTop.setUsePCM                                            ( m_usePCM );
504
505  // set internal bit-depth and constants
506  for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++)
507  {
508    m_cTEncTop.setBitDepth((ChannelType)channelType, m_internalBitDepth[channelType]);
509    m_cTEncTop.setPCMBitDepth((ChannelType)channelType, m_bPCMInputBitDepthFlag ? m_MSBExtendedBitDepth[channelType] : m_internalBitDepth[channelType]);
510  }
511
512  m_cTEncTop.setPCMLog2MaxSize                                    ( m_pcmLog2MaxSize);
513  m_cTEncTop.setMaxNumMergeCand                                   ( m_maxNumMergeCand );
514
515
516  //====== Weighted Prediction ========
517  m_cTEncTop.setUseWP                                             ( m_useWeightedPred      );
518  m_cTEncTop.setWPBiPred                                          ( m_useWeightedBiPred   );
519  //====== Parallel Merge Estimation ========
520  m_cTEncTop.setLog2ParallelMergeLevelMinus2                      ( m_log2ParallelMergeLevel - 2 );
521
522  //====== Slice ========
523  m_cTEncTop.setSliceMode                                         ( m_sliceMode );
524  m_cTEncTop.setSliceArgument                                     ( m_sliceArgument            );
525
526  //====== Dependent Slice ========
527  m_cTEncTop.setSliceSegmentMode                                  ( m_sliceSegmentMode );
528  m_cTEncTop.setSliceSegmentArgument                              ( m_sliceSegmentArgument     );
529
530  if(m_sliceMode == NO_SLICES )
531  {
532    m_bLFCrossSliceBoundaryFlag = true;
533  }
534  m_cTEncTop.setLFCrossSliceBoundaryFlag                          ( m_bLFCrossSliceBoundaryFlag );
535#if NH_MV
536  m_cTEncTop.setUseSAO ( m_bUseSAO[layerIdInVps] );
537#else
538  m_cTEncTop.setUseSAO                                            ( m_bUseSAO );
539#endif
540  m_cTEncTop.setTestSAODisableAtPictureLevel                      ( m_bTestSAODisableAtPictureLevel );
541  m_cTEncTop.setSaoEncodingRate                                   ( m_saoEncodingRate );
542  m_cTEncTop.setSaoEncodingRateChroma                             ( m_saoEncodingRateChroma );
543  m_cTEncTop.setMaxNumOffsetsPerPic                               ( m_maxNumOffsetsPerPic);
544
545  m_cTEncTop.setSaoCtuBoundary                                    ( m_saoCtuBoundary);
546  m_cTEncTop.setPCMInputBitDepthFlag                              ( m_bPCMInputBitDepthFlag);
547  m_cTEncTop.setPCMFilterDisableFlag                              ( m_bPCMFilterDisableFlag);
548
549  m_cTEncTop.setIntraSmoothingDisabledFlag                        (!m_enableIntraReferenceSmoothing );
550  m_cTEncTop.setDecodedPictureHashSEIType                         ( m_decodedPictureHashSEIType );
551  m_cTEncTop.setRecoveryPointSEIEnabled                           ( m_recoveryPointSEIEnabled );
552  m_cTEncTop.setBufferingPeriodSEIEnabled                         ( m_bufferingPeriodSEIEnabled );
553  m_cTEncTop.setPictureTimingSEIEnabled                           ( m_pictureTimingSEIEnabled );
554  m_cTEncTop.setToneMappingInfoSEIEnabled                         ( m_toneMappingInfoSEIEnabled );
555  m_cTEncTop.setTMISEIToneMapId                                   ( m_toneMapId );
556  m_cTEncTop.setTMISEIToneMapCancelFlag                           ( m_toneMapCancelFlag );
557  m_cTEncTop.setTMISEIToneMapPersistenceFlag                      ( m_toneMapPersistenceFlag );
558  m_cTEncTop.setTMISEICodedDataBitDepth                           ( m_toneMapCodedDataBitDepth );
559  m_cTEncTop.setTMISEITargetBitDepth                              ( m_toneMapTargetBitDepth );
560  m_cTEncTop.setTMISEIModelID                                     ( m_toneMapModelId );
561  m_cTEncTop.setTMISEIMinValue                                    ( m_toneMapMinValue );
562  m_cTEncTop.setTMISEIMaxValue                                    ( m_toneMapMaxValue );
563  m_cTEncTop.setTMISEISigmoidMidpoint                             ( m_sigmoidMidpoint );
564  m_cTEncTop.setTMISEISigmoidWidth                                ( m_sigmoidWidth );
565  m_cTEncTop.setTMISEIStartOfCodedInterva                         ( m_startOfCodedInterval );
566  m_cTEncTop.setTMISEINumPivots                                   ( m_numPivots );
567  m_cTEncTop.setTMISEICodedPivotValue                             ( m_codedPivotValue );
568  m_cTEncTop.setTMISEITargetPivotValue                            ( m_targetPivotValue );
569  m_cTEncTop.setTMISEICameraIsoSpeedIdc                           ( m_cameraIsoSpeedIdc );
570  m_cTEncTop.setTMISEICameraIsoSpeedValue                         ( m_cameraIsoSpeedValue );
571  m_cTEncTop.setTMISEIExposureIndexIdc                            ( m_exposureIndexIdc );
572  m_cTEncTop.setTMISEIExposureIndexValue                          ( m_exposureIndexValue );
573  m_cTEncTop.setTMISEIExposureCompensationValueSignFlag           ( m_exposureCompensationValueSignFlag );
574  m_cTEncTop.setTMISEIExposureCompensationValueNumerator          ( m_exposureCompensationValueNumerator );
575  m_cTEncTop.setTMISEIExposureCompensationValueDenomIdc           ( m_exposureCompensationValueDenomIdc );
576  m_cTEncTop.setTMISEIRefScreenLuminanceWhite                     ( m_refScreenLuminanceWhite );
577  m_cTEncTop.setTMISEIExtendedRangeWhiteLevel                     ( m_extendedRangeWhiteLevel );
578  m_cTEncTop.setTMISEINominalBlackLevelLumaCodeValue              ( m_nominalBlackLevelLumaCodeValue );
579  m_cTEncTop.setTMISEINominalWhiteLevelLumaCodeValue              ( m_nominalWhiteLevelLumaCodeValue );
580  m_cTEncTop.setTMISEIExtendedWhiteLevelLumaCodeValue             ( m_extendedWhiteLevelLumaCodeValue );
581  m_cTEncTop.setChromaResamplingFilterHintEnabled                 ( m_chromaResamplingFilterSEIenabled );
582  m_cTEncTop.setChromaResamplingHorFilterIdc                      ( m_chromaResamplingHorFilterIdc );
583  m_cTEncTop.setChromaResamplingVerFilterIdc                      ( m_chromaResamplingVerFilterIdc );
584  m_cTEncTop.setFramePackingArrangementSEIEnabled                 ( m_framePackingSEIEnabled );
585  m_cTEncTop.setFramePackingArrangementSEIType                    ( m_framePackingSEIType );
586  m_cTEncTop.setFramePackingArrangementSEIId                      ( m_framePackingSEIId );
587  m_cTEncTop.setFramePackingArrangementSEIQuincunx                ( m_framePackingSEIQuincunx );
588  m_cTEncTop.setFramePackingArrangementSEIInterpretation          ( m_framePackingSEIInterpretation );
589  m_cTEncTop.setSegmentedRectFramePackingArrangementSEIEnabled    ( m_segmentedRectFramePackingSEIEnabled );
590  m_cTEncTop.setSegmentedRectFramePackingArrangementSEICancel     ( m_segmentedRectFramePackingSEICancel );
591  m_cTEncTop.setSegmentedRectFramePackingArrangementSEIType       ( m_segmentedRectFramePackingSEIType );
592  m_cTEncTop.setSegmentedRectFramePackingArrangementSEIPersistence( m_segmentedRectFramePackingSEIPersistence );
593  m_cTEncTop.setDisplayOrientationSEIAngle                        ( m_displayOrientationSEIAngle );
594  m_cTEncTop.setTemporalLevel0IndexSEIEnabled                     ( m_temporalLevel0IndexSEIEnabled );
595  m_cTEncTop.setGradualDecodingRefreshInfoEnabled                 ( m_gradualDecodingRefreshInfoEnabled );
596  m_cTEncTop.setNoDisplaySEITLayer                                ( m_noDisplaySEITLayer );
597  m_cTEncTop.setDecodingUnitInfoSEIEnabled                        ( m_decodingUnitInfoSEIEnabled );
598  m_cTEncTop.setSOPDescriptionSEIEnabled                          ( m_SOPDescriptionSEIEnabled );
599  m_cTEncTop.setScalableNestingSEIEnabled                         ( m_scalableNestingSEIEnabled );
600#if NH_MV
601#if !NH_MV_SEI
602  m_cTEncTop.setSubBitstreamPropSEIEnabled                        ( m_subBistreamPropSEIEnabled );
603  if( m_subBistreamPropSEIEnabled )                               
604  {                                                               
605    m_cTEncTop.setNumAdditionalSubStreams                         ( m_sbPropNumAdditionalSubStreams );
606    m_cTEncTop.setSubBitstreamMode                                ( m_sbPropSubBitstreamMode );
607    m_cTEncTop.setOutputLayerSetIdxToVps                          ( m_sbPropOutputLayerSetIdxToVps );
608    m_cTEncTop.setHighestSublayerId                               ( m_sbPropHighestSublayerId );
609    m_cTEncTop.setAvgBitRate                                      ( m_sbPropAvgBitRate );
610    m_cTEncTop.setMaxBitRate                                      ( m_sbPropMaxBitRate );
611  }
612#endif
613#endif
614
615  m_cTEncTop.setTMCTSSEIEnabled                                   ( m_tmctsSEIEnabled );
616  m_cTEncTop.setTimeCodeSEIEnabled                                ( m_timeCodeSEIEnabled );
617  m_cTEncTop.setNumberOfTimeSets                                  ( m_timeCodeSEINumTs );
618  for(Int i = 0; i < m_timeCodeSEINumTs; i++)
619  {
620    m_cTEncTop.setTimeSet(m_timeSetArray[i], i);
621  }
622  m_cTEncTop.setKneeSEIEnabled                                    ( m_kneeSEIEnabled );
623  m_cTEncTop.setKneeSEIId                                         ( m_kneeSEIId );
624  m_cTEncTop.setKneeSEICancelFlag                                 ( m_kneeSEICancelFlag );
625  m_cTEncTop.setKneeSEIPersistenceFlag                            ( m_kneeSEIPersistenceFlag );
626  m_cTEncTop.setKneeSEIInputDrange                                ( m_kneeSEIInputDrange );
627  m_cTEncTop.setKneeSEIInputDispLuminance                         ( m_kneeSEIInputDispLuminance );
628  m_cTEncTop.setKneeSEIOutputDrange                               ( m_kneeSEIOutputDrange );
629  m_cTEncTop.setKneeSEIOutputDispLuminance                        ( m_kneeSEIOutputDispLuminance );
630  m_cTEncTop.setKneeSEINumKneePointsMinus1                        ( m_kneeSEINumKneePointsMinus1 );
631  m_cTEncTop.setKneeSEIInputKneePoint                             ( m_kneeSEIInputKneePoint );
632  m_cTEncTop.setKneeSEIOutputKneePoint                            ( m_kneeSEIOutputKneePoint );
633  m_cTEncTop.setColourRemapInfoSEIFileRoot                        ( m_colourRemapSEIFileRoot );
634  m_cTEncTop.setMasteringDisplaySEI                               ( m_masteringDisplay );
635
636#if NH_MV_SEI
637  m_cTEncTop.setSeiMessages                                       ( &m_seiMessages ); 
638#endif
639
640  m_cTEncTop.setTileUniformSpacingFlag                            ( m_tileUniformSpacingFlag );
641  m_cTEncTop.setNumColumnsMinus1                                  ( m_numTileColumnsMinus1 );
642  m_cTEncTop.setNumRowsMinus1                                     ( m_numTileRowsMinus1 );
643  if(!m_tileUniformSpacingFlag)
644  {
645    m_cTEncTop.setColumnWidth                                     ( m_tileColumnWidth );
646    m_cTEncTop.setRowHeight                                       ( m_tileRowHeight );
647  }
648  m_cTEncTop.xCheckGSParameters();
649  Int uiTilesCount = (m_numTileRowsMinus1+1) * (m_numTileColumnsMinus1+1);
650  if(uiTilesCount == 1)
651  {
652    m_bLFCrossTileBoundaryFlag = true;
653  }
654  m_cTEncTop.setLFCrossTileBoundaryFlag                           ( m_bLFCrossTileBoundaryFlag );
655  m_cTEncTop.setEntropyCodingSyncEnabledFlag                      ( m_entropyCodingSyncEnabledFlag );
656  m_cTEncTop.setTMVPModeId                                        ( m_TMVPModeId );
657  m_cTEncTop.setUseScalingListId                                  ( m_useScalingListId  );
658  m_cTEncTop.setScalingListFileName                               ( m_scalingListFileName );
659  m_cTEncTop.setSignHideFlag                                      ( m_signHideFlag);
660#if KWU_RC_VIEWRC_E0227 || KWU_RC_MADPRED_E0227
661  if(!m_cTEncTop.getIsDepth())    //only for texture
662  {
663    m_cTEncTop.setUseRateCtrl                                     ( m_RCEnableRateControl );
664  }                                                         
665  else                                                       
666  {                                                         
667    m_cTEncTop.setUseRateCtrl                                     ( 0 );
668  }
669#else
670  m_cTEncTop.setUseRateCtrl                                       ( m_RCEnableRateControl );
671#endif
672#if !KWU_RC_VIEWRC_E0227
673  m_cTEncTop.setTargetBitrate                                     ( m_RCTargetBitrate );
674#endif
675  m_cTEncTop.setKeepHierBit                                       ( m_RCKeepHierarchicalBit );
676  m_cTEncTop.setLCULevelRC                                        ( m_RCLCULevelRC );
677  m_cTEncTop.setUseLCUSeparateModel                               ( m_RCUseLCUSeparateModel );
678  m_cTEncTop.setInitialQP                                         ( m_RCInitialQP );
679  m_cTEncTop.setForceIntraQP                                      ( m_RCForceIntraQP );
680#if U0132_TARGET_BITS_SATURATION
681  m_cTEncTop.setCpbSaturationEnabled                              ( m_RCCpbSaturationEnabled );
682  m_cTEncTop.setCpbSize                                           ( m_RCCpbSize );
683  m_cTEncTop.setInitialCpbFullness                                ( m_RCInitialCpbFullness );
684#endif
685
686#if KWU_RC_MADPRED_E0227
687  if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
688  {
689    m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_depthMADPred       : 0);
690    if(m_cTEncTop.getUseDepthMADPred())
691    {
692      m_cTEncTop.setCamParam(&m_cCameraData);
693    }
694  }
695#endif
696#if KWU_RC_VIEWRC_E0227
697  if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
698  {
699    m_cTEncTop.setUseViewWiseRateCtrl(m_viewWiseRateCtrl);
700    if(m_iNumberOfViews == 1)
701    {
702      if(m_viewWiseRateCtrl)
703      {
704        m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);
705      }
706      else
707      {
708        m_cTEncTop.setTargetBitrate       ( m_RCTargetBitrate );
709      }
710    }
711    else
712    {
713      if(m_viewWiseRateCtrl)
714      {
715        m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);
716      }
717      else
718      {
719        if(m_iNumberOfViews == 2)
720        {
721          if(m_cTEncTop.getViewId() == 0)
722          {
723            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*80)/100 );
724          }
725          else if(m_cTEncTop.getViewId() == 1)
726          {
727            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*20)/100 );
728          }
729        }
730        else if(m_iNumberOfViews == 3)
731        {
732          if(m_cTEncTop.getViewId() == 0)
733          {
734            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*66)/100 );
735          }
736          else if(m_cTEncTop.getViewId() == 1)
737          {
738            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*17)/100 );
739          }
740          else if(m_cTEncTop.getViewId() == 2)
741          {
742            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*17)/100 );
743          }
744        }
745        else
746        {
747          m_cTEncTop.setTargetBitrate              ( m_RCTargetBitrate );
748        }
749      }
750    }
751  }
752#endif
753  m_cTEncTop.setTransquantBypassEnableFlag                        ( m_TransquantBypassEnableFlag );
754  m_cTEncTop.setCUTransquantBypassFlagForceValue                  ( m_CUTransquantBypassFlagForce );
755  m_cTEncTop.setCostMode                                          ( m_costMode );
756  m_cTEncTop.setUseRecalculateQPAccordingToLambda                 ( m_recalculateQPAccordingToLambda );
757  m_cTEncTop.setUseStrongIntraSmoothing                           ( m_useStrongIntraSmoothing );
758  m_cTEncTop.setActiveParameterSetsSEIEnabled                     ( m_activeParameterSetsSEIEnabled );
759  m_cTEncTop.setVuiParametersPresentFlag                          ( m_vuiParametersPresentFlag );
760  m_cTEncTop.setAspectRatioInfoPresentFlag                        ( m_aspectRatioInfoPresentFlag);
761  m_cTEncTop.setAspectRatioIdc                                    ( m_aspectRatioIdc );
762  m_cTEncTop.setSarWidth                                          ( m_sarWidth );
763  m_cTEncTop.setSarHeight                                         ( m_sarHeight );
764  m_cTEncTop.setOverscanInfoPresentFlag                           ( m_overscanInfoPresentFlag );
765  m_cTEncTop.setOverscanAppropriateFlag                           ( m_overscanAppropriateFlag );
766  m_cTEncTop.setVideoSignalTypePresentFlag                        ( m_videoSignalTypePresentFlag );
767  m_cTEncTop.setVideoFormat                                       ( m_videoFormat );
768  m_cTEncTop.setVideoFullRangeFlag                                ( m_videoFullRangeFlag );
769  m_cTEncTop.setColourDescriptionPresentFlag                      ( m_colourDescriptionPresentFlag );
770  m_cTEncTop.setColourPrimaries                                   ( m_colourPrimaries );
771  m_cTEncTop.setTransferCharacteristics                           ( m_transferCharacteristics );
772  m_cTEncTop.setMatrixCoefficients                                ( m_matrixCoefficients );
773  m_cTEncTop.setChromaLocInfoPresentFlag                          ( m_chromaLocInfoPresentFlag );
774  m_cTEncTop.setChromaSampleLocTypeTopField                       ( m_chromaSampleLocTypeTopField );
775  m_cTEncTop.setChromaSampleLocTypeBottomField                    ( m_chromaSampleLocTypeBottomField );
776  m_cTEncTop.setNeutralChromaIndicationFlag                       ( m_neutralChromaIndicationFlag );
777  m_cTEncTop.setDefaultDisplayWindow                              ( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset );
778  m_cTEncTop.setFrameFieldInfoPresentFlag                         ( m_frameFieldInfoPresentFlag );
779  m_cTEncTop.setPocProportionalToTimingFlag                       ( m_pocProportionalToTimingFlag );
780  m_cTEncTop.setNumTicksPocDiffOneMinus1                          ( m_numTicksPocDiffOneMinus1    );
781  m_cTEncTop.setBitstreamRestrictionFlag                          ( m_bitstreamRestrictionFlag );
782  m_cTEncTop.setTilesFixedStructureFlag                           ( m_tilesFixedStructureFlag );
783  m_cTEncTop.setMotionVectorsOverPicBoundariesFlag                ( m_motionVectorsOverPicBoundariesFlag );
784  m_cTEncTop.setMinSpatialSegmentationIdc                         ( m_minSpatialSegmentationIdc );
785  m_cTEncTop.setMaxBytesPerPicDenom                               ( m_maxBytesPerPicDenom );
786  m_cTEncTop.setMaxBitsPerMinCuDenom                              ( m_maxBitsPerMinCuDenom );
787  m_cTEncTop.setLog2MaxMvLengthHorizontal                         ( m_log2MaxMvLengthHorizontal );
788  m_cTEncTop.setLog2MaxMvLengthVertical                           ( m_log2MaxMvLengthVertical );
789  m_cTEncTop.setEfficientFieldIRAPEnabled                         ( m_bEfficientFieldIRAPEnabled );
790  m_cTEncTop.setHarmonizeGopFirstFieldCoupleEnabled               ( m_bHarmonizeGopFirstFieldCoupleEnabled );
791
792  m_cTEncTop.setSummaryOutFilename                                ( m_summaryOutFilename );
793  m_cTEncTop.setSummaryPicFilenameBase                            ( m_summaryPicFilenameBase );
794  m_cTEncTop.setSummaryVerboseness                                ( m_summaryVerboseness );
795
796#if NH_MV
797  }
798#endif
799#if NH_3D_VSO
800  if ( m_bUseVSO )
801  {
802    if ( m_uiVSOMode == 4 )
803    {
804#if H_3D_VSO_EARLY_SKIP
805      m_cRendererModel.create( m_cRenModStrParser.getNumOfBaseViews(), m_cRenModStrParser.getNumOfModels(), m_iSourceWidth, m_uiMaxCUHeight , LOG2_DISP_PREC_LUT, 0, m_bVSOEarlySkip );
806#else
807      m_cRendererModel.create( m_cRenModStrParser.getNumOfBaseViews(), m_cRenModStrParser.getNumOfModels(), m_iSourceWidth, m_uiMaxCUHeight , LOG2_DISP_PREC_LUT, 0 );
808#endif
809      for ( Int layer = 0; layer < m_numberOfLayers ; layer++ )
810      {
811        TEncTop* pcEncTop =  m_acTEncTopList[ layer ]; 
812        Int iViewNum      = pcEncTop->getViewIndex(); 
813        Int iContent      = pcEncTop->getIsDepth() ? 1 : 0; 
814        Int iNumOfModels  = m_cRenModStrParser.getNumOfModelsForView(iViewNum, iContent);
815
816        Bool bUseVSO      = (iNumOfModels != 0);
817
818        pcEncTop->setUseVSO( bUseVSO );
819        pcEncTop->getRdCost()->setRenModel( bUseVSO ? &m_cRendererModel : NULL );
820
821        for (Int iCurModel = 0; iCurModel < iNumOfModels; iCurModel++ )
822        {
823          Int iModelNum; Int iLeftViewNum; Int iRightViewNum; Int iDump; Int iOrgRefNum; Int iBlendMode;
824
825          m_cRenModStrParser.getSingleModelData  ( iViewNum, iContent, iCurModel, iModelNum, iBlendMode, iLeftViewNum, iRightViewNum, iOrgRefNum, iDump ) ;
826          m_cRendererModel  .createSingleModel   ( iViewNum, iContent, iModelNum, iLeftViewNum, iRightViewNum, (iOrgRefNum != -1), iBlendMode );
827        }           
828      }
829    }
830    else
831    {
832      AOT(true);
833    }
834  }
835#endif
836}
837
838Void TAppEncTop::xCreateLib()
839{
840#if NH_MV
841  // initialize global variables
842  initROM();
843#if NH_3D_DMM
844  initWedgeLists( true );
845#endif
846
847  for( Int layer=0; layer < m_numberOfLayers; layer++)
848  {
849    m_acTVideoIOYuvInputFileList[layer]->open( m_pchInputFileList[layer],     false, m_inputBitDepth, m_MSBExtendedBitDepth, m_internalBitDepth );  // read  mode
850    m_acTVideoIOYuvInputFileList[layer]->skipFrames( m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1], m_InputChromaFormatIDC);
851
852    if (m_pchReconFileList[layer])
853    {
854      m_acTVideoIOYuvReconFileList[layer]->open( m_pchReconFileList[layer], true, m_outputBitDepth, m_outputBitDepth, m_internalBitDepth);  // write mode
855    }
856    m_acTEncTopList[layer]->create();
857  }
858#else
859  // Video I/O
860  m_cTVideoIOYuvInputFile.open( m_inputFileName,     false, m_inputBitDepth, m_MSBExtendedBitDepth, m_internalBitDepth );  // read  mode
861  m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1], m_InputChromaFormatIDC);
862
863  if (!m_reconFileName.empty())
864  {
865    m_cTVideoIOYuvReconFile.open(m_reconFileName, true, m_outputBitDepth, m_outputBitDepth, m_internalBitDepth);  // write mode
866  }
867
868  // Neo Decoder
869  m_cTEncTop.create();
870#endif
871}
872
873Void TAppEncTop::xDestroyLib()
874{
875#if NH_MV
876  // destroy ROM
877  destroyROM();
878
879  for(Int layer=0; layer<m_numberOfLayers; layer++)
880  {
881    m_acTVideoIOYuvInputFileList[layer]->close();
882    m_acTVideoIOYuvReconFileList[layer]->close();
883    delete m_acTVideoIOYuvInputFileList[layer] ; 
884    m_acTVideoIOYuvInputFileList[layer] = NULL;
885    delete m_acTVideoIOYuvReconFileList[layer] ; 
886    m_acTVideoIOYuvReconFileList[layer] = NULL;
887    m_acTEncTopList[layer]->deletePicBuffer();
888    m_acTEncTopList[layer]->destroy();
889    delete m_acTEncTopList[layer] ; 
890    m_acTEncTopList[layer] = NULL;
891    delete m_cListPicYuvRec[layer] ; 
892    m_cListPicYuvRec[layer] = NULL;
893  }
894#else
895  // Video I/O
896  m_cTVideoIOYuvInputFile.close();
897  m_cTVideoIOYuvReconFile.close();
898
899  // Neo Decoder
900  m_cTEncTop.destroy();
901#endif
902}
903
904Void TAppEncTop::xInitLib(Bool isFieldCoding)
905{
906#if NH_MV
907  for(Int layer=0; layer<m_numberOfLayers; layer++)
908  {
909#if KWU_RC_MADPRED_E0227
910    m_acTEncTopList[layer]->init( isFieldCoding, this );
911#else
912    m_acTEncTopList[layer]->init( isFieldCoding );
913#endif
914  }
915#else
916  m_cTEncTop.init(isFieldCoding);
917#endif
918}
919
920// ====================================================================================================================
921// Public member functions
922// ====================================================================================================================
923
924/**
925 - create internal class
926 - initialize internal variable
927 - until the end of input YUV file, call encoding function in TEncTop class
928 - delete allocated buffers
929 - destroy internal class
930 .
931 */
932Void TAppEncTop::encode()
933{
934  fstream bitstreamFile(m_bitstreamFileName.c_str(), fstream::binary | fstream::out);
935  if (!bitstreamFile)
936  {
937    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_bitstreamFileName.c_str());
938    exit(EXIT_FAILURE);
939  }
940
941#if !NH_3D
942  TComPicYuv*       pcPicYuvOrg = new TComPicYuv;
943#endif
944  TComPicYuv*       pcPicYuvRec = NULL;
945
946  // initialize internal class & member variables
947  xInitLibCfg();
948  xCreateLib();
949  xInitLib(m_isField);
950
951  printChromaFormat();
952
953  // main encoder loop
954#if NH_MV
955  Bool  allEos = false;
956  std::vector<Bool>  eos ;
957  std::vector<Bool>  flush ; 
958 
959  Int gopSize    = 1;
960  Int maxGopSize = 0;
961  maxGopSize = (std::max)(maxGopSize, m_acTEncTopList[0]->getGOPSize()); 
962 
963  for(Int layer=0; layer < m_numberOfLayers; layer++ )
964  {
965    eos  .push_back( false );
966    flush.push_back( false );
967  }
968#else
969  Int   iNumEncoded = 0;
970  Bool  bEos = false;
971#endif
972  const InputColourSpaceConversion ipCSC  =  m_inputColourSpaceConvert;
973  const InputColourSpaceConversion snrCSC = (!m_snrInternalColourSpace) ? m_inputColourSpaceConvert : IPCOLOURSPACE_UNCHANGED;
974
975  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
976 
977#if NH_3D
978  TComPicYuv* picYuvOrg[2]; 
979  TComPicYuv  picYuvTrueOrg[2]; 
980  for (Int d = 0; d < 2 ; d++)
981  {
982    picYuvOrg[d] = new TComPicYuv;
983    picYuvOrg[d]   ->create( m_iSourceWidth, m_isField ? m_iSourceHeightOrg : m_iSourceHeight, ( d > 0 ) ? CHROMA_400 : m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true );
984    picYuvTrueOrg[d].create( m_iSourceWidth, m_isField ? m_iSourceHeightOrg : m_iSourceHeight, ( d > 0 ) ? CHROMA_400 : m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true );
985  }
986#else
987  TComPicYuv cPicYuvTrueOrg;
988
989  // allocate original YUV buffer
990  if( m_isField )
991  {
992    pcPicYuvOrg->create  ( m_iSourceWidth, m_iSourceHeightOrg, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true );
993    cPicYuvTrueOrg.create(m_iSourceWidth, m_iSourceHeightOrg, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true);
994  }
995  else
996  {
997    pcPicYuvOrg->create  ( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true );
998    cPicYuvTrueOrg.create(m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true );
999  }
1000#endif
1001#if NH_MV
1002  while ( (m_targetEncLayerIdList.size() != 0 ) && !allEos )
1003  {
1004    for(Int layer=0; layer < m_numberOfLayers; layer++ )
1005    {
1006#if NH_3D
1007      TComPicYuv* pcPicYuvOrg    =  picYuvOrg    [ m_depthFlag[layer] ];
1008      TComPicYuv& cPicYuvTrueOrg =  picYuvTrueOrg[ m_depthFlag[layer] ];
1009#endif
1010      if (!xLayerIdInTargetEncLayerIdList( m_vps->getLayerIdInNuh( layer ) ))
1011      {
1012        continue; 
1013      }
1014
1015      Int frmCnt = 0;
1016      while ( !eos[layer] && !(frmCnt == gopSize))
1017      {
1018        // get buffers
1019        xGetBuffer(pcPicYuvRec, layer);
1020
1021        // read input YUV file       
1022        m_acTVideoIOYuvInputFileList[layer]->read      ( pcPicYuvOrg, &cPicYuvTrueOrg, ipCSC, m_aiPad, m_InputChromaFormatIDC );
1023        m_acTEncTopList             [layer]->initNewPic( pcPicYuvOrg );
1024
1025        // increase number of received frames
1026        m_frameRcvd[layer]++;
1027       
1028        frmCnt++;
1029
1030        eos[layer] = (m_frameRcvd[layer] == m_framesToBeEncoded);
1031        allEos = allEos||eos[layer];
1032
1033        // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
1034        if (m_acTVideoIOYuvInputFileList[layer]->isEof())
1035        {
1036          flush          [layer] = true;
1037          eos            [layer] = true;
1038          m_frameRcvd    [layer]--;
1039          m_acTEncTopList[layer]->setFramesToBeEncoded(m_frameRcvd[layer]);
1040        }
1041      }
1042    }
1043    for ( Int gopId=0; gopId < gopSize; gopId++ )
1044    {
1045#if NH_3D
1046      UInt iNextPoc = m_acTEncTopList[0] -> getFrameId( gopId );
1047      if ( iNextPoc < m_framesToBeEncoded )
1048      {
1049        m_cCameraData.update( iNextPoc );
1050      }
1051#endif
1052      for(Int layer=0; layer < m_numberOfLayers; layer++ )
1053      {
1054#if NH_3D
1055        TComPicYuv* pcPicYuvOrg    =  picYuvOrg    [ m_depthFlag[layer] ];
1056        TComPicYuv& cPicYuvTrueOrg =  picYuvTrueOrg[ m_depthFlag[layer] ];
1057#endif
1058        if (!xLayerIdInTargetEncLayerIdList( m_vps->getLayerIdInNuh( layer ) ))
1059        {
1060          continue; 
1061        }
1062
1063#if NH_3D_VSO       
1064          if( m_bUseVSO && m_bUseEstimatedVSD && iNextPoc < m_framesToBeEncoded )
1065          {
1066            m_cCameraData.setDispCoeff( iNextPoc, m_acTEncTopList[layer]->getViewIndex() );
1067            m_acTEncTopList[layer]  ->setDispCoeff( m_cCameraData.getDispCoeff() );
1068          }
1069#endif
1070
1071        Int   iNumEncoded = 0;
1072
1073        // call encoding function for one frame                               
1074        m_acTEncTopList[layer]->encode( eos[layer], flush[layer] ? 0 : pcPicYuvOrg, flush[layer] ? 0 : &cPicYuvTrueOrg, snrCSC, *m_cListPicYuvRec[layer], outputAccessUnits, iNumEncoded, gopId );       
1075        xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits, layer);
1076        outputAccessUnits.clear();
1077      }
1078    }
1079
1080    gopSize = maxGopSize;
1081  }
1082  for(Int layer=0; layer < m_numberOfLayers; layer++ )
1083  {
1084    if (!xLayerIdInTargetEncLayerIdList( m_vps->getLayerIdInNuh( layer ) ))
1085    {
1086      continue; 
1087    }   
1088    m_acTEncTopList[layer]->printSummary(m_isField);
1089  }
1090#else
1091
1092  while ( !bEos )
1093  {
1094    // get buffers
1095    xGetBuffer(pcPicYuvRec);
1096
1097    // read input YUV file
1098    m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, &cPicYuvTrueOrg, ipCSC, m_aiPad, m_InputChromaFormatIDC, m_bClipInputVideoToRec709Range );
1099
1100    // increase number of received frames
1101    m_iFrameRcvd++;
1102
1103    bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) );
1104
1105    Bool flush = 0;
1106    // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
1107    if (m_cTVideoIOYuvInputFile.isEof())
1108    {
1109      flush = true;
1110      bEos = true;
1111      m_iFrameRcvd--;
1112      m_cTEncTop.setFramesToBeEncoded(m_iFrameRcvd);
1113    }
1114
1115    // call encoding function for one frame
1116    if ( m_isField )
1117    {
1118      m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, flush ? 0 : &cPicYuvTrueOrg, snrCSC, m_cListPicYuvRec, outputAccessUnits, iNumEncoded, m_isTopFieldFirst );
1119    }
1120    else
1121    {
1122      m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, flush ? 0 : &cPicYuvTrueOrg, snrCSC, m_cListPicYuvRec, outputAccessUnits, iNumEncoded );
1123    }
1124
1125    // write bistream to file if necessary
1126    if ( iNumEncoded > 0 )
1127    {
1128      xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits);
1129      outputAccessUnits.clear();
1130    }
1131  }
1132
1133  m_cTEncTop.printSummary(m_isField);
1134#endif
1135
1136#if NH_3D
1137  // delete original YUV buffer
1138  for (Int d = 0; d < 2; d++)
1139  {
1140    picYuvOrg[d]->destroy();
1141    delete picYuvOrg[d];
1142    picYuvOrg[d] = NULL;
1143
1144    picYuvTrueOrg[d].destroy();
1145  }
1146#else
1147  // delete original YUV buffer
1148  pcPicYuvOrg->destroy();
1149  delete pcPicYuvOrg;
1150  pcPicYuvOrg = NULL;
1151#endif
1152
1153#if !NH_MV
1154  // delete used buffers in encoder class
1155  m_cTEncTop.deletePicBuffer();
1156#endif
1157#if !NH_3D
1158  cPicYuvTrueOrg.destroy();
1159#endif
1160
1161  // delete buffers & classes
1162  xDeleteBuffer();
1163  xDestroyLib();
1164
1165  printRateSummary();
1166
1167#if H_3D_REN_MAX_DEV_OUT
1168  Double dMaxDispDiff = m_cCameraData.getMaxShiftDeviation(); 
1169
1170  if ( !(dMaxDispDiff < 0) )
1171  { 
1172    printf("\n Max. possible shift error: %12.3f samples.\n", dMaxDispDiff );
1173  }
1174#endif
1175
1176  return;
1177}
1178
1179// ====================================================================================================================
1180// Protected member functions
1181// ====================================================================================================================
1182
1183/**
1184 - application has picture buffer list with size of GOP
1185 - picture buffer list acts as ring buffer
1186 - end of the list has the latest picture
1187 .
1188 */
1189#if NH_MV
1190Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer)
1191#else
1192Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec)
1193#endif
1194{
1195  assert( m_iGOPSize > 0 );
1196
1197  // org. buffer
1198#if NH_MV
1199  if ( m_cListPicYuvRec[layer]->size() == (UInt)m_iGOPSize )
1200  {
1201    rpcPicYuvRec = m_cListPicYuvRec[layer]->popFront();
1202#else
1203  if ( m_cListPicYuvRec.size() >= (UInt)m_iGOPSize ) // buffer will be 1 element longer when using field coding, to maintain first field whilst processing second.
1204  {
1205    rpcPicYuvRec = m_cListPicYuvRec.popFront();
1206#endif
1207  }
1208  else
1209  {
1210    rpcPicYuvRec = new TComPicYuv;
1211#if NH_3D
1212    rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_depthFlag[layer] > 0 ? CHROMA_400 : m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true );
1213#else
1214    rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true );
1215#endif
1216
1217  }
1218#if NH_MV
1219  m_cListPicYuvRec[layer]->pushBack( rpcPicYuvRec );
1220#else
1221  m_cListPicYuvRec.pushBack( rpcPicYuvRec );
1222#endif
1223}
1224
1225Void TAppEncTop::xDeleteBuffer( )
1226{
1227#if NH_MV
1228  for(Int layer=0; layer<m_cListPicYuvRec.size(); layer++)
1229  {
1230    if(m_cListPicYuvRec[layer])
1231    {
1232      TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvRec[layer]->begin();
1233      Int iSize = Int( m_cListPicYuvRec[layer]->size() );
1234#else
1235  TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvRec.begin();
1236
1237  Int iSize = Int( m_cListPicYuvRec.size() );
1238#endif
1239
1240  for ( Int i = 0; i < iSize; i++ )
1241  {
1242    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1243    pcPicYuvRec->destroy();
1244    delete pcPicYuvRec; pcPicYuvRec = NULL;
1245  }
1246#if NH_MV
1247}
1248  }
1249#endif 
1250
1251}
1252
1253/**
1254  Write access units to output file.
1255  \param bitstreamFile  target bitstream file
1256  \param iNumEncoded    number of encoded frames
1257  \param accessUnits    list of access units to be written
1258 */
1259#if NH_MV
1260Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, std::list<AccessUnit>& accessUnits, UInt layerIdx)
1261#else
1262Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
1263#endif
1264{
1265  const InputColourSpaceConversion ipCSC = (!m_outputInternalColourSpace) ? m_inputColourSpaceConvert : IPCOLOURSPACE_UNCHANGED;
1266
1267  if (m_isField)
1268  {
1269    //Reinterlace fields
1270    Int i;
1271#if NH_MV
1272    if( iNumEncoded > 0 )
1273    {
1274      TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec[layerIdx]->end();
1275#else
1276    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
1277    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
1278#endif
1279
1280    for ( i = 0; i < iNumEncoded; i++ )
1281    {
1282      --iterPicYuvRec;
1283    }
1284
1285    for ( i = 0; i < iNumEncoded/2; i++ )
1286    {
1287      TComPicYuv*  pcPicYuvRecTop  = *(iterPicYuvRec++);
1288      TComPicYuv*  pcPicYuvRecBottom  = *(iterPicYuvRec++);
1289
1290#if NH_MV
1291      if (m_pchReconFileList[layerIdx])
1292      {
1293#if NH_3D
1294        m_acTVideoIOYuvReconFileList[layerIdx]->write( pcPicYuvRecTop, pcPicYuvRecBottom, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, m_depth420OutputFlag && m_depthFlag[layerIdx ] ? CHROMA_420 : NUM_CHROMA_FORMAT, m_isTopFieldFirst );
1295#else
1296        m_acTVideoIOYuvReconFileList[layerIdx]->write( pcPicYuvRecTop, pcPicYuvRecBottom, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, NUM_CHROMA_FORMAT, m_isTopFieldFirst );
1297#endif
1298      }
1299    }
1300  }
1301
1302  if( ! accessUnits.empty() )
1303  {
1304    list<AccessUnit>::iterator aUIter;
1305    for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ )
1306    {
1307      const vector<UInt>& stats = writeAnnexB(bitstreamFile, *aUIter);
1308      rateStatsAccum(*aUIter, stats);
1309    }
1310  }
1311#else
1312      if (!m_reconFileName.empty())
1313      {
1314        m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, NUM_CHROMA_FORMAT, m_isTopFieldFirst );
1315      }
1316
1317      const AccessUnit& auTop = *(iterBitstream++);
1318      const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
1319      rateStatsAccum(auTop, statsTop);
1320
1321      const AccessUnit& auBottom = *(iterBitstream++);
1322      const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom);
1323      rateStatsAccum(auBottom, statsBottom);
1324    }
1325#endif
1326  }
1327  else
1328  {
1329    Int i;
1330#if NH_MV
1331    if( iNumEncoded > 0 )
1332    {
1333      TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec[layerIdx]->end();
1334#else
1335    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
1336    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
1337#endif
1338
1339    for ( i = 0; i < iNumEncoded; i++ )
1340    {
1341      --iterPicYuvRec;
1342    }
1343
1344    for ( i = 0; i < iNumEncoded; i++ )
1345    {
1346      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1347#if NH_MV
1348      if (m_pchReconFileList[layerIdx])
1349      {
1350#if NH_3D
1351        m_acTVideoIOYuvReconFileList[layerIdx]->write( pcPicYuvRec, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, m_depth420OutputFlag && m_depthFlag[layerIdx ] ? CHROMA_420 : NUM_CHROMA_FORMAT  );
1352#else
1353        m_acTVideoIOYuvReconFileList[layerIdx]->write( pcPicYuvRec, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom );
1354#endif
1355
1356      }   
1357    }
1358  }
1359  if( ! accessUnits.empty() )
1360  {
1361    list<AccessUnit>::iterator aUIter;
1362    for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ )
1363    {
1364      const vector<unsigned>& stats = writeAnnexB(bitstreamFile, *aUIter);
1365      rateStatsAccum(*aUIter, stats);
1366    }
1367  }
1368#else
1369      if (!m_reconFileName.empty())
1370      {
1371        m_cTVideoIOYuvReconFile.write( pcPicYuvRec, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom,
1372            NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range  );
1373      }
1374
1375      const AccessUnit& au = *(iterBitstream++);
1376      const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
1377      rateStatsAccum(au, stats);
1378    }
1379#endif
1380  }
1381}
1382
1383/**
1384 *
1385 */
1386Void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& annexBsizes)
1387{
1388  AccessUnit::const_iterator it_au = au.begin();
1389  vector<UInt>::const_iterator it_stats = annexBsizes.begin();
1390
1391  for (; it_au != au.end(); it_au++, it_stats++)
1392  {
1393    switch ((*it_au)->m_nalUnitType)
1394    {
1395    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1396    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1397    case NAL_UNIT_CODED_SLICE_TSA_R:
1398    case NAL_UNIT_CODED_SLICE_TSA_N:
1399    case NAL_UNIT_CODED_SLICE_STSA_R:
1400    case NAL_UNIT_CODED_SLICE_STSA_N:
1401    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1402    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1403    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1404    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1405    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1406    case NAL_UNIT_CODED_SLICE_CRA:
1407    case NAL_UNIT_CODED_SLICE_RADL_N:
1408    case NAL_UNIT_CODED_SLICE_RADL_R:
1409    case NAL_UNIT_CODED_SLICE_RASL_N:
1410    case NAL_UNIT_CODED_SLICE_RASL_R:
1411    case NAL_UNIT_VPS:
1412    case NAL_UNIT_SPS:
1413    case NAL_UNIT_PPS:
1414      m_essentialBytes += *it_stats;
1415      break;
1416    default:
1417      break;
1418    }
1419
1420    m_totalBytes += *it_stats;
1421  }
1422}
1423
1424Void TAppEncTop::printRateSummary()
1425{
1426#if NH_MV
1427  Double time = (Double) m_frameRcvd[0] / m_iFrameRate;
1428  printf("\n");
1429#else
1430  Double time = (Double) m_iFrameRcvd / m_iFrameRate;
1431#endif
1432  printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time);
1433  if (m_summaryVerboseness > 0)
1434  {
1435  printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time);
1436  }
1437}
1438
1439Void TAppEncTop::printChromaFormat()
1440{
1441  std::cout << std::setw(43) << "Input ChromaFormatIDC = ";
1442  switch (m_InputChromaFormatIDC)
1443  {
1444  case CHROMA_400:  std::cout << "  4:0:0"; break;
1445  case CHROMA_420:  std::cout << "  4:2:0"; break;
1446  case CHROMA_422:  std::cout << "  4:2:2"; break;
1447  case CHROMA_444:  std::cout << "  4:4:4"; break;
1448  default:
1449    std::cerr << "Invalid";
1450    exit(1);
1451  }
1452  std::cout << std::endl;
1453
1454#if NH_MV
1455  for (Int i = 0; i < m_numberOfLayers; i++)
1456  {
1457    std::cout << "Layer " << i << std::setw( 43 - (i > 9 ? 6 : 7) ) << "Internal ChromaFormatIDC = ";
1458    switch (m_acTEncTopList[i]->getChromaFormatIdc())
1459#else
1460    std::cout << std::setw(43) << "Output (internal) ChromaFormatIDC = ";
1461    switch (m_cTEncTop.getChromaFormatIdc())
1462#endif
1463    {
1464    case CHROMA_400:  std::cout << "  4:0:0"; break;
1465    case CHROMA_420:  std::cout << "  4:2:0"; break;
1466    case CHROMA_422:  std::cout << "  4:2:2"; break;
1467    case CHROMA_444:  std::cout << "  4:4:4"; break;
1468    default:
1469      std::cerr << "Invalid";
1470      exit(1);
1471    }
1472#if NH_MV
1473    std::cout << std::endl;
1474  }
1475#endif
1476  std::cout << "\n" << std::endl;
1477}
1478
1479#if NH_3D_DLT
1480Void TAppEncTop::xAnalyzeInputBaseDepth(UInt layer, UInt uiNumFrames, TComVPS* vps, TComDLT* dlt)
1481{
1482  TComPicYuv*       pcDepthPicYuvOrg = new TComPicYuv;
1483  TComPicYuv*       pcDepthPicYuvTrueOrg = new TComPicYuv;
1484  // allocate original YUV buffer
1485  pcDepthPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, CHROMA_420, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, false );
1486  pcDepthPicYuvTrueOrg->create( m_iSourceWidth, m_iSourceHeight, CHROMA_420, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, false );
1487 
1488  TVideoIOYuv* depthVideoFile = new TVideoIOYuv;
1489 
1490  UInt uiMaxDepthValue = ((1 << m_inputBitDepth[CHANNEL_TYPE_LUMA])-1);
1491 
1492  std::vector<Bool> abValidDepths(256, false);
1493 
1494  depthVideoFile->open( m_pchInputFileList[layer], false, m_inputBitDepth, m_MSBExtendedBitDepth, m_internalBitDepth );
1495 
1496  Int iHeight   = pcDepthPicYuvOrg->getHeight(COMPONENT_Y);
1497  Int iWidth    = pcDepthPicYuvOrg->getWidth(COMPONENT_Y);
1498  Int iStride   = pcDepthPicYuvOrg->getStride(COMPONENT_Y);
1499 
1500  Pel* pInDM    = pcDepthPicYuvOrg->getAddr(COMPONENT_Y);
1501 
1502  for(Int uiFrame=0; uiFrame < uiNumFrames; uiFrame++ )
1503  {
1504    depthVideoFile->read( pcDepthPicYuvOrg, pcDepthPicYuvTrueOrg, IPCOLOURSPACE_UNCHANGED, m_aiPad, m_InputChromaFormatIDC, m_bClipInputVideoToRec709Range );
1505   
1506    // check all pixel values
1507    for (Int i=0; i<iHeight; i++)
1508    {
1509      Int rowOffset = i*iStride;
1510     
1511      for (Int j=0; j<iWidth; j++)
1512      {
1513        Pel depthValue = pInDM[rowOffset+j];
1514        abValidDepths[depthValue] = true;
1515      }
1516    }
1517  }
1518 
1519  depthVideoFile->close();
1520  delete depthVideoFile; 
1521 
1522  pcDepthPicYuvOrg->destroy();
1523  delete pcDepthPicYuvOrg;
1524  pcDepthPicYuvTrueOrg->destroy();
1525  delete pcDepthPicYuvTrueOrg;
1526 
1527  // convert boolean array to idx2Depth LUT
1528  std::vector<Int> aiIdx2DepthValue(256, 0);
1529  Int iNumDepthValues = 0;
1530  for(Int p=0; p<=uiMaxDepthValue; p++)
1531  {
1532    if( abValidDepths[p] == true)
1533    {
1534      aiIdx2DepthValue[iNumDepthValues++] = p;
1535    }
1536  }
1537 
1538  if( uiNumFrames == 0 || gCeilLog2(iNumDepthValues) == m_inputBitDepth[CHANNEL_TYPE_LUMA] )
1539  {
1540    dlt->setUseDLTFlag(layer, false);
1541  }
1542 
1543  // assign LUT
1544  if( dlt->getUseDLTFlag(layer) )
1545  {
1546    dlt->setDepthLUTs(layer, aiIdx2DepthValue, iNumDepthValues);
1547  }
1548}
1549#endif
1550
1551#if NH_MV
1552Void TAppEncTop::xSetDimensionIdAndLength( TComVPS& vps )
1553{   
1554  vps.setScalabilityMaskFlag( m_scalabilityMask ); 
1555  for( Int dim = 0; dim < m_dimIds.size(); dim++ )
1556  {
1557    vps.setDimensionIdLen( dim, m_dimensionIdLen[ dim ] );
1558    for( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ )
1559    {       
1560      vps.setDimensionId( layer, dim, m_dimIds[ dim ][ layer ] );       
1561    } 
1562  }
1563
1564  vps.initNumViews(); 
1565  Int maxViewId = xGetMax( m_viewId ); 
1566
1567  Int viewIdLen = gCeilLog2( maxViewId + 1 ); 
1568  const Int maxViewIdLen = ( 1 << 4 ) - 1; 
1569  assert( viewIdLen <= maxViewIdLen ); 
1570  vps.setViewIdLen( viewIdLen ); 
1571  for (Int i = 0; i < m_iNumberOfViews; i++)
1572  {
1573    vps.setViewIdVal( i, m_viewId[ i] ); 
1574  }
1575
1576  assert( m_iNumberOfViews == vps.getNumViews() ); 
1577
1578
1579#if NH_3D
1580  vps.initViewCompLayer( ); 
1581#endif
1582}
1583
1584Void TAppEncTop::xSetDependencies( TComVPS& vps )
1585{
1586  // Direct dependency flags + dependency types
1587  for( Int depLayer = 1; depLayer < MAX_NUM_LAYERS; depLayer++ )
1588  {
1589    for( Int refLayer = 0; refLayer < MAX_NUM_LAYERS; refLayer++ )
1590    {
1591      vps.setDirectDependencyFlag( depLayer, refLayer, false); 
1592      vps.setDirectDependencyType( depLayer, refLayer,    -1 ); 
1593    }
1594  }
1595
1596  Int  defaultDirectDependencyType = -1; 
1597  Bool defaultDirectDependencyFlag = false; 
1598
1599  Int directDepTypeLenMinus2 = 0; 
1600  for( Int depLayer = 1; depLayer < m_numberOfLayers; depLayer++ )
1601  {
1602    Int numRefLayers = (Int) m_directRefLayers[depLayer].size(); 
1603    assert(  numRefLayers == (Int) m_dependencyTypes[depLayer].size() ); 
1604    for( Int i = 0; i < numRefLayers; i++ )
1605    {
1606      Int refLayer = m_directRefLayers[depLayer][i]; 
1607      vps.setDirectDependencyFlag( depLayer, refLayer, true); 
1608      Int curDirectDependencyType = m_dependencyTypes[depLayer][i]; 
1609      directDepTypeLenMinus2 = std::max( directDepTypeLenMinus2, gCeilLog2( curDirectDependencyType + 1  ) - 2 ); 
1610      if ( defaultDirectDependencyType != -1 )   
1611      {
1612        defaultDirectDependencyFlag = defaultDirectDependencyFlag && (curDirectDependencyType == defaultDirectDependencyType );         
1613      }
1614      else
1615      {
1616        defaultDirectDependencyType = curDirectDependencyType; 
1617        defaultDirectDependencyFlag = true; 
1618      }
1619     
1620      vps.setDirectDependencyType( depLayer, refLayer, curDirectDependencyType);       
1621    }
1622  }
1623
1624  vps.setDefaultDirectDependencyFlag( defaultDirectDependencyFlag );       
1625  vps.setDefaultDirectDependencyType( defaultDirectDependencyFlag ? defaultDirectDependencyType : -1 );       
1626
1627  assert( directDepTypeLenMinus2 <= 1 ); 
1628  vps.setDirectDepTypeLenMinus2( directDepTypeLenMinus2 ); 
1629
1630
1631  vps.setRefLayers(); 
1632
1633  // Max sub layers, + presence flag
1634  Bool subLayersMaxMinus1PresentFlag = false; 
1635  for (Int curLayerIdInVps = 0; curLayerIdInVps < m_numberOfLayers; curLayerIdInVps++ )
1636  {   
1637    Int curSubLayersMaxMinus1 = 0; 
1638    for( Int i = 0; i < getGOPSize(); i++ ) 
1639    {
1640      GOPEntry geCur =  m_GOPListMvc[curLayerIdInVps][i];
1641      curSubLayersMaxMinus1 = std::max( curSubLayersMaxMinus1, geCur.m_temporalId ); 
1642    } 
1643
1644    vps.setSubLayersVpsMaxMinus1( curLayerIdInVps, curSubLayersMaxMinus1 ); 
1645    subLayersMaxMinus1PresentFlag = subLayersMaxMinus1PresentFlag || ( curSubLayersMaxMinus1 != vps.getMaxSubLayersMinus1() );
1646  }
1647
1648  vps.setVpsSubLayersMaxMinus1PresentFlag( subLayersMaxMinus1PresentFlag ); 
1649
1650  // Max temporal id for inter layer reference pictures
1651  for ( Int refLayerIdInVps = 0; refLayerIdInVps < m_numberOfLayers; refLayerIdInVps++)
1652  {
1653    Int refLayerIdInNuh = vps.getLayerIdInNuh( refLayerIdInVps );
1654    for ( Int curLayerIdInVps = 1; curLayerIdInVps < m_numberOfLayers; curLayerIdInVps++)
1655    {
1656      Int curLayerIdInNuh = vps.getLayerIdInNuh( curLayerIdInVps );     
1657      Int maxTid = -1; 
1658#if NH_3D
1659      if ( vps.getDirectDependencyFlag( curLayerIdInVps, refLayerIdInVps ) )
1660      {
1661        if ( m_depthFlag[ curLayerIdInVps] == m_depthFlag[ refLayerIdInVps ] )
1662        {
1663#endif
1664          for( Int i = 0; i < ( getGOPSize() + 1); i++ ) 
1665          {       
1666            GOPEntry geCur =  m_GOPListMvc[curLayerIdInVps][( i < getGOPSize()  ? i : MAX_GOP )];
1667            GOPEntry geRef =  m_GOPListMvc[refLayerIdInVps][( i < getGOPSize()  ? i : MAX_GOP )];
1668            for (Int j = 0; j < geCur.m_numActiveRefLayerPics; j++)
1669            {
1670#if NH_3D
1671              if ( vps.getIdRefListLayer( curLayerIdInNuh, geCur.m_interLayerPredLayerIdc[ j ] ) == refLayerIdInNuh )
1672#else
1673              if ( vps.getIdDirectRefLayer( curLayerIdInNuh, geCur.m_interLayerPredLayerIdc[ j ] ) == refLayerIdInNuh )
1674#endif
1675              {
1676                Bool refLayerZero   = ( i == getGOPSize() ) && ( refLayerIdInVps == 0 );
1677                maxTid = std::max( maxTid, refLayerZero ? 0 : geRef.m_temporalId ); 
1678              }
1679            }
1680          }             
1681#if NH_3D
1682        }
1683        else
1684        {       
1685          if( m_depthFlag[ curLayerIdInVps ] && ( m_mpiFlag|| m_qtPredFlag || m_intraContourFlag ) ) 
1686          {         
1687            Int nuhLayerIdTex = vps.getLayerIdInNuh( vps.getViewIndex( curLayerIdInNuh ), false ); 
1688            if ( nuhLayerIdTex == refLayerIdInNuh )
1689            {
1690              for( Int i = 0; i < ( getGOPSize() + 1); i++ ) 
1691              {       
1692                GOPEntry geCur =  m_GOPListMvc[curLayerIdInVps][( i < getGOPSize()  ? i : MAX_GOP )];
1693                GOPEntry geRef =  m_GOPListMvc[refLayerIdInVps][( i < getGOPSize()  ? i : MAX_GOP )];
1694                if ( geCur.m_interCompPredFlag )
1695                {
1696                  Bool refLayerZero   = ( i == getGOPSize() ) && ( refLayerIdInVps == 0 );
1697                  maxTid = std::max( maxTid, refLayerZero ? 0 : geRef.m_temporalId ); 
1698                }
1699              }
1700            }
1701          }
1702          if( !m_depthFlag[ curLayerIdInVps ] && vps.getNumRefListLayers( curLayerIdInNuh) > 0  && ( m_depthRefinementFlag || m_viewSynthesisPredFlag || m_depthBasedBlkPartFlag ) ) 
1703          {             
1704            for( Int i = 0; i < ( getGOPSize() + 1); i++ ) 
1705            {       
1706              GOPEntry geCur =  m_GOPListMvc[curLayerIdInVps][( i < getGOPSize()  ? i : MAX_GOP )];
1707              GOPEntry geRef =  m_GOPListMvc[refLayerIdInVps][( i < getGOPSize()  ? i : MAX_GOP )];
1708
1709              if ( geCur.m_interCompPredFlag )
1710              {
1711                for (Int j = 0; j < geCur.m_numActiveRefLayerPics; j++ )
1712                {
1713                  Int nuhLayerIdDep = vps.getLayerIdInNuh( vps.getViewIndex( vps.getIdRefListLayer( curLayerIdInNuh, geCur.m_interLayerPredLayerIdc[j] ) ), true ); 
1714                  if ( nuhLayerIdDep == refLayerIdInNuh )
1715                  {
1716                    Bool refLayerZero   = ( i == getGOPSize() ) && ( refLayerIdInVps == 0 );
1717                    maxTid = std::max( maxTid, refLayerZero ? 0 : geRef.m_temporalId ); 
1718                  }
1719                }
1720              }
1721            }
1722          }       
1723        }
1724      } // if ( vps.getDirectDependencyFlag( curLayerIdInVps, refLayerIdInVps ) )
1725      vps.setMaxTidIlRefPicsPlus1( refLayerIdInVps, curLayerIdInVps, maxTid + 1 );
1726#endif
1727    }  // Loop curLayerIdInVps
1728  } // Loop refLayerIdInVps
1729
1730  // Max temporal id for inter layer reference pictures presence flag
1731  Bool maxTidRefPresentFlag = false;   
1732  for ( Int refLayerIdInVps = 0; refLayerIdInVps < m_numberOfLayers; refLayerIdInVps++)
1733  {
1734    for ( Int curLayerIdInVps = 1; curLayerIdInVps < m_numberOfLayers; curLayerIdInVps++)
1735    {
1736        maxTidRefPresentFlag = maxTidRefPresentFlag || ( vps.getMaxTidIlRefPicsPlus1( refLayerIdInVps, curLayerIdInVps ) != 7 );   
1737    }
1738  }
1739  vps.setMaxTidRefPresentFlag( maxTidRefPresentFlag );
1740
1741
1742  // Max one active ref layer flag
1743  Bool maxOneActiveRefLayerFlag = true; 
1744  for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && maxOneActiveRefLayerFlag; layerIdInVps++)
1745  {
1746    for( Int i = 0; i < ( getGOPSize() + 1) && maxOneActiveRefLayerFlag; i++ ) 
1747    {       
1748      GOPEntry ge =  m_GOPListMvc[layerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]; 
1749      maxOneActiveRefLayerFlag =  maxOneActiveRefLayerFlag && (ge.m_numActiveRefLayerPics <= 1); 
1750    }           
1751  }
1752
1753  vps.setMaxOneActiveRefLayerFlag( maxOneActiveRefLayerFlag );
1754 
1755  // Poc Lsb Not Present Flag
1756  for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers; layerIdInVps++)
1757  {
1758    if ( m_directRefLayers[ layerIdInVps ].size() == 0 ) 
1759    {   
1760      vps.setPocLsbNotPresentFlag( layerIdInVps,  true ); 
1761    }
1762  } 
1763 
1764  // All Ref layers active flag
1765  Bool allRefLayersActiveFlag = true; 
1766  for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && allRefLayersActiveFlag; layerIdInVps++)
1767  {   
1768    Int layerIdInNuh = vps.getLayerIdInNuh( layerIdInVps ); 
1769    for( Int i = 0; i < ( getGOPSize() + 1) && allRefLayersActiveFlag; i++ ) 
1770    {       
1771      GOPEntry ge =  m_GOPListMvc[layerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]; 
1772      Int tId = ge.m_temporalId;  // Should be equal for all layers.
1773     
1774      // check if all reference layers when allRefLayerActiveFlag is equal to 1 are reference layer pictures specified in the gop entry
1775#if NH_3D
1776      for (Int k = 0; k < vps.getNumRefListLayers( layerIdInNuh ) && allRefLayersActiveFlag; k++ )
1777      {
1778        Int refLayerIdInVps = vps.getLayerIdInVps( vps.getIdRefListLayer( layerIdInNuh , k ) ); 
1779#else
1780      for (Int k = 0; k < vps.getNumDirectRefLayers( layerIdInNuh ) && allRefLayersActiveFlag; k++ )
1781      {
1782        Int refLayerIdInVps = vps.getLayerIdInVps( vps.getIdDirectRefLayer( layerIdInNuh , k ) ); 
1783#endif
1784        if ( vps.getSubLayersVpsMaxMinus1(refLayerIdInVps) >= tId  && ( tId == 0 || vps.getMaxTidIlRefPicsPlus1(refLayerIdInVps,layerIdInVps) > tId )  )
1785        {
1786          Bool gopEntryFoundFlag = false; 
1787          for( Int l = 0; l < ge.m_numActiveRefLayerPics && !gopEntryFoundFlag; l++ )
1788          {
1789            gopEntryFoundFlag = gopEntryFoundFlag || ( ge.m_interLayerPredLayerIdc[l] == k ); 
1790          }         
1791          allRefLayersActiveFlag = allRefLayersActiveFlag && gopEntryFoundFlag; 
1792        }       
1793      }
1794
1795      // check if all inter layer reference pictures specified in the gop entry are valid reference layer pictures when allRefLayerActiveFlag is equal to 1
1796      // (Should actually always be true)
1797      Bool maxTidIlRefAndSubLayerMaxValidFlag = true; 
1798      for( Int l = 0; l < ge.m_numActiveRefLayerPics; l++ )
1799      {   
1800        Bool referenceLayerFoundFlag = false; 
1801#if NH_3D
1802        for (Int k = 0; k < vps.getNumRefListLayers( layerIdInNuh ); k++ )
1803        {
1804          Int refLayerIdInVps = vps.getLayerIdInVps( vps.getIdRefListLayer( layerIdInNuh, k) );
1805#else
1806        for (Int k = 0; k < vps.getNumDirectRefLayers( layerIdInNuh ); k++ )
1807        {
1808          Int refLayerIdInVps = vps.getLayerIdInVps( vps.getIdDirectRefLayer( layerIdInNuh, k) );
1809#endif
1810          if ( vps.getSubLayersVpsMaxMinus1(refLayerIdInVps) >= tId  && ( tId == 0 || vps.getMaxTidIlRefPicsPlus1(refLayerIdInVps,layerIdInVps) > tId )  )
1811          {         
1812            referenceLayerFoundFlag = referenceLayerFoundFlag || ( ge.m_interLayerPredLayerIdc[l] == k ); 
1813          }         
1814        }
1815       maxTidIlRefAndSubLayerMaxValidFlag = maxTidIlRefAndSubLayerMaxValidFlag && referenceLayerFoundFlag; 
1816      }
1817      assert ( maxTidIlRefAndSubLayerMaxValidFlag ); // Something wrong with MaxTidIlRefPicsPlus1 or SubLayersVpsMaxMinus1
1818    }           
1819  }
1820
1821  vps.setAllRefLayersActiveFlag( allRefLayersActiveFlag );
1822}; 
1823
1824
1825GOPEntry* TAppEncTop::xGetGopEntry( Int layerIdInVps, Int poc )
1826{
1827  GOPEntry* geFound = NULL; 
1828  for( Int i = 0; i < ( getGOPSize() + 1) && geFound == NULL ; i++ ) 
1829  {
1830    GOPEntry* ge = &(m_GOPListMvc[layerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]);
1831    if ( ge->m_POC == poc )
1832    {
1833      geFound = ge;       
1834    }
1835  }
1836  assert( geFound != NULL ); 
1837  return geFound; 
1838}
1839
1840
1841Void TAppEncTop::xSetTimingInfo( TComVPS& vps )
1842{
1843  vps.getTimingInfo()->setTimingInfoPresentFlag( false );
1844}
1845
1846Void TAppEncTop::xSetHrdParameters( TComVPS& vps )
1847{
1848  vps.createHrdParamBuffer();
1849  for( Int i = 0; i < vps.getNumHrdParameters(); i++ )
1850  {
1851    vps.setHrdOpSetIdx( 0, i );
1852    vps.setCprmsPresentFlag( false, i );
1853  }
1854}
1855
1856Void TAppEncTop::xSetLayerIds( TComVPS& vps )
1857{
1858  vps.setSplittingFlag     ( m_splittingFlag );
1859
1860  Bool nuhLayerIdPresentFlag = false; 
1861 
1862
1863  vps.setVpsMaxLayerId( xGetMax( m_layerIdInNuh ) ); 
1864
1865  for (Int i = 0; i < m_numberOfLayers; i++)
1866  {
1867    nuhLayerIdPresentFlag = nuhLayerIdPresentFlag || ( m_layerIdInNuh[i] != i ); 
1868  }
1869
1870  vps.setVpsNuhLayerIdPresentFlag( nuhLayerIdPresentFlag ); 
1871
1872  for (Int layer = 0; layer < m_numberOfLayers; layer++ )
1873  {
1874    vps.setLayerIdInNuh( layer, nuhLayerIdPresentFlag ? m_layerIdInNuh[ layer ] : layer ); 
1875    vps.setLayerIdInVps( vps.getLayerIdInNuh( layer ), layer ); 
1876  }
1877}
1878
1879Int TAppEncTop::xGetMax( std::vector<Int>& vec )
1880{
1881  Int maxVec = 0; 
1882  for ( Int i = 0; i < vec.size(); i++)   
1883  {
1884    maxVec = max( vec[i], maxVec ); 
1885  }
1886  return maxVec;
1887}
1888
1889Void TAppEncTop::xSetProfileTierLevel( TComVPS& vps )
1890{ 
1891
1892  // SET PTL
1893  assert( m_profiles.size() == m_level.size() && m_profiles.size() == m_levelTier.size() ); 
1894  vps.setVpsNumProfileTierLevelMinus1( (Int) m_profiles.size() - 1 );
1895  for ( Int ptlIdx = 0; ptlIdx <= vps.getVpsNumProfileTierLevelMinus1(); ptlIdx++ )
1896  {
1897    if ( ptlIdx > 1 )
1898    {
1899      Bool vpsProfilePresentFlag = ( m_profiles[ptlIdx] != m_profiles[ptlIdx - 1] )
1900        || ( m_inblFlag[ptlIdx ] != m_inblFlag[ptlIdx - 1] ); 
1901      vps.setVpsProfilePresentFlag( ptlIdx, vpsProfilePresentFlag ); 
1902    }
1903
1904    xSetProfileTierLevel( vps, ptlIdx, -1, m_profiles[ptlIdx], m_level[ptlIdx], 
1905      m_levelTier[ ptlIdx ], m_progressiveSourceFlag, m_interlacedSourceFlag,
1906      m_nonPackedConstraintFlag, m_frameOnlyConstraintFlag,  m_inblFlag[ptlIdx] );     
1907  } 
1908}
1909
1910Void 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)
1911{
1912  TComPTL* ptlStruct = vps.getPTL( profileTierLevelIdx );   
1913  assert( ptlStruct != NULL ); 
1914
1915  ProfileTierLevel* ptl; 
1916  if ( subLayer == -1 )
1917  {
1918    ptl = ptlStruct->getGeneralPTL();
1919  }
1920  else
1921  {
1922    ptl = ptlStruct->getSubLayerPTL(  subLayer );
1923  }
1924
1925  assert( ptl != NULL );
1926
1927  ptl->setProfileIdc( profile );
1928  ptl->setTierFlag  ( tier    );
1929  ptl->setLevelIdc  ( level   );
1930  ptl->setProfileCompatibilityFlag( profile, true );
1931  ptl->setInbldFlag( inbldFlag );
1932
1933  switch ( profile )
1934  {
1935  case Profile::MAIN:
1936    break; 
1937  case Profile::MULTIVIEWMAIN:
1938#if NH_3D
1939  case Profile::MAIN3D:
1940#endif
1941    ptl->setMax12bitConstraintFlag      ( true  ); 
1942    ptl->setMax12bitConstraintFlag      ( true  );
1943    ptl->setMax10bitConstraintFlag      ( true  );
1944    ptl->setMax8bitConstraintFlag       ( true  );
1945    ptl->setMax422chromaConstraintFlag  ( true  );
1946    ptl->setMax420chromaConstraintFlag  ( true  );
1947    ptl->setMaxMonochromeConstraintFlag ( false );
1948    ptl->setIntraConstraintFlag         ( false ); 
1949    ptl->setOnePictureOnlyConstraintFlag( false );
1950    ptl->setLowerBitRateConstraintFlag  ( true  );       
1951    break; 
1952  default:
1953    assert( 0 ); // other profiles currently not supported
1954    break; 
1955  }
1956}
1957
1958Void TAppEncTop::xSetRepFormat( TComVPS& vps )
1959{
1960
1961  Bool anyDepth = false; 
1962#if NH_3D
1963  for ( Int i = 0; i < m_numberOfLayers; i++ )
1964  {
1965    vps.setVpsRepFormatIdx( i, m_depthFlag[ i ] ? 1 : 0 );
1966    anyDepth = anyDepth || m_depthFlag[ i ];
1967  }
1968#endif
1969
1970  vps.setRepFormatIdxPresentFlag( anyDepth ); 
1971  vps.setVpsNumRepFormatsMinus1 ( anyDepth ? 1 : 0     ); 
1972
1973
1974  std::vector<TComRepFormat> repFormat;
1975  repFormat.resize( vps.getVpsNumRepFormatsMinus1() + 1 ); 
1976  for ( Int j = 0; j <= vps.getVpsNumRepFormatsMinus1(); j++ )
1977  {           
1978    repFormat[j].setBitDepthVpsChromaMinus8   ( m_internalBitDepth[CHANNEL_TYPE_LUMA  ] - 8 ); 
1979    repFormat[j].setBitDepthVpsLumaMinus8     ( m_internalBitDepth[CHANNEL_TYPE_CHROMA] - 8 );
1980    repFormat[j].setChromaFormatVpsIdc        ( j == 1 ? CHROMA_400 :  CHROMA_420 );
1981    repFormat[j].setPicHeightVpsInLumaSamples ( m_iSourceHeight );
1982    repFormat[j].setPicWidthVpsInLumaSamples  ( m_iSourceWidth  );   
1983    repFormat[j].setChromaAndBitDepthVpsPresentFlag( true );   
1984    // ToDo not supported yet.
1985    //repFormat->setSeparateColourPlaneVpsFlag( );
1986
1987    repFormat[j].setConformanceWindowVpsFlag( true );
1988    repFormat[j].setConfWinVpsLeftOffset    ( m_confWinLeft   / TComSPS::getWinUnitX( repFormat[j].getChromaFormatVpsIdc() ) );
1989    repFormat[j].setConfWinVpsRightOffset   ( m_confWinRight  / TComSPS::getWinUnitX( repFormat[j].getChromaFormatVpsIdc() )  );
1990    repFormat[j].setConfWinVpsTopOffset     ( m_confWinTop    / TComSPS::getWinUnitY( repFormat[j].getChromaFormatVpsIdc() )  );
1991    repFormat[j].setConfWinVpsBottomOffset  ( m_confWinBottom / TComSPS::getWinUnitY( repFormat[j].getChromaFormatVpsIdc() ) ); 
1992  }
1993
1994  vps.setRepFormat( repFormat );
1995
1996}
1997
1998Void TAppEncTop::xSetDpbSize                ( TComVPS& vps )
1999{
2000  // These settings need to be verified
2001
2002  TComDpbSize dpbSize;   
2003  dpbSize.init( vps.getNumOutputLayerSets(), vps.getVpsMaxLayerId() + 1, vps.getMaxSubLayersMinus1() + 1 ) ;
2004 
2005
2006  for( Int i = 0; i < vps.getNumOutputLayerSets(); i++ )
2007  { 
2008    Int currLsIdx = vps.olsIdxToLsIdx( i ); 
2009    Bool subLayerFlagInfoPresentFlag = false; 
2010
2011    for( Int j = 0; j  <=  vps.getMaxSubLayersInLayerSetMinus1( currLsIdx ); j++ )
2012    {   
2013      Bool subLayerDpbInfoPresentFlag = false; 
2014      for( Int k = 0; k < vps.getNumLayersInIdList( currLsIdx ); k++ )   
2015      {
2016        Int layerIdInVps = vps.getLayerIdInVps( vps.getLayerSetLayerIdList( currLsIdx, k ) );
2017        if ( vps.getNecessaryLayerFlag( i,k ) && ( vps.getVpsBaseLayerInternalFlag() || vps.getLayerSetLayerIdList( currLsIdx, k ) != 0 ) )
2018        {       
2019          dpbSize.setMaxVpsDecPicBufferingMinus1( i, k, j, m_maxDecPicBufferingMvc[ layerIdInVps ][ j ] - 1 );
2020          if ( j > 0 )
2021          {
2022            subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize.getMaxVpsDecPicBufferingMinus1( i, k, j ) != dpbSize.getMaxVpsDecPicBufferingMinus1( i, k, j - 1 ) );
2023          }
2024        }
2025        else
2026        {
2027          if (vps.getNecessaryLayerFlag(i,k) && j == 0 && k == 0 )
2028          {         
2029            dpbSize.setMaxVpsDecPicBufferingMinus1(i, k ,j, 0 ); 
2030          }
2031        }
2032      }       
2033
2034      Int maxNumReorderPics = MIN_INT;
2035      for ( Int idx = 0; idx < vps.getNumLayersInIdList( currLsIdx ); idx++ )
2036      {
2037        if (vps.getNecessaryLayerFlag(i, idx ))
2038        {       
2039          Int layerIdInVps = vps.getLayerIdInVps( vps.getLayerSetLayerIdList(currLsIdx, idx) );       
2040          maxNumReorderPics = std::max( maxNumReorderPics, m_numReorderPicsMvc[ layerIdInVps ][ j ] ); 
2041        }
2042      }
2043      assert( maxNumReorderPics != MIN_INT ); 
2044
2045      dpbSize.setMaxVpsNumReorderPics( i, j, maxNumReorderPics );
2046      if ( j > 0 )
2047      {
2048        subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize.getMaxVpsNumReorderPics( i, j ) != dpbSize.getMaxVpsNumReorderPics( i, j - 1 ) );
2049      }
2050
2051      // To Be Done !
2052      // dpbSize.setMaxVpsLatencyIncreasePlus1( i, j, xx );
2053      if ( j > 0 )
2054      {
2055        subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize.getMaxVpsLatencyIncreasePlus1( i, j ) != dpbSize.getMaxVpsLatencyIncreasePlus1( i, j - 1  ) );
2056      }
2057
2058      if( j > 0 ) 
2059      {
2060        dpbSize.setSubLayerDpbInfoPresentFlag( i, j, subLayerDpbInfoPresentFlag );
2061        subLayerFlagInfoPresentFlag = subLayerFlagInfoPresentFlag || subLayerDpbInfoPresentFlag; 
2062      }       
2063    } 
2064    dpbSize.setSubLayerFlagInfoPresentFlag( i, subLayerFlagInfoPresentFlag ); 
2065  } 
2066  vps.setDpbSize( dpbSize ); 
2067}
2068
2069Void TAppEncTop::xSetLayerSets( TComVPS& vps )
2070{   
2071  // Layer sets
2072  vps.setVpsNumLayerSetsMinus1   ( m_vpsNumLayerSets - 1 ); 
2073   
2074  for (Int lsIdx = 0; lsIdx < m_vpsNumLayerSets; lsIdx++ )
2075  {
2076    for( Int layerId = 0; layerId < MAX_NUM_LAYER_IDS; layerId++ )
2077    {
2078      vps.setLayerIdIncludedFlag( false, lsIdx, layerId ); 
2079    }
2080    for ( Int i = 0; i < m_layerIdsInSets[lsIdx].size(); i++)
2081    {       
2082      vps.setLayerIdIncludedFlag( true, lsIdx, vps.getLayerIdInNuh( m_layerIdsInSets[lsIdx][i] ) ); 
2083    } 
2084  }
2085  vps.deriveLayerSetLayerIdList(); 
2086
2087  Int numAddOuputLayerSets = (Int) m_outputLayerSetIdx.size(); 
2088  // Additional output layer sets + profileLevelTierIdx
2089  vps.setDefaultOutputLayerIdc      ( m_defaultOutputLayerIdc );   
2090  if( vps.getNumIndependentLayers() == 0 && m_numAddLayerSets > 0  )
2091  {
2092    fprintf( stderr, "\nWarning: Ignoring additional layer sets since NumIndependentLayers is equal to 0.\n");           
2093  }
2094  else
2095  {
2096    vps.setNumAddLayerSets( m_numAddLayerSets ); 
2097    if ( m_highestLayerIdxPlus1.size() < vps.getNumAddLayerSets() ) 
2098    {
2099      fprintf(stderr, "\nError: Number of highestLayerIdxPlus1 parameters must be greater than or equal to NumAddLayerSets\n");
2100      exit(EXIT_FAILURE);
2101    }
2102
2103    for (Int i = 0; i < vps.getNumAddLayerSets(); i++)
2104    {
2105      if ( m_highestLayerIdxPlus1[ i ].size() < vps.getNumIndependentLayers() ) 
2106      {
2107        fprintf(stderr, "Error: Number of elements in highestLayerIdxPlus1[ %d ] parameters must be greater than or equal to NumIndependentLayers(= %d)\n", i, vps.getNumIndependentLayers());
2108        exit(EXIT_FAILURE);
2109      }
2110
2111      for (Int j = 1; j < vps.getNumIndependentLayers(); j++)
2112      {
2113        if ( m_highestLayerIdxPlus1[ i ][ j ]  < 0 || m_highestLayerIdxPlus1[ i ][ j ] > vps.getNumLayersInTreePartition( j ) ) 
2114        {
2115          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 ) );
2116          exit(EXIT_FAILURE);
2117        }
2118        vps.setHighestLayerIdxPlus1( i, j, m_highestLayerIdxPlus1[ i ][ j ] ); 
2119      }
2120      vps.deriveAddLayerSetLayerIdList( i );
2121    }       
2122  } 
2123  vps.setNumAddOlss                 ( numAddOuputLayerSets          ); 
2124  vps.initTargetLayerIdLists(); 
2125
2126  for (Int olsIdx = 0; olsIdx < vps.getNumLayerSets() + numAddOuputLayerSets; olsIdx++)
2127  {
2128    Int addOutLsIdx = olsIdx - vps.getNumLayerSets();     
2129    vps.setLayerSetIdxForOlsMinus1( olsIdx, ( ( addOutLsIdx < 0 ) ?  olsIdx  : m_outputLayerSetIdx[ addOutLsIdx ] ) - 1 ); 
2130
2131    Int lsIdx = vps.olsIdxToLsIdx( olsIdx );
2132    if (vps.getDefaultOutputLayerIdc() == 2 || addOutLsIdx >= 0 )
2133    { 
2134      for ( Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++)
2135      {
2136        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 !
2137      }
2138
2139      std::vector<Int>& outLayerIdList = ( addOutLsIdx >= 0 ) ? m_layerIdsInAddOutputLayerSet[addOutLsIdx] : m_layerIdsInDefOutputLayerSet[olsIdx]; 
2140
2141      Bool outputLayerInLayerSetFlag = false; 
2142      for (Int j = 0; j < outLayerIdList.size(); j++)
2143      {   
2144        for ( Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++)
2145        {
2146          if ( vps.getLayerSetLayerIdList( lsIdx, i ) == outLayerIdList[ j ] )
2147          {
2148            vps.setOutputLayerFlag( olsIdx, i, true );       
2149            outputLayerInLayerSetFlag = true; 
2150            break; 
2151          }
2152        }
2153        if ( !outputLayerInLayerSetFlag )
2154        {
2155          fprintf(stderr, "Error: Output layer %d in output layer set %d not in corresponding layer set %d \n", outLayerIdList[ j ], olsIdx , lsIdx );
2156          exit(EXIT_FAILURE);
2157        }
2158      }
2159    }
2160    else
2161    {
2162      for ( Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++)
2163      {
2164        vps.setOutputLayerFlag( olsIdx, i, vps.inferOutputLayerFlag( olsIdx, i ) );       
2165      }
2166    }
2167
2168    vps.deriveNecessaryLayerFlags( olsIdx ); 
2169    vps.deriveTargetLayerIdList(  olsIdx ); 
2170
2171    // SET profile_tier_level_index.
2172    if ( olsIdx == 0 )
2173    {   
2174      vps.setProfileTierLevelIdx( 0, 0 , vps.getMaxLayersMinus1() > 0 ? 1 : 0 ); 
2175    }
2176    else
2177    {
2178      if( (Int) m_profileTierLevelIdx[ olsIdx ].size() < vps.getNumLayersInIdList( lsIdx ) )
2179      {
2180        fprintf( stderr, "Warning: Not enough profileTierLevelIdx values given for the %d-th OLS. Inferring default values.\n", olsIdx ); 
2181      }
2182      for (Int j = 0; j < vps.getNumLayersInIdList( lsIdx ); j++)
2183      {
2184        if( j < (Int) m_profileTierLevelIdx[ olsIdx ].size() )
2185        {
2186          vps.setProfileTierLevelIdx(olsIdx, j, m_profileTierLevelIdx[olsIdx][j] );
2187          if( !vps.getNecessaryLayerFlag(olsIdx,j) && m_profileTierLevelIdx[ olsIdx ][ j ] != -1 )
2188          {
2189            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 ); 
2190          }         
2191        }
2192        else if ( vps.getNecessaryLayerFlag(olsIdx,j) )
2193        {
2194          // setting default values
2195          if ( j == 0 || vps.getVpsNumProfileTierLevelMinus1() < 1 )
2196          {
2197            // set base layer as default
2198            vps.setProfileTierLevelIdx(olsIdx, j, 1 );
2199          }
2200          else
2201          {
2202            // set VpsProfileTierLevel[2] as default
2203            vps.setProfileTierLevelIdx(olsIdx, j, 2 ); 
2204          }
2205        }
2206      }
2207    }
2208   
2209    if ( vps.getNumOutputLayersInOutputLayerSet( olsIdx ) == 1 && 
2210        vps.getNumDirectRefLayers( vps.getOlsHighestOutputLayerId( olsIdx ) ) )
2211    {   
2212      vps.setAltOutputLayerFlag( olsIdx , m_altOutputLayerFlag[ olsIdx ]);
2213    }
2214    else
2215    {
2216      vps.setAltOutputLayerFlag( olsIdx , false );
2217      if ( m_altOutputLayerFlag[ olsIdx ] )
2218      {
2219        printf( "\nWarning: Ignoring AltOutputLayerFlag for output layer set %d, since more than one output layer or no dependent layers.\n", olsIdx );           
2220      }
2221    }
2222  }
2223}
2224
2225Void TAppEncTop::xSetVPSVUI( TComVPS& vps )
2226{
2227  vps.setVpsVuiPresentFlag( m_vpsVuiPresentFlag ); 
2228
2229  TComVPSVUI vpsVui;
2230  vpsVui.init(vps.getNumAddLayerSets(),vps.getMaxSubLayersMinus1() + 1, vps.getMaxLayersMinus1() + 1 );
2231
2232  if ( m_vpsVuiPresentFlag )
2233  {
2234    // All this stuff could actually be derived by the encoder,
2235    // however preliminary setting it from input parameters
2236
2237    vpsVui.setCrossLayerPicTypeAlignedFlag( m_crossLayerPicTypeAlignedFlag );
2238    vpsVui.setCrossLayerIrapAlignedFlag   ( m_crossLayerIrapAlignedFlag    );
2239    vpsVui.setAllLayersIdrAlignedFlag     ( m_allLayersIdrAlignedFlag      );
2240    vpsVui.setBitRatePresentVpsFlag( m_bitRatePresentVpsFlag );
2241    vpsVui.setPicRatePresentVpsFlag( m_picRatePresentVpsFlag );
2242
2243    if( vpsVui.getBitRatePresentVpsFlag( )  ||  vpsVui.getPicRatePresentVpsFlag( ) )
2244    {
2245      for( Int i = 0; i  <  vps.getNumLayerSets(); i++ )
2246      {
2247        for( Int j = 0; j  <=  vps.getMaxTLayers(); j++ ) 
2248        {
2249          if( vpsVui.getBitRatePresentVpsFlag( ) && m_bitRatePresentFlag[i].size() > j )
2250          {
2251            vpsVui.setBitRatePresentFlag( i, j, m_bitRatePresentFlag[i][j] );           
2252          }
2253          if( vpsVui.getPicRatePresentVpsFlag( ) && m_picRatePresentFlag[i].size() > j   )
2254          {
2255            vpsVui.setPicRatePresentFlag( i, j, m_picRatePresentFlag[i][j] );
2256          }
2257          if( vpsVui.getBitRatePresentFlag( i, j )  && m_avgBitRate[i].size() > j )
2258          {
2259            vpsVui.setAvgBitRate( i, j, m_avgBitRate[i][j] );         
2260          }
2261          if( vpsVui.getBitRatePresentFlag( i, j )  && m_maxBitRate[i].size() > j )
2262          {
2263            vpsVui.setMaxBitRate( i, j, m_maxBitRate[i][j] );
2264          }
2265          if( vpsVui.getPicRatePresentFlag( i, j ) && m_constantPicRateIdc[i].size() > j )
2266          {
2267            vpsVui.setConstantPicRateIdc( i, j, m_constantPicRateIdc[i][j] );
2268          }
2269          if( vpsVui.getPicRatePresentFlag( i, j ) && m_avgPicRate[i].size() > j )
2270          {
2271            vpsVui.setAvgPicRate( i, j, m_avgPicRate[i][j] );
2272          }
2273        }
2274      }
2275    }
2276
2277    vpsVui.setTilesNotInUseFlag( m_tilesNotInUseFlag );
2278
2279    if( !vpsVui.getTilesNotInUseFlag() ) 
2280    {     
2281      for( Int i = 0; i  <=  vps.getMaxLayersMinus1(); i++ )
2282      {
2283        vpsVui.setTilesInUseFlag( i, m_tilesInUseFlag[ i ] );
2284        if( vpsVui.getTilesInUseFlag( i ) ) 
2285        {
2286          vpsVui.setLoopFilterNotAcrossTilesFlag( i, m_loopFilterNotAcrossTilesFlag[ i ] );
2287        }
2288      } 
2289
2290      for( Int i = 1; i  <=  vps.getMaxLayersMinus1(); i++ ) 
2291      {
2292        for( Int j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ) ; j++ )
2293        { 
2294          Int layerIdx = vps.getLayerIdInVps( vps.getIdDirectRefLayer(vps.getLayerIdInNuh( i ) , j  )); 
2295          if( vpsVui.getTilesInUseFlag( i )  &&  vpsVui.getTilesInUseFlag( layerIdx ) ) 
2296          {
2297            vpsVui.setTileBoundariesAlignedFlag( i, j, m_tileBoundariesAlignedFlag[i][j] );
2298          }
2299        } 
2300      }
2301    } 
2302
2303    vpsVui.setWppNotInUseFlag( m_wppNotInUseFlag );
2304
2305    if( !vpsVui.getWppNotInUseFlag( ) )
2306    {
2307      for( Int i = 1; i  <=  vps.getMaxLayersMinus1(); i++ ) 
2308      {
2309        vpsVui.setWppInUseFlag( i, m_wppInUseFlag[ i ]);
2310      }
2311    }
2312
2313  vpsVui.setSingleLayerForNonIrapFlag( m_singleLayerForNonIrapFlag );
2314  vpsVui.setHigherLayerIrapSkipFlag( m_higherLayerIrapSkipFlag );
2315
2316    vpsVui.setIlpRestrictedRefLayersFlag( m_ilpRestrictedRefLayersFlag );
2317
2318    if( vpsVui.getIlpRestrictedRefLayersFlag( ) )
2319    {
2320      for( Int i = 1; i  <=  vps.getMaxLayersMinus1(); i++ )
2321      {
2322        for( Int j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ); j++ )
2323        {
2324          if ( m_minSpatialSegmentOffsetPlus1[i].size() > j )
2325          {       
2326            vpsVui.setMinSpatialSegmentOffsetPlus1( i, j, m_minSpatialSegmentOffsetPlus1[i][j] );
2327          }
2328          if( vpsVui.getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
2329          {
2330            if ( m_ctuBasedOffsetEnabledFlag[i].size() > j )
2331            {       
2332              vpsVui.setCtuBasedOffsetEnabledFlag( i, j, m_ctuBasedOffsetEnabledFlag[i][j] );
2333            }
2334            if( vpsVui.getCtuBasedOffsetEnabledFlag( i, j ) )
2335            {
2336              if ( m_minHorizontalCtuOffsetPlus1[i].size() > j )
2337              {
2338                vpsVui.setMinHorizontalCtuOffsetPlus1( i, j, m_minHorizontalCtuOffsetPlus1[i][j] );
2339              }
2340            }
2341          }
2342        }
2343      }
2344    }     
2345    vpsVui.setVideoSignalInfoIdxPresentFlag( true ); 
2346    vpsVui.setVpsNumVideoSignalInfoMinus1  ( 0    );     
2347
2348    std::vector<TComVideoSignalInfo> videoSignalInfos;
2349    videoSignalInfos.resize( vpsVui.getVpsNumVideoSignalInfoMinus1() + 1 );
2350
2351    videoSignalInfos[0].setColourPrimariesVps        ( m_colourPrimaries ); 
2352    videoSignalInfos[0].setMatrixCoeffsVps           ( m_matrixCoefficients ); 
2353    videoSignalInfos[0].setTransferCharacteristicsVps( m_transferCharacteristics ); 
2354    videoSignalInfos[0].setVideoVpsFormat            ( m_videoFormat ); 
2355    videoSignalInfos[0].setVideoFullRangeVpsFlag     ( m_videoFullRangeFlag ); 
2356
2357    vpsVui.setVideoSignalInfo( videoSignalInfos );       
2358
2359    for (Int i = 0; i < m_numberOfLayers; i++)
2360    {     
2361      vpsVui.setVpsVideoSignalInfoIdx( i, 0 ); 
2362    }
2363    vpsVui.setVpsVuiBspHrdPresentFlag( false ); // TBD
2364  }
2365  else
2366  {
2367    //Default inference when not present.
2368    vpsVui.setCrossLayerIrapAlignedFlag   ( false   );
2369  }
2370  vps.setVPSVUI( vpsVui ); 
2371}
2372
2373#if NH_3D
2374Void TAppEncTop::xSetCamPara                ( TComVPS& vps )
2375{
2376  vps.setCpPrecision( m_cCameraData.getCamParsCodedPrecision()); 
2377
2378  for ( Int n = 1; n < vps.getNumViews(); n++ )
2379  { 
2380    Int i      = vps.getViewOIdxList( n ); 
2381    Int iInVps = vps.getVoiInVps    ( i ); 
2382    vps.setNumCp( iInVps,  n);   
2383
2384    if ( vps.getNumCp( iInVps ) > 0 )
2385    {
2386      vps.setCpInSliceSegmentHeaderFlag( iInVps, m_cCameraData.getVaryingCameraParameters() );
2387
2388      for( Int m = 0; m < vps.getNumCp( iInVps ); m++ )
2389      {
2390        vps.setCpRefVoi( iInVps, m, vps.getViewOIdxList( m ) ); 
2391        if( !vps.getCpInSliceSegmentHeaderFlag( iInVps ) ) 
2392        {
2393          Int j = vps.getCpRefVoi( iInVps, m );
2394          Int jInVps = vps.getVoiInVps( j );         
2395
2396          vps.setVpsCpScale   ( iInVps, jInVps, m_cCameraData.getCodedScale() [ jInVps ][ iInVps ] ) ;
2397          vps.setVpsCpInvScale( iInVps, jInVps, m_cCameraData.getCodedScale() [ iInVps ][ jInVps ] ) ;
2398          vps.setVpsCpOff     ( iInVps, jInVps, m_cCameraData.getCodedOffset()[ jInVps ][ iInVps ] ) ;
2399          vps.setVpsCpInvOff  ( iInVps, jInVps, m_cCameraData.getCodedOffset()[ iInVps ][ jInVps ] ) ;
2400        }
2401      }
2402    }
2403  }
2404  vps.deriveCpPresentFlag(); 
2405}
2406#endif
2407
2408
2409Bool TAppEncTop::xLayerIdInTargetEncLayerIdList(Int nuhLayerId)
2410{
2411  return  ( std::find(m_targetEncLayerIdList.begin(), m_targetEncLayerIdList.end(), nuhLayerId) != m_targetEncLayerIdList.end()) ;
2412}
2413
2414
2415#endif
2416
2417
2418#if NH_3D_DLT
2419Void TAppEncTop::xDeriveDltArray( TComVPS& vps, TComDLT* dlt )
2420{
2421  Int  iNumDepthViews  = 0;
2422  Bool bDltPresentFlag = false;
2423
2424  for ( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ )
2425  {
2426    Bool isDepth = ( vps.getDepthId( layer ) == 1 );
2427
2428    if ( isDepth )
2429    {
2430      iNumDepthViews++;
2431    }
2432
2433    dlt->setUseDLTFlag( layer , isDepth && m_useDLT );
2434    if( dlt->getUseDLTFlag( layer ) )
2435    {
2436      xAnalyzeInputBaseDepth(layer, max(m_iIntraPeriod[layer], 24), &vps, dlt);
2437      bDltPresentFlag = bDltPresentFlag || dlt->getUseDLTFlag(layer);
2438      dlt->setInterViewDltPredEnableFlag(layer, (dlt->getUseDLTFlag(layer) && (layer>1)));
2439     
2440      // ----------------------------- determine whether to use bit-map -----------------------------
2441      Bool bDltBitMapRepFlag       = false;
2442      UInt uiNumBitsNonBitMap      = 0;
2443      UInt uiNumBitsBitMap         = 0;
2444     
2445      UInt uiMaxDiff               = 0;
2446      UInt uiMinDiff               = MAX_INT;
2447      UInt uiLengthMinDiff         = 0;
2448      UInt uiLengthDltDiffMinusMin = 0;
2449     
2450      std::vector<Int> aiIdx2DepthValue_coded(256, 0);
2451      UInt uiNumDepthValues_coded = 0;
2452     
2453      uiNumDepthValues_coded = dlt->getNumDepthValues(layer);
2454      for( UInt ui = 0; ui<uiNumDepthValues_coded; ui++ )
2455      {
2456        aiIdx2DepthValue_coded[ui] = dlt->idx2DepthValue(layer, ui);
2457      }
2458     
2459      if( dlt->getInterViewDltPredEnableFlag( layer ) )
2460      {
2461        AOF( vps.getDepthId( 1 ) == 1 );
2462        AOF( layer > 1 );
2463        // assumes ref layer id to be 1
2464        std::vector<Int> piRefDLT = dlt->idx2DepthValue( 1 );
2465        UInt uiRefNum = dlt->getNumDepthValues( 1 );
2466        dlt->getDeltaDLT(layer, piRefDLT, uiRefNum, aiIdx2DepthValue_coded, uiNumDepthValues_coded);
2467      }
2468     
2469      std::vector<UInt> puiDltDiffValues(uiNumDepthValues_coded, 0);
2470     
2471      for (UInt d = 1; d < uiNumDepthValues_coded; d++)
2472      {
2473        puiDltDiffValues[d] = aiIdx2DepthValue_coded[d] - aiIdx2DepthValue_coded[d-1];
2474       
2475        if ( uiMaxDiff < puiDltDiffValues[d] )
2476        {
2477          uiMaxDiff = puiDltDiffValues[d];
2478        }
2479       
2480        if ( uiMinDiff > puiDltDiffValues[d] )
2481        {
2482          uiMinDiff = puiDltDiffValues[d];
2483        }
2484      }
2485     
2486      // counting bits
2487      // diff coding branch
2488      uiNumBitsNonBitMap += 8;                          // u(v) bits for num_depth_values_in_dlt[layerId] (i.e. num_entry[ layerId ])
2489     
2490      if ( uiNumDepthValues_coded > 1 )
2491      {
2492        uiNumBitsNonBitMap += 8;                        // u(v) bits for max_diff[ layerId ]
2493      }
2494     
2495      if ( uiNumDepthValues_coded > 2 )
2496      {
2497        uiLengthMinDiff    = (UInt) gCeilLog2(uiMaxDiff + 1);
2498        uiNumBitsNonBitMap += uiLengthMinDiff;          // u(v)  bits for min_diff[ layerId ]
2499      }
2500     
2501      uiNumBitsNonBitMap += 8;                          // u(v) bits for dlt_depth_value0[ layerId ]
2502     
2503      if (uiMaxDiff > uiMinDiff)
2504      {
2505        uiLengthDltDiffMinusMin = (UInt) gCeilLog2(uiMaxDiff - uiMinDiff + 1);
2506        uiNumBitsNonBitMap += uiLengthDltDiffMinusMin * (uiNumDepthValues_coded - 1);  // u(v) bits for dlt_depth_value_diff_minus_min[ layerId ][ j ]
2507      }
2508     
2509      // bit map branch
2510      uiNumBitsBitMap = 1 << m_inputBitDepth[CHANNEL_TYPE_LUMA];
2511     
2512      // determine bDltBitMapFlag
2513      bDltBitMapRepFlag = (uiNumBitsBitMap > uiNumBitsNonBitMap) ? false : true;
2514     
2515      dlt->setUseBitmapRep(layer, bDltBitMapRepFlag);
2516    }
2517  }
2518
2519  dlt->setDltPresentFlag( bDltPresentFlag );
2520  dlt->setNumDepthViews ( iNumDepthViews  );
2521  dlt->setDepthViewBitDepth( m_inputBitDepth[CHANNEL_TYPE_LUMA] );
2522}
2523#endif
2524//! \}
Note: See TracBrowser for help on using the repository browser.