source: 3DVCSoftware/branches/HTM-10.0-dev0/source/App/TAppEncoder/TAppEncTop.cpp @ 854

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

Integrated following MV-HEVC HLS 7 items:

H_MV_HLS7_GEN Stub for further integrations (not tested)
H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
Output layer sets, various

(VPS/P0300/alt output layer flag) #27 Change alt output layer flag to be signalled within the loop of output layer sets, from JCTVC-P0300-v2. Decision: Adopt.
(VPS/P0156/Num of output_layer_flag) #10 Proposal 3: The output_layer_flag[ i ][ j ] is signalled for j equal to 0 to NumLayersInIdList[ lsIdx ] inclusive. It was remarked that we might be able to just assume that the top layer is always output; however, this was not entirely clear , so the safe thing to do may be to also send the flag for this layer.
(VPS/P0295/Default output layer sets) #5 Discussion from (P0110). Decision: Three-state approach (text in P0295, decoder shall allow 3 to be present and shall treat 3 the same as the value 2).

H_MV_HLS_7_HRD_P0156_7 (HRD/P0156/MaxSubLayersInLayerSetMinus1) #7 Proposal 1: signal, in the VPS extension, the DPB parameters for an output layer set for sub-DPBs only up to the maximum temporal sub-layers in the corresponding layer set
H_MV_HLS_7_VPS_P0048_14
(VPS/P0048/profile_ref_minus1 rem) #14 Remove profile_ref_minus1 from the VPS extension, from JCTVC-P0048
H_MV_HLS_7_VPS_P0076_15 (VPS/P0076/video signal info move) #15 Move video signal information syntax structure earlier in the VPS VUI.
H_MV_HLS_7_SPS_P0155_16_32
(SPS/P0155/sps_sub_layer_ordering_info) #16, #32 Not signal the sps_max_num_reorder_pics[], sps_max_latency_increase_plus1[], and sps_max_dec_pic_buffering_minus1[] syntax elements in the SPS when nuh_layer_id > 0.
H_MV_HLS_7_GEN_P0166_PPS_EXTENSION (GEN/P0166/pps_extension) #17 Add PPS extension type flags for conditional presence of syntax extensions per extension type, aligned with the SPS extension type flags, from JCTVC-P0166. Further align the SPS extension type flags syntax between RExt and MV-HEVC/SHVC
H_MV_HLS_7_FIX_SET_DPB_SIZE
Fix derivation dpb size parameters
H_MV_HLS_7_RESERVED_FLAGS Added flags

(SPS/P0312/SHVC reserved flag) The flag will be used for the syntax vert_phase_position_enable_flag in SHVC draft
(VPS/O0215/SHVC reserved flag): this flag will be used for the syntax cross_layer_phase_alignment_flag in SHVC draft.
(VPS VUI/O0199,P0312/SHVC reserved flags) the 3 reserved bits will be used for the syntaxes single_layer_for_non_irap_flag, higher_layer_irap_skip_flag and vert_phase_position_not_in_use_flag in SHVC draft.

H_MV_FIX_VPS_LAYER_ID_NOT_EQUAL_ZERO Discard VPS with nuh_layer_Id > 0
H_MV_HLS_7_MISC_P0130_EOS
(MISC/P0130/EOS NAL layer id) #19 Require that end of bitstream NAL unit shall have nuh_layer_id equal to 0, from JCTVC-P0130. Decoders shall allow an end of bitstream NAL unit with nuh_layer_id > 0 to be present, and shall ignore the NAL unit.
H_MV_HLS_7_MISC_P0182_13 (MISC/P0182/BL PS Compatibility flag) #13 Define the flag (in VPS VUI) with the proposed semantics, without specifying an associated extraction process. Editors to select the position in the VPS VUI.
H_MV_HLS_7_MISC_P0068_21
(MISC/P0068/all irap idr flag) #21 Add flag in VUI to indicate that all IRAP pictures are IDRs and that all layer pictures in an AU are IDR aligned, from JCTVC-P0068 proposal 1.
H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG Fix inference of cross_layer_irap_aligned_flag
H_MV_HLS_7_MISC_P0079_18
(MISC/P0079/NumActiveRefLayerPics) #18 Modification of derivation of variable NumActiveRefLayerPics.

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