source: 3DVCSoftware/branches/HTM-12.2-dev2-LGE/source/App/TAppEncoder/TAppEncTop.cpp @ 1094

Last change on this file since 1094 was 1094, checked in by lg, 9 years ago

Integration of JCT3V-J0042. The MACRO is "LGE_DDD_REMOVAL_J0042_J0030."
Integration of JCT3V-J0046. The MACRO is "LGE_DEFAULT_DV_J0046."
Integration of JCT3V-J0050. The MACRO is "LGE_CHROMA_IC_J0050_J0034."
Integration of JCT3V-J0041. The MACRO is "LGE_SIMP_DISP_AVAIL_J0041."

By Sunmi Yoo (sunmi.yoo@…) and Junghak Nam (junghak.nam@…)

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