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