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-2014, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TAppEncTop.cpp |
---|
35 | \brief Encoder application class |
---|
36 | */ |
---|
37 | |
---|
38 | #include <list> |
---|
39 | #include <fstream> |
---|
40 | #include <stdlib.h> |
---|
41 | #include <stdio.h> |
---|
42 | #include <fcntl.h> |
---|
43 | #include <assert.h> |
---|
44 | |
---|
45 | #include "TAppEncTop.h" |
---|
46 | #include "TLibEncoder/AnnexBwrite.h" |
---|
47 | |
---|
48 | using namespace std; |
---|
49 | |
---|
50 | //! \ingroup TAppEncoder |
---|
51 | //! \{ |
---|
52 | |
---|
53 | // ==================================================================================================================== |
---|
54 | // Constructor / destructor / initialization / destroy |
---|
55 | // ==================================================================================================================== |
---|
56 | |
---|
57 | TAppEncTop::TAppEncTop() |
---|
58 | { |
---|
59 | |
---|
60 | #if H_MV |
---|
61 | m_vps = new TComVPS; |
---|
62 | #else |
---|
63 | m_iFrameRcvd = 0; |
---|
64 | #endif |
---|
65 | m_totalBytes = 0; |
---|
66 | m_essentialBytes = 0; |
---|
67 | } |
---|
68 | |
---|
69 | TAppEncTop::~TAppEncTop() |
---|
70 | { |
---|
71 | #if H_MV |
---|
72 | if (m_vps) |
---|
73 | { |
---|
74 | delete m_vps; |
---|
75 | }; |
---|
76 | #endif |
---|
77 | |
---|
78 | } |
---|
79 | |
---|
80 | Void TAppEncTop::xInitLibCfg() |
---|
81 | { |
---|
82 | #if H_MV |
---|
83 | TComVPS& vps = (*m_vps); |
---|
84 | #else |
---|
85 | TComVPS vps; |
---|
86 | #endif |
---|
87 | |
---|
88 | #if H_3D |
---|
89 | vps.createCamPars(m_iNumberOfViews); |
---|
90 | TComDLT& dlt = m_dlt; |
---|
91 | #endif |
---|
92 | |
---|
93 | #if H_MV |
---|
94 | Int maxTempLayer = -1; |
---|
95 | for (Int j = 0; j < m_numberOfLayers; j++) |
---|
96 | { |
---|
97 | maxTempLayer = max( m_maxTempLayerMvc[ j ], maxTempLayer ); |
---|
98 | } |
---|
99 | |
---|
100 | vps.setMaxTLayers ( maxTempLayer ); |
---|
101 | if ( maxTempLayer ) |
---|
102 | { |
---|
103 | vps.setTemporalNestingFlag(true); |
---|
104 | } |
---|
105 | vps.setMaxLayersMinus1( m_numberOfLayers - 1); |
---|
106 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
107 | { |
---|
108 | Int maxNumReOrderPics = 0; |
---|
109 | Int maxDecPicBuffering = 0; |
---|
110 | for (Int j = 0; j < m_numberOfLayers; j++) |
---|
111 | { |
---|
112 | maxNumReOrderPics = max( maxNumReOrderPics, m_numReorderPicsMvc [ j ][ i ] ); |
---|
113 | maxDecPicBuffering = max( maxDecPicBuffering, m_maxDecPicBufferingMvc[ j ][ i ] ); |
---|
114 | } |
---|
115 | |
---|
116 | vps.setNumReorderPics ( maxNumReOrderPics ,i ); |
---|
117 | vps.setMaxDecPicBuffering ( maxDecPicBuffering ,i ); |
---|
118 | } |
---|
119 | #else |
---|
120 | vps.setMaxTLayers ( m_maxTempLayer ); |
---|
121 | if (m_maxTempLayer == 1) |
---|
122 | { |
---|
123 | vps.setTemporalNestingFlag(true); |
---|
124 | } |
---|
125 | vps.setMaxLayers ( 1 ); |
---|
126 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
127 | { |
---|
128 | vps.setNumReorderPics ( m_numReorderPics[i], i ); |
---|
129 | vps.setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i ); |
---|
130 | } |
---|
131 | #endif |
---|
132 | #if H_MV |
---|
133 | xSetLayerIds ( vps ); |
---|
134 | xSetDimensionIdAndLength ( vps ); |
---|
135 | xSetDependencies( vps ); |
---|
136 | xSetProfileTierLevel ( vps ); |
---|
137 | xSetRepFormat ( vps ); |
---|
138 | xSetLayerSets ( vps ); |
---|
139 | xSetDpbSize ( vps ); |
---|
140 | xSetVPSVUI ( vps ); |
---|
141 | #if H_3D |
---|
142 | xSetVPSExtension2 ( vps ); |
---|
143 | m_ivPicLists.setVPS ( &vps ); |
---|
144 | xDeriveDltArray ( vps, dlt ); |
---|
145 | #endif |
---|
146 | |
---|
147 | |
---|
148 | for(Int layerIdInVps = 0; layerIdInVps < m_numberOfLayers; layerIdInVps++) |
---|
149 | { |
---|
150 | m_frameRcvd .push_back(0); |
---|
151 | m_acTEncTopList .push_back(new TEncTop); |
---|
152 | m_acTVideoIOYuvInputFileList.push_back(new TVideoIOYuv); |
---|
153 | m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv); |
---|
154 | m_picYuvRec .push_back(new TComList<TComPicYuv*>) ; |
---|
155 | m_ivPicLists.push_back( m_acTEncTopList[ layerIdInVps ]->getListPic() ); |
---|
156 | TEncTop& m_cTEncTop = *m_acTEncTopList[ layerIdInVps ]; // It is not a member, but this name helps avoiding code duplication !!! |
---|
157 | |
---|
158 | Int layerId = vps.getLayerIdInNuh( layerIdInVps ); |
---|
159 | m_cTEncTop.setLayerIdInVps ( layerIdInVps ); |
---|
160 | m_cTEncTop.setLayerId ( layerId ); |
---|
161 | m_cTEncTop.setViewId ( vps.getViewId ( layerId ) ); |
---|
162 | m_cTEncTop.setViewIndex ( vps.getViewIndex ( layerId ) ); |
---|
163 | #if H_3D |
---|
164 | Bool isDepth = ( vps.getDepthId ( layerId ) != 0 ) ; |
---|
165 | m_cTEncTop.setIsDepth ( isDepth ); |
---|
166 | //====== Camera Parameters ========= |
---|
167 | m_cTEncTop.setCameraParameters ( &m_cCameraData ); |
---|
168 | m_cTEncTop.setCamParPrecision ( m_cCameraData.getCamParsCodedPrecision () ); |
---|
169 | m_cTEncTop.setCamParInSliceHeader ( m_cCameraData.getVaryingCameraParameters() ); |
---|
170 | m_cTEncTop.setCodedScale ( m_cCameraData.getCodedScale () ); |
---|
171 | m_cTEncTop.setCodedOffset ( m_cCameraData.getCodedOffset () ); |
---|
172 | #if H_3D_VSO |
---|
173 | //====== VSO ========= |
---|
174 | m_cTEncTop.setRenderModelParameters ( &m_cRenModStrParser ); |
---|
175 | m_cTEncTop.setForceLambdaScaleVSO ( isDepth ? m_bForceLambdaScaleVSO : false ); |
---|
176 | m_cTEncTop.setLambdaScaleVSO ( isDepth ? m_dLambdaScaleVSO : 1 ); |
---|
177 | m_cTEncTop.setVSOMode ( isDepth ? m_uiVSOMode : 0 ); |
---|
178 | |
---|
179 | m_cTEncTop.setAllowNegDist ( isDepth ? m_bAllowNegDist : false ); |
---|
180 | |
---|
181 | // SAIT_VSO_EST_A0033 |
---|
182 | m_cTEncTop.setUseEstimatedVSD ( isDepth ? m_bUseEstimatedVSD : false ); |
---|
183 | |
---|
184 | // LGE_WVSO_A0119 |
---|
185 | m_cTEncTop.setUseWVSO ( isDepth ? m_bUseWVSO : false ); |
---|
186 | m_cTEncTop.setVSOWeight ( isDepth ? m_iVSOWeight : 0 ); |
---|
187 | m_cTEncTop.setVSDWeight ( isDepth ? m_iVSDWeight : 0 ); |
---|
188 | m_cTEncTop.setDWeight ( isDepth ? m_iDWeight : 0 ); |
---|
189 | #endif // H_3D_VSO |
---|
190 | #if H_3D_SPIVMP |
---|
191 | m_cTEncTop.setSubPULog2Size (( isDepth || 0==layerIdInVps ) ? 0 : m_iSubPULog2Size ); |
---|
192 | m_cTEncTop.setSubPUMPILog2Size ( !isDepth ? 0 : m_iSubPUMPILog2Size ); |
---|
193 | #endif |
---|
194 | #if H_3D_IC |
---|
195 | m_cTEncTop.setUseIC ( vps.getViewIndex( layerId ) == 0 || isDepth ? false : m_abUseIC ); |
---|
196 | m_cTEncTop.setUseICLowLatencyEnc ( m_bUseLowLatencyICEnc ); |
---|
197 | #endif |
---|
198 | //========== Depth intra modes ========== |
---|
199 | #if H_3D_DIM |
---|
200 | m_cTEncTop.setUseDMM ( isDepth ? m_useDMM : false ); |
---|
201 | m_cTEncTop.setUseSDC ( isDepth ? m_useSDC : false ); |
---|
202 | m_cTEncTop.setUseDLT ( isDepth ? m_useDLT : false ); |
---|
203 | #endif |
---|
204 | #if H_3D_QTLPC |
---|
205 | m_cTEncTop.setUseQTL ( isDepth ? m_bUseQTL : false ); |
---|
206 | m_cTEncTop.setUsePC ( isDepth ? m_bUsePC : false ); |
---|
207 | #endif |
---|
208 | //====== Depth Inter SDC ========= |
---|
209 | #if H_3D_INTER_SDC |
---|
210 | m_cTEncTop.setInterSDCEnable ( isDepth ? m_bDepthInterSDCFlag : false ); |
---|
211 | #endif |
---|
212 | #if H_3D_DBBP |
---|
213 | m_cTEncTop.setUseDBBP ( vps.getViewIndex( layerId ) == 0 || isDepth ? false : m_bUseDBBP ); |
---|
214 | #endif |
---|
215 | #if H_3D_IV_MERGE |
---|
216 | m_cTEncTop.setUseMPI ( isDepth ? m_bMPIFlag : false ); |
---|
217 | #endif |
---|
218 | #endif // H_3D |
---|
219 | |
---|
220 | m_cTEncTop.setIvPicLists ( &m_ivPicLists ); |
---|
221 | #endif // H_MV |
---|
222 | m_cTEncTop.setVPS(&vps); |
---|
223 | |
---|
224 | #if H_3D |
---|
225 | m_cTEncTop.setDLT(&dlt); |
---|
226 | #endif |
---|
227 | |
---|
228 | m_cTEncTop.setProfile(m_profile); |
---|
229 | m_cTEncTop.setLevel(m_levelTier, m_level); |
---|
230 | m_cTEncTop.setProgressiveSourceFlag(m_progressiveSourceFlag); |
---|
231 | m_cTEncTop.setInterlacedSourceFlag(m_interlacedSourceFlag); |
---|
232 | m_cTEncTop.setNonPackedConstraintFlag(m_nonPackedConstraintFlag); |
---|
233 | m_cTEncTop.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag); |
---|
234 | |
---|
235 | m_cTEncTop.setFrameRate ( m_iFrameRate ); |
---|
236 | m_cTEncTop.setFrameSkip ( m_FrameSkip ); |
---|
237 | m_cTEncTop.setSourceWidth ( m_iSourceWidth ); |
---|
238 | m_cTEncTop.setSourceHeight ( m_iSourceHeight ); |
---|
239 | m_cTEncTop.setConformanceWindow ( m_confLeft, m_confRight, m_confTop, m_confBottom ); |
---|
240 | m_cTEncTop.setFramesToBeEncoded ( m_framesToBeEncoded ); |
---|
241 | |
---|
242 | //====== Coding Structure ======== |
---|
243 | #if H_MV |
---|
244 | m_cTEncTop.setIntraPeriod ( m_iIntraPeriod[ layerIdInVps ] ); |
---|
245 | #else |
---|
246 | m_cTEncTop.setIntraPeriod ( m_iIntraPeriod ); |
---|
247 | #endif |
---|
248 | m_cTEncTop.setDecodingRefreshType ( m_iDecodingRefreshType ); |
---|
249 | m_cTEncTop.setGOPSize ( m_iGOPSize ); |
---|
250 | #if H_MV |
---|
251 | m_cTEncTop.setGopList ( m_GOPListMvc[layerIdInVps] ); |
---|
252 | m_cTEncTop.setExtraRPSs ( m_extraRPSsMvc[layerIdInVps] ); |
---|
253 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
254 | { |
---|
255 | m_cTEncTop.setNumReorderPics ( m_numReorderPicsMvc[layerIdInVps][i], i ); |
---|
256 | m_cTEncTop.setMaxDecPicBuffering ( m_maxDecPicBufferingMvc[layerIdInVps][i], i ); |
---|
257 | } |
---|
258 | #else |
---|
259 | m_cTEncTop.setGopList ( m_GOPList ); |
---|
260 | m_cTEncTop.setExtraRPSs ( m_extraRPSs ); |
---|
261 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
262 | { |
---|
263 | m_cTEncTop.setNumReorderPics ( m_numReorderPics[i], i ); |
---|
264 | m_cTEncTop.setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i ); |
---|
265 | } |
---|
266 | #endif |
---|
267 | for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop ) |
---|
268 | { |
---|
269 | m_cTEncTop.setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] ); |
---|
270 | } |
---|
271 | #if H_MV |
---|
272 | m_cTEncTop.setQP ( m_iQP[layerIdInVps] ); |
---|
273 | #else |
---|
274 | m_cTEncTop.setQP ( m_iQP ); |
---|
275 | #endif |
---|
276 | |
---|
277 | m_cTEncTop.setPad ( m_aiPad ); |
---|
278 | |
---|
279 | #if H_MV |
---|
280 | m_cTEncTop.setMaxTempLayer ( m_maxTempLayerMvc[layerIdInVps] ); |
---|
281 | #else |
---|
282 | m_cTEncTop.setMaxTempLayer ( m_maxTempLayer ); |
---|
283 | #endif |
---|
284 | m_cTEncTop.setUseAMP( m_enableAMP ); |
---|
285 | |
---|
286 | //===== Slice ======== |
---|
287 | |
---|
288 | //====== Loop/Deblock Filter ======== |
---|
289 | #if H_MV |
---|
290 | m_cTEncTop.setLoopFilterDisable ( m_bLoopFilterDisable[layerIdInVps]); |
---|
291 | #else |
---|
292 | m_cTEncTop.setLoopFilterDisable ( m_bLoopFilterDisable ); |
---|
293 | #endif |
---|
294 | m_cTEncTop.setLoopFilterOffsetInPPS ( m_loopFilterOffsetInPPS ); |
---|
295 | m_cTEncTop.setLoopFilterBetaOffset ( m_loopFilterBetaOffsetDiv2 ); |
---|
296 | m_cTEncTop.setLoopFilterTcOffset ( m_loopFilterTcOffsetDiv2 ); |
---|
297 | m_cTEncTop.setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent); |
---|
298 | m_cTEncTop.setDeblockingFilterMetric ( m_DeblockingFilterMetric ); |
---|
299 | |
---|
300 | //====== Motion search ======== |
---|
301 | m_cTEncTop.setFastSearch ( m_iFastSearch ); |
---|
302 | m_cTEncTop.setSearchRange ( m_iSearchRange ); |
---|
303 | m_cTEncTop.setBipredSearchRange ( m_bipredSearchRange ); |
---|
304 | |
---|
305 | //====== Quality control ======== |
---|
306 | m_cTEncTop.setMaxDeltaQP ( m_iMaxDeltaQP ); |
---|
307 | m_cTEncTop.setMaxCuDQPDepth ( m_iMaxCuDQPDepth ); |
---|
308 | |
---|
309 | m_cTEncTop.setChromaCbQpOffset ( m_cbQpOffset ); |
---|
310 | m_cTEncTop.setChromaCrQpOffset ( m_crQpOffset ); |
---|
311 | |
---|
312 | #if ADAPTIVE_QP_SELECTION |
---|
313 | m_cTEncTop.setUseAdaptQpSelect ( m_bUseAdaptQpSelect ); |
---|
314 | #endif |
---|
315 | |
---|
316 | m_cTEncTop.setUseAdaptiveQP ( m_bUseAdaptiveQP ); |
---|
317 | m_cTEncTop.setQPAdaptationRange ( m_iQPAdaptationRange ); |
---|
318 | |
---|
319 | //====== Tool list ======== |
---|
320 | m_cTEncTop.setDeltaQpRD ( m_uiDeltaQpRD ); |
---|
321 | m_cTEncTop.setUseASR ( m_bUseASR ); |
---|
322 | m_cTEncTop.setUseHADME ( m_bUseHADME ); |
---|
323 | #if H_MV |
---|
324 | m_cTEncTop.setdQPs ( m_aidQP[layerIdInVps] ); |
---|
325 | #else |
---|
326 | m_cTEncTop.setdQPs ( m_aidQP ); |
---|
327 | #endif |
---|
328 | m_cTEncTop.setUseRDOQ ( m_useRDOQ ); |
---|
329 | m_cTEncTop.setUseRDOQTS ( m_useRDOQTS ); |
---|
330 | m_cTEncTop.setRDpenalty ( m_rdPenalty ); |
---|
331 | m_cTEncTop.setQuadtreeTULog2MaxSize ( m_uiQuadtreeTULog2MaxSize ); |
---|
332 | m_cTEncTop.setQuadtreeTULog2MinSize ( m_uiQuadtreeTULog2MinSize ); |
---|
333 | m_cTEncTop.setQuadtreeTUMaxDepthInter ( m_uiQuadtreeTUMaxDepthInter ); |
---|
334 | m_cTEncTop.setQuadtreeTUMaxDepthIntra ( m_uiQuadtreeTUMaxDepthIntra ); |
---|
335 | m_cTEncTop.setUseFastEnc ( m_bUseFastEnc ); |
---|
336 | m_cTEncTop.setUseEarlyCU ( m_bUseEarlyCU ); |
---|
337 | m_cTEncTop.setUseFastDecisionForMerge ( m_useFastDecisionForMerge ); |
---|
338 | m_cTEncTop.setUseCbfFastMode ( m_bUseCbfFastMode ); |
---|
339 | m_cTEncTop.setUseEarlySkipDetection ( m_useEarlySkipDetection ); |
---|
340 | |
---|
341 | m_cTEncTop.setUseTransformSkip ( m_useTransformSkip ); |
---|
342 | m_cTEncTop.setUseTransformSkipFast ( m_useTransformSkipFast ); |
---|
343 | m_cTEncTop.setUseConstrainedIntraPred ( m_bUseConstrainedIntraPred ); |
---|
344 | m_cTEncTop.setPCMLog2MinSize ( m_uiPCMLog2MinSize); |
---|
345 | m_cTEncTop.setUsePCM ( m_usePCM ); |
---|
346 | m_cTEncTop.setPCMLog2MaxSize ( m_pcmLog2MaxSize); |
---|
347 | m_cTEncTop.setMaxNumMergeCand ( m_maxNumMergeCand ); |
---|
348 | |
---|
349 | |
---|
350 | //====== Weighted Prediction ======== |
---|
351 | m_cTEncTop.setUseWP ( m_useWeightedPred ); |
---|
352 | m_cTEncTop.setWPBiPred ( m_useWeightedBiPred ); |
---|
353 | //====== Parallel Merge Estimation ======== |
---|
354 | m_cTEncTop.setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 ); |
---|
355 | |
---|
356 | //====== Slice ======== |
---|
357 | m_cTEncTop.setSliceMode ( m_sliceMode ); |
---|
358 | m_cTEncTop.setSliceArgument ( m_sliceArgument ); |
---|
359 | |
---|
360 | //====== Dependent Slice ======== |
---|
361 | m_cTEncTop.setSliceSegmentMode ( m_sliceSegmentMode ); |
---|
362 | m_cTEncTop.setSliceSegmentArgument ( m_sliceSegmentArgument ); |
---|
363 | Int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1); |
---|
364 | if(m_sliceSegmentMode==FIXED_NUMBER_OF_LCU) |
---|
365 | { |
---|
366 | m_cTEncTop.setSliceSegmentArgument ( m_sliceSegmentArgument * iNumPartInCU ); |
---|
367 | } |
---|
368 | if(m_sliceMode==FIXED_NUMBER_OF_LCU) |
---|
369 | { |
---|
370 | m_cTEncTop.setSliceArgument ( m_sliceArgument * iNumPartInCU ); |
---|
371 | } |
---|
372 | if(m_sliceMode==FIXED_NUMBER_OF_TILES) |
---|
373 | { |
---|
374 | m_cTEncTop.setSliceArgument ( m_sliceArgument ); |
---|
375 | } |
---|
376 | |
---|
377 | if(m_sliceMode == 0 ) |
---|
378 | { |
---|
379 | m_bLFCrossSliceBoundaryFlag = true; |
---|
380 | } |
---|
381 | m_cTEncTop.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
382 | #if H_MV |
---|
383 | m_cTEncTop.setUseSAO ( m_bUseSAO[layerIdInVps] ); |
---|
384 | #else |
---|
385 | m_cTEncTop.setUseSAO ( m_bUseSAO ); |
---|
386 | #endif |
---|
387 | m_cTEncTop.setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic); |
---|
388 | |
---|
389 | m_cTEncTop.setSaoLcuBoundary (m_saoLcuBoundary); |
---|
390 | m_cTEncTop.setPCMInputBitDepthFlag ( m_bPCMInputBitDepthFlag); |
---|
391 | m_cTEncTop.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag); |
---|
392 | |
---|
393 | m_cTEncTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
394 | m_cTEncTop.setRecoveryPointSEIEnabled( m_recoveryPointSEIEnabled ); |
---|
395 | m_cTEncTop.setBufferingPeriodSEIEnabled( m_bufferingPeriodSEIEnabled ); |
---|
396 | m_cTEncTop.setPictureTimingSEIEnabled( m_pictureTimingSEIEnabled ); |
---|
397 | m_cTEncTop.setToneMappingInfoSEIEnabled ( m_toneMappingInfoSEIEnabled ); |
---|
398 | m_cTEncTop.setTMISEIToneMapId ( m_toneMapId ); |
---|
399 | m_cTEncTop.setTMISEIToneMapCancelFlag ( m_toneMapCancelFlag ); |
---|
400 | m_cTEncTop.setTMISEIToneMapPersistenceFlag ( m_toneMapPersistenceFlag ); |
---|
401 | m_cTEncTop.setTMISEICodedDataBitDepth ( m_toneMapCodedDataBitDepth ); |
---|
402 | m_cTEncTop.setTMISEITargetBitDepth ( m_toneMapTargetBitDepth ); |
---|
403 | m_cTEncTop.setTMISEIModelID ( m_toneMapModelId ); |
---|
404 | m_cTEncTop.setTMISEIMinValue ( m_toneMapMinValue ); |
---|
405 | m_cTEncTop.setTMISEIMaxValue ( m_toneMapMaxValue ); |
---|
406 | m_cTEncTop.setTMISEISigmoidMidpoint ( m_sigmoidMidpoint ); |
---|
407 | m_cTEncTop.setTMISEISigmoidWidth ( m_sigmoidWidth ); |
---|
408 | m_cTEncTop.setTMISEIStartOfCodedInterva ( m_startOfCodedInterval ); |
---|
409 | m_cTEncTop.setTMISEINumPivots ( m_numPivots ); |
---|
410 | m_cTEncTop.setTMISEICodedPivotValue ( m_codedPivotValue ); |
---|
411 | m_cTEncTop.setTMISEITargetPivotValue ( m_targetPivotValue ); |
---|
412 | m_cTEncTop.setTMISEICameraIsoSpeedIdc ( m_cameraIsoSpeedIdc ); |
---|
413 | m_cTEncTop.setTMISEICameraIsoSpeedValue ( m_cameraIsoSpeedValue ); |
---|
414 | m_cTEncTop.setTMISEIExposureIndexIdc ( m_exposureIndexIdc ); |
---|
415 | m_cTEncTop.setTMISEIExposureIndexValue ( m_exposureIndexValue ); |
---|
416 | m_cTEncTop.setTMISEIExposureCompensationValueSignFlag ( m_exposureCompensationValueSignFlag ); |
---|
417 | m_cTEncTop.setTMISEIExposureCompensationValueNumerator ( m_exposureCompensationValueNumerator ); |
---|
418 | m_cTEncTop.setTMISEIExposureCompensationValueDenomIdc ( m_exposureCompensationValueDenomIdc ); |
---|
419 | m_cTEncTop.setTMISEIRefScreenLuminanceWhite ( m_refScreenLuminanceWhite ); |
---|
420 | m_cTEncTop.setTMISEIExtendedRangeWhiteLevel ( m_extendedRangeWhiteLevel ); |
---|
421 | m_cTEncTop.setTMISEINominalBlackLevelLumaCodeValue ( m_nominalBlackLevelLumaCodeValue ); |
---|
422 | m_cTEncTop.setTMISEINominalWhiteLevelLumaCodeValue ( m_nominalWhiteLevelLumaCodeValue ); |
---|
423 | m_cTEncTop.setTMISEIExtendedWhiteLevelLumaCodeValue ( m_extendedWhiteLevelLumaCodeValue ); |
---|
424 | m_cTEncTop.setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled ); |
---|
425 | m_cTEncTop.setFramePackingArrangementSEIType( m_framePackingSEIType ); |
---|
426 | m_cTEncTop.setFramePackingArrangementSEIId( m_framePackingSEIId ); |
---|
427 | m_cTEncTop.setFramePackingArrangementSEIQuincunx( m_framePackingSEIQuincunx ); |
---|
428 | m_cTEncTop.setFramePackingArrangementSEIInterpretation( m_framePackingSEIInterpretation ); |
---|
429 | m_cTEncTop.setDisplayOrientationSEIAngle( m_displayOrientationSEIAngle ); |
---|
430 | m_cTEncTop.setTemporalLevel0IndexSEIEnabled( m_temporalLevel0IndexSEIEnabled ); |
---|
431 | m_cTEncTop.setGradualDecodingRefreshInfoEnabled( m_gradualDecodingRefreshInfoEnabled ); |
---|
432 | m_cTEncTop.setDecodingUnitInfoSEIEnabled( m_decodingUnitInfoSEIEnabled ); |
---|
433 | m_cTEncTop.setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled ); |
---|
434 | m_cTEncTop.setScalableNestingSEIEnabled( m_scalableNestingSEIEnabled ); |
---|
435 | #if H_MV |
---|
436 | m_cTEncTop.setSubBitstreamPropSEIEnabled( m_subBistreamPropSEIEnabled ); |
---|
437 | if( m_subBistreamPropSEIEnabled ) |
---|
438 | { |
---|
439 | m_cTEncTop.setNumAdditionalSubStreams ( m_sbPropNumAdditionalSubStreams ); |
---|
440 | m_cTEncTop.setSubBitstreamMode ( m_sbPropSubBitstreamMode ); |
---|
441 | m_cTEncTop.setOutputLayerSetIdxToVps ( m_sbPropOutputLayerSetIdxToVps ); |
---|
442 | m_cTEncTop.setHighestSublayerId ( m_sbPropHighestSublayerId ); |
---|
443 | m_cTEncTop.setAvgBitRate ( m_sbPropAvgBitRate ); |
---|
444 | m_cTEncTop.setMaxBitRate ( m_sbPropMaxBitRate ); |
---|
445 | } |
---|
446 | #endif |
---|
447 | m_cTEncTop.setUniformSpacingIdr ( m_iUniformSpacingIdr ); |
---|
448 | m_cTEncTop.setNumColumnsMinus1 ( m_iNumColumnsMinus1 ); |
---|
449 | m_cTEncTop.setNumRowsMinus1 ( m_iNumRowsMinus1 ); |
---|
450 | if(m_iUniformSpacingIdr==0) |
---|
451 | { |
---|
452 | m_cTEncTop.setColumnWidth ( m_pColumnWidth ); |
---|
453 | m_cTEncTop.setRowHeight ( m_pRowHeight ); |
---|
454 | } |
---|
455 | m_cTEncTop.xCheckGSParameters(); |
---|
456 | Int uiTilesCount = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1); |
---|
457 | if(uiTilesCount == 1) |
---|
458 | { |
---|
459 | m_bLFCrossTileBoundaryFlag = true; |
---|
460 | } |
---|
461 | m_cTEncTop.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag ); |
---|
462 | m_cTEncTop.setWaveFrontSynchro ( m_iWaveFrontSynchro ); |
---|
463 | m_cTEncTop.setWaveFrontSubstreams ( m_iWaveFrontSubstreams ); |
---|
464 | m_cTEncTop.setTMVPModeId ( m_TMVPModeId ); |
---|
465 | m_cTEncTop.setUseScalingListId ( m_useScalingListId ); |
---|
466 | m_cTEncTop.setScalingListFile ( m_scalingListFile ); |
---|
467 | m_cTEncTop.setSignHideFlag(m_signHideFlag); |
---|
468 | #if KWU_RC_VIEWRC_E0227 || KWU_RC_MADPRED_E0227 |
---|
469 | if(!m_cTEncTop.getIsDepth()) //only for texture |
---|
470 | { |
---|
471 | m_cTEncTop.setUseRateCtrl ( m_RCEnableRateControl ); |
---|
472 | } |
---|
473 | else |
---|
474 | { |
---|
475 | m_cTEncTop.setUseRateCtrl ( 0 ); |
---|
476 | } |
---|
477 | #else |
---|
478 | m_cTEncTop.setUseRateCtrl ( m_RCEnableRateControl ); |
---|
479 | #endif |
---|
480 | #if !KWU_RC_VIEWRC_E0227 |
---|
481 | m_cTEncTop.setTargetBitrate ( m_RCTargetBitrate ); |
---|
482 | #endif |
---|
483 | m_cTEncTop.setKeepHierBit ( m_RCKeepHierarchicalBit ); |
---|
484 | m_cTEncTop.setLCULevelRC ( m_RCLCULevelRC ); |
---|
485 | m_cTEncTop.setUseLCUSeparateModel ( m_RCUseLCUSeparateModel ); |
---|
486 | m_cTEncTop.setInitialQP ( m_RCInitialQP ); |
---|
487 | m_cTEncTop.setForceIntraQP ( m_RCForceIntraQP ); |
---|
488 | #if KWU_RC_MADPRED_E0227 |
---|
489 | if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth()) |
---|
490 | { |
---|
491 | m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_depthMADPred : 0); |
---|
492 | if(m_cTEncTop.getUseDepthMADPred()) |
---|
493 | { |
---|
494 | m_cTEncTop.setCamParam(&m_cCameraData); |
---|
495 | } |
---|
496 | } |
---|
497 | #endif |
---|
498 | #if KWU_RC_VIEWRC_E0227 |
---|
499 | if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth()) |
---|
500 | { |
---|
501 | m_cTEncTop.setUseViewWiseRateCtrl(m_viewWiseRateCtrl); |
---|
502 | if(m_iNumberOfViews == 1) |
---|
503 | { |
---|
504 | if(m_viewWiseRateCtrl) |
---|
505 | { |
---|
506 | m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]); |
---|
507 | } |
---|
508 | else |
---|
509 | { |
---|
510 | m_cTEncTop.setTargetBitrate ( m_RCTargetBitrate ); |
---|
511 | } |
---|
512 | } |
---|
513 | else |
---|
514 | { |
---|
515 | if(m_viewWiseRateCtrl) |
---|
516 | { |
---|
517 | m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]); |
---|
518 | } |
---|
519 | else |
---|
520 | { |
---|
521 | if(m_iNumberOfViews == 2) |
---|
522 | { |
---|
523 | if(m_cTEncTop.getViewId() == 0) |
---|
524 | { |
---|
525 | m_cTEncTop.setTargetBitrate ( (m_RCTargetBitrate*80)/100 ); |
---|
526 | } |
---|
527 | else if(m_cTEncTop.getViewId() == 1) |
---|
528 | { |
---|
529 | m_cTEncTop.setTargetBitrate ( (m_RCTargetBitrate*20)/100 ); |
---|
530 | } |
---|
531 | } |
---|
532 | else if(m_iNumberOfViews == 3) |
---|
533 | { |
---|
534 | if(m_cTEncTop.getViewId() == 0) |
---|
535 | { |
---|
536 | m_cTEncTop.setTargetBitrate ( (m_RCTargetBitrate*66)/100 ); |
---|
537 | } |
---|
538 | else if(m_cTEncTop.getViewId() == 1) |
---|
539 | { |
---|
540 | m_cTEncTop.setTargetBitrate ( (m_RCTargetBitrate*17)/100 ); |
---|
541 | } |
---|
542 | else if(m_cTEncTop.getViewId() == 2) |
---|
543 | { |
---|
544 | m_cTEncTop.setTargetBitrate ( (m_RCTargetBitrate*17)/100 ); |
---|
545 | } |
---|
546 | } |
---|
547 | else |
---|
548 | { |
---|
549 | m_cTEncTop.setTargetBitrate ( m_RCTargetBitrate ); |
---|
550 | } |
---|
551 | } |
---|
552 | } |
---|
553 | } |
---|
554 | #endif |
---|
555 | m_cTEncTop.setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag); |
---|
556 | m_cTEncTop.setCUTransquantBypassFlagForceValue(m_CUTransquantBypassFlagForce); |
---|
557 | m_cTEncTop.setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda ); |
---|
558 | m_cTEncTop.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing ); |
---|
559 | m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); |
---|
560 | m_cTEncTop.setVuiParametersPresentFlag( m_vuiParametersPresentFlag ); |
---|
561 | m_cTEncTop.setAspectRatioIdc( m_aspectRatioIdc ); |
---|
562 | m_cTEncTop.setSarWidth( m_sarWidth ); |
---|
563 | m_cTEncTop.setSarHeight( m_sarHeight ); |
---|
564 | m_cTEncTop.setOverscanInfoPresentFlag( m_overscanInfoPresentFlag ); |
---|
565 | m_cTEncTop.setOverscanAppropriateFlag( m_overscanAppropriateFlag ); |
---|
566 | m_cTEncTop.setVideoSignalTypePresentFlag( m_videoSignalTypePresentFlag ); |
---|
567 | m_cTEncTop.setVideoFormat( m_videoFormat ); |
---|
568 | m_cTEncTop.setVideoFullRangeFlag( m_videoFullRangeFlag ); |
---|
569 | m_cTEncTop.setColourDescriptionPresentFlag( m_colourDescriptionPresentFlag ); |
---|
570 | m_cTEncTop.setColourPrimaries( m_colourPrimaries ); |
---|
571 | m_cTEncTop.setTransferCharacteristics( m_transferCharacteristics ); |
---|
572 | m_cTEncTop.setMatrixCoefficients( m_matrixCoefficients ); |
---|
573 | m_cTEncTop.setChromaLocInfoPresentFlag( m_chromaLocInfoPresentFlag ); |
---|
574 | m_cTEncTop.setChromaSampleLocTypeTopField( m_chromaSampleLocTypeTopField ); |
---|
575 | m_cTEncTop.setChromaSampleLocTypeBottomField( m_chromaSampleLocTypeBottomField ); |
---|
576 | m_cTEncTop.setNeutralChromaIndicationFlag( m_neutralChromaIndicationFlag ); |
---|
577 | m_cTEncTop.setDefaultDisplayWindow( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset ); |
---|
578 | m_cTEncTop.setFrameFieldInfoPresentFlag( m_frameFieldInfoPresentFlag ); |
---|
579 | m_cTEncTop.setPocProportionalToTimingFlag( m_pocProportionalToTimingFlag ); |
---|
580 | m_cTEncTop.setNumTicksPocDiffOneMinus1 ( m_numTicksPocDiffOneMinus1 ); |
---|
581 | m_cTEncTop.setBitstreamRestrictionFlag( m_bitstreamRestrictionFlag ); |
---|
582 | m_cTEncTop.setTilesFixedStructureFlag( m_tilesFixedStructureFlag ); |
---|
583 | m_cTEncTop.setMotionVectorsOverPicBoundariesFlag( m_motionVectorsOverPicBoundariesFlag ); |
---|
584 | m_cTEncTop.setMinSpatialSegmentationIdc( m_minSpatialSegmentationIdc ); |
---|
585 | m_cTEncTop.setMaxBytesPerPicDenom( m_maxBytesPerPicDenom ); |
---|
586 | m_cTEncTop.setMaxBitsPerMinCuDenom( m_maxBitsPerMinCuDenom ); |
---|
587 | m_cTEncTop.setLog2MaxMvLengthHorizontal( m_log2MaxMvLengthHorizontal ); |
---|
588 | m_cTEncTop.setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical ); |
---|
589 | #if H_MV |
---|
590 | } |
---|
591 | #endif |
---|
592 | #if H_3D_VSO |
---|
593 | if ( m_bUseVSO ) |
---|
594 | { |
---|
595 | if ( m_uiVSOMode == 4 ) |
---|
596 | { |
---|
597 | #if H_3D_VSO_EARLY_SKIP |
---|
598 | m_cRendererModel.create( m_cRenModStrParser.getNumOfBaseViews(), m_cRenModStrParser.getNumOfModels(), m_iSourceWidth, g_uiMaxCUHeight , LOG2_DISP_PREC_LUT, 0, m_bVSOEarlySkip ); |
---|
599 | #else |
---|
600 | m_cRendererModel.create( m_cRenModStrParser.getNumOfBaseViews(), m_cRenModStrParser.getNumOfModels(), m_iSourceWidth, g_uiMaxCUHeight , LOG2_DISP_PREC_LUT, 0 ); |
---|
601 | #endif |
---|
602 | for ( Int layer = 0; layer < m_numberOfLayers ; layer++ ) |
---|
603 | { |
---|
604 | TEncTop* pcEncTop = m_acTEncTopList[ layer ]; |
---|
605 | Int iViewNum = pcEncTop->getViewIndex(); |
---|
606 | Int iContent = pcEncTop->getIsDepth() ? 1 : 0; |
---|
607 | Int iNumOfModels = m_cRenModStrParser.getNumOfModelsForView(iViewNum, iContent); |
---|
608 | |
---|
609 | Bool bUseVSO = (iNumOfModels != 0); |
---|
610 | |
---|
611 | pcEncTop->setUseVSO( bUseVSO ); |
---|
612 | pcEncTop->getRdCost()->setRenModel( bUseVSO ? &m_cRendererModel : NULL ); |
---|
613 | |
---|
614 | for (Int iCurModel = 0; iCurModel < iNumOfModels; iCurModel++ ) |
---|
615 | { |
---|
616 | Int iModelNum; Int iLeftViewNum; Int iRightViewNum; Int iDump; Int iOrgRefNum; Int iBlendMode; |
---|
617 | |
---|
618 | m_cRenModStrParser.getSingleModelData ( iViewNum, iContent, iCurModel, iModelNum, iBlendMode, iLeftViewNum, iRightViewNum, iOrgRefNum, iDump ) ; |
---|
619 | m_cRendererModel .createSingleModel ( iViewNum, iContent, iModelNum, iLeftViewNum, iRightViewNum, (iOrgRefNum != -1), iBlendMode ); |
---|
620 | } |
---|
621 | } |
---|
622 | } |
---|
623 | else |
---|
624 | { |
---|
625 | AOT(true); |
---|
626 | } |
---|
627 | } |
---|
628 | #endif |
---|
629 | } |
---|
630 | |
---|
631 | Void TAppEncTop::xCreateLib() |
---|
632 | { |
---|
633 | #if H_MV |
---|
634 | // initialize global variables |
---|
635 | initROM(); |
---|
636 | #if H_3D_DIM_DMM |
---|
637 | initWedgeLists( true ); |
---|
638 | #endif |
---|
639 | |
---|
640 | for( Int layer=0; layer < m_numberOfLayers; layer++) |
---|
641 | { |
---|
642 | m_acTVideoIOYuvInputFileList[layer]->open( m_pchInputFileList[layer], false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC ); // read mode |
---|
643 | m_acTVideoIOYuvInputFileList[layer]->skipFrames( m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]); |
---|
644 | |
---|
645 | if (m_pchReconFileList[layer]) |
---|
646 | { |
---|
647 | m_acTVideoIOYuvReconFileList[layer]->open( m_pchReconFileList[layer], true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC); // write mode |
---|
648 | } |
---|
649 | m_acTEncTopList[layer]->create(); |
---|
650 | } |
---|
651 | #else |
---|
652 | // Video I/O |
---|
653 | m_cTVideoIOYuvInputFile.open( m_pchInputFile, false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC ); // read mode |
---|
654 | m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]); |
---|
655 | |
---|
656 | if (m_pchReconFile) |
---|
657 | m_cTVideoIOYuvReconFile.open(m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC); // write mode |
---|
658 | |
---|
659 | // Neo Decoder |
---|
660 | m_cTEncTop.create(); |
---|
661 | #endif |
---|
662 | } |
---|
663 | |
---|
664 | Void TAppEncTop::xDestroyLib() |
---|
665 | { |
---|
666 | #if H_MV |
---|
667 | // destroy ROM |
---|
668 | destroyROM(); |
---|
669 | |
---|
670 | for(Int layer=0; layer<m_numberOfLayers; layer++) |
---|
671 | { |
---|
672 | m_acTVideoIOYuvInputFileList[layer]->close(); |
---|
673 | m_acTVideoIOYuvReconFileList[layer]->close(); |
---|
674 | delete m_acTVideoIOYuvInputFileList[layer] ; |
---|
675 | m_acTVideoIOYuvInputFileList[layer] = NULL; |
---|
676 | delete m_acTVideoIOYuvReconFileList[layer] ; |
---|
677 | m_acTVideoIOYuvReconFileList[layer] = NULL; |
---|
678 | m_acTEncTopList[layer]->deletePicBuffer(); |
---|
679 | m_acTEncTopList[layer]->destroy(); |
---|
680 | delete m_acTEncTopList[layer] ; |
---|
681 | m_acTEncTopList[layer] = NULL; |
---|
682 | delete m_picYuvRec[layer] ; |
---|
683 | m_picYuvRec[layer] = NULL; |
---|
684 | } |
---|
685 | #else |
---|
686 | // Video I/O |
---|
687 | m_cTVideoIOYuvInputFile.close(); |
---|
688 | m_cTVideoIOYuvReconFile.close(); |
---|
689 | |
---|
690 | // Neo Decoder |
---|
691 | m_cTEncTop.destroy(); |
---|
692 | #endif |
---|
693 | } |
---|
694 | |
---|
695 | Void TAppEncTop::xInitLib(Bool isFieldCoding) |
---|
696 | { |
---|
697 | #if H_3D |
---|
698 | for ( Int viewIndex = 0; viewIndex < m_vps->getNumViews(); viewIndex++ ) |
---|
699 | { |
---|
700 | m_vps->initCamParaVPS( viewIndex, true, m_cCameraData.getCamParsCodedPrecision(), |
---|
701 | m_cCameraData.getVaryingCameraParameters(), m_cCameraData.getCodedScale(), m_cCameraData.getCodedOffset() ); |
---|
702 | } |
---|
703 | #endif |
---|
704 | |
---|
705 | #if H_MV |
---|
706 | for(Int layer=0; layer<m_numberOfLayers; layer++) |
---|
707 | { |
---|
708 | #if KWU_RC_MADPRED_E0227 |
---|
709 | m_acTEncTopList[layer]->init( isFieldCoding, this ); |
---|
710 | #else |
---|
711 | m_acTEncTopList[layer]->init( isFieldCoding ); |
---|
712 | #endif |
---|
713 | } |
---|
714 | #else |
---|
715 | m_cTEncTop.init( isFieldCoding ); |
---|
716 | #endif |
---|
717 | } |
---|
718 | |
---|
719 | // ==================================================================================================================== |
---|
720 | // Public member functions |
---|
721 | // ==================================================================================================================== |
---|
722 | |
---|
723 | /** |
---|
724 | - create internal class |
---|
725 | - initialize internal variable |
---|
726 | - until the end of input YUV file, call encoding function in TEncTop class |
---|
727 | - delete allocated buffers |
---|
728 | - destroy internal class |
---|
729 | . |
---|
730 | */ |
---|
731 | Void TAppEncTop::encode() |
---|
732 | { |
---|
733 | fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out); |
---|
734 | if (!bitstreamFile) |
---|
735 | { |
---|
736 | fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile); |
---|
737 | exit(EXIT_FAILURE); |
---|
738 | } |
---|
739 | |
---|
740 | TComPicYuv* pcPicYuvOrg = new TComPicYuv; |
---|
741 | TComPicYuv* pcPicYuvRec = NULL; |
---|
742 | |
---|
743 | // initialize internal class & member variables |
---|
744 | xInitLibCfg(); |
---|
745 | xCreateLib(); |
---|
746 | xInitLib(m_isField); |
---|
747 | |
---|
748 | // main encoder loop |
---|
749 | #if H_MV |
---|
750 | Bool allEos = false; |
---|
751 | std::vector<Bool> eos ; |
---|
752 | std::vector<Bool> flush ; |
---|
753 | |
---|
754 | Int gopSize = 1; |
---|
755 | Int maxGopSize = 0; |
---|
756 | maxGopSize = (std::max)(maxGopSize, m_acTEncTopList[0]->getGOPSize()); |
---|
757 | |
---|
758 | for(Int layer=0; layer < m_numberOfLayers; layer++ ) |
---|
759 | { |
---|
760 | eos .push_back( false ); |
---|
761 | flush.push_back( false ); |
---|
762 | } |
---|
763 | #else |
---|
764 | Int iNumEncoded = 0; |
---|
765 | Bool bEos = false; |
---|
766 | #endif |
---|
767 | |
---|
768 | list<AccessUnit> outputAccessUnits; ///< list of access units to write out. is populated by the encoding process |
---|
769 | |
---|
770 | // allocate original YUV buffer |
---|
771 | if( m_isField ) |
---|
772 | { |
---|
773 | pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeightOrg, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth ); |
---|
774 | } |
---|
775 | else |
---|
776 | { |
---|
777 | pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth ); |
---|
778 | } |
---|
779 | |
---|
780 | #if H_MV |
---|
781 | while ( !allEos ) |
---|
782 | { |
---|
783 | for(Int layer=0; layer < m_numberOfLayers; layer++ ) |
---|
784 | { |
---|
785 | Int frmCnt = 0; |
---|
786 | while ( !eos[layer] && !(frmCnt == gopSize)) |
---|
787 | { |
---|
788 | // get buffers |
---|
789 | xGetBuffer(pcPicYuvRec, layer); |
---|
790 | |
---|
791 | // read input YUV file |
---|
792 | m_acTVideoIOYuvInputFileList[layer]->read ( pcPicYuvOrg, m_aiPad ); |
---|
793 | m_acTEncTopList [layer]->initNewPic( pcPicYuvOrg ); |
---|
794 | |
---|
795 | // increase number of received frames |
---|
796 | m_frameRcvd[layer]++; |
---|
797 | |
---|
798 | frmCnt++; |
---|
799 | |
---|
800 | eos[layer] = (m_frameRcvd[layer] == m_framesToBeEncoded); |
---|
801 | allEos = allEos||eos[layer]; |
---|
802 | |
---|
803 | // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures |
---|
804 | if (m_acTVideoIOYuvInputFileList[layer]->isEof()) |
---|
805 | { |
---|
806 | flush [layer] = true; |
---|
807 | eos [layer] = true; |
---|
808 | m_frameRcvd [layer]--; |
---|
809 | m_acTEncTopList[layer]->setFramesToBeEncoded(m_frameRcvd[layer]); |
---|
810 | } |
---|
811 | } |
---|
812 | } |
---|
813 | for ( Int gopId=0; gopId < gopSize; gopId++ ) |
---|
814 | { |
---|
815 | #if H_3D |
---|
816 | UInt iNextPoc = m_acTEncTopList[0] -> getFrameId( gopId ); |
---|
817 | if ( iNextPoc < m_framesToBeEncoded ) |
---|
818 | { |
---|
819 | m_cCameraData.update( iNextPoc ); |
---|
820 | } |
---|
821 | #endif |
---|
822 | for(Int layer=0; layer < m_numberOfLayers; layer++ ) |
---|
823 | { |
---|
824 | #if H_3D_VSO |
---|
825 | if( m_bUseVSO && m_bUseEstimatedVSD && iNextPoc < m_framesToBeEncoded ) |
---|
826 | { |
---|
827 | m_cCameraData.setDispCoeff( iNextPoc, m_acTEncTopList[layer]->getViewIndex() ); |
---|
828 | m_acTEncTopList[layer] ->setDispCoeff( m_cCameraData.getDispCoeff() ); |
---|
829 | } |
---|
830 | #endif |
---|
831 | |
---|
832 | #if H_3D_DDD |
---|
833 | m_acTEncTopList[ layer ]->getSliceEncoder()->setDDDPar( m_cCameraData.getCodedScale()[0][ m_acTEncTopList[layer]->getViewIndex() ], |
---|
834 | m_cCameraData.getCodedOffset()[0][ m_acTEncTopList[layer]->getViewIndex() ], |
---|
835 | m_cCameraData.getCamParsCodedPrecision() ); |
---|
836 | #endif |
---|
837 | Int iNumEncoded = 0; |
---|
838 | |
---|
839 | // call encoding function for one frame |
---|
840 | m_acTEncTopList[layer]->encode( eos[layer], flush[layer] ? 0 : pcPicYuvOrg, *m_picYuvRec[layer], outputAccessUnits, iNumEncoded, gopId ); |
---|
841 | xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits, layer); |
---|
842 | outputAccessUnits.clear(); |
---|
843 | } |
---|
844 | } |
---|
845 | |
---|
846 | gopSize = maxGopSize; |
---|
847 | } |
---|
848 | for(Int layer=0; layer < m_numberOfLayers; layer++ ) |
---|
849 | { |
---|
850 | m_acTEncTopList[layer]->printSummary( m_acTEncTopList[layer]->getNumAllPicCoded(), m_isField ); |
---|
851 | } |
---|
852 | #else |
---|
853 | while ( !bEos ) |
---|
854 | { |
---|
855 | // get buffers |
---|
856 | xGetBuffer(pcPicYuvRec); |
---|
857 | |
---|
858 | // read input YUV file |
---|
859 | m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, m_aiPad ); |
---|
860 | |
---|
861 | // increase number of received frames |
---|
862 | m_iFrameRcvd++; |
---|
863 | |
---|
864 | bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) ); |
---|
865 | |
---|
866 | Bool flush = 0; |
---|
867 | // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures |
---|
868 | if (m_cTVideoIOYuvInputFile.isEof()) |
---|
869 | { |
---|
870 | flush = true; |
---|
871 | bEos = true; |
---|
872 | m_iFrameRcvd--; |
---|
873 | m_cTEncTop.setFramesToBeEncoded(m_iFrameRcvd); |
---|
874 | } |
---|
875 | |
---|
876 | // call encoding function for one frame |
---|
877 | if ( m_isField ) |
---|
878 | { |
---|
879 | m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded, m_isTopFieldFirst); |
---|
880 | } |
---|
881 | else |
---|
882 | { |
---|
883 | m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded ); |
---|
884 | } |
---|
885 | |
---|
886 | // write bistream to file if necessary |
---|
887 | if ( iNumEncoded > 0 ) |
---|
888 | { |
---|
889 | xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits); |
---|
890 | outputAccessUnits.clear(); |
---|
891 | } |
---|
892 | } |
---|
893 | |
---|
894 | m_cTEncTop.printSummary(m_isField); |
---|
895 | #endif |
---|
896 | |
---|
897 | // delete original YUV buffer |
---|
898 | pcPicYuvOrg->destroy(); |
---|
899 | delete pcPicYuvOrg; |
---|
900 | pcPicYuvOrg = NULL; |
---|
901 | |
---|
902 | #if !H_MV |
---|
903 | // delete used buffers in encoder class |
---|
904 | m_cTEncTop.deletePicBuffer(); |
---|
905 | #endif |
---|
906 | |
---|
907 | // delete buffers & classes |
---|
908 | xDeleteBuffer(); |
---|
909 | xDestroyLib(); |
---|
910 | |
---|
911 | printRateSummary(); |
---|
912 | |
---|
913 | #if H_3D_REN_MAX_DEV_OUT |
---|
914 | Double dMaxDispDiff = m_cCameraData.getMaxShiftDeviation(); |
---|
915 | |
---|
916 | if ( !(dMaxDispDiff < 0) ) |
---|
917 | { |
---|
918 | printf("\n Max. possible shift error: %12.3f samples.\n", dMaxDispDiff ); |
---|
919 | } |
---|
920 | #endif |
---|
921 | |
---|
922 | return; |
---|
923 | } |
---|
924 | |
---|
925 | // ==================================================================================================================== |
---|
926 | // Protected member functions |
---|
927 | // ==================================================================================================================== |
---|
928 | |
---|
929 | /** |
---|
930 | - application has picture buffer list with size of GOP |
---|
931 | - picture buffer list acts as ring buffer |
---|
932 | - end of the list has the latest picture |
---|
933 | . |
---|
934 | */ |
---|
935 | #if H_MV |
---|
936 | Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer) |
---|
937 | #else |
---|
938 | Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec) |
---|
939 | #endif |
---|
940 | { |
---|
941 | assert( m_iGOPSize > 0 ); |
---|
942 | |
---|
943 | // org. buffer |
---|
944 | #if H_MV |
---|
945 | if ( m_picYuvRec[layer]->size() == (UInt)m_iGOPSize ) |
---|
946 | { |
---|
947 | rpcPicYuvRec = m_picYuvRec[layer]->popFront(); |
---|
948 | #else |
---|
949 | if ( m_cListPicYuvRec.size() == (UInt)m_iGOPSize ) |
---|
950 | { |
---|
951 | rpcPicYuvRec = m_cListPicYuvRec.popFront(); |
---|
952 | #endif |
---|
953 | |
---|
954 | } |
---|
955 | else |
---|
956 | { |
---|
957 | rpcPicYuvRec = new TComPicYuv; |
---|
958 | |
---|
959 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth ); |
---|
960 | |
---|
961 | } |
---|
962 | #if H_MV |
---|
963 | m_picYuvRec[layer]->pushBack( rpcPicYuvRec ); |
---|
964 | #else |
---|
965 | m_cListPicYuvRec.pushBack( rpcPicYuvRec ); |
---|
966 | #endif |
---|
967 | } |
---|
968 | |
---|
969 | Void TAppEncTop::xDeleteBuffer( ) |
---|
970 | { |
---|
971 | #if H_MV |
---|
972 | for(Int layer=0; layer<m_picYuvRec.size(); layer++) |
---|
973 | { |
---|
974 | if(m_picYuvRec[layer]) |
---|
975 | { |
---|
976 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_picYuvRec[layer]->begin(); |
---|
977 | Int iSize = Int( m_picYuvRec[layer]->size() ); |
---|
978 | #else |
---|
979 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.begin(); |
---|
980 | |
---|
981 | Int iSize = Int( m_cListPicYuvRec.size() ); |
---|
982 | #endif |
---|
983 | |
---|
984 | for ( Int i = 0; i < iSize; i++ ) |
---|
985 | { |
---|
986 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
---|
987 | pcPicYuvRec->destroy(); |
---|
988 | delete pcPicYuvRec; pcPicYuvRec = NULL; |
---|
989 | } |
---|
990 | |
---|
991 | #if H_MV |
---|
992 | } |
---|
993 | } |
---|
994 | #endif |
---|
995 | } |
---|
996 | |
---|
997 | /** \param iNumEncoded number of encoded frames |
---|
998 | */ |
---|
999 | #if H_MV |
---|
1000 | Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, std::list<AccessUnit>& accessUnits, UInt layerId) |
---|
1001 | #else |
---|
1002 | Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits) |
---|
1003 | #endif |
---|
1004 | { |
---|
1005 | if (m_isField) |
---|
1006 | { |
---|
1007 | //Reinterlace fields |
---|
1008 | Int i; |
---|
1009 | #if H_MV |
---|
1010 | if( iNumEncoded > 0 ) |
---|
1011 | { |
---|
1012 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_picYuvRec[layerId]->end(); |
---|
1013 | #else |
---|
1014 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end(); |
---|
1015 | list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin(); |
---|
1016 | #endif |
---|
1017 | |
---|
1018 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
1019 | { |
---|
1020 | --iterPicYuvRec; |
---|
1021 | } |
---|
1022 | |
---|
1023 | for ( i = 0; i < iNumEncoded/2; i++ ) |
---|
1024 | { |
---|
1025 | TComPicYuv* pcPicYuvRecTop = *(iterPicYuvRec++); |
---|
1026 | TComPicYuv* pcPicYuvRecBottom = *(iterPicYuvRec++); |
---|
1027 | |
---|
1028 | #if H_MV |
---|
1029 | if (m_pchReconFileList[layerId]) |
---|
1030 | { |
---|
1031 | m_acTVideoIOYuvReconFileList[layerId]->write( pcPicYuvRecTop, pcPicYuvRecBottom, m_confLeft, m_confRight, m_confTop, m_confBottom, m_isTopFieldFirst ); |
---|
1032 | } |
---|
1033 | } |
---|
1034 | } |
---|
1035 | |
---|
1036 | if( ! accessUnits.empty() ) |
---|
1037 | { |
---|
1038 | list<AccessUnit>::iterator aUIter; |
---|
1039 | for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ ) |
---|
1040 | { |
---|
1041 | const vector<UInt>& stats = writeAnnexB(bitstreamFile, *aUIter); |
---|
1042 | rateStatsAccum(*aUIter, stats); |
---|
1043 | } |
---|
1044 | } |
---|
1045 | #else |
---|
1046 | if (m_pchReconFile) |
---|
1047 | { |
---|
1048 | m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, m_confLeft, m_confRight, m_confTop, m_confBottom, m_isTopFieldFirst ); |
---|
1049 | } |
---|
1050 | |
---|
1051 | const AccessUnit& auTop = *(iterBitstream++); |
---|
1052 | const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop); |
---|
1053 | rateStatsAccum(auTop, statsTop); |
---|
1054 | |
---|
1055 | const AccessUnit& auBottom = *(iterBitstream++); |
---|
1056 | const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom); |
---|
1057 | rateStatsAccum(auBottom, statsBottom); |
---|
1058 | } |
---|
1059 | #endif |
---|
1060 | } |
---|
1061 | else |
---|
1062 | { |
---|
1063 | Int i; |
---|
1064 | #if H_MV |
---|
1065 | if( iNumEncoded > 0 ) |
---|
1066 | { |
---|
1067 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_picYuvRec[layerId]->end(); |
---|
1068 | #else |
---|
1069 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end(); |
---|
1070 | list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin(); |
---|
1071 | #endif |
---|
1072 | |
---|
1073 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
1074 | { |
---|
1075 | --iterPicYuvRec; |
---|
1076 | } |
---|
1077 | |
---|
1078 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
1079 | { |
---|
1080 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
---|
1081 | #if H_MV |
---|
1082 | if (m_pchReconFileList[layerId]) |
---|
1083 | { |
---|
1084 | m_acTVideoIOYuvReconFileList[layerId]->write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom ); |
---|
1085 | } |
---|
1086 | } |
---|
1087 | } |
---|
1088 | if( ! accessUnits.empty() ) |
---|
1089 | { |
---|
1090 | list<AccessUnit>::iterator aUIter; |
---|
1091 | for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ ) |
---|
1092 | { |
---|
1093 | const vector<unsigned>& stats = writeAnnexB(bitstreamFile, *aUIter); |
---|
1094 | rateStatsAccum(*aUIter, stats); |
---|
1095 | } |
---|
1096 | } |
---|
1097 | #else |
---|
1098 | if (m_pchReconFile) |
---|
1099 | { |
---|
1100 | m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom ); |
---|
1101 | } |
---|
1102 | |
---|
1103 | const AccessUnit& au = *(iterBitstream++); |
---|
1104 | const vector<UInt>& stats = writeAnnexB(bitstreamFile, au); |
---|
1105 | rateStatsAccum(au, stats); |
---|
1106 | } |
---|
1107 | #endif |
---|
1108 | } |
---|
1109 | } |
---|
1110 | |
---|
1111 | /** |
---|
1112 | * |
---|
1113 | */ |
---|
1114 | void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& annexBsizes) |
---|
1115 | { |
---|
1116 | AccessUnit::const_iterator it_au = au.begin(); |
---|
1117 | vector<UInt>::const_iterator it_stats = annexBsizes.begin(); |
---|
1118 | |
---|
1119 | for (; it_au != au.end(); it_au++, it_stats++) |
---|
1120 | { |
---|
1121 | switch ((*it_au)->m_nalUnitType) |
---|
1122 | { |
---|
1123 | case NAL_UNIT_CODED_SLICE_TRAIL_R: |
---|
1124 | case NAL_UNIT_CODED_SLICE_TRAIL_N: |
---|
1125 | case NAL_UNIT_CODED_SLICE_TSA_R: |
---|
1126 | case NAL_UNIT_CODED_SLICE_TSA_N: |
---|
1127 | case NAL_UNIT_CODED_SLICE_STSA_R: |
---|
1128 | case NAL_UNIT_CODED_SLICE_STSA_N: |
---|
1129 | case NAL_UNIT_CODED_SLICE_BLA_W_LP: |
---|
1130 | case NAL_UNIT_CODED_SLICE_BLA_W_RADL: |
---|
1131 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: |
---|
1132 | case NAL_UNIT_CODED_SLICE_IDR_W_RADL: |
---|
1133 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: |
---|
1134 | case NAL_UNIT_CODED_SLICE_CRA: |
---|
1135 | case NAL_UNIT_CODED_SLICE_RADL_N: |
---|
1136 | case NAL_UNIT_CODED_SLICE_RADL_R: |
---|
1137 | case NAL_UNIT_CODED_SLICE_RASL_N: |
---|
1138 | case NAL_UNIT_CODED_SLICE_RASL_R: |
---|
1139 | case NAL_UNIT_VPS: |
---|
1140 | case NAL_UNIT_SPS: |
---|
1141 | case NAL_UNIT_PPS: |
---|
1142 | m_essentialBytes += *it_stats; |
---|
1143 | break; |
---|
1144 | default: |
---|
1145 | break; |
---|
1146 | } |
---|
1147 | |
---|
1148 | m_totalBytes += *it_stats; |
---|
1149 | } |
---|
1150 | } |
---|
1151 | |
---|
1152 | void TAppEncTop::printRateSummary() |
---|
1153 | { |
---|
1154 | #if H_MV |
---|
1155 | Double time = (Double) m_frameRcvd[0] / m_iFrameRate; |
---|
1156 | printf("\n"); |
---|
1157 | #else |
---|
1158 | Double time = (Double) m_iFrameRcvd / m_iFrameRate; |
---|
1159 | #endif |
---|
1160 | printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time); |
---|
1161 | #if VERBOSE_RATE |
---|
1162 | printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time); |
---|
1163 | #endif |
---|
1164 | } |
---|
1165 | |
---|
1166 | #if H_3D_DIM_DLT |
---|
1167 | Void TAppEncTop::xAnalyzeInputBaseDepth(UInt layer, UInt uiNumFrames, TComVPS* vps, TComDLT* dlt) |
---|
1168 | { |
---|
1169 | TComPicYuv* pcDepthPicYuvOrg = new TComPicYuv; |
---|
1170 | // allocate original YUV buffer |
---|
1171 | pcDepthPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth ); |
---|
1172 | |
---|
1173 | TVideoIOYuv* depthVideoFile = new TVideoIOYuv; |
---|
1174 | |
---|
1175 | UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1); |
---|
1176 | |
---|
1177 | Bool abValidDepths[256]; |
---|
1178 | |
---|
1179 | depthVideoFile->open( m_pchInputFileList[layer], false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC ); // read mode |
---|
1180 | |
---|
1181 | // initialize boolean array |
---|
1182 | for(Int p=0; p<=uiMaxDepthValue; p++) |
---|
1183 | abValidDepths[p] = false; |
---|
1184 | |
---|
1185 | Int iHeight = pcDepthPicYuvOrg->getHeight(); |
---|
1186 | Int iWidth = pcDepthPicYuvOrg->getWidth(); |
---|
1187 | Int iStride = pcDepthPicYuvOrg->getStride(); |
---|
1188 | |
---|
1189 | Pel* pInDM = pcDepthPicYuvOrg->getLumaAddr(); |
---|
1190 | |
---|
1191 | for(Int uiFrame=0; uiFrame < uiNumFrames; uiFrame++ ) |
---|
1192 | { |
---|
1193 | depthVideoFile->read( pcDepthPicYuvOrg, m_aiPad ); |
---|
1194 | |
---|
1195 | // check all pixel values |
---|
1196 | for (Int i=0; i<iHeight; i++) |
---|
1197 | { |
---|
1198 | Int rowOffset = i*iStride; |
---|
1199 | |
---|
1200 | for (Int j=0; j<iWidth; j++) |
---|
1201 | { |
---|
1202 | Pel depthValue = pInDM[rowOffset+j]; |
---|
1203 | abValidDepths[depthValue] = true; |
---|
1204 | } |
---|
1205 | } |
---|
1206 | } |
---|
1207 | |
---|
1208 | depthVideoFile->close(); |
---|
1209 | delete depthVideoFile; |
---|
1210 | |
---|
1211 | pcDepthPicYuvOrg->destroy(); |
---|
1212 | delete pcDepthPicYuvOrg; |
---|
1213 | |
---|
1214 | // convert boolean array to idx2Depth LUT |
---|
1215 | Int* aiIdx2DepthValue = (Int*) calloc(uiMaxDepthValue, sizeof(Int)); |
---|
1216 | Int iNumDepthValues = 0; |
---|
1217 | for(Int p=0; p<=uiMaxDepthValue; p++) |
---|
1218 | { |
---|
1219 | if( abValidDepths[p] == true) |
---|
1220 | { |
---|
1221 | aiIdx2DepthValue[iNumDepthValues++] = p; |
---|
1222 | } |
---|
1223 | } |
---|
1224 | |
---|
1225 | if( uiNumFrames == 0 || numBitsForValue(iNumDepthValues) == g_bitDepthY ) |
---|
1226 | { |
---|
1227 | dlt->setUseDLTFlag(layer, false); |
---|
1228 | } |
---|
1229 | |
---|
1230 | // assign LUT |
---|
1231 | if( dlt->getUseDLTFlag(layer) ) |
---|
1232 | { |
---|
1233 | dlt->setDepthLUTs(layer, aiIdx2DepthValue, iNumDepthValues); |
---|
1234 | } |
---|
1235 | |
---|
1236 | // free temporary memory |
---|
1237 | free(aiIdx2DepthValue); |
---|
1238 | } |
---|
1239 | #endif |
---|
1240 | |
---|
1241 | #if H_MV |
---|
1242 | Void TAppEncTop::xSetDimensionIdAndLength( TComVPS& vps ) |
---|
1243 | { |
---|
1244 | vps.setScalabilityMaskFlag( m_scalabilityMask ); |
---|
1245 | for( Int dim = 0; dim < m_dimIds.size(); dim++ ) |
---|
1246 | { |
---|
1247 | vps.setDimensionIdLen( dim, m_dimensionIdLen[ dim ] ); |
---|
1248 | for( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ ) |
---|
1249 | |
---|
1250 | { |
---|
1251 | vps.setDimensionId( layer, dim, m_dimIds[ dim ][ layer ] ); |
---|
1252 | } |
---|
1253 | } |
---|
1254 | |
---|
1255 | Int maxViewId = xGetMax( m_viewId ); |
---|
1256 | |
---|
1257 | Int viewIdLen = gCeilLog2( maxViewId + 1 ); |
---|
1258 | const Int maxViewIdLen = ( 1 << 4 ) - 1; |
---|
1259 | assert( viewIdLen <= maxViewIdLen ); |
---|
1260 | vps.setViewIdLen( viewIdLen ); |
---|
1261 | for (Int i = 0; i < m_iNumberOfViews; i++) |
---|
1262 | { |
---|
1263 | vps.setViewIdVal( i, m_viewId[ i] ); |
---|
1264 | } |
---|
1265 | |
---|
1266 | assert( m_iNumberOfViews == vps.getNumViews() ); |
---|
1267 | } |
---|
1268 | |
---|
1269 | Void TAppEncTop::xSetDependencies( TComVPS& vps ) |
---|
1270 | { |
---|
1271 | // Direct dependency flags + dependency types |
---|
1272 | for( Int depLayer = 1; depLayer < MAX_NUM_LAYERS; depLayer++ ) |
---|
1273 | { |
---|
1274 | for( Int refLayer = 0; refLayer < MAX_NUM_LAYERS; refLayer++ ) |
---|
1275 | { |
---|
1276 | vps.setDirectDependencyFlag( depLayer, refLayer, false); |
---|
1277 | vps.setDirectDependencyType( depLayer, refLayer, -1 ); |
---|
1278 | } |
---|
1279 | } |
---|
1280 | |
---|
1281 | Int defaultDirectDependencyType = -1; |
---|
1282 | Bool defaultDirectDependencyFlag = false; |
---|
1283 | |
---|
1284 | for( Int depLayer = 1; depLayer < m_numberOfLayers; depLayer++ ) |
---|
1285 | { |
---|
1286 | Int numRefLayers = (Int) m_directRefLayers[depLayer].size(); |
---|
1287 | assert( numRefLayers == (Int) m_dependencyTypes[depLayer].size() ); |
---|
1288 | for( Int i = 0; i < numRefLayers; i++ ) |
---|
1289 | { |
---|
1290 | Int refLayer = m_directRefLayers[depLayer][i]; |
---|
1291 | vps.setDirectDependencyFlag( depLayer, refLayer, true); |
---|
1292 | Int curDirectDependencyType = m_dependencyTypes[depLayer][i]; |
---|
1293 | |
---|
1294 | if ( defaultDirectDependencyType != -1 ) |
---|
1295 | { |
---|
1296 | defaultDirectDependencyFlag = defaultDirectDependencyFlag && (curDirectDependencyType == defaultDirectDependencyType ); |
---|
1297 | } |
---|
1298 | else |
---|
1299 | { |
---|
1300 | defaultDirectDependencyType = curDirectDependencyType; |
---|
1301 | defaultDirectDependencyFlag = true; |
---|
1302 | } |
---|
1303 | |
---|
1304 | vps.setDirectDependencyType( depLayer, refLayer, curDirectDependencyType); |
---|
1305 | } |
---|
1306 | } |
---|
1307 | |
---|
1308 | vps.setDefaultDirectDependencyFlag( defaultDirectDependencyFlag ); |
---|
1309 | vps.setDefaultDirectDependencyType( defaultDirectDependencyFlag ? defaultDirectDependencyType : -1 ); |
---|
1310 | |
---|
1311 | // Max sub layers, + presence flag |
---|
1312 | Bool subLayersMaxMinus1PresentFlag = false; |
---|
1313 | Int subLayersMaxMinus1 = -1; |
---|
1314 | for (Int curLayerIdInVps = 0; curLayerIdInVps < m_numberOfLayers; curLayerIdInVps++ ) |
---|
1315 | { |
---|
1316 | Int curSubLayersMaxMinus1 = -1; |
---|
1317 | for( Int i = 0; i < getGOPSize(); i++ ) |
---|
1318 | { |
---|
1319 | GOPEntry geCur = m_GOPListMvc[curLayerIdInVps][i]; |
---|
1320 | curSubLayersMaxMinus1 = std::max( curSubLayersMaxMinus1, geCur.m_temporalId ); |
---|
1321 | } |
---|
1322 | |
---|
1323 | vps.setSubLayersVpsMaxMinus1( curLayerIdInVps, curSubLayersMaxMinus1 ); |
---|
1324 | if ( subLayersMaxMinus1 == -1 ) |
---|
1325 | { |
---|
1326 | subLayersMaxMinus1 = curSubLayersMaxMinus1; |
---|
1327 | } |
---|
1328 | else |
---|
1329 | { |
---|
1330 | subLayersMaxMinus1PresentFlag = subLayersMaxMinus1PresentFlag || ( curSubLayersMaxMinus1 != subLayersMaxMinus1 ); |
---|
1331 | } |
---|
1332 | } |
---|
1333 | |
---|
1334 | vps.setVpsSubLayersMaxMinus1PresentFlag( subLayersMaxMinus1PresentFlag ); |
---|
1335 | |
---|
1336 | |
---|
1337 | // Max temporal id for inter layer reference pictures + presence flag |
---|
1338 | Bool maxTidRefPresentFlag = false; |
---|
1339 | for ( Int refLayerIdInVps = 0; refLayerIdInVps < m_numberOfLayers; refLayerIdInVps++) |
---|
1340 | { |
---|
1341 | for ( Int curLayerIdInVps = 1; curLayerIdInVps < m_numberOfLayers; curLayerIdInVps++) |
---|
1342 | { |
---|
1343 | Int maxTid = -1; |
---|
1344 | for( Int i = 0; i < getGOPSize(); i++ ) |
---|
1345 | { |
---|
1346 | GOPEntry geCur = m_GOPListMvc[curLayerIdInVps][i]; |
---|
1347 | GOPEntry geRef = m_GOPListMvc[refLayerIdInVps][i]; |
---|
1348 | |
---|
1349 | for (Int j = 0; j < geCur.m_numActiveRefLayerPics; j++) |
---|
1350 | { |
---|
1351 | if ( m_directRefLayers[ curLayerIdInVps ][ geCur.m_interLayerPredLayerIdc[ j ]] == refLayerIdInVps ) |
---|
1352 | { |
---|
1353 | maxTid = std::max( maxTid, geRef.m_temporalId ); |
---|
1354 | } |
---|
1355 | } |
---|
1356 | } |
---|
1357 | vps.setMaxTidIlRefPicsPlus1( refLayerIdInVps, curLayerIdInVps, maxTid + 1 ); |
---|
1358 | maxTidRefPresentFlag = maxTidRefPresentFlag || ( maxTid != 6 ); |
---|
1359 | } |
---|
1360 | } |
---|
1361 | |
---|
1362 | vps.setMaxTidRefPresentFlag( maxTidRefPresentFlag ); |
---|
1363 | // Max one active ref layer flag |
---|
1364 | Bool maxOneActiveRefLayerFlag = true; |
---|
1365 | for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && maxOneActiveRefLayerFlag; layerIdInVps++) |
---|
1366 | { |
---|
1367 | for( Int i = 0; i < ( getGOPSize() + 1) && maxOneActiveRefLayerFlag; i++ ) |
---|
1368 | { |
---|
1369 | GOPEntry ge = m_GOPListMvc[layerIdInVps][ ( i < getGOPSize() ? i : MAX_GOP ) ]; |
---|
1370 | maxOneActiveRefLayerFlag = maxOneActiveRefLayerFlag && (ge.m_numActiveRefLayerPics <= 1); |
---|
1371 | } |
---|
1372 | } |
---|
1373 | |
---|
1374 | vps.setMaxOneActiveRefLayerFlag( maxOneActiveRefLayerFlag ); |
---|
1375 | |
---|
1376 | // Poc Lsb Not Present Flag |
---|
1377 | for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers; layerIdInVps++) |
---|
1378 | { |
---|
1379 | if ( m_directRefLayers[ layerIdInVps ].size() == 0 ) |
---|
1380 | { |
---|
1381 | vps.setPocLsbNotPresentFlag( layerIdInVps, true ); |
---|
1382 | } |
---|
1383 | } |
---|
1384 | |
---|
1385 | // All Ref layers active flag |
---|
1386 | Bool allRefLayersActiveFlag = true; |
---|
1387 | for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && allRefLayersActiveFlag; layerIdInVps++) |
---|
1388 | { |
---|
1389 | for( Int i = 0; i < ( getGOPSize() + 1) && allRefLayersActiveFlag; i++ ) |
---|
1390 | { |
---|
1391 | GOPEntry ge = m_GOPListMvc[layerIdInVps][ ( i < getGOPSize() ? i : MAX_GOP ) ]; |
---|
1392 | Int tId = ge.m_temporalId; // Should be equal for all layers. |
---|
1393 | |
---|
1394 | // check if all reference layers when allRefLayerActiveFlag is equal to 1 are reference layer pictures specified in the gop entry |
---|
1395 | for (Int k = 0; k < m_directRefLayers[ layerIdInVps].size() && allRefLayersActiveFlag; k++ ) |
---|
1396 | { |
---|
1397 | Int refLayerIdInVps = vps.getLayerIdInVps( m_directRefLayers[ layerIdInVps ][ k ] ); |
---|
1398 | if ( vps.getMaxTidIlRefPicsPlus1(refLayerIdInVps,layerIdInVps) > tId && vps.getSubLayersVpsMaxMinus1(refLayerIdInVps) >= tId ) |
---|
1399 | { |
---|
1400 | Bool gopEntryFoundFlag = false; |
---|
1401 | for( Int l = 0; l < ge.m_numActiveRefLayerPics && !gopEntryFoundFlag; l++ ) |
---|
1402 | { |
---|
1403 | gopEntryFoundFlag = gopEntryFoundFlag || ( ge.m_interLayerPredLayerIdc[l] == k ); |
---|
1404 | } |
---|
1405 | allRefLayersActiveFlag = allRefLayersActiveFlag && gopEntryFoundFlag; |
---|
1406 | } |
---|
1407 | } |
---|
1408 | |
---|
1409 | // check if all inter layer reference pictures specified in the gop entry are valid reference layer pictures when allRefLayerActiveFlag is equal to 1 |
---|
1410 | // (Should actually always be true) |
---|
1411 | Bool maxTidIlRefAndSubLayerMaxVaildFlag = true; |
---|
1412 | for( Int l = 0; l < ge.m_numActiveRefLayerPics; l++ ) |
---|
1413 | { |
---|
1414 | Bool referenceLayerFoundFlag = false; |
---|
1415 | for (Int k = 0; k < m_directRefLayers[ layerIdInVps].size(); k++ ) |
---|
1416 | { |
---|
1417 | Int refLayerIdInVps = vps.getLayerIdInVps( m_directRefLayers[ layerIdInVps ][ k ] ); |
---|
1418 | |
---|
1419 | if ( vps.getMaxTidIlRefPicsPlus1(refLayerIdInVps,layerIdInVps) > tId && vps.getSubLayersVpsMaxMinus1(refLayerIdInVps) >= tId ) |
---|
1420 | { |
---|
1421 | referenceLayerFoundFlag = referenceLayerFoundFlag || ( ge.m_interLayerPredLayerIdc[l] == k ); |
---|
1422 | } |
---|
1423 | } |
---|
1424 | maxTidIlRefAndSubLayerMaxVaildFlag = maxTidIlRefAndSubLayerMaxVaildFlag && referenceLayerFoundFlag; |
---|
1425 | } |
---|
1426 | assert ( maxTidIlRefAndSubLayerMaxVaildFlag ); // Something wrong with MaxTidIlRefPicsPlus1 or SubLayersVpsMaxMinus1 |
---|
1427 | } |
---|
1428 | } |
---|
1429 | |
---|
1430 | vps.setAllRefLayersActiveFlag( allRefLayersActiveFlag ); |
---|
1431 | |
---|
1432 | vps.setRefLayers(); |
---|
1433 | }; |
---|
1434 | |
---|
1435 | GOPEntry* TAppEncTop::xGetGopEntry( Int layerIdInVps, Int poc ) |
---|
1436 | { |
---|
1437 | GOPEntry* geFound = NULL; |
---|
1438 | for( Int i = 0; i < ( getGOPSize() + 1) && geFound == NULL ; i++ ) |
---|
1439 | { |
---|
1440 | GOPEntry* ge = &(m_GOPListMvc[layerIdInVps][ ( i < getGOPSize() ? i : MAX_GOP ) ]); |
---|
1441 | if ( ge->m_POC == poc ) |
---|
1442 | { |
---|
1443 | geFound = ge; |
---|
1444 | } |
---|
1445 | } |
---|
1446 | assert( geFound != NULL ); |
---|
1447 | return geFound; |
---|
1448 | } |
---|
1449 | |
---|
1450 | Void TAppEncTop::xSetLayerIds( TComVPS& vps ) |
---|
1451 | { |
---|
1452 | vps.setSplittingFlag ( m_splittingFlag ); |
---|
1453 | |
---|
1454 | Bool nuhLayerIdPresentFlag = !( m_layerIdInNuh.size() == 1 ); |
---|
1455 | Int maxNuhLayerId = nuhLayerIdPresentFlag ? xGetMax( m_layerIdInNuh ) : ( m_numberOfLayers - 1 ) ; |
---|
1456 | |
---|
1457 | vps.setVpsMaxLayerId( maxNuhLayerId ); |
---|
1458 | vps.setVpsNuhLayerIdPresentFlag( nuhLayerIdPresentFlag ); |
---|
1459 | |
---|
1460 | for (Int layer = 0; layer < m_numberOfLayers; layer++ ) |
---|
1461 | { |
---|
1462 | vps.setLayerIdInNuh( layer, nuhLayerIdPresentFlag ? m_layerIdInNuh[ layer ] : layer ); |
---|
1463 | vps.setLayerIdInVps( vps.getLayerIdInNuh( layer ), layer ); |
---|
1464 | } |
---|
1465 | } |
---|
1466 | |
---|
1467 | Int TAppEncTop::xGetMax( std::vector<Int>& vec ) |
---|
1468 | { |
---|
1469 | Int maxVec = 0; |
---|
1470 | for ( Int i = 0; i < vec.size(); i++) |
---|
1471 | { |
---|
1472 | maxVec = max( vec[i], maxVec ); |
---|
1473 | } |
---|
1474 | return maxVec; |
---|
1475 | } |
---|
1476 | |
---|
1477 | Void TAppEncTop::xSetProfileTierLevel( TComVPS& vps ) |
---|
1478 | { |
---|
1479 | const Int vpsNumProfileTierLevelMinus1 = 0; //TBD |
---|
1480 | vps.setVpsNumProfileTierLevelMinus1( vpsNumProfileTierLevelMinus1 ); |
---|
1481 | |
---|
1482 | for (Int i = 0; i <= vps.getVpsNumProfileTierLevelMinus1(); i++ ) |
---|
1483 | { |
---|
1484 | vps.setVpsProfilePresentFlag( i, true ); |
---|
1485 | } |
---|
1486 | } |
---|
1487 | |
---|
1488 | |
---|
1489 | Void TAppEncTop::xSetRepFormat( TComVPS& vps ) |
---|
1490 | { |
---|
1491 | vps.setRepFormatIdxPresentFlag( false ); |
---|
1492 | vps.setVpsNumRepFormatsMinus1 ( 0 ); |
---|
1493 | |
---|
1494 | TComRepFormat* repFormat = new TComRepFormat; |
---|
1495 | |
---|
1496 | repFormat->setBitDepthVpsChromaMinus8 ( g_bitDepthC - 8 ); |
---|
1497 | repFormat->setBitDepthVpsLumaMinus8 ( g_bitDepthY - 8 ); |
---|
1498 | repFormat->setChromaFormatVpsIdc ( CHROMA_420 ); |
---|
1499 | repFormat->setPicHeightVpsInLumaSamples ( m_iSourceHeight ); |
---|
1500 | repFormat->setPicWidthVpsInLumaSamples ( m_iSourceWidth ); |
---|
1501 | repFormat->setChromaAndBitDepthVpsPresentFlag( true ); |
---|
1502 | // ToDo not supported yet. |
---|
1503 | //repFormat->setSeparateColourPlaneVpsFlag( ); |
---|
1504 | |
---|
1505 | assert( vps.getRepFormat( 0 ) == NULL ); |
---|
1506 | vps.setRepFormat( 0 , repFormat ); |
---|
1507 | } |
---|
1508 | |
---|
1509 | Void TAppEncTop::xSetDpbSize ( TComVPS& vps ) |
---|
1510 | { |
---|
1511 | // These settings need to be verified |
---|
1512 | |
---|
1513 | TComDpbSize* dpbSize = vps.getDpbSize(); |
---|
1514 | |
---|
1515 | assert ( dpbSize != 0 ); |
---|
1516 | |
---|
1517 | for( Int i = 0; i < vps.getNumOutputLayerSets(); i++ ) |
---|
1518 | { |
---|
1519 | Int currLsIdx = vps.olsIdxToLsIdx( i ); |
---|
1520 | std::vector<Int> targetDecLayerIdList = vps.getTargetDecLayerIdList( i ); |
---|
1521 | Bool subLayerFlagInfoPresentFlag = false; |
---|
1522 | |
---|
1523 | for( Int j = 0; j <= vps.getMaxSubLayersInLayerSetMinus1( currLsIdx ); j++ ) |
---|
1524 | { |
---|
1525 | Bool subLayerDpbInfoPresentFlag = false; |
---|
1526 | assert( vps.getNumLayersInIdList( currLsIdx ) == targetDecLayerIdList.size() ); |
---|
1527 | for( Int k = 0; k < vps.getNumLayersInIdList( currLsIdx ); k++ ) |
---|
1528 | { |
---|
1529 | Int layerIdInVps = vps.getLayerIdInVps( targetDecLayerIdList[k] ); |
---|
1530 | dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, m_maxDecPicBufferingMvc[ layerIdInVps ][ j ] - 1 ); |
---|
1531 | if ( j > 0 ) |
---|
1532 | { |
---|
1533 | subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j ) != dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j - 1 ) ); |
---|
1534 | } |
---|
1535 | } |
---|
1536 | |
---|
1537 | Int maxNumReorderPics = MIN_INT; |
---|
1538 | for ( Int idx = 0; idx < targetDecLayerIdList.size(); idx++ ) |
---|
1539 | { |
---|
1540 | Int layerIdInVps = vps.getLayerIdInVps( targetDecLayerIdList[ idx ] ); |
---|
1541 | maxNumReorderPics = std::max( maxNumReorderPics, m_numReorderPicsMvc[ layerIdInVps ][ j ] ); |
---|
1542 | } |
---|
1543 | assert( maxNumReorderPics != MIN_INT ); |
---|
1544 | |
---|
1545 | dpbSize->setMaxVpsNumReorderPics( i, j, maxNumReorderPics ); |
---|
1546 | if ( j > 0 ) |
---|
1547 | { |
---|
1548 | subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize->getMaxVpsNumReorderPics( i, j ) != dpbSize->getMaxVpsNumReorderPics( i, j - 1 ) ); |
---|
1549 | } |
---|
1550 | |
---|
1551 | // To Be Done ! |
---|
1552 | // dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, xx ); |
---|
1553 | if ( j > 0 ) |
---|
1554 | { |
---|
1555 | subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize->getMaxVpsLatencyIncreasePlus1( i, j ) != dpbSize->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) ); |
---|
1556 | } |
---|
1557 | |
---|
1558 | if( j > 0 ) |
---|
1559 | { |
---|
1560 | dpbSize->setSubLayerDpbInfoPresentFlag( i, j, subLayerDpbInfoPresentFlag ); |
---|
1561 | subLayerFlagInfoPresentFlag = subLayerFlagInfoPresentFlag || subLayerDpbInfoPresentFlag; |
---|
1562 | } |
---|
1563 | } |
---|
1564 | dpbSize->setSubLayerFlagInfoPresentFlag( i, subLayerFlagInfoPresentFlag ); |
---|
1565 | } |
---|
1566 | } |
---|
1567 | |
---|
1568 | |
---|
1569 | Void TAppEncTop::xSetLayerSets( TComVPS& vps ) |
---|
1570 | { |
---|
1571 | // Layer sets |
---|
1572 | vps.setVpsNumLayerSetsMinus1 ( m_vpsNumLayerSets - 1 ); |
---|
1573 | |
---|
1574 | for (Int lsIdx = 0; lsIdx < m_vpsNumLayerSets; lsIdx++ ) |
---|
1575 | { |
---|
1576 | for( Int layerId = 0; layerId < MAX_NUM_LAYER_IDS; layerId++ ) |
---|
1577 | { |
---|
1578 | vps.setLayerIdIncludedFlag( false, lsIdx, layerId ); |
---|
1579 | } |
---|
1580 | for ( Int i = 0; i < m_layerIdsInSets[lsIdx].size(); i++) |
---|
1581 | { |
---|
1582 | vps.setLayerIdIncludedFlag( true, lsIdx, vps.getLayerIdInNuh( m_layerIdsInSets[lsIdx][i] ) ); |
---|
1583 | } |
---|
1584 | } |
---|
1585 | vps.deriveLayerSetLayerIdList(); |
---|
1586 | |
---|
1587 | Int numAddOuputLayerSets = (Int) m_outputLayerSetIdx.size(); |
---|
1588 | // Additional output layer sets + profileLevelTierIdx |
---|
1589 | vps.setDefaultOutputLayerIdc ( m_defaultOutputLayerIdc ); |
---|
1590 | vps.setNumAddLayerSets ( 0 ); |
---|
1591 | vps.setNumAddOlss ( numAddOuputLayerSets ); |
---|
1592 | vps.initTargetLayerIdLists(); |
---|
1593 | |
---|
1594 | for (Int olsIdx = 0; olsIdx < m_vpsNumLayerSets + numAddOuputLayerSets; olsIdx++) |
---|
1595 | { |
---|
1596 | Int addOutLsIdx = olsIdx - m_vpsNumLayerSets; |
---|
1597 | |
---|
1598 | vps.setLayerSetIdxForOlsMinus1( olsIdx, ( ( addOutLsIdx < 0 ) ? olsIdx : m_outputLayerSetIdx[ addOutLsIdx ] ) - 1 ); |
---|
1599 | |
---|
1600 | std::vector<Int>& layerIdList = m_layerIdsInSets[ vps.olsIdxToLsIdx( olsIdx ) ]; |
---|
1601 | |
---|
1602 | if (vps.getDefaultOutputLayerIdc() == 2 || addOutLsIdx >= 0 ) |
---|
1603 | { |
---|
1604 | for ( Int i = 0; i < layerIdList.size(); i++) |
---|
1605 | { |
---|
1606 | 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 ! |
---|
1607 | } |
---|
1608 | |
---|
1609 | std::vector<Int>& outLayerIdList = ( addOutLsIdx >= 0 ) ? m_layerIdsInAddOutputLayerSet[addOutLsIdx] : m_layerIdsInDefOutputLayerSet[olsIdx]; |
---|
1610 | |
---|
1611 | Bool outputLayerInLayerSetFlag = false; |
---|
1612 | for (Int j = 0; j < outLayerIdList.size(); j++) |
---|
1613 | { |
---|
1614 | for (Int i = 0; i < layerIdList.size(); i++ ) |
---|
1615 | { |
---|
1616 | if ( layerIdList[ i ] == outLayerIdList[ j ] ) |
---|
1617 | { |
---|
1618 | vps.setOutputLayerFlag( olsIdx, i, true ); |
---|
1619 | outputLayerInLayerSetFlag = true; |
---|
1620 | break; |
---|
1621 | } |
---|
1622 | } |
---|
1623 | assert( outputLayerInLayerSetFlag ); // The output layer is not not in the layer set. |
---|
1624 | } |
---|
1625 | } |
---|
1626 | else |
---|
1627 | { |
---|
1628 | for ( Int i = 0; i < layerIdList.size(); i++) |
---|
1629 | { |
---|
1630 | vps.setOutputLayerFlag( olsIdx, i, vps.inferOutputLayerFlag( olsIdx, i ) ); |
---|
1631 | } |
---|
1632 | } |
---|
1633 | |
---|
1634 | vps.deriveTargetLayerIdList( olsIdx ); |
---|
1635 | |
---|
1636 | if ( olsIdx > 0 ) |
---|
1637 | { |
---|
1638 | vps.setProfileLevelTierIdx( olsIdx, m_profileLevelTierIdx[ olsIdx ] ); |
---|
1639 | } |
---|
1640 | |
---|
1641 | if ( vps.getNumOutputLayersInOutputLayerSet( olsIdx ) == 1 && |
---|
1642 | vps.getNumDirectRefLayers( vps.getOlsHighestOutputLayerId( olsIdx ) ) ) |
---|
1643 | { |
---|
1644 | vps.setAltOutputLayerFlag( olsIdx , m_altOutputLayerFlag[ olsIdx ]); |
---|
1645 | } |
---|
1646 | else |
---|
1647 | { |
---|
1648 | vps.setAltOutputLayerFlag( olsIdx , false ); |
---|
1649 | if ( m_altOutputLayerFlag[ olsIdx ] ) |
---|
1650 | { |
---|
1651 | printf( "\nWarning: Ignoring AltOutputLayerFlag for output layer set %d, since more than one output layer or no dependent layers.\n", olsIdx ); |
---|
1652 | } |
---|
1653 | } |
---|
1654 | } |
---|
1655 | } |
---|
1656 | |
---|
1657 | Void TAppEncTop::xSetVPSVUI( TComVPS& vps ) |
---|
1658 | { |
---|
1659 | vps.setVpsVuiPresentFlag( m_vpsVuiPresentFlag ); |
---|
1660 | |
---|
1661 | TComVPSVUI* pcVPSVUI = vps.getVPSVUI( ); |
---|
1662 | assert( pcVPSVUI ); |
---|
1663 | |
---|
1664 | if ( m_vpsVuiPresentFlag ) |
---|
1665 | { |
---|
1666 | // All this stuff could actually be derived by the encoder, |
---|
1667 | // however preliminary setting it from input parameters |
---|
1668 | |
---|
1669 | pcVPSVUI->setCrossLayerPicTypeAlignedFlag( m_crossLayerPicTypeAlignedFlag ); |
---|
1670 | pcVPSVUI->setCrossLayerIrapAlignedFlag ( m_crossLayerIrapAlignedFlag ); |
---|
1671 | pcVPSVUI->setAllLayersIdrAlignedFlag ( m_allLayersIdrAlignedFlag ); |
---|
1672 | pcVPSVUI->setBitRatePresentVpsFlag( m_bitRatePresentVpsFlag ); |
---|
1673 | pcVPSVUI->setPicRatePresentVpsFlag( m_picRatePresentVpsFlag ); |
---|
1674 | |
---|
1675 | if( pcVPSVUI->getBitRatePresentVpsFlag( ) || pcVPSVUI->getPicRatePresentVpsFlag( ) ) |
---|
1676 | { |
---|
1677 | for( Int i = 0; i <= vps.getVpsNumLayerSetsMinus1(); i++ ) |
---|
1678 | { |
---|
1679 | for( Int j = 0; j <= vps.getMaxTLayers(); j++ ) |
---|
1680 | { |
---|
1681 | if( pcVPSVUI->getBitRatePresentVpsFlag( ) && m_bitRatePresentFlag[i].size() > j ) |
---|
1682 | { |
---|
1683 | pcVPSVUI->setBitRatePresentFlag( i, j, m_bitRatePresentFlag[i][j] ); |
---|
1684 | } |
---|
1685 | if( pcVPSVUI->getPicRatePresentVpsFlag( ) && m_picRatePresentFlag[i].size() > j ) |
---|
1686 | { |
---|
1687 | pcVPSVUI->setPicRatePresentFlag( i, j, m_picRatePresentFlag[i][j] ); |
---|
1688 | } |
---|
1689 | if( pcVPSVUI->getBitRatePresentFlag( i, j ) && m_avgBitRate[i].size() > j ) |
---|
1690 | { |
---|
1691 | pcVPSVUI->setAvgBitRate( i, j, m_avgBitRate[i][j] ); |
---|
1692 | } |
---|
1693 | if( pcVPSVUI->getBitRatePresentFlag( i, j ) && m_maxBitRate[i].size() > j ) |
---|
1694 | { |
---|
1695 | pcVPSVUI->setMaxBitRate( i, j, m_maxBitRate[i][j] ); |
---|
1696 | } |
---|
1697 | if( pcVPSVUI->getPicRatePresentFlag( i, j ) && m_constantPicRateIdc[i].size() > j ) |
---|
1698 | { |
---|
1699 | pcVPSVUI->setConstantPicRateIdc( i, j, m_constantPicRateIdc[i][j] ); |
---|
1700 | } |
---|
1701 | if( pcVPSVUI->getPicRatePresentFlag( i, j ) && m_avgPicRate[i].size() > j ) |
---|
1702 | { |
---|
1703 | pcVPSVUI->setAvgPicRate( i, j, m_avgPicRate[i][j] ); |
---|
1704 | } |
---|
1705 | } |
---|
1706 | } |
---|
1707 | } |
---|
1708 | |
---|
1709 | pcVPSVUI->setTilesNotInUseFlag( m_tilesNotInUseFlag ); |
---|
1710 | |
---|
1711 | if( !pcVPSVUI->getTilesNotInUseFlag() ) |
---|
1712 | { |
---|
1713 | for( Int i = 0; i <= vps.getMaxLayersMinus1(); i++ ) |
---|
1714 | { |
---|
1715 | pcVPSVUI->setTilesInUseFlag( i, m_tilesInUseFlag[ i ] ); |
---|
1716 | if( pcVPSVUI->getTilesInUseFlag( i ) ) |
---|
1717 | { |
---|
1718 | pcVPSVUI->setLoopFilterNotAcrossTilesFlag( i, m_loopFilterNotAcrossTilesFlag[ i ] ); |
---|
1719 | } |
---|
1720 | } |
---|
1721 | |
---|
1722 | for( Int i = 1; i <= vps.getMaxLayersMinus1(); i++ ) |
---|
1723 | { |
---|
1724 | for( Int j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ) ; j++ ) |
---|
1725 | { |
---|
1726 | Int layerIdx = vps.getLayerIdInVps( vps.getRefLayerId(vps.getLayerIdInNuh( i ) , j )); |
---|
1727 | if( pcVPSVUI->getTilesInUseFlag( i ) && pcVPSVUI->getTilesInUseFlag( layerIdx ) ) |
---|
1728 | { |
---|
1729 | pcVPSVUI->setTileBoundariesAlignedFlag( i, j, m_tileBoundariesAlignedFlag[i][j] ); |
---|
1730 | } |
---|
1731 | } |
---|
1732 | } |
---|
1733 | } |
---|
1734 | |
---|
1735 | pcVPSVUI->setWppNotInUseFlag( m_wppNotInUseFlag ); |
---|
1736 | |
---|
1737 | if( !pcVPSVUI->getWppNotInUseFlag( ) ) |
---|
1738 | { |
---|
1739 | for( Int i = 1; i <= vps.getMaxLayersMinus1(); i++ ) |
---|
1740 | { |
---|
1741 | pcVPSVUI->setWppInUseFlag( i, m_wppInUseFlag[ i ]); |
---|
1742 | } |
---|
1743 | } |
---|
1744 | |
---|
1745 | pcVPSVUI->setIlpRestrictedRefLayersFlag( m_ilpRestrictedRefLayersFlag ); |
---|
1746 | |
---|
1747 | if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) ) |
---|
1748 | { |
---|
1749 | for( Int i = 1; i <= vps.getMaxLayersMinus1(); i++ ) |
---|
1750 | { |
---|
1751 | for( Int j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ); j++ ) |
---|
1752 | { |
---|
1753 | if ( m_minSpatialSegmentOffsetPlus1[i].size() > j ) |
---|
1754 | { |
---|
1755 | pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, m_minSpatialSegmentOffsetPlus1[i][j] ); |
---|
1756 | } |
---|
1757 | if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 ) |
---|
1758 | { |
---|
1759 | if ( m_ctuBasedOffsetEnabledFlag[i].size() > j ) |
---|
1760 | { |
---|
1761 | pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, m_ctuBasedOffsetEnabledFlag[i][j] ); |
---|
1762 | } |
---|
1763 | if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) ) |
---|
1764 | { |
---|
1765 | if ( m_minHorizontalCtuOffsetPlus1[i].size() > j ) |
---|
1766 | { |
---|
1767 | pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, m_minHorizontalCtuOffsetPlus1[i][j] ); |
---|
1768 | } |
---|
1769 | } |
---|
1770 | } |
---|
1771 | } |
---|
1772 | } |
---|
1773 | } |
---|
1774 | pcVPSVUI->setVideoSignalInfoIdxPresentFlag( true ); |
---|
1775 | pcVPSVUI->setVpsNumVideoSignalInfoMinus1 ( 0 ); |
---|
1776 | |
---|
1777 | assert ( pcVPSVUI->getVideoSignalInfo( 0 ) == NULL ); |
---|
1778 | |
---|
1779 | TComVideoSignalInfo* videoSignalInfo = new TComVideoSignalInfo; |
---|
1780 | |
---|
1781 | videoSignalInfo->setColourPrimariesVps ( m_colourPrimaries ); |
---|
1782 | videoSignalInfo->setMatrixCoeffsVps ( m_matrixCoefficients ); |
---|
1783 | videoSignalInfo->setTransferCharacteristicsVps( m_transferCharacteristics ); |
---|
1784 | videoSignalInfo->setVideoVpsFormat ( m_videoFormat ); |
---|
1785 | videoSignalInfo->setVideoFullRangeVpsFlag ( m_videoFullRangeFlag ); |
---|
1786 | |
---|
1787 | pcVPSVUI->setVideoSignalInfo( 0, videoSignalInfo ); |
---|
1788 | |
---|
1789 | for (Int i = 0; i < m_numberOfLayers; i++) |
---|
1790 | { |
---|
1791 | pcVPSVUI->setVpsVideoSignalInfoIdx( i, 0 ); |
---|
1792 | } |
---|
1793 | pcVPSVUI->setVpsVuiBspHrdPresentFlag( false ); // TBD |
---|
1794 | } |
---|
1795 | else |
---|
1796 | { |
---|
1797 | pcVPSVUI->setCrossLayerIrapAlignedFlag ( false ); |
---|
1798 | } |
---|
1799 | } |
---|
1800 | #endif |
---|
1801 | #if H_3D |
---|
1802 | Void TAppEncTop::xSetVPSExtension2( TComVPS& vps ) |
---|
1803 | { |
---|
1804 | for ( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ ) |
---|
1805 | { |
---|
1806 | Bool isDepth = ( vps.getDepthId( layer ) == 1 ) ; |
---|
1807 | Bool isLayerZero = ( layer == 0 ); |
---|
1808 | |
---|
1809 | #if H_3D_ARP |
---|
1810 | vps.setUseAdvRP ( layer, ( isDepth || isLayerZero || !vps.getNumDirectRefLayers(layer) ) ? 0 : m_uiUseAdvResPred ); |
---|
1811 | vps.setARPStepNum ( layer, ( isDepth || isLayerZero || !vps.getNumDirectRefLayers(layer) ) ? 1 : H_3D_ARP_WFNR ); |
---|
1812 | #endif |
---|
1813 | #if H_3D_SPIVMP |
---|
1814 | if( isDepth ) |
---|
1815 | { |
---|
1816 | vps.setSubPULog2Size ( layer, (layer != 1) ? 6: 0 ); |
---|
1817 | } |
---|
1818 | else |
---|
1819 | { |
---|
1820 | vps.setSubPULog2Size ( layer, (!isLayerZero) ? m_iSubPULog2Size: 0 ); |
---|
1821 | } |
---|
1822 | #endif |
---|
1823 | |
---|
1824 | #if H_3D_DIM |
---|
1825 | vps.setVpsDepthModesFlag( layer, isDepth && !isLayerZero && (m_useDMM || m_useSDC || m_useDLT ) ); |
---|
1826 | #endif |
---|
1827 | |
---|
1828 | #if H_3D_IV_MERGE |
---|
1829 | if( !vps.getNumDirectRefLayers(layer) ) |
---|
1830 | { |
---|
1831 | vps.setIvMvPredFlag (layer, false); |
---|
1832 | } |
---|
1833 | else |
---|
1834 | { |
---|
1835 | if( isDepth ) |
---|
1836 | { |
---|
1837 | vps.setIvMvPredFlag ( layer, (layer != 1) && m_ivMvPredFlag[1] ); |
---|
1838 | } |
---|
1839 | else |
---|
1840 | { |
---|
1841 | vps.setIvMvPredFlag ( layer, !isLayerZero && m_ivMvPredFlag[0] ); |
---|
1842 | } |
---|
1843 | } |
---|
1844 | #endif |
---|
1845 | #if H_3D_NBDV_REF |
---|
1846 | vps.setDepthRefinementFlag ( layer, !isLayerZero && !isDepth && m_depthRefinementFlag ); |
---|
1847 | #endif |
---|
1848 | #if H_3D_VSP |
---|
1849 | vps.setViewSynthesisPredFlag( layer, !isLayerZero && !isDepth && vps.getNumDirectRefLayers(layer) && m_viewSynthesisPredFlag ); |
---|
1850 | #endif |
---|
1851 | #if H_3D_DBBP |
---|
1852 | vps.setUseDBBP ( layer, !isLayerZero && !isDepth && m_bUseDBBP ); |
---|
1853 | #endif |
---|
1854 | #if H_3D_INTER_SDC |
---|
1855 | vps.setInterSDCFlag( layer, !isLayerZero && isDepth && m_bDepthInterSDCFlag ); |
---|
1856 | #endif |
---|
1857 | #if H_3D_IV_MERGE |
---|
1858 | vps.setMPIFlag( layer, !isLayerZero && isDepth && m_bMPIFlag ); |
---|
1859 | #endif |
---|
1860 | } |
---|
1861 | #if H_3D_SPIVMP |
---|
1862 | vps.setSubPUMPILog2Size( m_iSubPUMPILog2Size ); |
---|
1863 | #endif |
---|
1864 | #if H_3D |
---|
1865 | vps.setIvMvScalingFlag( m_ivMvScalingFlag ); |
---|
1866 | #endif |
---|
1867 | } |
---|
1868 | |
---|
1869 | Void TAppEncTop::xDeriveDltArray( TComVPS& vps, TComDLT& dlt ) |
---|
1870 | { |
---|
1871 | Int iNumDepthViews = 0; |
---|
1872 | Bool bDltPresentFlag = false; |
---|
1873 | |
---|
1874 | for ( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ ) |
---|
1875 | { |
---|
1876 | Bool isDepth = ( vps.getDepthId( layer ) == 1 ); |
---|
1877 | |
---|
1878 | if ( isDepth ) |
---|
1879 | { |
---|
1880 | iNumDepthViews++; |
---|
1881 | } |
---|
1882 | |
---|
1883 | dlt.setUseDLTFlag( layer , isDepth && m_useDLT ); |
---|
1884 | if( dlt.getUseDLTFlag( layer ) ) |
---|
1885 | { |
---|
1886 | xAnalyzeInputBaseDepth(layer, max(m_iIntraPeriod[layer], 24), &vps, &dlt); |
---|
1887 | bDltPresentFlag = bDltPresentFlag || dlt.getUseDLTFlag(layer); |
---|
1888 | #if H_3D_DELTA_DLT |
---|
1889 | dlt.setInterViewDltPredEnableFlag(layer, (dlt.getUseDLTFlag(layer) && (layer>1))); |
---|
1890 | #endif |
---|
1891 | } |
---|
1892 | } |
---|
1893 | |
---|
1894 | dlt.setDltPresentFlag( bDltPresentFlag ); |
---|
1895 | dlt.setNumDepthViews ( iNumDepthViews ); |
---|
1896 | } |
---|
1897 | #endif |
---|
1898 | //! \} |
---|