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-2016, 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 | #include <iomanip> |
---|
45 | |
---|
46 | #include "TAppEncTop.h" |
---|
47 | #include "TLibEncoder/AnnexBwrite.h" |
---|
48 | |
---|
49 | using namespace std; |
---|
50 | |
---|
51 | //! \ingroup TAppEncoder |
---|
52 | //! \{ |
---|
53 | |
---|
54 | // ==================================================================================================================== |
---|
55 | // Constructor / destructor / initialization / destroy |
---|
56 | // ==================================================================================================================== |
---|
57 | |
---|
58 | TAppEncTop::TAppEncTop() |
---|
59 | { |
---|
60 | |
---|
61 | #if NH_MV |
---|
62 | m_vps = new TComVPS; |
---|
63 | #else |
---|
64 | m_iFrameRcvd = 0; |
---|
65 | #endif |
---|
66 | m_totalBytes = 0; |
---|
67 | m_essentialBytes = 0; |
---|
68 | } |
---|
69 | |
---|
70 | TAppEncTop::~TAppEncTop() |
---|
71 | { |
---|
72 | #if NH_MV |
---|
73 | if (m_vps) |
---|
74 | { |
---|
75 | delete m_vps; |
---|
76 | }; |
---|
77 | #endif |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | Void TAppEncTop::xInitLibCfg() |
---|
82 | { |
---|
83 | #if NH_MV |
---|
84 | TComVPS& vps = (*m_vps); |
---|
85 | #else |
---|
86 | TComVPS vps; |
---|
87 | #endif |
---|
88 | |
---|
89 | #if NH_3D |
---|
90 | vps.createCamPars(m_iNumberOfViews); |
---|
91 | #endif |
---|
92 | |
---|
93 | #if NH_3D_DLT |
---|
94 | TComDLT dlt = TComDLT(); |
---|
95 | #endif |
---|
96 | |
---|
97 | #if NH_MV |
---|
98 | Int maxTempLayer = -1; |
---|
99 | for (Int j = 0; j < m_numberOfLayers; j++) |
---|
100 | { |
---|
101 | maxTempLayer = max( m_maxTempLayerMvc[ j ], maxTempLayer ); |
---|
102 | } |
---|
103 | |
---|
104 | vps.setMaxTLayers ( maxTempLayer ); |
---|
105 | if ( maxTempLayer ) |
---|
106 | { |
---|
107 | vps.setTemporalNestingFlag(true); |
---|
108 | } |
---|
109 | vps.setMaxLayersMinus1( m_numberOfLayers - 1); |
---|
110 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
111 | { |
---|
112 | Int maxNumReOrderPics = 0; |
---|
113 | Int maxDecPicBuffering = 0; |
---|
114 | for (Int j = 0; j < m_numberOfLayers; j++) |
---|
115 | { |
---|
116 | maxNumReOrderPics = max( maxNumReOrderPics, m_numReorderPicsMvc [ j ][ i ] ); |
---|
117 | maxDecPicBuffering = max( maxDecPicBuffering, m_maxDecPicBufferingMvc[ j ][ i ] ); |
---|
118 | } |
---|
119 | |
---|
120 | vps.setNumReorderPics ( maxNumReOrderPics ,i ); |
---|
121 | vps.setMaxDecPicBuffering ( maxDecPicBuffering ,i ); |
---|
122 | } |
---|
123 | #else |
---|
124 | vps.setMaxTLayers ( m_maxTempLayer ); |
---|
125 | if (m_maxTempLayer == 1) |
---|
126 | { |
---|
127 | vps.setTemporalNestingFlag(true); |
---|
128 | } |
---|
129 | vps.setMaxLayers ( 1 ); |
---|
130 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
131 | { |
---|
132 | vps.setNumReorderPics ( m_numReorderPics[i], i ); |
---|
133 | vps.setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i ); |
---|
134 | } |
---|
135 | #endif |
---|
136 | #if NH_MV |
---|
137 | xSetTimingInfo ( vps ); |
---|
138 | xSetHrdParameters ( vps ); |
---|
139 | xSetLayerIds ( vps ); |
---|
140 | xSetDimensionIdAndLength ( vps ); |
---|
141 | xSetDependencies ( vps ); |
---|
142 | xSetRepFormat ( vps ); |
---|
143 | xSetProfileTierLevel ( vps ); |
---|
144 | xSetLayerSets ( vps ); |
---|
145 | xSetDpbSize ( vps ); |
---|
146 | xSetVPSVUI ( vps ); |
---|
147 | #if NH_3D |
---|
148 | xSetCamPara ( vps ); |
---|
149 | #endif |
---|
150 | #if NH_3D_VSO || NH_3D |
---|
151 | m_ivPicLists.setVPS ( &vps ); |
---|
152 | #endif |
---|
153 | #if NH_3D_DLT |
---|
154 | xDeriveDltArray ( vps, &dlt ); |
---|
155 | #endif |
---|
156 | if ( m_targetEncLayerIdList.size() == 0 ) |
---|
157 | { |
---|
158 | for (Int i = 0; i < m_numberOfLayers; i++ ) |
---|
159 | { |
---|
160 | m_targetEncLayerIdList.push_back( vps.getLayerIdInNuh( i ) ); |
---|
161 | } |
---|
162 | } |
---|
163 | for( Int i = (Int) m_targetEncLayerIdList.size()-1 ; i >= 0 ; i--) |
---|
164 | { |
---|
165 | Int iNuhLayerId = m_targetEncLayerIdList[i]; |
---|
166 | Bool allRefLayersPresent = true; |
---|
167 | for( Int j = 0; j < vps.getNumRefLayers( iNuhLayerId ); j++) |
---|
168 | { |
---|
169 | allRefLayersPresent = allRefLayersPresent && xLayerIdInTargetEncLayerIdList( vps.getIdRefLayer( iNuhLayerId, j) ); |
---|
170 | } |
---|
171 | if ( !allRefLayersPresent ) |
---|
172 | { |
---|
173 | printf("\nCannot encode layer with nuh_layer_id equal to %d since not all reference layers are in TargetEncLayerIdList\n", iNuhLayerId); |
---|
174 | m_targetEncLayerIdList.erase( m_targetEncLayerIdList.begin() + i ); |
---|
175 | } |
---|
176 | } |
---|
177 | |
---|
178 | if ( m_outputVpsInfo ) |
---|
179 | { |
---|
180 | vps.printScalabilityId(); |
---|
181 | vps.printLayerDependencies(); |
---|
182 | vps.printLayerSets(); |
---|
183 | vps.printPTL(); |
---|
184 | } |
---|
185 | |
---|
186 | #if NH_3D |
---|
187 | // Set 3d tool parameters |
---|
188 | for (Int d = 0; d < 2; d++) |
---|
189 | { |
---|
190 | m_sps3dExtension.setIvDiMcEnabledFlag ( d, m_ivMvPredFlag[d] ); |
---|
191 | m_sps3dExtension.setIvMvScalEnabledFlag ( d, m_ivMvScalingFlag[d] ); |
---|
192 | if (d == 0 ) |
---|
193 | { |
---|
194 | m_sps3dExtension.setLog2IvmcSubPbSizeMinus3 ( d, m_log2SubPbSizeMinus3 ); |
---|
195 | m_sps3dExtension.setIvResPredEnabledFlag ( d, m_ivResPredFlag ); |
---|
196 | m_sps3dExtension.setDepthRefEnabledFlag ( d, m_depthRefinementFlag ); |
---|
197 | m_sps3dExtension.setVspMcEnabledFlag ( d, m_viewSynthesisPredFlag ); |
---|
198 | m_sps3dExtension.setDbbpEnabledFlag ( d, m_depthBasedBlkPartFlag ); |
---|
199 | } |
---|
200 | else |
---|
201 | { |
---|
202 | m_sps3dExtension.setTexMcEnabledFlag ( d, m_mpiFlag ); |
---|
203 | m_sps3dExtension.setLog2TexmcSubPbSizeMinus3( d, m_log2MpiSubPbSizeMinus3); |
---|
204 | m_sps3dExtension.setIntraContourEnabledFlag ( d, m_intraContourFlag ); |
---|
205 | m_sps3dExtension.setIntraDcOnlyWedgeEnabledFlag ( d, m_intraSdcFlag || m_intraWedgeFlag ); |
---|
206 | m_sps3dExtension.setCqtCuPartPredEnabledFlag ( d, m_qtPredFlag ); |
---|
207 | m_sps3dExtension.setInterDcOnlyEnabledFlag ( d, m_interSdcFlag ); |
---|
208 | m_sps3dExtension.setSkipIntraEnabledFlag ( d, m_depthIntraSkipFlag ); |
---|
209 | } |
---|
210 | } |
---|
211 | #endif |
---|
212 | |
---|
213 | |
---|
214 | /// Create encoders and set profiles profiles |
---|
215 | for(Int layerIdInVps = 0; layerIdInVps < m_numberOfLayers; layerIdInVps++) |
---|
216 | { |
---|
217 | m_frameRcvd .push_back(0); |
---|
218 | m_acTEncTopList .push_back(new TEncTop); |
---|
219 | m_acTVideoIOYuvInputFileList.push_back(new TVideoIOYuv); |
---|
220 | m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv); |
---|
221 | #if NH_3D |
---|
222 | Int profileIdc = -1; |
---|
223 | for (Int olsIdx = 0; olsIdx < vps.getNumOutputLayerSets(); olsIdx++ ) |
---|
224 | { |
---|
225 | Int lsIdx = vps.olsIdxToLsIdx( olsIdx ); |
---|
226 | for(Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++ ) |
---|
227 | { |
---|
228 | if( vps.getLayerIdInNuh( layerIdInVps) == vps.getLayerSetLayerIdList(lsIdx, i) ) |
---|
229 | { |
---|
230 | Int ptlIdx = vps.getProfileTierLevelIdx( olsIdx, i ); |
---|
231 | if ( ptlIdx != -1 ) |
---|
232 | { |
---|
233 | Int curProfileIdc = vps.getPTL(ptlIdx)->getGeneralPTL()->getProfileIdc(); |
---|
234 | if (profileIdc == -1) |
---|
235 | { |
---|
236 | profileIdc = curProfileIdc; |
---|
237 | } |
---|
238 | else |
---|
239 | { |
---|
240 | if ( profileIdc != curProfileIdc ) |
---|
241 | { |
---|
242 | fprintf(stderr, "Error: ProfileIdc for layer with index %d in VPS not equal in all OLSs. \n", layerIdInVps ); |
---|
243 | exit(EXIT_FAILURE); |
---|
244 | } |
---|
245 | } |
---|
246 | } |
---|
247 | } |
---|
248 | } |
---|
249 | } |
---|
250 | |
---|
251 | if (profileIdc == -1 ) |
---|
252 | { |
---|
253 | fprintf(stderr, "Error: No profile given for layer with index %d in VPS not equal in all OLS. \n", layerIdInVps ); |
---|
254 | exit(EXIT_FAILURE); |
---|
255 | } |
---|
256 | m_acTEncTopList[ layerIdInVps ]->setProfileIdc( profileIdc ); |
---|
257 | #endif |
---|
258 | } |
---|
259 | |
---|
260 | |
---|
261 | for(Int layerIdInVps = 0; layerIdInVps < m_numberOfLayers; layerIdInVps++) |
---|
262 | { |
---|
263 | m_cListPicYuvRec .push_back(new TComList<TComPicYuv*>) ; |
---|
264 | |
---|
265 | #if !NH_MV |
---|
266 | m_ivPicLists.push_back( m_acTEncTopList[ layerIdInVps ]->getListPic() ); |
---|
267 | #endif |
---|
268 | |
---|
269 | TEncTop& m_cTEncTop = *m_acTEncTopList[ layerIdInVps ]; // It is not a member, but this name helps avoiding code duplication !!! |
---|
270 | |
---|
271 | Int layerId = vps.getLayerIdInNuh ( layerIdInVps ); |
---|
272 | #if NH_MV |
---|
273 | m_ivPicLists.getSubDpb( layerId, true ); |
---|
274 | #endif |
---|
275 | |
---|
276 | m_cTEncTop.setLayerIdInVps ( layerIdInVps ); |
---|
277 | m_cTEncTop.setLayerId ( layerId ); |
---|
278 | m_cTEncTop.setViewId ( vps.getViewId ( layerId ) ); |
---|
279 | m_cTEncTop.setViewIndex ( vps.getViewIndex ( layerId ) ); |
---|
280 | #if NH_3D_VSO || NH_3D |
---|
281 | Bool isDepth = ( vps.getDepthId ( layerId ) != 0 ) ; |
---|
282 | Bool isAuxDepth = ( vps.getAuxId ( layerId ) == 2 ) ; // TBD: define 2 as AUX_DEPTH |
---|
283 | m_cTEncTop.setIsDepth ( isDepth ); |
---|
284 | m_cTEncTop.setIsAuxDepth ( isAuxDepth ); |
---|
285 | //====== Camera Parameters ========= |
---|
286 | m_cTEncTop.setCameraParameters ( &m_cCameraData ); |
---|
287 | #endif |
---|
288 | #if NH_3D_VSO |
---|
289 | //====== VSO ========= |
---|
290 | m_cTEncTop.setRenderModelParameters ( &m_cRenModStrParser ); |
---|
291 | m_cTEncTop.setForceLambdaScaleVSO ( isDepth || isAuxDepth ? m_bForceLambdaScaleVSO : false ); |
---|
292 | m_cTEncTop.setLambdaScaleVSO ( isDepth || isAuxDepth ? m_dLambdaScaleVSO : 1 ); |
---|
293 | m_cTEncTop.setVSOMode ( isDepth || isAuxDepth ? m_uiVSOMode : 0 ); |
---|
294 | |
---|
295 | m_cTEncTop.setAllowNegDist ( isDepth || isAuxDepth ? m_bAllowNegDist : false ); |
---|
296 | |
---|
297 | // SAIT_VSO_EST_A0033 |
---|
298 | m_cTEncTop.setUseEstimatedVSD ( isDepth || isAuxDepth ? m_bUseEstimatedVSD : false ); |
---|
299 | |
---|
300 | // LGE_WVSO_A0119 |
---|
301 | m_cTEncTop.setUseWVSO ( isDepth || isAuxDepth ? m_bUseWVSO : false ); |
---|
302 | m_cTEncTop.setVSOWeight ( isDepth || isAuxDepth ? m_iVSOWeight : 0 ); |
---|
303 | m_cTEncTop.setVSDWeight ( isDepth || isAuxDepth ? m_iVSDWeight : 0 ); |
---|
304 | m_cTEncTop.setDWeight ( isDepth || isAuxDepth ? m_iDWeight : 0 ); |
---|
305 | #endif // H_3D_VSO |
---|
306 | #if NH_3D |
---|
307 | #if NH_3D_IC |
---|
308 | m_cTEncTop.setUseIC ( vps.getViewIndex( layerId ) == 0 || isDepth ? false : m_abUseIC ); |
---|
309 | m_cTEncTop.setUseICLowLatencyEnc ( m_bUseLowLatencyICEnc ); |
---|
310 | #endif |
---|
311 | |
---|
312 | |
---|
313 | m_cTEncTop.setUseDMM ( isDepth ? m_intraWedgeFlag : false ); |
---|
314 | m_cTEncTop.setUseSDC ( isDepth ? m_intraSdcFlag : false ); |
---|
315 | m_cTEncTop.setUseDLT ( isDepth ? m_useDLT : false ); |
---|
316 | #endif |
---|
317 | #if NH_3D_QTL |
---|
318 | m_cTEncTop.setUseQTL ( isDepth || isAuxDepth ? m_bUseQTL : false ); |
---|
319 | #endif |
---|
320 | #if NH_3D |
---|
321 | m_cTEncTop.setSps3dExtension ( m_sps3dExtension ); |
---|
322 | #endif // NH_3D |
---|
323 | |
---|
324 | m_cTEncTop.setIvPicLists ( &m_ivPicLists ); |
---|
325 | #endif // NH_MV |
---|
326 | m_cTEncTop.setVPS(&vps); |
---|
327 | |
---|
328 | #if NH_3D_DLT |
---|
329 | m_cTEncTop.setDLT(dlt); |
---|
330 | #endif |
---|
331 | |
---|
332 | #if NH_MV |
---|
333 | m_cTEncTop.setProfile ( m_profiles[0]); |
---|
334 | m_cTEncTop.setLevel ( m_levelTier[0], m_level[0] ); |
---|
335 | #else |
---|
336 | m_cTEncTop.setProfile ( m_profile); |
---|
337 | m_cTEncTop.setLevel ( m_levelTier, m_level); |
---|
338 | #endif |
---|
339 | m_cTEncTop.setProgressiveSourceFlag ( m_progressiveSourceFlag); |
---|
340 | m_cTEncTop.setInterlacedSourceFlag ( m_interlacedSourceFlag); |
---|
341 | m_cTEncTop.setNonPackedConstraintFlag ( m_nonPackedConstraintFlag); |
---|
342 | m_cTEncTop.setFrameOnlyConstraintFlag ( m_frameOnlyConstraintFlag); |
---|
343 | m_cTEncTop.setBitDepthConstraintValue ( m_bitDepthConstraint ); |
---|
344 | m_cTEncTop.setChromaFormatConstraintValue ( m_chromaFormatConstraint ); |
---|
345 | m_cTEncTop.setIntraConstraintFlag ( m_intraConstraintFlag ); |
---|
346 | m_cTEncTop.setOnePictureOnlyConstraintFlag ( m_onePictureOnlyConstraintFlag ); |
---|
347 | m_cTEncTop.setLowerBitRateConstraintFlag ( m_lowerBitRateConstraintFlag ); |
---|
348 | |
---|
349 | m_cTEncTop.setPrintMSEBasedSequencePSNR ( m_printMSEBasedSequencePSNR); |
---|
350 | m_cTEncTop.setPrintFrameMSE ( m_printFrameMSE); |
---|
351 | m_cTEncTop.setPrintSequenceMSE ( m_printSequenceMSE); |
---|
352 | m_cTEncTop.setCabacZeroWordPaddingEnabled ( m_cabacZeroWordPaddingEnabled ); |
---|
353 | |
---|
354 | m_cTEncTop.setFrameRate ( m_iFrameRate ); |
---|
355 | m_cTEncTop.setFrameSkip ( m_FrameSkip ); |
---|
356 | m_cTEncTop.setTemporalSubsampleRatio ( m_temporalSubsampleRatio ); |
---|
357 | m_cTEncTop.setSourceWidth ( m_iSourceWidth ); |
---|
358 | m_cTEncTop.setSourceHeight ( m_iSourceHeight ); |
---|
359 | m_cTEncTop.setConformanceWindow ( m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom ); |
---|
360 | m_cTEncTop.setFramesToBeEncoded ( m_framesToBeEncoded ); |
---|
361 | |
---|
362 | //====== Coding Structure ======== |
---|
363 | #if NH_MV |
---|
364 | m_cTEncTop.setIntraPeriod ( m_iIntraPeriod[ layerIdInVps ] ); |
---|
365 | #else |
---|
366 | m_cTEncTop.setIntraPeriod ( m_iIntraPeriod ); |
---|
367 | #endif |
---|
368 | m_cTEncTop.setDecodingRefreshType ( m_iDecodingRefreshType ); |
---|
369 | m_cTEncTop.setGOPSize ( m_iGOPSize ); |
---|
370 | #if NH_MV |
---|
371 | m_cTEncTop.setGopList ( m_GOPListMvc[layerIdInVps] ); |
---|
372 | m_cTEncTop.setExtraRPSs ( m_extraRPSsMvc[layerIdInVps] ); |
---|
373 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
374 | { |
---|
375 | m_cTEncTop.setNumReorderPics ( m_numReorderPicsMvc[layerIdInVps][i], i ); |
---|
376 | m_cTEncTop.setMaxDecPicBuffering ( m_maxDecPicBufferingMvc[layerIdInVps][i], i ); |
---|
377 | } |
---|
378 | #else |
---|
379 | m_cTEncTop.setGopList ( m_GOPList ); |
---|
380 | m_cTEncTop.setExtraRPSs ( m_extraRPSs ); |
---|
381 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
382 | { |
---|
383 | m_cTEncTop.setNumReorderPics ( m_numReorderPics[i], i ); |
---|
384 | m_cTEncTop.setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i ); |
---|
385 | } |
---|
386 | #endif |
---|
387 | for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop ) |
---|
388 | { |
---|
389 | m_cTEncTop.setLambdaModifier ( uiLoop, m_adLambdaModifier[ uiLoop ] ); |
---|
390 | } |
---|
391 | m_cTEncTop.setIntraLambdaModifier ( m_adIntraLambdaModifier ); |
---|
392 | m_cTEncTop.setIntraQpFactor ( m_dIntraQpFactor ); |
---|
393 | |
---|
394 | #if NH_MV |
---|
395 | m_cTEncTop.setQP ( m_iQP[layerIdInVps] ); |
---|
396 | #else |
---|
397 | m_cTEncTop.setQP ( m_iQP ); |
---|
398 | #endif |
---|
399 | |
---|
400 | m_cTEncTop.setPad ( m_aiPad ); |
---|
401 | m_cTEncTop.setAccessUnitDelimiter ( m_AccessUnitDelimiter ); |
---|
402 | #if NH_MV |
---|
403 | m_cTEncTop.setMaxTempLayer ( m_maxTempLayerMvc[layerIdInVps] ); |
---|
404 | #else |
---|
405 | m_cTEncTop.setMaxTempLayer ( m_maxTempLayer ); |
---|
406 | #endif |
---|
407 | m_cTEncTop.setUseAMP( m_enableAMP ); |
---|
408 | |
---|
409 | //===== Slice ======== |
---|
410 | |
---|
411 | //====== Loop/Deblock Filter ======== |
---|
412 | #if NH_MV |
---|
413 | m_cTEncTop.setLoopFilterDisable ( m_bLoopFilterDisable[layerIdInVps]); |
---|
414 | #else |
---|
415 | m_cTEncTop.setLoopFilterDisable ( m_bLoopFilterDisable ); |
---|
416 | #endif |
---|
417 | m_cTEncTop.setLoopFilterOffsetInPPS ( m_loopFilterOffsetInPPS ); |
---|
418 | m_cTEncTop.setLoopFilterBetaOffset ( m_loopFilterBetaOffsetDiv2 ); |
---|
419 | m_cTEncTop.setLoopFilterTcOffset ( m_loopFilterTcOffsetDiv2 ); |
---|
420 | #if W0038_DB_OPT |
---|
421 | m_cTEncTop.setDeblockingFilterMetric ( m_deblockingFilterMetric ); |
---|
422 | #else |
---|
423 | m_cTEncTop.setDeblockingFilterMetric ( m_DeblockingFilterMetric ); |
---|
424 | #endif |
---|
425 | |
---|
426 | //====== Motion search ======== |
---|
427 | m_cTEncTop.setDisableIntraPUsInInterSlices ( m_bDisableIntraPUsInInterSlices ); |
---|
428 | m_cTEncTop.setMotionEstimationSearchMethod ( m_motionEstimationSearchMethod ); |
---|
429 | m_cTEncTop.setSearchRange ( m_iSearchRange ); |
---|
430 | m_cTEncTop.setBipredSearchRange ( m_bipredSearchRange ); |
---|
431 | m_cTEncTop.setClipForBiPredMeEnabled ( m_bClipForBiPredMeEnabled ); |
---|
432 | m_cTEncTop.setFastMEAssumingSmootherMVEnabled ( m_bFastMEAssumingSmootherMVEnabled ); |
---|
433 | m_cTEncTop.setMinSearchWindow ( m_minSearchWindow ); |
---|
434 | m_cTEncTop.setRestrictMESampling ( m_bRestrictMESampling ); |
---|
435 | |
---|
436 | #if NH_MV |
---|
437 | m_cTEncTop.setUseDisparitySearchRangeRestriction ( m_bUseDisparitySearchRangeRestriction ); |
---|
438 | m_cTEncTop.setVerticalDisparitySearchRange ( m_iVerticalDisparitySearchRange ); |
---|
439 | #endif |
---|
440 | //====== Quality control ======== |
---|
441 | m_cTEncTop.setMaxDeltaQP ( m_iMaxDeltaQP ); |
---|
442 | m_cTEncTop.setMaxCuDQPDepth ( m_iMaxCuDQPDepth ); |
---|
443 | m_cTEncTop.setDiffCuChromaQpOffsetDepth ( m_diffCuChromaQpOffsetDepth ); |
---|
444 | m_cTEncTop.setChromaCbQpOffset ( m_cbQpOffset ); |
---|
445 | m_cTEncTop.setChromaCrQpOffset ( m_crQpOffset ); |
---|
446 | #if W0038_CQP_ADJ |
---|
447 | m_cTEncTop.setSliceChromaOffsetQpIntraOrPeriodic ( m_sliceChromaQpOffsetPeriodicity, m_sliceChromaQpOffsetIntraOrPeriodic ); |
---|
448 | #endif |
---|
449 | |
---|
450 | #if NH_3D |
---|
451 | m_cTEncTop.setChromaFormatIdc ( isDepth ? CHROMA_400 : m_chromaFormatIDC ); |
---|
452 | #else |
---|
453 | m_cTEncTop.setChromaFormatIdc ( m_chromaFormatIDC ); |
---|
454 | #endif |
---|
455 | |
---|
456 | #if ADAPTIVE_QP_SELECTION |
---|
457 | m_cTEncTop.setUseAdaptQpSelect ( m_bUseAdaptQpSelect ); |
---|
458 | #endif |
---|
459 | |
---|
460 | m_cTEncTop.setUseAdaptiveQP ( m_bUseAdaptiveQP ); |
---|
461 | m_cTEncTop.setQPAdaptationRange ( m_iQPAdaptationRange ); |
---|
462 | m_cTEncTop.setExtendedPrecisionProcessingFlag ( m_extendedPrecisionProcessingFlag ); |
---|
463 | m_cTEncTop.setHighPrecisionOffsetsEnabledFlag ( m_highPrecisionOffsetsEnabledFlag ); |
---|
464 | |
---|
465 | m_cTEncTop.setWeightedPredictionMethod( m_weightedPredictionMethod ); |
---|
466 | |
---|
467 | //====== Tool list ======== |
---|
468 | m_cTEncTop.setDeltaQpRD ( m_uiDeltaQpRD ); |
---|
469 | m_cTEncTop.setFastDeltaQp ( m_bFastDeltaQP ); |
---|
470 | m_cTEncTop.setUseASR ( m_bUseASR ); |
---|
471 | m_cTEncTop.setUseHADME ( m_bUseHADME ); |
---|
472 | #if NH_MV |
---|
473 | m_cTEncTop.setdQPs ( m_aidQP[layerIdInVps] ); |
---|
474 | #else |
---|
475 | m_cTEncTop.setdQPs ( m_aidQP ); |
---|
476 | #endif |
---|
477 | m_cTEncTop.setUseRDOQ ( m_useRDOQ ); |
---|
478 | m_cTEncTop.setUseRDOQTS ( m_useRDOQTS ); |
---|
479 | #if T0196_SELECTIVE_RDOQ |
---|
480 | m_cTEncTop.setUseSelectiveRDOQ ( m_useSelectiveRDOQ ); |
---|
481 | #endif |
---|
482 | m_cTEncTop.setRDpenalty ( m_rdPenalty ); |
---|
483 | m_cTEncTop.setMaxCUWidth ( m_uiMaxCUWidth ); |
---|
484 | m_cTEncTop.setMaxCUHeight ( m_uiMaxCUHeight ); |
---|
485 | m_cTEncTop.setMaxTotalCUDepth ( m_uiMaxTotalCUDepth ); |
---|
486 | m_cTEncTop.setLog2DiffMaxMinCodingBlockSize ( m_uiLog2DiffMaxMinCodingBlockSize ); |
---|
487 | m_cTEncTop.setQuadtreeTULog2MaxSize ( m_uiQuadtreeTULog2MaxSize ); |
---|
488 | m_cTEncTop.setQuadtreeTULog2MinSize ( m_uiQuadtreeTULog2MinSize ); |
---|
489 | m_cTEncTop.setQuadtreeTUMaxDepthInter ( m_uiQuadtreeTUMaxDepthInter ); |
---|
490 | m_cTEncTop.setQuadtreeTUMaxDepthIntra ( m_uiQuadtreeTUMaxDepthIntra ); |
---|
491 | m_cTEncTop.setFastInterSearchMode ( m_fastInterSearchMode ); |
---|
492 | m_cTEncTop.setUseEarlyCU ( m_bUseEarlyCU ); |
---|
493 | m_cTEncTop.setUseFastDecisionForMerge ( m_useFastDecisionForMerge ); |
---|
494 | m_cTEncTop.setUseCbfFastMode ( m_bUseCbfFastMode ); |
---|
495 | m_cTEncTop.setUseEarlySkipDetection ( m_useEarlySkipDetection ); |
---|
496 | m_cTEncTop.setCrossComponentPredictionEnabledFlag ( m_crossComponentPredictionEnabledFlag ); |
---|
497 | m_cTEncTop.setUseReconBasedCrossCPredictionEstimate ( m_reconBasedCrossCPredictionEstimate ); |
---|
498 | #if NH_MV |
---|
499 | m_cTEncTop.setLog2SaoOffsetScale ( CHANNEL_TYPE_LUMA , m_log2SaoOffsetScale[layerIdInVps][CHANNEL_TYPE_LUMA] ); |
---|
500 | m_cTEncTop.setLog2SaoOffsetScale ( CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[layerIdInVps][CHANNEL_TYPE_CHROMA] ); |
---|
501 | #else |
---|
502 | m_cTEncTop.setLog2SaoOffsetScale ( CHANNEL_TYPE_LUMA , m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA] ); |
---|
503 | m_cTEncTop.setLog2SaoOffsetScale ( CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA] ); |
---|
504 | #endif |
---|
505 | m_cTEncTop.setUseTransformSkip ( m_useTransformSkip ); |
---|
506 | m_cTEncTop.setUseTransformSkipFast ( m_useTransformSkipFast ); |
---|
507 | m_cTEncTop.setTransformSkipRotationEnabledFlag ( m_transformSkipRotationEnabledFlag ); |
---|
508 | m_cTEncTop.setTransformSkipContextEnabledFlag ( m_transformSkipContextEnabledFlag ); |
---|
509 | m_cTEncTop.setPersistentRiceAdaptationEnabledFlag ( m_persistentRiceAdaptationEnabledFlag ); |
---|
510 | m_cTEncTop.setCabacBypassAlignmentEnabledFlag ( m_cabacBypassAlignmentEnabledFlag ); |
---|
511 | m_cTEncTop.setLog2MaxTransformSkipBlockSize ( m_log2MaxTransformSkipBlockSize ); |
---|
512 | for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++) |
---|
513 | { |
---|
514 | m_cTEncTop.setRdpcmEnabledFlag ( RDPCMSignallingMode(signallingModeIndex), m_rdpcmEnabledFlag[signallingModeIndex]); |
---|
515 | } |
---|
516 | m_cTEncTop.setUseConstrainedIntraPred ( m_bUseConstrainedIntraPred ); |
---|
517 | m_cTEncTop.setFastUDIUseMPMEnabled ( m_bFastUDIUseMPMEnabled ); |
---|
518 | m_cTEncTop.setFastMEForGenBLowDelayEnabled ( m_bFastMEForGenBLowDelayEnabled ); |
---|
519 | m_cTEncTop.setUseBLambdaForNonKeyLowDelayPictures ( m_bUseBLambdaForNonKeyLowDelayPictures ); |
---|
520 | m_cTEncTop.setPCMLog2MinSize ( m_uiPCMLog2MinSize); |
---|
521 | m_cTEncTop.setUsePCM ( m_usePCM ); |
---|
522 | |
---|
523 | // set internal bit-depth and constants |
---|
524 | for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++) |
---|
525 | { |
---|
526 | m_cTEncTop.setBitDepth((ChannelType)channelType, m_internalBitDepth[channelType]); |
---|
527 | m_cTEncTop.setPCMBitDepth((ChannelType)channelType, m_bPCMInputBitDepthFlag ? m_MSBExtendedBitDepth[channelType] : m_internalBitDepth[channelType]); |
---|
528 | } |
---|
529 | |
---|
530 | m_cTEncTop.setPCMLog2MaxSize ( m_pcmLog2MaxSize); |
---|
531 | m_cTEncTop.setMaxNumMergeCand ( m_maxNumMergeCand ); |
---|
532 | |
---|
533 | |
---|
534 | //====== Weighted Prediction ======== |
---|
535 | m_cTEncTop.setUseWP ( m_useWeightedPred ); |
---|
536 | m_cTEncTop.setWPBiPred ( m_useWeightedBiPred ); |
---|
537 | //====== Parallel Merge Estimation ======== |
---|
538 | m_cTEncTop.setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 ); |
---|
539 | |
---|
540 | //====== Slice ======== |
---|
541 | m_cTEncTop.setSliceMode ( m_sliceMode ); |
---|
542 | m_cTEncTop.setSliceArgument ( m_sliceArgument ); |
---|
543 | |
---|
544 | //====== Dependent Slice ======== |
---|
545 | m_cTEncTop.setSliceSegmentMode ( m_sliceSegmentMode ); |
---|
546 | m_cTEncTop.setSliceSegmentArgument ( m_sliceSegmentArgument ); |
---|
547 | |
---|
548 | if(m_sliceMode == NO_SLICES ) |
---|
549 | { |
---|
550 | m_bLFCrossSliceBoundaryFlag = true; |
---|
551 | } |
---|
552 | m_cTEncTop.setLFCrossSliceBoundaryFlag ( m_bLFCrossSliceBoundaryFlag ); |
---|
553 | #if NH_MV |
---|
554 | m_cTEncTop.setUseSAO ( m_bUseSAO[layerIdInVps] ); |
---|
555 | #else |
---|
556 | m_cTEncTop.setUseSAO ( m_bUseSAO ); |
---|
557 | #endif |
---|
558 | m_cTEncTop.setTestSAODisableAtPictureLevel ( m_bTestSAODisableAtPictureLevel ); |
---|
559 | m_cTEncTop.setSaoEncodingRate ( m_saoEncodingRate ); |
---|
560 | m_cTEncTop.setSaoEncodingRateChroma ( m_saoEncodingRateChroma ); |
---|
561 | m_cTEncTop.setMaxNumOffsetsPerPic ( m_maxNumOffsetsPerPic); |
---|
562 | |
---|
563 | m_cTEncTop.setSaoCtuBoundary ( m_saoCtuBoundary); |
---|
564 | #if OPTIONAL_RESET_SAO_ENCODING_AFTER_IRAP |
---|
565 | m_cTEncTop.setSaoResetEncoderStateAfterIRAP ( m_saoResetEncoderStateAfterIRAP); |
---|
566 | #endif |
---|
567 | m_cTEncTop.setPCMInputBitDepthFlag ( m_bPCMInputBitDepthFlag); |
---|
568 | m_cTEncTop.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag); |
---|
569 | |
---|
570 | m_cTEncTop.setIntraSmoothingDisabledFlag (!m_enableIntraReferenceSmoothing ); |
---|
571 | m_cTEncTop.setDecodedPictureHashSEIType ( m_decodedPictureHashSEIType ); |
---|
572 | m_cTEncTop.setRecoveryPointSEIEnabled ( m_recoveryPointSEIEnabled ); |
---|
573 | m_cTEncTop.setBufferingPeriodSEIEnabled ( m_bufferingPeriodSEIEnabled ); |
---|
574 | m_cTEncTop.setPictureTimingSEIEnabled ( m_pictureTimingSEIEnabled ); |
---|
575 | m_cTEncTop.setToneMappingInfoSEIEnabled ( m_toneMappingInfoSEIEnabled ); |
---|
576 | m_cTEncTop.setTMISEIToneMapId ( m_toneMapId ); |
---|
577 | m_cTEncTop.setTMISEIToneMapCancelFlag ( m_toneMapCancelFlag ); |
---|
578 | m_cTEncTop.setTMISEIToneMapPersistenceFlag ( m_toneMapPersistenceFlag ); |
---|
579 | m_cTEncTop.setTMISEICodedDataBitDepth ( m_toneMapCodedDataBitDepth ); |
---|
580 | m_cTEncTop.setTMISEITargetBitDepth ( m_toneMapTargetBitDepth ); |
---|
581 | m_cTEncTop.setTMISEIModelID ( m_toneMapModelId ); |
---|
582 | m_cTEncTop.setTMISEIMinValue ( m_toneMapMinValue ); |
---|
583 | m_cTEncTop.setTMISEIMaxValue ( m_toneMapMaxValue ); |
---|
584 | m_cTEncTop.setTMISEISigmoidMidpoint ( m_sigmoidMidpoint ); |
---|
585 | m_cTEncTop.setTMISEISigmoidWidth ( m_sigmoidWidth ); |
---|
586 | m_cTEncTop.setTMISEIStartOfCodedInterva ( m_startOfCodedInterval ); |
---|
587 | m_cTEncTop.setTMISEINumPivots ( m_numPivots ); |
---|
588 | m_cTEncTop.setTMISEICodedPivotValue ( m_codedPivotValue ); |
---|
589 | m_cTEncTop.setTMISEITargetPivotValue ( m_targetPivotValue ); |
---|
590 | m_cTEncTop.setTMISEICameraIsoSpeedIdc ( m_cameraIsoSpeedIdc ); |
---|
591 | m_cTEncTop.setTMISEICameraIsoSpeedValue ( m_cameraIsoSpeedValue ); |
---|
592 | m_cTEncTop.setTMISEIExposureIndexIdc ( m_exposureIndexIdc ); |
---|
593 | m_cTEncTop.setTMISEIExposureIndexValue ( m_exposureIndexValue ); |
---|
594 | m_cTEncTop.setTMISEIExposureCompensationValueSignFlag ( m_exposureCompensationValueSignFlag ); |
---|
595 | m_cTEncTop.setTMISEIExposureCompensationValueNumerator ( m_exposureCompensationValueNumerator ); |
---|
596 | m_cTEncTop.setTMISEIExposureCompensationValueDenomIdc ( m_exposureCompensationValueDenomIdc ); |
---|
597 | m_cTEncTop.setTMISEIRefScreenLuminanceWhite ( m_refScreenLuminanceWhite ); |
---|
598 | m_cTEncTop.setTMISEIExtendedRangeWhiteLevel ( m_extendedRangeWhiteLevel ); |
---|
599 | m_cTEncTop.setTMISEINominalBlackLevelLumaCodeValue ( m_nominalBlackLevelLumaCodeValue ); |
---|
600 | m_cTEncTop.setTMISEINominalWhiteLevelLumaCodeValue ( m_nominalWhiteLevelLumaCodeValue ); |
---|
601 | m_cTEncTop.setTMISEIExtendedWhiteLevelLumaCodeValue ( m_extendedWhiteLevelLumaCodeValue ); |
---|
602 | m_cTEncTop.setChromaResamplingFilterHintEnabled ( m_chromaResamplingFilterSEIenabled ); |
---|
603 | m_cTEncTop.setChromaResamplingHorFilterIdc ( m_chromaResamplingHorFilterIdc ); |
---|
604 | m_cTEncTop.setChromaResamplingVerFilterIdc ( m_chromaResamplingVerFilterIdc ); |
---|
605 | m_cTEncTop.setFramePackingArrangementSEIEnabled ( m_framePackingSEIEnabled ); |
---|
606 | m_cTEncTop.setFramePackingArrangementSEIType ( m_framePackingSEIType ); |
---|
607 | m_cTEncTop.setFramePackingArrangementSEIId ( m_framePackingSEIId ); |
---|
608 | m_cTEncTop.setFramePackingArrangementSEIQuincunx ( m_framePackingSEIQuincunx ); |
---|
609 | m_cTEncTop.setFramePackingArrangementSEIInterpretation ( m_framePackingSEIInterpretation ); |
---|
610 | m_cTEncTop.setSegmentedRectFramePackingArrangementSEIEnabled ( m_segmentedRectFramePackingSEIEnabled ); |
---|
611 | m_cTEncTop.setSegmentedRectFramePackingArrangementSEICancel ( m_segmentedRectFramePackingSEICancel ); |
---|
612 | m_cTEncTop.setSegmentedRectFramePackingArrangementSEIType ( m_segmentedRectFramePackingSEIType ); |
---|
613 | m_cTEncTop.setSegmentedRectFramePackingArrangementSEIPersistence( m_segmentedRectFramePackingSEIPersistence ); |
---|
614 | m_cTEncTop.setDisplayOrientationSEIAngle ( m_displayOrientationSEIAngle ); |
---|
615 | m_cTEncTop.setTemporalLevel0IndexSEIEnabled ( m_temporalLevel0IndexSEIEnabled ); |
---|
616 | m_cTEncTop.setGradualDecodingRefreshInfoEnabled ( m_gradualDecodingRefreshInfoEnabled ); |
---|
617 | m_cTEncTop.setNoDisplaySEITLayer ( m_noDisplaySEITLayer ); |
---|
618 | m_cTEncTop.setDecodingUnitInfoSEIEnabled ( m_decodingUnitInfoSEIEnabled ); |
---|
619 | m_cTEncTop.setSOPDescriptionSEIEnabled ( m_SOPDescriptionSEIEnabled ); |
---|
620 | m_cTEncTop.setScalableNestingSEIEnabled ( m_scalableNestingSEIEnabled ); |
---|
621 | m_cTEncTop.setTMCTSSEIEnabled ( m_tmctsSEIEnabled ); |
---|
622 | m_cTEncTop.setTimeCodeSEIEnabled ( m_timeCodeSEIEnabled ); |
---|
623 | m_cTEncTop.setNumberOfTimeSets ( m_timeCodeSEINumTs ); |
---|
624 | for(Int i = 0; i < m_timeCodeSEINumTs; i++) |
---|
625 | { |
---|
626 | m_cTEncTop.setTimeSet(m_timeSetArray[i], i); |
---|
627 | } |
---|
628 | m_cTEncTop.setKneeSEIEnabled ( m_kneeSEIEnabled ); |
---|
629 | m_cTEncTop.setKneeSEIId ( m_kneeSEIId ); |
---|
630 | m_cTEncTop.setKneeSEICancelFlag ( m_kneeSEICancelFlag ); |
---|
631 | m_cTEncTop.setKneeSEIPersistenceFlag ( m_kneeSEIPersistenceFlag ); |
---|
632 | m_cTEncTop.setKneeSEIInputDrange ( m_kneeSEIInputDrange ); |
---|
633 | m_cTEncTop.setKneeSEIInputDispLuminance ( m_kneeSEIInputDispLuminance ); |
---|
634 | m_cTEncTop.setKneeSEIOutputDrange ( m_kneeSEIOutputDrange ); |
---|
635 | m_cTEncTop.setKneeSEIOutputDispLuminance ( m_kneeSEIOutputDispLuminance ); |
---|
636 | m_cTEncTop.setKneeSEINumKneePointsMinus1 ( m_kneeSEINumKneePointsMinus1 ); |
---|
637 | m_cTEncTop.setKneeSEIInputKneePoint ( m_kneeSEIInputKneePoint ); |
---|
638 | m_cTEncTop.setKneeSEIOutputKneePoint ( m_kneeSEIOutputKneePoint ); |
---|
639 | m_cTEncTop.setColourRemapInfoSEIFileRoot ( m_colourRemapSEIFileRoot ); |
---|
640 | m_cTEncTop.setMasteringDisplaySEI ( m_masteringDisplay ); |
---|
641 | #if U0033_ALTERNATIVE_TRANSFER_CHARACTERISTICS_SEI |
---|
642 | m_cTEncTop.setSEIAlternativeTransferCharacteristicsSEIEnable ( m_preferredTransferCharacteristics>=0 ); |
---|
643 | m_cTEncTop.setSEIPreferredTransferCharacteristics ( UChar(m_preferredTransferCharacteristics) ); |
---|
644 | #endif |
---|
645 | |
---|
646 | #if NH_MV |
---|
647 | m_cTEncTop.setSeiMessages ( &m_seiMessages ); |
---|
648 | #endif |
---|
649 | |
---|
650 | m_cTEncTop.setTileUniformSpacingFlag ( m_tileUniformSpacingFlag ); |
---|
651 | m_cTEncTop.setNumColumnsMinus1 ( m_numTileColumnsMinus1 ); |
---|
652 | m_cTEncTop.setNumRowsMinus1 ( m_numTileRowsMinus1 ); |
---|
653 | if(!m_tileUniformSpacingFlag) |
---|
654 | { |
---|
655 | m_cTEncTop.setColumnWidth ( m_tileColumnWidth ); |
---|
656 | m_cTEncTop.setRowHeight ( m_tileRowHeight ); |
---|
657 | } |
---|
658 | m_cTEncTop.xCheckGSParameters(); |
---|
659 | Int uiTilesCount = (m_numTileRowsMinus1+1) * (m_numTileColumnsMinus1+1); |
---|
660 | if(uiTilesCount == 1) |
---|
661 | { |
---|
662 | m_bLFCrossTileBoundaryFlag = true; |
---|
663 | } |
---|
664 | m_cTEncTop.setLFCrossTileBoundaryFlag ( m_bLFCrossTileBoundaryFlag ); |
---|
665 | m_cTEncTop.setEntropyCodingSyncEnabledFlag ( m_entropyCodingSyncEnabledFlag ); |
---|
666 | m_cTEncTop.setTMVPModeId ( m_TMVPModeId ); |
---|
667 | m_cTEncTop.setUseScalingListId ( m_useScalingListId ); |
---|
668 | m_cTEncTop.setScalingListFileName ( m_scalingListFileName ); |
---|
669 | m_cTEncTop.setSignHideFlag ( m_signHideFlag); |
---|
670 | #if KWU_RC_VIEWRC_E0227 || KWU_RC_MADPRED_E0227 |
---|
671 | if(!m_cTEncTop.getIsDepth()) //only for texture |
---|
672 | { |
---|
673 | m_cTEncTop.setUseRateCtrl ( m_RCEnableRateControl ); |
---|
674 | } |
---|
675 | else |
---|
676 | { |
---|
677 | m_cTEncTop.setUseRateCtrl ( 0 ); |
---|
678 | } |
---|
679 | #else |
---|
680 | m_cTEncTop.setUseRateCtrl ( m_RCEnableRateControl ); |
---|
681 | #endif |
---|
682 | #if !KWU_RC_VIEWRC_E0227 |
---|
683 | m_cTEncTop.setTargetBitrate ( m_RCTargetBitrate ); |
---|
684 | #endif |
---|
685 | m_cTEncTop.setKeepHierBit ( m_RCKeepHierarchicalBit ); |
---|
686 | m_cTEncTop.setLCULevelRC ( m_RCLCULevelRC ); |
---|
687 | m_cTEncTop.setUseLCUSeparateModel ( m_RCUseLCUSeparateModel ); |
---|
688 | m_cTEncTop.setInitialQP ( m_RCInitialQP ); |
---|
689 | m_cTEncTop.setForceIntraQP ( m_RCForceIntraQP ); |
---|
690 | #if U0132_TARGET_BITS_SATURATION |
---|
691 | m_cTEncTop.setCpbSaturationEnabled ( m_RCCpbSaturationEnabled ); |
---|
692 | m_cTEncTop.setCpbSize ( m_RCCpbSize ); |
---|
693 | m_cTEncTop.setInitialCpbFullness ( m_RCInitialCpbFullness ); |
---|
694 | #endif |
---|
695 | |
---|
696 | #if KWU_RC_MADPRED_E0227 |
---|
697 | if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth()) |
---|
698 | { |
---|
699 | m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_depthMADPred : 0); |
---|
700 | if(m_cTEncTop.getUseDepthMADPred()) |
---|
701 | { |
---|
702 | m_cTEncTop.setCamParam(&m_cCameraData); |
---|
703 | } |
---|
704 | } |
---|
705 | #endif |
---|
706 | #if KWU_RC_VIEWRC_E0227 |
---|
707 | if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth()) |
---|
708 | { |
---|
709 | m_cTEncTop.setUseViewWiseRateCtrl(m_viewWiseRateCtrl); |
---|
710 | if(m_iNumberOfViews == 1) |
---|
711 | { |
---|
712 | if(m_viewWiseRateCtrl) |
---|
713 | { |
---|
714 | m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]); |
---|
715 | } |
---|
716 | else |
---|
717 | { |
---|
718 | m_cTEncTop.setTargetBitrate ( m_RCTargetBitrate ); |
---|
719 | } |
---|
720 | } |
---|
721 | else |
---|
722 | { |
---|
723 | if(m_viewWiseRateCtrl) |
---|
724 | { |
---|
725 | m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]); |
---|
726 | } |
---|
727 | else |
---|
728 | { |
---|
729 | if(m_iNumberOfViews == 2) |
---|
730 | { |
---|
731 | if(m_cTEncTop.getViewId() == 0) |
---|
732 | { |
---|
733 | m_cTEncTop.setTargetBitrate ( (m_RCTargetBitrate*80)/100 ); |
---|
734 | } |
---|
735 | else if(m_cTEncTop.getViewId() == 1) |
---|
736 | { |
---|
737 | m_cTEncTop.setTargetBitrate ( (m_RCTargetBitrate*20)/100 ); |
---|
738 | } |
---|
739 | } |
---|
740 | else if(m_iNumberOfViews == 3) |
---|
741 | { |
---|
742 | if(m_cTEncTop.getViewId() == 0) |
---|
743 | { |
---|
744 | m_cTEncTop.setTargetBitrate ( (m_RCTargetBitrate*66)/100 ); |
---|
745 | } |
---|
746 | else if(m_cTEncTop.getViewId() == 1) |
---|
747 | { |
---|
748 | m_cTEncTop.setTargetBitrate ( (m_RCTargetBitrate*17)/100 ); |
---|
749 | } |
---|
750 | else if(m_cTEncTop.getViewId() == 2) |
---|
751 | { |
---|
752 | m_cTEncTop.setTargetBitrate ( (m_RCTargetBitrate*17)/100 ); |
---|
753 | } |
---|
754 | } |
---|
755 | else |
---|
756 | { |
---|
757 | m_cTEncTop.setTargetBitrate ( m_RCTargetBitrate ); |
---|
758 | } |
---|
759 | } |
---|
760 | } |
---|
761 | } |
---|
762 | #endif |
---|
763 | m_cTEncTop.setTransquantBypassEnableFlag ( m_TransquantBypassEnableFlag ); |
---|
764 | m_cTEncTop.setCUTransquantBypassFlagForceValue ( m_CUTransquantBypassFlagForce ); |
---|
765 | m_cTEncTop.setCostMode ( m_costMode ); |
---|
766 | m_cTEncTop.setUseRecalculateQPAccordingToLambda ( m_recalculateQPAccordingToLambda ); |
---|
767 | m_cTEncTop.setUseStrongIntraSmoothing ( m_useStrongIntraSmoothing ); |
---|
768 | m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); |
---|
769 | m_cTEncTop.setVuiParametersPresentFlag ( m_vuiParametersPresentFlag ); |
---|
770 | m_cTEncTop.setAspectRatioInfoPresentFlag ( m_aspectRatioInfoPresentFlag); |
---|
771 | m_cTEncTop.setAspectRatioIdc ( m_aspectRatioIdc ); |
---|
772 | m_cTEncTop.setSarWidth ( m_sarWidth ); |
---|
773 | m_cTEncTop.setSarHeight ( m_sarHeight ); |
---|
774 | m_cTEncTop.setOverscanInfoPresentFlag ( m_overscanInfoPresentFlag ); |
---|
775 | m_cTEncTop.setOverscanAppropriateFlag ( m_overscanAppropriateFlag ); |
---|
776 | m_cTEncTop.setVideoSignalTypePresentFlag ( m_videoSignalTypePresentFlag ); |
---|
777 | m_cTEncTop.setVideoFormat ( m_videoFormat ); |
---|
778 | m_cTEncTop.setVideoFullRangeFlag ( m_videoFullRangeFlag ); |
---|
779 | m_cTEncTop.setColourDescriptionPresentFlag ( m_colourDescriptionPresentFlag ); |
---|
780 | m_cTEncTop.setColourPrimaries ( m_colourPrimaries ); |
---|
781 | m_cTEncTop.setTransferCharacteristics ( m_transferCharacteristics ); |
---|
782 | m_cTEncTop.setMatrixCoefficients ( m_matrixCoefficients ); |
---|
783 | m_cTEncTop.setChromaLocInfoPresentFlag ( m_chromaLocInfoPresentFlag ); |
---|
784 | m_cTEncTop.setChromaSampleLocTypeTopField ( m_chromaSampleLocTypeTopField ); |
---|
785 | m_cTEncTop.setChromaSampleLocTypeBottomField ( m_chromaSampleLocTypeBottomField ); |
---|
786 | m_cTEncTop.setNeutralChromaIndicationFlag ( m_neutralChromaIndicationFlag ); |
---|
787 | m_cTEncTop.setDefaultDisplayWindow ( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset ); |
---|
788 | m_cTEncTop.setFrameFieldInfoPresentFlag ( m_frameFieldInfoPresentFlag ); |
---|
789 | m_cTEncTop.setPocProportionalToTimingFlag ( m_pocProportionalToTimingFlag ); |
---|
790 | m_cTEncTop.setNumTicksPocDiffOneMinus1 ( m_numTicksPocDiffOneMinus1 ); |
---|
791 | m_cTEncTop.setBitstreamRestrictionFlag ( m_bitstreamRestrictionFlag ); |
---|
792 | m_cTEncTop.setTilesFixedStructureFlag ( m_tilesFixedStructureFlag ); |
---|
793 | m_cTEncTop.setMotionVectorsOverPicBoundariesFlag ( m_motionVectorsOverPicBoundariesFlag ); |
---|
794 | m_cTEncTop.setMinSpatialSegmentationIdc ( m_minSpatialSegmentationIdc ); |
---|
795 | m_cTEncTop.setMaxBytesPerPicDenom ( m_maxBytesPerPicDenom ); |
---|
796 | m_cTEncTop.setMaxBitsPerMinCuDenom ( m_maxBitsPerMinCuDenom ); |
---|
797 | m_cTEncTop.setLog2MaxMvLengthHorizontal ( m_log2MaxMvLengthHorizontal ); |
---|
798 | m_cTEncTop.setLog2MaxMvLengthVertical ( m_log2MaxMvLengthVertical ); |
---|
799 | m_cTEncTop.setEfficientFieldIRAPEnabled ( m_bEfficientFieldIRAPEnabled ); |
---|
800 | m_cTEncTop.setHarmonizeGopFirstFieldCoupleEnabled ( m_bHarmonizeGopFirstFieldCoupleEnabled ); |
---|
801 | |
---|
802 | m_cTEncTop.setSummaryOutFilename ( m_summaryOutFilename ); |
---|
803 | m_cTEncTop.setSummaryPicFilenameBase ( m_summaryPicFilenameBase ); |
---|
804 | m_cTEncTop.setSummaryVerboseness ( m_summaryVerboseness ); |
---|
805 | |
---|
806 | #if NH_MV |
---|
807 | } |
---|
808 | #endif |
---|
809 | #if NH_3D_VSO |
---|
810 | if ( m_bUseVSO ) |
---|
811 | { |
---|
812 | if ( m_uiVSOMode == 4 ) |
---|
813 | { |
---|
814 | #if H_3D_VSO_EARLY_SKIP |
---|
815 | m_cRendererModel.create( m_cRenModStrParser.getNumOfBaseViews(), m_cRenModStrParser.getNumOfModels(), m_iSourceWidth, m_uiMaxCUHeight , LOG2_DISP_PREC_LUT, 0, true, m_bVSOEarlySkip ); |
---|
816 | #else |
---|
817 | m_cRendererModel.create( m_cRenModStrParser.getNumOfBaseViews(), m_cRenModStrParser.getNumOfModels(), m_iSourceWidth, m_uiMaxCUHeight , LOG2_DISP_PREC_LUT, 0 , true); |
---|
818 | #endif |
---|
819 | for ( Int layer = 0; layer < m_numberOfLayers ; layer++ ) |
---|
820 | { |
---|
821 | TEncTop* pcEncTop = m_acTEncTopList[ layer ]; |
---|
822 | Int iViewNum = pcEncTop->getViewIndex(); |
---|
823 | Int iContent = pcEncTop->getIsDepth() || pcEncTop->getIsAuxDepth() ? 1 : 0; |
---|
824 | Int iNumOfModels = m_cRenModStrParser.getNumOfModelsForView(iViewNum, iContent); |
---|
825 | |
---|
826 | Bool bUseVSO = (iNumOfModels != 0); |
---|
827 | |
---|
828 | pcEncTop->setUseVSO( bUseVSO ); |
---|
829 | pcEncTop->getRdCost()->setRenModel( bUseVSO ? &m_cRendererModel : NULL ); |
---|
830 | |
---|
831 | for (Int iCurModel = 0; iCurModel < iNumOfModels; iCurModel++ ) |
---|
832 | { |
---|
833 | Int iModelNum; Int iLeftViewNum; Int iRightViewNum; Int iDump; Int iOrgRefNum; Int iBlendMode; |
---|
834 | |
---|
835 | m_cRenModStrParser.getSingleModelData ( iViewNum, iContent, iCurModel, iModelNum, iBlendMode, iLeftViewNum, iRightViewNum, iOrgRefNum, iDump ) ; |
---|
836 | m_cRendererModel .createSingleModel ( iViewNum, iContent, iModelNum, iLeftViewNum, iRightViewNum, (iOrgRefNum != -1), iBlendMode ); |
---|
837 | } |
---|
838 | } |
---|
839 | } |
---|
840 | else |
---|
841 | { |
---|
842 | AOT(true); |
---|
843 | } |
---|
844 | } |
---|
845 | #endif |
---|
846 | } |
---|
847 | |
---|
848 | Void TAppEncTop::xCreateLib() |
---|
849 | { |
---|
850 | #if NH_MV |
---|
851 | // initialize global variables |
---|
852 | initROM(); |
---|
853 | #if NH_3D_DMM |
---|
854 | initWedgeLists( true ); |
---|
855 | #endif |
---|
856 | |
---|
857 | for( Int layer=0; layer < m_numberOfLayers; layer++) |
---|
858 | { |
---|
859 | m_acTVideoIOYuvInputFileList[layer]->open( m_pchInputFileList[layer], false, m_inputBitDepth, m_MSBExtendedBitDepth, m_internalBitDepth ); // read mode |
---|
860 | m_acTVideoIOYuvInputFileList[layer]->skipFrames( m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1], m_InputChromaFormatIDC); |
---|
861 | |
---|
862 | if (m_pchReconFileList[layer]) |
---|
863 | { |
---|
864 | m_acTVideoIOYuvReconFileList[layer]->open( m_pchReconFileList[layer], true, m_outputBitDepth, m_outputBitDepth, m_internalBitDepth); // write mode |
---|
865 | } |
---|
866 | m_acTEncTopList[layer]->create(); |
---|
867 | } |
---|
868 | #else |
---|
869 | // Video I/O |
---|
870 | m_cTVideoIOYuvInputFile.open( m_inputFileName, false, m_inputBitDepth, m_MSBExtendedBitDepth, m_internalBitDepth ); // read mode |
---|
871 | m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1], m_InputChromaFormatIDC); |
---|
872 | |
---|
873 | if (!m_reconFileName.empty()) |
---|
874 | { |
---|
875 | m_cTVideoIOYuvReconFile.open(m_reconFileName, true, m_outputBitDepth, m_outputBitDepth, m_internalBitDepth); // write mode |
---|
876 | } |
---|
877 | |
---|
878 | // Neo Decoder |
---|
879 | m_cTEncTop.create(); |
---|
880 | #endif |
---|
881 | } |
---|
882 | |
---|
883 | Void TAppEncTop::xDestroyLib() |
---|
884 | { |
---|
885 | #if NH_MV |
---|
886 | // destroy ROM |
---|
887 | destroyROM(); |
---|
888 | |
---|
889 | for(Int layer=0; layer<m_numberOfLayers; layer++) |
---|
890 | { |
---|
891 | m_acTVideoIOYuvInputFileList[layer]->close(); |
---|
892 | m_acTVideoIOYuvReconFileList[layer]->close(); |
---|
893 | delete m_acTVideoIOYuvInputFileList[layer] ; |
---|
894 | m_acTVideoIOYuvInputFileList[layer] = NULL; |
---|
895 | delete m_acTVideoIOYuvReconFileList[layer] ; |
---|
896 | m_acTVideoIOYuvReconFileList[layer] = NULL; |
---|
897 | m_acTEncTopList[layer]->deletePicBuffer(); |
---|
898 | m_acTEncTopList[layer]->destroy(); |
---|
899 | delete m_acTEncTopList[layer] ; |
---|
900 | m_acTEncTopList[layer] = NULL; |
---|
901 | delete m_cListPicYuvRec[layer] ; |
---|
902 | m_cListPicYuvRec[layer] = NULL; |
---|
903 | } |
---|
904 | #else |
---|
905 | // Video I/O |
---|
906 | m_cTVideoIOYuvInputFile.close(); |
---|
907 | m_cTVideoIOYuvReconFile.close(); |
---|
908 | |
---|
909 | // Neo Decoder |
---|
910 | m_cTEncTop.destroy(); |
---|
911 | #endif |
---|
912 | } |
---|
913 | |
---|
914 | Void TAppEncTop::xInitLib(Bool isFieldCoding) |
---|
915 | { |
---|
916 | #if NH_MV |
---|
917 | for(Int layer=0; layer<m_numberOfLayers; layer++) |
---|
918 | { |
---|
919 | #if KWU_RC_MADPRED_E0227 |
---|
920 | m_acTEncTopList[layer]->init( isFieldCoding, this ); |
---|
921 | #else |
---|
922 | m_acTEncTopList[layer]->init( isFieldCoding ); |
---|
923 | #endif |
---|
924 | } |
---|
925 | #else |
---|
926 | m_cTEncTop.init(isFieldCoding); |
---|
927 | #endif |
---|
928 | } |
---|
929 | |
---|
930 | // ==================================================================================================================== |
---|
931 | // Public member functions |
---|
932 | // ==================================================================================================================== |
---|
933 | |
---|
934 | /** |
---|
935 | - create internal class |
---|
936 | - initialize internal variable |
---|
937 | - until the end of input YUV file, call encoding function in TEncTop class |
---|
938 | - delete allocated buffers |
---|
939 | - destroy internal class |
---|
940 | . |
---|
941 | */ |
---|
942 | Void TAppEncTop::encode() |
---|
943 | { |
---|
944 | fstream bitstreamFile(m_bitstreamFileName.c_str(), fstream::binary | fstream::out); |
---|
945 | if (!bitstreamFile) |
---|
946 | { |
---|
947 | fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_bitstreamFileName.c_str()); |
---|
948 | exit(EXIT_FAILURE); |
---|
949 | } |
---|
950 | |
---|
951 | #if !NH_3D |
---|
952 | TComPicYuv* pcPicYuvOrg = new TComPicYuv; |
---|
953 | #endif |
---|
954 | TComPicYuv* pcPicYuvRec = NULL; |
---|
955 | |
---|
956 | // initialize internal class & member variables |
---|
957 | xInitLibCfg(); |
---|
958 | xCreateLib(); |
---|
959 | xInitLib(m_isField); |
---|
960 | |
---|
961 | printChromaFormat(); |
---|
962 | |
---|
963 | // main encoder loop |
---|
964 | #if NH_MV |
---|
965 | Bool allEos = false; |
---|
966 | std::vector<Bool> eos ; |
---|
967 | std::vector<Bool> flush ; |
---|
968 | |
---|
969 | Int gopSize = 1; |
---|
970 | Int maxGopSize = 0; |
---|
971 | maxGopSize = (std::max)(maxGopSize, m_acTEncTopList[0]->getGOPSize()); |
---|
972 | |
---|
973 | for(Int layer=0; layer < m_numberOfLayers; layer++ ) |
---|
974 | { |
---|
975 | eos .push_back( false ); |
---|
976 | flush.push_back( false ); |
---|
977 | } |
---|
978 | #else |
---|
979 | Int iNumEncoded = 0; |
---|
980 | Bool bEos = false; |
---|
981 | #endif |
---|
982 | const InputColourSpaceConversion ipCSC = m_inputColourSpaceConvert; |
---|
983 | const InputColourSpaceConversion snrCSC = (!m_snrInternalColourSpace) ? m_inputColourSpaceConvert : IPCOLOURSPACE_UNCHANGED; |
---|
984 | |
---|
985 | list<AccessUnit> outputAccessUnits; ///< list of access units to write out. is populated by the encoding process |
---|
986 | |
---|
987 | #if NH_3D |
---|
988 | TComPicYuv* picYuvOrg[2]; |
---|
989 | TComPicYuv picYuvTrueOrg[2]; |
---|
990 | for (Int d = 0; d < 2 ; d++) |
---|
991 | { |
---|
992 | picYuvOrg[d] = new TComPicYuv; |
---|
993 | picYuvOrg[d] ->create( m_iSourceWidth, m_isField ? m_iSourceHeightOrg : m_iSourceHeight, ( d > 0 ) ? CHROMA_400 : m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
---|
994 | picYuvTrueOrg[d].create( m_iSourceWidth, m_isField ? m_iSourceHeightOrg : m_iSourceHeight, ( d > 0 ) ? CHROMA_400 : m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
---|
995 | } |
---|
996 | #else |
---|
997 | TComPicYuv cPicYuvTrueOrg; |
---|
998 | |
---|
999 | // allocate original YUV buffer |
---|
1000 | if( m_isField ) |
---|
1001 | { |
---|
1002 | pcPicYuvOrg->create ( m_iSourceWidth, m_iSourceHeightOrg, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
---|
1003 | cPicYuvTrueOrg.create(m_iSourceWidth, m_iSourceHeightOrg, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true); |
---|
1004 | } |
---|
1005 | else |
---|
1006 | { |
---|
1007 | pcPicYuvOrg->create ( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
---|
1008 | cPicYuvTrueOrg.create(m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
---|
1009 | } |
---|
1010 | #endif |
---|
1011 | #if NH_MV |
---|
1012 | while ( (m_targetEncLayerIdList.size() != 0 ) && !allEos ) |
---|
1013 | { |
---|
1014 | for(Int layer=0; layer < m_numberOfLayers; layer++ ) |
---|
1015 | { |
---|
1016 | #if NH_3D |
---|
1017 | TComPicYuv* pcPicYuvOrg = picYuvOrg [ m_depthFlag[layer] ]; |
---|
1018 | TComPicYuv& cPicYuvTrueOrg = picYuvTrueOrg[ m_depthFlag[layer] ]; |
---|
1019 | #endif |
---|
1020 | if (!xLayerIdInTargetEncLayerIdList( m_vps->getLayerIdInNuh( layer ) )) |
---|
1021 | { |
---|
1022 | continue; |
---|
1023 | } |
---|
1024 | |
---|
1025 | Int frmCnt = 0; |
---|
1026 | while ( !eos[layer] && !(frmCnt == gopSize)) |
---|
1027 | { |
---|
1028 | // get buffers |
---|
1029 | xGetBuffer(pcPicYuvRec, layer); |
---|
1030 | |
---|
1031 | // read input YUV file |
---|
1032 | m_acTVideoIOYuvInputFileList[layer]->read ( pcPicYuvOrg, &cPicYuvTrueOrg, ipCSC, m_aiPad, m_InputChromaFormatIDC ); |
---|
1033 | m_acTEncTopList [layer]->initNewPic( pcPicYuvOrg ); |
---|
1034 | |
---|
1035 | // increase number of received frames |
---|
1036 | m_frameRcvd[layer]++; |
---|
1037 | |
---|
1038 | frmCnt++; |
---|
1039 | |
---|
1040 | eos[layer] = (m_frameRcvd[layer] == m_framesToBeEncoded); |
---|
1041 | allEos = allEos||eos[layer]; |
---|
1042 | |
---|
1043 | // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures |
---|
1044 | if (m_acTVideoIOYuvInputFileList[layer]->isEof()) |
---|
1045 | { |
---|
1046 | flush [layer] = true; |
---|
1047 | eos [layer] = true; |
---|
1048 | m_frameRcvd [layer]--; |
---|
1049 | m_acTEncTopList[layer]->setFramesToBeEncoded(m_frameRcvd[layer]); |
---|
1050 | } |
---|
1051 | } |
---|
1052 | } |
---|
1053 | for ( Int gopId=0; gopId < gopSize; gopId++ ) |
---|
1054 | { |
---|
1055 | #if NH_3D_VSO || NH_3D |
---|
1056 | UInt iNextPoc = m_acTEncTopList[0] -> getFrameId( gopId ); |
---|
1057 | if ( iNextPoc < m_framesToBeEncoded ) |
---|
1058 | { |
---|
1059 | m_cCameraData.update( iNextPoc ); |
---|
1060 | } |
---|
1061 | #endif |
---|
1062 | for(Int layer=0; layer < m_numberOfLayers; layer++ ) |
---|
1063 | { |
---|
1064 | #if NH_3D |
---|
1065 | TComPicYuv* pcPicYuvOrg = picYuvOrg [ m_depthFlag[layer] ]; |
---|
1066 | TComPicYuv& cPicYuvTrueOrg = picYuvTrueOrg[ m_depthFlag[layer] ]; |
---|
1067 | #endif |
---|
1068 | if (!xLayerIdInTargetEncLayerIdList( m_vps->getLayerIdInNuh( layer ) )) |
---|
1069 | { |
---|
1070 | continue; |
---|
1071 | } |
---|
1072 | |
---|
1073 | #if NH_3D_VSO |
---|
1074 | if( m_bUseVSO && m_bUseEstimatedVSD && iNextPoc < m_framesToBeEncoded ) |
---|
1075 | { |
---|
1076 | m_cCameraData.setDispCoeff( iNextPoc, m_acTEncTopList[layer]->getViewIndex() ); |
---|
1077 | m_acTEncTopList[layer] ->setDispCoeff( m_cCameraData.getDispCoeff() ); |
---|
1078 | } |
---|
1079 | #endif |
---|
1080 | |
---|
1081 | Int iNumEncoded = 0; |
---|
1082 | |
---|
1083 | // call encoding function for one frame |
---|
1084 | m_acTEncTopList[layer]->encode( eos[layer], flush[layer] ? 0 : pcPicYuvOrg, flush[layer] ? 0 : &cPicYuvTrueOrg, snrCSC, *m_cListPicYuvRec[layer], outputAccessUnits, iNumEncoded, gopId ); |
---|
1085 | xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits, layer); |
---|
1086 | outputAccessUnits.clear(); |
---|
1087 | } |
---|
1088 | } |
---|
1089 | |
---|
1090 | gopSize = maxGopSize; |
---|
1091 | } |
---|
1092 | for(Int layer=0; layer < m_numberOfLayers; layer++ ) |
---|
1093 | { |
---|
1094 | if (!xLayerIdInTargetEncLayerIdList( m_vps->getLayerIdInNuh( layer ) )) |
---|
1095 | { |
---|
1096 | continue; |
---|
1097 | } |
---|
1098 | m_acTEncTopList[layer]->printSummary(m_isField); |
---|
1099 | } |
---|
1100 | #else |
---|
1101 | |
---|
1102 | while ( !bEos ) |
---|
1103 | { |
---|
1104 | // get buffers |
---|
1105 | xGetBuffer(pcPicYuvRec); |
---|
1106 | |
---|
1107 | // read input YUV file |
---|
1108 | m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, &cPicYuvTrueOrg, ipCSC, m_aiPad, m_InputChromaFormatIDC, m_bClipInputVideoToRec709Range ); |
---|
1109 | |
---|
1110 | // increase number of received frames |
---|
1111 | m_iFrameRcvd++; |
---|
1112 | |
---|
1113 | bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) ); |
---|
1114 | |
---|
1115 | Bool flush = 0; |
---|
1116 | // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures |
---|
1117 | if (m_cTVideoIOYuvInputFile.isEof()) |
---|
1118 | { |
---|
1119 | flush = true; |
---|
1120 | bEos = true; |
---|
1121 | m_iFrameRcvd--; |
---|
1122 | m_cTEncTop.setFramesToBeEncoded(m_iFrameRcvd); |
---|
1123 | } |
---|
1124 | |
---|
1125 | // call encoding function for one frame |
---|
1126 | if ( m_isField ) |
---|
1127 | { |
---|
1128 | m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, flush ? 0 : &cPicYuvTrueOrg, snrCSC, m_cListPicYuvRec, outputAccessUnits, iNumEncoded, m_isTopFieldFirst ); |
---|
1129 | } |
---|
1130 | else |
---|
1131 | { |
---|
1132 | m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, flush ? 0 : &cPicYuvTrueOrg, snrCSC, m_cListPicYuvRec, outputAccessUnits, iNumEncoded ); |
---|
1133 | } |
---|
1134 | |
---|
1135 | // write bistream to file if necessary |
---|
1136 | if ( iNumEncoded > 0 ) |
---|
1137 | { |
---|
1138 | xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits); |
---|
1139 | outputAccessUnits.clear(); |
---|
1140 | } |
---|
1141 | // temporally skip frames |
---|
1142 | if( m_temporalSubsampleRatio > 1 ) |
---|
1143 | { |
---|
1144 | m_cTVideoIOYuvInputFile.skipFrames(m_temporalSubsampleRatio-1, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1], m_InputChromaFormatIDC); |
---|
1145 | } |
---|
1146 | } |
---|
1147 | |
---|
1148 | m_cTEncTop.printSummary(m_isField); |
---|
1149 | #endif |
---|
1150 | |
---|
1151 | #if NH_3D |
---|
1152 | // delete original YUV buffer |
---|
1153 | for (Int d = 0; d < 2; d++) |
---|
1154 | { |
---|
1155 | picYuvOrg[d]->destroy(); |
---|
1156 | delete picYuvOrg[d]; |
---|
1157 | picYuvOrg[d] = NULL; |
---|
1158 | |
---|
1159 | picYuvTrueOrg[d].destroy(); |
---|
1160 | } |
---|
1161 | #else |
---|
1162 | // delete original YUV buffer |
---|
1163 | pcPicYuvOrg->destroy(); |
---|
1164 | delete pcPicYuvOrg; |
---|
1165 | pcPicYuvOrg = NULL; |
---|
1166 | #endif |
---|
1167 | |
---|
1168 | #if !NH_MV |
---|
1169 | // delete used buffers in encoder class |
---|
1170 | m_cTEncTop.deletePicBuffer(); |
---|
1171 | #endif |
---|
1172 | #if !NH_3D |
---|
1173 | cPicYuvTrueOrg.destroy(); |
---|
1174 | #endif |
---|
1175 | |
---|
1176 | // delete buffers & classes |
---|
1177 | xDeleteBuffer(); |
---|
1178 | xDestroyLib(); |
---|
1179 | |
---|
1180 | printRateSummary(); |
---|
1181 | |
---|
1182 | #if NH_3D_REN_MAX_DEV_OUT |
---|
1183 | Double dMaxDispDiff = m_cCameraData.getMaxShiftDeviation(); |
---|
1184 | |
---|
1185 | if ( !(dMaxDispDiff < 0) ) |
---|
1186 | { |
---|
1187 | printf("\n Max. possible shift error: %12.3f samples.\n", dMaxDispDiff ); |
---|
1188 | } |
---|
1189 | #endif |
---|
1190 | |
---|
1191 | return; |
---|
1192 | } |
---|
1193 | |
---|
1194 | // ==================================================================================================================== |
---|
1195 | // Protected member functions |
---|
1196 | // ==================================================================================================================== |
---|
1197 | |
---|
1198 | /** |
---|
1199 | - application has picture buffer list with size of GOP |
---|
1200 | - picture buffer list acts as ring buffer |
---|
1201 | - end of the list has the latest picture |
---|
1202 | . |
---|
1203 | */ |
---|
1204 | #if NH_MV |
---|
1205 | Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer) |
---|
1206 | #else |
---|
1207 | Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec) |
---|
1208 | #endif |
---|
1209 | { |
---|
1210 | assert( m_iGOPSize > 0 ); |
---|
1211 | |
---|
1212 | // org. buffer |
---|
1213 | #if NH_MV |
---|
1214 | if ( m_cListPicYuvRec[layer]->size() == (UInt)m_iGOPSize ) |
---|
1215 | { |
---|
1216 | rpcPicYuvRec = m_cListPicYuvRec[layer]->popFront(); |
---|
1217 | #else |
---|
1218 | if ( m_cListPicYuvRec.size() >= (UInt)m_iGOPSize ) // buffer will be 1 element longer when using field coding, to maintain first field whilst processing second. |
---|
1219 | { |
---|
1220 | rpcPicYuvRec = m_cListPicYuvRec.popFront(); |
---|
1221 | #endif |
---|
1222 | } |
---|
1223 | else |
---|
1224 | { |
---|
1225 | rpcPicYuvRec = new TComPicYuv; |
---|
1226 | #if NH_3D |
---|
1227 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_depthFlag[layer] > 0 ? CHROMA_400 : m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
---|
1228 | #else |
---|
1229 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
---|
1230 | #endif |
---|
1231 | |
---|
1232 | } |
---|
1233 | #if NH_MV |
---|
1234 | m_cListPicYuvRec[layer]->pushBack( rpcPicYuvRec ); |
---|
1235 | #else |
---|
1236 | m_cListPicYuvRec.pushBack( rpcPicYuvRec ); |
---|
1237 | #endif |
---|
1238 | } |
---|
1239 | |
---|
1240 | Void TAppEncTop::xDeleteBuffer( ) |
---|
1241 | { |
---|
1242 | #if NH_MV |
---|
1243 | for(Int layer=0; layer<m_cListPicYuvRec.size(); layer++) |
---|
1244 | { |
---|
1245 | if(m_cListPicYuvRec[layer]) |
---|
1246 | { |
---|
1247 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec[layer]->begin(); |
---|
1248 | Int iSize = Int( m_cListPicYuvRec[layer]->size() ); |
---|
1249 | #else |
---|
1250 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.begin(); |
---|
1251 | |
---|
1252 | Int iSize = Int( m_cListPicYuvRec.size() ); |
---|
1253 | #endif |
---|
1254 | |
---|
1255 | for ( Int i = 0; i < iSize; i++ ) |
---|
1256 | { |
---|
1257 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
---|
1258 | pcPicYuvRec->destroy(); |
---|
1259 | delete pcPicYuvRec; pcPicYuvRec = NULL; |
---|
1260 | } |
---|
1261 | #if NH_MV |
---|
1262 | } |
---|
1263 | } |
---|
1264 | #endif |
---|
1265 | |
---|
1266 | } |
---|
1267 | |
---|
1268 | /** |
---|
1269 | Write access units to output file. |
---|
1270 | \param bitstreamFile target bitstream file |
---|
1271 | \param iNumEncoded number of encoded frames |
---|
1272 | \param accessUnits list of access units to be written |
---|
1273 | */ |
---|
1274 | #if NH_MV |
---|
1275 | Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, std::list<AccessUnit>& accessUnits, UInt layerIdx) |
---|
1276 | #else |
---|
1277 | Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits) |
---|
1278 | #endif |
---|
1279 | { |
---|
1280 | const InputColourSpaceConversion ipCSC = (!m_outputInternalColourSpace) ? m_inputColourSpaceConvert : IPCOLOURSPACE_UNCHANGED; |
---|
1281 | |
---|
1282 | if (m_isField) |
---|
1283 | { |
---|
1284 | //Reinterlace fields |
---|
1285 | Int i; |
---|
1286 | #if NH_MV |
---|
1287 | if( iNumEncoded > 0 ) |
---|
1288 | { |
---|
1289 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec[layerIdx]->end(); |
---|
1290 | #else |
---|
1291 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end(); |
---|
1292 | list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin(); |
---|
1293 | #endif |
---|
1294 | |
---|
1295 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
1296 | { |
---|
1297 | --iterPicYuvRec; |
---|
1298 | } |
---|
1299 | |
---|
1300 | for ( i = 0; i < iNumEncoded/2; i++ ) |
---|
1301 | { |
---|
1302 | TComPicYuv* pcPicYuvRecTop = *(iterPicYuvRec++); |
---|
1303 | TComPicYuv* pcPicYuvRecBottom = *(iterPicYuvRec++); |
---|
1304 | |
---|
1305 | #if NH_MV |
---|
1306 | if (m_pchReconFileList[layerIdx]) |
---|
1307 | { |
---|
1308 | #if NH_3D |
---|
1309 | m_acTVideoIOYuvReconFileList[layerIdx]->write( pcPicYuvRecTop, pcPicYuvRecBottom, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, m_depth420OutputFlag && m_depthFlag[layerIdx ] ? CHROMA_420 : NUM_CHROMA_FORMAT, m_isTopFieldFirst ); |
---|
1310 | #else |
---|
1311 | m_acTVideoIOYuvReconFileList[layerIdx]->write( pcPicYuvRecTop, pcPicYuvRecBottom, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, NUM_CHROMA_FORMAT, m_isTopFieldFirst ); |
---|
1312 | #endif |
---|
1313 | } |
---|
1314 | } |
---|
1315 | } |
---|
1316 | |
---|
1317 | if( ! accessUnits.empty() ) |
---|
1318 | { |
---|
1319 | list<AccessUnit>::iterator aUIter; |
---|
1320 | for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ ) |
---|
1321 | { |
---|
1322 | const vector<UInt>& stats = writeAnnexB(bitstreamFile, *aUIter); |
---|
1323 | rateStatsAccum(*aUIter, stats); |
---|
1324 | } |
---|
1325 | } |
---|
1326 | #else |
---|
1327 | if (!m_reconFileName.empty()) |
---|
1328 | { |
---|
1329 | m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, NUM_CHROMA_FORMAT, m_isTopFieldFirst ); |
---|
1330 | } |
---|
1331 | |
---|
1332 | const AccessUnit& auTop = *(iterBitstream++); |
---|
1333 | const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop); |
---|
1334 | rateStatsAccum(auTop, statsTop); |
---|
1335 | |
---|
1336 | const AccessUnit& auBottom = *(iterBitstream++); |
---|
1337 | const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom); |
---|
1338 | rateStatsAccum(auBottom, statsBottom); |
---|
1339 | } |
---|
1340 | #endif |
---|
1341 | } |
---|
1342 | else |
---|
1343 | { |
---|
1344 | Int i; |
---|
1345 | #if NH_MV |
---|
1346 | if( iNumEncoded > 0 ) |
---|
1347 | { |
---|
1348 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec[layerIdx]->end(); |
---|
1349 | #else |
---|
1350 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end(); |
---|
1351 | list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin(); |
---|
1352 | #endif |
---|
1353 | |
---|
1354 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
1355 | { |
---|
1356 | --iterPicYuvRec; |
---|
1357 | } |
---|
1358 | |
---|
1359 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
1360 | { |
---|
1361 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
---|
1362 | #if NH_MV |
---|
1363 | if (m_pchReconFileList[layerIdx]) |
---|
1364 | { |
---|
1365 | #if NH_3D |
---|
1366 | m_acTVideoIOYuvReconFileList[layerIdx]->write( pcPicYuvRec, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, m_depth420OutputFlag && m_depthFlag[layerIdx ] ? CHROMA_420 : NUM_CHROMA_FORMAT ); |
---|
1367 | #else |
---|
1368 | m_acTVideoIOYuvReconFileList[layerIdx]->write( pcPicYuvRec, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom ); |
---|
1369 | #endif |
---|
1370 | |
---|
1371 | } |
---|
1372 | } |
---|
1373 | } |
---|
1374 | if( ! accessUnits.empty() ) |
---|
1375 | { |
---|
1376 | list<AccessUnit>::iterator aUIter; |
---|
1377 | for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ ) |
---|
1378 | { |
---|
1379 | const vector<unsigned>& stats = writeAnnexB(bitstreamFile, *aUIter); |
---|
1380 | rateStatsAccum(*aUIter, stats); |
---|
1381 | } |
---|
1382 | } |
---|
1383 | #else |
---|
1384 | if (!m_reconFileName.empty()) |
---|
1385 | { |
---|
1386 | m_cTVideoIOYuvReconFile.write( pcPicYuvRec, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, |
---|
1387 | NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range ); |
---|
1388 | } |
---|
1389 | |
---|
1390 | const AccessUnit& au = *(iterBitstream++); |
---|
1391 | const vector<UInt>& stats = writeAnnexB(bitstreamFile, au); |
---|
1392 | rateStatsAccum(au, stats); |
---|
1393 | } |
---|
1394 | #endif |
---|
1395 | } |
---|
1396 | } |
---|
1397 | |
---|
1398 | /** |
---|
1399 | * |
---|
1400 | */ |
---|
1401 | Void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& annexBsizes) |
---|
1402 | { |
---|
1403 | AccessUnit::const_iterator it_au = au.begin(); |
---|
1404 | vector<UInt>::const_iterator it_stats = annexBsizes.begin(); |
---|
1405 | |
---|
1406 | for (; it_au != au.end(); it_au++, it_stats++) |
---|
1407 | { |
---|
1408 | switch ((*it_au)->m_nalUnitType) |
---|
1409 | { |
---|
1410 | case NAL_UNIT_CODED_SLICE_TRAIL_R: |
---|
1411 | case NAL_UNIT_CODED_SLICE_TRAIL_N: |
---|
1412 | case NAL_UNIT_CODED_SLICE_TSA_R: |
---|
1413 | case NAL_UNIT_CODED_SLICE_TSA_N: |
---|
1414 | case NAL_UNIT_CODED_SLICE_STSA_R: |
---|
1415 | case NAL_UNIT_CODED_SLICE_STSA_N: |
---|
1416 | case NAL_UNIT_CODED_SLICE_BLA_W_LP: |
---|
1417 | case NAL_UNIT_CODED_SLICE_BLA_W_RADL: |
---|
1418 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: |
---|
1419 | case NAL_UNIT_CODED_SLICE_IDR_W_RADL: |
---|
1420 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: |
---|
1421 | case NAL_UNIT_CODED_SLICE_CRA: |
---|
1422 | case NAL_UNIT_CODED_SLICE_RADL_N: |
---|
1423 | case NAL_UNIT_CODED_SLICE_RADL_R: |
---|
1424 | case NAL_UNIT_CODED_SLICE_RASL_N: |
---|
1425 | case NAL_UNIT_CODED_SLICE_RASL_R: |
---|
1426 | case NAL_UNIT_VPS: |
---|
1427 | case NAL_UNIT_SPS: |
---|
1428 | case NAL_UNIT_PPS: |
---|
1429 | m_essentialBytes += *it_stats; |
---|
1430 | break; |
---|
1431 | default: |
---|
1432 | break; |
---|
1433 | } |
---|
1434 | |
---|
1435 | m_totalBytes += *it_stats; |
---|
1436 | } |
---|
1437 | } |
---|
1438 | |
---|
1439 | Void TAppEncTop::printRateSummary() |
---|
1440 | { |
---|
1441 | #if NH_MV |
---|
1442 | Double time = (Double) m_frameRcvd[0] / m_iFrameRate * m_temporalSubsampleRatio; |
---|
1443 | printf("\n"); |
---|
1444 | #else |
---|
1445 | Double time = (Double) m_iFrameRcvd / m_iFrameRate * m_temporalSubsampleRatio; |
---|
1446 | #endif |
---|
1447 | printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time); |
---|
1448 | if (m_summaryVerboseness > 0) |
---|
1449 | { |
---|
1450 | printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time); |
---|
1451 | } |
---|
1452 | } |
---|
1453 | |
---|
1454 | Void TAppEncTop::printChromaFormat() |
---|
1455 | { |
---|
1456 | std::cout << std::setw(43) << "Input ChromaFormatIDC = "; |
---|
1457 | switch (m_InputChromaFormatIDC) |
---|
1458 | { |
---|
1459 | case CHROMA_400: std::cout << " 4:0:0"; break; |
---|
1460 | case CHROMA_420: std::cout << " 4:2:0"; break; |
---|
1461 | case CHROMA_422: std::cout << " 4:2:2"; break; |
---|
1462 | case CHROMA_444: std::cout << " 4:4:4"; break; |
---|
1463 | default: |
---|
1464 | std::cerr << "Invalid"; |
---|
1465 | exit(1); |
---|
1466 | } |
---|
1467 | std::cout << std::endl; |
---|
1468 | |
---|
1469 | #if NH_MV |
---|
1470 | for (Int i = 0; i < m_numberOfLayers; i++) |
---|
1471 | { |
---|
1472 | std::cout << "Layer " << i << std::setw( 43 - (i > 9 ? 6 : 7) ) << "Internal ChromaFormatIDC = "; |
---|
1473 | switch (m_acTEncTopList[i]->getChromaFormatIdc()) |
---|
1474 | #else |
---|
1475 | std::cout << std::setw(43) << "Output (internal) ChromaFormatIDC = "; |
---|
1476 | switch (m_cTEncTop.getChromaFormatIdc()) |
---|
1477 | #endif |
---|
1478 | { |
---|
1479 | case CHROMA_400: std::cout << " 4:0:0"; break; |
---|
1480 | case CHROMA_420: std::cout << " 4:2:0"; break; |
---|
1481 | case CHROMA_422: std::cout << " 4:2:2"; break; |
---|
1482 | case CHROMA_444: std::cout << " 4:4:4"; break; |
---|
1483 | default: |
---|
1484 | std::cerr << "Invalid"; |
---|
1485 | exit(1); |
---|
1486 | } |
---|
1487 | #if NH_MV |
---|
1488 | std::cout << std::endl; |
---|
1489 | } |
---|
1490 | #endif |
---|
1491 | std::cout << "\n" << std::endl; |
---|
1492 | } |
---|
1493 | |
---|
1494 | #if NH_3D_DLT |
---|
1495 | Void TAppEncTop::xAnalyzeInputBaseDepth(UInt layer, UInt uiNumFrames, TComVPS* vps, TComDLT* dlt) |
---|
1496 | { |
---|
1497 | TComPicYuv* pcDepthPicYuvOrg = new TComPicYuv; |
---|
1498 | TComPicYuv* pcDepthPicYuvTrueOrg = new TComPicYuv; |
---|
1499 | // allocate original YUV buffer |
---|
1500 | pcDepthPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, CHROMA_420, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, false ); |
---|
1501 | pcDepthPicYuvTrueOrg->create( m_iSourceWidth, m_iSourceHeight, CHROMA_420, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, false ); |
---|
1502 | |
---|
1503 | TVideoIOYuv* depthVideoFile = new TVideoIOYuv; |
---|
1504 | |
---|
1505 | UInt uiMaxDepthValue = ((1 << m_inputBitDepth[CHANNEL_TYPE_LUMA])-1); |
---|
1506 | |
---|
1507 | std::vector<Bool> abValidDepths(256, false); |
---|
1508 | |
---|
1509 | depthVideoFile->open( m_pchInputFileList[layer], false, m_inputBitDepth, m_MSBExtendedBitDepth, m_internalBitDepth ); |
---|
1510 | |
---|
1511 | Int iHeight = pcDepthPicYuvOrg->getHeight(COMPONENT_Y); |
---|
1512 | Int iWidth = pcDepthPicYuvOrg->getWidth(COMPONENT_Y); |
---|
1513 | Int iStride = pcDepthPicYuvOrg->getStride(COMPONENT_Y); |
---|
1514 | |
---|
1515 | Pel* pInDM = pcDepthPicYuvOrg->getAddr(COMPONENT_Y); |
---|
1516 | |
---|
1517 | for(Int uiFrame=0; uiFrame < uiNumFrames; uiFrame++ ) |
---|
1518 | { |
---|
1519 | depthVideoFile->read( pcDepthPicYuvOrg, pcDepthPicYuvTrueOrg, IPCOLOURSPACE_UNCHANGED, m_aiPad, m_InputChromaFormatIDC, m_bClipInputVideoToRec709Range ); |
---|
1520 | |
---|
1521 | // check all pixel values |
---|
1522 | for (Int i=0; i<iHeight; i++) |
---|
1523 | { |
---|
1524 | Int rowOffset = i*iStride; |
---|
1525 | |
---|
1526 | for (Int j=0; j<iWidth; j++) |
---|
1527 | { |
---|
1528 | Pel depthValue = pInDM[rowOffset+j]; |
---|
1529 | abValidDepths[depthValue] = true; |
---|
1530 | } |
---|
1531 | } |
---|
1532 | } |
---|
1533 | |
---|
1534 | depthVideoFile->close(); |
---|
1535 | delete depthVideoFile; |
---|
1536 | |
---|
1537 | pcDepthPicYuvOrg->destroy(); |
---|
1538 | delete pcDepthPicYuvOrg; |
---|
1539 | pcDepthPicYuvTrueOrg->destroy(); |
---|
1540 | delete pcDepthPicYuvTrueOrg; |
---|
1541 | |
---|
1542 | // convert boolean array to idx2Depth LUT |
---|
1543 | std::vector<Int> aiIdx2DepthValue(256, 0); |
---|
1544 | Int iNumDepthValues = 0; |
---|
1545 | for(Int p=0; p<=uiMaxDepthValue; p++) |
---|
1546 | { |
---|
1547 | if( abValidDepths[p] == true) |
---|
1548 | { |
---|
1549 | aiIdx2DepthValue[iNumDepthValues++] = p; |
---|
1550 | } |
---|
1551 | } |
---|
1552 | |
---|
1553 | if( uiNumFrames == 0 || gCeilLog2(iNumDepthValues) == m_inputBitDepth[CHANNEL_TYPE_LUMA] ) |
---|
1554 | { |
---|
1555 | dlt->setUseDLTFlag(layer, false); |
---|
1556 | } |
---|
1557 | |
---|
1558 | // assign LUT |
---|
1559 | if( dlt->getUseDLTFlag(layer) ) |
---|
1560 | { |
---|
1561 | dlt->setDepthLUTs(layer, aiIdx2DepthValue, iNumDepthValues); |
---|
1562 | } |
---|
1563 | } |
---|
1564 | #endif |
---|
1565 | |
---|
1566 | #if NH_MV |
---|
1567 | Void TAppEncTop::xSetDimensionIdAndLength( TComVPS& vps ) |
---|
1568 | { |
---|
1569 | vps.setScalabilityMaskFlag( m_scalabilityMask ); |
---|
1570 | for( Int dim = 0; dim < m_dimIds.size(); dim++ ) |
---|
1571 | { |
---|
1572 | vps.setDimensionIdLen( dim, m_dimensionIdLen[ dim ] ); |
---|
1573 | for( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ ) |
---|
1574 | { |
---|
1575 | vps.setDimensionId( layer, dim, m_dimIds[ dim ][ layer ] ); |
---|
1576 | } |
---|
1577 | } |
---|
1578 | |
---|
1579 | vps.initNumViews(); |
---|
1580 | Int maxViewId = xGetMax( m_viewId ); |
---|
1581 | |
---|
1582 | Int viewIdLen = gCeilLog2( maxViewId + 1 ); |
---|
1583 | const Int maxViewIdLen = ( 1 << 4 ) - 1; |
---|
1584 | assert( viewIdLen <= maxViewIdLen ); |
---|
1585 | vps.setViewIdLen( viewIdLen ); |
---|
1586 | for (Int i = 0; i < m_iNumberOfViews; i++) |
---|
1587 | { |
---|
1588 | vps.setViewIdVal( i, m_viewId[ i] ); |
---|
1589 | } |
---|
1590 | |
---|
1591 | assert( m_iNumberOfViews == vps.getNumViews() ); |
---|
1592 | |
---|
1593 | |
---|
1594 | #if NH_3D |
---|
1595 | vps.initViewCompLayer( ); |
---|
1596 | #endif |
---|
1597 | } |
---|
1598 | |
---|
1599 | Void TAppEncTop::xSetDependencies( TComVPS& vps ) |
---|
1600 | { |
---|
1601 | // Direct dependency flags + dependency types |
---|
1602 | for( Int depLayer = 1; depLayer < MAX_NUM_LAYERS; depLayer++ ) |
---|
1603 | { |
---|
1604 | for( Int refLayer = 0; refLayer < MAX_NUM_LAYERS; refLayer++ ) |
---|
1605 | { |
---|
1606 | vps.setDirectDependencyFlag( depLayer, refLayer, false); |
---|
1607 | vps.setDirectDependencyType( depLayer, refLayer, -1 ); |
---|
1608 | } |
---|
1609 | } |
---|
1610 | |
---|
1611 | Int defaultDirectDependencyType = -1; |
---|
1612 | Bool defaultDirectDependencyFlag = false; |
---|
1613 | |
---|
1614 | Int directDepTypeLenMinus2 = 0; |
---|
1615 | for( Int depLayer = 1; depLayer < m_numberOfLayers; depLayer++ ) |
---|
1616 | { |
---|
1617 | Int numRefLayers = (Int) m_directRefLayers[depLayer].size(); |
---|
1618 | assert( numRefLayers == (Int) m_dependencyTypes[depLayer].size() ); |
---|
1619 | for( Int i = 0; i < numRefLayers; i++ ) |
---|
1620 | { |
---|
1621 | Int refLayer = m_directRefLayers[depLayer][i]; |
---|
1622 | vps.setDirectDependencyFlag( depLayer, refLayer, true); |
---|
1623 | Int curDirectDependencyType = m_dependencyTypes[depLayer][i]; |
---|
1624 | directDepTypeLenMinus2 = std::max( directDepTypeLenMinus2, gCeilLog2( curDirectDependencyType + 1 ) - 2 ); |
---|
1625 | if ( defaultDirectDependencyType != -1 ) |
---|
1626 | { |
---|
1627 | defaultDirectDependencyFlag = defaultDirectDependencyFlag && (curDirectDependencyType == defaultDirectDependencyType ); |
---|
1628 | } |
---|
1629 | else |
---|
1630 | { |
---|
1631 | defaultDirectDependencyType = curDirectDependencyType; |
---|
1632 | defaultDirectDependencyFlag = true; |
---|
1633 | } |
---|
1634 | |
---|
1635 | vps.setDirectDependencyType( depLayer, refLayer, curDirectDependencyType); |
---|
1636 | } |
---|
1637 | } |
---|
1638 | |
---|
1639 | vps.setDefaultDirectDependencyFlag( defaultDirectDependencyFlag ); |
---|
1640 | vps.setDefaultDirectDependencyType( defaultDirectDependencyFlag ? defaultDirectDependencyType : -1 ); |
---|
1641 | |
---|
1642 | assert( directDepTypeLenMinus2 <= 1 ); |
---|
1643 | vps.setDirectDepTypeLenMinus2( directDepTypeLenMinus2 ); |
---|
1644 | |
---|
1645 | |
---|
1646 | vps.setRefLayers(); |
---|
1647 | |
---|
1648 | // Max sub layers, + presence flag |
---|
1649 | Bool subLayersMaxMinus1PresentFlag = false; |
---|
1650 | for (Int curLayerIdInVps = 0; curLayerIdInVps < m_numberOfLayers; curLayerIdInVps++ ) |
---|
1651 | { |
---|
1652 | Int curSubLayersMaxMinus1 = 0; |
---|
1653 | for( Int i = 0; i < getGOPSize(); i++ ) |
---|
1654 | { |
---|
1655 | GOPEntry geCur = m_GOPListMvc[curLayerIdInVps][i]; |
---|
1656 | curSubLayersMaxMinus1 = std::max( curSubLayersMaxMinus1, geCur.m_temporalId ); |
---|
1657 | } |
---|
1658 | |
---|
1659 | vps.setSubLayersVpsMaxMinus1( curLayerIdInVps, curSubLayersMaxMinus1 ); |
---|
1660 | subLayersMaxMinus1PresentFlag = subLayersMaxMinus1PresentFlag || ( curSubLayersMaxMinus1 != vps.getMaxSubLayersMinus1() ); |
---|
1661 | } |
---|
1662 | |
---|
1663 | vps.setVpsSubLayersMaxMinus1PresentFlag( subLayersMaxMinus1PresentFlag ); |
---|
1664 | |
---|
1665 | // Max temporal id for inter layer reference pictures |
---|
1666 | for ( Int refLayerIdInVps = 0; refLayerIdInVps < m_numberOfLayers; refLayerIdInVps++) |
---|
1667 | { |
---|
1668 | Int refLayerIdInNuh = vps.getLayerIdInNuh( refLayerIdInVps ); |
---|
1669 | for ( Int curLayerIdInVps = 1; curLayerIdInVps < m_numberOfLayers; curLayerIdInVps++) |
---|
1670 | { |
---|
1671 | Int curLayerIdInNuh = vps.getLayerIdInNuh( curLayerIdInVps ); |
---|
1672 | Int maxTid = -1; |
---|
1673 | #if NH_3D |
---|
1674 | if ( vps.getDirectDependencyFlag( curLayerIdInVps, refLayerIdInVps ) ) |
---|
1675 | { |
---|
1676 | if ( m_depthFlag[ curLayerIdInVps] == m_depthFlag[ refLayerIdInVps ] ) |
---|
1677 | { |
---|
1678 | #endif |
---|
1679 | for( Int i = 0; i < ( getGOPSize() + 1); i++ ) |
---|
1680 | { |
---|
1681 | GOPEntry geCur = m_GOPListMvc[curLayerIdInVps][( i < getGOPSize() ? i : MAX_GOP )]; |
---|
1682 | GOPEntry geRef = m_GOPListMvc[refLayerIdInVps][( i < getGOPSize() ? i : MAX_GOP )]; |
---|
1683 | for (Int j = 0; j < geCur.m_numActiveRefLayerPics; j++) |
---|
1684 | { |
---|
1685 | #if NH_3D |
---|
1686 | if ( vps.getIdRefListLayer( curLayerIdInNuh, geCur.m_interLayerPredLayerIdc[ j ] ) == refLayerIdInNuh ) |
---|
1687 | #else |
---|
1688 | if ( vps.getIdDirectRefLayer( curLayerIdInNuh, geCur.m_interLayerPredLayerIdc[ j ] ) == refLayerIdInNuh ) |
---|
1689 | #endif |
---|
1690 | { |
---|
1691 | Bool refLayerZero = ( i == getGOPSize() ) && ( refLayerIdInVps == 0 ); |
---|
1692 | maxTid = std::max( maxTid, refLayerZero ? 0 : geRef.m_temporalId ); |
---|
1693 | } |
---|
1694 | } |
---|
1695 | } |
---|
1696 | #if NH_3D |
---|
1697 | } |
---|
1698 | else |
---|
1699 | { |
---|
1700 | if( m_depthFlag[ curLayerIdInVps ] && ( m_mpiFlag|| m_qtPredFlag || m_intraContourFlag ) ) |
---|
1701 | { |
---|
1702 | Int nuhLayerIdTex = vps.getLayerIdInNuh( vps.getViewIndex( curLayerIdInNuh ), false, 0 ); |
---|
1703 | if ( nuhLayerIdTex == refLayerIdInNuh ) |
---|
1704 | { |
---|
1705 | for( Int i = 0; i < ( getGOPSize() + 1); i++ ) |
---|
1706 | { |
---|
1707 | GOPEntry geCur = m_GOPListMvc[curLayerIdInVps][( i < getGOPSize() ? i : MAX_GOP )]; |
---|
1708 | GOPEntry geRef = m_GOPListMvc[refLayerIdInVps][( i < getGOPSize() ? i : MAX_GOP )]; |
---|
1709 | if ( geCur.m_interCompPredFlag ) |
---|
1710 | { |
---|
1711 | Bool refLayerZero = ( i == getGOPSize() ) && ( refLayerIdInVps == 0 ); |
---|
1712 | maxTid = std::max( maxTid, refLayerZero ? 0 : geRef.m_temporalId ); |
---|
1713 | } |
---|
1714 | } |
---|
1715 | } |
---|
1716 | } |
---|
1717 | if( !m_depthFlag[ curLayerIdInVps ] && vps.getNumRefListLayers( curLayerIdInNuh) > 0 && ( m_depthRefinementFlag || m_viewSynthesisPredFlag || m_depthBasedBlkPartFlag ) ) |
---|
1718 | { |
---|
1719 | for( Int i = 0; i < ( getGOPSize() + 1); i++ ) |
---|
1720 | { |
---|
1721 | GOPEntry geCur = m_GOPListMvc[curLayerIdInVps][( i < getGOPSize() ? i : MAX_GOP )]; |
---|
1722 | GOPEntry geRef = m_GOPListMvc[refLayerIdInVps][( i < getGOPSize() ? i : MAX_GOP )]; |
---|
1723 | |
---|
1724 | if ( geCur.m_interCompPredFlag ) |
---|
1725 | { |
---|
1726 | for (Int j = 0; j < geCur.m_numActiveRefLayerPics; j++ ) |
---|
1727 | { |
---|
1728 | Int nuhLayerIdDep = vps.getLayerIdInNuh( vps.getViewIndex( vps.getIdRefListLayer( curLayerIdInNuh, geCur.m_interLayerPredLayerIdc[j] ) ), true, 0 ); |
---|
1729 | if ( nuhLayerIdDep == refLayerIdInNuh ) |
---|
1730 | { |
---|
1731 | Bool refLayerZero = ( i == getGOPSize() ) && ( refLayerIdInVps == 0 ); |
---|
1732 | maxTid = std::max( maxTid, refLayerZero ? 0 : geRef.m_temporalId ); |
---|
1733 | } |
---|
1734 | } |
---|
1735 | } |
---|
1736 | } |
---|
1737 | } |
---|
1738 | } |
---|
1739 | } // if ( vps.getDirectDependencyFlag( curLayerIdInVps, refLayerIdInVps ) ) |
---|
1740 | vps.setMaxTidIlRefPicsPlus1( refLayerIdInVps, curLayerIdInVps, maxTid + 1 ); |
---|
1741 | #endif |
---|
1742 | } // Loop curLayerIdInVps |
---|
1743 | } // Loop refLayerIdInVps |
---|
1744 | |
---|
1745 | // Max temporal id for inter layer reference pictures presence flag |
---|
1746 | Bool maxTidRefPresentFlag = false; |
---|
1747 | for ( Int refLayerIdInVps = 0; refLayerIdInVps < m_numberOfLayers; refLayerIdInVps++) |
---|
1748 | { |
---|
1749 | for ( Int curLayerIdInVps = 1; curLayerIdInVps < m_numberOfLayers; curLayerIdInVps++) |
---|
1750 | { |
---|
1751 | maxTidRefPresentFlag = maxTidRefPresentFlag || ( vps.getMaxTidIlRefPicsPlus1( refLayerIdInVps, curLayerIdInVps ) != 7 ); |
---|
1752 | } |
---|
1753 | } |
---|
1754 | vps.setMaxTidRefPresentFlag( maxTidRefPresentFlag ); |
---|
1755 | |
---|
1756 | |
---|
1757 | // Max one active ref layer flag |
---|
1758 | Bool maxOneActiveRefLayerFlag = true; |
---|
1759 | for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && maxOneActiveRefLayerFlag; layerIdInVps++) |
---|
1760 | { |
---|
1761 | for( Int i = 0; i < ( getGOPSize() + 1) && maxOneActiveRefLayerFlag; i++ ) |
---|
1762 | { |
---|
1763 | GOPEntry ge = m_GOPListMvc[layerIdInVps][ ( i < getGOPSize() ? i : MAX_GOP ) ]; |
---|
1764 | maxOneActiveRefLayerFlag = maxOneActiveRefLayerFlag && (ge.m_numActiveRefLayerPics <= 1); |
---|
1765 | } |
---|
1766 | } |
---|
1767 | |
---|
1768 | vps.setMaxOneActiveRefLayerFlag( maxOneActiveRefLayerFlag ); |
---|
1769 | |
---|
1770 | // Poc Lsb Not Present Flag |
---|
1771 | for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers; layerIdInVps++) |
---|
1772 | { |
---|
1773 | if ( m_directRefLayers[ layerIdInVps ].size() == 0 ) |
---|
1774 | { |
---|
1775 | vps.setPocLsbNotPresentFlag( layerIdInVps, true ); |
---|
1776 | } |
---|
1777 | } |
---|
1778 | |
---|
1779 | // All Ref layers active flag |
---|
1780 | Bool allRefLayersActiveFlag = true; |
---|
1781 | for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && allRefLayersActiveFlag; layerIdInVps++) |
---|
1782 | { |
---|
1783 | Int layerIdInNuh = vps.getLayerIdInNuh( layerIdInVps ); |
---|
1784 | for( Int i = 0; i < ( getGOPSize() + 1) && allRefLayersActiveFlag; i++ ) |
---|
1785 | { |
---|
1786 | GOPEntry ge = m_GOPListMvc[layerIdInVps][ ( i < getGOPSize() ? i : MAX_GOP ) ]; |
---|
1787 | Int tId = ge.m_temporalId; // Should be equal for all layers. |
---|
1788 | |
---|
1789 | // check if all reference layers when allRefLayerActiveFlag is equal to 1 are reference layer pictures specified in the gop entry |
---|
1790 | #if NH_3D |
---|
1791 | for (Int k = 0; k < vps.getNumRefListLayers( layerIdInNuh ) && allRefLayersActiveFlag; k++ ) |
---|
1792 | { |
---|
1793 | Int refLayerIdInVps = vps.getLayerIdInVps( vps.getIdRefListLayer( layerIdInNuh , k ) ); |
---|
1794 | #else |
---|
1795 | for (Int k = 0; k < vps.getNumDirectRefLayers( layerIdInNuh ) && allRefLayersActiveFlag; k++ ) |
---|
1796 | { |
---|
1797 | Int refLayerIdInVps = vps.getLayerIdInVps( vps.getIdDirectRefLayer( layerIdInNuh , k ) ); |
---|
1798 | #endif |
---|
1799 | if ( vps.getSubLayersVpsMaxMinus1(refLayerIdInVps) >= tId && ( tId == 0 || vps.getMaxTidIlRefPicsPlus1(refLayerIdInVps,layerIdInVps) > tId ) ) |
---|
1800 | { |
---|
1801 | Bool gopEntryFoundFlag = false; |
---|
1802 | for( Int l = 0; l < ge.m_numActiveRefLayerPics && !gopEntryFoundFlag; l++ ) |
---|
1803 | { |
---|
1804 | gopEntryFoundFlag = gopEntryFoundFlag || ( ge.m_interLayerPredLayerIdc[l] == k ); |
---|
1805 | } |
---|
1806 | allRefLayersActiveFlag = allRefLayersActiveFlag && gopEntryFoundFlag; |
---|
1807 | } |
---|
1808 | } |
---|
1809 | |
---|
1810 | // check if all inter layer reference pictures specified in the gop entry are valid reference layer pictures when allRefLayerActiveFlag is equal to 1 |
---|
1811 | // (Should actually always be true) |
---|
1812 | Bool maxTidIlRefAndSubLayerMaxValidFlag = true; |
---|
1813 | for( Int l = 0; l < ge.m_numActiveRefLayerPics; l++ ) |
---|
1814 | { |
---|
1815 | Bool referenceLayerFoundFlag = false; |
---|
1816 | #if NH_3D |
---|
1817 | for (Int k = 0; k < vps.getNumRefListLayers( layerIdInNuh ); k++ ) |
---|
1818 | { |
---|
1819 | Int refLayerIdInVps = vps.getLayerIdInVps( vps.getIdRefListLayer( layerIdInNuh, k) ); |
---|
1820 | #else |
---|
1821 | for (Int k = 0; k < vps.getNumDirectRefLayers( layerIdInNuh ); k++ ) |
---|
1822 | { |
---|
1823 | Int refLayerIdInVps = vps.getLayerIdInVps( vps.getIdDirectRefLayer( layerIdInNuh, k) ); |
---|
1824 | #endif |
---|
1825 | if ( vps.getSubLayersVpsMaxMinus1(refLayerIdInVps) >= tId && ( tId == 0 || vps.getMaxTidIlRefPicsPlus1(refLayerIdInVps,layerIdInVps) > tId ) ) |
---|
1826 | { |
---|
1827 | referenceLayerFoundFlag = referenceLayerFoundFlag || ( ge.m_interLayerPredLayerIdc[l] == k ); |
---|
1828 | } |
---|
1829 | } |
---|
1830 | maxTidIlRefAndSubLayerMaxValidFlag = maxTidIlRefAndSubLayerMaxValidFlag && referenceLayerFoundFlag; |
---|
1831 | } |
---|
1832 | assert ( maxTidIlRefAndSubLayerMaxValidFlag ); // Something wrong with MaxTidIlRefPicsPlus1 or SubLayersVpsMaxMinus1 |
---|
1833 | } |
---|
1834 | } |
---|
1835 | |
---|
1836 | vps.setAllRefLayersActiveFlag( allRefLayersActiveFlag ); |
---|
1837 | }; |
---|
1838 | |
---|
1839 | |
---|
1840 | GOPEntry* TAppEncTop::xGetGopEntry( Int layerIdInVps, Int poc ) |
---|
1841 | { |
---|
1842 | GOPEntry* geFound = NULL; |
---|
1843 | for( Int i = 0; i < ( getGOPSize() + 1) && geFound == NULL ; i++ ) |
---|
1844 | { |
---|
1845 | GOPEntry* ge = &(m_GOPListMvc[layerIdInVps][ ( i < getGOPSize() ? i : MAX_GOP ) ]); |
---|
1846 | if ( ge->m_POC == poc ) |
---|
1847 | { |
---|
1848 | geFound = ge; |
---|
1849 | } |
---|
1850 | } |
---|
1851 | assert( geFound != NULL ); |
---|
1852 | return geFound; |
---|
1853 | } |
---|
1854 | |
---|
1855 | |
---|
1856 | Void TAppEncTop::xSetTimingInfo( TComVPS& vps ) |
---|
1857 | { |
---|
1858 | vps.getTimingInfo()->setTimingInfoPresentFlag( false ); |
---|
1859 | } |
---|
1860 | |
---|
1861 | Void TAppEncTop::xSetHrdParameters( TComVPS& vps ) |
---|
1862 | { |
---|
1863 | vps.createHrdParamBuffer(); |
---|
1864 | for( Int i = 0; i < vps.getNumHrdParameters(); i++ ) |
---|
1865 | { |
---|
1866 | vps.setHrdOpSetIdx( 0, i ); |
---|
1867 | vps.setCprmsPresentFlag( false, i ); |
---|
1868 | } |
---|
1869 | } |
---|
1870 | |
---|
1871 | Void TAppEncTop::xSetLayerIds( TComVPS& vps ) |
---|
1872 | { |
---|
1873 | vps.setSplittingFlag ( m_splittingFlag ); |
---|
1874 | |
---|
1875 | Bool nuhLayerIdPresentFlag = false; |
---|
1876 | |
---|
1877 | |
---|
1878 | vps.setVpsMaxLayerId( xGetMax( m_layerIdInNuh ) ); |
---|
1879 | |
---|
1880 | for (Int i = 0; i < m_numberOfLayers; i++) |
---|
1881 | { |
---|
1882 | nuhLayerIdPresentFlag = nuhLayerIdPresentFlag || ( m_layerIdInNuh[i] != i ); |
---|
1883 | } |
---|
1884 | |
---|
1885 | vps.setVpsNuhLayerIdPresentFlag( nuhLayerIdPresentFlag ); |
---|
1886 | |
---|
1887 | for (Int layer = 0; layer < m_numberOfLayers; layer++ ) |
---|
1888 | { |
---|
1889 | vps.setLayerIdInNuh( layer, nuhLayerIdPresentFlag ? m_layerIdInNuh[ layer ] : layer ); |
---|
1890 | vps.setLayerIdInVps( vps.getLayerIdInNuh( layer ), layer ); |
---|
1891 | } |
---|
1892 | } |
---|
1893 | |
---|
1894 | Int TAppEncTop::xGetMax( std::vector<Int>& vec ) |
---|
1895 | { |
---|
1896 | Int maxVec = 0; |
---|
1897 | for ( Int i = 0; i < vec.size(); i++) |
---|
1898 | { |
---|
1899 | maxVec = max( vec[i], maxVec ); |
---|
1900 | } |
---|
1901 | return maxVec; |
---|
1902 | } |
---|
1903 | |
---|
1904 | Void TAppEncTop::xSetProfileTierLevel( TComVPS& vps ) |
---|
1905 | { |
---|
1906 | |
---|
1907 | // SET PTL |
---|
1908 | assert( m_profiles.size() == m_level.size() && m_profiles.size() == m_levelTier.size() ); |
---|
1909 | vps.setVpsNumProfileTierLevelMinus1( (Int) m_profiles.size() - 1 ); |
---|
1910 | for ( Int ptlIdx = 0; ptlIdx <= vps.getVpsNumProfileTierLevelMinus1(); ptlIdx++ ) |
---|
1911 | { |
---|
1912 | if ( ptlIdx > 1 ) |
---|
1913 | { |
---|
1914 | Bool vpsProfilePresentFlag = ( m_profiles[ptlIdx] != m_profiles[ptlIdx - 1] ) |
---|
1915 | || ( m_inblFlag[ptlIdx ] != m_inblFlag[ptlIdx - 1] ); |
---|
1916 | vps.setVpsProfilePresentFlag( ptlIdx, vpsProfilePresentFlag ); |
---|
1917 | } |
---|
1918 | |
---|
1919 | xSetProfileTierLevel( vps, ptlIdx, -1, m_profiles[ptlIdx], m_level[ptlIdx], |
---|
1920 | m_levelTier[ ptlIdx ], m_progressiveSourceFlag, m_interlacedSourceFlag, |
---|
1921 | m_nonPackedConstraintFlag, m_frameOnlyConstraintFlag, m_inblFlag[ptlIdx] ); |
---|
1922 | } |
---|
1923 | } |
---|
1924 | |
---|
1925 | Void TAppEncTop::xSetProfileTierLevel(TComVPS& vps, Int profileTierLevelIdx, Int subLayer, Profile::Name profile, Level::Name level, Level::Tier tier, Bool progressiveSourceFlag, Bool interlacedSourceFlag, Bool nonPackedConstraintFlag, Bool frameOnlyConstraintFlag, Bool inbldFlag) |
---|
1926 | { |
---|
1927 | TComPTL* ptlStruct = vps.getPTL( profileTierLevelIdx ); |
---|
1928 | assert( ptlStruct != NULL ); |
---|
1929 | |
---|
1930 | ProfileTierLevel* ptl; |
---|
1931 | if ( subLayer == -1 ) |
---|
1932 | { |
---|
1933 | ptl = ptlStruct->getGeneralPTL(); |
---|
1934 | } |
---|
1935 | else |
---|
1936 | { |
---|
1937 | ptl = ptlStruct->getSubLayerPTL( subLayer ); |
---|
1938 | } |
---|
1939 | |
---|
1940 | assert( ptl != NULL ); |
---|
1941 | |
---|
1942 | ptl->setProfileIdc( profile ); |
---|
1943 | ptl->setTierFlag ( tier ); |
---|
1944 | ptl->setLevelIdc ( level ); |
---|
1945 | ptl->setProfileCompatibilityFlag( profile, true ); |
---|
1946 | ptl->setInbldFlag( inbldFlag ); |
---|
1947 | |
---|
1948 | switch ( profile ) |
---|
1949 | { |
---|
1950 | case Profile::MAIN: |
---|
1951 | break; |
---|
1952 | case Profile::MULTIVIEWMAIN: |
---|
1953 | #if NH_3D |
---|
1954 | case Profile::MAIN3D: |
---|
1955 | #endif |
---|
1956 | ptl->setMax12bitConstraintFlag ( true ); |
---|
1957 | ptl->setMax12bitConstraintFlag ( true ); |
---|
1958 | ptl->setMax10bitConstraintFlag ( true ); |
---|
1959 | ptl->setMax8bitConstraintFlag ( true ); |
---|
1960 | ptl->setMax422chromaConstraintFlag ( true ); |
---|
1961 | ptl->setMax420chromaConstraintFlag ( true ); |
---|
1962 | ptl->setMaxMonochromeConstraintFlag ( false ); |
---|
1963 | ptl->setIntraConstraintFlag ( false ); |
---|
1964 | ptl->setOnePictureOnlyConstraintFlag( false ); |
---|
1965 | ptl->setLowerBitRateConstraintFlag ( true ); |
---|
1966 | break; |
---|
1967 | default: |
---|
1968 | assert( 0 ); // other profiles currently not supported |
---|
1969 | break; |
---|
1970 | } |
---|
1971 | } |
---|
1972 | |
---|
1973 | Void TAppEncTop::xSetRepFormat( TComVPS& vps ) |
---|
1974 | { |
---|
1975 | |
---|
1976 | Bool anyDepth = false; |
---|
1977 | #if NH_3D |
---|
1978 | for ( Int i = 0; i < m_numberOfLayers; i++ ) |
---|
1979 | { |
---|
1980 | vps.setVpsRepFormatIdx( i, m_depthFlag[ i ] ? 1 : 0 ); |
---|
1981 | anyDepth = anyDepth || m_depthFlag[ i ]; |
---|
1982 | } |
---|
1983 | #endif |
---|
1984 | |
---|
1985 | vps.setRepFormatIdxPresentFlag( anyDepth ); |
---|
1986 | vps.setVpsNumRepFormatsMinus1 ( anyDepth ? 1 : 0 ); |
---|
1987 | |
---|
1988 | |
---|
1989 | std::vector<TComRepFormat> repFormat; |
---|
1990 | repFormat.resize( vps.getVpsNumRepFormatsMinus1() + 1 ); |
---|
1991 | for ( Int j = 0; j <= vps.getVpsNumRepFormatsMinus1(); j++ ) |
---|
1992 | { |
---|
1993 | repFormat[j].setBitDepthVpsChromaMinus8 ( m_internalBitDepth[CHANNEL_TYPE_LUMA ] - 8 ); |
---|
1994 | repFormat[j].setBitDepthVpsLumaMinus8 ( m_internalBitDepth[CHANNEL_TYPE_CHROMA] - 8 ); |
---|
1995 | repFormat[j].setChromaFormatVpsIdc ( j == 1 ? CHROMA_400 : CHROMA_420 ); |
---|
1996 | repFormat[j].setPicHeightVpsInLumaSamples ( m_iSourceHeight ); |
---|
1997 | repFormat[j].setPicWidthVpsInLumaSamples ( m_iSourceWidth ); |
---|
1998 | repFormat[j].setChromaAndBitDepthVpsPresentFlag( true ); |
---|
1999 | // ToDo not supported yet. |
---|
2000 | //repFormat->setSeparateColourPlaneVpsFlag( ); |
---|
2001 | |
---|
2002 | repFormat[j].setConformanceWindowVpsFlag( true ); |
---|
2003 | repFormat[j].setConfWinVpsLeftOffset ( m_confWinLeft / TComSPS::getWinUnitX( repFormat[j].getChromaFormatVpsIdc() ) ); |
---|
2004 | repFormat[j].setConfWinVpsRightOffset ( m_confWinRight / TComSPS::getWinUnitX( repFormat[j].getChromaFormatVpsIdc() ) ); |
---|
2005 | repFormat[j].setConfWinVpsTopOffset ( m_confWinTop / TComSPS::getWinUnitY( repFormat[j].getChromaFormatVpsIdc() ) ); |
---|
2006 | repFormat[j].setConfWinVpsBottomOffset ( m_confWinBottom / TComSPS::getWinUnitY( repFormat[j].getChromaFormatVpsIdc() ) ); |
---|
2007 | } |
---|
2008 | |
---|
2009 | vps.setRepFormat( repFormat ); |
---|
2010 | |
---|
2011 | } |
---|
2012 | |
---|
2013 | Void TAppEncTop::xSetDpbSize ( TComVPS& vps ) |
---|
2014 | { |
---|
2015 | // These settings need to be verified |
---|
2016 | |
---|
2017 | TComDpbSize dpbSize; |
---|
2018 | dpbSize.init( vps.getNumOutputLayerSets(), vps.getVpsMaxLayerId() + 1, vps.getMaxSubLayersMinus1() + 1 ) ; |
---|
2019 | |
---|
2020 | |
---|
2021 | for( Int i = 0; i < vps.getNumOutputLayerSets(); i++ ) |
---|
2022 | { |
---|
2023 | Int currLsIdx = vps.olsIdxToLsIdx( i ); |
---|
2024 | Bool subLayerFlagInfoPresentFlag = false; |
---|
2025 | |
---|
2026 | for( Int j = 0; j <= vps.getMaxSubLayersInLayerSetMinus1( currLsIdx ); j++ ) |
---|
2027 | { |
---|
2028 | Bool subLayerDpbInfoPresentFlag = false; |
---|
2029 | for( Int k = 0; k < vps.getNumLayersInIdList( currLsIdx ); k++ ) |
---|
2030 | { |
---|
2031 | Int layerIdInVps = vps.getLayerIdInVps( vps.getLayerSetLayerIdList( currLsIdx, k ) ); |
---|
2032 | if ( vps.getNecessaryLayerFlag( i,k ) && ( vps.getVpsBaseLayerInternalFlag() || vps.getLayerSetLayerIdList( currLsIdx, k ) != 0 ) ) |
---|
2033 | { |
---|
2034 | dpbSize.setMaxVpsDecPicBufferingMinus1( i, k, j, m_maxDecPicBufferingMvc[ layerIdInVps ][ j ] - 1 ); |
---|
2035 | if ( j > 0 ) |
---|
2036 | { |
---|
2037 | subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize.getMaxVpsDecPicBufferingMinus1( i, k, j ) != dpbSize.getMaxVpsDecPicBufferingMinus1( i, k, j - 1 ) ); |
---|
2038 | } |
---|
2039 | } |
---|
2040 | else |
---|
2041 | { |
---|
2042 | if (vps.getNecessaryLayerFlag(i,k) && j == 0 && k == 0 ) |
---|
2043 | { |
---|
2044 | dpbSize.setMaxVpsDecPicBufferingMinus1(i, k ,j, 0 ); |
---|
2045 | } |
---|
2046 | } |
---|
2047 | } |
---|
2048 | |
---|
2049 | Int maxNumReorderPics = MIN_INT; |
---|
2050 | for ( Int idx = 0; idx < vps.getNumLayersInIdList( currLsIdx ); idx++ ) |
---|
2051 | { |
---|
2052 | if (vps.getNecessaryLayerFlag(i, idx )) |
---|
2053 | { |
---|
2054 | Int layerIdInVps = vps.getLayerIdInVps( vps.getLayerSetLayerIdList(currLsIdx, idx) ); |
---|
2055 | maxNumReorderPics = std::max( maxNumReorderPics, m_numReorderPicsMvc[ layerIdInVps ][ j ] ); |
---|
2056 | } |
---|
2057 | } |
---|
2058 | assert( maxNumReorderPics != MIN_INT ); |
---|
2059 | |
---|
2060 | dpbSize.setMaxVpsNumReorderPics( i, j, maxNumReorderPics ); |
---|
2061 | if ( j > 0 ) |
---|
2062 | { |
---|
2063 | subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize.getMaxVpsNumReorderPics( i, j ) != dpbSize.getMaxVpsNumReorderPics( i, j - 1 ) ); |
---|
2064 | } |
---|
2065 | |
---|
2066 | // To Be Done ! |
---|
2067 | // dpbSize.setMaxVpsLatencyIncreasePlus1( i, j, xx ); |
---|
2068 | if ( j > 0 ) |
---|
2069 | { |
---|
2070 | subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize.getMaxVpsLatencyIncreasePlus1( i, j ) != dpbSize.getMaxVpsLatencyIncreasePlus1( i, j - 1 ) ); |
---|
2071 | } |
---|
2072 | |
---|
2073 | if( j > 0 ) |
---|
2074 | { |
---|
2075 | dpbSize.setSubLayerDpbInfoPresentFlag( i, j, subLayerDpbInfoPresentFlag ); |
---|
2076 | subLayerFlagInfoPresentFlag = subLayerFlagInfoPresentFlag || subLayerDpbInfoPresentFlag; |
---|
2077 | } |
---|
2078 | } |
---|
2079 | dpbSize.setSubLayerFlagInfoPresentFlag( i, subLayerFlagInfoPresentFlag ); |
---|
2080 | } |
---|
2081 | vps.setDpbSize( dpbSize ); |
---|
2082 | } |
---|
2083 | |
---|
2084 | Void TAppEncTop::xSetLayerSets( TComVPS& vps ) |
---|
2085 | { |
---|
2086 | // Layer sets |
---|
2087 | vps.setVpsNumLayerSetsMinus1 ( m_vpsNumLayerSets - 1 ); |
---|
2088 | |
---|
2089 | for (Int lsIdx = 0; lsIdx < m_vpsNumLayerSets; lsIdx++ ) |
---|
2090 | { |
---|
2091 | for( Int layerId = 0; layerId < MAX_NUM_LAYER_IDS; layerId++ ) |
---|
2092 | { |
---|
2093 | vps.setLayerIdIncludedFlag( false, lsIdx, layerId ); |
---|
2094 | } |
---|
2095 | for ( Int i = 0; i < m_layerIdxInVpsInSets[lsIdx].size(); i++) |
---|
2096 | { |
---|
2097 | vps.setLayerIdIncludedFlag( true, lsIdx, vps.getLayerIdInNuh( m_layerIdxInVpsInSets[lsIdx][i] ) ); |
---|
2098 | } |
---|
2099 | } |
---|
2100 | vps.deriveLayerSetLayerIdList(); |
---|
2101 | |
---|
2102 | Int numAddOuputLayerSets = (Int) m_outputLayerSetIdx.size(); |
---|
2103 | // Additional output layer sets + profileLevelTierIdx |
---|
2104 | vps.setDefaultOutputLayerIdc ( m_defaultOutputLayerIdc ); |
---|
2105 | if( vps.getNumIndependentLayers() == 0 && m_numAddLayerSets > 0 ) |
---|
2106 | { |
---|
2107 | fprintf( stderr, "\nWarning: Ignoring additional layer sets since NumIndependentLayers is equal to 0.\n"); |
---|
2108 | } |
---|
2109 | else |
---|
2110 | { |
---|
2111 | vps.setNumAddLayerSets( m_numAddLayerSets ); |
---|
2112 | if ( m_highestLayerIdxPlus1.size() < vps.getNumAddLayerSets() ) |
---|
2113 | { |
---|
2114 | fprintf(stderr, "\nError: Number of highestLayerIdxPlus1 parameters must be greater than or equal to NumAddLayerSets\n"); |
---|
2115 | exit(EXIT_FAILURE); |
---|
2116 | } |
---|
2117 | |
---|
2118 | for (Int i = 0; i < vps.getNumAddLayerSets(); i++) |
---|
2119 | { |
---|
2120 | if ( m_highestLayerIdxPlus1[ i ].size() < vps.getNumIndependentLayers() ) |
---|
2121 | { |
---|
2122 | fprintf(stderr, "Error: Number of elements in highestLayerIdxPlus1[ %d ] parameters must be greater than or equal to NumIndependentLayers(= %d)\n", i, vps.getNumIndependentLayers()); |
---|
2123 | exit(EXIT_FAILURE); |
---|
2124 | } |
---|
2125 | |
---|
2126 | for (Int j = 1; j < vps.getNumIndependentLayers(); j++) |
---|
2127 | { |
---|
2128 | if ( m_highestLayerIdxPlus1[ i ][ j ] < 0 || m_highestLayerIdxPlus1[ i ][ j ] > vps.getNumLayersInTreePartition( j ) ) |
---|
2129 | { |
---|
2130 | fprintf(stderr, "Error: highestLayerIdxPlus1[ %d ][ %d ] shall be in the range of 0 to NumLayersInTreePartition[ %d ] (= %d ), inclusive. \n", i, j, j, vps.getNumLayersInTreePartition( j ) ); |
---|
2131 | exit(EXIT_FAILURE); |
---|
2132 | } |
---|
2133 | vps.setHighestLayerIdxPlus1( i, j, m_highestLayerIdxPlus1[ i ][ j ] ); |
---|
2134 | } |
---|
2135 | vps.deriveAddLayerSetLayerIdList( i ); |
---|
2136 | } |
---|
2137 | } |
---|
2138 | vps.setNumAddOlss ( numAddOuputLayerSets ); |
---|
2139 | vps.initTargetLayerIdLists(); |
---|
2140 | |
---|
2141 | for (Int olsIdx = 0; olsIdx < vps.getNumLayerSets() + numAddOuputLayerSets; olsIdx++) |
---|
2142 | { |
---|
2143 | Int addOutLsIdx = olsIdx - vps.getNumLayerSets(); |
---|
2144 | vps.setLayerSetIdxForOlsMinus1( olsIdx, ( ( addOutLsIdx < 0 ) ? olsIdx : m_outputLayerSetIdx[ addOutLsIdx ] ) - 1 ); |
---|
2145 | |
---|
2146 | Int lsIdx = vps.olsIdxToLsIdx( olsIdx ); |
---|
2147 | if (vps.getDefaultOutputLayerIdc() == 2 || addOutLsIdx >= 0 ) |
---|
2148 | { |
---|
2149 | for ( Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++) |
---|
2150 | { |
---|
2151 | vps.setOutputLayerFlag( olsIdx, i, ( olsIdx == 0 && i == 0 ) ? vps.inferOutputLayerFlag(olsIdx, i ) : false ); // This is a software only fix for a bug in the spec. In spec outputLayerFlag neither present nor inferred for this case ! |
---|
2152 | } |
---|
2153 | |
---|
2154 | std::vector<Int>& outLayerIdList = ( addOutLsIdx >= 0 ) ? m_layerIdsInAddOutputLayerSet[addOutLsIdx] : m_layerIdsInDefOutputLayerSet[olsIdx]; |
---|
2155 | |
---|
2156 | Bool outputLayerInLayerSetFlag = false; |
---|
2157 | for (Int j = 0; j < outLayerIdList.size(); j++) |
---|
2158 | { |
---|
2159 | for ( Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++) |
---|
2160 | { |
---|
2161 | if ( vps.getLayerSetLayerIdList( lsIdx, i ) == outLayerIdList[ j ] ) |
---|
2162 | { |
---|
2163 | vps.setOutputLayerFlag( olsIdx, i, true ); |
---|
2164 | outputLayerInLayerSetFlag = true; |
---|
2165 | break; |
---|
2166 | } |
---|
2167 | } |
---|
2168 | if ( !outputLayerInLayerSetFlag ) |
---|
2169 | { |
---|
2170 | fprintf(stderr, "Error: Output layer %d in output layer set %d not in corresponding layer set %d \n", outLayerIdList[ j ], olsIdx , lsIdx ); |
---|
2171 | exit(EXIT_FAILURE); |
---|
2172 | } |
---|
2173 | } |
---|
2174 | } |
---|
2175 | else |
---|
2176 | { |
---|
2177 | for ( Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++) |
---|
2178 | { |
---|
2179 | vps.setOutputLayerFlag( olsIdx, i, vps.inferOutputLayerFlag( olsIdx, i ) ); |
---|
2180 | } |
---|
2181 | } |
---|
2182 | |
---|
2183 | vps.deriveNecessaryLayerFlags( olsIdx ); |
---|
2184 | vps.deriveTargetLayerIdList( olsIdx ); |
---|
2185 | |
---|
2186 | // SET profile_tier_level_index. |
---|
2187 | if ( olsIdx == 0 ) |
---|
2188 | { |
---|
2189 | vps.setProfileTierLevelIdx( 0, 0 , vps.getMaxLayersMinus1() > 0 ? 1 : 0 ); |
---|
2190 | } |
---|
2191 | else |
---|
2192 | { |
---|
2193 | if( (Int) m_profileTierLevelIdx[ olsIdx ].size() < vps.getNumLayersInIdList( lsIdx ) ) |
---|
2194 | { |
---|
2195 | fprintf( stderr, "Warning: Not enough profileTierLevelIdx values given for the %d-th OLS. Inferring default values.\n", olsIdx ); |
---|
2196 | } |
---|
2197 | for (Int j = 0; j < vps.getNumLayersInIdList( lsIdx ); j++) |
---|
2198 | { |
---|
2199 | if( j < (Int) m_profileTierLevelIdx[ olsIdx ].size() ) |
---|
2200 | { |
---|
2201 | vps.setProfileTierLevelIdx(olsIdx, j, m_profileTierLevelIdx[olsIdx][j] ); |
---|
2202 | if( !vps.getNecessaryLayerFlag(olsIdx,j) && m_profileTierLevelIdx[ olsIdx ][ j ] != -1 ) |
---|
2203 | { |
---|
2204 | fprintf( stderr, "Warning: The %d-th layer in the %d-th OLS is not necessary such that profileTierLevelIdx[%d][%d] will be ignored. Set value to -1 to suppress warning.\n", j,olsIdx,olsIdx,j ); |
---|
2205 | } |
---|
2206 | } |
---|
2207 | else if ( vps.getNecessaryLayerFlag(olsIdx,j) ) |
---|
2208 | { |
---|
2209 | // setting default values |
---|
2210 | if ( j == 0 || vps.getVpsNumProfileTierLevelMinus1() < 1 ) |
---|
2211 | { |
---|
2212 | // set base layer as default |
---|
2213 | vps.setProfileTierLevelIdx(olsIdx, j, 1 ); |
---|
2214 | } |
---|
2215 | else |
---|
2216 | { |
---|
2217 | // set VpsProfileTierLevel[2] as default |
---|
2218 | vps.setProfileTierLevelIdx(olsIdx, j, 2 ); |
---|
2219 | } |
---|
2220 | } |
---|
2221 | } |
---|
2222 | } |
---|
2223 | |
---|
2224 | if ( vps.getNumOutputLayersInOutputLayerSet( olsIdx ) == 1 && |
---|
2225 | vps.getNumDirectRefLayers( vps.getOlsHighestOutputLayerId( olsIdx ) ) ) |
---|
2226 | { |
---|
2227 | vps.setAltOutputLayerFlag( olsIdx , m_altOutputLayerFlag[ olsIdx ]); |
---|
2228 | } |
---|
2229 | else |
---|
2230 | { |
---|
2231 | vps.setAltOutputLayerFlag( olsIdx , false ); |
---|
2232 | if ( m_altOutputLayerFlag[ olsIdx ] ) |
---|
2233 | { |
---|
2234 | printf( "\nWarning: Ignoring AltOutputLayerFlag for output layer set %d, since more than one output layer or no dependent layers.\n", olsIdx ); |
---|
2235 | } |
---|
2236 | } |
---|
2237 | } |
---|
2238 | } |
---|
2239 | |
---|
2240 | Void TAppEncTop::xSetVPSVUI( TComVPS& vps ) |
---|
2241 | { |
---|
2242 | vps.setVpsVuiPresentFlag( m_vpsVuiPresentFlag ); |
---|
2243 | |
---|
2244 | TComVPSVUI vpsVui; |
---|
2245 | vpsVui.init(vps.getNumAddLayerSets(),vps.getMaxSubLayersMinus1() + 1, vps.getMaxLayersMinus1() + 1 ); |
---|
2246 | |
---|
2247 | if ( m_vpsVuiPresentFlag ) |
---|
2248 | { |
---|
2249 | // All this stuff could actually be derived by the encoder, |
---|
2250 | // however preliminary setting it from input parameters |
---|
2251 | |
---|
2252 | vpsVui.setCrossLayerPicTypeAlignedFlag( m_crossLayerPicTypeAlignedFlag ); |
---|
2253 | vpsVui.setCrossLayerIrapAlignedFlag ( m_crossLayerIrapAlignedFlag ); |
---|
2254 | vpsVui.setAllLayersIdrAlignedFlag ( m_allLayersIdrAlignedFlag ); |
---|
2255 | vpsVui.setBitRatePresentVpsFlag( m_bitRatePresentVpsFlag ); |
---|
2256 | vpsVui.setPicRatePresentVpsFlag( m_picRatePresentVpsFlag ); |
---|
2257 | |
---|
2258 | if( vpsVui.getBitRatePresentVpsFlag( ) || vpsVui.getPicRatePresentVpsFlag( ) ) |
---|
2259 | { |
---|
2260 | for( Int i = 0; i < vps.getNumLayerSets(); i++ ) |
---|
2261 | { |
---|
2262 | for( Int j = 0; j <= vps.getMaxTLayers(); j++ ) |
---|
2263 | { |
---|
2264 | if( vpsVui.getBitRatePresentVpsFlag( ) && m_bitRatePresentFlag[i].size() > j ) |
---|
2265 | { |
---|
2266 | vpsVui.setBitRatePresentFlag( i, j, m_bitRatePresentFlag[i][j] ); |
---|
2267 | } |
---|
2268 | if( vpsVui.getPicRatePresentVpsFlag( ) && m_picRatePresentFlag[i].size() > j ) |
---|
2269 | { |
---|
2270 | vpsVui.setPicRatePresentFlag( i, j, m_picRatePresentFlag[i][j] ); |
---|
2271 | } |
---|
2272 | if( vpsVui.getBitRatePresentFlag( i, j ) && m_avgBitRate[i].size() > j ) |
---|
2273 | { |
---|
2274 | vpsVui.setAvgBitRate( i, j, m_avgBitRate[i][j] ); |
---|
2275 | } |
---|
2276 | if( vpsVui.getBitRatePresentFlag( i, j ) && m_maxBitRate[i].size() > j ) |
---|
2277 | { |
---|
2278 | vpsVui.setMaxBitRate( i, j, m_maxBitRate[i][j] ); |
---|
2279 | } |
---|
2280 | if( vpsVui.getPicRatePresentFlag( i, j ) && m_constantPicRateIdc[i].size() > j ) |
---|
2281 | { |
---|
2282 | vpsVui.setConstantPicRateIdc( i, j, m_constantPicRateIdc[i][j] ); |
---|
2283 | } |
---|
2284 | if( vpsVui.getPicRatePresentFlag( i, j ) && m_avgPicRate[i].size() > j ) |
---|
2285 | { |
---|
2286 | vpsVui.setAvgPicRate( i, j, m_avgPicRate[i][j] ); |
---|
2287 | } |
---|
2288 | } |
---|
2289 | } |
---|
2290 | } |
---|
2291 | |
---|
2292 | vpsVui.setTilesNotInUseFlag( m_tilesNotInUseFlag ); |
---|
2293 | |
---|
2294 | if( !vpsVui.getTilesNotInUseFlag() ) |
---|
2295 | { |
---|
2296 | for( Int i = 0; i <= vps.getMaxLayersMinus1(); i++ ) |
---|
2297 | { |
---|
2298 | vpsVui.setTilesInUseFlag( i, m_tilesInUseFlag[ i ] ); |
---|
2299 | if( vpsVui.getTilesInUseFlag( i ) ) |
---|
2300 | { |
---|
2301 | vpsVui.setLoopFilterNotAcrossTilesFlag( i, m_loopFilterNotAcrossTilesFlag[ i ] ); |
---|
2302 | } |
---|
2303 | } |
---|
2304 | |
---|
2305 | for( Int i = 1; i <= vps.getMaxLayersMinus1(); i++ ) |
---|
2306 | { |
---|
2307 | for( Int j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ) ; j++ ) |
---|
2308 | { |
---|
2309 | Int layerIdx = vps.getLayerIdInVps( vps.getIdDirectRefLayer(vps.getLayerIdInNuh( i ) , j )); |
---|
2310 | if( vpsVui.getTilesInUseFlag( i ) && vpsVui.getTilesInUseFlag( layerIdx ) ) |
---|
2311 | { |
---|
2312 | vpsVui.setTileBoundariesAlignedFlag( i, j, m_tileBoundariesAlignedFlag[i][j] ); |
---|
2313 | } |
---|
2314 | } |
---|
2315 | } |
---|
2316 | } |
---|
2317 | |
---|
2318 | vpsVui.setWppNotInUseFlag( m_wppNotInUseFlag ); |
---|
2319 | |
---|
2320 | if( !vpsVui.getWppNotInUseFlag( ) ) |
---|
2321 | { |
---|
2322 | for( Int i = 1; i <= vps.getMaxLayersMinus1(); i++ ) |
---|
2323 | { |
---|
2324 | vpsVui.setWppInUseFlag( i, m_wppInUseFlag[ i ]); |
---|
2325 | } |
---|
2326 | } |
---|
2327 | |
---|
2328 | vpsVui.setSingleLayerForNonIrapFlag( m_singleLayerForNonIrapFlag ); |
---|
2329 | vpsVui.setHigherLayerIrapSkipFlag( m_higherLayerIrapSkipFlag ); |
---|
2330 | |
---|
2331 | vpsVui.setIlpRestrictedRefLayersFlag( m_ilpRestrictedRefLayersFlag ); |
---|
2332 | |
---|
2333 | if( vpsVui.getIlpRestrictedRefLayersFlag( ) ) |
---|
2334 | { |
---|
2335 | for( Int i = 1; i <= vps.getMaxLayersMinus1(); i++ ) |
---|
2336 | { |
---|
2337 | for( Int j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ); j++ ) |
---|
2338 | { |
---|
2339 | if ( m_minSpatialSegmentOffsetPlus1[i].size() > j ) |
---|
2340 | { |
---|
2341 | vpsVui.setMinSpatialSegmentOffsetPlus1( i, j, m_minSpatialSegmentOffsetPlus1[i][j] ); |
---|
2342 | } |
---|
2343 | if( vpsVui.getMinSpatialSegmentOffsetPlus1( i, j ) > 0 ) |
---|
2344 | { |
---|
2345 | if ( m_ctuBasedOffsetEnabledFlag[i].size() > j ) |
---|
2346 | { |
---|
2347 | vpsVui.setCtuBasedOffsetEnabledFlag( i, j, m_ctuBasedOffsetEnabledFlag[i][j] ); |
---|
2348 | } |
---|
2349 | if( vpsVui.getCtuBasedOffsetEnabledFlag( i, j ) ) |
---|
2350 | { |
---|
2351 | if ( m_minHorizontalCtuOffsetPlus1[i].size() > j ) |
---|
2352 | { |
---|
2353 | vpsVui.setMinHorizontalCtuOffsetPlus1( i, j, m_minHorizontalCtuOffsetPlus1[i][j] ); |
---|
2354 | } |
---|
2355 | } |
---|
2356 | } |
---|
2357 | } |
---|
2358 | } |
---|
2359 | } |
---|
2360 | vpsVui.setVideoSignalInfoIdxPresentFlag( true ); |
---|
2361 | vpsVui.setVpsNumVideoSignalInfoMinus1 ( 0 ); |
---|
2362 | |
---|
2363 | std::vector<TComVideoSignalInfo> videoSignalInfos; |
---|
2364 | videoSignalInfos.resize( vpsVui.getVpsNumVideoSignalInfoMinus1() + 1 ); |
---|
2365 | |
---|
2366 | videoSignalInfos[0].setColourPrimariesVps ( m_colourPrimaries ); |
---|
2367 | videoSignalInfos[0].setMatrixCoeffsVps ( m_matrixCoefficients ); |
---|
2368 | videoSignalInfos[0].setTransferCharacteristicsVps( m_transferCharacteristics ); |
---|
2369 | videoSignalInfos[0].setVideoVpsFormat ( m_videoFormat ); |
---|
2370 | videoSignalInfos[0].setVideoFullRangeVpsFlag ( m_videoFullRangeFlag ); |
---|
2371 | |
---|
2372 | vpsVui.setVideoSignalInfo( videoSignalInfos ); |
---|
2373 | |
---|
2374 | for (Int i = 0; i < m_numberOfLayers; i++) |
---|
2375 | { |
---|
2376 | vpsVui.setVpsVideoSignalInfoIdx( i, 0 ); |
---|
2377 | } |
---|
2378 | vpsVui.setVpsVuiBspHrdPresentFlag( false ); // TBD |
---|
2379 | } |
---|
2380 | else |
---|
2381 | { |
---|
2382 | //Default inference when not present. |
---|
2383 | vpsVui.setCrossLayerIrapAlignedFlag ( false ); |
---|
2384 | } |
---|
2385 | vps.setVPSVUI( vpsVui ); |
---|
2386 | } |
---|
2387 | |
---|
2388 | #if NH_3D |
---|
2389 | Void TAppEncTop::xSetCamPara ( TComVPS& vps ) |
---|
2390 | { |
---|
2391 | vps.setCpPrecision( m_cCameraData.getCamParsCodedPrecision()); |
---|
2392 | |
---|
2393 | for ( Int n = 1; n < vps.getNumViews(); n++ ) |
---|
2394 | { |
---|
2395 | Int i = vps.getViewOIdxList( n ); |
---|
2396 | Int iInVps = vps.getVoiInVps ( i ); |
---|
2397 | vps.setNumCp( iInVps, n); |
---|
2398 | |
---|
2399 | if ( vps.getNumCp( iInVps ) > 0 ) |
---|
2400 | { |
---|
2401 | vps.setCpInSliceSegmentHeaderFlag( iInVps, m_cCameraData.getVaryingCameraParameters() ); |
---|
2402 | |
---|
2403 | for( Int m = 0; m < vps.getNumCp( iInVps ); m++ ) |
---|
2404 | { |
---|
2405 | vps.setCpRefVoi( iInVps, m, vps.getViewOIdxList( m ) ); |
---|
2406 | if( !vps.getCpInSliceSegmentHeaderFlag( iInVps ) ) |
---|
2407 | { |
---|
2408 | Int j = vps.getCpRefVoi( iInVps, m ); |
---|
2409 | Int jInVps = vps.getVoiInVps( j ); |
---|
2410 | |
---|
2411 | vps.setVpsCpScale ( iInVps, jInVps, m_cCameraData.getCodedScale() [ jInVps ][ iInVps ] ) ; |
---|
2412 | vps.setVpsCpInvScale( iInVps, jInVps, m_cCameraData.getCodedScale() [ iInVps ][ jInVps ] ) ; |
---|
2413 | vps.setVpsCpOff ( iInVps, jInVps, m_cCameraData.getCodedOffset()[ jInVps ][ iInVps ] ) ; |
---|
2414 | vps.setVpsCpInvOff ( iInVps, jInVps, m_cCameraData.getCodedOffset()[ iInVps ][ jInVps ] ) ; |
---|
2415 | } |
---|
2416 | } |
---|
2417 | } |
---|
2418 | } |
---|
2419 | vps.deriveCpPresentFlag(); |
---|
2420 | } |
---|
2421 | #endif |
---|
2422 | |
---|
2423 | |
---|
2424 | Bool TAppEncTop::xLayerIdInTargetEncLayerIdList(Int nuhLayerId) |
---|
2425 | { |
---|
2426 | return ( std::find(m_targetEncLayerIdList.begin(), m_targetEncLayerIdList.end(), nuhLayerId) != m_targetEncLayerIdList.end()) ; |
---|
2427 | } |
---|
2428 | |
---|
2429 | |
---|
2430 | #endif |
---|
2431 | |
---|
2432 | |
---|
2433 | #if NH_3D_DLT |
---|
2434 | Void TAppEncTop::xDeriveDltArray( TComVPS& vps, TComDLT* dlt ) |
---|
2435 | { |
---|
2436 | Int iNumDepthViews = 0; |
---|
2437 | Bool bDltPresentFlag = false; |
---|
2438 | |
---|
2439 | for ( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ ) |
---|
2440 | { |
---|
2441 | Bool isDepth = ( vps.getDepthId( layer ) == 1 ); |
---|
2442 | |
---|
2443 | if ( isDepth ) |
---|
2444 | { |
---|
2445 | iNumDepthViews++; |
---|
2446 | } |
---|
2447 | |
---|
2448 | dlt->setUseDLTFlag( layer , isDepth && m_useDLT ); |
---|
2449 | if( dlt->getUseDLTFlag( layer ) ) |
---|
2450 | { |
---|
2451 | xAnalyzeInputBaseDepth(layer, max(m_iIntraPeriod[layer], 24), &vps, dlt); |
---|
2452 | bDltPresentFlag = bDltPresentFlag || dlt->getUseDLTFlag(layer); |
---|
2453 | dlt->setInterViewDltPredEnableFlag(layer, (dlt->getUseDLTFlag(layer) && (layer>1))); |
---|
2454 | |
---|
2455 | // ----------------------------- determine whether to use bit-map ----------------------------- |
---|
2456 | Bool bDltBitMapRepFlag = false; |
---|
2457 | UInt uiNumBitsNonBitMap = 0; |
---|
2458 | UInt uiNumBitsBitMap = 0; |
---|
2459 | |
---|
2460 | UInt uiMaxDiff = 0; |
---|
2461 | UInt uiMinDiff = MAX_INT; |
---|
2462 | UInt uiLengthMinDiff = 0; |
---|
2463 | UInt uiLengthDltDiffMinusMin = 0; |
---|
2464 | |
---|
2465 | std::vector<Int> aiIdx2DepthValue_coded(256, 0); |
---|
2466 | UInt uiNumDepthValues_coded = 0; |
---|
2467 | |
---|
2468 | uiNumDepthValues_coded = dlt->getNumDepthValues(layer); |
---|
2469 | for( UInt ui = 0; ui<uiNumDepthValues_coded; ui++ ) |
---|
2470 | { |
---|
2471 | aiIdx2DepthValue_coded[ui] = dlt->idx2DepthValue(layer, ui); |
---|
2472 | } |
---|
2473 | |
---|
2474 | if( dlt->getInterViewDltPredEnableFlag( layer ) ) |
---|
2475 | { |
---|
2476 | AOF( vps.getDepthId( 1 ) == 1 ); |
---|
2477 | AOF( layer > 1 ); |
---|
2478 | // assumes ref layer id to be 1 |
---|
2479 | std::vector<Int> piRefDLT = dlt->idx2DepthValue( 1 ); |
---|
2480 | UInt uiRefNum = dlt->getNumDepthValues( 1 ); |
---|
2481 | dlt->getDeltaDLT(layer, piRefDLT, uiRefNum, aiIdx2DepthValue_coded, uiNumDepthValues_coded); |
---|
2482 | } |
---|
2483 | |
---|
2484 | std::vector<UInt> puiDltDiffValues(uiNumDepthValues_coded, 0); |
---|
2485 | |
---|
2486 | for (UInt d = 1; d < uiNumDepthValues_coded; d++) |
---|
2487 | { |
---|
2488 | puiDltDiffValues[d] = aiIdx2DepthValue_coded[d] - aiIdx2DepthValue_coded[d-1]; |
---|
2489 | |
---|
2490 | if ( uiMaxDiff < puiDltDiffValues[d] ) |
---|
2491 | { |
---|
2492 | uiMaxDiff = puiDltDiffValues[d]; |
---|
2493 | } |
---|
2494 | |
---|
2495 | if ( uiMinDiff > puiDltDiffValues[d] ) |
---|
2496 | { |
---|
2497 | uiMinDiff = puiDltDiffValues[d]; |
---|
2498 | } |
---|
2499 | } |
---|
2500 | |
---|
2501 | // counting bits |
---|
2502 | // diff coding branch |
---|
2503 | uiNumBitsNonBitMap += 8; // u(v) bits for num_depth_values_in_dlt[layerId] (i.e. num_entry[ layerId ]) |
---|
2504 | |
---|
2505 | if ( uiNumDepthValues_coded > 1 ) |
---|
2506 | { |
---|
2507 | uiNumBitsNonBitMap += 8; // u(v) bits for max_diff[ layerId ] |
---|
2508 | } |
---|
2509 | |
---|
2510 | if ( uiNumDepthValues_coded > 2 ) |
---|
2511 | { |
---|
2512 | uiLengthMinDiff = (UInt) gCeilLog2(uiMaxDiff + 1); |
---|
2513 | uiNumBitsNonBitMap += uiLengthMinDiff; // u(v) bits for min_diff[ layerId ] |
---|
2514 | } |
---|
2515 | |
---|
2516 | uiNumBitsNonBitMap += 8; // u(v) bits for dlt_depth_value0[ layerId ] |
---|
2517 | |
---|
2518 | if (uiMaxDiff > uiMinDiff) |
---|
2519 | { |
---|
2520 | uiLengthDltDiffMinusMin = (UInt) gCeilLog2(uiMaxDiff - uiMinDiff + 1); |
---|
2521 | uiNumBitsNonBitMap += uiLengthDltDiffMinusMin * (uiNumDepthValues_coded - 1); // u(v) bits for dlt_depth_value_diff_minus_min[ layerId ][ j ] |
---|
2522 | } |
---|
2523 | |
---|
2524 | // bit map branch |
---|
2525 | uiNumBitsBitMap = 1 << m_inputBitDepth[CHANNEL_TYPE_LUMA]; |
---|
2526 | |
---|
2527 | // determine bDltBitMapFlag |
---|
2528 | bDltBitMapRepFlag = (uiNumBitsBitMap > uiNumBitsNonBitMap) ? false : true; |
---|
2529 | |
---|
2530 | dlt->setUseBitmapRep(layer, bDltBitMapRepFlag); |
---|
2531 | } |
---|
2532 | } |
---|
2533 | |
---|
2534 | dlt->setDltPresentFlag( bDltPresentFlag ); |
---|
2535 | dlt->setNumDepthViews ( iNumDepthViews ); |
---|
2536 | dlt->setDepthViewBitDepth( m_inputBitDepth[CHANNEL_TYPE_LUMA] ); |
---|
2537 | } |
---|
2538 | #endif |
---|
2539 | //! \} |
---|