source: 3DVCSoftware/branches/HTM-15.1-dev0/source/App/TAppEncoder/TAppEncTop.cpp @ 1328

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

Integrated general SEI changes and following SEIs:

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