HEVC Test Model (HM)  HM-16.3
TAppEncTop.cpp
Go to the documentation of this file.
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-2015, 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 
38 #include <list>
39 #include <fstream>
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <fcntl.h>
43 #include <assert.h>
44 #include <iomanip>
45 
46 #include "TAppEncTop.h"
48 
49 using namespace std;
50 
53 
54 // ====================================================================================================================
55 // Constructor / destructor / initialization / destroy
56 // ====================================================================================================================
57 
59 {
60  m_iFrameRcvd = 0;
61  m_totalBytes = 0;
62  m_essentialBytes = 0;
63 }
64 
66 {
67 }
68 
70 {
71  TComVPS vps;
72 
73  vps.setMaxTLayers ( m_maxTempLayer );
74  if (m_maxTempLayer == 1)
75  {
76  vps.setTemporalNestingFlag(true);
77  }
78  vps.setMaxLayers ( 1 );
79  for(Int i = 0; i < MAX_TLAYER; i++)
80  {
81  vps.setNumReorderPics ( m_numReorderPics[i], i );
82  vps.setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i );
83  }
84  m_cTEncTop.setVPS(&vps);
85 
86  m_cTEncTop.setProfile ( m_profile);
87  m_cTEncTop.setLevel ( m_levelTier, m_level);
88  m_cTEncTop.setProgressiveSourceFlag ( m_progressiveSourceFlag);
89  m_cTEncTop.setInterlacedSourceFlag ( m_interlacedSourceFlag);
90  m_cTEncTop.setNonPackedConstraintFlag ( m_nonPackedConstraintFlag);
91  m_cTEncTop.setFrameOnlyConstraintFlag ( m_frameOnlyConstraintFlag);
92  m_cTEncTop.setBitDepthConstraintValue ( m_bitDepthConstraint );
93  m_cTEncTop.setChromaFormatConstraintValue ( m_chromaFormatConstraint );
94  m_cTEncTop.setIntraConstraintFlag ( m_intraConstraintFlag );
95  m_cTEncTop.setLowerBitRateConstraintFlag ( m_lowerBitRateConstraintFlag );
96 
97  m_cTEncTop.setPrintMSEBasedSequencePSNR ( m_printMSEBasedSequencePSNR);
98  m_cTEncTop.setPrintFrameMSE ( m_printFrameMSE);
99  m_cTEncTop.setPrintSequenceMSE ( m_printSequenceMSE);
100  m_cTEncTop.setCabacZeroWordPaddingEnabled ( m_cabacZeroWordPaddingEnabled );
101 
102  m_cTEncTop.setFrameRate ( m_iFrameRate );
103  m_cTEncTop.setFrameSkip ( m_FrameSkip );
104  m_cTEncTop.setSourceWidth ( m_iSourceWidth );
105  m_cTEncTop.setSourceHeight ( m_iSourceHeight );
106  m_cTEncTop.setConformanceWindow ( m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom );
107  m_cTEncTop.setFramesToBeEncoded ( m_framesToBeEncoded );
108 
109  //====== Coding Structure ========
110  m_cTEncTop.setIntraPeriod ( m_iIntraPeriod );
111  m_cTEncTop.setDecodingRefreshType ( m_iDecodingRefreshType );
112  m_cTEncTop.setGOPSize ( m_iGOPSize );
113  m_cTEncTop.setGopList ( m_GOPList );
114  m_cTEncTop.setExtraRPSs ( m_extraRPSs );
115  for(Int i = 0; i < MAX_TLAYER; i++)
116  {
117  m_cTEncTop.setNumReorderPics ( m_numReorderPics[i], i );
118  m_cTEncTop.setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i );
119  }
120  for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
121  {
122  m_cTEncTop.setLambdaModifier ( uiLoop, m_adLambdaModifier[ uiLoop ] );
123  }
124  m_cTEncTop.setQP ( m_iQP );
125 
126  m_cTEncTop.setPad ( m_aiPad );
127 
128  m_cTEncTop.setMaxTempLayer ( m_maxTempLayer );
129  m_cTEncTop.setUseAMP( m_enableAMP );
130 
131  //===== Slice ========
132 
133  //====== Loop/Deblock Filter ========
134  m_cTEncTop.setLoopFilterDisable ( m_bLoopFilterDisable );
135  m_cTEncTop.setLoopFilterOffsetInPPS ( m_loopFilterOffsetInPPS );
136  m_cTEncTop.setLoopFilterBetaOffset ( m_loopFilterBetaOffsetDiv2 );
137  m_cTEncTop.setLoopFilterTcOffset ( m_loopFilterTcOffsetDiv2 );
138  m_cTEncTop.setDeblockingFilterControlPresent ( m_DeblockingFilterControlPresent);
139  m_cTEncTop.setDeblockingFilterMetric ( m_DeblockingFilterMetric );
140 
141  //====== Motion search ========
142  m_cTEncTop.setFastSearch ( m_iFastSearch );
143  m_cTEncTop.setSearchRange ( m_iSearchRange );
144  m_cTEncTop.setBipredSearchRange ( m_bipredSearchRange );
145 
146  //====== Quality control ========
147  m_cTEncTop.setMaxDeltaQP ( m_iMaxDeltaQP );
148  m_cTEncTop.setMaxCuDQPDepth ( m_iMaxCuDQPDepth );
149  m_cTEncTop.setMaxCUChromaQpAdjustmentDepth ( m_maxCUChromaQpAdjustmentDepth );
150  m_cTEncTop.setChromaCbQpOffset ( m_cbQpOffset );
151  m_cTEncTop.setChromaCrQpOffset ( m_crQpOffset );
152 
153  m_cTEncTop.setChromaFormatIdc ( m_chromaFormatIDC );
154 
155 #if ADAPTIVE_QP_SELECTION
156  m_cTEncTop.setUseAdaptQpSelect ( m_bUseAdaptQpSelect );
157 #endif
158 
159  m_cTEncTop.setUseAdaptiveQP ( m_bUseAdaptiveQP );
160  m_cTEncTop.setQPAdaptationRange ( m_iQPAdaptationRange );
161  m_cTEncTop.setUseExtendedPrecision ( m_useExtendedPrecision );
162  m_cTEncTop.setUseHighPrecisionPredictionWeighting ( m_useHighPrecisionPredictionWeighting );
163  //====== Tool list ========
164  m_cTEncTop.setDeltaQpRD ( m_uiDeltaQpRD );
165  m_cTEncTop.setUseASR ( m_bUseASR );
166  m_cTEncTop.setUseHADME ( m_bUseHADME );
167  m_cTEncTop.setdQPs ( m_aidQP );
168  m_cTEncTop.setUseRDOQ ( m_useRDOQ );
169  m_cTEncTop.setUseRDOQTS ( m_useRDOQTS );
170  m_cTEncTop.setRDpenalty ( m_rdPenalty );
171  m_cTEncTop.setQuadtreeTULog2MaxSize ( m_uiQuadtreeTULog2MaxSize );
172  m_cTEncTop.setQuadtreeTULog2MinSize ( m_uiQuadtreeTULog2MinSize );
173  m_cTEncTop.setQuadtreeTUMaxDepthInter ( m_uiQuadtreeTUMaxDepthInter );
174  m_cTEncTop.setQuadtreeTUMaxDepthIntra ( m_uiQuadtreeTUMaxDepthIntra );
175  m_cTEncTop.setUseFastEnc ( m_bUseFastEnc );
176  m_cTEncTop.setUseEarlyCU ( m_bUseEarlyCU );
177  m_cTEncTop.setUseFastDecisionForMerge ( m_useFastDecisionForMerge );
178  m_cTEncTop.setUseCbfFastMode ( m_bUseCbfFastMode );
179  m_cTEncTop.setUseEarlySkipDetection ( m_useEarlySkipDetection );
180  m_cTEncTop.setUseCrossComponentPrediction ( m_useCrossComponentPrediction );
181  m_cTEncTop.setUseReconBasedCrossCPredictionEstimate ( m_reconBasedCrossCPredictionEstimate );
182  m_cTEncTop.setSaoOffsetBitShift ( CHANNEL_TYPE_LUMA , m_saoOffsetBitShift[CHANNEL_TYPE_LUMA] );
183  m_cTEncTop.setSaoOffsetBitShift ( CHANNEL_TYPE_CHROMA, m_saoOffsetBitShift[CHANNEL_TYPE_CHROMA] );
184  m_cTEncTop.setUseTransformSkip ( m_useTransformSkip );
185  m_cTEncTop.setUseTransformSkipFast ( m_useTransformSkipFast );
186  m_cTEncTop.setUseResidualRotation ( m_useResidualRotation );
187  m_cTEncTop.setUseSingleSignificanceMapContext ( m_useSingleSignificanceMapContext );
188  m_cTEncTop.setUseGolombRiceParameterAdaptation ( m_useGolombRiceParameterAdaptation );
189  m_cTEncTop.setAlignCABACBeforeBypass ( m_alignCABACBeforeBypass );
190  m_cTEncTop.setTransformSkipLog2MaxSize ( m_transformSkipLog2MaxSize );
191  for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++)
192  {
193  m_cTEncTop.setUseResidualDPCM ( RDPCMSignallingMode(signallingModeIndex), m_useResidualDPCM[signallingModeIndex]);
194  }
195  m_cTEncTop.setUseConstrainedIntraPred ( m_bUseConstrainedIntraPred );
196  m_cTEncTop.setPCMLog2MinSize ( m_uiPCMLog2MinSize);
197  m_cTEncTop.setUsePCM ( m_usePCM );
198  m_cTEncTop.setPCMLog2MaxSize ( m_pcmLog2MaxSize);
199  m_cTEncTop.setMaxNumMergeCand ( m_maxNumMergeCand );
200 
201 
202  //====== Weighted Prediction ========
203  m_cTEncTop.setUseWP ( m_useWeightedPred );
204  m_cTEncTop.setWPBiPred ( m_useWeightedBiPred );
205  //====== Parallel Merge Estimation ========
206  m_cTEncTop.setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 );
207 
208  //====== Slice ========
209  m_cTEncTop.setSliceMode ( (SliceConstraint) m_sliceMode );
210  m_cTEncTop.setSliceArgument ( m_sliceArgument );
211 
212  //====== Dependent Slice ========
213  m_cTEncTop.setSliceSegmentMode ( (SliceConstraint) m_sliceSegmentMode );
214  m_cTEncTop.setSliceSegmentArgument ( m_sliceSegmentArgument );
215 
216  if(m_sliceMode == NO_SLICES )
217  {
218  m_bLFCrossSliceBoundaryFlag = true;
219  }
220  m_cTEncTop.setLFCrossSliceBoundaryFlag ( m_bLFCrossSliceBoundaryFlag );
221  m_cTEncTop.setUseSAO ( m_bUseSAO );
222  m_cTEncTop.setMaxNumOffsetsPerPic ( m_maxNumOffsetsPerPic);
223 
224  m_cTEncTop.setSaoCtuBoundary ( m_saoCtuBoundary);
225  m_cTEncTop.setPCMInputBitDepthFlag ( m_bPCMInputBitDepthFlag);
226  m_cTEncTop.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag);
227 
228  m_cTEncTop.setDisableIntraReferenceSmoothing (!m_enableIntraReferenceSmoothing );
229  m_cTEncTop.setDecodedPictureHashSEIEnabled ( m_decodedPictureHashSEIEnabled );
230  m_cTEncTop.setRecoveryPointSEIEnabled ( m_recoveryPointSEIEnabled );
231  m_cTEncTop.setBufferingPeriodSEIEnabled ( m_bufferingPeriodSEIEnabled );
232  m_cTEncTop.setPictureTimingSEIEnabled ( m_pictureTimingSEIEnabled );
233  m_cTEncTop.setToneMappingInfoSEIEnabled ( m_toneMappingInfoSEIEnabled );
234  m_cTEncTop.setTMISEIToneMapId ( m_toneMapId );
235  m_cTEncTop.setTMISEIToneMapCancelFlag ( m_toneMapCancelFlag );
236  m_cTEncTop.setTMISEIToneMapPersistenceFlag ( m_toneMapPersistenceFlag );
237  m_cTEncTop.setTMISEICodedDataBitDepth ( m_toneMapCodedDataBitDepth );
238  m_cTEncTop.setTMISEITargetBitDepth ( m_toneMapTargetBitDepth );
239  m_cTEncTop.setTMISEIModelID ( m_toneMapModelId );
240  m_cTEncTop.setTMISEIMinValue ( m_toneMapMinValue );
241  m_cTEncTop.setTMISEIMaxValue ( m_toneMapMaxValue );
242  m_cTEncTop.setTMISEISigmoidMidpoint ( m_sigmoidMidpoint );
243  m_cTEncTop.setTMISEISigmoidWidth ( m_sigmoidWidth );
244  m_cTEncTop.setTMISEIStartOfCodedInterva ( m_startOfCodedInterval );
245  m_cTEncTop.setTMISEINumPivots ( m_numPivots );
246  m_cTEncTop.setTMISEICodedPivotValue ( m_codedPivotValue );
247  m_cTEncTop.setTMISEITargetPivotValue ( m_targetPivotValue );
248  m_cTEncTop.setTMISEICameraIsoSpeedIdc ( m_cameraIsoSpeedIdc );
249  m_cTEncTop.setTMISEICameraIsoSpeedValue ( m_cameraIsoSpeedValue );
250  m_cTEncTop.setTMISEIExposureIndexIdc ( m_exposureIndexIdc );
251  m_cTEncTop.setTMISEIExposureIndexValue ( m_exposureIndexValue );
252  m_cTEncTop.setTMISEIExposureCompensationValueSignFlag ( m_exposureCompensationValueSignFlag );
253  m_cTEncTop.setTMISEIExposureCompensationValueNumerator ( m_exposureCompensationValueNumerator );
254  m_cTEncTop.setTMISEIExposureCompensationValueDenomIdc ( m_exposureCompensationValueDenomIdc );
255  m_cTEncTop.setTMISEIRefScreenLuminanceWhite ( m_refScreenLuminanceWhite );
256  m_cTEncTop.setTMISEIExtendedRangeWhiteLevel ( m_extendedRangeWhiteLevel );
257  m_cTEncTop.setTMISEINominalBlackLevelLumaCodeValue ( m_nominalBlackLevelLumaCodeValue );
258  m_cTEncTop.setTMISEINominalWhiteLevelLumaCodeValue ( m_nominalWhiteLevelLumaCodeValue );
259  m_cTEncTop.setTMISEIExtendedWhiteLevelLumaCodeValue ( m_extendedWhiteLevelLumaCodeValue );
260  m_cTEncTop.setChromaSamplingFilterHintEnabled ( m_chromaSamplingFilterSEIenabled );
261  m_cTEncTop.setChromaSamplingHorFilterIdc ( m_chromaSamplingHorFilterIdc );
262  m_cTEncTop.setChromaSamplingVerFilterIdc ( m_chromaSamplingVerFilterIdc );
263  m_cTEncTop.setFramePackingArrangementSEIEnabled ( m_framePackingSEIEnabled );
264  m_cTEncTop.setFramePackingArrangementSEIType ( m_framePackingSEIType );
265  m_cTEncTop.setFramePackingArrangementSEIId ( m_framePackingSEIId );
266  m_cTEncTop.setFramePackingArrangementSEIQuincunx ( m_framePackingSEIQuincunx );
267  m_cTEncTop.setFramePackingArrangementSEIInterpretation ( m_framePackingSEIInterpretation );
268  m_cTEncTop.setSegmentedRectFramePackingArrangementSEIEnabled ( m_segmentedRectFramePackingSEIEnabled );
269  m_cTEncTop.setSegmentedRectFramePackingArrangementSEICancel ( m_segmentedRectFramePackingSEICancel );
270  m_cTEncTop.setSegmentedRectFramePackingArrangementSEIType ( m_segmentedRectFramePackingSEIType );
271  m_cTEncTop.setSegmentedRectFramePackingArrangementSEIPersistence( m_segmentedRectFramePackingSEIPersistence );
272  m_cTEncTop.setDisplayOrientationSEIAngle ( m_displayOrientationSEIAngle );
273  m_cTEncTop.setTemporalLevel0IndexSEIEnabled ( m_temporalLevel0IndexSEIEnabled );
274  m_cTEncTop.setGradualDecodingRefreshInfoEnabled ( m_gradualDecodingRefreshInfoEnabled );
275  m_cTEncTop.setNoDisplaySEITLayer ( m_noDisplaySEITLayer );
276  m_cTEncTop.setDecodingUnitInfoSEIEnabled ( m_decodingUnitInfoSEIEnabled );
277  m_cTEncTop.setSOPDescriptionSEIEnabled ( m_SOPDescriptionSEIEnabled );
278  m_cTEncTop.setScalableNestingSEIEnabled ( m_scalableNestingSEIEnabled );
279  m_cTEncTop.setTMCTSSEIEnabled ( m_tmctsSEIEnabled );
280  m_cTEncTop.setTimeCodeSEIEnabled ( m_timeCodeSEIEnabled );
281  m_cTEncTop.setNumberOfTimeSets ( m_timeCodeSEINumTs );
282  for(Int i = 0; i < m_timeCodeSEINumTs; i++)
283  {
284  m_cTEncTop.setTimeSet(m_timeSetArray[i], i);
285  }
286  m_cTEncTop.setKneeSEIEnabled ( m_kneeSEIEnabled );
287  m_cTEncTop.setKneeSEIId ( m_kneeSEIId );
288  m_cTEncTop.setKneeSEICancelFlag ( m_kneeSEICancelFlag );
289  m_cTEncTop.setKneeSEIPersistenceFlag ( m_kneeSEIPersistenceFlag );
290  m_cTEncTop.setKneeSEIInputDrange ( m_kneeSEIInputDrange );
291  m_cTEncTop.setKneeSEIInputDispLuminance ( m_kneeSEIInputDispLuminance );
292  m_cTEncTop.setKneeSEIOutputDrange ( m_kneeSEIOutputDrange );
293  m_cTEncTop.setKneeSEIOutputDispLuminance ( m_kneeSEIOutputDispLuminance );
294  m_cTEncTop.setKneeSEINumKneePointsMinus1 ( m_kneeSEINumKneePointsMinus1 );
295  m_cTEncTop.setKneeSEIInputKneePoint ( m_kneeSEIInputKneePoint );
296  m_cTEncTop.setKneeSEIOutputKneePoint ( m_kneeSEIOutputKneePoint );
297  m_cTEncTop.setMasteringDisplaySEI ( m_masteringDisplay );
298 
299  m_cTEncTop.setTileUniformSpacingFlag ( m_tileUniformSpacingFlag );
300  m_cTEncTop.setNumColumnsMinus1 ( m_numTileColumnsMinus1 );
301  m_cTEncTop.setNumRowsMinus1 ( m_numTileRowsMinus1 );
302  if(!m_tileUniformSpacingFlag)
303  {
304  m_cTEncTop.setColumnWidth ( m_tileColumnWidth );
305  m_cTEncTop.setRowHeight ( m_tileRowHeight );
306  }
307  m_cTEncTop.xCheckGSParameters();
308  Int uiTilesCount = (m_numTileRowsMinus1+1) * (m_numTileColumnsMinus1+1);
309  if(uiTilesCount == 1)
310  {
311  m_bLFCrossTileBoundaryFlag = true;
312  }
313  m_cTEncTop.setLFCrossTileBoundaryFlag ( m_bLFCrossTileBoundaryFlag );
314  m_cTEncTop.setWaveFrontSynchro ( m_iWaveFrontSynchro );
315  m_cTEncTop.setTMVPModeId ( m_TMVPModeId );
316  m_cTEncTop.setUseScalingListId ( m_useScalingListId );
317  m_cTEncTop.setScalingListFile ( m_scalingListFile );
318  m_cTEncTop.setSignHideFlag ( m_signHideFlag);
319  m_cTEncTop.setUseRateCtrl ( m_RCEnableRateControl );
320  m_cTEncTop.setTargetBitrate ( m_RCTargetBitrate );
321  m_cTEncTop.setKeepHierBit ( m_RCKeepHierarchicalBit );
322  m_cTEncTop.setLCULevelRC ( m_RCLCULevelRC );
323  m_cTEncTop.setUseLCUSeparateModel ( m_RCUseLCUSeparateModel );
324  m_cTEncTop.setInitialQP ( m_RCInitialQP );
325  m_cTEncTop.setForceIntraQP ( m_RCForceIntraQP );
326  m_cTEncTop.setTransquantBypassEnableFlag ( m_TransquantBypassEnableFlag );
327  m_cTEncTop.setCUTransquantBypassFlagForceValue ( m_CUTransquantBypassFlagForce );
328  m_cTEncTop.setCostMode ( m_costMode );
329  m_cTEncTop.setUseRecalculateQPAccordingToLambda ( m_recalculateQPAccordingToLambda );
330  m_cTEncTop.setUseStrongIntraSmoothing ( m_useStrongIntraSmoothing );
331  m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled );
332  m_cTEncTop.setVuiParametersPresentFlag ( m_vuiParametersPresentFlag );
333  m_cTEncTop.setAspectRatioInfoPresentFlag ( m_aspectRatioInfoPresentFlag);
334  m_cTEncTop.setAspectRatioIdc ( m_aspectRatioIdc );
335  m_cTEncTop.setSarWidth ( m_sarWidth );
336  m_cTEncTop.setSarHeight ( m_sarHeight );
337  m_cTEncTop.setOverscanInfoPresentFlag ( m_overscanInfoPresentFlag );
338  m_cTEncTop.setOverscanAppropriateFlag ( m_overscanAppropriateFlag );
339  m_cTEncTop.setVideoSignalTypePresentFlag ( m_videoSignalTypePresentFlag );
340  m_cTEncTop.setVideoFormat ( m_videoFormat );
341  m_cTEncTop.setVideoFullRangeFlag ( m_videoFullRangeFlag );
342  m_cTEncTop.setColourDescriptionPresentFlag ( m_colourDescriptionPresentFlag );
343  m_cTEncTop.setColourPrimaries ( m_colourPrimaries );
344  m_cTEncTop.setTransferCharacteristics ( m_transferCharacteristics );
345  m_cTEncTop.setMatrixCoefficients ( m_matrixCoefficients );
346  m_cTEncTop.setChromaLocInfoPresentFlag ( m_chromaLocInfoPresentFlag );
347  m_cTEncTop.setChromaSampleLocTypeTopField ( m_chromaSampleLocTypeTopField );
348  m_cTEncTop.setChromaSampleLocTypeBottomField ( m_chromaSampleLocTypeBottomField );
349  m_cTEncTop.setNeutralChromaIndicationFlag ( m_neutralChromaIndicationFlag );
350  m_cTEncTop.setDefaultDisplayWindow ( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset );
351  m_cTEncTop.setFrameFieldInfoPresentFlag ( m_frameFieldInfoPresentFlag );
352  m_cTEncTop.setPocProportionalToTimingFlag ( m_pocProportionalToTimingFlag );
353  m_cTEncTop.setNumTicksPocDiffOneMinus1 ( m_numTicksPocDiffOneMinus1 );
354  m_cTEncTop.setBitstreamRestrictionFlag ( m_bitstreamRestrictionFlag );
355  m_cTEncTop.setTilesFixedStructureFlag ( m_tilesFixedStructureFlag );
356  m_cTEncTop.setMotionVectorsOverPicBoundariesFlag ( m_motionVectorsOverPicBoundariesFlag );
357  m_cTEncTop.setMinSpatialSegmentationIdc ( m_minSpatialSegmentationIdc );
358  m_cTEncTop.setMaxBytesPerPicDenom ( m_maxBytesPerPicDenom );
359  m_cTEncTop.setMaxBitsPerMinCuDenom ( m_maxBitsPerMinCuDenom );
360  m_cTEncTop.setLog2MaxMvLengthHorizontal ( m_log2MaxMvLengthHorizontal );
361  m_cTEncTop.setLog2MaxMvLengthVertical ( m_log2MaxMvLengthVertical );
362 }
363 
365 {
366  // Video I/O
367  m_cTVideoIOYuvInputFile.open( m_pchInputFile, false, m_inputBitDepth, m_MSBExtendedBitDepth, m_internalBitDepth ); // read mode
368  m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1], m_InputChromaFormatIDC);
369 
370  if (m_pchReconFile)
371  {
372  m_cTVideoIOYuvReconFile.open(m_pchReconFile, true, m_outputBitDepth, m_outputBitDepth, m_internalBitDepth); // write mode
373  }
374 
375  // Neo Decoder
376  m_cTEncTop.create();
377 }
378 
380 {
381  // Video I/O
382  m_cTVideoIOYuvInputFile.close();
383  m_cTVideoIOYuvReconFile.close();
384 
385  // Neo Decoder
386  m_cTEncTop.destroy();
387 }
388 
390 {
391  m_cTEncTop.init(isFieldCoding);
392 }
393 
394 // ====================================================================================================================
395 // Public member functions
396 // ====================================================================================================================
397 
407 {
408  fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out);
409  if (!bitstreamFile)
410  {
411  fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile);
412  exit(EXIT_FAILURE);
413  }
414 
415  TComPicYuv* pcPicYuvOrg = new TComPicYuv;
416  TComPicYuv* pcPicYuvRec = NULL;
417 
418  // initialize internal class & member variables
419  xInitLibCfg();
420  xCreateLib();
421  xInitLib(m_isField);
422 
423  printChromaFormat();
424 
425  // main encoder loop
426  Int iNumEncoded = 0;
427  Bool bEos = false;
428 
429  const InputColourSpaceConversion ipCSC = m_inputColourSpaceConvert;
430  const InputColourSpaceConversion snrCSC = (!m_snrInternalColourSpace) ? m_inputColourSpaceConvert : IPCOLOURSPACE_UNCHANGED;
431 
432  list<AccessUnit> outputAccessUnits;
433 
434  TComPicYuv cPicYuvTrueOrg;
435 
436  // allocate original YUV buffer
437  if( m_isField )
438  {
439  pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeightOrg, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
440  cPicYuvTrueOrg.create(m_iSourceWidth, m_iSourceHeightOrg, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth);
441  }
442  else
443  {
444  pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
445  cPicYuvTrueOrg.create(m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth);
446  }
447 
448  while ( !bEos )
449  {
450  // get buffers
451  xGetBuffer(pcPicYuvRec);
452 
453  // read input YUV file
454  m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, &cPicYuvTrueOrg, ipCSC, m_aiPad, m_InputChromaFormatIDC );
455 
456  // increase number of received frames
457  m_iFrameRcvd++;
458 
459  bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) );
460 
461  Bool flush = 0;
462  // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
463  if (m_cTVideoIOYuvInputFile.isEof())
464  {
465  flush = true;
466  bEos = true;
467  m_iFrameRcvd--;
468  m_cTEncTop.setFramesToBeEncoded(m_iFrameRcvd);
469  }
470 
471  // call encoding function for one frame
472  if ( m_isField )
473  {
474  m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, flush ? 0 : &cPicYuvTrueOrg, snrCSC, m_cListPicYuvRec, outputAccessUnits, iNumEncoded, m_isTopFieldFirst );
475  }
476  else
477  {
478  m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, flush ? 0 : &cPicYuvTrueOrg, snrCSC, m_cListPicYuvRec, outputAccessUnits, iNumEncoded );
479  }
480 
481  // write bistream to file if necessary
482  if ( iNumEncoded > 0 )
483  {
484  xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits);
485  outputAccessUnits.clear();
486  }
487  }
488 
489  m_cTEncTop.printSummary(m_isField);
490 
491  // delete original YUV buffer
492  pcPicYuvOrg->destroy();
493  delete pcPicYuvOrg;
494  pcPicYuvOrg = NULL;
495 
496  // delete used buffers in encoder class
497  m_cTEncTop.deletePicBuffer();
498  cPicYuvTrueOrg.destroy();
499 
500  // delete buffers & classes
501  xDeleteBuffer();
502  xDestroyLib();
503 
504  printRateSummary();
505 
506  return;
507 }
508 
509 // ====================================================================================================================
510 // Protected member functions
511 // ====================================================================================================================
512 
520 {
521  assert( m_iGOPSize > 0 );
522 
523  // org. buffer
524  if ( m_cListPicYuvRec.size() >= (UInt)m_iGOPSize ) // buffer will be 1 element longer when using field coding, to maintain first field whilst processing second.
525  {
526  rpcPicYuvRec = m_cListPicYuvRec.popFront();
527 
528  }
529  else
530  {
531  rpcPicYuvRec = new TComPicYuv;
532 
533  rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
534 
535  }
536  m_cListPicYuvRec.pushBack( rpcPicYuvRec );
537 }
538 
540 {
541  TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.begin();
542 
543  Int iSize = Int( m_cListPicYuvRec.size() );
544 
545  for ( Int i = 0; i < iSize; i++ )
546  {
547  TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++);
548  pcPicYuvRec->destroy();
549  delete pcPicYuvRec; pcPicYuvRec = NULL;
550  }
551 
552 }
553 
560 Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
561 {
562  const InputColourSpaceConversion ipCSC = (!m_outputInternalColourSpace) ? m_inputColourSpaceConvert : IPCOLOURSPACE_UNCHANGED;
563 
564  if (m_isField)
565  {
566  //Reinterlace fields
567  Int i;
568  TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
569  list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
570 
571  for ( i = 0; i < iNumEncoded; i++ )
572  {
573  --iterPicYuvRec;
574  }
575 
576  for ( i = 0; i < iNumEncoded/2; i++ )
577  {
578  TComPicYuv* pcPicYuvRecTop = *(iterPicYuvRec++);
579  TComPicYuv* pcPicYuvRecBottom = *(iterPicYuvRec++);
580 
581  if (m_pchReconFile)
582  {
583  m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, NUM_CHROMA_FORMAT, m_isTopFieldFirst );
584  }
585 
586  const AccessUnit& auTop = *(iterBitstream++);
587  const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
588  rateStatsAccum(auTop, statsTop);
589 
590  const AccessUnit& auBottom = *(iterBitstream++);
591  const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom);
592  rateStatsAccum(auBottom, statsBottom);
593  }
594  }
595  else
596  {
597  Int i;
598 
599  TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
600  list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
601 
602  for ( i = 0; i < iNumEncoded; i++ )
603  {
604  --iterPicYuvRec;
605  }
606 
607  for ( i = 0; i < iNumEncoded; i++ )
608  {
609  TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++);
610  if (m_pchReconFile)
611  {
612  m_cTVideoIOYuvReconFile.write( pcPicYuvRec, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom );
613  }
614 
615  const AccessUnit& au = *(iterBitstream++);
616  const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
617  rateStatsAccum(au, stats);
618  }
619  }
620 }
621 
625 Void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& annexBsizes)
626 {
627  AccessUnit::const_iterator it_au = au.begin();
628  vector<UInt>::const_iterator it_stats = annexBsizes.begin();
629 
630  for (; it_au != au.end(); it_au++, it_stats++)
631  {
632  switch ((*it_au)->m_nalUnitType)
633  {
650  case NAL_UNIT_VPS:
651  case NAL_UNIT_SPS:
652  case NAL_UNIT_PPS:
653  m_essentialBytes += *it_stats;
654  break;
655  default:
656  break;
657  }
658 
659  m_totalBytes += *it_stats;
660  }
661 }
662 
664 {
665  Double time = (Double) m_iFrameRcvd / m_iFrameRate;
666  printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time);
667 #if VERBOSE_RATE
668  printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time);
669 #endif
670 }
671 
673 {
674  std::cout << std::setw(43) << "Input ChromaFormatIDC = ";
675  switch (m_InputChromaFormatIDC)
676  {
677  case CHROMA_400: std::cout << " 4:0:0"; break;
678  case CHROMA_420: std::cout << " 4:2:0"; break;
679  case CHROMA_422: std::cout << " 4:2:2"; break;
680  case CHROMA_444: std::cout << " 4:4:4"; break;
681  default:
682  std::cerr << "Invalid";
683  exit(1);
684  }
685  std::cout << std::endl;
686 
687  std::cout << std::setw(43) << "Output (internal) ChromaFormatIDC = ";
688  switch (m_cTEncTop.getChromaFormatIdc())
689  {
690  case CHROMA_400: std::cout << " 4:0:0"; break;
691  case CHROMA_420: std::cout << " 4:2:0"; break;
692  case CHROMA_422: std::cout << " 4:2:2"; break;
693  case CHROMA_444: std::cout << " 4:4:4"; break;
694  default:
695  std::cerr << "Invalid";
696  exit(1);
697  }
698  std::cout << "\n" << std::endl;
699 }
700 
Void rateStatsAccum(const AccessUnit &au, const std::vector< UInt > &stats)
Definition: TAppEncTop.cpp:625
Void printChromaFormat()
Definition: TAppEncTop.cpp:672
Void create(const Int iPicWidth, const Int iPicHeight, const ChromaFormat chromaFormatIDC, const UInt uiMaxCUWidth, const UInt uiMaxCUHeight, const UInt uiMaxCUDepth)
Definition: TComPicYuv.cpp:81
picture YUV buffer class
Definition: TComPicYuv.h:55
Encoder application class (header)
void Void
Definition: TypeDef.h:285
#define NULL
Definition: CommonDef.h:100
don't use slices / slice segments
Definition: TypeDef.h:564
virtual ~TAppEncTop()
Definition: TAppEncTop.cpp:65
Void xDeleteBuffer()
delete allocated buffers
Definition: TAppEncTop.cpp:539
unsigned int UInt
Definition: TypeDef.h:297
#define MAX_TLAYER
max number of temporal layer
Definition: CommonDef.h:192
Void xInitLib(Bool isFieldCoding)
initialize encoder class
Definition: TAppEncTop.cpp:389
STL namespace.
Void setNumReorderPics(UInt v, UInt tLayer)
Definition: TComSlice.h:488
Void setMaxLayers(UInt l)
Definition: TComSlice.h:483
Void xWriteOutput(std::ostream &bitstreamFile, Int iNumEncoded, const std::list< AccessUnit > &accessUnits)
write bitstream to file
Definition: TAppEncTop.cpp:560
Void setMaxDecPicBuffering(UInt v, UInt tLayer)
Definition: TComSlice.h:491
bool Bool
Definition: TypeDef.h:286
Void xCreateLib()
create files & encoder class
Definition: TAppEncTop.cpp:364
Void printRateSummary()
Definition: TAppEncTop.cpp:663
Void setMaxTLayers(UInt t)
Definition: TComSlice.h:480
SliceConstraint
Definition: TypeDef.h:562
Void xInitLibCfg()
initialize internal variables
Definition: TAppEncTop.cpp:69
RDPCMSignallingMode
Definition: TypeDef.h:335
Void xGetBuffer(TComPicYuv *&rpcPicYuvRec)
obtain required buffers
Definition: TAppEncTop.cpp:519
InputColourSpaceConversion
Definition: TypeDef.h:376
Void encode()
main encoding function
Definition: TAppEncTop.cpp:406
Void xDestroyLib()
destroy encoder class
Definition: TAppEncTop.cpp:379
list template
Definition: TComList.h:61
int Int
Definition: TypeDef.h:296
double Double
Definition: TypeDef.h:298
Void setTemporalNestingFlag(Bool t)
Definition: TComSlice.h:486
Void destroy()
Definition: TComPicYuv.cpp:146
static std::vector< UInt > writeAnnexB(std::ostream &out, const AccessUnit &au)
Definition: AnnexBwrite.h:53