source: 3DVCSoftware/trunk/source/App/TAppEncoder/TAppEncTop.cpp @ 1196

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

Merged 14.0-dev0@1187.

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