source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncTop.cpp @ 532

Last change on this file since 532 was 532, checked in by tech, 11 years ago
  • Fixed cfg files.
  • Fixed several memory leaks.
  • Fixed encoder/decoder mismatch and aligned order of vps syntax elements with draft text.
  • Added missing iv_mv_scaling flag.
  • Property svn:eol-style set to native
File size: 41.6 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2013, 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_MV
79  Int maxTempLayer = -1; 
80  for (Int j = 0; j < m_numberOfLayers; j++)
81  {
82    maxTempLayer = max( m_maxTempLayerMvc[ j ], maxTempLayer ); 
83  }
84
85  vps.setMaxTLayers                       ( maxTempLayer );
86  if ( maxTempLayer )
87  {
88    vps.setTemporalNestingFlag(true);
89  }
90  vps.setMaxLayers( m_numberOfLayers );
91  for(Int i = 0; i < MAX_TLAYER; i++)
92  {
93    Int maxNumReOrderPics  = 0; 
94    Int maxDecPicBuffering = 0;
95    for (Int j = 0; j < m_numberOfLayers; j++)
96    {
97      maxNumReOrderPics  = max( maxNumReOrderPics,  m_numReorderPicsMvc    [ j ][ i ] );     
98      maxDecPicBuffering = max( maxDecPicBuffering, m_maxDecPicBufferingMvc[ j ][ i ] );     
99    }
100
101    vps.setNumReorderPics                 ( maxNumReOrderPics  ,i );
102    vps.setMaxDecPicBuffering             ( maxDecPicBuffering ,i );
103  }
104#else
105  vps.setMaxTLayers                       ( m_maxTempLayer );
106  if (m_maxTempLayer == 1)
107  {
108    vps.setTemporalNestingFlag(true);
109  }
110  vps.setMaxLayers                        ( 1 );
111  for(Int i = 0; i < MAX_TLAYER; i++)
112  {
113    vps.setNumReorderPics                 ( m_numReorderPics[i], i );
114    vps.setMaxDecPicBuffering             ( m_maxDecPicBuffering[i], i );
115  }
116#endif
117#if H_MV
118  xSetLayerIds             ( vps );   
119  xSetDimensionIdAndLength ( vps );
120  xSetDirectDependencyFlags( vps );
121#if H_3D
122  vps.initViewIndex(); 
123#if H_3D_GEN
124  xSetVPSExtension2        ( vps ); 
125#endif
126  m_ivPicLists.setVPS      ( &vps ); 
127#endif
128
129  for(Int layer = 0; layer < m_numberOfLayers; layer++)
130  {
131    m_frameRcvd                 .push_back(0);
132    m_acTEncTopList             .push_back(new TEncTop); 
133    m_acTVideoIOYuvInputFileList.push_back(new TVideoIOYuv);
134    m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv);
135    m_picYuvRec                 .push_back(new TComList<TComPicYuv*>) ;
136
137    m_ivPicLists.push_back( m_acTEncTopList[ layer ]->getListPic()  ); 
138    TEncTop& m_cTEncTop = *m_acTEncTopList[ layer ];  // It is not a member, but this name helps avoiding code duplication !!!
139   
140    m_cTEncTop.setLayerIdInVps                 ( layer ); 
141    m_cTEncTop.setLayerId                      ( vps.getLayerIdInNuh( layer ) );   
142    m_cTEncTop.setViewId                       ( vps.getViewId      ( layer ) );
143#if H_3D
144    Bool isDepth = ( vps.getDepthId     ( layer ) != 0 ) ;
145    m_cTEncTop.setViewIndex                    ( vps.getViewIndex   ( layer ) );
146    m_cTEncTop.setIsDepth                      ( isDepth );
147    //====== Camera Parameters =========
148    m_cTEncTop.setCameraParameters             ( &m_cCameraData );     
149    m_cTEncTop.setCamParPrecision              ( isDepth ? false : m_cCameraData.getCamParsCodedPrecision  () );
150    m_cTEncTop.setCamParInSliceHeader          ( isDepth ? 0     : m_cCameraData.getVaryingCameraParameters() );
151    m_cTEncTop.setCodedScale                   ( isDepth ? 0     : m_cCameraData.getCodedScale             () );
152    m_cTEncTop.setCodedOffset                  ( isDepth ? 0     : m_cCameraData.getCodedOffset            () );
153#if H_3D_VSO
154    //====== VSO =========
155    m_cTEncTop.setRenderModelParameters        ( &m_cRenModStrParser ); 
156    m_cTEncTop.setForceLambdaScaleVSO          ( isDepth ? m_bForceLambdaScaleVSO : false );
157    m_cTEncTop.setLambdaScaleVSO               ( isDepth ? m_dLambdaScaleVSO      : 1     );
158    m_cTEncTop.setVSOMode                      ( isDepth ? m_uiVSOMode            : 0     );
159
160    m_cTEncTop.setAllowNegDist                 ( isDepth ? m_bAllowNegDist        : false );
161
162    // SAIT_VSO_EST_A0033
163    m_cTEncTop.setUseEstimatedVSD              ( isDepth ? m_bUseEstimatedVSD     : false );
164
165    // LGE_WVSO_A0119
166    m_cTEncTop.setUseWVSO                      ( isDepth ? m_bUseWVSO             : false );   
167    m_cTEncTop.setVSOWeight                    ( isDepth ? m_iVSOWeight           : 0     );
168    m_cTEncTop.setVSDWeight                    ( isDepth ? m_iVSDWeight           : 0     );
169    m_cTEncTop.setDWeight                      ( isDepth ? m_iDWeight             : 0     );
170#endif // H_3D_VSO
171#if H_3D_ARP
172    //====== Advanced Inter-view Residual Prediction =========
173    m_cTEncTop.setUseAdvRP                     ( ( isDepth || 0==layer ) ? 0 : m_uiUseAdvResPred );
174    m_cTEncTop.setARPStepNum                   ( ( isDepth || 0==layer ) ? 1 : H_3D_ARP_WFNR     );
175#endif
176#if H_3D_IC
177    m_cTEncTop.setUseIC                        ( vps.getViewIndex( layer ) == 0 ? false : m_abUseIC[isDepth ? 1 : 0] );
178#endif
179  //========== Depth intra modes ==========
180#if H_3D_DIM
181    m_cTEncTop.setUseDMM                       ( isDepth ? m_useDMM               : false );
182    m_cTEncTop.setUseRBC                       ( isDepth ? m_useRBC               : false );
183    m_cTEncTop.setUseSDC                       ( isDepth ? m_useSDC               : false );
184    m_cTEncTop.setUseDLT                       ( isDepth ? m_useDLT               : false );
185#endif
186#endif // H_3D
187
188    m_cTEncTop.setIvPicLists                   ( &m_ivPicLists ); 
189#endif // H_MV
190  m_cTEncTop.setVPS(&vps);
191
192  m_cTEncTop.setProfile(m_profile);
193  m_cTEncTop.setLevel(m_levelTier, m_level);
194#if L0046_CONSTRAINT_FLAGS
195  m_cTEncTop.setProgressiveSourceFlag(m_progressiveSourceFlag);
196  m_cTEncTop.setInterlacedSourceFlag(m_interlacedSourceFlag);
197  m_cTEncTop.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
198  m_cTEncTop.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
199#endif
200 
201  m_cTEncTop.setFrameRate                    ( m_iFrameRate );
202  m_cTEncTop.setFrameSkip                    ( m_FrameSkip );
203  m_cTEncTop.setSourceWidth                  ( m_iSourceWidth );
204  m_cTEncTop.setSourceHeight                 ( m_iSourceHeight );
205  m_cTEncTop.setConformanceWindow            ( m_confLeft, m_confRight, m_confTop, m_confBottom );
206  m_cTEncTop.setFramesToBeEncoded            ( m_framesToBeEncoded );
207 
208  //====== Coding Structure ========
209  m_cTEncTop.setIntraPeriod                  ( m_iIntraPeriod );
210  m_cTEncTop.setDecodingRefreshType          ( m_iDecodingRefreshType );
211  m_cTEncTop.setGOPSize                      ( m_iGOPSize );
212#if H_MV
213  m_cTEncTop.setGopList                      ( m_GOPListMvc[layer] );
214  m_cTEncTop.setExtraRPSs                    ( m_extraRPSsMvc[layer] );
215  for(Int i = 0; i < MAX_TLAYER; i++)
216  {
217    m_cTEncTop.setNumReorderPics             ( m_numReorderPicsMvc[layer][i], i );
218    m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBufferingMvc[layer][i], i );
219  }
220#else
221  m_cTEncTop.setGopList                      ( m_GOPList );
222  m_cTEncTop.setExtraRPSs                    ( m_extraRPSs );
223  for(Int i = 0; i < MAX_TLAYER; i++)
224  {
225    m_cTEncTop.setNumReorderPics             ( m_numReorderPics[i], i );
226    m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBuffering[i], i );
227  }
228#endif
229  for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
230  {
231    m_cTEncTop.setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
232  }
233#if H_MV
234  m_cTEncTop.setQP                           ( m_iQP[layer] );
235#else
236  m_cTEncTop.setQP                           ( m_iQP );
237#endif
238
239  m_cTEncTop.setPad                          ( m_aiPad );
240
241#if H_MV
242  m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayerMvc[layer] );
243#else
244  m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayer );
245#endif
246  m_cTEncTop.setUseAMP( m_enableAMP );
247 
248  //===== Slice ========
249 
250  //====== Loop/Deblock Filter ========
251#if H_MV
252  m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable[layer]);
253#else
254  m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable       );
255#endif
256  m_cTEncTop.setLoopFilterOffsetInPPS        ( m_loopFilterOffsetInPPS );
257  m_cTEncTop.setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
258  m_cTEncTop.setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
259  m_cTEncTop.setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
260#if L0386_DB_METRIC
261  m_cTEncTop.setDeblockingFilterMetric       ( m_DeblockingFilterMetric );
262#endif
263
264  //====== Motion search ========
265  m_cTEncTop.setFastSearch                   ( m_iFastSearch  );
266  m_cTEncTop.setSearchRange                  ( m_iSearchRange );
267  m_cTEncTop.setBipredSearchRange            ( m_bipredSearchRange );
268
269  //====== Quality control ========
270  m_cTEncTop.setMaxDeltaQP                   ( m_iMaxDeltaQP  );
271  m_cTEncTop.setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
272
273  m_cTEncTop.setChromaCbQpOffset               ( m_cbQpOffset     );
274  m_cTEncTop.setChromaCrQpOffset            ( m_crQpOffset  );
275
276#if ADAPTIVE_QP_SELECTION
277  m_cTEncTop.setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
278#endif
279
280  Int lowestQP;
281  lowestQP =  - 6*(g_bitDepthY - 8); // XXX: check
282
283#if H_MV
284  if ((m_iMaxDeltaQP == 0 ) && (m_iQP[layer] == lowestQP) && (m_useLossless == true))
285#else
286  if ((m_iMaxDeltaQP == 0 ) && (m_iQP == lowestQP) && (m_useLossless == true))
287#endif
288  {
289    m_bUseAdaptiveQP = false;
290  }
291  m_cTEncTop.setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
292  m_cTEncTop.setQPAdaptationRange            ( m_iQPAdaptationRange );
293 
294  //====== Tool list ========
295  m_cTEncTop.setUseSBACRD                    ( m_bUseSBACRD   );
296  m_cTEncTop.setDeltaQpRD                    ( m_uiDeltaQpRD  );
297  m_cTEncTop.setUseASR                       ( m_bUseASR      );
298  m_cTEncTop.setUseHADME                     ( m_bUseHADME    );
299  m_cTEncTop.setUseLossless                  ( m_useLossless );
300#if !L0034_COMBINED_LIST_CLEANUP
301  m_cTEncTop.setUseLComb                     ( m_bUseLComb    );
302#endif
303#if H_MV
304  m_cTEncTop.setdQPs                         ( m_aidQP[layer]   );
305#else
306  m_cTEncTop.setdQPs                         ( m_aidQP        );
307#endif
308  m_cTEncTop.setUseRDOQ                      ( m_useRDOQ     );
309  m_cTEncTop.setUseRDOQTS                    ( m_useRDOQTS   );
310#if L0232_RD_PENALTY
311  m_cTEncTop.setRDpenalty                 ( m_rdPenalty );
312#endif
313  m_cTEncTop.setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
314  m_cTEncTop.setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
315  m_cTEncTop.setQuadtreeTUMaxDepthInter      ( m_uiQuadtreeTUMaxDepthInter );
316  m_cTEncTop.setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
317  m_cTEncTop.setUseFastEnc                   ( m_bUseFastEnc  );
318  m_cTEncTop.setUseEarlyCU                   ( m_bUseEarlyCU  ); 
319  m_cTEncTop.setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
320  m_cTEncTop.setUseCbfFastMode            ( m_bUseCbfFastMode  );
321  m_cTEncTop.setUseEarlySkipDetection            ( m_useEarlySkipDetection );
322
323  m_cTEncTop.setUseTransformSkip             ( m_useTransformSkip      );
324  m_cTEncTop.setUseTransformSkipFast         ( m_useTransformSkipFast  );
325  m_cTEncTop.setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
326  m_cTEncTop.setPCMLog2MinSize          ( m_uiPCMLog2MinSize);
327  m_cTEncTop.setUsePCM                       ( m_usePCM );
328  m_cTEncTop.setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
329  m_cTEncTop.setMaxNumMergeCand              ( m_maxNumMergeCand );
330 
331
332  //====== Weighted Prediction ========
333  m_cTEncTop.setUseWP                   ( m_useWeightedPred      );
334  m_cTEncTop.setWPBiPred                ( m_useWeightedBiPred   );
335  //====== Parallel Merge Estimation ========
336  m_cTEncTop.setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 );
337
338  //====== Slice ========
339  m_cTEncTop.setSliceMode               ( m_sliceMode                );
340  m_cTEncTop.setSliceArgument           ( m_sliceArgument            );
341
342  //====== Dependent Slice ========
343  m_cTEncTop.setSliceSegmentMode        ( m_sliceSegmentMode         );
344  m_cTEncTop.setSliceSegmentArgument    ( m_sliceSegmentArgument     );
345  Int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
346  if(m_sliceSegmentMode==FIXED_NUMBER_OF_LCU)
347  {
348    m_cTEncTop.setSliceSegmentArgument ( m_sliceSegmentArgument * iNumPartInCU );
349  }
350  if(m_sliceMode==FIXED_NUMBER_OF_LCU)
351  {
352    m_cTEncTop.setSliceArgument ( m_sliceArgument * iNumPartInCU );
353  }
354  if(m_sliceMode==FIXED_NUMBER_OF_TILES)
355  {
356    m_cTEncTop.setSliceArgument ( m_sliceArgument );
357  }
358 
359  if(m_sliceMode == 0 )
360  {
361    m_bLFCrossSliceBoundaryFlag = true;
362  }
363  m_cTEncTop.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
364#if H_MV
365  m_cTEncTop.setUseSAO ( m_bUseSAO[layer] );
366#else
367  m_cTEncTop.setUseSAO ( m_bUseSAO );
368#endif
369  m_cTEncTop.setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
370
371  m_cTEncTop.setSaoLcuBoundary (m_saoLcuBoundary);
372  m_cTEncTop.setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
373  m_cTEncTop.setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
374  m_cTEncTop.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
375
376  m_cTEncTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
377  m_cTEncTop.setRecoveryPointSEIEnabled( m_recoveryPointSEIEnabled );
378  m_cTEncTop.setBufferingPeriodSEIEnabled( m_bufferingPeriodSEIEnabled );
379  m_cTEncTop.setPictureTimingSEIEnabled( m_pictureTimingSEIEnabled );
380#if J0149_TONE_MAPPING_SEI
381  m_cTEncTop.setToneMappingInfoSEIEnabled                 ( m_toneMappingInfoSEIEnabled );
382  m_cTEncTop.setTMISEIToneMapId                           ( m_toneMapId );
383  m_cTEncTop.setTMISEIToneMapCancelFlag                   ( m_toneMapCancelFlag );
384  m_cTEncTop.setTMISEIToneMapPersistenceFlag              ( m_toneMapPersistenceFlag );
385  m_cTEncTop.setTMISEICodedDataBitDepth                   ( m_toneMapCodedDataBitDepth );
386  m_cTEncTop.setTMISEITargetBitDepth                      ( m_toneMapTargetBitDepth );
387  m_cTEncTop.setTMISEIModelID                             ( m_toneMapModelId );
388  m_cTEncTop.setTMISEIMinValue                            ( m_toneMapMinValue );
389  m_cTEncTop.setTMISEIMaxValue                            ( m_toneMapMaxValue );
390  m_cTEncTop.setTMISEISigmoidMidpoint                     ( m_sigmoidMidpoint );
391  m_cTEncTop.setTMISEISigmoidWidth                        ( m_sigmoidWidth );
392  m_cTEncTop.setTMISEIStartOfCodedInterva                 ( m_startOfCodedInterval );
393  m_cTEncTop.setTMISEINumPivots                           ( m_numPivots );
394  m_cTEncTop.setTMISEICodedPivotValue                     ( m_codedPivotValue );
395  m_cTEncTop.setTMISEITargetPivotValue                    ( m_targetPivotValue );
396  m_cTEncTop.setTMISEICameraIsoSpeedIdc                   ( m_cameraIsoSpeedIdc );
397  m_cTEncTop.setTMISEICameraIsoSpeedValue                 ( m_cameraIsoSpeedValue );
398  m_cTEncTop.setTMISEIExposureCompensationValueSignFlag   ( m_exposureCompensationValueSignFlag );
399  m_cTEncTop.setTMISEIExposureCompensationValueNumerator  ( m_exposureCompensationValueNumerator );
400  m_cTEncTop.setTMISEIExposureCompensationValueDenomIdc   ( m_exposureCompensationValueDenomIdc );
401  m_cTEncTop.setTMISEIRefScreenLuminanceWhite             ( m_refScreenLuminanceWhite );
402  m_cTEncTop.setTMISEIExtendedRangeWhiteLevel             ( m_extendedRangeWhiteLevel );
403  m_cTEncTop.setTMISEINominalBlackLevelLumaCodeValue      ( m_nominalBlackLevelLumaCodeValue );
404  m_cTEncTop.setTMISEINominalWhiteLevelLumaCodeValue      ( m_nominalWhiteLevelLumaCodeValue );
405  m_cTEncTop.setTMISEIExtendedWhiteLevelLumaCodeValue     ( m_extendedWhiteLevelLumaCodeValue );
406#endif
407  m_cTEncTop.setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled );
408  m_cTEncTop.setFramePackingArrangementSEIType( m_framePackingSEIType );
409  m_cTEncTop.setFramePackingArrangementSEIId( m_framePackingSEIId );
410  m_cTEncTop.setFramePackingArrangementSEIQuincunx( m_framePackingSEIQuincunx );
411  m_cTEncTop.setFramePackingArrangementSEIInterpretation( m_framePackingSEIInterpretation );
412  m_cTEncTop.setDisplayOrientationSEIAngle( m_displayOrientationSEIAngle );
413  m_cTEncTop.setTemporalLevel0IndexSEIEnabled( m_temporalLevel0IndexSEIEnabled );
414  m_cTEncTop.setGradualDecodingRefreshInfoEnabled( m_gradualDecodingRefreshInfoEnabled );
415  m_cTEncTop.setDecodingUnitInfoSEIEnabled( m_decodingUnitInfoSEIEnabled );
416#if L0208_SOP_DESCRIPTION_SEI
417  m_cTEncTop.setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled );
418#endif
419#if K0180_SCALABLE_NESTING_SEI
420  m_cTEncTop.setScalableNestingSEIEnabled( m_scalableNestingSEIEnabled );
421#endif
422  m_cTEncTop.setUniformSpacingIdr          ( m_iUniformSpacingIdr );
423  m_cTEncTop.setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
424  m_cTEncTop.setNumRowsMinus1              ( m_iNumRowsMinus1 );
425  if(m_iUniformSpacingIdr==0)
426  {
427    m_cTEncTop.setColumnWidth              ( m_pColumnWidth );
428    m_cTEncTop.setRowHeight                ( m_pRowHeight );
429  }
430  m_cTEncTop.xCheckGSParameters();
431  Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
432  if(uiTilesCount == 1)
433  {
434    m_bLFCrossTileBoundaryFlag = true; 
435  }
436  m_cTEncTop.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
437  m_cTEncTop.setWaveFrontSynchro           ( m_iWaveFrontSynchro );
438  m_cTEncTop.setWaveFrontSubstreams        ( m_iWaveFrontSubstreams );
439  m_cTEncTop.setTMVPModeId ( m_TMVPModeId );
440  m_cTEncTop.setUseScalingListId           ( m_useScalingListId  );
441  m_cTEncTop.setScalingListFile            ( m_scalingListFile   );
442  m_cTEncTop.setSignHideFlag(m_signHideFlag);
443#if RATE_CONTROL_LAMBDA_DOMAIN
444  m_cTEncTop.setUseRateCtrl         ( m_RCEnableRateControl );
445  m_cTEncTop.setTargetBitrate       ( m_RCTargetBitrate );
446  m_cTEncTop.setKeepHierBit         ( m_RCKeepHierarchicalBit );
447  m_cTEncTop.setLCULevelRC          ( m_RCLCULevelRC );
448  m_cTEncTop.setUseLCUSeparateModel ( m_RCUseLCUSeparateModel );
449  m_cTEncTop.setInitialQP           ( m_RCInitialQP );
450  m_cTEncTop.setForceIntraQP        ( m_RCForceIntraQP );
451#else
452  m_cTEncTop.setUseRateCtrl     ( m_enableRateCtrl);
453  m_cTEncTop.setTargetBitrate   ( m_targetBitrate);
454  m_cTEncTop.setNumLCUInUnit    ( m_numLCUInUnit);
455#endif
456  m_cTEncTop.setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
457  m_cTEncTop.setCUTransquantBypassFlagValue(m_CUTransquantBypassFlagValue);
458  m_cTEncTop.setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
459  m_cTEncTop.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
460  m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); 
461  m_cTEncTop.setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
462  m_cTEncTop.setAspectRatioIdc( m_aspectRatioIdc );
463  m_cTEncTop.setSarWidth( m_sarWidth );
464  m_cTEncTop.setSarHeight( m_sarHeight );
465  m_cTEncTop.setOverscanInfoPresentFlag( m_overscanInfoPresentFlag );
466  m_cTEncTop.setOverscanAppropriateFlag( m_overscanAppropriateFlag );
467  m_cTEncTop.setVideoSignalTypePresentFlag( m_videoSignalTypePresentFlag );
468  m_cTEncTop.setVideoFormat( m_videoFormat );
469  m_cTEncTop.setVideoFullRangeFlag( m_videoFullRangeFlag );
470  m_cTEncTop.setColourDescriptionPresentFlag( m_colourDescriptionPresentFlag );
471  m_cTEncTop.setColourPrimaries( m_colourPrimaries );
472  m_cTEncTop.setTransferCharacteristics( m_transferCharacteristics );
473  m_cTEncTop.setMatrixCoefficients( m_matrixCoefficients );
474  m_cTEncTop.setChromaLocInfoPresentFlag( m_chromaLocInfoPresentFlag );
475  m_cTEncTop.setChromaSampleLocTypeTopField( m_chromaSampleLocTypeTopField );
476  m_cTEncTop.setChromaSampleLocTypeBottomField( m_chromaSampleLocTypeBottomField );
477  m_cTEncTop.setNeutralChromaIndicationFlag( m_neutralChromaIndicationFlag );
478  m_cTEncTop.setDefaultDisplayWindow( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset );
479  m_cTEncTop.setFrameFieldInfoPresentFlag( m_frameFieldInfoPresentFlag );
480  m_cTEncTop.setPocProportionalToTimingFlag( m_pocProportionalToTimingFlag );
481  m_cTEncTop.setNumTicksPocDiffOneMinus1   ( m_numTicksPocDiffOneMinus1    );
482  m_cTEncTop.setBitstreamRestrictionFlag( m_bitstreamRestrictionFlag );
483  m_cTEncTop.setTilesFixedStructureFlag( m_tilesFixedStructureFlag );
484  m_cTEncTop.setMotionVectorsOverPicBoundariesFlag( m_motionVectorsOverPicBoundariesFlag );
485  m_cTEncTop.setMinSpatialSegmentationIdc( m_minSpatialSegmentationIdc );
486  m_cTEncTop.setMaxBytesPerPicDenom( m_maxBytesPerPicDenom );
487  m_cTEncTop.setMaxBitsPerMinCuDenom( m_maxBitsPerMinCuDenom );
488  m_cTEncTop.setLog2MaxMvLengthHorizontal( m_log2MaxMvLengthHorizontal );
489  m_cTEncTop.setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
490#if SIGNAL_BITRATE_PICRATE_IN_VPS
491  TComBitRatePicRateInfo *bitRatePicRateInfo = m_cTEncTop.getVPS()->getBitratePicrateInfo();
492  // The number of bit rate/pic rate have to equal to number of sub-layers.
493  if(m_bitRatePicRateMaxTLayers)
494  {
495    assert(m_bitRatePicRateMaxTLayers == m_cTEncTop.getVPS()->getMaxTLayers());
496  }
497  for(Int i = 0; i < m_bitRatePicRateMaxTLayers; i++)
498  {
499    bitRatePicRateInfo->setBitRateInfoPresentFlag( i, m_bitRateInfoPresentFlag[i] );
500    if( bitRatePicRateInfo->getBitRateInfoPresentFlag(i) )
501    {
502      bitRatePicRateInfo->setAvgBitRate(i, m_avgBitRate[i]);
503      bitRatePicRateInfo->setMaxBitRate(i, m_maxBitRate[i]);
504    }
505  }
506  for(Int i = 0; i < m_bitRatePicRateMaxTLayers; i++)
507  {
508    bitRatePicRateInfo->setPicRateInfoPresentFlag( i, m_picRateInfoPresentFlag[i] );
509    if( bitRatePicRateInfo->getPicRateInfoPresentFlag(i) )
510    {
511      bitRatePicRateInfo->setAvgPicRate     (i, m_avgPicRate[i]);
512      bitRatePicRateInfo->setConstantPicRateIdc(i, m_constantPicRateIdc[i]);
513    }
514  }
515#endif
516#if H_MV
517  }
518#endif
519#if H_3D_VSO
520  if ( m_bUseVSO )
521  {
522    if ( m_uiVSOMode == 4 )
523    {
524#if H_3D_VSO_EARLY_SKIP
525      m_cRendererModel.create( m_cRenModStrParser.getNumOfBaseViews(), m_cRenModStrParser.getNumOfModels(), m_iSourceWidth, g_uiMaxCUHeight , LOG2_DISP_PREC_LUT, 0, m_bVSOEarlySkip );
526#else
527      m_cRendererModel.create( m_cRenModStrParser.getNumOfBaseViews(), m_cRenModStrParser.getNumOfModels(), m_iSourceWidth, g_uiMaxCUHeight , LOG2_DISP_PREC_LUT, 0 );
528#endif
529      for ( Int layer = 0; layer < m_numberOfLayers ; layer++ )
530      {
531        TEncTop* pcEncTop =  m_acTEncTopList[ layer ]; 
532        Int iViewNum      = pcEncTop->getViewIndex(); 
533        Int iContent      = pcEncTop->getIsDepth() ? 1 : 0; 
534        Int iNumOfModels  = m_cRenModStrParser.getNumOfModelsForView(iViewNum, iContent);
535
536        Bool bUseVSO      = (iNumOfModels != 0);
537
538        pcEncTop->setUseVSO( bUseVSO );
539        pcEncTop->getRdCost()->setRenModel( bUseVSO ? &m_cRendererModel : NULL );
540
541        for (Int iCurModel = 0; iCurModel < iNumOfModels; iCurModel++ )
542        {
543          Int iModelNum; Int iLeftViewNum; Int iRightViewNum; Int iDump; Int iOrgRefNum; Int iBlendMode;
544
545          m_cRenModStrParser.getSingleModelData  ( iViewNum, iContent, iCurModel, iModelNum, iBlendMode, iLeftViewNum, iRightViewNum, iOrgRefNum, iDump ) ;
546          m_cRendererModel  .createSingleModel   ( iViewNum, iContent, iModelNum, iLeftViewNum, iRightViewNum, (iOrgRefNum != -1), iBlendMode );
547        }           
548      }
549    }
550    else
551    {
552      AOT(true);
553    }
554  }
555#endif
556}
557
558Void TAppEncTop::xCreateLib()
559{
560#if H_MV
561  // initialize global variables
562  initROM();
563#if H_3D_DIM_DMM
564  initWedgeLists( true );
565#endif
566
567  for( Int layer=0; layer < m_numberOfLayers; layer++)
568  {
569    m_acTVideoIOYuvInputFileList[layer]->open( m_pchInputFileList[layer],     false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
570    m_acTVideoIOYuvInputFileList[layer]->skipFrames( m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
571
572    if (m_pchReconFileList[layer])
573    {
574      m_acTVideoIOYuvReconFileList[layer]->open( m_pchReconFileList[layer], true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC);  // write mode
575    }
576    m_acTEncTopList[layer]->create();
577  }
578#else
579  // Video I/O
580  m_cTVideoIOYuvInputFile.open( m_pchInputFile,     false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
581  m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
582
583  if (m_pchReconFile)
584    m_cTVideoIOYuvReconFile.open(m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC);  // write mode
585 
586  // Neo Decoder
587  m_cTEncTop.create();
588#endif
589}
590
591Void TAppEncTop::xDestroyLib()
592{
593#if H_MV
594  // destroy ROM
595  destroyROM();
596
597  for(Int layer=0; layer<m_numberOfLayers; layer++)
598  {
599    m_acTVideoIOYuvInputFileList[layer]->close();
600    m_acTVideoIOYuvReconFileList[layer]->close();
601    delete m_acTVideoIOYuvInputFileList[layer] ; 
602    m_acTVideoIOYuvInputFileList[layer] = NULL;
603    delete m_acTVideoIOYuvReconFileList[layer] ; 
604    m_acTVideoIOYuvReconFileList[layer] = NULL;
605    m_acTEncTopList[layer]->deletePicBuffer();
606    m_acTEncTopList[layer]->destroy();
607    delete m_acTEncTopList[layer] ; 
608    m_acTEncTopList[layer] = NULL;
609    delete m_picYuvRec[layer] ; 
610    m_picYuvRec[layer] = NULL;
611  }
612#else
613  // Video I/O
614  m_cTVideoIOYuvInputFile.close();
615  m_cTVideoIOYuvReconFile.close();
616 
617  // Neo Decoder
618  m_cTEncTop.destroy();
619#endif
620}
621
622Void TAppEncTop::xInitLib()
623{
624#if H_MV
625  for(Int layer=0; layer<m_numberOfLayers; layer++)
626  {
627    m_acTEncTopList[layer]->init( );
628  }
629#else
630  m_cTEncTop.init();
631#endif
632}
633
634// ====================================================================================================================
635// Public member functions
636// ====================================================================================================================
637
638/**
639 - create internal class
640 - initialize internal variable
641 - until the end of input YUV file, call encoding function in TEncTop class
642 - delete allocated buffers
643 - destroy internal class
644 .
645 */
646Void TAppEncTop::encode()
647{
648  fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out);
649  if (!bitstreamFile)
650  {
651    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile);
652    exit(EXIT_FAILURE);
653  }
654
655  TComPicYuv*       pcPicYuvOrg = new TComPicYuv;
656  TComPicYuv*       pcPicYuvRec = NULL;
657 
658  // initialize internal class & member variables
659  xInitLibCfg();
660  xCreateLib();
661  xInitLib();
662 
663  // main encoder loop
664#if H_MV
665  Bool  allEos = false;
666  std::vector<Bool>  eos ;
667  std::vector<Bool>  flush ; 
668 
669  Int gopSize    = 1;
670  Int maxGopSize = 0;
671  maxGopSize = (std::max)(maxGopSize, m_acTEncTopList[0]->getGOPSize()); 
672 
673  for(Int layer=0; layer < m_numberOfLayers; layer++ )
674  {
675    eos  .push_back( false );
676    flush.push_back( false );
677  }
678#else
679  Int   iNumEncoded = 0;
680  Bool  bEos = false;
681#endif
682 
683  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
684
685  // allocate original YUV buffer
686  pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
687 
688#if H_MV
689  while ( !allEos )
690  {
691    for(Int layer=0; layer < m_numberOfLayers; layer++ )
692    {
693      Int frmCnt = 0;
694      while ( !eos[layer] && !(frmCnt == gopSize))
695      {
696        // get buffers
697        xGetBuffer(pcPicYuvRec, layer);
698
699        // read input YUV file
700        m_acTVideoIOYuvInputFileList[layer]->read      ( pcPicYuvOrg, m_aiPad );
701        m_acTEncTopList             [layer]->initNewPic( pcPicYuvOrg );
702
703        // increase number of received frames
704        m_frameRcvd[layer]++;
705       
706        frmCnt++;
707
708        eos[layer] = (m_frameRcvd[layer] == m_framesToBeEncoded);
709        allEos = allEos||eos[layer];
710
711        // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
712        if (m_acTVideoIOYuvInputFileList[layer]->isEof())
713        {
714          flush          [layer] = true;
715          eos            [layer] = true;
716          m_frameRcvd    [layer]--;
717          m_acTEncTopList[layer]->setFramesToBeEncoded(m_frameRcvd[layer]);
718        }
719      }
720    }
721    for ( Int gopId=0; gopId < gopSize; gopId++ )
722    {
723#if H_3D
724      UInt iNextPoc = m_acTEncTopList[0] -> getFrameId( gopId );
725      if ( iNextPoc < m_framesToBeEncoded )
726      {
727        m_cCameraData.update( iNextPoc );
728      }
729#endif
730      for(Int layer=0; layer < m_numberOfLayers; layer++ )
731      {
732#if H_3D_VSO       
733          if( m_bUseVSO && m_bUseEstimatedVSD && iNextPoc < m_framesToBeEncoded )
734          {
735            m_cCameraData.setDispCoeff( iNextPoc, m_acTEncTopList[layer]->getViewIndex() );
736            m_acTEncTopList[layer]  ->setDispCoeff( m_cCameraData.getDispCoeff() );
737          }
738#endif
739        Int   iNumEncoded = 0;
740
741        // call encoding function for one frame         
742        m_acTEncTopList[layer]->encode( eos[layer], flush[layer] ? 0 : pcPicYuvOrg, *m_picYuvRec[layer], outputAccessUnits, iNumEncoded, gopId );       
743        xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits, layer);
744        outputAccessUnits.clear();
745      }
746    }
747    gopSize = maxGopSize;
748  }
749  for(Int layer=0; layer < m_numberOfLayers; layer++ )
750  {
751    m_acTEncTopList[layer]->printSummary( m_acTEncTopList[layer]->getNumAllPicCoded() );
752  }
753#else
754  while ( !bEos )
755  {
756    // get buffers
757    xGetBuffer(pcPicYuvRec);
758
759    // read input YUV file
760    m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, m_aiPad );
761
762    // increase number of received frames
763    m_iFrameRcvd++;
764
765    bEos = (m_iFrameRcvd == m_framesToBeEncoded);
766
767    Bool flush = 0;
768    // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
769    if (m_cTVideoIOYuvInputFile.isEof())
770    {
771      flush = true;
772      bEos = true;
773      m_iFrameRcvd--;
774      m_cTEncTop.setFramesToBeEncoded(m_iFrameRcvd);
775    }
776
777    // call encoding function for one frame
778    m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded );
779   
780    // write bistream to file if necessary
781    if ( iNumEncoded > 0 )
782    {
783      xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits);
784      outputAccessUnits.clear();
785    }
786  }
787
788  m_cTEncTop.printSummary();
789#endif
790
791  // delete original YUV buffer
792  pcPicYuvOrg->destroy();
793  delete pcPicYuvOrg;
794  pcPicYuvOrg = NULL;
795 
796#if !H_MV
797  // delete used buffers in encoder class
798  m_cTEncTop.deletePicBuffer();
799#endif
800
801  // delete buffers & classes
802  xDeleteBuffer();
803  xDestroyLib();
804 
805  printRateSummary();
806
807  return;
808}
809
810// ====================================================================================================================
811// Protected member functions
812// ====================================================================================================================
813
814/**
815 - application has picture buffer list with size of GOP
816 - picture buffer list acts as ring buffer
817 - end of the list has the latest picture
818 .
819 */
820#if H_MV
821Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer)
822#else
823Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec)
824#endif
825{
826  assert( m_iGOPSize > 0 );
827 
828  // org. buffer
829#if H_MV
830  if ( m_picYuvRec[layer]->size() == (UInt)m_iGOPSize )
831  {
832    rpcPicYuvRec = m_picYuvRec[layer]->popFront();
833#else
834  if ( m_cListPicYuvRec.size() == (UInt)m_iGOPSize )
835  {
836    rpcPicYuvRec = m_cListPicYuvRec.popFront();
837#endif
838
839  }
840  else
841  {
842    rpcPicYuvRec = new TComPicYuv;
843   
844    rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
845
846  }
847#if H_MV
848  m_picYuvRec[layer]->pushBack( rpcPicYuvRec );
849#else
850  m_cListPicYuvRec.pushBack( rpcPicYuvRec );
851#endif
852}
853
854Void TAppEncTop::xDeleteBuffer( )
855{
856#if H_MV
857  for(Int layer=0; layer<m_picYuvRec.size(); layer++)
858  {
859    if(m_picYuvRec[layer])
860    {
861      TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_picYuvRec[layer]->begin();
862      Int iSize = Int( m_picYuvRec[layer]->size() );
863#else
864  TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvRec.begin();
865 
866  Int iSize = Int( m_cListPicYuvRec.size() );
867#endif
868
869  for ( Int i = 0; i < iSize; i++ )
870  {
871    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
872    pcPicYuvRec->destroy();
873    delete pcPicYuvRec; pcPicYuvRec = NULL;
874  }
875
876#if H_MV
877    }
878  }
879#endif 
880}
881
882/** \param iNumEncoded  number of encoded frames
883 */
884#if H_MV
885Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, std::list<AccessUnit>& accessUnits, UInt layerId)
886#else
887Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
888#endif
889{
890  Int i;
891 
892#if H_MV
893  if( iNumEncoded > 0 )
894  {
895    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_picYuvRec[layerId]->end();
896#else
897  TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
898  list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
899#endif
900
901  for ( i = 0; i < iNumEncoded; i++ )
902  {
903    --iterPicYuvRec;
904  }
905 
906  for ( i = 0; i < iNumEncoded; i++ )
907  {
908    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
909#if H_MV
910      if (m_pchReconFileList[layerId])
911      {
912        m_acTVideoIOYuvReconFileList[layerId]->write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
913      }
914    }
915  }
916  if( ! accessUnits.empty() )
917  {
918    list<AccessUnit>::iterator aUIter;
919    for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ )
920    {
921      const vector<unsigned>& stats = writeAnnexB(bitstreamFile, *aUIter);
922      rateStatsAccum(*aUIter, stats);
923    }
924  }
925#else
926    if (m_pchReconFile)
927    {
928      m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
929    }
930
931    const AccessUnit& au = *(iterBitstream++);
932    const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
933    rateStatsAccum(au, stats);
934  }
935#endif
936}
937
938/**
939 *
940 */
941void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& annexBsizes)
942{
943  AccessUnit::const_iterator it_au = au.begin();
944  vector<UInt>::const_iterator it_stats = annexBsizes.begin();
945
946  for (; it_au != au.end(); it_au++, it_stats++)
947  {
948    switch ((*it_au)->m_nalUnitType)
949    {
950    case NAL_UNIT_CODED_SLICE_TRAIL_R:
951    case NAL_UNIT_CODED_SLICE_TRAIL_N:
952    case NAL_UNIT_CODED_SLICE_TLA_R:
953    case NAL_UNIT_CODED_SLICE_TSA_N:
954    case NAL_UNIT_CODED_SLICE_STSA_R:
955    case NAL_UNIT_CODED_SLICE_STSA_N:
956    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
957    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
958    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
959    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
960    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
961    case NAL_UNIT_CODED_SLICE_CRA:
962    case NAL_UNIT_CODED_SLICE_RADL_N:
963    case NAL_UNIT_CODED_SLICE_RADL_R:
964    case NAL_UNIT_CODED_SLICE_RASL_N:
965    case NAL_UNIT_CODED_SLICE_RASL_R:
966    case NAL_UNIT_VPS:
967    case NAL_UNIT_SPS:
968    case NAL_UNIT_PPS:
969      m_essentialBytes += *it_stats;
970      break;
971    default:
972      break;
973    }
974
975    m_totalBytes += *it_stats;
976  }
977}
978
979void TAppEncTop::printRateSummary()
980{
981#if H_MV
982  Double time = (Double) m_frameRcvd[0] / m_iFrameRate;
983  printf("\n");
984#else
985  Double time = (Double) m_iFrameRcvd / m_iFrameRate;
986#endif
987  printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time);
988#if VERBOSE_RATE
989  printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time);
990#endif
991}
992
993#if H_3D_DIM_DLT
994Void TAppEncTop::xAnalyzeInputBaseDepth(UInt layer, UInt uiNumFrames, TComVPS* vps)
995{
996  TComPicYuv*       pcDepthPicYuvOrg = new TComPicYuv;
997  // allocate original YUV buffer
998  pcDepthPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
999 
1000  TVideoIOYuv* depthVideoFile = new TVideoIOYuv;
1001 
1002  UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1);
1003 
1004  Bool abValidDepths[256];
1005 
1006  depthVideoFile->open( m_pchInputFileList[layer], false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
1007 
1008  // initialize boolean array
1009  for(Int p=0; p<=uiMaxDepthValue; p++)
1010    abValidDepths[p] = false;
1011 
1012  Int iHeight   = pcDepthPicYuvOrg->getHeight();
1013  Int iWidth    = pcDepthPicYuvOrg->getWidth();
1014  Int iStride   = pcDepthPicYuvOrg->getStride();
1015 
1016  Pel* pInDM    = pcDepthPicYuvOrg->getLumaAddr();
1017 
1018  for(Int uiFrame=0; uiFrame < uiNumFrames; uiFrame++ )
1019  {
1020    depthVideoFile->read( pcDepthPicYuvOrg, m_aiPad );
1021   
1022    // check all pixel values
1023    for (Int i=0; i<iHeight; i++)
1024    {
1025      Int rowOffset = i*iStride;
1026     
1027      for (Int j=0; j<iWidth; j++)
1028      {
1029        Pel depthValue = pInDM[rowOffset+j];
1030        abValidDepths[depthValue] = true;
1031      }
1032    }
1033  }
1034 
1035  depthVideoFile->close();
1036  delete depthVideoFile; 
1037 
1038  pcDepthPicYuvOrg->destroy();
1039  delete pcDepthPicYuvOrg;
1040 
1041  // convert boolean array to idx2Depth LUT
1042  Int* aiIdx2DepthValue = (Int*) calloc(uiMaxDepthValue, sizeof(Int));
1043  Int iNumDepthValues = 0;
1044  for(Int p=0; p<=uiMaxDepthValue; p++)
1045  {
1046    if( abValidDepths[p] == true)
1047    {
1048      aiIdx2DepthValue[iNumDepthValues++] = p;
1049    }
1050  }
1051 
1052  if( uiNumFrames == 0 || numBitsForValue(iNumDepthValues) == g_bitDepthY )
1053  {
1054    // don't use DLT
1055    vps->setUseDLTFlag(layer, false);
1056  }
1057 
1058  // assign LUT
1059  if( vps->getUseDLTFlag(layer) )
1060    vps->setDepthLUTs(layer, aiIdx2DepthValue, iNumDepthValues);
1061 
1062  // free temporary memory
1063  free(aiIdx2DepthValue);
1064}
1065#endif
1066
1067#if H_MV
1068Void TAppEncTop::xSetDimensionIdAndLength( TComVPS& vps )
1069{   
1070  vps.setScalabilityMask( m_scalabilityMask ); 
1071  for( Int dim = 0; dim < m_dimIds.size(); dim++ )
1072  {
1073    vps.setDimensionIdLen( dim, m_dimensionIdLen[ dim ] );
1074    for( Int layer = 0; layer < vps.getMaxLayers(); layer++ )
1075    {       
1076      vps.setDimensionId( layer, dim, m_dimIds[ dim ][ layer ] );       
1077    } 
1078  }
1079}
1080
1081Void TAppEncTop::xSetDirectDependencyFlags( TComVPS& vps )
1082{
1083  for( Int layer = 0; layer < m_numberOfLayers; layer++ )
1084  {
1085    if( m_GOPListMvc[layer][MAX_GOP].m_POC == -1 )
1086    {
1087      continue;
1088    }
1089    for( Int i = 0; i < getGOPSize()+1; i++ ) 
1090    {
1091      GOPEntry ge = ( i < getGOPSize() ) ? m_GOPListMvc[layer][i] : m_GOPListMvc[layer][MAX_GOP];
1092      for( Int j = 0; j < ge.m_numInterViewRefPics; j++ )
1093      {
1094        Int interLayerRef = layer + ge.m_interViewRefs[j];
1095        vps.setDirectDependencyFlag( layer, interLayerRef, true );
1096      }
1097    }
1098  }
1099
1100  vps.checkVPSExtensionSyntax(); 
1101  vps.calcIvRefLayers();
1102}
1103
1104Void TAppEncTop::xSetLayerIds( TComVPS& vps )
1105{
1106  vps.setSplittingFlag     ( m_splittingFlag );
1107
1108  Bool nuhLayerIdPresentFlag = !( m_layerIdInNuh.size() == 1 ); 
1109  Int  maxNuhLayerId = nuhLayerIdPresentFlag ? xGetMax( m_layerIdInNuh ) : ( m_numberOfLayers - 1 ) ; 
1110
1111  vps.setMaxNuhLayerId( maxNuhLayerId ); 
1112  vps.setVpsNuhLayerIdPresentFlag( nuhLayerIdPresentFlag ); 
1113
1114  for (Int layer = 0; layer < m_numberOfLayers; layer++ )
1115  {
1116    vps.setLayerIdInNuh( layer, nuhLayerIdPresentFlag ? m_layerIdInNuh[ layer ] : layer ); 
1117    vps.setLayerIdInVps( vps.getLayerIdInNuh( layer ), layer ); 
1118  }
1119}
1120
1121Int TAppEncTop::xGetMax( std::vector<Int>& vec )
1122{
1123  Int maxVec = 0; 
1124  for ( Int i = 0; i < vec.size(); i++)   
1125    maxVec = max( vec[i], maxVec ); 
1126  return maxVec;
1127}
1128#endif
1129#if H_3D_GEN
1130Void TAppEncTop::xSetVPSExtension2( TComVPS& vps )
1131{
1132  for ( Int layer = 0; layer < vps.getMaxLayers(); layer++ )
1133  {
1134    Bool isDepth      = ( vps.getDepthId( layer ) == 1 ) ;
1135    Bool isLayerZero  = ( layer == 0 ); 
1136
1137#if H_3D_ARP
1138    vps.setUseAdvRP        ( layer, ( isDepth || isLayerZero ) ? 0 : m_uiUseAdvResPred );
1139    vps.setARPStepNum      ( layer, ( isDepth || isLayerZero ) ? 1 : H_3D_ARP_WFNR     );
1140#endif 
1141
1142#if H_3D_DIM
1143    vps.setVpsDepthModesFlag( layer, isDepth && !isLayerZero && (m_useDMM || m_useRBC || m_useSDC || m_useDLT ) );
1144#if H_3D_DIM_DLT
1145    vps.setUseDLTFlag( layer , isDepth && m_useDLT );
1146    if( vps.getUseDLTFlag( layer ) )
1147    {
1148      xAnalyzeInputBaseDepth(layer, max(m_iIntraPeriod, 24), &vps);
1149    }
1150#endif
1151#endif
1152
1153#if H_3D_IV_MERGE
1154    vps.setIvMvPredFlag         ( layer, !isLayerZero && !isDepth && m_ivMvPredFlag ); 
1155#endif
1156#if H_3D_NBDV_REF
1157    vps.setDepthRefinementFlag  ( layer, !isLayerZero && !isDepth && m_depthRefinementFlag );         
1158#endif
1159#if H_3D_VSP
1160    vps.setViewSynthesisPredFlag( layer, !isLayerZero && !isDepth && m_viewSynthesisPredFlag );         
1161#endif     
1162  } 
1163#if H_3D_TMVP
1164  vps.setIvMvScalingFlag( m_ivMvScalingFlag );   
1165#endif
1166}
1167#endif
1168//! \}
Note: See TracBrowser for help on using the repository browser.