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

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

Further minor cleanups.

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