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

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

MV-HEVC related fix for derivation of number of views (H_MV_FIX_NUM_VIEWS).
Initial code for J0107 item 5 (not enabled yet). (HHI_VIEW_ID_LIST_I5_J0107)

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