source: 3DVCSoftware/branches/HTM-14.1-update-dev1-RWTH/source/App/TAppEncoder/TAppEncTop.cpp @ 1237

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