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