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 | |
---|
48 | using namespace std; |
---|
49 | |
---|
50 | //! \ingroup TAppEncoder |
---|
51 | //! \{ |
---|
52 | |
---|
53 | // ==================================================================================================================== |
---|
54 | // Constructor / destructor / initialization / destroy |
---|
55 | // ==================================================================================================================== |
---|
56 | |
---|
57 | TAppEncTop::TAppEncTop() |
---|
58 | { |
---|
59 | m_iFrameRcvd = 0; |
---|
60 | m_totalBytes = 0; |
---|
61 | m_essentialBytes = 0; |
---|
62 | #if SVC_EXTENSION |
---|
63 | for(UInt layer=0; layer < MAX_LAYERS; layer++) |
---|
64 | { |
---|
65 | m_apcTEncTop[layer] = &m_acTEncTop[layer]; |
---|
66 | } |
---|
67 | #endif |
---|
68 | } |
---|
69 | |
---|
70 | TAppEncTop::~TAppEncTop() |
---|
71 | { |
---|
72 | } |
---|
73 | |
---|
74 | #if SVC_EXTENSION |
---|
75 | Void TAppEncTop::xInitLibCfg() |
---|
76 | { |
---|
77 | TComVPS* vps = m_acTEncTop[0].getVPS(); |
---|
78 | |
---|
79 | vps->setMaxTLayers ( m_maxTempLayer ); |
---|
80 | if (m_maxTempLayer == 1) |
---|
81 | { |
---|
82 | vps->setTemporalNestingFlag(true); |
---|
83 | } |
---|
84 | #if !VPS_RENAME |
---|
85 | vps.setMaxLayers ( 1 ); |
---|
86 | #endif |
---|
87 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
88 | { |
---|
89 | vps->setNumReorderPics ( m_numReorderPics[i], i ); |
---|
90 | vps->setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i ); |
---|
91 | } |
---|
92 | |
---|
93 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
94 | { |
---|
95 | //m_acTEncTop[layer].setVPS(&vps); |
---|
96 | m_acTEncTop[layer].setFrameRate ( m_acLayerCfg[layer].getFrameRate() ); |
---|
97 | m_acTEncTop[layer].setFrameSkip ( m_FrameSkip ); |
---|
98 | m_acTEncTop[layer].setSourceWidth ( m_acLayerCfg[layer].getSourceWidth() ); |
---|
99 | m_acTEncTop[layer].setSourceHeight ( m_acLayerCfg[layer].getSourceHeight() ); |
---|
100 | m_acTEncTop[layer].setConformanceMode ( m_acLayerCfg[layer].getConformanceMode() ); |
---|
101 | m_acTEncTop[layer].setConformanceWindow ( m_acLayerCfg[layer].m_confLeft, m_acLayerCfg[layer].m_confRight, m_acLayerCfg[layer].m_confTop, m_acLayerCfg[layer].m_confBottom ); |
---|
102 | m_acTEncTop[layer].setFramesToBeEncoded ( m_framesToBeEncoded ); |
---|
103 | |
---|
104 | m_acTEncTop[layer].setProfile(m_profile); |
---|
105 | m_acTEncTop[layer].setLevel(m_levelTier, m_level); |
---|
106 | #if L0046_CONSTRAINT_FLAGS |
---|
107 | m_acTEncTop[layer].setProgressiveSourceFlag(m_progressiveSourceFlag); |
---|
108 | m_acTEncTop[layer].setInterlacedSourceFlag(m_interlacedSourceFlag); |
---|
109 | m_acTEncTop[layer].setNonPackedConstraintFlag(m_nonPackedConstraintFlag); |
---|
110 | m_acTEncTop[layer].setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag); |
---|
111 | #endif |
---|
112 | |
---|
113 | #if REF_IDX_MFM |
---|
114 | m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : true); |
---|
115 | #endif |
---|
116 | // set layer ID |
---|
117 | m_acTEncTop[layer].setLayerId ( layer ); |
---|
118 | m_acTEncTop[layer].setNumLayer ( m_numLayers ); |
---|
119 | m_acTEncTop[layer].setLayerEnc(m_apcTEncTop); |
---|
120 | |
---|
121 | //====== Coding Structure ======== |
---|
122 | m_acTEncTop[layer].setIntraPeriod ( m_acLayerCfg[layer].m_iIntraPeriod ); |
---|
123 | m_acTEncTop[layer].setDecodingRefreshType ( m_iDecodingRefreshType ); |
---|
124 | m_acTEncTop[layer].setGOPSize ( m_iGOPSize ); |
---|
125 | m_acTEncTop[layer].setGopList ( m_GOPList ); |
---|
126 | m_acTEncTop[layer].setExtraRPSs ( m_extraRPSs ); |
---|
127 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
128 | { |
---|
129 | m_acTEncTop[layer].setNumReorderPics ( m_numReorderPics[i], i ); |
---|
130 | m_acTEncTop[layer].setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i ); |
---|
131 | } |
---|
132 | for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop ) |
---|
133 | { |
---|
134 | m_acTEncTop[layer].setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] ); |
---|
135 | } |
---|
136 | m_acTEncTop[layer].setQP ( m_acLayerCfg[layer].getIntQP() ); |
---|
137 | |
---|
138 | m_acTEncTop[layer].setPad ( m_acLayerCfg[layer].getPad() ); |
---|
139 | |
---|
140 | m_acTEncTop[layer].setMaxTempLayer ( m_maxTempLayer ); |
---|
141 | m_acTEncTop[layer].setUseAMP( m_enableAMP ); |
---|
142 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
143 | if(layer) |
---|
144 | { |
---|
145 | if(m_acLayerCfg[layer].getNumDirectRefLayers() == -1) |
---|
146 | { |
---|
147 | // Not included in the configuration file; assume that each layer depends on previous layer |
---|
148 | m_acTEncTop[layer].setNumDirectRefLayers (1); // One ref. layer |
---|
149 | m_acTEncTop[layer].setRefLayerId (0, layer - 1); // Previous layer |
---|
150 | } |
---|
151 | else |
---|
152 | { |
---|
153 | m_acTEncTop[layer].setNumDirectRefLayers ( m_acLayerCfg[layer].getNumDirectRefLayers() ); |
---|
154 | for(Int i = 0; i < m_acTEncTop[layer].getNumDirectRefLayers(); i++) |
---|
155 | { |
---|
156 | m_acTEncTop[layer].setRefLayerId ( i, m_acLayerCfg[layer].getRefLayerId(i)); |
---|
157 | } |
---|
158 | } |
---|
159 | } |
---|
160 | #endif |
---|
161 | //===== Slice ======== |
---|
162 | |
---|
163 | //====== Loop/Deblock Filter ======== |
---|
164 | m_acTEncTop[layer].setLoopFilterDisable ( m_bLoopFilterDisable ); |
---|
165 | m_acTEncTop[layer].setLoopFilterOffsetInPPS ( m_loopFilterOffsetInPPS ); |
---|
166 | m_acTEncTop[layer].setLoopFilterBetaOffset ( m_loopFilterBetaOffsetDiv2 ); |
---|
167 | m_acTEncTop[layer].setLoopFilterTcOffset ( m_loopFilterTcOffsetDiv2 ); |
---|
168 | m_acTEncTop[layer].setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent); |
---|
169 | #if L0386_DB_METRIC |
---|
170 | m_acTEncTop[layer].setDeblockingFilterMetric ( m_DeblockingFilterMetric ); |
---|
171 | #endif |
---|
172 | |
---|
173 | //====== Motion search ======== |
---|
174 | m_acTEncTop[layer].setFastSearch ( m_iFastSearch ); |
---|
175 | m_acTEncTop[layer].setSearchRange ( m_iSearchRange ); |
---|
176 | m_acTEncTop[layer].setBipredSearchRange ( m_bipredSearchRange ); |
---|
177 | |
---|
178 | //====== Quality control ======== |
---|
179 | m_acTEncTop[layer].setMaxDeltaQP ( m_iMaxDeltaQP ); |
---|
180 | m_acTEncTop[layer].setMaxCuDQPDepth ( m_iMaxCuDQPDepth ); |
---|
181 | |
---|
182 | m_acTEncTop[layer].setChromaCbQpOffset ( m_cbQpOffset ); |
---|
183 | m_acTEncTop[layer].setChromaCrQpOffset ( m_crQpOffset ); |
---|
184 | |
---|
185 | #if ADAPTIVE_QP_SELECTION |
---|
186 | m_acTEncTop[layer].setUseAdaptQpSelect ( m_bUseAdaptQpSelect ); |
---|
187 | #endif |
---|
188 | |
---|
189 | Int lowestQP; |
---|
190 | lowestQP = - 6*(g_bitDepthY - 8); // XXX: check |
---|
191 | |
---|
192 | if ((m_iMaxDeltaQP == 0 ) && (m_acLayerCfg[layer].getIntQP() == lowestQP) && (m_useLossless == true)) |
---|
193 | { |
---|
194 | m_bUseAdaptiveQP = false; |
---|
195 | } |
---|
196 | m_acTEncTop[layer].setUseAdaptiveQP ( m_bUseAdaptiveQP ); |
---|
197 | m_acTEncTop[layer].setQPAdaptationRange ( m_iQPAdaptationRange ); |
---|
198 | |
---|
199 | //====== Tool list ======== |
---|
200 | m_acTEncTop[layer].setUseSBACRD ( m_bUseSBACRD ); |
---|
201 | m_acTEncTop[layer].setDeltaQpRD ( m_uiDeltaQpRD ); |
---|
202 | m_acTEncTop[layer].setUseASR ( m_bUseASR ); |
---|
203 | m_acTEncTop[layer].setUseHADME ( m_bUseHADME ); |
---|
204 | m_acTEncTop[layer].setUseLossless ( m_useLossless ); |
---|
205 | #if !L0034_COMBINED_LIST_CLEANUP |
---|
206 | m_cTEncTop.setUseLComb ( m_bUseLComb ); |
---|
207 | #endif |
---|
208 | m_acTEncTop[layer].setdQPs ( m_acLayerCfg[layer].getdQPs() ); |
---|
209 | m_acTEncTop[layer].setUseRDOQ ( m_useRDOQ ); |
---|
210 | m_acTEncTop[layer].setUseRDOQTS ( m_useRDOQTS ); |
---|
211 | #if L0232_RD_PENALTY |
---|
212 | m_acTEncTop[layer].setRDpenalty ( m_rdPenalty ); |
---|
213 | #endif |
---|
214 | m_acTEncTop[layer].setQuadtreeTULog2MaxSize ( m_uiQuadtreeTULog2MaxSize ); |
---|
215 | m_acTEncTop[layer].setQuadtreeTULog2MinSize ( m_uiQuadtreeTULog2MinSize ); |
---|
216 | m_acTEncTop[layer].setQuadtreeTUMaxDepthInter ( m_uiQuadtreeTUMaxDepthInter ); |
---|
217 | m_acTEncTop[layer].setQuadtreeTUMaxDepthIntra ( m_uiQuadtreeTUMaxDepthIntra ); |
---|
218 | m_acTEncTop[layer].setUseFastEnc ( m_bUseFastEnc ); |
---|
219 | m_acTEncTop[layer].setUseEarlyCU ( m_bUseEarlyCU ); |
---|
220 | m_acTEncTop[layer].setUseFastDecisionForMerge ( m_useFastDecisionForMerge ); |
---|
221 | m_acTEncTop[layer].setUseCbfFastMode ( m_bUseCbfFastMode ); |
---|
222 | m_acTEncTop[layer].setUseEarlySkipDetection ( m_useEarlySkipDetection ); |
---|
223 | |
---|
224 | m_acTEncTop[layer].setUseTransformSkip ( m_useTransformSkip ); |
---|
225 | m_acTEncTop[layer].setUseTransformSkipFast ( m_useTransformSkipFast ); |
---|
226 | m_acTEncTop[layer].setUseConstrainedIntraPred ( m_bUseConstrainedIntraPred ); |
---|
227 | m_acTEncTop[layer].setPCMLog2MinSize ( m_uiPCMLog2MinSize); |
---|
228 | m_acTEncTop[layer].setUsePCM ( m_usePCM ); |
---|
229 | m_acTEncTop[layer].setPCMLog2MaxSize ( m_pcmLog2MaxSize); |
---|
230 | m_acTEncTop[layer].setMaxNumMergeCand ( m_maxNumMergeCand ); |
---|
231 | |
---|
232 | |
---|
233 | //====== Weighted Prediction ======== |
---|
234 | m_acTEncTop[layer].setUseWP ( m_useWeightedPred ); |
---|
235 | m_acTEncTop[layer].setWPBiPred ( m_useWeightedBiPred ); |
---|
236 | //====== Parallel Merge Estimation ======== |
---|
237 | m_acTEncTop[layer].setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 ); |
---|
238 | |
---|
239 | //====== Slice ======== |
---|
240 | m_acTEncTop[layer].setSliceMode ( m_sliceMode ); |
---|
241 | m_acTEncTop[layer].setSliceArgument ( m_sliceArgument ); |
---|
242 | |
---|
243 | //====== Dependent Slice ======== |
---|
244 | m_acTEncTop[layer].setSliceSegmentMode ( m_sliceSegmentMode ); |
---|
245 | m_acTEncTop[layer].setSliceSegmentArgument ( m_sliceSegmentArgument ); |
---|
246 | Int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1); |
---|
247 | if(m_sliceSegmentMode==FIXED_NUMBER_OF_LCU) |
---|
248 | { |
---|
249 | m_acTEncTop[layer].setSliceSegmentArgument ( m_sliceSegmentArgument * iNumPartInCU ); |
---|
250 | } |
---|
251 | if(m_sliceMode==FIXED_NUMBER_OF_LCU) |
---|
252 | { |
---|
253 | m_acTEncTop[layer].setSliceArgument ( m_sliceArgument * iNumPartInCU ); |
---|
254 | } |
---|
255 | if(m_sliceMode==FIXED_NUMBER_OF_TILES) |
---|
256 | { |
---|
257 | m_acTEncTop[layer].setSliceArgument ( m_sliceArgument ); |
---|
258 | } |
---|
259 | |
---|
260 | if(m_sliceMode == 0 ) |
---|
261 | { |
---|
262 | m_bLFCrossSliceBoundaryFlag = true; |
---|
263 | } |
---|
264 | m_acTEncTop[layer].setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
265 | m_acTEncTop[layer].setUseSAO ( m_bUseSAO ); |
---|
266 | m_acTEncTop[layer].setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic); |
---|
267 | |
---|
268 | m_acTEncTop[layer].setSaoLcuBoundary (m_saoLcuBoundary); |
---|
269 | m_acTEncTop[layer].setSaoLcuBasedOptimization (m_saoLcuBasedOptimization); |
---|
270 | m_acTEncTop[layer].setPCMInputBitDepthFlag ( m_bPCMInputBitDepthFlag); |
---|
271 | m_acTEncTop[layer].setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag); |
---|
272 | |
---|
273 | m_acTEncTop[layer].setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
274 | m_acTEncTop[layer].setRecoveryPointSEIEnabled( m_recoveryPointSEIEnabled ); |
---|
275 | m_acTEncTop[layer].setBufferingPeriodSEIEnabled( m_bufferingPeriodSEIEnabled ); |
---|
276 | m_acTEncTop[layer].setPictureTimingSEIEnabled( m_pictureTimingSEIEnabled ); |
---|
277 | #if J0149_TONE_MAPPING_SEI |
---|
278 | m_acTEncTop[layer].setToneMappingInfoSEIEnabled ( m_toneMappingInfoSEIEnabled ); |
---|
279 | m_acTEncTop[layer].setTMISEIToneMapId ( m_toneMapId ); |
---|
280 | m_acTEncTop[layer].setTMISEIToneMapCancelFlag ( m_toneMapCancelFlag ); |
---|
281 | m_acTEncTop[layer].setTMISEIToneMapPersistenceFlag ( m_toneMapPersistenceFlag ); |
---|
282 | m_acTEncTop[layer].setTMISEICodedDataBitDepth ( m_toneMapCodedDataBitDepth ); |
---|
283 | m_acTEncTop[layer].setTMISEITargetBitDepth ( m_toneMapTargetBitDepth ); |
---|
284 | m_acTEncTop[layer].setTMISEIModelID ( m_toneMapModelId ); |
---|
285 | m_acTEncTop[layer].setTMISEIMinValue ( m_toneMapMinValue ); |
---|
286 | m_acTEncTop[layer].setTMISEIMaxValue ( m_toneMapMaxValue ); |
---|
287 | m_acTEncTop[layer].setTMISEISigmoidMidpoint ( m_sigmoidMidpoint ); |
---|
288 | m_acTEncTop[layer].setTMISEISigmoidWidth ( m_sigmoidWidth ); |
---|
289 | m_acTEncTop[layer].setTMISEIStartOfCodedInterva ( m_startOfCodedInterval ); |
---|
290 | m_acTEncTop[layer].setTMISEINumPivots ( m_numPivots ); |
---|
291 | m_acTEncTop[layer].setTMISEICodedPivotValue ( m_codedPivotValue ); |
---|
292 | m_acTEncTop[layer].setTMISEITargetPivotValue ( m_targetPivotValue ); |
---|
293 | m_acTEncTop[layer].setTMISEICameraIsoSpeedIdc ( m_cameraIsoSpeedIdc ); |
---|
294 | m_acTEncTop[layer].setTMISEICameraIsoSpeedValue ( m_cameraIsoSpeedValue ); |
---|
295 | m_acTEncTop[layer].setTMISEIExposureCompensationValueSignFlag ( m_exposureCompensationValueSignFlag ); |
---|
296 | m_acTEncTop[layer].setTMISEIExposureCompensationValueNumerator ( m_exposureCompensationValueNumerator ); |
---|
297 | m_acTEncTop[layer].setTMISEIExposureCompensationValueDenomIdc ( m_exposureCompensationValueDenomIdc ); |
---|
298 | m_acTEncTop[layer].setTMISEIRefScreenLuminanceWhite ( m_refScreenLuminanceWhite ); |
---|
299 | m_acTEncTop[layer].setTMISEIExtendedRangeWhiteLevel ( m_extendedRangeWhiteLevel ); |
---|
300 | m_acTEncTop[layer].setTMISEINominalBlackLevelLumaCodeValue ( m_nominalBlackLevelLumaCodeValue ); |
---|
301 | m_acTEncTop[layer].setTMISEINominalWhiteLevelLumaCodeValue ( m_nominalWhiteLevelLumaCodeValue ); |
---|
302 | m_acTEncTop[layer].setTMISEIExtendedWhiteLevelLumaCodeValue ( m_extendedWhiteLevelLumaCodeValue ); |
---|
303 | #endif |
---|
304 | m_acTEncTop[layer].setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled ); |
---|
305 | m_acTEncTop[layer].setFramePackingArrangementSEIType( m_framePackingSEIType ); |
---|
306 | m_acTEncTop[layer].setFramePackingArrangementSEIId( m_framePackingSEIId ); |
---|
307 | m_acTEncTop[layer].setFramePackingArrangementSEIQuincunx( m_framePackingSEIQuincunx ); |
---|
308 | m_acTEncTop[layer].setFramePackingArrangementSEIInterpretation( m_framePackingSEIInterpretation ); |
---|
309 | m_acTEncTop[layer].setDisplayOrientationSEIAngle( m_displayOrientationSEIAngle ); |
---|
310 | m_acTEncTop[layer].setTemporalLevel0IndexSEIEnabled( m_temporalLevel0IndexSEIEnabled ); |
---|
311 | m_acTEncTop[layer].setGradualDecodingRefreshInfoEnabled( m_gradualDecodingRefreshInfoEnabled ); |
---|
312 | m_acTEncTop[layer].setDecodingUnitInfoSEIEnabled( m_decodingUnitInfoSEIEnabled ); |
---|
313 | #if L0208_SOP_DESCRIPTION_SEI |
---|
314 | m_acTEncTop[layer].setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled ); |
---|
315 | #endif |
---|
316 | #if K0180_SCALABLE_NESTING_SEI |
---|
317 | m_acTEncTop[layer].setScalableNestingSEIEnabled( m_scalableNestingSEIEnabled ); |
---|
318 | #endif |
---|
319 | m_acTEncTop[layer].setUniformSpacingIdr ( m_iUniformSpacingIdr ); |
---|
320 | m_acTEncTop[layer].setNumColumnsMinus1 ( m_iNumColumnsMinus1 ); |
---|
321 | m_acTEncTop[layer].setNumRowsMinus1 ( m_iNumRowsMinus1 ); |
---|
322 | if(m_iUniformSpacingIdr==0) |
---|
323 | { |
---|
324 | m_acTEncTop[layer].setColumnWidth ( m_pColumnWidth ); |
---|
325 | m_acTEncTop[layer].setRowHeight ( m_pRowHeight ); |
---|
326 | } |
---|
327 | m_acTEncTop[layer].xCheckGSParameters(); |
---|
328 | Int uiTilesCount = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1); |
---|
329 | if(uiTilesCount == 1) |
---|
330 | { |
---|
331 | m_bLFCrossTileBoundaryFlag = true; |
---|
332 | } |
---|
333 | m_acTEncTop[layer].setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag ); |
---|
334 | m_acTEncTop[layer].setWaveFrontSynchro ( m_iWaveFrontSynchro ); |
---|
335 | m_acTEncTop[layer].setWaveFrontSubstreams ( m_acLayerCfg[layer].m_iWaveFrontSubstreams ); |
---|
336 | m_acTEncTop[layer].setTMVPModeId ( m_TMVPModeId ); |
---|
337 | m_acTEncTop[layer].setUseScalingListId ( m_useScalingListId ); |
---|
338 | m_acTEncTop[layer].setScalingListFile ( m_scalingListFile ); |
---|
339 | m_acTEncTop[layer].setSignHideFlag(m_signHideFlag); |
---|
340 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
341 | m_acTEncTop[layer].setUseRateCtrl ( m_RCEnableRateControl ); |
---|
342 | m_acTEncTop[layer].setTargetBitrate ( m_RCTargetBitrate ); |
---|
343 | m_acTEncTop[layer].setKeepHierBit ( m_RCKeepHierarchicalBit ); |
---|
344 | m_acTEncTop[layer].setLCULevelRC ( m_RCLCULevelRC ); |
---|
345 | m_acTEncTop[layer].setUseLCUSeparateModel ( m_RCUseLCUSeparateModel ); |
---|
346 | m_acTEncTop[layer].setInitialQP ( m_RCInitialQP ); |
---|
347 | m_acTEncTop[layer].setForceIntraQP ( m_RCForceIntraQP ); |
---|
348 | #else |
---|
349 | m_acTEncTop[layer].setUseRateCtrl ( m_enableRateCtrl); |
---|
350 | m_acTEncTop[layer].setTargetBitrate ( m_targetBitrate); |
---|
351 | m_acTEncTop[layer].setNumLCUInUnit ( m_numLCUInUnit); |
---|
352 | #endif |
---|
353 | m_acTEncTop[layer].setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag); |
---|
354 | m_acTEncTop[layer].setCUTransquantBypassFlagValue(m_CUTransquantBypassFlagValue); |
---|
355 | m_acTEncTop[layer].setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda ); |
---|
356 | m_acTEncTop[layer].setUseStrongIntraSmoothing( m_useStrongIntraSmoothing ); |
---|
357 | m_acTEncTop[layer].setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); |
---|
358 | m_acTEncTop[layer].setVuiParametersPresentFlag( m_vuiParametersPresentFlag ); |
---|
359 | m_acTEncTop[layer].setAspectRatioIdc( m_aspectRatioIdc ); |
---|
360 | m_acTEncTop[layer].setSarWidth( m_sarWidth ); |
---|
361 | m_acTEncTop[layer].setSarHeight( m_sarHeight ); |
---|
362 | m_acTEncTop[layer].setOverscanInfoPresentFlag( m_overscanInfoPresentFlag ); |
---|
363 | m_acTEncTop[layer].setOverscanAppropriateFlag( m_overscanAppropriateFlag ); |
---|
364 | m_acTEncTop[layer].setVideoSignalTypePresentFlag( m_videoSignalTypePresentFlag ); |
---|
365 | m_acTEncTop[layer].setVideoFormat( m_videoFormat ); |
---|
366 | m_acTEncTop[layer].setVideoFullRangeFlag( m_videoFullRangeFlag ); |
---|
367 | m_acTEncTop[layer].setColourDescriptionPresentFlag( m_colourDescriptionPresentFlag ); |
---|
368 | m_acTEncTop[layer].setColourPrimaries( m_colourPrimaries ); |
---|
369 | m_acTEncTop[layer].setTransferCharacteristics( m_transferCharacteristics ); |
---|
370 | m_acTEncTop[layer].setMatrixCoefficients( m_matrixCoefficients ); |
---|
371 | m_acTEncTop[layer].setChromaLocInfoPresentFlag( m_chromaLocInfoPresentFlag ); |
---|
372 | m_acTEncTop[layer].setChromaSampleLocTypeTopField( m_chromaSampleLocTypeTopField ); |
---|
373 | m_acTEncTop[layer].setChromaSampleLocTypeBottomField( m_chromaSampleLocTypeBottomField ); |
---|
374 | m_acTEncTop[layer].setNeutralChromaIndicationFlag( m_neutralChromaIndicationFlag ); |
---|
375 | m_acTEncTop[layer].setDefaultDisplayWindow( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset ); |
---|
376 | m_acTEncTop[layer].setFrameFieldInfoPresentFlag( m_frameFieldInfoPresentFlag ); |
---|
377 | m_acTEncTop[layer].setPocProportionalToTimingFlag( m_pocProportionalToTimingFlag ); |
---|
378 | m_acTEncTop[layer].setNumTicksPocDiffOneMinus1 ( m_numTicksPocDiffOneMinus1 ); |
---|
379 | m_acTEncTop[layer].setBitstreamRestrictionFlag( m_bitstreamRestrictionFlag ); |
---|
380 | m_acTEncTop[layer].setTilesFixedStructureFlag( m_tilesFixedStructureFlag ); |
---|
381 | m_acTEncTop[layer].setMotionVectorsOverPicBoundariesFlag( m_motionVectorsOverPicBoundariesFlag ); |
---|
382 | m_acTEncTop[layer].setMinSpatialSegmentationIdc( m_minSpatialSegmentationIdc ); |
---|
383 | m_acTEncTop[layer].setMaxBytesPerPicDenom( m_maxBytesPerPicDenom ); |
---|
384 | m_acTEncTop[layer].setMaxBitsPerMinCuDenom( m_maxBitsPerMinCuDenom ); |
---|
385 | m_acTEncTop[layer].setLog2MaxMvLengthHorizontal( m_log2MaxMvLengthHorizontal ); |
---|
386 | m_acTEncTop[layer].setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical ); |
---|
387 | #if SIGNAL_BITRATE_PICRATE_IN_VPS |
---|
388 | TComBitRatePicRateInfo *bitRatePicRateInfo = m_cTEncTop[layer].getVPS()->getBitratePicrateInfo(); |
---|
389 | // The number of bit rate/pic rate have to equal to number of sub-layers. |
---|
390 | if(m_bitRatePicRateMaxTLayers) |
---|
391 | { |
---|
392 | assert(m_bitRatePicRateMaxTLayers == m_cTEncTop[layer].getVPS()->getMaxTLayers()); |
---|
393 | } |
---|
394 | for(Int i = 0; i < m_bitRatePicRateMaxTLayers; i++) |
---|
395 | { |
---|
396 | bitRatePicRateInfo->setBitRateInfoPresentFlag( i, m_bitRateInfoPresentFlag[i] ); |
---|
397 | if( bitRatePicRateInfo->getBitRateInfoPresentFlag(i) ) |
---|
398 | { |
---|
399 | bitRatePicRateInfo->setAvgBitRate(i, m_avgBitRate[i]); |
---|
400 | bitRatePicRateInfo->setMaxBitRate(i, m_maxBitRate[i]); |
---|
401 | } |
---|
402 | } |
---|
403 | for(Int i = 0; i < m_bitRatePicRateMaxTLayers; i++) |
---|
404 | { |
---|
405 | bitRatePicRateInfo->setPicRateInfoPresentFlag( i, m_picRateInfoPresentFlag[i] ); |
---|
406 | if( bitRatePicRateInfo->getPicRateInfoPresentFlag(i) ) |
---|
407 | { |
---|
408 | bitRatePicRateInfo->setAvgPicRate (i, m_avgPicRate[i]); |
---|
409 | bitRatePicRateInfo->setConstantPicRateIdc(i, m_constantPicRateIdc[i]); |
---|
410 | } |
---|
411 | } |
---|
412 | #endif |
---|
413 | #if REF_IDX_FRAMEWORK |
---|
414 | m_acTEncTop[layer].setElRapSliceTypeB(layer == 0? 0 : m_elRapSliceBEnabled); |
---|
415 | #endif |
---|
416 | } |
---|
417 | } |
---|
418 | #else |
---|
419 | Void TAppEncTop::xInitLibCfg() |
---|
420 | { |
---|
421 | TComVPS vps; |
---|
422 | |
---|
423 | vps.setMaxTLayers ( m_maxTempLayer ); |
---|
424 | if (m_maxTempLayer == 1) |
---|
425 | { |
---|
426 | vps.setTemporalNestingFlag(true); |
---|
427 | } |
---|
428 | vps.setMaxLayers ( 1 ); |
---|
429 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
430 | { |
---|
431 | vps.setNumReorderPics ( m_numReorderPics[i], i ); |
---|
432 | vps.setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i ); |
---|
433 | } |
---|
434 | m_cTEncTop.setVPS(&vps); |
---|
435 | |
---|
436 | m_cTEncTop.setProfile(m_profile); |
---|
437 | m_cTEncTop.setLevel(m_levelTier, m_level); |
---|
438 | #if L0046_CONSTRAINT_FLAGS |
---|
439 | m_cTEncTop.setProgressiveSourceFlag(m_progressiveSourceFlag); |
---|
440 | m_cTEncTop.setInterlacedSourceFlag(m_interlacedSourceFlag); |
---|
441 | m_cTEncTop.setNonPackedConstraintFlag(m_nonPackedConstraintFlag); |
---|
442 | m_cTEncTop.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag); |
---|
443 | #endif |
---|
444 | |
---|
445 | m_cTEncTop.setFrameRate ( m_iFrameRate ); |
---|
446 | m_cTEncTop.setFrameSkip ( m_FrameSkip ); |
---|
447 | m_cTEncTop.setSourceWidth ( m_iSourceWidth ); |
---|
448 | m_cTEncTop.setSourceHeight ( m_iSourceHeight ); |
---|
449 | m_cTEncTop.setConformanceWindow ( m_confLeft, m_confRight, m_confTop, m_confBottom ); |
---|
450 | m_cTEncTop.setFramesToBeEncoded ( m_framesToBeEncoded ); |
---|
451 | |
---|
452 | //====== Coding Structure ======== |
---|
453 | m_cTEncTop.setIntraPeriod ( m_iIntraPeriod ); |
---|
454 | m_cTEncTop.setDecodingRefreshType ( m_iDecodingRefreshType ); |
---|
455 | m_cTEncTop.setGOPSize ( m_iGOPSize ); |
---|
456 | m_cTEncTop.setGopList ( m_GOPList ); |
---|
457 | m_cTEncTop.setExtraRPSs ( m_extraRPSs ); |
---|
458 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
459 | { |
---|
460 | m_cTEncTop.setNumReorderPics ( m_numReorderPics[i], i ); |
---|
461 | m_cTEncTop.setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i ); |
---|
462 | } |
---|
463 | for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop ) |
---|
464 | { |
---|
465 | m_cTEncTop.setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] ); |
---|
466 | } |
---|
467 | m_cTEncTop.setQP ( m_iQP ); |
---|
468 | |
---|
469 | m_cTEncTop.setPad ( m_aiPad ); |
---|
470 | |
---|
471 | m_cTEncTop.setMaxTempLayer ( m_maxTempLayer ); |
---|
472 | m_cTEncTop.setUseAMP( m_enableAMP ); |
---|
473 | |
---|
474 | //===== Slice ======== |
---|
475 | |
---|
476 | //====== Loop/Deblock Filter ======== |
---|
477 | m_cTEncTop.setLoopFilterDisable ( m_bLoopFilterDisable ); |
---|
478 | m_cTEncTop.setLoopFilterOffsetInPPS ( m_loopFilterOffsetInPPS ); |
---|
479 | m_cTEncTop.setLoopFilterBetaOffset ( m_loopFilterBetaOffsetDiv2 ); |
---|
480 | m_cTEncTop.setLoopFilterTcOffset ( m_loopFilterTcOffsetDiv2 ); |
---|
481 | m_cTEncTop.setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent); |
---|
482 | #if L0386_DB_METRIC |
---|
483 | m_cTEncTop.setDeblockingFilterMetric ( m_DeblockingFilterMetric ); |
---|
484 | #endif |
---|
485 | |
---|
486 | //====== Motion search ======== |
---|
487 | m_cTEncTop.setFastSearch ( m_iFastSearch ); |
---|
488 | m_cTEncTop.setSearchRange ( m_iSearchRange ); |
---|
489 | m_cTEncTop.setBipredSearchRange ( m_bipredSearchRange ); |
---|
490 | |
---|
491 | //====== Quality control ======== |
---|
492 | m_cTEncTop.setMaxDeltaQP ( m_iMaxDeltaQP ); |
---|
493 | m_cTEncTop.setMaxCuDQPDepth ( m_iMaxCuDQPDepth ); |
---|
494 | |
---|
495 | m_cTEncTop.setChromaCbQpOffset ( m_cbQpOffset ); |
---|
496 | m_cTEncTop.setChromaCrQpOffset ( m_crQpOffset ); |
---|
497 | |
---|
498 | #if ADAPTIVE_QP_SELECTION |
---|
499 | m_cTEncTop.setUseAdaptQpSelect ( m_bUseAdaptQpSelect ); |
---|
500 | #endif |
---|
501 | |
---|
502 | Int lowestQP; |
---|
503 | lowestQP = - 6*(g_bitDepthY - 8); // XXX: check |
---|
504 | |
---|
505 | if ((m_iMaxDeltaQP == 0 ) && (m_iQP == lowestQP) && (m_useLossless == true)) |
---|
506 | { |
---|
507 | m_bUseAdaptiveQP = false; |
---|
508 | } |
---|
509 | m_cTEncTop.setUseAdaptiveQP ( m_bUseAdaptiveQP ); |
---|
510 | m_cTEncTop.setQPAdaptationRange ( m_iQPAdaptationRange ); |
---|
511 | |
---|
512 | //====== Tool list ======== |
---|
513 | m_cTEncTop.setUseSBACRD ( m_bUseSBACRD ); |
---|
514 | m_cTEncTop.setDeltaQpRD ( m_uiDeltaQpRD ); |
---|
515 | m_cTEncTop.setUseASR ( m_bUseASR ); |
---|
516 | m_cTEncTop.setUseHADME ( m_bUseHADME ); |
---|
517 | m_cTEncTop.setUseLossless ( m_useLossless ); |
---|
518 | #if !L0034_COMBINED_LIST_CLEANUP |
---|
519 | m_cTEncTop.setUseLComb ( m_bUseLComb ); |
---|
520 | #endif |
---|
521 | m_cTEncTop.setdQPs ( m_aidQP ); |
---|
522 | m_cTEncTop.setUseRDOQ ( m_useRDOQ ); |
---|
523 | m_cTEncTop.setUseRDOQTS ( m_useRDOQTS ); |
---|
524 | #if L0232_RD_PENALTY |
---|
525 | m_cTEncTop.setRDpenalty ( m_rdPenalty ); |
---|
526 | #endif |
---|
527 | m_cTEncTop.setQuadtreeTULog2MaxSize ( m_uiQuadtreeTULog2MaxSize ); |
---|
528 | m_cTEncTop.setQuadtreeTULog2MinSize ( m_uiQuadtreeTULog2MinSize ); |
---|
529 | m_cTEncTop.setQuadtreeTUMaxDepthInter ( m_uiQuadtreeTUMaxDepthInter ); |
---|
530 | m_cTEncTop.setQuadtreeTUMaxDepthIntra ( m_uiQuadtreeTUMaxDepthIntra ); |
---|
531 | m_cTEncTop.setUseFastEnc ( m_bUseFastEnc ); |
---|
532 | m_cTEncTop.setUseEarlyCU ( m_bUseEarlyCU ); |
---|
533 | m_cTEncTop.setUseFastDecisionForMerge ( m_useFastDecisionForMerge ); |
---|
534 | m_cTEncTop.setUseCbfFastMode ( m_bUseCbfFastMode ); |
---|
535 | m_cTEncTop.setUseEarlySkipDetection ( m_useEarlySkipDetection ); |
---|
536 | |
---|
537 | m_cTEncTop.setUseTransformSkip ( m_useTransformSkip ); |
---|
538 | m_cTEncTop.setUseTransformSkipFast ( m_useTransformSkipFast ); |
---|
539 | m_cTEncTop.setUseConstrainedIntraPred ( m_bUseConstrainedIntraPred ); |
---|
540 | m_cTEncTop.setPCMLog2MinSize ( m_uiPCMLog2MinSize); |
---|
541 | m_cTEncTop.setUsePCM ( m_usePCM ); |
---|
542 | m_cTEncTop.setPCMLog2MaxSize ( m_pcmLog2MaxSize); |
---|
543 | m_cTEncTop.setMaxNumMergeCand ( m_maxNumMergeCand ); |
---|
544 | |
---|
545 | |
---|
546 | //====== Weighted Prediction ======== |
---|
547 | m_cTEncTop.setUseWP ( m_useWeightedPred ); |
---|
548 | m_cTEncTop.setWPBiPred ( m_useWeightedBiPred ); |
---|
549 | //====== Parallel Merge Estimation ======== |
---|
550 | m_cTEncTop.setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 ); |
---|
551 | |
---|
552 | //====== Slice ======== |
---|
553 | m_cTEncTop.setSliceMode ( m_sliceMode ); |
---|
554 | m_cTEncTop.setSliceArgument ( m_sliceArgument ); |
---|
555 | |
---|
556 | //====== Dependent Slice ======== |
---|
557 | m_cTEncTop.setSliceSegmentMode ( m_sliceSegmentMode ); |
---|
558 | m_cTEncTop.setSliceSegmentArgument ( m_sliceSegmentArgument ); |
---|
559 | Int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1); |
---|
560 | if(m_sliceSegmentMode==FIXED_NUMBER_OF_LCU) |
---|
561 | { |
---|
562 | m_cTEncTop.setSliceSegmentArgument ( m_sliceSegmentArgument * iNumPartInCU ); |
---|
563 | } |
---|
564 | if(m_sliceMode==FIXED_NUMBER_OF_LCU) |
---|
565 | { |
---|
566 | m_cTEncTop.setSliceArgument ( m_sliceArgument * iNumPartInCU ); |
---|
567 | } |
---|
568 | if(m_sliceMode==FIXED_NUMBER_OF_TILES) |
---|
569 | { |
---|
570 | m_cTEncTop.setSliceArgument ( m_sliceArgument ); |
---|
571 | } |
---|
572 | |
---|
573 | if(m_sliceMode == 0 ) |
---|
574 | { |
---|
575 | m_bLFCrossSliceBoundaryFlag = true; |
---|
576 | } |
---|
577 | m_cTEncTop.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
578 | m_cTEncTop.setUseSAO ( m_bUseSAO ); |
---|
579 | m_cTEncTop.setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic); |
---|
580 | |
---|
581 | m_cTEncTop.setSaoLcuBoundary (m_saoLcuBoundary); |
---|
582 | m_cTEncTop.setSaoLcuBasedOptimization (m_saoLcuBasedOptimization); |
---|
583 | m_cTEncTop.setPCMInputBitDepthFlag ( m_bPCMInputBitDepthFlag); |
---|
584 | m_cTEncTop.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag); |
---|
585 | |
---|
586 | m_cTEncTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
587 | m_cTEncTop.setRecoveryPointSEIEnabled( m_recoveryPointSEIEnabled ); |
---|
588 | m_cTEncTop.setBufferingPeriodSEIEnabled( m_bufferingPeriodSEIEnabled ); |
---|
589 | m_cTEncTop.setPictureTimingSEIEnabled( m_pictureTimingSEIEnabled ); |
---|
590 | #if J0149_TONE_MAPPING_SEI |
---|
591 | m_cTEncTop.setToneMappingInfoSEIEnabled ( m_toneMappingInfoSEIEnabled ); |
---|
592 | m_cTEncTop.setTMISEIToneMapId ( m_toneMapId ); |
---|
593 | m_cTEncTop.setTMISEIToneMapCancelFlag ( m_toneMapCancelFlag ); |
---|
594 | m_cTEncTop.setTMISEIToneMapPersistenceFlag ( m_toneMapPersistenceFlag ); |
---|
595 | m_cTEncTop.setTMISEICodedDataBitDepth ( m_toneMapCodedDataBitDepth ); |
---|
596 | m_cTEncTop.setTMISEITargetBitDepth ( m_toneMapTargetBitDepth ); |
---|
597 | m_cTEncTop.setTMISEIModelID ( m_toneMapModelId ); |
---|
598 | m_cTEncTop.setTMISEIMinValue ( m_toneMapMinValue ); |
---|
599 | m_cTEncTop.setTMISEIMaxValue ( m_toneMapMaxValue ); |
---|
600 | m_cTEncTop.setTMISEISigmoidMidpoint ( m_sigmoidMidpoint ); |
---|
601 | m_cTEncTop.setTMISEISigmoidWidth ( m_sigmoidWidth ); |
---|
602 | m_cTEncTop.setTMISEIStartOfCodedInterva ( m_startOfCodedInterval ); |
---|
603 | m_cTEncTop.setTMISEINumPivots ( m_numPivots ); |
---|
604 | m_cTEncTop.setTMISEICodedPivotValue ( m_codedPivotValue ); |
---|
605 | m_cTEncTop.setTMISEITargetPivotValue ( m_targetPivotValue ); |
---|
606 | m_cTEncTop.setTMISEICameraIsoSpeedIdc ( m_cameraIsoSpeedIdc ); |
---|
607 | m_cTEncTop.setTMISEICameraIsoSpeedValue ( m_cameraIsoSpeedValue ); |
---|
608 | m_cTEncTop.setTMISEIExposureCompensationValueSignFlag ( m_exposureCompensationValueSignFlag ); |
---|
609 | m_cTEncTop.setTMISEIExposureCompensationValueNumerator ( m_exposureCompensationValueNumerator ); |
---|
610 | m_cTEncTop.setTMISEIExposureCompensationValueDenomIdc ( m_exposureCompensationValueDenomIdc ); |
---|
611 | m_cTEncTop.setTMISEIRefScreenLuminanceWhite ( m_refScreenLuminanceWhite ); |
---|
612 | m_cTEncTop.setTMISEIExtendedRangeWhiteLevel ( m_extendedRangeWhiteLevel ); |
---|
613 | m_cTEncTop.setTMISEINominalBlackLevelLumaCodeValue ( m_nominalBlackLevelLumaCodeValue ); |
---|
614 | m_cTEncTop.setTMISEINominalWhiteLevelLumaCodeValue ( m_nominalWhiteLevelLumaCodeValue ); |
---|
615 | m_cTEncTop.setTMISEIExtendedWhiteLevelLumaCodeValue ( m_extendedWhiteLevelLumaCodeValue ); |
---|
616 | #endif |
---|
617 | m_cTEncTop.setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled ); |
---|
618 | m_cTEncTop.setFramePackingArrangementSEIType( m_framePackingSEIType ); |
---|
619 | m_cTEncTop.setFramePackingArrangementSEIId( m_framePackingSEIId ); |
---|
620 | m_cTEncTop.setFramePackingArrangementSEIQuincunx( m_framePackingSEIQuincunx ); |
---|
621 | m_cTEncTop.setFramePackingArrangementSEIInterpretation( m_framePackingSEIInterpretation ); |
---|
622 | m_cTEncTop.setDisplayOrientationSEIAngle( m_displayOrientationSEIAngle ); |
---|
623 | m_cTEncTop.setTemporalLevel0IndexSEIEnabled( m_temporalLevel0IndexSEIEnabled ); |
---|
624 | m_cTEncTop.setGradualDecodingRefreshInfoEnabled( m_gradualDecodingRefreshInfoEnabled ); |
---|
625 | m_cTEncTop.setDecodingUnitInfoSEIEnabled( m_decodingUnitInfoSEIEnabled ); |
---|
626 | #if L0208_SOP_DESCRIPTION_SEI |
---|
627 | m_cTEncTop.setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled ); |
---|
628 | #endif |
---|
629 | #if K0180_SCALABLE_NESTING_SEI |
---|
630 | m_cTEncTop.setScalableNestingSEIEnabled( m_scalableNestingSEIEnabled ); |
---|
631 | #endif |
---|
632 | m_cTEncTop.setUniformSpacingIdr ( m_iUniformSpacingIdr ); |
---|
633 | m_cTEncTop.setNumColumnsMinus1 ( m_iNumColumnsMinus1 ); |
---|
634 | m_cTEncTop.setNumRowsMinus1 ( m_iNumRowsMinus1 ); |
---|
635 | if(m_iUniformSpacingIdr==0) |
---|
636 | { |
---|
637 | m_cTEncTop.setColumnWidth ( m_pColumnWidth ); |
---|
638 | m_cTEncTop.setRowHeight ( m_pRowHeight ); |
---|
639 | } |
---|
640 | m_cTEncTop.xCheckGSParameters(); |
---|
641 | Int uiTilesCount = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1); |
---|
642 | if(uiTilesCount == 1) |
---|
643 | { |
---|
644 | m_bLFCrossTileBoundaryFlag = true; |
---|
645 | } |
---|
646 | m_cTEncTop.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag ); |
---|
647 | m_cTEncTop.setWaveFrontSynchro ( m_iWaveFrontSynchro ); |
---|
648 | m_cTEncTop.setWaveFrontSubstreams ( m_iWaveFrontSubstreams ); |
---|
649 | m_cTEncTop.setTMVPModeId ( m_TMVPModeId ); |
---|
650 | m_cTEncTop.setUseScalingListId ( m_useScalingListId ); |
---|
651 | m_cTEncTop.setScalingListFile ( m_scalingListFile ); |
---|
652 | m_cTEncTop.setSignHideFlag(m_signHideFlag); |
---|
653 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
654 | m_cTEncTop.setUseRateCtrl ( m_RCEnableRateControl ); |
---|
655 | m_cTEncTop.setTargetBitrate ( m_RCTargetBitrate ); |
---|
656 | m_cTEncTop.setKeepHierBit ( m_RCKeepHierarchicalBit ); |
---|
657 | m_cTEncTop.setLCULevelRC ( m_RCLCULevelRC ); |
---|
658 | m_cTEncTop.setUseLCUSeparateModel ( m_RCUseLCUSeparateModel ); |
---|
659 | m_cTEncTop.setInitialQP ( m_RCInitialQP ); |
---|
660 | m_cTEncTop.setForceIntraQP ( m_RCForceIntraQP ); |
---|
661 | #else |
---|
662 | m_cTEncTop.setUseRateCtrl ( m_enableRateCtrl); |
---|
663 | m_cTEncTop.setTargetBitrate ( m_targetBitrate); |
---|
664 | m_cTEncTop.setNumLCUInUnit ( m_numLCUInUnit); |
---|
665 | #endif |
---|
666 | m_cTEncTop.setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag); |
---|
667 | m_cTEncTop.setCUTransquantBypassFlagValue(m_CUTransquantBypassFlagValue); |
---|
668 | m_cTEncTop.setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda ); |
---|
669 | m_cTEncTop.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing ); |
---|
670 | m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); |
---|
671 | m_cTEncTop.setVuiParametersPresentFlag( m_vuiParametersPresentFlag ); |
---|
672 | m_cTEncTop.setAspectRatioIdc( m_aspectRatioIdc ); |
---|
673 | m_cTEncTop.setSarWidth( m_sarWidth ); |
---|
674 | m_cTEncTop.setSarHeight( m_sarHeight ); |
---|
675 | m_cTEncTop.setOverscanInfoPresentFlag( m_overscanInfoPresentFlag ); |
---|
676 | m_cTEncTop.setOverscanAppropriateFlag( m_overscanAppropriateFlag ); |
---|
677 | m_cTEncTop.setVideoSignalTypePresentFlag( m_videoSignalTypePresentFlag ); |
---|
678 | m_cTEncTop.setVideoFormat( m_videoFormat ); |
---|
679 | m_cTEncTop.setVideoFullRangeFlag( m_videoFullRangeFlag ); |
---|
680 | m_cTEncTop.setColourDescriptionPresentFlag( m_colourDescriptionPresentFlag ); |
---|
681 | m_cTEncTop.setColourPrimaries( m_colourPrimaries ); |
---|
682 | m_cTEncTop.setTransferCharacteristics( m_transferCharacteristics ); |
---|
683 | m_cTEncTop.setMatrixCoefficients( m_matrixCoefficients ); |
---|
684 | m_cTEncTop.setChromaLocInfoPresentFlag( m_chromaLocInfoPresentFlag ); |
---|
685 | m_cTEncTop.setChromaSampleLocTypeTopField( m_chromaSampleLocTypeTopField ); |
---|
686 | m_cTEncTop.setChromaSampleLocTypeBottomField( m_chromaSampleLocTypeBottomField ); |
---|
687 | m_cTEncTop.setNeutralChromaIndicationFlag( m_neutralChromaIndicationFlag ); |
---|
688 | m_cTEncTop.setDefaultDisplayWindow( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset ); |
---|
689 | m_cTEncTop.setFrameFieldInfoPresentFlag( m_frameFieldInfoPresentFlag ); |
---|
690 | m_cTEncTop.setPocProportionalToTimingFlag( m_pocProportionalToTimingFlag ); |
---|
691 | m_cTEncTop.setNumTicksPocDiffOneMinus1 ( m_numTicksPocDiffOneMinus1 ); |
---|
692 | m_cTEncTop.setBitstreamRestrictionFlag( m_bitstreamRestrictionFlag ); |
---|
693 | m_cTEncTop.setTilesFixedStructureFlag( m_tilesFixedStructureFlag ); |
---|
694 | m_cTEncTop.setMotionVectorsOverPicBoundariesFlag( m_motionVectorsOverPicBoundariesFlag ); |
---|
695 | m_cTEncTop.setMinSpatialSegmentationIdc( m_minSpatialSegmentationIdc ); |
---|
696 | m_cTEncTop.setMaxBytesPerPicDenom( m_maxBytesPerPicDenom ); |
---|
697 | m_cTEncTop.setMaxBitsPerMinCuDenom( m_maxBitsPerMinCuDenom ); |
---|
698 | m_cTEncTop.setLog2MaxMvLengthHorizontal( m_log2MaxMvLengthHorizontal ); |
---|
699 | m_cTEncTop.setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical ); |
---|
700 | #if SIGNAL_BITRATE_PICRATE_IN_VPS |
---|
701 | TComBitRatePicRateInfo *bitRatePicRateInfo = m_cTEncTop.getVPS()->getBitratePicrateInfo(); |
---|
702 | // The number of bit rate/pic rate have to equal to number of sub-layers. |
---|
703 | if(m_bitRatePicRateMaxTLayers) |
---|
704 | { |
---|
705 | assert(m_bitRatePicRateMaxTLayers == m_cTEncTop.getVPS()->getMaxTLayers()); |
---|
706 | } |
---|
707 | for(Int i = 0; i < m_bitRatePicRateMaxTLayers; i++) |
---|
708 | { |
---|
709 | bitRatePicRateInfo->setBitRateInfoPresentFlag( i, m_bitRateInfoPresentFlag[i] ); |
---|
710 | if( bitRatePicRateInfo->getBitRateInfoPresentFlag(i) ) |
---|
711 | { |
---|
712 | bitRatePicRateInfo->setAvgBitRate(i, m_avgBitRate[i]); |
---|
713 | bitRatePicRateInfo->setMaxBitRate(i, m_maxBitRate[i]); |
---|
714 | } |
---|
715 | } |
---|
716 | for(Int i = 0; i < m_bitRatePicRateMaxTLayers; i++) |
---|
717 | { |
---|
718 | bitRatePicRateInfo->setPicRateInfoPresentFlag( i, m_picRateInfoPresentFlag[i] ); |
---|
719 | if( bitRatePicRateInfo->getPicRateInfoPresentFlag(i) ) |
---|
720 | { |
---|
721 | bitRatePicRateInfo->setAvgPicRate (i, m_avgPicRate[i]); |
---|
722 | bitRatePicRateInfo->setConstantPicRateIdc(i, m_constantPicRateIdc[i]); |
---|
723 | } |
---|
724 | } |
---|
725 | #endif |
---|
726 | } |
---|
727 | #endif |
---|
728 | |
---|
729 | Void TAppEncTop::xCreateLib() |
---|
730 | { |
---|
731 | // Video I/O |
---|
732 | #if SVC_EXTENSION |
---|
733 | // initialize global variables |
---|
734 | initROM(); |
---|
735 | |
---|
736 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
737 | { |
---|
738 | m_acTVideoIOYuvInputFile[layer].open( (Char *)m_acLayerCfg[layer].getInputFile().c_str(), false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC ); // read mode |
---|
739 | m_acTVideoIOYuvInputFile[layer].skipFrames(m_FrameSkip, m_acLayerCfg[layer].getSourceWidth() - m_acLayerCfg[layer].getPad()[0], m_acLayerCfg[layer].getSourceHeight() - m_acLayerCfg[layer].getPad()[1]); |
---|
740 | |
---|
741 | if (!m_acLayerCfg[layer].getReconFile().empty()) |
---|
742 | { |
---|
743 | m_acTVideoIOYuvReconFile[layer].open((Char *)m_acLayerCfg[layer].getReconFile().c_str(), true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC ); // write mode |
---|
744 | } |
---|
745 | |
---|
746 | m_acTEncTop[layer].create(); |
---|
747 | } |
---|
748 | #else |
---|
749 | m_cTVideoIOYuvInputFile.open( m_pchInputFile, false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC ); // read mode |
---|
750 | m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]); |
---|
751 | |
---|
752 | if (m_pchReconFile) |
---|
753 | m_cTVideoIOYuvReconFile.open(m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC); // write mode |
---|
754 | |
---|
755 | // Neo Decoder |
---|
756 | m_cTEncTop.create(); |
---|
757 | #endif |
---|
758 | } |
---|
759 | |
---|
760 | Void TAppEncTop::xDestroyLib() |
---|
761 | { |
---|
762 | // Video I/O |
---|
763 | #if SVC_EXTENSION |
---|
764 | // destroy ROM |
---|
765 | destroyROM(); |
---|
766 | |
---|
767 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
768 | { |
---|
769 | m_acTVideoIOYuvInputFile[layer].close(); |
---|
770 | m_acTVideoIOYuvReconFile[layer].close(); |
---|
771 | |
---|
772 | m_acTEncTop[layer].destroy(); |
---|
773 | } |
---|
774 | #else |
---|
775 | m_cTVideoIOYuvInputFile.close(); |
---|
776 | m_cTVideoIOYuvReconFile.close(); |
---|
777 | |
---|
778 | // Neo Decoder |
---|
779 | m_cTEncTop.destroy(); |
---|
780 | #endif |
---|
781 | } |
---|
782 | |
---|
783 | Void TAppEncTop::xInitLib() |
---|
784 | { |
---|
785 | #if SVC_EXTENSION |
---|
786 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
787 | { |
---|
788 | m_acTEncTop[layer].init(); |
---|
789 | } |
---|
790 | #if VPS_RENAME |
---|
791 | m_acTEncTop[0].getVPS()->setMaxLayers( m_numLayers ); |
---|
792 | #endif |
---|
793 | #if VPS_EXTN_OP_LAYER_SETS |
---|
794 | TComVPS* vps = m_acTEncTop[0].getVPS(); |
---|
795 | vps->setMaxLayerId(m_numLayers - 1); // Set max-layer ID |
---|
796 | |
---|
797 | vps->setNumLayerSets(m_numLayers); |
---|
798 | for(Int setId = 1; setId < vps->getNumLayerSets(); setId++) |
---|
799 | { |
---|
800 | for(Int layerId = 0; layerId <= vps->getMaxLayerId(); layerId++) |
---|
801 | { |
---|
802 | vps->setLayerIdIncludedFlag(true, setId, layerId); |
---|
803 | } |
---|
804 | } |
---|
805 | #if VPS_EXTN_MASK_AND_DIM_INFO |
---|
806 | UInt i = 0, dimIdLen = 0; |
---|
807 | vps->setAvcBaseLayerFlag(false); |
---|
808 | vps->setSplittingFlag(false); |
---|
809 | for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++) |
---|
810 | { |
---|
811 | vps->setScalabilityMask(i, false); |
---|
812 | } |
---|
813 | if(m_numLayers > 1) |
---|
814 | { |
---|
815 | vps->setScalabilityMask(1, true); // Only turn on spatial/SNR scalability |
---|
816 | vps->setNumScalabilityTypes(1); |
---|
817 | } |
---|
818 | else |
---|
819 | { |
---|
820 | vps->setNumScalabilityTypes(0); |
---|
821 | } |
---|
822 | while((1 << dimIdLen) < m_numLayers) |
---|
823 | { |
---|
824 | dimIdLen++; |
---|
825 | } |
---|
826 | vps->setDimensionIdLen(0, dimIdLen); |
---|
827 | vps->setNuhLayerIdPresentFlag(false); |
---|
828 | vps->setLayerIdInNuh(0, 0); |
---|
829 | vps->setLayerIdInVps(0, 0); |
---|
830 | for(i = 1; i < vps->getMaxLayers(); i++) |
---|
831 | { |
---|
832 | vps->setLayerIdInNuh(i, i); |
---|
833 | vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i); |
---|
834 | vps->setDimensionId(i, 0, i); |
---|
835 | } |
---|
836 | #endif |
---|
837 | #if VPS_EXTN_PROFILE_INFO |
---|
838 | vps->getPTLForExtnPtr()->resize(vps->getNumLayerSets()); |
---|
839 | for(Int setId = 1; setId < vps->getNumLayerSets(); setId++) |
---|
840 | { |
---|
841 | vps->setProfilePresentFlag(setId, true); |
---|
842 | // Note - may need to be changed for other layer structures. |
---|
843 | *(vps->getPTLForExtn(setId)) = *(m_acTEncTop[setId].getSPS()->getPTL()); |
---|
844 | } |
---|
845 | #endif |
---|
846 | // Target output layer |
---|
847 | vps->setNumOutputLayerSets(1); |
---|
848 | Int lsIdx = 1; |
---|
849 | vps->setOutputLayerSetIdx(0, lsIdx); // Because only one layer set |
---|
850 | // Include the highest layer as output layer |
---|
851 | for(UInt layer=0; layer <= vps->getMaxLayerId() ; layer++) |
---|
852 | { |
---|
853 | if(vps->getLayerIdIncludedFlag(lsIdx, layer)) |
---|
854 | { |
---|
855 | vps->setOutputLayerFlag(lsIdx, layer, layer == (vps->getMaxLayerId())); |
---|
856 | } |
---|
857 | } |
---|
858 | #endif |
---|
859 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
860 | // Direct reference layers |
---|
861 | for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++) |
---|
862 | { |
---|
863 | vps->setNumDirectRefLayers( layerCtr, m_acTEncTop[layerCtr].getNumDirectRefLayers() ); |
---|
864 | for(i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++) |
---|
865 | { |
---|
866 | vps->setRefLayerId( layerCtr, i, m_acTEncTop[layerCtr].getRefLayerId(i) ); |
---|
867 | } |
---|
868 | // Set direct dependency flag |
---|
869 | // Initialize flag to 0 |
---|
870 | for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++) |
---|
871 | { |
---|
872 | vps->setDirectDependencyFlag( layerCtr, refLayerCtr, false ); |
---|
873 | } |
---|
874 | for(i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++) |
---|
875 | { |
---|
876 | vps->setDirectDependencyFlag( layerCtr, vps->getLayerIdInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true); |
---|
877 | } |
---|
878 | } |
---|
879 | #endif |
---|
880 | #else |
---|
881 | m_cTEncTop.init(); |
---|
882 | #endif |
---|
883 | } |
---|
884 | |
---|
885 | // ==================================================================================================================== |
---|
886 | // Public member functions |
---|
887 | // ==================================================================================================================== |
---|
888 | |
---|
889 | /** |
---|
890 | - create internal class |
---|
891 | - initialize internal variable |
---|
892 | - until the end of input YUV file, call encoding function in TEncTop class |
---|
893 | - delete allocated buffers |
---|
894 | - destroy internal class |
---|
895 | . |
---|
896 | */ |
---|
897 | #if SVC_EXTENSION |
---|
898 | Void TAppEncTop::encode() |
---|
899 | { |
---|
900 | fstream bitstreamFile(m_pBitstreamFile, fstream::binary | fstream::out); |
---|
901 | if (!bitstreamFile) |
---|
902 | { |
---|
903 | fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pBitstreamFile); |
---|
904 | exit(EXIT_FAILURE); |
---|
905 | } |
---|
906 | |
---|
907 | TComPicYuv* pcPicYuvOrg [MAX_LAYERS]; |
---|
908 | TComPicYuv* pcPicYuvRec = NULL; |
---|
909 | |
---|
910 | // initialize internal class & member variables |
---|
911 | xInitLibCfg(); |
---|
912 | xCreateLib(); |
---|
913 | xInitLib(); |
---|
914 | |
---|
915 | // main encoder loop |
---|
916 | Int iNumEncoded = 0, iTotalNumEncoded = 0; |
---|
917 | Bool bEos = false; |
---|
918 | |
---|
919 | list<AccessUnit> outputAccessUnits; ///< list of access units to write out. is populated by the encoding process |
---|
920 | |
---|
921 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
922 | { |
---|
923 | // allocate original YUV buffer |
---|
924 | pcPicYuvOrg[layer] = new TComPicYuv; |
---|
925 | #if SVC_UPSAMPLING |
---|
926 | pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL ); |
---|
927 | #else |
---|
928 | pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth ); |
---|
929 | #endif |
---|
930 | } |
---|
931 | |
---|
932 | #if AVC_SYNTAX |
---|
933 | if( !m_BLSyntaxFile ) |
---|
934 | { |
---|
935 | printf( "Wrong base layer syntax input file\n" ); |
---|
936 | exit(EXIT_FAILURE); |
---|
937 | } |
---|
938 | fstream streamSyntaxFile( m_BLSyntaxFile, fstream::in | fstream::binary ); |
---|
939 | if( !streamSyntaxFile.good() ) |
---|
940 | { |
---|
941 | printf( "Base layer syntax input reading error\n" ); |
---|
942 | exit(EXIT_FAILURE); |
---|
943 | } |
---|
944 | m_acTEncTop[0].setBLSyntaxFile( &streamSyntaxFile ); |
---|
945 | #endif |
---|
946 | |
---|
947 | Bool bFirstFrame = true; |
---|
948 | while ( !bEos ) |
---|
949 | { |
---|
950 | // Read enough frames |
---|
951 | Bool bFramesReadyToCode = false; |
---|
952 | while(!bFramesReadyToCode) |
---|
953 | { |
---|
954 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
955 | { |
---|
956 | // get buffers |
---|
957 | xGetBuffer(pcPicYuvRec, layer); |
---|
958 | |
---|
959 | // read input YUV file |
---|
960 | m_acTVideoIOYuvInputFile[layer].read( pcPicYuvOrg[layer], m_acLayerCfg[layer].getPad() ); |
---|
961 | |
---|
962 | if(layer == m_numLayers-1) |
---|
963 | { |
---|
964 | // increase number of received frames |
---|
965 | m_iFrameRcvd++; |
---|
966 | // check end of file |
---|
967 | bEos = (m_iFrameRcvd == m_framesToBeEncoded); |
---|
968 | } |
---|
969 | |
---|
970 | m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer] ); |
---|
971 | } |
---|
972 | |
---|
973 | bFramesReadyToCode = !(!bFirstFrame && ( m_acTEncTop[m_numLayers-1].getNumPicRcvd() != m_iGOPSize && m_iGOPSize ) && !bEos ); |
---|
974 | } |
---|
975 | Bool flush = 0; |
---|
976 | // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures |
---|
977 | if (m_acTVideoIOYuvInputFile[m_numLayers-1].isEof()) |
---|
978 | { |
---|
979 | flush = true; |
---|
980 | bEos = true; |
---|
981 | m_iFrameRcvd--; |
---|
982 | m_acTEncTop[m_numLayers-1].setFramesToBeEncoded(m_iFrameRcvd); |
---|
983 | } |
---|
984 | |
---|
985 | // loop through frames in one GOP |
---|
986 | for ( UInt iPicIdInGOP=0; iPicIdInGOP < (bFirstFrame? 1:m_iGOPSize); iPicIdInGOP++ ) |
---|
987 | { |
---|
988 | // layer by layer for each frame |
---|
989 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
990 | { |
---|
991 | // call encoding function for one frame |
---|
992 | m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP ); |
---|
993 | } |
---|
994 | } |
---|
995 | |
---|
996 | iTotalNumEncoded = 0; |
---|
997 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
998 | { |
---|
999 | // write bistream to file if necessary |
---|
1000 | iNumEncoded = m_acTEncTop[layer].getNumPicRcvd(); |
---|
1001 | if ( iNumEncoded > 0 ) |
---|
1002 | { |
---|
1003 | xWriteRecon(layer, iNumEncoded); |
---|
1004 | iTotalNumEncoded += iNumEncoded; |
---|
1005 | } |
---|
1006 | m_acTEncTop[layer].setNumPicRcvd( 0 ); |
---|
1007 | } |
---|
1008 | |
---|
1009 | // write bitstream out |
---|
1010 | if(iTotalNumEncoded) |
---|
1011 | { |
---|
1012 | xWriteStream(bitstreamFile, iTotalNumEncoded, outputAccessUnits); |
---|
1013 | outputAccessUnits.clear(); |
---|
1014 | } |
---|
1015 | |
---|
1016 | // print out summary |
---|
1017 | if (bEos) |
---|
1018 | { |
---|
1019 | printOutSummary(); |
---|
1020 | } |
---|
1021 | |
---|
1022 | bFirstFrame = false; |
---|
1023 | } |
---|
1024 | // delete original YUV buffer |
---|
1025 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
1026 | { |
---|
1027 | pcPicYuvOrg[layer]->destroy(); |
---|
1028 | delete pcPicYuvOrg[layer]; |
---|
1029 | pcPicYuvOrg[layer] = NULL; |
---|
1030 | |
---|
1031 | // delete used buffers in encoder class |
---|
1032 | m_acTEncTop[layer].deletePicBuffer(); |
---|
1033 | } |
---|
1034 | |
---|
1035 | #if AVC_SYNTAX |
---|
1036 | if( streamSyntaxFile.is_open() ) |
---|
1037 | { |
---|
1038 | streamSyntaxFile.close(); |
---|
1039 | } |
---|
1040 | #endif |
---|
1041 | |
---|
1042 | // delete buffers & classes |
---|
1043 | xDeleteBuffer(); |
---|
1044 | xDestroyLib(); |
---|
1045 | |
---|
1046 | printRateSummary(); |
---|
1047 | |
---|
1048 | return; |
---|
1049 | } |
---|
1050 | |
---|
1051 | Void TAppEncTop::printOutSummary() |
---|
1052 | { |
---|
1053 | UInt layer; |
---|
1054 | |
---|
1055 | // set frame rate |
---|
1056 | for(layer = 0; layer < m_numLayers; layer++) |
---|
1057 | { |
---|
1058 | m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate()); |
---|
1059 | m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() ); |
---|
1060 | m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() ); |
---|
1061 | m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() ); |
---|
1062 | } |
---|
1063 | |
---|
1064 | //-- all |
---|
1065 | printf( "\n\nSUMMARY --------------------------------------------------------\n" ); |
---|
1066 | printf( "\tTotal Frames | " "Bitrate " "Y-PSNR " "U-PSNR " "V-PSNR \n" ); |
---|
1067 | for(layer = 0; layer < m_numLayers; layer++) |
---|
1068 | { |
---|
1069 | m_gcAnalyzeAll[layer].printOut('a', layer); |
---|
1070 | } |
---|
1071 | |
---|
1072 | printf( "\n\nI Slices--------------------------------------------------------\n" ); |
---|
1073 | printf( "\tTotal Frames | " "Bitrate " "Y-PSNR " "U-PSNR " "V-PSNR \n" ); |
---|
1074 | for(layer = 0; layer < m_numLayers; layer++) |
---|
1075 | { |
---|
1076 | m_gcAnalyzeI[layer].printOut('i', layer); |
---|
1077 | } |
---|
1078 | |
---|
1079 | printf( "\n\nP Slices--------------------------------------------------------\n" ); |
---|
1080 | printf( "\tTotal Frames | " "Bitrate " "Y-PSNR " "U-PSNR " "V-PSNR \n" ); |
---|
1081 | for(layer = 0; layer < m_numLayers; layer++) |
---|
1082 | { |
---|
1083 | m_gcAnalyzeP[layer].printOut('p', layer); |
---|
1084 | } |
---|
1085 | |
---|
1086 | printf( "\n\nB Slices--------------------------------------------------------\n" ); |
---|
1087 | printf( "\tTotal Frames | " "Bitrate " "Y-PSNR " "U-PSNR " "V-PSNR \n" ); |
---|
1088 | for(layer = 0; layer < m_numLayers; layer++) |
---|
1089 | { |
---|
1090 | m_gcAnalyzeB[layer].printOut('b', layer); |
---|
1091 | } |
---|
1092 | } |
---|
1093 | |
---|
1094 | #else |
---|
1095 | Void TAppEncTop::encode() |
---|
1096 | { |
---|
1097 | fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out); |
---|
1098 | if (!bitstreamFile) |
---|
1099 | { |
---|
1100 | fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile); |
---|
1101 | exit(EXIT_FAILURE); |
---|
1102 | } |
---|
1103 | |
---|
1104 | TComPicYuv* pcPicYuvOrg = new TComPicYuv; |
---|
1105 | TComPicYuv* pcPicYuvRec = NULL; |
---|
1106 | |
---|
1107 | // initialize internal class & member variables |
---|
1108 | xInitLibCfg(); |
---|
1109 | xCreateLib(); |
---|
1110 | xInitLib(); |
---|
1111 | |
---|
1112 | // main encoder loop |
---|
1113 | Int iNumEncoded = 0; |
---|
1114 | Bool bEos = false; |
---|
1115 | |
---|
1116 | list<AccessUnit> outputAccessUnits; ///< list of access units to write out. is populated by the encoding process |
---|
1117 | |
---|
1118 | // allocate original YUV buffer |
---|
1119 | pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth ); |
---|
1120 | |
---|
1121 | while ( !bEos ) |
---|
1122 | { |
---|
1123 | // get buffers |
---|
1124 | xGetBuffer(pcPicYuvRec); |
---|
1125 | |
---|
1126 | // read input YUV file |
---|
1127 | m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, m_aiPad ); |
---|
1128 | |
---|
1129 | // increase number of received frames |
---|
1130 | m_iFrameRcvd++; |
---|
1131 | |
---|
1132 | bEos = (m_iFrameRcvd == m_framesToBeEncoded); |
---|
1133 | |
---|
1134 | Bool flush = 0; |
---|
1135 | // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures |
---|
1136 | if (m_cTVideoIOYuvInputFile.isEof()) |
---|
1137 | { |
---|
1138 | flush = true; |
---|
1139 | bEos = true; |
---|
1140 | m_iFrameRcvd--; |
---|
1141 | m_cTEncTop.setFramesToBeEncoded(m_iFrameRcvd); |
---|
1142 | } |
---|
1143 | |
---|
1144 | // call encoding function for one frame |
---|
1145 | m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded ); |
---|
1146 | |
---|
1147 | // write bistream to file if necessary |
---|
1148 | if ( iNumEncoded > 0 ) |
---|
1149 | { |
---|
1150 | xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits); |
---|
1151 | outputAccessUnits.clear(); |
---|
1152 | } |
---|
1153 | } |
---|
1154 | |
---|
1155 | m_cTEncTop.printSummary(); |
---|
1156 | |
---|
1157 | // delete original YUV buffer |
---|
1158 | pcPicYuvOrg->destroy(); |
---|
1159 | delete pcPicYuvOrg; |
---|
1160 | pcPicYuvOrg = NULL; |
---|
1161 | |
---|
1162 | // delete used buffers in encoder class |
---|
1163 | m_cTEncTop.deletePicBuffer(); |
---|
1164 | |
---|
1165 | // delete buffers & classes |
---|
1166 | xDeleteBuffer(); |
---|
1167 | xDestroyLib(); |
---|
1168 | |
---|
1169 | printRateSummary(); |
---|
1170 | |
---|
1171 | return; |
---|
1172 | } |
---|
1173 | #endif |
---|
1174 | |
---|
1175 | // ==================================================================================================================== |
---|
1176 | // Protected member functions |
---|
1177 | // ==================================================================================================================== |
---|
1178 | |
---|
1179 | /** |
---|
1180 | - application has picture buffer list with size of GOP |
---|
1181 | - picture buffer list acts as ring buffer |
---|
1182 | - end of the list has the latest picture |
---|
1183 | . |
---|
1184 | */ |
---|
1185 | #if SVC_EXTENSION |
---|
1186 | Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer) |
---|
1187 | { |
---|
1188 | assert( m_iGOPSize > 0 ); |
---|
1189 | |
---|
1190 | // org. buffer |
---|
1191 | if ( m_acListPicYuvRec[layer].size() == (UInt)m_iGOPSize ) |
---|
1192 | { |
---|
1193 | rpcPicYuvRec = m_acListPicYuvRec[layer].popFront(); |
---|
1194 | |
---|
1195 | } |
---|
1196 | else |
---|
1197 | { |
---|
1198 | rpcPicYuvRec = new TComPicYuv; |
---|
1199 | |
---|
1200 | #if SVC_UPSAMPLING |
---|
1201 | rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL ); |
---|
1202 | #else |
---|
1203 | rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth ); |
---|
1204 | #endif |
---|
1205 | |
---|
1206 | } |
---|
1207 | m_acListPicYuvRec[layer].pushBack( rpcPicYuvRec ); |
---|
1208 | } |
---|
1209 | |
---|
1210 | Void TAppEncTop::xDeleteBuffer( ) |
---|
1211 | { |
---|
1212 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
1213 | { |
---|
1214 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].begin(); |
---|
1215 | |
---|
1216 | Int iSize = Int( m_acListPicYuvRec[layer].size() ); |
---|
1217 | |
---|
1218 | for ( Int i = 0; i < iSize; i++ ) |
---|
1219 | { |
---|
1220 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
---|
1221 | pcPicYuvRec->destroy(); |
---|
1222 | delete pcPicYuvRec; pcPicYuvRec = NULL; |
---|
1223 | } |
---|
1224 | } |
---|
1225 | } |
---|
1226 | |
---|
1227 | Void TAppEncTop::xWriteRecon(UInt layer, Int iNumEncoded) |
---|
1228 | { |
---|
1229 | Int i; |
---|
1230 | |
---|
1231 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end(); |
---|
1232 | |
---|
1233 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
1234 | { |
---|
1235 | --iterPicYuvRec; |
---|
1236 | } |
---|
1237 | |
---|
1238 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
1239 | { |
---|
1240 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
---|
1241 | if (!m_acLayerCfg[layer].getReconFile().empty()) |
---|
1242 | { |
---|
1243 | m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(), |
---|
1244 | m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom() ); |
---|
1245 | } |
---|
1246 | } |
---|
1247 | } |
---|
1248 | |
---|
1249 | Void TAppEncTop::xWriteStream(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits) |
---|
1250 | { |
---|
1251 | Int i; |
---|
1252 | |
---|
1253 | list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin(); |
---|
1254 | |
---|
1255 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
1256 | { |
---|
1257 | const AccessUnit& au = *(iterBitstream++); |
---|
1258 | const vector<UInt>& stats = writeAnnexB(bitstreamFile, au); |
---|
1259 | rateStatsAccum(au, stats); |
---|
1260 | } |
---|
1261 | } |
---|
1262 | |
---|
1263 | #else // SVC_EXTENSION |
---|
1264 | Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec) |
---|
1265 | { |
---|
1266 | assert( m_iGOPSize > 0 ); |
---|
1267 | |
---|
1268 | // org. buffer |
---|
1269 | if ( m_cListPicYuvRec.size() == (UInt)m_iGOPSize ) |
---|
1270 | { |
---|
1271 | rpcPicYuvRec = m_cListPicYuvRec.popFront(); |
---|
1272 | |
---|
1273 | } |
---|
1274 | else |
---|
1275 | { |
---|
1276 | rpcPicYuvRec = new TComPicYuv; |
---|
1277 | |
---|
1278 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth ); |
---|
1279 | |
---|
1280 | } |
---|
1281 | m_cListPicYuvRec.pushBack( rpcPicYuvRec ); |
---|
1282 | } |
---|
1283 | |
---|
1284 | Void TAppEncTop::xDeleteBuffer( ) |
---|
1285 | { |
---|
1286 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.begin(); |
---|
1287 | |
---|
1288 | Int iSize = Int( m_cListPicYuvRec.size() ); |
---|
1289 | |
---|
1290 | for ( Int i = 0; i < iSize; i++ ) |
---|
1291 | { |
---|
1292 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
---|
1293 | pcPicYuvRec->destroy(); |
---|
1294 | delete pcPicYuvRec; pcPicYuvRec = NULL; |
---|
1295 | } |
---|
1296 | |
---|
1297 | } |
---|
1298 | |
---|
1299 | /** \param iNumEncoded number of encoded frames |
---|
1300 | */ |
---|
1301 | Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits) |
---|
1302 | { |
---|
1303 | Int i; |
---|
1304 | |
---|
1305 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end(); |
---|
1306 | list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin(); |
---|
1307 | |
---|
1308 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
1309 | { |
---|
1310 | --iterPicYuvRec; |
---|
1311 | } |
---|
1312 | |
---|
1313 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
1314 | { |
---|
1315 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
---|
1316 | if (m_pchReconFile) |
---|
1317 | { |
---|
1318 | #if SYNTAX_OUTPUT && ILP_DECODED_PICTURE |
---|
1319 | m_cTVideoIOYuvReconFile.write( pcPicYuvRec ); |
---|
1320 | #else |
---|
1321 | m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom ); |
---|
1322 | #endif |
---|
1323 | } |
---|
1324 | |
---|
1325 | const AccessUnit& au = *(iterBitstream++); |
---|
1326 | const vector<UInt>& stats = writeAnnexB(bitstreamFile, au); |
---|
1327 | rateStatsAccum(au, stats); |
---|
1328 | } |
---|
1329 | } |
---|
1330 | #endif |
---|
1331 | |
---|
1332 | /** |
---|
1333 | * |
---|
1334 | */ |
---|
1335 | void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& annexBsizes) |
---|
1336 | { |
---|
1337 | AccessUnit::const_iterator it_au = au.begin(); |
---|
1338 | vector<UInt>::const_iterator it_stats = annexBsizes.begin(); |
---|
1339 | |
---|
1340 | for (; it_au != au.end(); it_au++, it_stats++) |
---|
1341 | { |
---|
1342 | switch ((*it_au)->m_nalUnitType) |
---|
1343 | { |
---|
1344 | case NAL_UNIT_CODED_SLICE_TRAIL_R: |
---|
1345 | case NAL_UNIT_CODED_SLICE_TRAIL_N: |
---|
1346 | case NAL_UNIT_CODED_SLICE_TLA_R: |
---|
1347 | case NAL_UNIT_CODED_SLICE_TSA_N: |
---|
1348 | case NAL_UNIT_CODED_SLICE_STSA_R: |
---|
1349 | case NAL_UNIT_CODED_SLICE_STSA_N: |
---|
1350 | case NAL_UNIT_CODED_SLICE_BLA_W_LP: |
---|
1351 | case NAL_UNIT_CODED_SLICE_BLA_W_RADL: |
---|
1352 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: |
---|
1353 | case NAL_UNIT_CODED_SLICE_IDR_W_RADL: |
---|
1354 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: |
---|
1355 | case NAL_UNIT_CODED_SLICE_CRA: |
---|
1356 | case NAL_UNIT_CODED_SLICE_RADL_N: |
---|
1357 | case NAL_UNIT_CODED_SLICE_RADL_R: |
---|
1358 | case NAL_UNIT_CODED_SLICE_RASL_N: |
---|
1359 | case NAL_UNIT_CODED_SLICE_RASL_R: |
---|
1360 | case NAL_UNIT_VPS: |
---|
1361 | case NAL_UNIT_SPS: |
---|
1362 | case NAL_UNIT_PPS: |
---|
1363 | m_essentialBytes += *it_stats; |
---|
1364 | break; |
---|
1365 | default: |
---|
1366 | break; |
---|
1367 | } |
---|
1368 | |
---|
1369 | m_totalBytes += *it_stats; |
---|
1370 | } |
---|
1371 | } |
---|
1372 | |
---|
1373 | void TAppEncTop::printRateSummary() |
---|
1374 | { |
---|
1375 | #if SVC_EXTENSION |
---|
1376 | Double time = (Double) m_iFrameRcvd / m_acLayerCfg[m_numLayers-1].getFrameRate(); |
---|
1377 | #else |
---|
1378 | Double time = (Double) m_iFrameRcvd / m_iFrameRate; |
---|
1379 | #endif |
---|
1380 | printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time); |
---|
1381 | #if VERBOSE_RATE |
---|
1382 | printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time); |
---|
1383 | #endif |
---|
1384 | } |
---|
1385 | |
---|
1386 | //! \} |
---|