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

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

Further fixes and alignments.

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