source: 3DVCSoftware/branches/HTM-15.0-dev0/source/App/TAppEncoder/TAppEncTop.cpp @ 1317

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

Clean-ups. HLS.

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