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