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

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

Merged 12.0-dev1@1065.

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