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

Last change on this file since 531 was 531, checked in by tech, 12 years ago

Merged HTM-DEV-0.3-dev1 Rev. 520.

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