1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TEncGOP.cpp |
---|
35 | \brief GOP encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include <list> |
---|
39 | #include <algorithm> |
---|
40 | #include <functional> |
---|
41 | |
---|
42 | #include "TEncTop.h" |
---|
43 | #include "TEncGOP.h" |
---|
44 | #include "TEncAnalyze.h" |
---|
45 | #include "libmd5/MD5.h" |
---|
46 | #include "TLibCommon/SEI.h" |
---|
47 | #include "TLibCommon/NAL.h" |
---|
48 | #include "NALwrite.h" |
---|
49 | #include <time.h> |
---|
50 | #include <math.h> |
---|
51 | |
---|
52 | using namespace std; |
---|
53 | //! \ingroup TLibEncoder |
---|
54 | //! \{ |
---|
55 | |
---|
56 | // ==================================================================================================================== |
---|
57 | // Constructor / destructor / initialization / destroy |
---|
58 | // ==================================================================================================================== |
---|
59 | Int getLSB(Int poc, Int maxLSB) |
---|
60 | { |
---|
61 | if (poc >= 0) |
---|
62 | { |
---|
63 | return poc % maxLSB; |
---|
64 | } |
---|
65 | else |
---|
66 | { |
---|
67 | return (maxLSB - ((-poc) % maxLSB)) % maxLSB; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | TEncGOP::TEncGOP() |
---|
72 | { |
---|
73 | m_iLastIDR = 0; |
---|
74 | m_iGopSize = 0; |
---|
75 | m_iNumPicCoded = 0; //Niko |
---|
76 | m_bFirst = true; |
---|
77 | |
---|
78 | m_pcCfg = NULL; |
---|
79 | m_pcSliceEncoder = NULL; |
---|
80 | m_pcListPic = NULL; |
---|
81 | |
---|
82 | m_pcEntropyCoder = NULL; |
---|
83 | m_pcCavlcCoder = NULL; |
---|
84 | m_pcSbacCoder = NULL; |
---|
85 | m_pcBinCABAC = NULL; |
---|
86 | |
---|
87 | m_bSeqFirst = true; |
---|
88 | |
---|
89 | m_bRefreshPending = 0; |
---|
90 | m_pocCRA = 0; |
---|
91 | m_numLongTermRefPicSPS = 0; |
---|
92 | ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps)); |
---|
93 | ::memset(m_ltRefPicUsedByCurrPicFlag, 0, sizeof(m_ltRefPicUsedByCurrPicFlag)); |
---|
94 | m_cpbRemovalDelay = 0; |
---|
95 | m_lastBPSEI = 0; |
---|
96 | xResetNonNestedSEIPresentFlags(); |
---|
97 | xResetNestedSEIPresentFlags(); |
---|
98 | #if SVC_UPSAMPLING |
---|
99 | m_pcPredSearch = NULL; |
---|
100 | #endif |
---|
101 | return; |
---|
102 | } |
---|
103 | |
---|
104 | TEncGOP::~TEncGOP() |
---|
105 | { |
---|
106 | } |
---|
107 | |
---|
108 | /** Create list to contain pointers to LCU start addresses of slice. |
---|
109 | */ |
---|
110 | #if SVC_EXTENSION |
---|
111 | Void TEncGOP::create( UInt layerId ) |
---|
112 | { |
---|
113 | m_bLongtermTestPictureHasBeenCoded = 0; |
---|
114 | m_bLongtermTestPictureHasBeenCoded2 = 0; |
---|
115 | m_layerId = layerId; |
---|
116 | } |
---|
117 | #else |
---|
118 | Void TEncGOP::create() |
---|
119 | { |
---|
120 | m_bLongtermTestPictureHasBeenCoded = 0; |
---|
121 | m_bLongtermTestPictureHasBeenCoded2 = 0; |
---|
122 | } |
---|
123 | #endif |
---|
124 | |
---|
125 | Void TEncGOP::destroy() |
---|
126 | { |
---|
127 | } |
---|
128 | |
---|
129 | Void TEncGOP::init ( TEncTop* pcTEncTop ) |
---|
130 | { |
---|
131 | m_pcEncTop = pcTEncTop; |
---|
132 | m_pcCfg = pcTEncTop; |
---|
133 | m_pcSliceEncoder = pcTEncTop->getSliceEncoder(); |
---|
134 | m_pcListPic = pcTEncTop->getListPic(); |
---|
135 | |
---|
136 | m_pcEntropyCoder = pcTEncTop->getEntropyCoder(); |
---|
137 | m_pcCavlcCoder = pcTEncTop->getCavlcCoder(); |
---|
138 | m_pcSbacCoder = pcTEncTop->getSbacCoder(); |
---|
139 | m_pcBinCABAC = pcTEncTop->getBinCABAC(); |
---|
140 | m_pcLoopFilter = pcTEncTop->getLoopFilter(); |
---|
141 | m_pcBitCounter = pcTEncTop->getBitCounter(); |
---|
142 | |
---|
143 | //--Adaptive Loop filter |
---|
144 | m_pcSAO = pcTEncTop->getSAO(); |
---|
145 | m_pcRateCtrl = pcTEncTop->getRateCtrl(); |
---|
146 | m_lastBPSEI = 0; |
---|
147 | m_totalCoded = 0; |
---|
148 | |
---|
149 | #if SVC_EXTENSION |
---|
150 | m_ppcTEncTop = pcTEncTop->getLayerEnc(); |
---|
151 | #endif |
---|
152 | #if SVC_UPSAMPLING |
---|
153 | m_pcPredSearch = pcTEncTop->getPredSearch(); ///< encoder search class |
---|
154 | #endif |
---|
155 | } |
---|
156 | |
---|
157 | SEIActiveParameterSets* TEncGOP::xCreateSEIActiveParameterSets (TComSPS *sps) |
---|
158 | { |
---|
159 | SEIActiveParameterSets *seiActiveParameterSets = new SEIActiveParameterSets(); |
---|
160 | seiActiveParameterSets->activeVPSId = m_pcCfg->getVPS()->getVPSId(); |
---|
161 | seiActiveParameterSets->m_fullRandomAccessFlag = false; |
---|
162 | seiActiveParameterSets->m_noParamSetUpdateFlag = false; |
---|
163 | seiActiveParameterSets->numSpsIdsMinus1 = 0; |
---|
164 | seiActiveParameterSets->activeSeqParamSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1); |
---|
165 | seiActiveParameterSets->activeSeqParamSetId[0] = sps->getSPSId(); |
---|
166 | return seiActiveParameterSets; |
---|
167 | } |
---|
168 | |
---|
169 | #if M0043_LAYERS_PRESENT_SEI |
---|
170 | SEILayersPresent* TEncGOP::xCreateSEILayersPresent () |
---|
171 | { |
---|
172 | UInt i = 0; |
---|
173 | SEILayersPresent *seiLayersPresent = new SEILayersPresent(); |
---|
174 | seiLayersPresent->m_activeVpsId = m_pcCfg->getVPS()->getVPSId(); |
---|
175 | seiLayersPresent->m_vpsMaxLayers = m_pcCfg->getVPS()->getMaxLayers(); |
---|
176 | for ( ; i < seiLayersPresent->m_vpsMaxLayers; i++) |
---|
177 | { |
---|
178 | seiLayersPresent->m_layerPresentFlag[i] = true; |
---|
179 | } |
---|
180 | for ( ; i < MAX_LAYERS; i++) |
---|
181 | { |
---|
182 | seiLayersPresent->m_layerPresentFlag[i] = false; |
---|
183 | } |
---|
184 | return seiLayersPresent; |
---|
185 | } |
---|
186 | #endif |
---|
187 | |
---|
188 | SEIFramePacking* TEncGOP::xCreateSEIFramePacking() |
---|
189 | { |
---|
190 | SEIFramePacking *seiFramePacking = new SEIFramePacking(); |
---|
191 | seiFramePacking->m_arrangementId = m_pcCfg->getFramePackingArrangementSEIId(); |
---|
192 | seiFramePacking->m_arrangementCancelFlag = 0; |
---|
193 | seiFramePacking->m_arrangementType = m_pcCfg->getFramePackingArrangementSEIType(); |
---|
194 | assert((seiFramePacking->m_arrangementType > 2) && (seiFramePacking->m_arrangementType < 6) ); |
---|
195 | seiFramePacking->m_quincunxSamplingFlag = m_pcCfg->getFramePackingArrangementSEIQuincunx(); |
---|
196 | seiFramePacking->m_contentInterpretationType = m_pcCfg->getFramePackingArrangementSEIInterpretation(); |
---|
197 | seiFramePacking->m_spatialFlippingFlag = 0; |
---|
198 | seiFramePacking->m_frame0FlippedFlag = 0; |
---|
199 | seiFramePacking->m_fieldViewsFlag = (seiFramePacking->m_arrangementType == 2); |
---|
200 | seiFramePacking->m_currentFrameIsFrame0Flag = ((seiFramePacking->m_arrangementType == 5) && m_iNumPicCoded&1); |
---|
201 | seiFramePacking->m_frame0SelfContainedFlag = 0; |
---|
202 | seiFramePacking->m_frame1SelfContainedFlag = 0; |
---|
203 | seiFramePacking->m_frame0GridPositionX = 0; |
---|
204 | seiFramePacking->m_frame0GridPositionY = 0; |
---|
205 | seiFramePacking->m_frame1GridPositionX = 0; |
---|
206 | seiFramePacking->m_frame1GridPositionY = 0; |
---|
207 | seiFramePacking->m_arrangementReservedByte = 0; |
---|
208 | seiFramePacking->m_arrangementPersistenceFlag = true; |
---|
209 | seiFramePacking->m_upsampledAspectRatio = 0; |
---|
210 | return seiFramePacking; |
---|
211 | } |
---|
212 | |
---|
213 | SEIDisplayOrientation* TEncGOP::xCreateSEIDisplayOrientation() |
---|
214 | { |
---|
215 | SEIDisplayOrientation *seiDisplayOrientation = new SEIDisplayOrientation(); |
---|
216 | seiDisplayOrientation->cancelFlag = false; |
---|
217 | seiDisplayOrientation->horFlip = false; |
---|
218 | seiDisplayOrientation->verFlip = false; |
---|
219 | seiDisplayOrientation->anticlockwiseRotation = m_pcCfg->getDisplayOrientationSEIAngle(); |
---|
220 | return seiDisplayOrientation; |
---|
221 | } |
---|
222 | |
---|
223 | SEIToneMappingInfo* TEncGOP::xCreateSEIToneMappingInfo() |
---|
224 | { |
---|
225 | SEIToneMappingInfo *seiToneMappingInfo = new SEIToneMappingInfo(); |
---|
226 | seiToneMappingInfo->m_toneMapId = m_pcCfg->getTMISEIToneMapId(); |
---|
227 | seiToneMappingInfo->m_toneMapCancelFlag = m_pcCfg->getTMISEIToneMapCancelFlag(); |
---|
228 | seiToneMappingInfo->m_toneMapPersistenceFlag = m_pcCfg->getTMISEIToneMapPersistenceFlag(); |
---|
229 | |
---|
230 | seiToneMappingInfo->m_codedDataBitDepth = m_pcCfg->getTMISEICodedDataBitDepth(); |
---|
231 | assert(seiToneMappingInfo->m_codedDataBitDepth >= 8 && seiToneMappingInfo->m_codedDataBitDepth <= 14); |
---|
232 | seiToneMappingInfo->m_targetBitDepth = m_pcCfg->getTMISEITargetBitDepth(); |
---|
233 | assert( seiToneMappingInfo->m_targetBitDepth >= 1 && seiToneMappingInfo->m_targetBitDepth <= 17 ); |
---|
234 | seiToneMappingInfo->m_modelId = m_pcCfg->getTMISEIModelID(); |
---|
235 | assert(seiToneMappingInfo->m_modelId >=0 &&seiToneMappingInfo->m_modelId<=4); |
---|
236 | |
---|
237 | switch( seiToneMappingInfo->m_modelId) |
---|
238 | { |
---|
239 | case 0: |
---|
240 | { |
---|
241 | seiToneMappingInfo->m_minValue = m_pcCfg->getTMISEIMinValue(); |
---|
242 | seiToneMappingInfo->m_maxValue = m_pcCfg->getTMISEIMaxValue(); |
---|
243 | break; |
---|
244 | } |
---|
245 | case 1: |
---|
246 | { |
---|
247 | seiToneMappingInfo->m_sigmoidMidpoint = m_pcCfg->getTMISEISigmoidMidpoint(); |
---|
248 | seiToneMappingInfo->m_sigmoidWidth = m_pcCfg->getTMISEISigmoidWidth(); |
---|
249 | break; |
---|
250 | } |
---|
251 | case 2: |
---|
252 | { |
---|
253 | UInt num = 1u<<(seiToneMappingInfo->m_targetBitDepth); |
---|
254 | seiToneMappingInfo->m_startOfCodedInterval.resize(num); |
---|
255 | Int* ptmp = m_pcCfg->getTMISEIStartOfCodedInterva(); |
---|
256 | if(ptmp) |
---|
257 | { |
---|
258 | for(int i=0; i<num;i++) |
---|
259 | { |
---|
260 | seiToneMappingInfo->m_startOfCodedInterval[i] = ptmp[i]; |
---|
261 | } |
---|
262 | } |
---|
263 | break; |
---|
264 | } |
---|
265 | case 3: |
---|
266 | { |
---|
267 | seiToneMappingInfo->m_numPivots = m_pcCfg->getTMISEINumPivots(); |
---|
268 | seiToneMappingInfo->m_codedPivotValue.resize(seiToneMappingInfo->m_numPivots); |
---|
269 | seiToneMappingInfo->m_targetPivotValue.resize(seiToneMappingInfo->m_numPivots); |
---|
270 | Int* ptmpcoded = m_pcCfg->getTMISEICodedPivotValue(); |
---|
271 | Int* ptmptarget = m_pcCfg->getTMISEITargetPivotValue(); |
---|
272 | if(ptmpcoded&&ptmptarget) |
---|
273 | { |
---|
274 | for(int i=0; i<(seiToneMappingInfo->m_numPivots);i++) |
---|
275 | { |
---|
276 | seiToneMappingInfo->m_codedPivotValue[i]=ptmpcoded[i]; |
---|
277 | seiToneMappingInfo->m_targetPivotValue[i]=ptmptarget[i]; |
---|
278 | } |
---|
279 | } |
---|
280 | break; |
---|
281 | } |
---|
282 | case 4: |
---|
283 | { |
---|
284 | seiToneMappingInfo->m_cameraIsoSpeedIdc = m_pcCfg->getTMISEICameraIsoSpeedIdc(); |
---|
285 | seiToneMappingInfo->m_cameraIsoSpeedValue = m_pcCfg->getTMISEICameraIsoSpeedValue(); |
---|
286 | assert( seiToneMappingInfo->m_cameraIsoSpeedValue !=0 ); |
---|
287 | seiToneMappingInfo->m_exposureCompensationValueSignFlag = m_pcCfg->getTMISEIExposureCompensationValueSignFlag(); |
---|
288 | seiToneMappingInfo->m_exposureCompensationValueNumerator = m_pcCfg->getTMISEIExposureCompensationValueNumerator(); |
---|
289 | seiToneMappingInfo->m_exposureCompensationValueDenomIdc = m_pcCfg->getTMISEIExposureCompensationValueDenomIdc(); |
---|
290 | seiToneMappingInfo->m_refScreenLuminanceWhite = m_pcCfg->getTMISEIRefScreenLuminanceWhite(); |
---|
291 | seiToneMappingInfo->m_extendedRangeWhiteLevel = m_pcCfg->getTMISEIExtendedRangeWhiteLevel(); |
---|
292 | assert( seiToneMappingInfo->m_extendedRangeWhiteLevel >= 100 ); |
---|
293 | seiToneMappingInfo->m_nominalBlackLevelLumaCodeValue = m_pcCfg->getTMISEINominalBlackLevelLumaCodeValue(); |
---|
294 | seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue = m_pcCfg->getTMISEINominalWhiteLevelLumaCodeValue(); |
---|
295 | assert( seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue > seiToneMappingInfo->m_nominalBlackLevelLumaCodeValue ); |
---|
296 | seiToneMappingInfo->m_extendedWhiteLevelLumaCodeValue = m_pcCfg->getTMISEIExtendedWhiteLevelLumaCodeValue(); |
---|
297 | assert( seiToneMappingInfo->m_extendedWhiteLevelLumaCodeValue >= seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue ); |
---|
298 | break; |
---|
299 | } |
---|
300 | default: |
---|
301 | { |
---|
302 | assert(!"Undefined SEIToneMapModelId"); |
---|
303 | break; |
---|
304 | } |
---|
305 | } |
---|
306 | return seiToneMappingInfo; |
---|
307 | } |
---|
308 | |
---|
309 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
310 | SEIInterLayerConstrainedTileSets* TEncGOP::xCreateSEIInterLayerConstrainedTileSets() |
---|
311 | { |
---|
312 | SEIInterLayerConstrainedTileSets *seiInterLayerConstrainedTileSets = new SEIInterLayerConstrainedTileSets(); |
---|
313 | seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag = false; |
---|
314 | seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag = false; |
---|
315 | if (!seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag) |
---|
316 | { |
---|
317 | seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 = m_pcCfg->getIlNumSetsInMessage() - 1; |
---|
318 | if (seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1) |
---|
319 | { |
---|
320 | seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = m_pcCfg->getSkippedTileSetPresentFlag(); |
---|
321 | } |
---|
322 | else |
---|
323 | { |
---|
324 | seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = false; |
---|
325 | } |
---|
326 | seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 += seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag ? 1 : 0; |
---|
327 | for (UInt i = 0; i < m_pcCfg->getIlNumSetsInMessage(); i++) |
---|
328 | { |
---|
329 | seiInterLayerConstrainedTileSets->m_ilctsId[i] = i; |
---|
330 | seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i] = 0; |
---|
331 | for( UInt j = 0; j <= seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i]; j++) |
---|
332 | { |
---|
333 | seiInterLayerConstrainedTileSets->m_ilTopLeftTileIndex[i][j] = m_pcCfg->getTopLeftTileIndex(i); |
---|
334 | seiInterLayerConstrainedTileSets->m_ilBottomRightTileIndex[i][j] = m_pcCfg->getBottomRightTileIndex(i); |
---|
335 | } |
---|
336 | seiInterLayerConstrainedTileSets->m_ilcIdc[i] = m_pcCfg->getIlcIdc(i); |
---|
337 | if (seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag) |
---|
338 | { |
---|
339 | seiInterLayerConstrainedTileSets->m_ilExactSampleValueMatchFlag[i] = false; |
---|
340 | } |
---|
341 | } |
---|
342 | } |
---|
343 | |
---|
344 | return seiInterLayerConstrainedTileSets; |
---|
345 | } |
---|
346 | #endif |
---|
347 | |
---|
348 | Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps) |
---|
349 | { |
---|
350 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
351 | |
---|
352 | if(m_pcCfg->getActiveParameterSetsSEIEnabled()) |
---|
353 | { |
---|
354 | SEIActiveParameterSets *sei = xCreateSEIActiveParameterSets (sps); |
---|
355 | |
---|
356 | //nalu = NALUnit(NAL_UNIT_SEI); |
---|
357 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
358 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
359 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
360 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
361 | delete sei; |
---|
362 | m_activeParameterSetSEIPresentInAU = true; |
---|
363 | } |
---|
364 | |
---|
365 | #if M0043_LAYERS_PRESENT_SEI |
---|
366 | if(m_pcCfg->getLayersPresentSEIEnabled()) |
---|
367 | { |
---|
368 | SEILayersPresent *sei = xCreateSEILayersPresent (); |
---|
369 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
370 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
371 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
372 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
373 | delete sei; |
---|
374 | } |
---|
375 | #endif |
---|
376 | |
---|
377 | if(m_pcCfg->getFramePackingArrangementSEIEnabled()) |
---|
378 | { |
---|
379 | SEIFramePacking *sei = xCreateSEIFramePacking (); |
---|
380 | |
---|
381 | nalu = NALUnit(NAL_UNIT_PREFIX_SEI); |
---|
382 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
383 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
384 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
385 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
386 | delete sei; |
---|
387 | } |
---|
388 | if (m_pcCfg->getDisplayOrientationSEIAngle()) |
---|
389 | { |
---|
390 | SEIDisplayOrientation *sei = xCreateSEIDisplayOrientation(); |
---|
391 | |
---|
392 | nalu = NALUnit(NAL_UNIT_PREFIX_SEI); |
---|
393 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
394 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
395 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
396 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
397 | delete sei; |
---|
398 | } |
---|
399 | if(m_pcCfg->getToneMappingInfoSEIEnabled()) |
---|
400 | { |
---|
401 | SEIToneMappingInfo *sei = xCreateSEIToneMappingInfo (); |
---|
402 | |
---|
403 | nalu = NALUnit(NAL_UNIT_PREFIX_SEI); |
---|
404 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
405 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
406 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
407 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
408 | delete sei; |
---|
409 | } |
---|
410 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
411 | if(m_pcCfg->getInterLayerConstrainedTileSetsSEIEnabled()) |
---|
412 | { |
---|
413 | SEIInterLayerConstrainedTileSets *sei = xCreateSEIInterLayerConstrainedTileSets (); |
---|
414 | |
---|
415 | nalu = NALUnit(NAL_UNIT_PREFIX_SEI, 0, m_pcCfg->getNumLayer()-1); // For highest layer |
---|
416 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
417 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
418 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
419 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
420 | delete sei; |
---|
421 | } |
---|
422 | #endif |
---|
423 | } |
---|
424 | |
---|
425 | // ==================================================================================================================== |
---|
426 | // Public member functions |
---|
427 | // ==================================================================================================================== |
---|
428 | #if SVC_EXTENSION |
---|
429 | Void TEncGOP::compressGOP( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff) |
---|
430 | #else |
---|
431 | Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff) |
---|
432 | #endif |
---|
433 | { |
---|
434 | TComPic* pcPic; |
---|
435 | TComPicYuv* pcPicYuvRecOut; |
---|
436 | TComSlice* pcSlice; |
---|
437 | TComOutputBitstream *pcBitstreamRedirect; |
---|
438 | pcBitstreamRedirect = new TComOutputBitstream; |
---|
439 | AccessUnit::iterator itLocationToPushSliceHeaderNALU; // used to store location where NALU containing slice header is to be inserted |
---|
440 | UInt uiOneBitstreamPerSliceLength = 0; |
---|
441 | TEncSbac* pcSbacCoders = NULL; |
---|
442 | TComOutputBitstream* pcSubstreamsOut = NULL; |
---|
443 | |
---|
444 | xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut, isField ); |
---|
445 | |
---|
446 | m_iNumPicCoded = 0; |
---|
447 | SEIPictureTiming pictureTimingSEI; |
---|
448 | Bool writeSOP = m_pcCfg->getSOPDescriptionSEIEnabled(); |
---|
449 | // Initialize Scalable Nesting SEI with single layer values |
---|
450 | SEIScalableNesting scalableNestingSEI; |
---|
451 | scalableNestingSEI.m_bitStreamSubsetFlag = 1; // If the nested SEI messages are picture buffereing SEI mesages, picure timing SEI messages or sub-picture timing SEI messages, bitstream_subset_flag shall be equal to 1 |
---|
452 | scalableNestingSEI.m_nestingOpFlag = 0; |
---|
453 | scalableNestingSEI.m_nestingNumOpsMinus1 = 0; //nesting_num_ops_minus1 |
---|
454 | scalableNestingSEI.m_allLayersFlag = 0; |
---|
455 | scalableNestingSEI.m_nestingNoOpMaxTemporalIdPlus1 = 6 + 1; //nesting_no_op_max_temporal_id_plus1 |
---|
456 | scalableNestingSEI.m_nestingNumLayersMinus1 = 1 - 1; //nesting_num_layers_minus1 |
---|
457 | scalableNestingSEI.m_nestingLayerId[0] = 0; |
---|
458 | scalableNestingSEI.m_callerOwnsSEIs = true; |
---|
459 | Int picSptDpbOutputDuDelay = 0; |
---|
460 | UInt *accumBitsDU = NULL; |
---|
461 | UInt *accumNalsDU = NULL; |
---|
462 | SEIDecodingUnitInfo decodingUnitInfoSEI; |
---|
463 | #if SVC_EXTENSION |
---|
464 | for ( Int iGOPid=iPicIdInGOP; iGOPid < iPicIdInGOP+1; iGOPid++ ) |
---|
465 | #else |
---|
466 | for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ ) |
---|
467 | #endif |
---|
468 | { |
---|
469 | UInt uiColDir = 1; |
---|
470 | //-- For time output for each slice |
---|
471 | long iBeforeTime = clock(); |
---|
472 | |
---|
473 | //select uiColDir |
---|
474 | Int iCloseLeft=1, iCloseRight=-1; |
---|
475 | for(Int i = 0; i<m_pcCfg->getGOPEntry(iGOPid).m_numRefPics; i++) |
---|
476 | { |
---|
477 | Int iRef = m_pcCfg->getGOPEntry(iGOPid).m_referencePics[i]; |
---|
478 | if(iRef>0&&(iRef<iCloseRight||iCloseRight==-1)) |
---|
479 | { |
---|
480 | iCloseRight=iRef; |
---|
481 | } |
---|
482 | else if(iRef<0&&(iRef>iCloseLeft||iCloseLeft==1)) |
---|
483 | { |
---|
484 | iCloseLeft=iRef; |
---|
485 | } |
---|
486 | } |
---|
487 | if(iCloseRight>-1) |
---|
488 | { |
---|
489 | iCloseRight=iCloseRight+m_pcCfg->getGOPEntry(iGOPid).m_POC-1; |
---|
490 | } |
---|
491 | if(iCloseLeft<1) |
---|
492 | { |
---|
493 | iCloseLeft=iCloseLeft+m_pcCfg->getGOPEntry(iGOPid).m_POC-1; |
---|
494 | while(iCloseLeft<0) |
---|
495 | { |
---|
496 | iCloseLeft+=m_iGopSize; |
---|
497 | } |
---|
498 | } |
---|
499 | Int iLeftQP=0, iRightQP=0; |
---|
500 | for(Int i=0; i<m_iGopSize; i++) |
---|
501 | { |
---|
502 | if(m_pcCfg->getGOPEntry(i).m_POC==(iCloseLeft%m_iGopSize)+1) |
---|
503 | { |
---|
504 | iLeftQP= m_pcCfg->getGOPEntry(i).m_QPOffset; |
---|
505 | } |
---|
506 | if (m_pcCfg->getGOPEntry(i).m_POC==(iCloseRight%m_iGopSize)+1) |
---|
507 | { |
---|
508 | iRightQP=m_pcCfg->getGOPEntry(i).m_QPOffset; |
---|
509 | } |
---|
510 | } |
---|
511 | if(iCloseRight>-1&&iRightQP<iLeftQP) |
---|
512 | { |
---|
513 | uiColDir=0; |
---|
514 | } |
---|
515 | |
---|
516 | /////////////////////////////////////////////////////////////////////////////////////////////////// Initial to start encoding |
---|
517 | Int iTimeOffset; |
---|
518 | Int pocCurr; |
---|
519 | |
---|
520 | if(iPOCLast == 0) //case first frame or first top field |
---|
521 | { |
---|
522 | pocCurr=0; |
---|
523 | iTimeOffset = 1; |
---|
524 | } |
---|
525 | else if(iPOCLast == 1 && isField) //case first bottom field, just like the first frame, the poc computation is not right anymore, we set the right value |
---|
526 | { |
---|
527 | pocCurr = 1; |
---|
528 | iTimeOffset = 1; |
---|
529 | } |
---|
530 | else |
---|
531 | { |
---|
532 | pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - isField; |
---|
533 | iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC; |
---|
534 | } |
---|
535 | |
---|
536 | if(pocCurr>=m_pcCfg->getFramesToBeEncoded()) |
---|
537 | { |
---|
538 | continue; |
---|
539 | } |
---|
540 | |
---|
541 | #if M0040_ADAPTIVE_RESOLUTION_CHANGE |
---|
542 | if (m_pcEncTop->getAdaptiveResolutionChange() > 0 && ((m_layerId == 1 && pocCurr < m_pcEncTop->getAdaptiveResolutionChange()) || |
---|
543 | (m_layerId == 0 && pocCurr > m_pcEncTop->getAdaptiveResolutionChange())) ) |
---|
544 | { |
---|
545 | continue; |
---|
546 | } |
---|
547 | #endif |
---|
548 | |
---|
549 | if( getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
---|
550 | { |
---|
551 | m_iLastIDR = pocCurr; |
---|
552 | } |
---|
553 | // start a new access unit: create an entry in the list of output access units |
---|
554 | accessUnitsInGOP.push_back(AccessUnit()); |
---|
555 | AccessUnit& accessUnit = accessUnitsInGOP.back(); |
---|
556 | xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr, isField ); |
---|
557 | |
---|
558 | // Slice data initialization |
---|
559 | pcPic->clearSliceBuffer(); |
---|
560 | assert(pcPic->getNumAllocatedSlice() == 1); |
---|
561 | m_pcSliceEncoder->setSliceIdx(0); |
---|
562 | pcPic->setCurrSliceIdx(0); |
---|
563 | #if SVC_EXTENSION |
---|
564 | pcPic->setLayerId( m_layerId ); |
---|
565 | m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getVPS(), isField ); |
---|
566 | #else |
---|
567 | m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), isField ); |
---|
568 | #endif |
---|
569 | |
---|
570 | //Set Frame/Field coding |
---|
571 | pcSlice->getPic()->setField(isField); |
---|
572 | |
---|
573 | #if POC_RESET_FLAG |
---|
574 | if( !pcSlice->getPocResetFlag() ) // For picture that are not reset, we should adjust the value of POC calculated from the configuration files. |
---|
575 | { |
---|
576 | // Subtract POC adjustment value until now. |
---|
577 | pcSlice->setPOC( pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue() ); |
---|
578 | } |
---|
579 | else |
---|
580 | { |
---|
581 | // Check if this is the first slice in the picture |
---|
582 | // In the encoder, the POC values are copied along with copySliceInfo, so we only need |
---|
583 | // to do this for the first slice. |
---|
584 | Int pocAdjustValue = pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue(); |
---|
585 | if( pcSlice->getSliceIdx() == 0 ) |
---|
586 | { |
---|
587 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
588 | |
---|
589 | // Iterate through all picture in DPB |
---|
590 | while( iterPic != rcListPic.end() ) |
---|
591 | { |
---|
592 | TComPic *dpbPic = *iterPic; |
---|
593 | if( dpbPic->getPOC() == pocCurr ) |
---|
594 | { |
---|
595 | if( dpbPic->getReconMark() ) |
---|
596 | { |
---|
597 | assert( !( dpbPic->getSlice(0)->isReferenced() ) && !( dpbPic->getOutputMark() ) ); |
---|
598 | } |
---|
599 | } |
---|
600 | // Check if the picture pointed to by iterPic is either used for reference or |
---|
601 | // needed for output, are in the same layer, and not the current picture. |
---|
602 | if( /* ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) ) |
---|
603 | && */ ( dpbPic->getLayerId() == pcSlice->getLayerId() ) |
---|
604 | && ( dpbPic->getReconMark() ) |
---|
605 | ) |
---|
606 | { |
---|
607 | for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--) |
---|
608 | { |
---|
609 | TComSlice *slice = dpbPic->getSlice(i); |
---|
610 | TComReferencePictureSet *rps = slice->getRPS(); |
---|
611 | slice->setPOC( dpbPic->getSlice(i)->getPOC() - pocAdjustValue ); |
---|
612 | |
---|
613 | // Also adjust the POC value stored in the RPS of each such slice |
---|
614 | for(Int j = rps->getNumberOfPictures(); j >= 0; j--) |
---|
615 | { |
---|
616 | rps->setPOC( j, rps->getPOC(j) - pocAdjustValue ); |
---|
617 | } |
---|
618 | // Also adjust the value of refPOC |
---|
619 | for(Int k = 0; k < 2; k++) // For List 0 and List 1 |
---|
620 | { |
---|
621 | RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0; |
---|
622 | for(Int j = 0; j < slice->getNumRefIdx(list); j++) |
---|
623 | { |
---|
624 | slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j); |
---|
625 | } |
---|
626 | } |
---|
627 | } |
---|
628 | } |
---|
629 | iterPic++; |
---|
630 | } |
---|
631 | m_pcEncTop->setPocAdjustmentValue( m_pcEncTop->getPocAdjustmentValue() + pocAdjustValue ); |
---|
632 | } |
---|
633 | pcSlice->setPocValueBeforeReset( pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue() + pocAdjustValue ); |
---|
634 | pcSlice->setPOC( 0 ); |
---|
635 | } |
---|
636 | #endif |
---|
637 | #if O0149_CROSS_LAYER_BLA_FLAG |
---|
638 | if( m_layerId == 0 && (getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP) ) |
---|
639 | { |
---|
640 | pcSlice->setCrossLayerBLAFlag(m_pcEncTop->getCrossLayerBLAFlag()); |
---|
641 | } |
---|
642 | else |
---|
643 | { |
---|
644 | pcSlice->setCrossLayerBLAFlag(false); |
---|
645 | } |
---|
646 | #endif |
---|
647 | #if NO_CLRAS_OUTPUT_FLAG |
---|
648 | if (m_layerId == 0 && |
---|
649 | (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
650 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
651 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
652 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
653 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
654 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)) |
---|
655 | { |
---|
656 | if (m_bFirst) |
---|
657 | { |
---|
658 | m_pcEncTop->setNoClrasOutputFlag(true); |
---|
659 | } |
---|
660 | else if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
661 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
662 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP) |
---|
663 | { |
---|
664 | m_pcEncTop->setNoClrasOutputFlag(true); |
---|
665 | } |
---|
666 | #if O0149_CROSS_LAYER_BLA_FLAG |
---|
667 | else if ((pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP) && |
---|
668 | pcSlice->getCrossLayerBLAFlag()) |
---|
669 | { |
---|
670 | m_pcEncTop->setNoClrasOutputFlag(true); |
---|
671 | } |
---|
672 | #endif |
---|
673 | else |
---|
674 | { |
---|
675 | m_pcEncTop->setNoClrasOutputFlag(false); |
---|
676 | } |
---|
677 | if (m_pcEncTop->getNoClrasOutputFlag()) |
---|
678 | { |
---|
679 | for (UInt i = 0; i < m_pcCfg->getNumLayer(); i++) |
---|
680 | { |
---|
681 | m_ppcTEncTop[i]->setLayerInitializedFlag(false); |
---|
682 | m_ppcTEncTop[i]->setFirstPicInLayerDecodedFlag(false); |
---|
683 | } |
---|
684 | } |
---|
685 | } |
---|
686 | #endif |
---|
687 | #if M0040_ADAPTIVE_RESOLUTION_CHANGE |
---|
688 | if (m_pcEncTop->getAdaptiveResolutionChange() > 0 && m_layerId == 1 && pocCurr > m_pcEncTop->getAdaptiveResolutionChange()) |
---|
689 | { |
---|
690 | pcSlice->setActiveNumILRRefIdx(0); |
---|
691 | pcSlice->setInterLayerPredEnabledFlag(false); |
---|
692 | #if M0457_COL_PICTURE_SIGNALING |
---|
693 | pcSlice->setMFMEnabledFlag(false); |
---|
694 | #if !REMOVE_COL_PICTURE_SIGNALING |
---|
695 | pcSlice->setAltColIndicationFlag(false); |
---|
696 | #endif |
---|
697 | #endif |
---|
698 | } |
---|
699 | #endif |
---|
700 | |
---|
701 | #if M0457_IL_SAMPLE_PRED_ONLY_FLAG |
---|
702 | pcSlice->setNumSamplePredRefLayers( m_pcEncTop->getNumSamplePredRefLayers() ); |
---|
703 | pcSlice->setInterLayerSamplePredOnlyFlag( 0 ); |
---|
704 | if( pcSlice->getNumSamplePredRefLayers() > 0 && pcSlice->getActiveNumILRRefIdx() > 0 ) |
---|
705 | { |
---|
706 | if( m_pcEncTop->getIlSampleOnlyPred() > 0 ) |
---|
707 | { |
---|
708 | pcSlice->setInterLayerSamplePredOnlyFlag( true ); |
---|
709 | } |
---|
710 | } |
---|
711 | #endif |
---|
712 | |
---|
713 | pcSlice->setLastIDR(m_iLastIDR); |
---|
714 | pcSlice->setSliceIdx(0); |
---|
715 | //set default slice level flag to the same as SPS level flag |
---|
716 | pcSlice->setLFCrossSliceBoundaryFlag( pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() ); |
---|
717 | pcSlice->setScalingList ( m_pcEncTop->getScalingList() ); |
---|
718 | if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF) |
---|
719 | { |
---|
720 | m_pcEncTop->getTrQuant()->setFlatScalingList(); |
---|
721 | m_pcEncTop->getTrQuant()->setUseScalingList(false); |
---|
722 | m_pcEncTop->getSPS()->setScalingListPresentFlag(false); |
---|
723 | m_pcEncTop->getPPS()->setScalingListPresentFlag(false); |
---|
724 | } |
---|
725 | else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_DEFAULT) |
---|
726 | { |
---|
727 | #if SCALINGLIST_INFERRING |
---|
728 | // inferring of the scaling list can be moved to the config file |
---|
729 | UInt refLayerId = 0; |
---|
730 | if( m_layerId > 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() && m_pcEncTop->getVPS()->getRecursiveRefLayerFlag( m_layerId, refLayerId ) ) |
---|
731 | { |
---|
732 | m_pcEncTop->getSPS()->setInferScalingListFlag( true ); |
---|
733 | m_pcEncTop->getSPS()->setScalingListRefLayerId( refLayerId ); |
---|
734 | m_pcEncTop->getSPS()->setScalingListPresentFlag( false ); |
---|
735 | m_pcEncTop->getPPS()->setInferScalingListFlag( false ); |
---|
736 | m_pcEncTop->getPPS()->setScalingListPresentFlag( false ); |
---|
737 | |
---|
738 | // infer the scaling list from the reference layer |
---|
739 | pcSlice->setScalingList ( m_ppcTEncTop[refLayerId]->getScalingList() ); |
---|
740 | } |
---|
741 | else |
---|
742 | { |
---|
743 | #endif |
---|
744 | pcSlice->setDefaultScalingList (); |
---|
745 | m_pcEncTop->getSPS()->setScalingListPresentFlag(false); |
---|
746 | m_pcEncTop->getPPS()->setScalingListPresentFlag(false); |
---|
747 | |
---|
748 | #if SCALINGLIST_INFERRING |
---|
749 | } |
---|
750 | #endif |
---|
751 | |
---|
752 | m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList()); |
---|
753 | m_pcEncTop->getTrQuant()->setUseScalingList(true); |
---|
754 | } |
---|
755 | else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_FILE_READ) |
---|
756 | { |
---|
757 | #if SCALINGLIST_INFERRING |
---|
758 | // inferring of the scaling list can be moved to the config file |
---|
759 | UInt refLayerId = 0; |
---|
760 | if( m_layerId > 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() && m_pcEncTop->getVPS()->getRecursiveRefLayerFlag( m_layerId, refLayerId ) ) |
---|
761 | { |
---|
762 | m_pcEncTop->getSPS()->setInferScalingListFlag( true ); |
---|
763 | m_pcEncTop->getSPS()->setScalingListRefLayerId( refLayerId ); |
---|
764 | m_pcEncTop->getSPS()->setScalingListPresentFlag( false ); |
---|
765 | m_pcEncTop->getPPS()->setInferScalingListFlag( false ); |
---|
766 | m_pcEncTop->getPPS()->setScalingListPresentFlag( false ); |
---|
767 | |
---|
768 | // infer the scaling list from the reference layer |
---|
769 | pcSlice->setScalingList ( m_ppcTEncTop[refLayerId]->getScalingList() ); |
---|
770 | } |
---|
771 | else |
---|
772 | { |
---|
773 | #endif |
---|
774 | |
---|
775 | if(pcSlice->getScalingList()->xParseScalingList(m_pcCfg->getScalingListFile())) |
---|
776 | { |
---|
777 | pcSlice->setDefaultScalingList (); |
---|
778 | } |
---|
779 | |
---|
780 | pcSlice->getScalingList()->checkDcOfMatrix(); |
---|
781 | m_pcEncTop->getSPS()->setScalingListPresentFlag(pcSlice->checkDefaultScalingList()); |
---|
782 | m_pcEncTop->getPPS()->setScalingListPresentFlag(false); |
---|
783 | |
---|
784 | #if SCALINGLIST_INFERRING |
---|
785 | } |
---|
786 | #endif |
---|
787 | |
---|
788 | m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList()); |
---|
789 | m_pcEncTop->getTrQuant()->setUseScalingList(true); |
---|
790 | } |
---|
791 | else |
---|
792 | { |
---|
793 | printf("error : ScalingList == %d no support\n",m_pcEncTop->getUseScalingListId()); |
---|
794 | assert(0); |
---|
795 | } |
---|
796 | |
---|
797 | if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='P') |
---|
798 | { |
---|
799 | pcSlice->setSliceType(P_SLICE); |
---|
800 | } |
---|
801 | // Set the nal unit type |
---|
802 | pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR)); |
---|
803 | #if SVC_EXTENSION |
---|
804 | if (m_layerId > 0) |
---|
805 | { |
---|
806 | Int interLayerPredLayerIdcTmp[MAX_VPS_LAYER_ID_PLUS1]; |
---|
807 | Int activeNumILRRefIdxTmp = 0; |
---|
808 | |
---|
809 | for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
---|
810 | { |
---|
811 | UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i); |
---|
812 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
813 | TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(refLayerIdc)->getListPic(); |
---|
814 | #else |
---|
815 | TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId-1]->getListPic(); |
---|
816 | #endif |
---|
817 | pcSlice->setBaseColPic( *cListPic, refLayerIdc ); |
---|
818 | |
---|
819 | // Apply temporal layer restriction to inter-layer prediction |
---|
820 | #if O0225_MAX_TID_FOR_REF_LAYERS |
---|
821 | Int maxTidIlRefPicsPlus1 = m_pcEncTop->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getLayerId(),m_layerId); |
---|
822 | #else |
---|
823 | Int maxTidIlRefPicsPlus1 = m_pcEncTop->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getLayerId()); |
---|
824 | #endif |
---|
825 | if( ((Int)(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getRapPicFlag()) ) |
---|
826 | { |
---|
827 | interLayerPredLayerIdcTmp[activeNumILRRefIdxTmp++] = refLayerIdc; // add picture to the list of valid inter-layer pictures |
---|
828 | } |
---|
829 | else |
---|
830 | { |
---|
831 | continue; // ILP is not valid due to temporal layer restriction |
---|
832 | } |
---|
833 | |
---|
834 | #if O0098_SCALED_REF_LAYER_ID |
---|
835 | const Window &scalEL = m_pcEncTop->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc)); |
---|
836 | #else |
---|
837 | const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow(refLayerIdc); |
---|
838 | #endif |
---|
839 | |
---|
840 | Int widthBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth(); |
---|
841 | Int heightBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight(); |
---|
842 | |
---|
843 | Int widthEL = pcPic->getPicYuvRec()->getWidth() - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset(); |
---|
844 | Int heightEL = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset() - scalEL.getWindowBottomOffset(); |
---|
845 | |
---|
846 | g_mvScalingFactor[refLayerIdc][0] = widthEL == widthBL ? 4096 : Clip3(-4096, 4095, ((widthEL << 8) + (widthBL >> 1)) / widthBL); |
---|
847 | g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL); |
---|
848 | |
---|
849 | g_posScalingFactor[refLayerIdc][0] = ((widthBL << 16) + (widthEL >> 1)) / widthEL; |
---|
850 | g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL; |
---|
851 | |
---|
852 | #if SVC_UPSAMPLING |
---|
853 | if( pcPic->isSpatialEnhLayer(refLayerIdc)) |
---|
854 | { |
---|
855 | /*#if O0098_SCALED_REF_LAYER_ID |
---|
856 | Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc)); |
---|
857 | #else |
---|
858 | Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc); |
---|
859 | #endif*/ |
---|
860 | #if O0215_PHASE_ALIGNMENT |
---|
861 | #if O0194_JOINT_US_BITSHIFT |
---|
862 | m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() ); |
---|
863 | #else |
---|
864 | m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() ); |
---|
865 | #endif |
---|
866 | #else |
---|
867 | #if O0194_JOINT_US_BITSHIFT |
---|
868 | m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL ); |
---|
869 | #else |
---|
870 | m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL ); |
---|
871 | #endif |
---|
872 | #endif |
---|
873 | } |
---|
874 | else |
---|
875 | { |
---|
876 | pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() ); |
---|
877 | } |
---|
878 | pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) ); |
---|
879 | #endif |
---|
880 | } |
---|
881 | |
---|
882 | // Update the list of active inter-layer pictures |
---|
883 | for ( Int i = 0; i < activeNumILRRefIdxTmp; i++) |
---|
884 | { |
---|
885 | pcSlice->setInterLayerPredLayerIdc( interLayerPredLayerIdcTmp[i], i ); |
---|
886 | } |
---|
887 | |
---|
888 | #if !O0225_TID_BASED_IL_RPS_DERIV |
---|
889 | pcSlice->setActiveNumILRRefIdx( activeNumILRRefIdxTmp ); |
---|
890 | #endif |
---|
891 | if ( pcSlice->getActiveNumILRRefIdx() == 0 ) |
---|
892 | { |
---|
893 | // No valid inter-layer pictures -> disable inter-layer prediction |
---|
894 | pcSlice->setInterLayerPredEnabledFlag(false); |
---|
895 | } |
---|
896 | |
---|
897 | if( pocCurr % m_pcCfg->getIntraPeriod() == 0 ) |
---|
898 | { |
---|
899 | #if N0147_IRAP_ALIGN_FLAG |
---|
900 | if(pcSlice->getVPS()->getCrossLayerIrapAlignFlag()) |
---|
901 | { |
---|
902 | TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic(); |
---|
903 | TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() ); |
---|
904 | if(picLayer0) |
---|
905 | { |
---|
906 | pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType()); |
---|
907 | } |
---|
908 | else |
---|
909 | { |
---|
910 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA); |
---|
911 | } |
---|
912 | } |
---|
913 | else |
---|
914 | #endif |
---|
915 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA); |
---|
916 | |
---|
917 | #if IDR_ALIGNMENT |
---|
918 | TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic(); |
---|
919 | TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() ); |
---|
920 | if( picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
---|
921 | { |
---|
922 | pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType()); |
---|
923 | } |
---|
924 | else |
---|
925 | { |
---|
926 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA); |
---|
927 | } |
---|
928 | #endif |
---|
929 | } |
---|
930 | |
---|
931 | if( pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) |
---|
932 | { |
---|
933 | pcSlice->setSliceType(I_SLICE); |
---|
934 | } |
---|
935 | else if( !m_pcEncTop->getElRapSliceTypeB() ) |
---|
936 | { |
---|
937 | if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) && |
---|
938 | (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) && |
---|
939 | pcSlice->getSliceType() == B_SLICE ) |
---|
940 | { |
---|
941 | pcSlice->setSliceType(P_SLICE); |
---|
942 | } |
---|
943 | } |
---|
944 | } |
---|
945 | #endif //#if SVC_EXTENSION |
---|
946 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
947 | { |
---|
948 | if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_R && |
---|
949 | !(m_iGopSize == 1 && pcSlice->getSliceType() == I_SLICE)) |
---|
950 | // Add this condition to avoid POC issues with encoder_intra_main.cfg configuration (see #1127 in bug tracker) |
---|
951 | { |
---|
952 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N); |
---|
953 | } |
---|
954 | if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RADL_R) |
---|
955 | { |
---|
956 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RADL_N); |
---|
957 | } |
---|
958 | if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RASL_R) |
---|
959 | { |
---|
960 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RASL_N); |
---|
961 | } |
---|
962 | } |
---|
963 | |
---|
964 | // Do decoding refresh marking if any |
---|
965 | #if NO_CLRAS_OUTPUT_FLAG |
---|
966 | pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic, m_pcEncTop->getNoClrasOutputFlag()); |
---|
967 | #else |
---|
968 | pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic); |
---|
969 | #endif |
---|
970 | m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid); |
---|
971 | pcSlice->getRPS()->setNumberOfLongtermPictures(0); |
---|
972 | |
---|
973 | if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP())) |
---|
974 | { |
---|
975 | pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP()); |
---|
976 | } |
---|
977 | pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS()); |
---|
978 | |
---|
979 | if(pcSlice->getTLayer() > 0) |
---|
980 | { |
---|
981 | if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic) || pcSlice->getSPS()->getTemporalIdNestingFlag()) |
---|
982 | { |
---|
983 | #if ALIGN_TSA_STSA_PICS |
---|
984 | if( pcSlice->getLayerId() > 0 ) |
---|
985 | { |
---|
986 | Bool oneRefLayerTSA = false, oneRefLayerNotTSA = false; |
---|
987 | for( Int i = 0; i < pcSlice->getLayerId(); i++) |
---|
988 | { |
---|
989 | TComList<TComPic *> *cListPic = m_ppcTEncTop[i]->getListPic(); |
---|
990 | TComPic *lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC()); |
---|
991 | if( lowerLayerPic && pcSlice->getVPS()->getDirectDependencyFlag(pcSlice->getLayerId(), i) ) |
---|
992 | { |
---|
993 | if( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ) || |
---|
994 | ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R ) |
---|
995 | ) |
---|
996 | { |
---|
997 | if(pcSlice->getTemporalLayerNonReferenceFlag() ) |
---|
998 | { |
---|
999 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_N); |
---|
1000 | } |
---|
1001 | else |
---|
1002 | { |
---|
1003 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R ); |
---|
1004 | } |
---|
1005 | oneRefLayerTSA = true; |
---|
1006 | } |
---|
1007 | else |
---|
1008 | { |
---|
1009 | oneRefLayerNotTSA = true; |
---|
1010 | } |
---|
1011 | } |
---|
1012 | } |
---|
1013 | assert( !( oneRefLayerNotTSA && oneRefLayerTSA ) ); // Only one variable should be true - failure of this assert means |
---|
1014 | // that two independent reference layers that are not dependent on |
---|
1015 | // each other, but are reference for current layer have inconsistency |
---|
1016 | if( oneRefLayerNotTSA /*&& !oneRefLayerTSA*/ ) // No reference layer is TSA - set current as TRAIL |
---|
1017 | { |
---|
1018 | if(pcSlice->getTemporalLayerNonReferenceFlag() ) |
---|
1019 | { |
---|
1020 | pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_N ); |
---|
1021 | } |
---|
1022 | else |
---|
1023 | { |
---|
1024 | pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_R ); |
---|
1025 | } |
---|
1026 | } |
---|
1027 | else // This means there is no reference layer picture for current picture in this AU |
---|
1028 | { |
---|
1029 | if(pcSlice->getTemporalLayerNonReferenceFlag() ) |
---|
1030 | { |
---|
1031 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_N); |
---|
1032 | } |
---|
1033 | else |
---|
1034 | { |
---|
1035 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R ); |
---|
1036 | } |
---|
1037 | } |
---|
1038 | } |
---|
1039 | #else |
---|
1040 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
1041 | { |
---|
1042 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_N); |
---|
1043 | } |
---|
1044 | else |
---|
1045 | { |
---|
1046 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R); |
---|
1047 | } |
---|
1048 | #endif |
---|
1049 | } |
---|
1050 | else if(pcSlice->isStepwiseTemporalLayerSwitchingPointCandidate(rcListPic)) |
---|
1051 | { |
---|
1052 | Bool isSTSA=true; |
---|
1053 | for(Int ii=iGOPid+1;(ii<m_pcCfg->getGOPSize() && isSTSA==true);ii++) |
---|
1054 | { |
---|
1055 | Int lTid= m_pcCfg->getGOPEntry(ii).m_temporalId; |
---|
1056 | if(lTid==pcSlice->getTLayer()) |
---|
1057 | { |
---|
1058 | TComReferencePictureSet* nRPS = pcSlice->getSPS()->getRPSList()->getReferencePictureSet(ii); |
---|
1059 | for(Int jj=0;jj<nRPS->getNumberOfPictures();jj++) |
---|
1060 | { |
---|
1061 | if(nRPS->getUsed(jj)) |
---|
1062 | { |
---|
1063 | Int tPoc=m_pcCfg->getGOPEntry(ii).m_POC+nRPS->getDeltaPOC(jj); |
---|
1064 | Int kk=0; |
---|
1065 | for(kk=0;kk<m_pcCfg->getGOPSize();kk++) |
---|
1066 | { |
---|
1067 | if(m_pcCfg->getGOPEntry(kk).m_POC==tPoc) |
---|
1068 | break; |
---|
1069 | } |
---|
1070 | Int tTid=m_pcCfg->getGOPEntry(kk).m_temporalId; |
---|
1071 | if(tTid >= pcSlice->getTLayer()) |
---|
1072 | { |
---|
1073 | isSTSA=false; |
---|
1074 | break; |
---|
1075 | } |
---|
1076 | } |
---|
1077 | } |
---|
1078 | } |
---|
1079 | } |
---|
1080 | if(isSTSA==true) |
---|
1081 | { |
---|
1082 | #if ALIGN_TSA_STSA_PICS |
---|
1083 | if( pcSlice->getLayerId() > 0 ) |
---|
1084 | { |
---|
1085 | Bool oneRefLayerSTSA = false, oneRefLayerNotSTSA = false; |
---|
1086 | for( Int i = 0; i < pcSlice->getLayerId(); i++) |
---|
1087 | { |
---|
1088 | TComList<TComPic *> *cListPic = m_ppcTEncTop[i]->getListPic(); |
---|
1089 | TComPic *lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC()); |
---|
1090 | if( lowerLayerPic && pcSlice->getVPS()->getDirectDependencyFlag(pcSlice->getLayerId(), i) ) |
---|
1091 | { |
---|
1092 | if( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ) || |
---|
1093 | ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R ) |
---|
1094 | ) |
---|
1095 | { |
---|
1096 | if(pcSlice->getTemporalLayerNonReferenceFlag() ) |
---|
1097 | { |
---|
1098 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N); |
---|
1099 | } |
---|
1100 | else |
---|
1101 | { |
---|
1102 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R ); |
---|
1103 | } |
---|
1104 | oneRefLayerSTSA = true; |
---|
1105 | } |
---|
1106 | else |
---|
1107 | { |
---|
1108 | oneRefLayerNotSTSA = true; |
---|
1109 | } |
---|
1110 | } |
---|
1111 | } |
---|
1112 | assert( !( oneRefLayerNotSTSA && oneRefLayerSTSA ) ); // Only one variable should be true - failure of this assert means |
---|
1113 | // that two independent reference layers that are not dependent on |
---|
1114 | // each other, but are reference for current layer have inconsistency |
---|
1115 | if( oneRefLayerNotSTSA /*&& !oneRefLayerSTSA*/ ) // No reference layer is STSA - set current as TRAIL |
---|
1116 | { |
---|
1117 | if(pcSlice->getTemporalLayerNonReferenceFlag() ) |
---|
1118 | { |
---|
1119 | pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_N ); |
---|
1120 | } |
---|
1121 | else |
---|
1122 | { |
---|
1123 | pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_R ); |
---|
1124 | } |
---|
1125 | } |
---|
1126 | else // This means there is no reference layer picture for current picture in this AU |
---|
1127 | { |
---|
1128 | if(pcSlice->getTemporalLayerNonReferenceFlag() ) |
---|
1129 | { |
---|
1130 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N); |
---|
1131 | } |
---|
1132 | else |
---|
1133 | { |
---|
1134 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R ); |
---|
1135 | } |
---|
1136 | } |
---|
1137 | } |
---|
1138 | #else |
---|
1139 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
1140 | { |
---|
1141 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N); |
---|
1142 | } |
---|
1143 | else |
---|
1144 | { |
---|
1145 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R); |
---|
1146 | } |
---|
1147 | #endif |
---|
1148 | } |
---|
1149 | } |
---|
1150 | } |
---|
1151 | arrangeLongtermPicturesInRPS(pcSlice, rcListPic); |
---|
1152 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
---|
1153 | refPicListModification->setRefPicListModificationFlagL0(0); |
---|
1154 | refPicListModification->setRefPicListModificationFlagL1(0); |
---|
1155 | pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures())); |
---|
1156 | pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures())); |
---|
1157 | |
---|
1158 | #if SVC_EXTENSION |
---|
1159 | if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() ) |
---|
1160 | { |
---|
1161 | #if POC_RESET_FLAG |
---|
1162 | if ( pocCurr > 0 && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL()) |
---|
1163 | #else |
---|
1164 | if (pcSlice->getPOC()>0 && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL()) |
---|
1165 | #endif |
---|
1166 | { |
---|
1167 | #if JCTVC_M0458_INTERLAYER_RPS_SIG |
---|
1168 | pcSlice->setActiveNumILRRefIdx(0); |
---|
1169 | pcSlice->setInterLayerPredEnabledFlag(0); |
---|
1170 | #else |
---|
1171 | pcSlice->setNumILRRefIdx(0); |
---|
1172 | #endif |
---|
1173 | } |
---|
1174 | #if JCTVC_M0458_INTERLAYER_RPS_SIG |
---|
1175 | if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) |
---|
1176 | { |
---|
1177 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getActiveNumILRRefIdx()); |
---|
1178 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getActiveNumILRRefIdx()); |
---|
1179 | } |
---|
1180 | else |
---|
1181 | { |
---|
1182 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumRefIdx(REF_PIC_LIST_0)+pcSlice->getActiveNumILRRefIdx()); |
---|
1183 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumRefIdx(REF_PIC_LIST_1)+pcSlice->getActiveNumILRRefIdx()); |
---|
1184 | } |
---|
1185 | #else |
---|
1186 | if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) |
---|
1187 | { |
---|
1188 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumILRRefIdx()); |
---|
1189 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumILRRefIdx()); |
---|
1190 | } |
---|
1191 | else |
---|
1192 | { |
---|
1193 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumRefIdx(REF_PIC_LIST_0)+pcSlice->getNumILRRefIdx()); |
---|
1194 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumRefIdx(REF_PIC_LIST_1)+pcSlice->getNumILRRefIdx()); |
---|
1195 | } |
---|
1196 | #endif |
---|
1197 | } |
---|
1198 | #endif //SVC_EXTENSION |
---|
1199 | |
---|
1200 | #if ADAPTIVE_QP_SELECTION |
---|
1201 | pcSlice->setTrQuant( m_pcEncTop->getTrQuant() ); |
---|
1202 | #endif |
---|
1203 | |
---|
1204 | #if SVC_EXTENSION |
---|
1205 | #if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING |
---|
1206 | if ( pcSlice->getSliceType() == B_SLICE && !(pcSlice->getActiveNumILRRefIdx() > 0 && m_pcEncTop->getNumMotionPredRefLayers() > 0) ) |
---|
1207 | #else |
---|
1208 | if( pcSlice->getSliceType() == B_SLICE ) |
---|
1209 | #endif |
---|
1210 | { |
---|
1211 | pcSlice->setColFromL0Flag(1-uiColDir); |
---|
1212 | } |
---|
1213 | |
---|
1214 | // Set reference list |
---|
1215 | if(m_layerId == 0 || ( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() == 0 ) ) |
---|
1216 | { |
---|
1217 | pcSlice->setRefPicList( rcListPic); |
---|
1218 | } |
---|
1219 | |
---|
1220 | if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() ) |
---|
1221 | { |
---|
1222 | pcSlice->setILRPic( m_pcEncTop->getIlpList() ); |
---|
1223 | #if REF_IDX_MFM |
---|
1224 | #if M0457_COL_PICTURE_SIGNALING |
---|
1225 | if( pcSlice->getMFMEnabledFlag() ) |
---|
1226 | #else |
---|
1227 | if( pcSlice->getSPS()->getMFMEnabledFlag() ) |
---|
1228 | #endif |
---|
1229 | { |
---|
1230 | pcSlice->setRefPOCListILP(m_pcEncTop->getIlpList(), pcSlice->getBaseColPic()); |
---|
1231 | #if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING |
---|
1232 | pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice)); |
---|
1233 | #endif |
---|
1234 | } |
---|
1235 | #else |
---|
1236 | // Set reference list |
---|
1237 | pcSlice->setRefPicList ( rcListPic ); |
---|
1238 | #endif //SVC_EXTENSION |
---|
1239 | pcSlice->setRefPicListModificationSvc(); |
---|
1240 | pcSlice->setRefPicList( rcListPic, false, m_pcEncTop->getIlpList()); |
---|
1241 | |
---|
1242 | #if REF_IDX_MFM |
---|
1243 | #if M0457_COL_PICTURE_SIGNALING |
---|
1244 | #if REMOVE_COL_PICTURE_SIGNALING |
---|
1245 | if( pcSlice->getMFMEnabledFlag() ) |
---|
1246 | #else |
---|
1247 | if( pcSlice->getMFMEnabledFlag() && !(pcSlice->getActiveNumILRRefIdx() > 0 && m_pcEncTop->getNumMotionPredRefLayers() > 0) ) |
---|
1248 | #endif |
---|
1249 | #else |
---|
1250 | if( pcSlice->getSPS()->getMFMEnabledFlag() ) |
---|
1251 | #endif |
---|
1252 | { |
---|
1253 | Bool found = false; |
---|
1254 | UInt ColFromL0Flag = pcSlice->getColFromL0Flag(); |
---|
1255 | UInt ColRefIdx = pcSlice->getColRefIdx(); |
---|
1256 | |
---|
1257 | for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) |
---|
1258 | { |
---|
1259 | if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) |
---|
1260 | #if MFM_ENCCONSTRAINT |
---|
1261 | && pcSlice->getBaseColPic( *m_ppcTEncTop[pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->getLayerId()]->getListPic() )->checkSameRefInfo() == true |
---|
1262 | #endif |
---|
1263 | ) |
---|
1264 | { |
---|
1265 | ColRefIdx = colIdx; |
---|
1266 | found = true; |
---|
1267 | break; |
---|
1268 | } |
---|
1269 | } |
---|
1270 | |
---|
1271 | if( found == false ) |
---|
1272 | { |
---|
1273 | ColFromL0Flag = 1 - ColFromL0Flag; |
---|
1274 | for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) |
---|
1275 | { |
---|
1276 | if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) |
---|
1277 | #if MFM_ENCCONSTRAINT |
---|
1278 | && pcSlice->getBaseColPic( *m_ppcTEncTop[pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->getLayerId()]->getListPic() )->checkSameRefInfo() == true |
---|
1279 | #endif |
---|
1280 | ) |
---|
1281 | { |
---|
1282 | ColRefIdx = colIdx; |
---|
1283 | found = true; |
---|
1284 | break; |
---|
1285 | } |
---|
1286 | } |
---|
1287 | } |
---|
1288 | |
---|
1289 | if(found == true) |
---|
1290 | { |
---|
1291 | pcSlice->setColFromL0Flag(ColFromL0Flag); |
---|
1292 | pcSlice->setColRefIdx(ColRefIdx); |
---|
1293 | } |
---|
1294 | } |
---|
1295 | #endif |
---|
1296 | } |
---|
1297 | #else //SVC_EXTENSION |
---|
1298 | // Set reference list |
---|
1299 | pcSlice->setRefPicList ( rcListPic ); |
---|
1300 | #endif //#if SVC_EXTENSION |
---|
1301 | |
---|
1302 | // Slice info. refinement |
---|
1303 | if ( (pcSlice->getSliceType() == B_SLICE) && (pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0) ) |
---|
1304 | { |
---|
1305 | pcSlice->setSliceType ( P_SLICE ); |
---|
1306 | } |
---|
1307 | |
---|
1308 | #if M0457_IL_SAMPLE_PRED_ONLY_FLAG |
---|
1309 | if (pcSlice->getSliceType() == B_SLICE && m_pcEncTop->getIlSampleOnlyPred() == 0) |
---|
1310 | #else |
---|
1311 | if (pcSlice->getSliceType() == B_SLICE) |
---|
1312 | #endif |
---|
1313 | { |
---|
1314 | #if !SVC_EXTENSION |
---|
1315 | pcSlice->setColFromL0Flag(1-uiColDir); |
---|
1316 | #endif |
---|
1317 | Bool bLowDelay = true; |
---|
1318 | Int iCurrPOC = pcSlice->getPOC(); |
---|
1319 | Int iRefIdx = 0; |
---|
1320 | |
---|
1321 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++) |
---|
1322 | { |
---|
1323 | if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC ) |
---|
1324 | { |
---|
1325 | bLowDelay = false; |
---|
1326 | } |
---|
1327 | } |
---|
1328 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++) |
---|
1329 | { |
---|
1330 | if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC ) |
---|
1331 | { |
---|
1332 | bLowDelay = false; |
---|
1333 | } |
---|
1334 | } |
---|
1335 | |
---|
1336 | pcSlice->setCheckLDC(bLowDelay); |
---|
1337 | } |
---|
1338 | else |
---|
1339 | { |
---|
1340 | pcSlice->setCheckLDC(true); |
---|
1341 | } |
---|
1342 | |
---|
1343 | uiColDir = 1-uiColDir; |
---|
1344 | |
---|
1345 | //------------------------------------------------------------- |
---|
1346 | pcSlice->setRefPOCList(); |
---|
1347 | |
---|
1348 | pcSlice->setList1IdxToList0Idx(); |
---|
1349 | |
---|
1350 | if (m_pcEncTop->getTMVPModeId() == 2) |
---|
1351 | { |
---|
1352 | if (iGOPid == 0) // first picture in SOP (i.e. forward B) |
---|
1353 | { |
---|
1354 | pcSlice->setEnableTMVPFlag(0); |
---|
1355 | } |
---|
1356 | else |
---|
1357 | { |
---|
1358 | // Note: pcSlice->getColFromL0Flag() is assumed to be always 0 and getcolRefIdx() is always 0. |
---|
1359 | pcSlice->setEnableTMVPFlag(1); |
---|
1360 | } |
---|
1361 | pcSlice->getSPS()->setTMVPFlagsPresent(1); |
---|
1362 | } |
---|
1363 | else if (m_pcEncTop->getTMVPModeId() == 1) |
---|
1364 | { |
---|
1365 | pcSlice->getSPS()->setTMVPFlagsPresent(1); |
---|
1366 | #if SVC_EXTENSION |
---|
1367 | if( pcSlice->getIdrPicFlag() ) |
---|
1368 | { |
---|
1369 | pcSlice->setEnableTMVPFlag(0); |
---|
1370 | } |
---|
1371 | else |
---|
1372 | #endif |
---|
1373 | pcSlice->setEnableTMVPFlag(1); |
---|
1374 | } |
---|
1375 | else |
---|
1376 | { |
---|
1377 | pcSlice->getSPS()->setTMVPFlagsPresent(0); |
---|
1378 | pcSlice->setEnableTMVPFlag(0); |
---|
1379 | } |
---|
1380 | /////////////////////////////////////////////////////////////////////////////////////////////////// Compress a slice |
---|
1381 | // Slice compression |
---|
1382 | if (m_pcCfg->getUseASR()) |
---|
1383 | { |
---|
1384 | m_pcSliceEncoder->setSearchRange(pcSlice); |
---|
1385 | } |
---|
1386 | |
---|
1387 | Bool bGPBcheck=false; |
---|
1388 | if ( pcSlice->getSliceType() == B_SLICE) |
---|
1389 | { |
---|
1390 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
1391 | { |
---|
1392 | bGPBcheck=true; |
---|
1393 | Int i; |
---|
1394 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
1395 | { |
---|
1396 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
1397 | { |
---|
1398 | bGPBcheck=false; |
---|
1399 | break; |
---|
1400 | } |
---|
1401 | } |
---|
1402 | } |
---|
1403 | } |
---|
1404 | if(bGPBcheck) |
---|
1405 | { |
---|
1406 | pcSlice->setMvdL1ZeroFlag(true); |
---|
1407 | } |
---|
1408 | else |
---|
1409 | { |
---|
1410 | pcSlice->setMvdL1ZeroFlag(false); |
---|
1411 | } |
---|
1412 | pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag()); |
---|
1413 | |
---|
1414 | Double lambda = 0.0; |
---|
1415 | Int actualHeadBits = 0; |
---|
1416 | Int actualTotalBits = 0; |
---|
1417 | Int estimatedBits = 0; |
---|
1418 | Int tmpBitsBeforeWriting = 0; |
---|
1419 | if ( m_pcCfg->getUseRateCtrl() ) |
---|
1420 | { |
---|
1421 | Int frameLevel = m_pcRateCtrl->getRCSeq()->getGOPID2Level( iGOPid ); |
---|
1422 | if ( pcPic->getSlice(0)->getSliceType() == I_SLICE ) |
---|
1423 | { |
---|
1424 | frameLevel = 0; |
---|
1425 | } |
---|
1426 | m_pcRateCtrl->initRCPic( frameLevel ); |
---|
1427 | estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits(); |
---|
1428 | |
---|
1429 | Int sliceQP = m_pcCfg->getInitialQP(); |
---|
1430 | #if POC_RESET_FLAG |
---|
1431 | if ( ( pocCurr == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified |
---|
1432 | #else |
---|
1433 | if ( ( pcSlice->getPOC() == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified |
---|
1434 | #endif |
---|
1435 | { |
---|
1436 | Int NumberBFrames = ( m_pcCfg->getGOPSize() - 1 ); |
---|
1437 | Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames ); |
---|
1438 | Double dQPFactor = 0.57*dLambda_scale; |
---|
1439 | Int SHIFT_QP = 12; |
---|
1440 | Int bitdepth_luma_qp_scale = 0; |
---|
1441 | Double qp_temp = (Double) sliceQP + bitdepth_luma_qp_scale - SHIFT_QP; |
---|
1442 | lambda = dQPFactor*pow( 2.0, qp_temp/3.0 ); |
---|
1443 | } |
---|
1444 | else if ( frameLevel == 0 ) // intra case, but use the model |
---|
1445 | { |
---|
1446 | m_pcSliceEncoder->calCostSliceI(pcPic); |
---|
1447 | if ( m_pcCfg->getIntraPeriod() != 1 ) // do not refine allocated bits for all intra case |
---|
1448 | { |
---|
1449 | Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits(); |
---|
1450 | bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits ); |
---|
1451 | if ( bits < 200 ) |
---|
1452 | { |
---|
1453 | bits = 200; |
---|
1454 | } |
---|
1455 | m_pcRateCtrl->getRCPic()->setTargetBits( bits ); |
---|
1456 | } |
---|
1457 | |
---|
1458 | list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); |
---|
1459 | m_pcRateCtrl->getRCPic()->getLCUInitTargetBits(); |
---|
1460 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); |
---|
1461 | sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); |
---|
1462 | } |
---|
1463 | else // normal case |
---|
1464 | { |
---|
1465 | list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); |
---|
1466 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); |
---|
1467 | sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); |
---|
1468 | } |
---|
1469 | |
---|
1470 | #if REPN_FORMAT_IN_VPS |
---|
1471 | sliceQP = Clip3( -pcSlice->getQpBDOffsetY(), MAX_QP, sliceQP ); |
---|
1472 | #else |
---|
1473 | sliceQP = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, sliceQP ); |
---|
1474 | #endif |
---|
1475 | m_pcRateCtrl->getRCPic()->setPicEstQP( sliceQP ); |
---|
1476 | |
---|
1477 | m_pcSliceEncoder->resetQP( pcPic, sliceQP, lambda ); |
---|
1478 | } |
---|
1479 | |
---|
1480 | UInt uiNumSlices = 1; |
---|
1481 | |
---|
1482 | UInt uiInternalAddress = pcPic->getNumPartInCU()-4; |
---|
1483 | UInt uiExternalAddress = pcPic->getPicSym()->getNumberOfCUsInFrame()-1; |
---|
1484 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1485 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1486 | #if REPN_FORMAT_IN_VPS |
---|
1487 | UInt uiWidth = pcSlice->getPicWidthInLumaSamples(); |
---|
1488 | UInt uiHeight = pcSlice->getPicHeightInLumaSamples(); |
---|
1489 | #else |
---|
1490 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
1491 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
1492 | #endif |
---|
1493 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
1494 | { |
---|
1495 | uiInternalAddress--; |
---|
1496 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1497 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1498 | } |
---|
1499 | uiInternalAddress++; |
---|
1500 | if(uiInternalAddress==pcPic->getNumPartInCU()) |
---|
1501 | { |
---|
1502 | uiInternalAddress = 0; |
---|
1503 | uiExternalAddress++; |
---|
1504 | } |
---|
1505 | UInt uiRealEndAddress = uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress; |
---|
1506 | |
---|
1507 | UInt uiCummulativeTileWidth; |
---|
1508 | UInt uiCummulativeTileHeight; |
---|
1509 | Int p, j; |
---|
1510 | UInt uiEncCUAddr; |
---|
1511 | |
---|
1512 | //set NumColumnsMinus1 and NumRowsMinus1 |
---|
1513 | pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() ); |
---|
1514 | pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() ); |
---|
1515 | |
---|
1516 | //create the TComTileArray |
---|
1517 | pcPic->getPicSym()->xCreateTComTileArray(); |
---|
1518 | |
---|
1519 | if( pcSlice->getPPS()->getUniformSpacingFlag() == 1 ) |
---|
1520 | { |
---|
1521 | //set the width for each tile |
---|
1522 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
1523 | { |
---|
1524 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++) |
---|
1525 | { |
---|
1526 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )-> |
---|
1527 | setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) |
---|
1528 | - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) ); |
---|
1529 | } |
---|
1530 | } |
---|
1531 | |
---|
1532 | //set the height for each tile |
---|
1533 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
1534 | { |
---|
1535 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++) |
---|
1536 | { |
---|
1537 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )-> |
---|
1538 | setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) |
---|
1539 | - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) ); |
---|
1540 | } |
---|
1541 | } |
---|
1542 | } |
---|
1543 | else |
---|
1544 | { |
---|
1545 | //set the width for each tile |
---|
1546 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
1547 | { |
---|
1548 | uiCummulativeTileWidth = 0; |
---|
1549 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1(); p++) |
---|
1550 | { |
---|
1551 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->setTileWidth( pcSlice->getPPS()->getColumnWidth(p) ); |
---|
1552 | uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(p); |
---|
1553 | } |
---|
1554 | pcPic->getPicSym()->getTComTile(j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth ); |
---|
1555 | } |
---|
1556 | |
---|
1557 | //set the height for each tile |
---|
1558 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
1559 | { |
---|
1560 | uiCummulativeTileHeight = 0; |
---|
1561 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1(); p++) |
---|
1562 | { |
---|
1563 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->setTileHeight( pcSlice->getPPS()->getRowHeight(p) ); |
---|
1564 | uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(p); |
---|
1565 | } |
---|
1566 | pcPic->getPicSym()->getTComTile(p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight ); |
---|
1567 | } |
---|
1568 | } |
---|
1569 | //intialize each tile of the current picture |
---|
1570 | pcPic->getPicSym()->xInitTiles(); |
---|
1571 | |
---|
1572 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
1573 | if (m_pcCfg->getInterLayerConstrainedTileSetsSEIEnabled()) |
---|
1574 | { |
---|
1575 | xBuildTileSetsMap(pcPic->getPicSym()); |
---|
1576 | } |
---|
1577 | #endif |
---|
1578 | |
---|
1579 | // Allocate some coders, now we know how many tiles there are. |
---|
1580 | Int iNumSubstreams = pcSlice->getPPS()->getNumSubstreams(); |
---|
1581 | |
---|
1582 | //generate the Coding Order Map and Inverse Coding Order Map |
---|
1583 | for(p=0, uiEncCUAddr=0; p<pcPic->getPicSym()->getNumberOfCUsInFrame(); p++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr)) |
---|
1584 | { |
---|
1585 | pcPic->getPicSym()->setCUOrderMap(p, uiEncCUAddr); |
---|
1586 | pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, p); |
---|
1587 | } |
---|
1588 | pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
1589 | pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
1590 | |
---|
1591 | // Allocate some coders, now we know how many tiles there are. |
---|
1592 | m_pcEncTop->createWPPCoders(iNumSubstreams); |
---|
1593 | pcSbacCoders = m_pcEncTop->getSbacCoders(); |
---|
1594 | pcSubstreamsOut = new TComOutputBitstream[iNumSubstreams]; |
---|
1595 | |
---|
1596 | UInt startCUAddrSliceIdx = 0; // used to index "m_uiStoredStartCUAddrForEncodingSlice" containing locations of slice boundaries |
---|
1597 | UInt startCUAddrSlice = 0; // used to keep track of current slice's starting CU addr. |
---|
1598 | pcSlice->setSliceCurStartCUAddr( startCUAddrSlice ); // Setting "start CU addr" for current slice |
---|
1599 | m_storedStartCUAddrForEncodingSlice.clear(); |
---|
1600 | |
---|
1601 | UInt startCUAddrSliceSegmentIdx = 0; // used to index "m_uiStoredStartCUAddrForEntropyEncodingSlice" containing locations of slice boundaries |
---|
1602 | UInt startCUAddrSliceSegment = 0; // used to keep track of current Dependent slice's starting CU addr. |
---|
1603 | pcSlice->setSliceSegmentCurStartCUAddr( startCUAddrSliceSegment ); // Setting "start CU addr" for current Dependent slice |
---|
1604 | |
---|
1605 | m_storedStartCUAddrForEncodingSliceSegment.clear(); |
---|
1606 | UInt nextCUAddr = 0; |
---|
1607 | m_storedStartCUAddrForEncodingSlice.push_back (nextCUAddr); |
---|
1608 | startCUAddrSliceIdx++; |
---|
1609 | m_storedStartCUAddrForEncodingSliceSegment.push_back(nextCUAddr); |
---|
1610 | startCUAddrSliceSegmentIdx++; |
---|
1611 | #if AVC_BASE |
---|
1612 | if( m_layerId == 0 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) |
---|
1613 | { |
---|
1614 | pcPic->getPicYuvOrg()->copyToPic( pcPic->getPicYuvRec() ); |
---|
1615 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
1616 | // Calculate for the base layer to be used in EL as Inter layer reference |
---|
1617 | m_pcSliceEncoder->estimateILWpParam( pcSlice ); |
---|
1618 | #endif |
---|
1619 | #if AVC_SYNTAX |
---|
1620 | pcPic->readBLSyntax( m_ppcTEncTop[0]->getBLSyntaxFile(), SYNTAX_BYTES ); |
---|
1621 | #endif |
---|
1622 | return; |
---|
1623 | } |
---|
1624 | #endif |
---|
1625 | |
---|
1626 | while(nextCUAddr<uiRealEndAddress) // determine slice boundaries |
---|
1627 | { |
---|
1628 | pcSlice->setNextSlice ( false ); |
---|
1629 | pcSlice->setNextSliceSegment( false ); |
---|
1630 | assert(pcPic->getNumAllocatedSlice() == startCUAddrSliceIdx); |
---|
1631 | m_pcSliceEncoder->precompressSlice( pcPic ); |
---|
1632 | m_pcSliceEncoder->compressSlice ( pcPic ); |
---|
1633 | |
---|
1634 | Bool bNoBinBitConstraintViolated = (!pcSlice->isNextSlice() && !pcSlice->isNextSliceSegment()); |
---|
1635 | if (pcSlice->isNextSlice() || (bNoBinBitConstraintViolated && m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU)) |
---|
1636 | { |
---|
1637 | startCUAddrSlice = pcSlice->getSliceCurEndCUAddr(); |
---|
1638 | // Reconstruction slice |
---|
1639 | m_storedStartCUAddrForEncodingSlice.push_back(startCUAddrSlice); |
---|
1640 | startCUAddrSliceIdx++; |
---|
1641 | // Dependent slice |
---|
1642 | if (startCUAddrSliceSegmentIdx>0 && m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx-1] != startCUAddrSlice) |
---|
1643 | { |
---|
1644 | m_storedStartCUAddrForEncodingSliceSegment.push_back(startCUAddrSlice); |
---|
1645 | startCUAddrSliceSegmentIdx++; |
---|
1646 | } |
---|
1647 | |
---|
1648 | if (startCUAddrSlice < uiRealEndAddress) |
---|
1649 | { |
---|
1650 | pcPic->allocateNewSlice(); |
---|
1651 | pcPic->setCurrSliceIdx ( startCUAddrSliceIdx-1 ); |
---|
1652 | m_pcSliceEncoder->setSliceIdx ( startCUAddrSliceIdx-1 ); |
---|
1653 | pcSlice = pcPic->getSlice ( startCUAddrSliceIdx-1 ); |
---|
1654 | pcSlice->copySliceInfo ( pcPic->getSlice(0) ); |
---|
1655 | pcSlice->setSliceIdx ( startCUAddrSliceIdx-1 ); |
---|
1656 | pcSlice->setSliceCurStartCUAddr ( startCUAddrSlice ); |
---|
1657 | pcSlice->setSliceSegmentCurStartCUAddr ( startCUAddrSlice ); |
---|
1658 | pcSlice->setSliceBits(0); |
---|
1659 | #if SVC_EXTENSION |
---|
1660 | // copy reference list modification info from the first slice, assuming that this information is the same across all slices in the picture |
---|
1661 | memcpy( pcSlice->getRefPicListModification(), pcPic->getSlice(0)->getRefPicListModification(), sizeof(TComRefPicListModification) ); |
---|
1662 | #endif |
---|
1663 | uiNumSlices ++; |
---|
1664 | } |
---|
1665 | } |
---|
1666 | else if (pcSlice->isNextSliceSegment() || (bNoBinBitConstraintViolated && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)) |
---|
1667 | { |
---|
1668 | startCUAddrSliceSegment = pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
1669 | m_storedStartCUAddrForEncodingSliceSegment.push_back(startCUAddrSliceSegment); |
---|
1670 | startCUAddrSliceSegmentIdx++; |
---|
1671 | pcSlice->setSliceSegmentCurStartCUAddr( startCUAddrSliceSegment ); |
---|
1672 | } |
---|
1673 | else |
---|
1674 | { |
---|
1675 | startCUAddrSlice = pcSlice->getSliceCurEndCUAddr(); |
---|
1676 | startCUAddrSliceSegment = pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
1677 | } |
---|
1678 | |
---|
1679 | nextCUAddr = (startCUAddrSlice > startCUAddrSliceSegment) ? startCUAddrSlice : startCUAddrSliceSegment; |
---|
1680 | } |
---|
1681 | m_storedStartCUAddrForEncodingSlice.push_back( pcSlice->getSliceCurEndCUAddr()); |
---|
1682 | startCUAddrSliceIdx++; |
---|
1683 | m_storedStartCUAddrForEncodingSliceSegment.push_back(pcSlice->getSliceCurEndCUAddr()); |
---|
1684 | startCUAddrSliceSegmentIdx++; |
---|
1685 | |
---|
1686 | pcSlice = pcPic->getSlice(0); |
---|
1687 | |
---|
1688 | // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas |
---|
1689 | #if HM_CLEANUP_SAO |
---|
1690 | if( pcSlice->getSPS()->getUseSAO() && m_pcCfg->getSaoLcuBoundary() ) |
---|
1691 | { |
---|
1692 | m_pcSAO->getPreDBFStatistics(pcPic); |
---|
1693 | } |
---|
1694 | #else |
---|
1695 | if( m_pcCfg->getSaoLcuBasedOptimization() && m_pcCfg->getSaoLcuBoundary() ) |
---|
1696 | { |
---|
1697 | m_pcSAO->resetStats(); |
---|
1698 | m_pcSAO->calcSaoStatsCu_BeforeDblk( pcPic ); |
---|
1699 | } |
---|
1700 | #endif |
---|
1701 | //-- Loop filter |
---|
1702 | Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag(); |
---|
1703 | m_pcLoopFilter->setCfg(bLFCrossTileBoundary); |
---|
1704 | if ( m_pcCfg->getDeblockingFilterMetric() ) |
---|
1705 | { |
---|
1706 | dblMetric(pcPic, uiNumSlices); |
---|
1707 | } |
---|
1708 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
1709 | |
---|
1710 | #if !HM_CLEANUP_SAO |
---|
1711 | pcSlice = pcPic->getSlice(0); |
---|
1712 | if(pcSlice->getSPS()->getUseSAO()) |
---|
1713 | { |
---|
1714 | std::vector<Bool> LFCrossSliceBoundaryFlag; |
---|
1715 | for(Int s=0; s< uiNumSlices; s++) |
---|
1716 | { |
---|
1717 | LFCrossSliceBoundaryFlag.push_back( ((uiNumSlices==1)?true:pcPic->getSlice(s)->getLFCrossSliceBoundaryFlag()) ); |
---|
1718 | } |
---|
1719 | m_storedStartCUAddrForEncodingSlice.resize(uiNumSlices+1); |
---|
1720 | pcPic->createNonDBFilterInfo(m_storedStartCUAddrForEncodingSlice, 0, &LFCrossSliceBoundaryFlag ,pcPic->getPicSym()->getNumTiles() ,bLFCrossTileBoundary); |
---|
1721 | } |
---|
1722 | |
---|
1723 | |
---|
1724 | pcSlice = pcPic->getSlice(0); |
---|
1725 | |
---|
1726 | if(pcSlice->getSPS()->getUseSAO()) |
---|
1727 | { |
---|
1728 | m_pcSAO->createPicSaoInfo(pcPic); |
---|
1729 | } |
---|
1730 | #endif |
---|
1731 | /////////////////////////////////////////////////////////////////////////////////////////////////// File writing |
---|
1732 | // Set entropy coder |
---|
1733 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
1734 | |
---|
1735 | /* write various header sets. */ |
---|
1736 | if ( m_bSeqFirst ) |
---|
1737 | { |
---|
1738 | #if SVC_EXTENSION |
---|
1739 | #if VPS_NUH_LAYER_ID |
---|
1740 | OutputNALUnit nalu(NAL_UNIT_VPS, 0, 0 ); // The value of nuh_layer_id of VPS NAL unit shall be equal to 0. |
---|
1741 | #else |
---|
1742 | OutputNALUnit nalu(NAL_UNIT_VPS, 0, m_layerId); |
---|
1743 | #endif |
---|
1744 | #if AVC_BASE |
---|
1745 | if( ( m_layerId == 1 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) || ( m_layerId == 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) ) |
---|
1746 | #else |
---|
1747 | if( m_layerId == 0 ) |
---|
1748 | #endif |
---|
1749 | { |
---|
1750 | #else |
---|
1751 | OutputNALUnit nalu(NAL_UNIT_VPS); |
---|
1752 | #endif |
---|
1753 | #if VPS_VUI_OFFSET |
---|
1754 | // The following code also calculates the VPS VUI offset |
---|
1755 | #endif |
---|
1756 | #if VPS_EXTN_OFFSET_CALC |
---|
1757 | OutputNALUnit tempNalu(NAL_UNIT_VPS, 0, 0 ); // The value of nuh_layer_id of VPS NAL unit shall be equal to 0. |
---|
1758 | m_pcEntropyCoder->setBitstream(&tempNalu.m_Bitstream); |
---|
1759 | m_pcEntropyCoder->encodeVPS(m_pcEncTop->getVPS()); // Use to calculate the VPS extension offset |
---|
1760 | #endif |
---|
1761 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1762 | m_pcEntropyCoder->encodeVPS(m_pcEncTop->getVPS()); |
---|
1763 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1764 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1765 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
1766 | #if SVC_EXTENSION |
---|
1767 | } |
---|
1768 | #endif |
---|
1769 | |
---|
1770 | #if SVC_EXTENSION |
---|
1771 | nalu = NALUnit(NAL_UNIT_SPS, 0, m_layerId); |
---|
1772 | #else |
---|
1773 | nalu = NALUnit(NAL_UNIT_SPS); |
---|
1774 | #endif |
---|
1775 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1776 | if (m_bSeqFirst) |
---|
1777 | { |
---|
1778 | pcSlice->getSPS()->setNumLongTermRefPicSPS(m_numLongTermRefPicSPS); |
---|
1779 | for (Int k = 0; k < m_numLongTermRefPicSPS; k++) |
---|
1780 | { |
---|
1781 | pcSlice->getSPS()->setLtRefPicPocLsbSps(k, m_ltRefPicPocLsbSps[k]); |
---|
1782 | pcSlice->getSPS()->setUsedByCurrPicLtSPSFlag(k, m_ltRefPicUsedByCurrPicFlag[k]); |
---|
1783 | } |
---|
1784 | } |
---|
1785 | if( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) |
---|
1786 | { |
---|
1787 | UInt maxCU = m_pcCfg->getSliceArgument() >> ( pcSlice->getSPS()->getMaxCUDepth() << 1); |
---|
1788 | UInt numDU = ( m_pcCfg->getSliceMode() == 1 ) ? ( pcPic->getNumCUsInFrame() / maxCU ) : ( 0 ); |
---|
1789 | if( pcPic->getNumCUsInFrame() % maxCU != 0 || numDU == 0 ) |
---|
1790 | { |
---|
1791 | numDU ++; |
---|
1792 | } |
---|
1793 | pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->setNumDU( numDU ); |
---|
1794 | pcSlice->getSPS()->setHrdParameters( m_pcCfg->getFrameRate(), numDU, m_pcCfg->getTargetBitrate(), ( m_pcCfg->getIntraPeriod() > 0 ) ); |
---|
1795 | } |
---|
1796 | if( m_pcCfg->getBufferingPeriodSEIEnabled() || m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) |
---|
1797 | { |
---|
1798 | pcSlice->getSPS()->getVuiParameters()->setHrdParametersPresentFlag( true ); |
---|
1799 | } |
---|
1800 | #if O0092_0094_DEPENDENCY_CONSTRAINT |
---|
1801 | assert( pcSlice->getSPS()->getLayerId() == 0 || pcSlice->getSPS()->getLayerId() == m_layerId || m_pcEncTop->getVPS()->getRecursiveRefLayerFlag(m_layerId, pcSlice->getSPS()->getLayerId()) ); |
---|
1802 | #endif |
---|
1803 | m_pcEntropyCoder->encodeSPS(pcSlice->getSPS()); |
---|
1804 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1805 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1806 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
1807 | |
---|
1808 | #if SVC_EXTENSION |
---|
1809 | nalu = NALUnit(NAL_UNIT_PPS, 0, m_layerId); |
---|
1810 | #else |
---|
1811 | nalu = NALUnit(NAL_UNIT_PPS); |
---|
1812 | #endif |
---|
1813 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1814 | #if O0092_0094_DEPENDENCY_CONSTRAINT |
---|
1815 | assert( pcSlice->getPPS()->getPPSId() == 0 || pcSlice->getPPS()->getPPSId() == m_layerId || m_pcEncTop->getVPS()->getRecursiveRefLayerFlag(m_layerId, pcSlice->getPPS()->getPPSId()) ); |
---|
1816 | #endif |
---|
1817 | m_pcEntropyCoder->encodePPS(pcSlice->getPPS()); |
---|
1818 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1819 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1820 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
1821 | |
---|
1822 | xCreateLeadingSEIMessages(accessUnit, pcSlice->getSPS()); |
---|
1823 | |
---|
1824 | m_bSeqFirst = false; |
---|
1825 | } |
---|
1826 | |
---|
1827 | if (writeSOP) // write SOP description SEI (if enabled) at the beginning of GOP |
---|
1828 | { |
---|
1829 | Int SOPcurrPOC = pocCurr; |
---|
1830 | |
---|
1831 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
1832 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1833 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1834 | |
---|
1835 | SEISOPDescription SOPDescriptionSEI; |
---|
1836 | SOPDescriptionSEI.m_sopSeqParameterSetId = pcSlice->getSPS()->getSPSId(); |
---|
1837 | |
---|
1838 | UInt i = 0; |
---|
1839 | UInt prevEntryId = iGOPid; |
---|
1840 | for (j = iGOPid; j < m_iGopSize; j++) |
---|
1841 | { |
---|
1842 | Int deltaPOC = m_pcCfg->getGOPEntry(j).m_POC - m_pcCfg->getGOPEntry(prevEntryId).m_POC; |
---|
1843 | if ((SOPcurrPOC + deltaPOC) < m_pcCfg->getFramesToBeEncoded()) |
---|
1844 | { |
---|
1845 | SOPcurrPOC += deltaPOC; |
---|
1846 | SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR); |
---|
1847 | SOPDescriptionSEI.m_sopDescTemporalId[i] = m_pcCfg->getGOPEntry(j).m_temporalId; |
---|
1848 | SOPDescriptionSEI.m_sopDescStRpsIdx[i] = m_pcEncTop->getReferencePictureSetIdxForSOP(pcSlice, SOPcurrPOC, j); |
---|
1849 | SOPDescriptionSEI.m_sopDescPocDelta[i] = deltaPOC; |
---|
1850 | |
---|
1851 | prevEntryId = j; |
---|
1852 | i++; |
---|
1853 | } |
---|
1854 | } |
---|
1855 | |
---|
1856 | SOPDescriptionSEI.m_numPicsInSopMinus1 = i - 1; |
---|
1857 | |
---|
1858 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, SOPDescriptionSEI, pcSlice->getSPS()); |
---|
1859 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1860 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1861 | |
---|
1862 | writeSOP = false; |
---|
1863 | } |
---|
1864 | |
---|
1865 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
1866 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
1867 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
1868 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) |
---|
1869 | { |
---|
1870 | if( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getSubPicCpbParamsPresentFlag() ) |
---|
1871 | { |
---|
1872 | UInt numDU = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNumDU(); |
---|
1873 | pictureTimingSEI.m_numDecodingUnitsMinus1 = ( numDU - 1 ); |
---|
1874 | pictureTimingSEI.m_duCommonCpbRemovalDelayFlag = false; |
---|
1875 | |
---|
1876 | if( pictureTimingSEI.m_numNalusInDuMinus1 == NULL ) |
---|
1877 | { |
---|
1878 | pictureTimingSEI.m_numNalusInDuMinus1 = new UInt[ numDU ]; |
---|
1879 | } |
---|
1880 | if( pictureTimingSEI.m_duCpbRemovalDelayMinus1 == NULL ) |
---|
1881 | { |
---|
1882 | pictureTimingSEI.m_duCpbRemovalDelayMinus1 = new UInt[ numDU ]; |
---|
1883 | } |
---|
1884 | if( accumBitsDU == NULL ) |
---|
1885 | { |
---|
1886 | accumBitsDU = new UInt[ numDU ]; |
---|
1887 | } |
---|
1888 | if( accumNalsDU == NULL ) |
---|
1889 | { |
---|
1890 | accumNalsDU = new UInt[ numDU ]; |
---|
1891 | } |
---|
1892 | } |
---|
1893 | pictureTimingSEI.m_auCpbRemovalDelay = std::min<Int>(std::max<Int>(1, m_totalCoded - m_lastBPSEI), static_cast<Int>(pow(2, static_cast<double>(pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getCpbRemovalDelayLengthMinus1()+1)))); // Syntax element signalled as minus, hence the . |
---|
1894 | #if POC_RESET_FLAG |
---|
1895 | pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pocCurr - m_totalCoded; |
---|
1896 | #else |
---|
1897 | pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded; |
---|
1898 | #endif |
---|
1899 | Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2; |
---|
1900 | pictureTimingSEI.m_picDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay; |
---|
1901 | if( m_pcCfg->getDecodingUnitInfoSEIEnabled() ) |
---|
1902 | { |
---|
1903 | picSptDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay; |
---|
1904 | } |
---|
1905 | } |
---|
1906 | |
---|
1907 | if( ( m_pcCfg->getBufferingPeriodSEIEnabled() ) && ( pcSlice->getSliceType() == I_SLICE ) && |
---|
1908 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
1909 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
1910 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) |
---|
1911 | { |
---|
1912 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
1913 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1914 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1915 | |
---|
1916 | SEIBufferingPeriod sei_buffering_period; |
---|
1917 | |
---|
1918 | UInt uiInitialCpbRemovalDelay = (90000/2); // 0.5 sec |
---|
1919 | sei_buffering_period.m_initialCpbRemovalDelay [0][0] = uiInitialCpbRemovalDelay; |
---|
1920 | sei_buffering_period.m_initialCpbRemovalDelayOffset[0][0] = uiInitialCpbRemovalDelay; |
---|
1921 | sei_buffering_period.m_initialCpbRemovalDelay [0][1] = uiInitialCpbRemovalDelay; |
---|
1922 | sei_buffering_period.m_initialCpbRemovalDelayOffset[0][1] = uiInitialCpbRemovalDelay; |
---|
1923 | |
---|
1924 | Double dTmp = (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getNumUnitsInTick() / (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getTimeScale(); |
---|
1925 | |
---|
1926 | UInt uiTmp = (UInt)( dTmp * 90000.0 ); |
---|
1927 | uiInitialCpbRemovalDelay -= uiTmp; |
---|
1928 | uiInitialCpbRemovalDelay -= uiTmp / ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2 ); |
---|
1929 | sei_buffering_period.m_initialAltCpbRemovalDelay [0][0] = uiInitialCpbRemovalDelay; |
---|
1930 | sei_buffering_period.m_initialAltCpbRemovalDelayOffset[0][0] = uiInitialCpbRemovalDelay; |
---|
1931 | sei_buffering_period.m_initialAltCpbRemovalDelay [0][1] = uiInitialCpbRemovalDelay; |
---|
1932 | sei_buffering_period.m_initialAltCpbRemovalDelayOffset[0][1] = uiInitialCpbRemovalDelay; |
---|
1933 | |
---|
1934 | sei_buffering_period.m_rapCpbParamsPresentFlag = 0; |
---|
1935 | //for the concatenation, it can be set to one during splicing. |
---|
1936 | sei_buffering_period.m_concatenationFlag = 0; |
---|
1937 | //since the temporal layer HRD is not ready, we assumed it is fixed |
---|
1938 | sei_buffering_period.m_auCpbRemovalDelayDelta = 1; |
---|
1939 | sei_buffering_period.m_cpbDelayOffset = 0; |
---|
1940 | sei_buffering_period.m_dpbDelayOffset = 0; |
---|
1941 | |
---|
1942 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_buffering_period, pcSlice->getSPS()); |
---|
1943 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1944 | { |
---|
1945 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
1946 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU; // Insert BP SEI after APS SEI |
---|
1947 | AccessUnit::iterator it; |
---|
1948 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
1949 | { |
---|
1950 | it++; |
---|
1951 | } |
---|
1952 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
1953 | m_bufferingPeriodSEIPresentInAU = true; |
---|
1954 | } |
---|
1955 | |
---|
1956 | if (m_pcCfg->getScalableNestingSEIEnabled()) |
---|
1957 | { |
---|
1958 | OutputNALUnit naluTmp(NAL_UNIT_PREFIX_SEI); |
---|
1959 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1960 | m_pcEntropyCoder->setBitstream(&naluTmp.m_Bitstream); |
---|
1961 | scalableNestingSEI.m_nestedSEIs.clear(); |
---|
1962 | scalableNestingSEI.m_nestedSEIs.push_back(&sei_buffering_period); |
---|
1963 | m_seiWriter.writeSEImessage( naluTmp.m_Bitstream, scalableNestingSEI, pcSlice->getSPS()); |
---|
1964 | writeRBSPTrailingBits(naluTmp.m_Bitstream); |
---|
1965 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
1966 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU; // Insert BP SEI after non-nested APS, BP and PT SEIs |
---|
1967 | AccessUnit::iterator it; |
---|
1968 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
1969 | { |
---|
1970 | it++; |
---|
1971 | } |
---|
1972 | accessUnit.insert(it, new NALUnitEBSP(naluTmp)); |
---|
1973 | m_nestedBufferingPeriodSEIPresentInAU = true; |
---|
1974 | } |
---|
1975 | |
---|
1976 | m_lastBPSEI = m_totalCoded; |
---|
1977 | m_cpbRemovalDelay = 0; |
---|
1978 | } |
---|
1979 | m_cpbRemovalDelay ++; |
---|
1980 | if( ( m_pcEncTop->getRecoveryPointSEIEnabled() ) && ( pcSlice->getSliceType() == I_SLICE ) ) |
---|
1981 | { |
---|
1982 | if( m_pcEncTop->getGradualDecodingRefreshInfoEnabled() && !pcSlice->getRapPicFlag() ) |
---|
1983 | { |
---|
1984 | // Gradual decoding refresh SEI |
---|
1985 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
1986 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1987 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1988 | |
---|
1989 | SEIGradualDecodingRefreshInfo seiGradualDecodingRefreshInfo; |
---|
1990 | seiGradualDecodingRefreshInfo.m_gdrForegroundFlag = true; // Indicating all "foreground" |
---|
1991 | |
---|
1992 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, seiGradualDecodingRefreshInfo, pcSlice->getSPS() ); |
---|
1993 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1994 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1995 | } |
---|
1996 | // Recovery point SEI |
---|
1997 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
1998 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1999 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
2000 | |
---|
2001 | SEIRecoveryPoint sei_recovery_point; |
---|
2002 | sei_recovery_point.m_recoveryPocCnt = 0; |
---|
2003 | #if POC_RESET_FLAG |
---|
2004 | sei_recovery_point.m_exactMatchingFlag = ( pocCurr == 0 ) ? (true) : (false); |
---|
2005 | #else |
---|
2006 | sei_recovery_point.m_exactMatchingFlag = ( pcSlice->getPOC() == 0 ) ? (true) : (false); |
---|
2007 | #endif |
---|
2008 | sei_recovery_point.m_brokenLinkFlag = false; |
---|
2009 | |
---|
2010 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_recovery_point, pcSlice->getSPS() ); |
---|
2011 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
2012 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
2013 | } |
---|
2014 | |
---|
2015 | /* use the main bitstream buffer for storing the marshalled picture */ |
---|
2016 | m_pcEntropyCoder->setBitstream(NULL); |
---|
2017 | |
---|
2018 | startCUAddrSliceIdx = 0; |
---|
2019 | startCUAddrSlice = 0; |
---|
2020 | |
---|
2021 | startCUAddrSliceSegmentIdx = 0; |
---|
2022 | startCUAddrSliceSegment = 0; |
---|
2023 | nextCUAddr = 0; |
---|
2024 | pcSlice = pcPic->getSlice(startCUAddrSliceIdx); |
---|
2025 | |
---|
2026 | Int processingState = (pcSlice->getSPS()->getUseSAO())?(EXECUTE_INLOOPFILTER):(ENCODE_SLICE); |
---|
2027 | Bool skippedSlice=false; |
---|
2028 | while (nextCUAddr < uiRealEndAddress) // Iterate over all slices |
---|
2029 | { |
---|
2030 | switch(processingState) |
---|
2031 | { |
---|
2032 | case ENCODE_SLICE: |
---|
2033 | { |
---|
2034 | pcSlice->setNextSlice ( false ); |
---|
2035 | pcSlice->setNextSliceSegment( false ); |
---|
2036 | if (nextCUAddr == m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx]) |
---|
2037 | { |
---|
2038 | pcSlice = pcPic->getSlice(startCUAddrSliceIdx); |
---|
2039 | if(startCUAddrSliceIdx > 0 && pcSlice->getSliceType()!= I_SLICE) |
---|
2040 | { |
---|
2041 | pcSlice->checkColRefIdx(startCUAddrSliceIdx, pcPic); |
---|
2042 | } |
---|
2043 | pcPic->setCurrSliceIdx(startCUAddrSliceIdx); |
---|
2044 | m_pcSliceEncoder->setSliceIdx(startCUAddrSliceIdx); |
---|
2045 | assert(startCUAddrSliceIdx == pcSlice->getSliceIdx()); |
---|
2046 | // Reconstruction slice |
---|
2047 | pcSlice->setSliceCurStartCUAddr( nextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
2048 | pcSlice->setSliceCurEndCUAddr ( m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx+1 ] ); |
---|
2049 | // Dependent slice |
---|
2050 | pcSlice->setSliceSegmentCurStartCUAddr( nextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
2051 | pcSlice->setSliceSegmentCurEndCUAddr ( m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx+1 ] ); |
---|
2052 | |
---|
2053 | pcSlice->setNextSlice ( true ); |
---|
2054 | |
---|
2055 | startCUAddrSliceIdx++; |
---|
2056 | startCUAddrSliceSegmentIdx++; |
---|
2057 | } |
---|
2058 | else if (nextCUAddr == m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx]) |
---|
2059 | { |
---|
2060 | // Dependent slice |
---|
2061 | pcSlice->setSliceSegmentCurStartCUAddr( nextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
2062 | pcSlice->setSliceSegmentCurEndCUAddr ( m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx+1 ] ); |
---|
2063 | |
---|
2064 | pcSlice->setNextSliceSegment( true ); |
---|
2065 | |
---|
2066 | startCUAddrSliceSegmentIdx++; |
---|
2067 | } |
---|
2068 | #if SVC_EXTENSION && M0457_COL_PICTURE_SIGNALING |
---|
2069 | pcSlice->setNumMotionPredRefLayers(m_pcEncTop->getNumMotionPredRefLayers()); |
---|
2070 | #endif |
---|
2071 | pcSlice->setRPS(pcPic->getSlice(0)->getRPS()); |
---|
2072 | pcSlice->setRPSidx(pcPic->getSlice(0)->getRPSidx()); |
---|
2073 | UInt uiDummyStartCUAddr; |
---|
2074 | UInt uiDummyBoundingCUAddr; |
---|
2075 | m_pcSliceEncoder->xDetermineStartAndBoundingCUAddr(uiDummyStartCUAddr,uiDummyBoundingCUAddr,pcPic,true); |
---|
2076 | |
---|
2077 | uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
---|
2078 | uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
---|
2079 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
2080 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
2081 | |
---|
2082 | #if REPN_FORMAT_IN_VPS |
---|
2083 | uiWidth = pcSlice->getPicWidthInLumaSamples(); |
---|
2084 | uiHeight = pcSlice->getPicHeightInLumaSamples(); |
---|
2085 | #else |
---|
2086 | uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
2087 | uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
2088 | #endif |
---|
2089 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
2090 | { |
---|
2091 | uiInternalAddress--; |
---|
2092 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
2093 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
2094 | } |
---|
2095 | uiInternalAddress++; |
---|
2096 | if(uiInternalAddress==pcPic->getNumPartInCU()) |
---|
2097 | { |
---|
2098 | uiInternalAddress = 0; |
---|
2099 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
---|
2100 | } |
---|
2101 | UInt endAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
---|
2102 | if(endAddress<=pcSlice->getSliceSegmentCurStartCUAddr()) |
---|
2103 | { |
---|
2104 | UInt boundingAddrSlice, boundingAddrSliceSegment; |
---|
2105 | boundingAddrSlice = m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx]; |
---|
2106 | boundingAddrSliceSegment = m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx]; |
---|
2107 | nextCUAddr = min(boundingAddrSlice, boundingAddrSliceSegment); |
---|
2108 | if(pcSlice->isNextSlice()) |
---|
2109 | { |
---|
2110 | skippedSlice=true; |
---|
2111 | } |
---|
2112 | continue; |
---|
2113 | } |
---|
2114 | if(skippedSlice) |
---|
2115 | { |
---|
2116 | pcSlice->setNextSlice ( true ); |
---|
2117 | pcSlice->setNextSliceSegment( false ); |
---|
2118 | } |
---|
2119 | skippedSlice=false; |
---|
2120 | pcSlice->allocSubstreamSizes( iNumSubstreams ); |
---|
2121 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
2122 | { |
---|
2123 | pcSubstreamsOut[ui].clear(); |
---|
2124 | } |
---|
2125 | |
---|
2126 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
2127 | m_pcEntropyCoder->resetEntropy (); |
---|
2128 | /* start slice NALunit */ |
---|
2129 | #if SVC_EXTENSION |
---|
2130 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer(), m_layerId ); |
---|
2131 | #else |
---|
2132 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer() ); |
---|
2133 | #endif |
---|
2134 | Bool sliceSegment = (!pcSlice->isNextSlice()); |
---|
2135 | if (!sliceSegment) |
---|
2136 | { |
---|
2137 | uiOneBitstreamPerSliceLength = 0; // start of a new slice |
---|
2138 | } |
---|
2139 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
2140 | tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2141 | m_pcEntropyCoder->encodeSliceHeader(pcSlice); |
---|
2142 | actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting ); |
---|
2143 | |
---|
2144 | // is it needed? |
---|
2145 | { |
---|
2146 | if (!sliceSegment) |
---|
2147 | { |
---|
2148 | pcBitstreamRedirect->writeAlignOne(); |
---|
2149 | } |
---|
2150 | else |
---|
2151 | { |
---|
2152 | // We've not completed our slice header info yet, do the alignment later. |
---|
2153 | } |
---|
2154 | m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC ); |
---|
2155 | m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); |
---|
2156 | m_pcEntropyCoder->resetEntropy (); |
---|
2157 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ ) |
---|
2158 | { |
---|
2159 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
2160 | m_pcEntropyCoder->resetEntropy (); |
---|
2161 | } |
---|
2162 | } |
---|
2163 | |
---|
2164 | if(pcSlice->isNextSlice()) |
---|
2165 | { |
---|
2166 | // set entropy coder for writing |
---|
2167 | m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC ); |
---|
2168 | { |
---|
2169 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ ) |
---|
2170 | { |
---|
2171 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
2172 | m_pcEntropyCoder->resetEntropy (); |
---|
2173 | } |
---|
2174 | pcSbacCoders[0].load(m_pcSbacCoder); |
---|
2175 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[0], pcSlice ); //ALF is written in substream #0 with CABAC coder #0 (see ALF param encoding below) |
---|
2176 | } |
---|
2177 | m_pcEntropyCoder->resetEntropy (); |
---|
2178 | // File writing |
---|
2179 | if (!sliceSegment) |
---|
2180 | { |
---|
2181 | m_pcEntropyCoder->setBitstream(pcBitstreamRedirect); |
---|
2182 | } |
---|
2183 | else |
---|
2184 | { |
---|
2185 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
2186 | } |
---|
2187 | // for now, override the TILES_DECODER setting in order to write substreams. |
---|
2188 | m_pcEntropyCoder->setBitstream ( &pcSubstreamsOut[0] ); |
---|
2189 | |
---|
2190 | } |
---|
2191 | pcSlice->setFinalized(true); |
---|
2192 | |
---|
2193 | m_pcSbacCoder->load( &pcSbacCoders[0] ); |
---|
2194 | |
---|
2195 | pcSlice->setTileOffstForMultES( uiOneBitstreamPerSliceLength ); |
---|
2196 | pcSlice->setTileLocationCount ( 0 ); |
---|
2197 | m_pcSliceEncoder->encodeSlice(pcPic, pcSubstreamsOut); |
---|
2198 | |
---|
2199 | { |
---|
2200 | // Construct the final bitstream by flushing and concatenating substreams. |
---|
2201 | // The final bitstream is either nalu.m_Bitstream or pcBitstreamRedirect; |
---|
2202 | UInt* puiSubstreamSizes = pcSlice->getSubstreamSizes(); |
---|
2203 | UInt uiTotalCodedSize = 0; // for padding calcs. |
---|
2204 | UInt uiNumSubstreamsPerTile = iNumSubstreams; |
---|
2205 | if (iNumSubstreams > 1) |
---|
2206 | { |
---|
2207 | uiNumSubstreamsPerTile /= pcPic->getPicSym()->getNumTiles(); |
---|
2208 | } |
---|
2209 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
2210 | { |
---|
2211 | // Flush all substreams -- this includes empty ones. |
---|
2212 | // Terminating bit and flush. |
---|
2213 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
2214 | m_pcEntropyCoder->setBitstream ( &pcSubstreamsOut[ui] ); |
---|
2215 | m_pcEntropyCoder->encodeTerminatingBit( 1 ); |
---|
2216 | m_pcEntropyCoder->encodeSliceFinish(); |
---|
2217 | |
---|
2218 | pcSubstreamsOut[ui].writeByteAlignment(); // Byte-alignment in slice_data() at end of sub-stream |
---|
2219 | // Byte alignment is necessary between tiles when tiles are independent. |
---|
2220 | uiTotalCodedSize += pcSubstreamsOut[ui].getNumberOfWrittenBits(); |
---|
2221 | |
---|
2222 | Bool bNextSubstreamInNewTile = ((ui+1) < iNumSubstreams)&& ((ui+1)%uiNumSubstreamsPerTile == 0); |
---|
2223 | if (bNextSubstreamInNewTile) |
---|
2224 | { |
---|
2225 | pcSlice->setTileLocation(ui/uiNumSubstreamsPerTile, pcSlice->getTileOffstForMultES()+(uiTotalCodedSize>>3)); |
---|
2226 | } |
---|
2227 | if (ui+1 < pcSlice->getPPS()->getNumSubstreams()) |
---|
2228 | { |
---|
2229 | puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits() + (pcSubstreamsOut[ui].countStartCodeEmulations()<<3); |
---|
2230 | } |
---|
2231 | } |
---|
2232 | |
---|
2233 | // Complete the slice header info. |
---|
2234 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
2235 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
2236 | m_pcEntropyCoder->encodeTilesWPPEntryPoint( pcSlice ); |
---|
2237 | |
---|
2238 | // Substreams... |
---|
2239 | TComOutputBitstream *pcOut = pcBitstreamRedirect; |
---|
2240 | Int offs = 0; |
---|
2241 | Int nss = pcSlice->getPPS()->getNumSubstreams(); |
---|
2242 | if (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) |
---|
2243 | { |
---|
2244 | // 1st line present for WPP. |
---|
2245 | offs = pcSlice->getSliceSegmentCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU()/pcSlice->getPic()->getFrameWidthInCU(); |
---|
2246 | nss = pcSlice->getNumEntryPointOffsets()+1; |
---|
2247 | } |
---|
2248 | for ( UInt ui = 0 ; ui < nss; ui++ ) |
---|
2249 | { |
---|
2250 | pcOut->addSubstream(&pcSubstreamsOut[ui+offs]); |
---|
2251 | } |
---|
2252 | } |
---|
2253 | |
---|
2254 | UInt boundingAddrSlice, boundingAddrSliceSegment; |
---|
2255 | boundingAddrSlice = m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx]; |
---|
2256 | boundingAddrSliceSegment = m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx]; |
---|
2257 | nextCUAddr = min(boundingAddrSlice, boundingAddrSliceSegment); |
---|
2258 | // If current NALU is the first NALU of slice (containing slice header) and more NALUs exist (due to multiple dependent slices) then buffer it. |
---|
2259 | // If current NALU is the last NALU of slice and a NALU was buffered, then (a) Write current NALU (b) Update an write buffered NALU at approproate location in NALU list. |
---|
2260 | Bool bNALUAlignedWrittenToList = false; // used to ensure current NALU is not written more than once to the NALU list. |
---|
2261 | xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect); |
---|
2262 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
2263 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
2264 | bNALUAlignedWrittenToList = true; |
---|
2265 | uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits(); // length of bitstream after byte-alignment |
---|
2266 | |
---|
2267 | if (!bNALUAlignedWrittenToList) |
---|
2268 | { |
---|
2269 | { |
---|
2270 | nalu.m_Bitstream.writeAlignZero(); |
---|
2271 | } |
---|
2272 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
2273 | uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits() + 24; // length of bitstream after byte-alignment + 3 byte startcode 0x000001 |
---|
2274 | } |
---|
2275 | |
---|
2276 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
2277 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
2278 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
2279 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) && |
---|
2280 | ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getSubPicCpbParamsPresentFlag() ) ) |
---|
2281 | { |
---|
2282 | UInt numNalus = 0; |
---|
2283 | UInt numRBSPBytes = 0; |
---|
2284 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
2285 | { |
---|
2286 | UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size()); |
---|
2287 | if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) |
---|
2288 | { |
---|
2289 | numRBSPBytes += numRBSPBytes_nal; |
---|
2290 | numNalus ++; |
---|
2291 | } |
---|
2292 | } |
---|
2293 | accumBitsDU[ pcSlice->getSliceIdx() ] = ( numRBSPBytes << 3 ); |
---|
2294 | accumNalsDU[ pcSlice->getSliceIdx() ] = numNalus; // SEI not counted for bit count; hence shouldn't be counted for # of NALUs - only for consistency |
---|
2295 | } |
---|
2296 | processingState = ENCODE_SLICE; |
---|
2297 | } |
---|
2298 | break; |
---|
2299 | case EXECUTE_INLOOPFILTER: |
---|
2300 | { |
---|
2301 | // set entropy coder for RD |
---|
2302 | m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); |
---|
2303 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
2304 | if ( pcSlice->getSPS()->getUseSAO() && !( m_pcEncTop->getSkipPictureAtArcSwitch() && m_pcEncTop->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncTop->getAdaptiveResolutionChange()) ) |
---|
2305 | #else |
---|
2306 | if ( pcSlice->getSPS()->getUseSAO() ) |
---|
2307 | #endif |
---|
2308 | { |
---|
2309 | m_pcEntropyCoder->resetEntropy(); |
---|
2310 | m_pcEntropyCoder->setBitstream( m_pcBitCounter ); |
---|
2311 | #if HM_CLEANUP_SAO |
---|
2312 | Bool sliceEnabled[NUM_SAO_COMPONENTS]; |
---|
2313 | m_pcSAO->initRDOCabacCoder(m_pcEncTop->getRDGoOnSbacCoder(), pcSlice); |
---|
2314 | m_pcSAO->SAOProcess(pcPic |
---|
2315 | , sliceEnabled |
---|
2316 | , pcPic->getSlice(0)->getLambdas() |
---|
2317 | #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK |
---|
2318 | , m_pcCfg->getSaoLcuBoundary() |
---|
2319 | #endif |
---|
2320 | ); |
---|
2321 | m_pcSAO->PCMLFDisableProcess(pcPic); |
---|
2322 | |
---|
2323 | //assign SAO slice header |
---|
2324 | for(Int s=0; s< uiNumSlices; s++) |
---|
2325 | { |
---|
2326 | pcPic->getSlice(s)->setSaoEnabledFlag(sliceEnabled[SAO_Y]); |
---|
2327 | assert(sliceEnabled[SAO_Cb] == sliceEnabled[SAO_Cr]); |
---|
2328 | pcPic->getSlice(s)->setSaoEnabledFlagChroma(sliceEnabled[SAO_Cb]); |
---|
2329 | } |
---|
2330 | #else |
---|
2331 | m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcEncTop->getRDGoOnSbacCoder()); |
---|
2332 | SAOParam& cSaoParam = *pcSlice->getPic()->getPicSym()->getSaoParam(); |
---|
2333 | |
---|
2334 | #if SAO_ENCODING_CHOICE |
---|
2335 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdas()[TEXT_LUMA], pcPic->getSlice(0)->getLambdas()[TEXT_CHROMA], pcPic->getSlice(0)->getDepth()); |
---|
2336 | #else |
---|
2337 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma()); |
---|
2338 | #endif |
---|
2339 | m_pcSAO->endSaoEnc(); |
---|
2340 | m_pcSAO->PCMLFDisableProcess(pcPic); |
---|
2341 | #endif |
---|
2342 | } |
---|
2343 | #if !HM_CLEANUP_SAO |
---|
2344 | #if SAO_RDO |
---|
2345 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
2346 | #endif |
---|
2347 | #endif |
---|
2348 | processingState = ENCODE_SLICE; |
---|
2349 | #if !HM_CLEANUP_SAO |
---|
2350 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
2351 | if ( ( m_pcEncTop->getSkipPictureAtArcSwitch() && m_pcEncTop->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncTop->getAdaptiveResolutionChange()) ) |
---|
2352 | { |
---|
2353 | pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[0]=0; |
---|
2354 | pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[1]=0; |
---|
2355 | } |
---|
2356 | #endif |
---|
2357 | for(Int s=0; s< uiNumSlices; s++) |
---|
2358 | { |
---|
2359 | if (pcSlice->getSPS()->getUseSAO()) |
---|
2360 | { |
---|
2361 | pcPic->getSlice(s)->setSaoEnabledFlag((pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[0]==1)?true:false); |
---|
2362 | } |
---|
2363 | } |
---|
2364 | #endif |
---|
2365 | } |
---|
2366 | break; |
---|
2367 | default: |
---|
2368 | { |
---|
2369 | printf("Not a supported encoding state\n"); |
---|
2370 | assert(0); |
---|
2371 | exit(-1); |
---|
2372 | } |
---|
2373 | } |
---|
2374 | } // end iteration over slices |
---|
2375 | #if !HM_CLEANUP_SAO |
---|
2376 | if(pcSlice->getSPS()->getUseSAO()) |
---|
2377 | { |
---|
2378 | if(pcSlice->getSPS()->getUseSAO()) |
---|
2379 | { |
---|
2380 | m_pcSAO->destroyPicSaoInfo(); |
---|
2381 | } |
---|
2382 | pcPic->destroyNonDBFilterInfo(); |
---|
2383 | } |
---|
2384 | #endif |
---|
2385 | pcPic->compressMotion(); |
---|
2386 | |
---|
2387 | //-- For time output for each slice |
---|
2388 | Double dEncTime = (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
2389 | |
---|
2390 | const Char* digestStr = NULL; |
---|
2391 | if (m_pcCfg->getDecodedPictureHashSEIEnabled()) |
---|
2392 | { |
---|
2393 | /* calculate MD5sum for entire reconstructed picture */ |
---|
2394 | SEIDecodedPictureHash sei_recon_picture_digest; |
---|
2395 | if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 1) |
---|
2396 | { |
---|
2397 | sei_recon_picture_digest.method = SEIDecodedPictureHash::MD5; |
---|
2398 | calcMD5(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
2399 | digestStr = digestToString(sei_recon_picture_digest.digest, 16); |
---|
2400 | } |
---|
2401 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 2) |
---|
2402 | { |
---|
2403 | sei_recon_picture_digest.method = SEIDecodedPictureHash::CRC; |
---|
2404 | calcCRC(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
2405 | digestStr = digestToString(sei_recon_picture_digest.digest, 2); |
---|
2406 | } |
---|
2407 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 3) |
---|
2408 | { |
---|
2409 | sei_recon_picture_digest.method = SEIDecodedPictureHash::CHECKSUM; |
---|
2410 | calcChecksum(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
2411 | digestStr = digestToString(sei_recon_picture_digest.digest, 4); |
---|
2412 | } |
---|
2413 | #if SVC_EXTENSION |
---|
2414 | OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer(), m_layerId); |
---|
2415 | #else |
---|
2416 | OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer()); |
---|
2417 | #endif |
---|
2418 | |
---|
2419 | /* write the SEI messages */ |
---|
2420 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
2421 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei_recon_picture_digest, pcSlice->getSPS()); |
---|
2422 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
2423 | |
---|
2424 | accessUnit.insert(accessUnit.end(), new NALUnitEBSP(nalu)); |
---|
2425 | } |
---|
2426 | if (m_pcCfg->getTemporalLevel0IndexSEIEnabled()) |
---|
2427 | { |
---|
2428 | SEITemporalLevel0Index sei_temporal_level0_index; |
---|
2429 | if (pcSlice->getRapPicFlag()) |
---|
2430 | { |
---|
2431 | m_tl0Idx = 0; |
---|
2432 | m_rapIdx = (m_rapIdx + 1) & 0xFF; |
---|
2433 | } |
---|
2434 | else |
---|
2435 | { |
---|
2436 | m_tl0Idx = (m_tl0Idx + (pcSlice->getTLayer() ? 0 : 1)) & 0xFF; |
---|
2437 | } |
---|
2438 | sei_temporal_level0_index.tl0Idx = m_tl0Idx; |
---|
2439 | sei_temporal_level0_index.rapIdx = m_rapIdx; |
---|
2440 | |
---|
2441 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
2442 | |
---|
2443 | /* write the SEI messages */ |
---|
2444 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
2445 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei_temporal_level0_index, pcSlice->getSPS()); |
---|
2446 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
2447 | |
---|
2448 | /* insert the SEI message NALUnit before any Slice NALUnits */ |
---|
2449 | AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice)); |
---|
2450 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
2451 | } |
---|
2452 | |
---|
2453 | xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime ); |
---|
2454 | |
---|
2455 | //In case of field coding, compute the interlaced PSNR for both fields |
---|
2456 | if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff))) |
---|
2457 | { |
---|
2458 | //get complementary top field |
---|
2459 | TComPic* pcPicTop; |
---|
2460 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
2461 | while ((*iterPic)->getPOC() != pcPic->getPOC()-1) |
---|
2462 | { |
---|
2463 | iterPic ++; |
---|
2464 | } |
---|
2465 | pcPicTop = *(iterPic); |
---|
2466 | xCalculateInterlacedAddPSNR(pcPicTop, pcPic, pcPicTop->getPicYuvRec(), pcPic->getPicYuvRec(), accessUnit, dEncTime ); |
---|
2467 | } |
---|
2468 | |
---|
2469 | if (digestStr) |
---|
2470 | { |
---|
2471 | if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 1) |
---|
2472 | { |
---|
2473 | printf(" [MD5:%s]", digestStr); |
---|
2474 | } |
---|
2475 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 2) |
---|
2476 | { |
---|
2477 | printf(" [CRC:%s]", digestStr); |
---|
2478 | } |
---|
2479 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 3) |
---|
2480 | { |
---|
2481 | printf(" [Checksum:%s]", digestStr); |
---|
2482 | } |
---|
2483 | } |
---|
2484 | if ( m_pcCfg->getUseRateCtrl() ) |
---|
2485 | { |
---|
2486 | Double avgQP = m_pcRateCtrl->getRCPic()->calAverageQP(); |
---|
2487 | Double avgLambda = m_pcRateCtrl->getRCPic()->calAverageLambda(); |
---|
2488 | if ( avgLambda < 0.0 ) |
---|
2489 | { |
---|
2490 | avgLambda = lambda; |
---|
2491 | } |
---|
2492 | m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, pcSlice->getSliceType()); |
---|
2493 | m_pcRateCtrl->getRCPic()->addToPictureLsit( m_pcRateCtrl->getPicList() ); |
---|
2494 | |
---|
2495 | m_pcRateCtrl->getRCSeq()->updateAfterPic( actualTotalBits ); |
---|
2496 | if ( pcSlice->getSliceType() != I_SLICE ) |
---|
2497 | { |
---|
2498 | m_pcRateCtrl->getRCGOP()->updateAfterPicture( actualTotalBits ); |
---|
2499 | } |
---|
2500 | else // for intra picture, the estimated bits are used to update the current status in the GOP |
---|
2501 | { |
---|
2502 | m_pcRateCtrl->getRCGOP()->updateAfterPicture( estimatedBits ); |
---|
2503 | } |
---|
2504 | } |
---|
2505 | |
---|
2506 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
2507 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
2508 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
2509 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) |
---|
2510 | { |
---|
2511 | TComVUI *vui = pcSlice->getSPS()->getVuiParameters(); |
---|
2512 | TComHRD *hrd = vui->getHrdParameters(); |
---|
2513 | |
---|
2514 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
2515 | { |
---|
2516 | Int i; |
---|
2517 | UInt64 ui64Tmp; |
---|
2518 | UInt uiPrev = 0; |
---|
2519 | UInt numDU = ( pictureTimingSEI.m_numDecodingUnitsMinus1 + 1 ); |
---|
2520 | UInt *pCRD = &pictureTimingSEI.m_duCpbRemovalDelayMinus1[0]; |
---|
2521 | UInt maxDiff = ( hrd->getTickDivisorMinus2() + 2 ) - 1; |
---|
2522 | |
---|
2523 | for( i = 0; i < numDU; i ++ ) |
---|
2524 | { |
---|
2525 | pictureTimingSEI.m_numNalusInDuMinus1[ i ] = ( i == 0 ) ? ( accumNalsDU[ i ] - 1 ) : ( accumNalsDU[ i ] - accumNalsDU[ i - 1] - 1 ); |
---|
2526 | } |
---|
2527 | |
---|
2528 | if( numDU == 1 ) |
---|
2529 | { |
---|
2530 | pCRD[ 0 ] = 0; /* don't care */ |
---|
2531 | } |
---|
2532 | else |
---|
2533 | { |
---|
2534 | pCRD[ numDU - 1 ] = 0;/* by definition */ |
---|
2535 | UInt tmp = 0; |
---|
2536 | UInt accum = 0; |
---|
2537 | |
---|
2538 | for( i = ( numDU - 2 ); i >= 0; i -- ) |
---|
2539 | { |
---|
2540 | ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ] - accumBitsDU[ i ] ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
2541 | if( (UInt)ui64Tmp > maxDiff ) |
---|
2542 | { |
---|
2543 | tmp ++; |
---|
2544 | } |
---|
2545 | } |
---|
2546 | uiPrev = 0; |
---|
2547 | |
---|
2548 | UInt flag = 0; |
---|
2549 | for( i = ( numDU - 2 ); i >= 0; i -- ) |
---|
2550 | { |
---|
2551 | flag = 0; |
---|
2552 | ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ] - accumBitsDU[ i ] ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
2553 | |
---|
2554 | if( (UInt)ui64Tmp > maxDiff ) |
---|
2555 | { |
---|
2556 | if(uiPrev >= maxDiff - tmp) |
---|
2557 | { |
---|
2558 | ui64Tmp = uiPrev + 1; |
---|
2559 | flag = 1; |
---|
2560 | } |
---|
2561 | else ui64Tmp = maxDiff - tmp + 1; |
---|
2562 | } |
---|
2563 | pCRD[ i ] = (UInt)ui64Tmp - uiPrev - 1; |
---|
2564 | if( (Int)pCRD[ i ] < 0 ) |
---|
2565 | { |
---|
2566 | pCRD[ i ] = 0; |
---|
2567 | } |
---|
2568 | else if (tmp > 0 && flag == 1) |
---|
2569 | { |
---|
2570 | tmp --; |
---|
2571 | } |
---|
2572 | accum += pCRD[ i ] + 1; |
---|
2573 | uiPrev = accum; |
---|
2574 | } |
---|
2575 | } |
---|
2576 | } |
---|
2577 | if( m_pcCfg->getPictureTimingSEIEnabled() ) |
---|
2578 | { |
---|
2579 | { |
---|
2580 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer()); |
---|
2581 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
2582 | pictureTimingSEI.m_picStruct = (isField && pcSlice->getPic()->isTopField())? 1 : isField? 2 : 0; |
---|
2583 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS()); |
---|
2584 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
2585 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
2586 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU |
---|
2587 | + m_bufferingPeriodSEIPresentInAU; // Insert PT SEI after APS and BP SEI |
---|
2588 | AccessUnit::iterator it; |
---|
2589 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
2590 | { |
---|
2591 | it++; |
---|
2592 | } |
---|
2593 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
2594 | m_pictureTimingSEIPresentInAU = true; |
---|
2595 | } |
---|
2596 | if ( m_pcCfg->getScalableNestingSEIEnabled() ) // put picture timing SEI into scalable nesting SEI |
---|
2597 | { |
---|
2598 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer()); |
---|
2599 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
2600 | scalableNestingSEI.m_nestedSEIs.clear(); |
---|
2601 | scalableNestingSEI.m_nestedSEIs.push_back(&pictureTimingSEI); |
---|
2602 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, scalableNestingSEI, pcSlice->getSPS()); |
---|
2603 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
2604 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
2605 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU |
---|
2606 | + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU + m_nestedBufferingPeriodSEIPresentInAU; // Insert PT SEI after APS and BP SEI |
---|
2607 | AccessUnit::iterator it; |
---|
2608 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
2609 | { |
---|
2610 | it++; |
---|
2611 | } |
---|
2612 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
2613 | m_nestedPictureTimingSEIPresentInAU = true; |
---|
2614 | } |
---|
2615 | } |
---|
2616 | if( m_pcCfg->getDecodingUnitInfoSEIEnabled() && hrd->getSubPicCpbParamsPresentFlag() ) |
---|
2617 | { |
---|
2618 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
2619 | for( Int i = 0; i < ( pictureTimingSEI.m_numDecodingUnitsMinus1 + 1 ); i ++ ) |
---|
2620 | { |
---|
2621 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer()); |
---|
2622 | |
---|
2623 | SEIDecodingUnitInfo tempSEI; |
---|
2624 | tempSEI.m_decodingUnitIdx = i; |
---|
2625 | tempSEI.m_duSptCpbRemovalDelay = pictureTimingSEI.m_duCpbRemovalDelayMinus1[i] + 1; |
---|
2626 | tempSEI.m_dpbOutputDuDelayPresentFlag = false; |
---|
2627 | tempSEI.m_picSptDpbOutputDuDelay = picSptDpbOutputDuDelay; |
---|
2628 | |
---|
2629 | AccessUnit::iterator it; |
---|
2630 | // Insert the first one in the right location, before the first slice |
---|
2631 | if(i == 0) |
---|
2632 | { |
---|
2633 | // Insert before the first slice. |
---|
2634 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, tempSEI, pcSlice->getSPS()); |
---|
2635 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
2636 | |
---|
2637 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
2638 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU |
---|
2639 | + m_bufferingPeriodSEIPresentInAU |
---|
2640 | + m_pictureTimingSEIPresentInAU; // Insert DU info SEI after APS, BP and PT SEI |
---|
2641 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
2642 | { |
---|
2643 | it++; |
---|
2644 | } |
---|
2645 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
2646 | } |
---|
2647 | else |
---|
2648 | { |
---|
2649 | Int ctr; |
---|
2650 | // For the second decoding unit onwards we know how many NALUs are present |
---|
2651 | for (ctr = 0, it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
2652 | { |
---|
2653 | if(ctr == accumNalsDU[ i - 1 ]) |
---|
2654 | { |
---|
2655 | // Insert before the first slice. |
---|
2656 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, tempSEI, pcSlice->getSPS()); |
---|
2657 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
2658 | |
---|
2659 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
2660 | break; |
---|
2661 | } |
---|
2662 | if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) |
---|
2663 | { |
---|
2664 | ctr++; |
---|
2665 | } |
---|
2666 | } |
---|
2667 | } |
---|
2668 | } |
---|
2669 | } |
---|
2670 | } |
---|
2671 | xResetNonNestedSEIPresentFlags(); |
---|
2672 | xResetNestedSEIPresentFlags(); |
---|
2673 | pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut); |
---|
2674 | |
---|
2675 | #if M0040_ADAPTIVE_RESOLUTION_CHANGE |
---|
2676 | pcPicYuvRecOut->setReconstructed(true); |
---|
2677 | #endif |
---|
2678 | |
---|
2679 | pcPic->setReconMark ( true ); |
---|
2680 | m_bFirst = false; |
---|
2681 | m_iNumPicCoded++; |
---|
2682 | m_totalCoded ++; |
---|
2683 | /* logging: insert a newline at end of picture period */ |
---|
2684 | printf("\n"); |
---|
2685 | fflush(stdout); |
---|
2686 | |
---|
2687 | delete[] pcSubstreamsOut; |
---|
2688 | } |
---|
2689 | delete pcBitstreamRedirect; |
---|
2690 | |
---|
2691 | if( accumBitsDU != NULL) delete accumBitsDU; |
---|
2692 | if( accumNalsDU != NULL) delete accumNalsDU; |
---|
2693 | |
---|
2694 | #if SVC_EXTENSION |
---|
2695 | assert ( m_iNumPicCoded <= 1 || (isField && iPOCLast == 1) ); |
---|
2696 | #else |
---|
2697 | assert ( (m_iNumPicCoded == iNumPicRcvd) || (isField && iPOCLast == 1) ); |
---|
2698 | #endif |
---|
2699 | } |
---|
2700 | |
---|
2701 | #if !SVC_EXTENSION |
---|
2702 | Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded, Bool isField) |
---|
2703 | { |
---|
2704 | assert (uiNumAllPicCoded == m_gcAnalyzeAll.getNumPic()); |
---|
2705 | |
---|
2706 | |
---|
2707 | //--CFG_KDY |
---|
2708 | if(isField) |
---|
2709 | { |
---|
2710 | m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() * 2); |
---|
2711 | m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() * 2); |
---|
2712 | m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() * 2); |
---|
2713 | m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() * 2); |
---|
2714 | } |
---|
2715 | else |
---|
2716 | { |
---|
2717 | m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
2718 | m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
2719 | m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
2720 | m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
2721 | } |
---|
2722 | |
---|
2723 | //-- all |
---|
2724 | printf( "\n\nSUMMARY --------------------------------------------------------\n" ); |
---|
2725 | m_gcAnalyzeAll.printOut('a'); |
---|
2726 | |
---|
2727 | printf( "\n\nI Slices--------------------------------------------------------\n" ); |
---|
2728 | m_gcAnalyzeI.printOut('i'); |
---|
2729 | |
---|
2730 | printf( "\n\nP Slices--------------------------------------------------------\n" ); |
---|
2731 | m_gcAnalyzeP.printOut('p'); |
---|
2732 | |
---|
2733 | printf( "\n\nB Slices--------------------------------------------------------\n" ); |
---|
2734 | m_gcAnalyzeB.printOut('b'); |
---|
2735 | |
---|
2736 | #if _SUMMARY_OUT_ |
---|
2737 | m_gcAnalyzeAll.printSummaryOut(); |
---|
2738 | #endif |
---|
2739 | #if _SUMMARY_PIC_ |
---|
2740 | m_gcAnalyzeI.printSummary('I'); |
---|
2741 | m_gcAnalyzeP.printSummary('P'); |
---|
2742 | m_gcAnalyzeB.printSummary('B'); |
---|
2743 | #endif |
---|
2744 | |
---|
2745 | if(isField) |
---|
2746 | { |
---|
2747 | //-- interlaced summary |
---|
2748 | m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate()); |
---|
2749 | printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" ); |
---|
2750 | m_gcAnalyzeAll_in.printOutInterlaced('a', m_gcAnalyzeAll.getBits()); |
---|
2751 | |
---|
2752 | #if _SUMMARY_OUT_ |
---|
2753 | m_gcAnalyzeAll_in.printSummaryOutInterlaced(); |
---|
2754 | #endif |
---|
2755 | } |
---|
2756 | |
---|
2757 | printf("\nRVM: %.3lf\n" , xCalculateRVM()); |
---|
2758 | } |
---|
2759 | #endif |
---|
2760 | |
---|
2761 | Void TEncGOP::preLoopFilterPicAll( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits ) |
---|
2762 | { |
---|
2763 | TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx()); |
---|
2764 | Bool bCalcDist = false; |
---|
2765 | m_pcLoopFilter->setCfg(m_pcCfg->getLFCrossTileBoundaryFlag()); |
---|
2766 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
2767 | |
---|
2768 | m_pcEntropyCoder->setEntropyCoder ( m_pcEncTop->getRDGoOnSbacCoder(), pcSlice ); |
---|
2769 | m_pcEntropyCoder->resetEntropy (); |
---|
2770 | m_pcEntropyCoder->setBitstream ( m_pcBitCounter ); |
---|
2771 | #if !HM_CLEANUP_SAO |
---|
2772 | pcSlice = pcPic->getSlice(0); |
---|
2773 | if(pcSlice->getSPS()->getUseSAO()) |
---|
2774 | { |
---|
2775 | std::vector<Bool> LFCrossSliceBoundaryFlag(1, true); |
---|
2776 | std::vector<Int> sliceStartAddress; |
---|
2777 | sliceStartAddress.push_back(0); |
---|
2778 | sliceStartAddress.push_back(pcPic->getNumCUsInFrame()* pcPic->getNumPartInCU()); |
---|
2779 | pcPic->createNonDBFilterInfo(sliceStartAddress, 0, &LFCrossSliceBoundaryFlag); |
---|
2780 | } |
---|
2781 | |
---|
2782 | if( pcSlice->getSPS()->getUseSAO()) |
---|
2783 | { |
---|
2784 | pcPic->destroyNonDBFilterInfo(); |
---|
2785 | } |
---|
2786 | #endif |
---|
2787 | m_pcEntropyCoder->resetEntropy (); |
---|
2788 | ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2789 | |
---|
2790 | if (!bCalcDist) |
---|
2791 | ruiDist = xFindDistortionFrame(pcPic->getPicYuvOrg(), pcPic->getPicYuvRec()); |
---|
2792 | } |
---|
2793 | |
---|
2794 | // ==================================================================================================================== |
---|
2795 | // Protected member functions |
---|
2796 | // ==================================================================================================================== |
---|
2797 | |
---|
2798 | |
---|
2799 | Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Bool isField ) |
---|
2800 | { |
---|
2801 | assert( iNumPicRcvd > 0 ); |
---|
2802 | // Exception for the first frames |
---|
2803 | if ( ( isField && (iPOCLast == 0 || iPOCLast == 1) ) || (!isField && (iPOCLast == 0)) ) |
---|
2804 | { |
---|
2805 | m_iGopSize = 1; |
---|
2806 | } |
---|
2807 | else |
---|
2808 | { |
---|
2809 | m_iGopSize = m_pcCfg->getGOPSize(); |
---|
2810 | } |
---|
2811 | assert (m_iGopSize > 0); |
---|
2812 | |
---|
2813 | return; |
---|
2814 | } |
---|
2815 | |
---|
2816 | Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut ) |
---|
2817 | { |
---|
2818 | assert( iNumPicRcvd > 0 ); |
---|
2819 | // Exception for the first frame |
---|
2820 | if ( iPOCLast == 0 ) |
---|
2821 | { |
---|
2822 | m_iGopSize = 1; |
---|
2823 | } |
---|
2824 | else |
---|
2825 | m_iGopSize = m_pcCfg->getGOPSize(); |
---|
2826 | |
---|
2827 | assert (m_iGopSize > 0); |
---|
2828 | |
---|
2829 | return; |
---|
2830 | } |
---|
2831 | |
---|
2832 | Void TEncGOP::xGetBuffer( TComList<TComPic*>& rcListPic, |
---|
2833 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
2834 | Int iNumPicRcvd, |
---|
2835 | Int iTimeOffset, |
---|
2836 | TComPic*& rpcPic, |
---|
2837 | TComPicYuv*& rpcPicYuvRecOut, |
---|
2838 | Int pocCurr, |
---|
2839 | Bool isField) |
---|
2840 | { |
---|
2841 | Int i; |
---|
2842 | // Rec. output |
---|
2843 | TComList<TComPicYuv*>::iterator iterPicYuvRec = rcListPicYuvRecOut.end(); |
---|
2844 | |
---|
2845 | if (isField) |
---|
2846 | { |
---|
2847 | for ( i = 0; i < ( (pocCurr == 0 ) || (pocCurr == 1 ) ? (iNumPicRcvd - iTimeOffset + 1) : (iNumPicRcvd - iTimeOffset + 2) ); i++ ) |
---|
2848 | { |
---|
2849 | iterPicYuvRec--; |
---|
2850 | } |
---|
2851 | } |
---|
2852 | else |
---|
2853 | { |
---|
2854 | for ( i = 0; i < (iNumPicRcvd - iTimeOffset + 1); i++ ) |
---|
2855 | { |
---|
2856 | iterPicYuvRec--; |
---|
2857 | } |
---|
2858 | |
---|
2859 | } |
---|
2860 | |
---|
2861 | if (isField) |
---|
2862 | { |
---|
2863 | if(pocCurr == 1) |
---|
2864 | { |
---|
2865 | iterPicYuvRec++; |
---|
2866 | } |
---|
2867 | } |
---|
2868 | rpcPicYuvRecOut = *(iterPicYuvRec); |
---|
2869 | |
---|
2870 | // Current pic. |
---|
2871 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
2872 | while (iterPic != rcListPic.end()) |
---|
2873 | { |
---|
2874 | rpcPic = *(iterPic); |
---|
2875 | rpcPic->setCurrSliceIdx(0); |
---|
2876 | if (rpcPic->getPOC() == pocCurr) |
---|
2877 | { |
---|
2878 | break; |
---|
2879 | } |
---|
2880 | iterPic++; |
---|
2881 | } |
---|
2882 | |
---|
2883 | assert( rpcPic != NULL ); |
---|
2884 | assert( rpcPic->getPOC() == pocCurr ); |
---|
2885 | |
---|
2886 | return; |
---|
2887 | } |
---|
2888 | |
---|
2889 | UInt64 TEncGOP::xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1) |
---|
2890 | { |
---|
2891 | Int x, y; |
---|
2892 | Pel* pSrc0 = pcPic0 ->getLumaAddr(); |
---|
2893 | Pel* pSrc1 = pcPic1 ->getLumaAddr(); |
---|
2894 | UInt uiShift = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8); |
---|
2895 | Int iTemp; |
---|
2896 | |
---|
2897 | Int iStride = pcPic0->getStride(); |
---|
2898 | Int iWidth = pcPic0->getWidth(); |
---|
2899 | Int iHeight = pcPic0->getHeight(); |
---|
2900 | |
---|
2901 | UInt64 uiTotalDiff = 0; |
---|
2902 | |
---|
2903 | for( y = 0; y < iHeight; y++ ) |
---|
2904 | { |
---|
2905 | for( x = 0; x < iWidth; x++ ) |
---|
2906 | { |
---|
2907 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
2908 | } |
---|
2909 | pSrc0 += iStride; |
---|
2910 | pSrc1 += iStride; |
---|
2911 | } |
---|
2912 | |
---|
2913 | uiShift = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthC-8); |
---|
2914 | iHeight >>= 1; |
---|
2915 | iWidth >>= 1; |
---|
2916 | iStride >>= 1; |
---|
2917 | |
---|
2918 | pSrc0 = pcPic0->getCbAddr(); |
---|
2919 | pSrc1 = pcPic1->getCbAddr(); |
---|
2920 | |
---|
2921 | for( y = 0; y < iHeight; y++ ) |
---|
2922 | { |
---|
2923 | for( x = 0; x < iWidth; x++ ) |
---|
2924 | { |
---|
2925 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
2926 | } |
---|
2927 | pSrc0 += iStride; |
---|
2928 | pSrc1 += iStride; |
---|
2929 | } |
---|
2930 | |
---|
2931 | pSrc0 = pcPic0->getCrAddr(); |
---|
2932 | pSrc1 = pcPic1->getCrAddr(); |
---|
2933 | |
---|
2934 | for( y = 0; y < iHeight; y++ ) |
---|
2935 | { |
---|
2936 | for( x = 0; x < iWidth; x++ ) |
---|
2937 | { |
---|
2938 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
2939 | } |
---|
2940 | pSrc0 += iStride; |
---|
2941 | pSrc1 += iStride; |
---|
2942 | } |
---|
2943 | |
---|
2944 | return uiTotalDiff; |
---|
2945 | } |
---|
2946 | |
---|
2947 | #if VERBOSE_RATE |
---|
2948 | static const Char* nalUnitTypeToString(NalUnitType type) |
---|
2949 | { |
---|
2950 | switch (type) |
---|
2951 | { |
---|
2952 | case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R"; |
---|
2953 | case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N"; |
---|
2954 | case NAL_UNIT_CODED_SLICE_TSA_R: return "TSA_R"; |
---|
2955 | case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N"; |
---|
2956 | case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R"; |
---|
2957 | case NAL_UNIT_CODED_SLICE_STSA_N: return "STSA_N"; |
---|
2958 | case NAL_UNIT_CODED_SLICE_BLA_W_LP: return "BLA_W_LP"; |
---|
2959 | case NAL_UNIT_CODED_SLICE_BLA_W_RADL: return "BLA_W_RADL"; |
---|
2960 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: return "BLA_N_LP"; |
---|
2961 | case NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL"; |
---|
2962 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: return "IDR_N_LP"; |
---|
2963 | case NAL_UNIT_CODED_SLICE_CRA: return "CRA"; |
---|
2964 | case NAL_UNIT_CODED_SLICE_RADL_R: return "RADL_R"; |
---|
2965 | case NAL_UNIT_CODED_SLICE_RASL_R: return "RASL_R"; |
---|
2966 | case NAL_UNIT_VPS: return "VPS"; |
---|
2967 | case NAL_UNIT_SPS: return "SPS"; |
---|
2968 | case NAL_UNIT_PPS: return "PPS"; |
---|
2969 | case NAL_UNIT_ACCESS_UNIT_DELIMITER: return "AUD"; |
---|
2970 | case NAL_UNIT_EOS: return "EOS"; |
---|
2971 | case NAL_UNIT_EOB: return "EOB"; |
---|
2972 | case NAL_UNIT_FILLER_DATA: return "FILLER"; |
---|
2973 | case NAL_UNIT_PREFIX_SEI: return "SEI"; |
---|
2974 | case NAL_UNIT_SUFFIX_SEI: return "SEI"; |
---|
2975 | default: return "UNK"; |
---|
2976 | } |
---|
2977 | } |
---|
2978 | #endif |
---|
2979 | |
---|
2980 | Void TEncGOP::xCalculateAddPSNR( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit& accessUnit, Double dEncTime ) |
---|
2981 | { |
---|
2982 | Int x, y; |
---|
2983 | UInt64 uiSSDY = 0; |
---|
2984 | UInt64 uiSSDU = 0; |
---|
2985 | UInt64 uiSSDV = 0; |
---|
2986 | |
---|
2987 | Double dYPSNR = 0.0; |
---|
2988 | Double dUPSNR = 0.0; |
---|
2989 | Double dVPSNR = 0.0; |
---|
2990 | |
---|
2991 | //===== calculate PSNR ===== |
---|
2992 | Pel* pOrg = pcPic ->getPicYuvOrg()->getLumaAddr(); |
---|
2993 | Pel* pRec = pcPicD->getLumaAddr(); |
---|
2994 | Int iStride = pcPicD->getStride(); |
---|
2995 | |
---|
2996 | Int iWidth; |
---|
2997 | Int iHeight; |
---|
2998 | |
---|
2999 | iWidth = pcPicD->getWidth () - m_pcEncTop->getPad(0); |
---|
3000 | iHeight = pcPicD->getHeight() - m_pcEncTop->getPad(1); |
---|
3001 | |
---|
3002 | Int iSize = iWidth*iHeight; |
---|
3003 | |
---|
3004 | for( y = 0; y < iHeight; y++ ) |
---|
3005 | { |
---|
3006 | for( x = 0; x < iWidth; x++ ) |
---|
3007 | { |
---|
3008 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
3009 | uiSSDY += iDiff * iDiff; |
---|
3010 | } |
---|
3011 | pOrg += iStride; |
---|
3012 | pRec += iStride; |
---|
3013 | } |
---|
3014 | |
---|
3015 | iHeight >>= 1; |
---|
3016 | iWidth >>= 1; |
---|
3017 | iStride >>= 1; |
---|
3018 | pOrg = pcPic ->getPicYuvOrg()->getCbAddr(); |
---|
3019 | pRec = pcPicD->getCbAddr(); |
---|
3020 | |
---|
3021 | for( y = 0; y < iHeight; y++ ) |
---|
3022 | { |
---|
3023 | for( x = 0; x < iWidth; x++ ) |
---|
3024 | { |
---|
3025 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
3026 | uiSSDU += iDiff * iDiff; |
---|
3027 | } |
---|
3028 | pOrg += iStride; |
---|
3029 | pRec += iStride; |
---|
3030 | } |
---|
3031 | |
---|
3032 | pOrg = pcPic ->getPicYuvOrg()->getCrAddr(); |
---|
3033 | pRec = pcPicD->getCrAddr(); |
---|
3034 | |
---|
3035 | for( y = 0; y < iHeight; y++ ) |
---|
3036 | { |
---|
3037 | for( x = 0; x < iWidth; x++ ) |
---|
3038 | { |
---|
3039 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
3040 | uiSSDV += iDiff * iDiff; |
---|
3041 | } |
---|
3042 | pOrg += iStride; |
---|
3043 | pRec += iStride; |
---|
3044 | } |
---|
3045 | |
---|
3046 | Int maxvalY = 255 << (g_bitDepthY-8); |
---|
3047 | Int maxvalC = 255 << (g_bitDepthC-8); |
---|
3048 | Double fRefValueY = (Double) maxvalY * maxvalY * iSize; |
---|
3049 | Double fRefValueC = (Double) maxvalC * maxvalC * iSize / 4.0; |
---|
3050 | dYPSNR = ( uiSSDY ? 10.0 * log10( fRefValueY / (Double)uiSSDY ) : 99.99 ); |
---|
3051 | dUPSNR = ( uiSSDU ? 10.0 * log10( fRefValueC / (Double)uiSSDU ) : 99.99 ); |
---|
3052 | dVPSNR = ( uiSSDV ? 10.0 * log10( fRefValueC / (Double)uiSSDV ) : 99.99 ); |
---|
3053 | |
---|
3054 | /* calculate the size of the access unit, excluding: |
---|
3055 | * - any AnnexB contributions (start_code_prefix, zero_byte, etc.,) |
---|
3056 | * - SEI NAL units |
---|
3057 | */ |
---|
3058 | UInt numRBSPBytes = 0; |
---|
3059 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
3060 | { |
---|
3061 | UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size()); |
---|
3062 | #if VERBOSE_RATE |
---|
3063 | printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString((*it)->m_nalUnitType), numRBSPBytes_nal); |
---|
3064 | #endif |
---|
3065 | if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) |
---|
3066 | { |
---|
3067 | numRBSPBytes += numRBSPBytes_nal; |
---|
3068 | } |
---|
3069 | } |
---|
3070 | |
---|
3071 | UInt uibits = numRBSPBytes * 8; |
---|
3072 | m_vRVM_RP.push_back( uibits ); |
---|
3073 | |
---|
3074 | //===== add PSNR ===== |
---|
3075 | #if SVC_EXTENSION |
---|
3076 | m_gcAnalyzeAll[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
3077 | TComSlice* pcSlice = pcPic->getSlice(0); |
---|
3078 | if (pcSlice->isIntra()) |
---|
3079 | { |
---|
3080 | m_gcAnalyzeI[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
3081 | } |
---|
3082 | if (pcSlice->isInterP()) |
---|
3083 | { |
---|
3084 | m_gcAnalyzeP[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
3085 | } |
---|
3086 | if (pcSlice->isInterB()) |
---|
3087 | { |
---|
3088 | m_gcAnalyzeB[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
3089 | } |
---|
3090 | #else |
---|
3091 | m_gcAnalyzeAll.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
3092 | TComSlice* pcSlice = pcPic->getSlice(0); |
---|
3093 | if (pcSlice->isIntra()) |
---|
3094 | { |
---|
3095 | m_gcAnalyzeI.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
3096 | } |
---|
3097 | if (pcSlice->isInterP()) |
---|
3098 | { |
---|
3099 | m_gcAnalyzeP.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
3100 | } |
---|
3101 | if (pcSlice->isInterB()) |
---|
3102 | { |
---|
3103 | m_gcAnalyzeB.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
3104 | } |
---|
3105 | #endif |
---|
3106 | |
---|
3107 | Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B'); |
---|
3108 | if (!pcSlice->isReferenced()) c += 32; |
---|
3109 | |
---|
3110 | #if SVC_EXTENSION |
---|
3111 | #if ADAPTIVE_QP_SELECTION |
---|
3112 | printf("POC %4d LId: %1d TId: %1d ( %c-SLICE %s, nQP %d QP %d ) %10d bits", |
---|
3113 | pcSlice->getPOC(), |
---|
3114 | pcSlice->getLayerId(), |
---|
3115 | pcSlice->getTLayer(), |
---|
3116 | c, |
---|
3117 | NaluToStr( pcSlice->getNalUnitType() ).data(), |
---|
3118 | pcSlice->getSliceQpBase(), |
---|
3119 | pcSlice->getSliceQp(), |
---|
3120 | uibits ); |
---|
3121 | #else |
---|
3122 | printf("POC %4d LId: %1d TId: %1d ( %c-SLICE %s, QP %d ) %10d bits", |
---|
3123 | pcSlice->getPOC()-pcSlice->getLastIDR(), |
---|
3124 | pcSlice->getLayerId(), |
---|
3125 | pcSlice->getTLayer(), |
---|
3126 | c, |
---|
3127 | NaluToStr( pcSlice->getNalUnitType() ).data(). |
---|
3128 | pcSlice->getSliceQp(), |
---|
3129 | uibits ); |
---|
3130 | #endif |
---|
3131 | #else |
---|
3132 | #if ADAPTIVE_QP_SELECTION |
---|
3133 | printf("POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits", |
---|
3134 | pcSlice->getPOC(), |
---|
3135 | pcSlice->getTLayer(), |
---|
3136 | c, |
---|
3137 | pcSlice->getSliceQpBase(), |
---|
3138 | pcSlice->getSliceQp(), |
---|
3139 | uibits ); |
---|
3140 | #else |
---|
3141 | printf("POC %4d TId: %1d ( %c-SLICE, QP %d ) %10d bits", |
---|
3142 | pcSlice->getPOC()-pcSlice->getLastIDR(), |
---|
3143 | pcSlice->getTLayer(), |
---|
3144 | c, |
---|
3145 | pcSlice->getSliceQp(), |
---|
3146 | uibits ); |
---|
3147 | #endif |
---|
3148 | #endif |
---|
3149 | |
---|
3150 | printf(" [Y %6.4lf dB U %6.4lf dB V %6.4lf dB]", dYPSNR, dUPSNR, dVPSNR ); |
---|
3151 | printf(" [ET %5.0f ]", dEncTime ); |
---|
3152 | |
---|
3153 | for (Int iRefList = 0; iRefList < 2; iRefList++) |
---|
3154 | { |
---|
3155 | printf(" [L%d ", iRefList); |
---|
3156 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++) |
---|
3157 | { |
---|
3158 | #if SVC_EXTENSION |
---|
3159 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
3160 | if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR(m_layerId) ) |
---|
3161 | { |
---|
3162 | printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR(), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() ); |
---|
3163 | } |
---|
3164 | else |
---|
3165 | { |
---|
3166 | printf ("%d", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR()); |
---|
3167 | } |
---|
3168 | #endif |
---|
3169 | if( pcSlice->getEnableTMVPFlag() && iRefList == 1 - pcSlice->getColFromL0Flag() && iRefIndex == pcSlice->getColRefIdx() ) |
---|
3170 | { |
---|
3171 | printf( "c" ); |
---|
3172 | } |
---|
3173 | |
---|
3174 | printf( " " ); |
---|
3175 | #else |
---|
3176 | printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR()); |
---|
3177 | #endif |
---|
3178 | } |
---|
3179 | printf("]"); |
---|
3180 | } |
---|
3181 | } |
---|
3182 | |
---|
3183 | |
---|
3184 | Void reinterlace(Pel* top, Pel* bottom, Pel* dst, UInt stride, UInt width, UInt height, Bool isTff) |
---|
3185 | { |
---|
3186 | |
---|
3187 | for (Int y = 0; y < height; y++) |
---|
3188 | { |
---|
3189 | for (Int x = 0; x < width; x++) |
---|
3190 | { |
---|
3191 | dst[x] = isTff ? top[x] : bottom[x]; |
---|
3192 | dst[stride+x] = isTff ? bottom[x] : top[x]; |
---|
3193 | } |
---|
3194 | top += stride; |
---|
3195 | bottom += stride; |
---|
3196 | dst += stride*2; |
---|
3197 | } |
---|
3198 | } |
---|
3199 | |
---|
3200 | Void TEncGOP::xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime ) |
---|
3201 | { |
---|
3202 | Int x, y; |
---|
3203 | |
---|
3204 | UInt64 uiSSDY_in = 0; |
---|
3205 | UInt64 uiSSDU_in = 0; |
---|
3206 | UInt64 uiSSDV_in = 0; |
---|
3207 | |
---|
3208 | Double dYPSNR_in = 0.0; |
---|
3209 | Double dUPSNR_in = 0.0; |
---|
3210 | Double dVPSNR_in = 0.0; |
---|
3211 | |
---|
3212 | /*------ INTERLACED PSNR -----------*/ |
---|
3213 | |
---|
3214 | /* Luma */ |
---|
3215 | |
---|
3216 | Pel* pOrgTop = pcPicOrgTop->getPicYuvOrg()->getLumaAddr(); |
---|
3217 | Pel* pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getLumaAddr(); |
---|
3218 | Pel* pRecTop = pcPicRecTop->getLumaAddr(); |
---|
3219 | Pel* pRecBottom = pcPicRecBottom->getLumaAddr(); |
---|
3220 | |
---|
3221 | Int iWidth; |
---|
3222 | Int iHeight; |
---|
3223 | Int iStride; |
---|
3224 | |
---|
3225 | iWidth = pcPicOrgTop->getPicYuvOrg()->getWidth () - m_pcEncTop->getPad(0); |
---|
3226 | iHeight = pcPicOrgTop->getPicYuvOrg()->getHeight() - m_pcEncTop->getPad(1); |
---|
3227 | iStride = pcPicOrgTop->getPicYuvOrg()->getStride(); |
---|
3228 | Int iSize = iWidth*iHeight; |
---|
3229 | bool isTff = pcPicOrgTop->isTopField(); |
---|
3230 | |
---|
3231 | TComPicYuv* pcOrgInterlaced = new TComPicYuv; |
---|
3232 | #if AUXILIARY_PICTURES |
---|
3233 | pcOrgInterlaced->create( iWidth, iHeight << 1, pcPicOrgTop->getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
3234 | #else |
---|
3235 | pcOrgInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
3236 | #endif |
---|
3237 | |
---|
3238 | TComPicYuv* pcRecInterlaced = new TComPicYuv; |
---|
3239 | #if AUXILIARY_PICTURES |
---|
3240 | pcRecInterlaced->create( iWidth, iHeight << 1, pcPicOrgTop->getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
3241 | #else |
---|
3242 | pcRecInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
3243 | #endif |
---|
3244 | |
---|
3245 | Pel* pOrgInterlaced = pcOrgInterlaced->getLumaAddr(); |
---|
3246 | Pel* pRecInterlaced = pcRecInterlaced->getLumaAddr(); |
---|
3247 | |
---|
3248 | //=== Interlace fields ==== |
---|
3249 | reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff); |
---|
3250 | reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff); |
---|
3251 | |
---|
3252 | //===== calculate PSNR ===== |
---|
3253 | for( y = 0; y < iHeight << 1; y++ ) |
---|
3254 | { |
---|
3255 | for( x = 0; x < iWidth; x++ ) |
---|
3256 | { |
---|
3257 | Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] ); |
---|
3258 | uiSSDY_in += iDiff * iDiff; |
---|
3259 | } |
---|
3260 | pOrgInterlaced += iStride; |
---|
3261 | pRecInterlaced += iStride; |
---|
3262 | } |
---|
3263 | |
---|
3264 | /*Chroma*/ |
---|
3265 | |
---|
3266 | iHeight >>= 1; |
---|
3267 | iWidth >>= 1; |
---|
3268 | iStride >>= 1; |
---|
3269 | |
---|
3270 | pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCbAddr(); |
---|
3271 | pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCbAddr(); |
---|
3272 | pRecTop = pcPicRecTop->getCbAddr(); |
---|
3273 | pRecBottom = pcPicRecBottom->getCbAddr(); |
---|
3274 | pOrgInterlaced = pcOrgInterlaced->getCbAddr(); |
---|
3275 | pRecInterlaced = pcRecInterlaced->getCbAddr(); |
---|
3276 | |
---|
3277 | //=== Interlace fields ==== |
---|
3278 | reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff); |
---|
3279 | reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff); |
---|
3280 | |
---|
3281 | //===== calculate PSNR ===== |
---|
3282 | for( y = 0; y < iHeight << 1; y++ ) |
---|
3283 | { |
---|
3284 | for( x = 0; x < iWidth; x++ ) |
---|
3285 | { |
---|
3286 | Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] ); |
---|
3287 | uiSSDU_in += iDiff * iDiff; |
---|
3288 | } |
---|
3289 | pOrgInterlaced += iStride; |
---|
3290 | pRecInterlaced += iStride; |
---|
3291 | } |
---|
3292 | |
---|
3293 | pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCrAddr(); |
---|
3294 | pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCrAddr(); |
---|
3295 | pRecTop = pcPicRecTop->getCrAddr(); |
---|
3296 | pRecBottom = pcPicRecBottom->getCrAddr(); |
---|
3297 | pOrgInterlaced = pcOrgInterlaced->getCrAddr(); |
---|
3298 | pRecInterlaced = pcRecInterlaced->getCrAddr(); |
---|
3299 | |
---|
3300 | //=== Interlace fields ==== |
---|
3301 | reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff); |
---|
3302 | reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff); |
---|
3303 | |
---|
3304 | //===== calculate PSNR ===== |
---|
3305 | for( y = 0; y < iHeight << 1; y++ ) |
---|
3306 | { |
---|
3307 | for( x = 0; x < iWidth; x++ ) |
---|
3308 | { |
---|
3309 | Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] ); |
---|
3310 | uiSSDV_in += iDiff * iDiff; |
---|
3311 | } |
---|
3312 | pOrgInterlaced += iStride; |
---|
3313 | pRecInterlaced += iStride; |
---|
3314 | } |
---|
3315 | |
---|
3316 | Int maxvalY = 255 << (g_bitDepthY-8); |
---|
3317 | Int maxvalC = 255 << (g_bitDepthC-8); |
---|
3318 | Double fRefValueY = (Double) maxvalY * maxvalY * iSize*2; |
---|
3319 | Double fRefValueC = (Double) maxvalC * maxvalC * iSize*2 / 4.0; |
---|
3320 | dYPSNR_in = ( uiSSDY_in ? 10.0 * log10( fRefValueY / (Double)uiSSDY_in ) : 99.99 ); |
---|
3321 | dUPSNR_in = ( uiSSDU_in ? 10.0 * log10( fRefValueC / (Double)uiSSDU_in ) : 99.99 ); |
---|
3322 | dVPSNR_in = ( uiSSDV_in ? 10.0 * log10( fRefValueC / (Double)uiSSDV_in ) : 99.99 ); |
---|
3323 | |
---|
3324 | /* calculate the size of the access unit, excluding: |
---|
3325 | * - any AnnexB contributions (start_code_prefix, zero_byte, etc.,) |
---|
3326 | * - SEI NAL units |
---|
3327 | */ |
---|
3328 | UInt numRBSPBytes = 0; |
---|
3329 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
3330 | { |
---|
3331 | UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size()); |
---|
3332 | |
---|
3333 | if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) |
---|
3334 | numRBSPBytes += numRBSPBytes_nal; |
---|
3335 | } |
---|
3336 | |
---|
3337 | UInt uibits = numRBSPBytes * 8 ; |
---|
3338 | |
---|
3339 | //===== add PSNR ===== |
---|
3340 | m_gcAnalyzeAll_in.addResult (dYPSNR_in, dUPSNR_in, dVPSNR_in, (Double)uibits); |
---|
3341 | |
---|
3342 | printf("\n Interlaced frame %d: [Y %6.4lf dB U %6.4lf dB V %6.4lf dB]", pcPicOrgBottom->getPOC()/2 , dYPSNR_in, dUPSNR_in, dVPSNR_in ); |
---|
3343 | |
---|
3344 | pcOrgInterlaced->destroy(); |
---|
3345 | delete pcOrgInterlaced; |
---|
3346 | pcRecInterlaced->destroy(); |
---|
3347 | delete pcRecInterlaced; |
---|
3348 | } |
---|
3349 | |
---|
3350 | |
---|
3351 | |
---|
3352 | /** Function for deciding the nal_unit_type. |
---|
3353 | * \param pocCurr POC of the current picture |
---|
3354 | * \returns the nal unit type of the picture |
---|
3355 | * This function checks the configuration and returns the appropriate nal_unit_type for the picture. |
---|
3356 | */ |
---|
3357 | NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR) |
---|
3358 | { |
---|
3359 | if (pocCurr == 0) |
---|
3360 | { |
---|
3361 | return NAL_UNIT_CODED_SLICE_IDR_W_RADL; |
---|
3362 | } |
---|
3363 | if (pocCurr % m_pcCfg->getIntraPeriod() == 0) |
---|
3364 | { |
---|
3365 | if (m_pcCfg->getDecodingRefreshType() == 1) |
---|
3366 | { |
---|
3367 | return NAL_UNIT_CODED_SLICE_CRA; |
---|
3368 | } |
---|
3369 | else if (m_pcCfg->getDecodingRefreshType() == 2) |
---|
3370 | { |
---|
3371 | return NAL_UNIT_CODED_SLICE_IDR_W_RADL; |
---|
3372 | } |
---|
3373 | } |
---|
3374 | if(m_pocCRA>0) |
---|
3375 | { |
---|
3376 | if(pocCurr<m_pocCRA) |
---|
3377 | { |
---|
3378 | // All leading pictures are being marked as TFD pictures here since current encoder uses all |
---|
3379 | // reference pictures while encoding leading pictures. An encoder can ensure that a leading |
---|
3380 | // picture can be still decodable when random accessing to a CRA/CRANT/BLA/BLANT picture by |
---|
3381 | // controlling the reference pictures used for encoding that leading picture. Such a leading |
---|
3382 | // picture need not be marked as a TFD picture. |
---|
3383 | return NAL_UNIT_CODED_SLICE_RASL_R; |
---|
3384 | } |
---|
3385 | } |
---|
3386 | if (lastIDR>0) |
---|
3387 | { |
---|
3388 | if (pocCurr < lastIDR) |
---|
3389 | { |
---|
3390 | return NAL_UNIT_CODED_SLICE_RADL_R; |
---|
3391 | } |
---|
3392 | } |
---|
3393 | return NAL_UNIT_CODED_SLICE_TRAIL_R; |
---|
3394 | } |
---|
3395 | |
---|
3396 | Double TEncGOP::xCalculateRVM() |
---|
3397 | { |
---|
3398 | Double dRVM = 0; |
---|
3399 | |
---|
3400 | if( m_pcCfg->getGOPSize() == 1 && m_pcCfg->getIntraPeriod() != 1 && m_pcCfg->getFramesToBeEncoded() > RVM_VCEGAM10_M * 2 ) |
---|
3401 | { |
---|
3402 | // calculate RVM only for lowdelay configurations |
---|
3403 | std::vector<Double> vRL , vB; |
---|
3404 | size_t N = m_vRVM_RP.size(); |
---|
3405 | vRL.resize( N ); |
---|
3406 | vB.resize( N ); |
---|
3407 | |
---|
3408 | Int i; |
---|
3409 | Double dRavg = 0 , dBavg = 0; |
---|
3410 | vB[RVM_VCEGAM10_M] = 0; |
---|
3411 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
3412 | { |
---|
3413 | vRL[i] = 0; |
---|
3414 | for( Int j = i - RVM_VCEGAM10_M ; j <= i + RVM_VCEGAM10_M - 1 ; j++ ) |
---|
3415 | vRL[i] += m_vRVM_RP[j]; |
---|
3416 | vRL[i] /= ( 2 * RVM_VCEGAM10_M ); |
---|
3417 | vB[i] = vB[i-1] + m_vRVM_RP[i] - vRL[i]; |
---|
3418 | dRavg += m_vRVM_RP[i]; |
---|
3419 | dBavg += vB[i]; |
---|
3420 | } |
---|
3421 | |
---|
3422 | dRavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
3423 | dBavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
3424 | |
---|
3425 | Double dSigamB = 0; |
---|
3426 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
3427 | { |
---|
3428 | Double tmp = vB[i] - dBavg; |
---|
3429 | dSigamB += tmp * tmp; |
---|
3430 | } |
---|
3431 | dSigamB = sqrt( dSigamB / ( N - 2 * RVM_VCEGAM10_M ) ); |
---|
3432 | |
---|
3433 | Double f = sqrt( 12.0 * ( RVM_VCEGAM10_M - 1 ) / ( RVM_VCEGAM10_M + 1 ) ); |
---|
3434 | |
---|
3435 | dRVM = dSigamB / dRavg * f; |
---|
3436 | } |
---|
3437 | |
---|
3438 | return( dRVM ); |
---|
3439 | } |
---|
3440 | |
---|
3441 | /** Attaches the input bitstream to the stream in the output NAL unit |
---|
3442 | Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call. |
---|
3443 | * \param codedSliceData contains the coded slice data (bitstream) to be concatenated to rNalu |
---|
3444 | * \param rNalu target NAL unit |
---|
3445 | */ |
---|
3446 | Void TEncGOP::xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& codedSliceData) |
---|
3447 | { |
---|
3448 | // Byte-align |
---|
3449 | rNalu.m_Bitstream.writeByteAlignment(); // Slice header byte-alignment |
---|
3450 | |
---|
3451 | // Perform bitstream concatenation |
---|
3452 | if (codedSliceData->getNumberOfWrittenBits() > 0) |
---|
3453 | { |
---|
3454 | rNalu.m_Bitstream.addSubstream(codedSliceData); |
---|
3455 | } |
---|
3456 | |
---|
3457 | m_pcEntropyCoder->setBitstream(&rNalu.m_Bitstream); |
---|
3458 | |
---|
3459 | codedSliceData->clear(); |
---|
3460 | } |
---|
3461 | |
---|
3462 | // Function will arrange the long-term pictures in the decreasing order of poc_lsb_lt, |
---|
3463 | // and among the pictures with the same lsb, it arranges them in increasing delta_poc_msb_cycle_lt value |
---|
3464 | Void TEncGOP::arrangeLongtermPicturesInRPS(TComSlice *pcSlice, TComList<TComPic*>& rcListPic) |
---|
3465 | { |
---|
3466 | TComReferencePictureSet *rps = pcSlice->getRPS(); |
---|
3467 | if(!rps->getNumberOfLongtermPictures()) |
---|
3468 | { |
---|
3469 | return; |
---|
3470 | } |
---|
3471 | |
---|
3472 | // Arrange long-term reference pictures in the correct order of LSB and MSB, |
---|
3473 | // and assign values for pocLSBLT and MSB present flag |
---|
3474 | Int longtermPicsPoc[MAX_NUM_REF_PICS], longtermPicsLSB[MAX_NUM_REF_PICS], indices[MAX_NUM_REF_PICS]; |
---|
3475 | Int longtermPicsMSB[MAX_NUM_REF_PICS]; |
---|
3476 | Bool mSBPresentFlag[MAX_NUM_REF_PICS]; |
---|
3477 | ::memset(longtermPicsPoc, 0, sizeof(longtermPicsPoc)); // Store POC values of LTRP |
---|
3478 | ::memset(longtermPicsLSB, 0, sizeof(longtermPicsLSB)); // Store POC LSB values of LTRP |
---|
3479 | ::memset(longtermPicsMSB, 0, sizeof(longtermPicsMSB)); // Store POC LSB values of LTRP |
---|
3480 | ::memset(indices , 0, sizeof(indices)); // Indices to aid in tracking sorted LTRPs |
---|
3481 | ::memset(mSBPresentFlag , 0, sizeof(mSBPresentFlag)); // Indicate if MSB needs to be present |
---|
3482 | |
---|
3483 | // Get the long-term reference pictures |
---|
3484 | Int offset = rps->getNumberOfNegativePictures() + rps->getNumberOfPositivePictures(); |
---|
3485 | Int i, ctr = 0; |
---|
3486 | Int maxPicOrderCntLSB = 1 << pcSlice->getSPS()->getBitsForPOC(); |
---|
3487 | for(i = rps->getNumberOfPictures() - 1; i >= offset; i--, ctr++) |
---|
3488 | { |
---|
3489 | longtermPicsPoc[ctr] = rps->getPOC(i); // LTRP POC |
---|
3490 | longtermPicsLSB[ctr] = getLSB(longtermPicsPoc[ctr], maxPicOrderCntLSB); // LTRP POC LSB |
---|
3491 | indices[ctr] = i; |
---|
3492 | longtermPicsMSB[ctr] = longtermPicsPoc[ctr] - longtermPicsLSB[ctr]; |
---|
3493 | } |
---|
3494 | Int numLongPics = rps->getNumberOfLongtermPictures(); |
---|
3495 | assert(ctr == numLongPics); |
---|
3496 | |
---|
3497 | // Arrange pictures in decreasing order of MSB; |
---|
3498 | for(i = 0; i < numLongPics; i++) |
---|
3499 | { |
---|
3500 | for(Int j = 0; j < numLongPics - 1; j++) |
---|
3501 | { |
---|
3502 | if(longtermPicsMSB[j] < longtermPicsMSB[j+1]) |
---|
3503 | { |
---|
3504 | std::swap(longtermPicsPoc[j], longtermPicsPoc[j+1]); |
---|
3505 | std::swap(longtermPicsLSB[j], longtermPicsLSB[j+1]); |
---|
3506 | std::swap(longtermPicsMSB[j], longtermPicsMSB[j+1]); |
---|
3507 | std::swap(indices[j] , indices[j+1] ); |
---|
3508 | } |
---|
3509 | } |
---|
3510 | } |
---|
3511 | |
---|
3512 | for(i = 0; i < numLongPics; i++) |
---|
3513 | { |
---|
3514 | // Check if MSB present flag should be enabled. |
---|
3515 | // Check if the buffer contains any pictures that have the same LSB. |
---|
3516 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
3517 | TComPic* pcPic; |
---|
3518 | while ( iterPic != rcListPic.end() ) |
---|
3519 | { |
---|
3520 | pcPic = *iterPic; |
---|
3521 | if( (getLSB(pcPic->getPOC(), maxPicOrderCntLSB) == longtermPicsLSB[i]) && // Same LSB |
---|
3522 | (pcPic->getSlice(0)->isReferenced()) && // Reference picture |
---|
3523 | (pcPic->getPOC() != longtermPicsPoc[i]) ) // Not the LTRP itself |
---|
3524 | { |
---|
3525 | mSBPresentFlag[i] = true; |
---|
3526 | break; |
---|
3527 | } |
---|
3528 | iterPic++; |
---|
3529 | } |
---|
3530 | } |
---|
3531 | |
---|
3532 | // tempArray for usedByCurr flag |
---|
3533 | Bool tempArray[MAX_NUM_REF_PICS]; ::memset(tempArray, 0, sizeof(tempArray)); |
---|
3534 | for(i = 0; i < numLongPics; i++) |
---|
3535 | { |
---|
3536 | tempArray[i] = rps->getUsed(indices[i]); |
---|
3537 | } |
---|
3538 | // Now write the final values; |
---|
3539 | ctr = 0; |
---|
3540 | Int currMSB = 0, currLSB = 0; |
---|
3541 | // currPicPoc = currMSB + currLSB |
---|
3542 | currLSB = getLSB(pcSlice->getPOC(), maxPicOrderCntLSB); |
---|
3543 | currMSB = pcSlice->getPOC() - currLSB; |
---|
3544 | |
---|
3545 | for(i = rps->getNumberOfPictures() - 1; i >= offset; i--, ctr++) |
---|
3546 | { |
---|
3547 | rps->setPOC (i, longtermPicsPoc[ctr]); |
---|
3548 | rps->setDeltaPOC (i, - pcSlice->getPOC() + longtermPicsPoc[ctr]); |
---|
3549 | rps->setUsed (i, tempArray[ctr]); |
---|
3550 | rps->setPocLSBLT (i, longtermPicsLSB[ctr]); |
---|
3551 | rps->setDeltaPocMSBCycleLT (i, (currMSB - (longtermPicsPoc[ctr] - longtermPicsLSB[ctr])) / maxPicOrderCntLSB); |
---|
3552 | rps->setDeltaPocMSBPresentFlag(i, mSBPresentFlag[ctr]); |
---|
3553 | |
---|
3554 | assert(rps->getDeltaPocMSBCycleLT(i) >= 0); // Non-negative value |
---|
3555 | } |
---|
3556 | for(i = rps->getNumberOfPictures() - 1, ctr = 1; i >= offset; i--, ctr++) |
---|
3557 | { |
---|
3558 | for(Int j = rps->getNumberOfPictures() - 1 - ctr; j >= offset; j--) |
---|
3559 | { |
---|
3560 | // Here at the encoder we know that we have set the full POC value for the LTRPs, hence we |
---|
3561 | // don't have to check the MSB present flag values for this constraint. |
---|
3562 | assert( rps->getPOC(i) != rps->getPOC(j) ); // If assert fails, LTRP entry repeated in RPS!!! |
---|
3563 | } |
---|
3564 | } |
---|
3565 | } |
---|
3566 | |
---|
3567 | /** Function for finding the position to insert the first of APS and non-nested BP, PT, DU info SEI messages. |
---|
3568 | * \param accessUnit Access Unit of the current picture |
---|
3569 | * This function finds the position to insert the first of APS and non-nested BP, PT, DU info SEI messages. |
---|
3570 | */ |
---|
3571 | Int TEncGOP::xGetFirstSeiLocation(AccessUnit &accessUnit) |
---|
3572 | { |
---|
3573 | // Find the location of the first SEI message |
---|
3574 | AccessUnit::iterator it; |
---|
3575 | Int seiStartPos = 0; |
---|
3576 | for(it = accessUnit.begin(); it != accessUnit.end(); it++, seiStartPos++) |
---|
3577 | { |
---|
3578 | if ((*it)->isSei() || (*it)->isVcl()) |
---|
3579 | { |
---|
3580 | break; |
---|
3581 | } |
---|
3582 | } |
---|
3583 | // assert(it != accessUnit.end()); // Triggers with some legit configurations |
---|
3584 | return seiStartPos; |
---|
3585 | } |
---|
3586 | |
---|
3587 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
3588 | Void TEncGOP::xBuildTileSetsMap(TComPicSym* picSym) |
---|
3589 | { |
---|
3590 | Int numCUs = picSym->getFrameWidthInCU() * picSym->getFrameHeightInCU(); |
---|
3591 | |
---|
3592 | for (Int i = 0; i < numCUs; i++) |
---|
3593 | { |
---|
3594 | picSym->setTileSetIdxMap(i, -1, 0, false); |
---|
3595 | } |
---|
3596 | |
---|
3597 | for (Int i = 0; i < m_pcCfg->getIlNumSetsInMessage(); i++) |
---|
3598 | { |
---|
3599 | TComTile* topLeftTile = picSym->getTComTile(m_pcCfg->getTopLeftTileIndex(i)); |
---|
3600 | TComTile* bottomRightTile = picSym->getTComTile(m_pcCfg->getBottomRightTileIndex(i)); |
---|
3601 | Int tileSetLeftEdgePosInCU = topLeftTile->getRightEdgePosInCU() - topLeftTile->getTileWidth() + 1; |
---|
3602 | Int tileSetRightEdgePosInCU = bottomRightTile->getRightEdgePosInCU(); |
---|
3603 | Int tileSetTopEdgePosInCU = topLeftTile->getBottomEdgePosInCU() - topLeftTile->getTileHeight() + 1; |
---|
3604 | Int tileSetBottomEdgePosInCU = bottomRightTile->getBottomEdgePosInCU(); |
---|
3605 | assert(tileSetLeftEdgePosInCU < tileSetRightEdgePosInCU && tileSetTopEdgePosInCU < tileSetBottomEdgePosInCU); |
---|
3606 | for (Int j = tileSetTopEdgePosInCU; j <= tileSetBottomEdgePosInCU; j++) |
---|
3607 | { |
---|
3608 | for (Int k = tileSetLeftEdgePosInCU; k <= tileSetRightEdgePosInCU; k++) |
---|
3609 | { |
---|
3610 | picSym->setTileSetIdxMap(j * picSym->getFrameWidthInCU() + k, i, m_pcCfg->getIlcIdc(i), false); |
---|
3611 | } |
---|
3612 | } |
---|
3613 | } |
---|
3614 | |
---|
3615 | if (m_pcCfg->getSkippedTileSetPresentFlag()) |
---|
3616 | { |
---|
3617 | Int skippedTileSetIdx = m_pcCfg->getIlNumSetsInMessage(); |
---|
3618 | for (Int i = 0; i < numCUs; i++) |
---|
3619 | { |
---|
3620 | if (picSym->getTileSetIdxMap(i) < 0) |
---|
3621 | { |
---|
3622 | picSym->setTileSetIdxMap(i, skippedTileSetIdx, 0, true); |
---|
3623 | } |
---|
3624 | } |
---|
3625 | } |
---|
3626 | } |
---|
3627 | #endif |
---|
3628 | |
---|
3629 | Void TEncGOP::dblMetric( TComPic* pcPic, UInt uiNumSlices ) |
---|
3630 | { |
---|
3631 | TComPicYuv* pcPicYuvRec = pcPic->getPicYuvRec(); |
---|
3632 | Pel* Rec = pcPicYuvRec->getLumaAddr( 0 ); |
---|
3633 | Pel* tempRec = Rec; |
---|
3634 | Int stride = pcPicYuvRec->getStride(); |
---|
3635 | UInt log2maxTB = pcPic->getSlice(0)->getSPS()->getQuadtreeTULog2MaxSize(); |
---|
3636 | UInt maxTBsize = (1<<log2maxTB); |
---|
3637 | const UInt minBlockArtSize = 8; |
---|
3638 | const UInt picWidth = pcPicYuvRec->getWidth(); |
---|
3639 | const UInt picHeight = pcPicYuvRec->getHeight(); |
---|
3640 | const UInt noCol = (picWidth>>log2maxTB); |
---|
3641 | const UInt noRows = (picHeight>>log2maxTB); |
---|
3642 | assert(noCol > 1); |
---|
3643 | assert(noRows > 1); |
---|
3644 | UInt64 *colSAD = (UInt64*)malloc(noCol*sizeof(UInt64)); |
---|
3645 | UInt64 *rowSAD = (UInt64*)malloc(noRows*sizeof(UInt64)); |
---|
3646 | UInt colIdx = 0; |
---|
3647 | UInt rowIdx = 0; |
---|
3648 | Pel p0, p1, p2, q0, q1, q2; |
---|
3649 | |
---|
3650 | Int qp = pcPic->getSlice(0)->getSliceQp(); |
---|
3651 | Int bitdepthScale = 1 << (g_bitDepthY-8); |
---|
3652 | Int beta = TComLoopFilter::getBeta( qp ) * bitdepthScale; |
---|
3653 | const Int thr2 = (beta>>2); |
---|
3654 | const Int thr1 = 2*bitdepthScale; |
---|
3655 | UInt a = 0; |
---|
3656 | |
---|
3657 | memset(colSAD, 0, noCol*sizeof(UInt64)); |
---|
3658 | memset(rowSAD, 0, noRows*sizeof(UInt64)); |
---|
3659 | |
---|
3660 | if (maxTBsize > minBlockArtSize) |
---|
3661 | { |
---|
3662 | // Analyze vertical artifact edges |
---|
3663 | for(Int c = maxTBsize; c < picWidth; c += maxTBsize) |
---|
3664 | { |
---|
3665 | for(Int r = 0; r < picHeight; r++) |
---|
3666 | { |
---|
3667 | p2 = Rec[c-3]; |
---|
3668 | p1 = Rec[c-2]; |
---|
3669 | p0 = Rec[c-1]; |
---|
3670 | q0 = Rec[c]; |
---|
3671 | q1 = Rec[c+1]; |
---|
3672 | q2 = Rec[c+2]; |
---|
3673 | a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1); |
---|
3674 | if ( thr1 < a && a < thr2) |
---|
3675 | { |
---|
3676 | colSAD[colIdx] += abs(p0 - q0); |
---|
3677 | } |
---|
3678 | Rec += stride; |
---|
3679 | } |
---|
3680 | colIdx++; |
---|
3681 | Rec = tempRec; |
---|
3682 | } |
---|
3683 | |
---|
3684 | // Analyze horizontal artifact edges |
---|
3685 | for(Int r = maxTBsize; r < picHeight; r += maxTBsize) |
---|
3686 | { |
---|
3687 | for(Int c = 0; c < picWidth; c++) |
---|
3688 | { |
---|
3689 | p2 = Rec[c + (r-3)*stride]; |
---|
3690 | p1 = Rec[c + (r-2)*stride]; |
---|
3691 | p0 = Rec[c + (r-1)*stride]; |
---|
3692 | q0 = Rec[c + r*stride]; |
---|
3693 | q1 = Rec[c + (r+1)*stride]; |
---|
3694 | q2 = Rec[c + (r+2)*stride]; |
---|
3695 | a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1); |
---|
3696 | if (thr1 < a && a < thr2) |
---|
3697 | { |
---|
3698 | rowSAD[rowIdx] += abs(p0 - q0); |
---|
3699 | } |
---|
3700 | } |
---|
3701 | rowIdx++; |
---|
3702 | } |
---|
3703 | } |
---|
3704 | |
---|
3705 | UInt64 colSADsum = 0; |
---|
3706 | UInt64 rowSADsum = 0; |
---|
3707 | for(Int c = 0; c < noCol-1; c++) |
---|
3708 | { |
---|
3709 | colSADsum += colSAD[c]; |
---|
3710 | } |
---|
3711 | for(Int r = 0; r < noRows-1; r++) |
---|
3712 | { |
---|
3713 | rowSADsum += rowSAD[r]; |
---|
3714 | } |
---|
3715 | |
---|
3716 | colSADsum <<= 10; |
---|
3717 | rowSADsum <<= 10; |
---|
3718 | colSADsum /= (noCol-1); |
---|
3719 | colSADsum /= picHeight; |
---|
3720 | rowSADsum /= (noRows-1); |
---|
3721 | rowSADsum /= picWidth; |
---|
3722 | |
---|
3723 | UInt64 avgSAD = ((colSADsum + rowSADsum)>>1); |
---|
3724 | avgSAD >>= (g_bitDepthY-8); |
---|
3725 | |
---|
3726 | if ( avgSAD > 2048 ) |
---|
3727 | { |
---|
3728 | avgSAD >>= 9; |
---|
3729 | Int offset = Clip3(2,6,(Int)avgSAD); |
---|
3730 | for (Int i=0; i<uiNumSlices; i++) |
---|
3731 | { |
---|
3732 | pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true); |
---|
3733 | pcPic->getSlice(i)->setDeblockingFilterDisable(false); |
---|
3734 | pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( offset ); |
---|
3735 | pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( offset ); |
---|
3736 | } |
---|
3737 | } |
---|
3738 | else |
---|
3739 | { |
---|
3740 | for (Int i=0; i<uiNumSlices; i++) |
---|
3741 | { |
---|
3742 | pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(false); |
---|
3743 | pcPic->getSlice(i)->setDeblockingFilterDisable( pcPic->getSlice(i)->getPPS()->getPicDisableDeblockingFilterFlag() ); |
---|
3744 | pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterBetaOffsetDiv2() ); |
---|
3745 | pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterTcOffsetDiv2() ); |
---|
3746 | } |
---|
3747 | } |
---|
3748 | |
---|
3749 | free(colSAD); |
---|
3750 | free(rowSAD); |
---|
3751 | } |
---|
3752 | |
---|
3753 | #if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING |
---|
3754 | TComPic* TEncGOP::getMotionPredIlp(TComSlice* pcSlice) |
---|
3755 | { |
---|
3756 | TComPic* ilpPic = NULL; |
---|
3757 | Int activeMotionPredReflayerIdx = 0; |
---|
3758 | |
---|
3759 | for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
---|
3760 | { |
---|
3761 | UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i); |
---|
3762 | if( m_pcEncTop->getMotionPredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) ) ) |
---|
3763 | { |
---|
3764 | if (activeMotionPredReflayerIdx == pcSlice->getColRefLayerIdx()) |
---|
3765 | { |
---|
3766 | ilpPic = m_pcEncTop->getIlpList()[refLayerIdc]; |
---|
3767 | break; |
---|
3768 | } |
---|
3769 | else |
---|
3770 | { |
---|
3771 | activeMotionPredReflayerIdx++; |
---|
3772 | } |
---|
3773 | } |
---|
3774 | } |
---|
3775 | |
---|
3776 | assert(ilpPic != NULL); |
---|
3777 | |
---|
3778 | return ilpPic; |
---|
3779 | } |
---|
3780 | #endif |
---|
3781 | |
---|
3782 | //! \} |
---|