source: 3DVCSoftware/branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/TAppEncTop.cpp @ 362

Last change on this file since 362 was 362, checked in by tech, 11 years ago

Update to HM-10.1.

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