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 | Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps) |
---|
310 | { |
---|
311 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
312 | |
---|
313 | if(m_pcCfg->getActiveParameterSetsSEIEnabled()) |
---|
314 | { |
---|
315 | SEIActiveParameterSets *sei = xCreateSEIActiveParameterSets (sps); |
---|
316 | |
---|
317 | //nalu = NALUnit(NAL_UNIT_SEI); |
---|
318 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
319 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
320 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
321 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
322 | delete sei; |
---|
323 | m_activeParameterSetSEIPresentInAU = true; |
---|
324 | } |
---|
325 | |
---|
326 | #if M0043_LAYERS_PRESENT_SEI |
---|
327 | if(m_pcCfg->getLayersPresentSEIEnabled()) |
---|
328 | { |
---|
329 | SEILayersPresent *sei = xCreateSEILayersPresent (); |
---|
330 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
331 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
332 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
333 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
334 | delete sei; |
---|
335 | } |
---|
336 | #endif |
---|
337 | |
---|
338 | if(m_pcCfg->getFramePackingArrangementSEIEnabled()) |
---|
339 | { |
---|
340 | SEIFramePacking *sei = xCreateSEIFramePacking (); |
---|
341 | |
---|
342 | nalu = NALUnit(NAL_UNIT_PREFIX_SEI); |
---|
343 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
344 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
345 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
346 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
347 | delete sei; |
---|
348 | } |
---|
349 | if (m_pcCfg->getDisplayOrientationSEIAngle()) |
---|
350 | { |
---|
351 | SEIDisplayOrientation *sei = xCreateSEIDisplayOrientation(); |
---|
352 | |
---|
353 | nalu = NALUnit(NAL_UNIT_PREFIX_SEI); |
---|
354 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
355 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
356 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
357 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
358 | delete sei; |
---|
359 | } |
---|
360 | if(m_pcCfg->getToneMappingInfoSEIEnabled()) |
---|
361 | { |
---|
362 | SEIToneMappingInfo *sei = xCreateSEIToneMappingInfo (); |
---|
363 | |
---|
364 | nalu = NALUnit(NAL_UNIT_PREFIX_SEI); |
---|
365 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
366 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
367 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
368 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
369 | delete sei; |
---|
370 | } |
---|
371 | } |
---|
372 | |
---|
373 | // ==================================================================================================================== |
---|
374 | // Public member functions |
---|
375 | // ==================================================================================================================== |
---|
376 | #if SVC_EXTENSION |
---|
377 | Void TEncGOP::compressGOP( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP) |
---|
378 | #else |
---|
379 | Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP) |
---|
380 | #endif |
---|
381 | { |
---|
382 | TComPic* pcPic; |
---|
383 | TComPicYuv* pcPicYuvRecOut; |
---|
384 | TComSlice* pcSlice; |
---|
385 | TComOutputBitstream *pcBitstreamRedirect; |
---|
386 | pcBitstreamRedirect = new TComOutputBitstream; |
---|
387 | AccessUnit::iterator itLocationToPushSliceHeaderNALU; // used to store location where NALU containing slice header is to be inserted |
---|
388 | UInt uiOneBitstreamPerSliceLength = 0; |
---|
389 | TEncSbac* pcSbacCoders = NULL; |
---|
390 | TComOutputBitstream* pcSubstreamsOut = NULL; |
---|
391 | |
---|
392 | xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut ); |
---|
393 | |
---|
394 | m_iNumPicCoded = 0; |
---|
395 | SEIPictureTiming pictureTimingSEI; |
---|
396 | Bool writeSOP = m_pcCfg->getSOPDescriptionSEIEnabled(); |
---|
397 | // Initialize Scalable Nesting SEI with single layer values |
---|
398 | SEIScalableNesting scalableNestingSEI; |
---|
399 | 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 |
---|
400 | scalableNestingSEI.m_nestingOpFlag = 0; |
---|
401 | scalableNestingSEI.m_nestingNumOpsMinus1 = 0; //nesting_num_ops_minus1 |
---|
402 | scalableNestingSEI.m_allLayersFlag = 0; |
---|
403 | scalableNestingSEI.m_nestingNoOpMaxTemporalIdPlus1 = 6 + 1; //nesting_no_op_max_temporal_id_plus1 |
---|
404 | scalableNestingSEI.m_nestingNumLayersMinus1 = 1 - 1; //nesting_num_layers_minus1 |
---|
405 | scalableNestingSEI.m_nestingLayerId[0] = 0; |
---|
406 | scalableNestingSEI.m_callerOwnsSEIs = true; |
---|
407 | Int picSptDpbOutputDuDelay = 0; |
---|
408 | UInt *accumBitsDU = NULL; |
---|
409 | UInt *accumNalsDU = NULL; |
---|
410 | SEIDecodingUnitInfo decodingUnitInfoSEI; |
---|
411 | #if SVC_EXTENSION |
---|
412 | for ( Int iGOPid=iPicIdInGOP; iGOPid < iPicIdInGOP+1; iGOPid++ ) |
---|
413 | #else |
---|
414 | for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ ) |
---|
415 | #endif |
---|
416 | { |
---|
417 | UInt uiColDir = 1; |
---|
418 | //-- For time output for each slice |
---|
419 | long iBeforeTime = clock(); |
---|
420 | |
---|
421 | //select uiColDir |
---|
422 | Int iCloseLeft=1, iCloseRight=-1; |
---|
423 | for(Int i = 0; i<m_pcCfg->getGOPEntry(iGOPid).m_numRefPics; i++) |
---|
424 | { |
---|
425 | Int iRef = m_pcCfg->getGOPEntry(iGOPid).m_referencePics[i]; |
---|
426 | if(iRef>0&&(iRef<iCloseRight||iCloseRight==-1)) |
---|
427 | { |
---|
428 | iCloseRight=iRef; |
---|
429 | } |
---|
430 | else if(iRef<0&&(iRef>iCloseLeft||iCloseLeft==1)) |
---|
431 | { |
---|
432 | iCloseLeft=iRef; |
---|
433 | } |
---|
434 | } |
---|
435 | if(iCloseRight>-1) |
---|
436 | { |
---|
437 | iCloseRight=iCloseRight+m_pcCfg->getGOPEntry(iGOPid).m_POC-1; |
---|
438 | } |
---|
439 | if(iCloseLeft<1) |
---|
440 | { |
---|
441 | iCloseLeft=iCloseLeft+m_pcCfg->getGOPEntry(iGOPid).m_POC-1; |
---|
442 | while(iCloseLeft<0) |
---|
443 | { |
---|
444 | iCloseLeft+=m_iGopSize; |
---|
445 | } |
---|
446 | } |
---|
447 | Int iLeftQP=0, iRightQP=0; |
---|
448 | for(Int i=0; i<m_iGopSize; i++) |
---|
449 | { |
---|
450 | if(m_pcCfg->getGOPEntry(i).m_POC==(iCloseLeft%m_iGopSize)+1) |
---|
451 | { |
---|
452 | iLeftQP= m_pcCfg->getGOPEntry(i).m_QPOffset; |
---|
453 | } |
---|
454 | if (m_pcCfg->getGOPEntry(i).m_POC==(iCloseRight%m_iGopSize)+1) |
---|
455 | { |
---|
456 | iRightQP=m_pcCfg->getGOPEntry(i).m_QPOffset; |
---|
457 | } |
---|
458 | } |
---|
459 | if(iCloseRight>-1&&iRightQP<iLeftQP) |
---|
460 | { |
---|
461 | uiColDir=0; |
---|
462 | } |
---|
463 | |
---|
464 | /////////////////////////////////////////////////////////////////////////////////////////////////// Initial to start encoding |
---|
465 | Int pocCurr = iPOCLast -iNumPicRcvd+ m_pcCfg->getGOPEntry(iGOPid).m_POC; |
---|
466 | Int iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC; |
---|
467 | if(iPOCLast == 0) |
---|
468 | { |
---|
469 | pocCurr=0; |
---|
470 | iTimeOffset = 1; |
---|
471 | } |
---|
472 | if(pocCurr>=m_pcCfg->getFramesToBeEncoded()) |
---|
473 | { |
---|
474 | continue; |
---|
475 | } |
---|
476 | |
---|
477 | #if M0040_ADAPTIVE_RESOLUTION_CHANGE |
---|
478 | if (m_pcEncTop->getAdaptiveResolutionChange() > 0 && ((m_layerId == 1 && pocCurr < m_pcEncTop->getAdaptiveResolutionChange()) || |
---|
479 | (m_layerId == 0 && pocCurr > m_pcEncTop->getAdaptiveResolutionChange())) ) |
---|
480 | { |
---|
481 | continue; |
---|
482 | } |
---|
483 | #endif |
---|
484 | |
---|
485 | if( getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
---|
486 | { |
---|
487 | m_iLastIDR = pocCurr; |
---|
488 | } |
---|
489 | // start a new access unit: create an entry in the list of output access units |
---|
490 | accessUnitsInGOP.push_back(AccessUnit()); |
---|
491 | AccessUnit& accessUnit = accessUnitsInGOP.back(); |
---|
492 | xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr ); |
---|
493 | |
---|
494 | // Slice data initialization |
---|
495 | pcPic->clearSliceBuffer(); |
---|
496 | assert(pcPic->getNumAllocatedSlice() == 1); |
---|
497 | m_pcSliceEncoder->setSliceIdx(0); |
---|
498 | pcPic->setCurrSliceIdx(0); |
---|
499 | #if SVC_EXTENSION |
---|
500 | pcPic->setLayerId( m_layerId ); |
---|
501 | m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getVPS() ); |
---|
502 | #else |
---|
503 | m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() ); |
---|
504 | #endif |
---|
505 | #if POC_RESET_FLAG |
---|
506 | if( !pcSlice->getPocResetFlag() ) // For picture that are not reset, we should adjust the value of POC calculated from the configuration files. |
---|
507 | { |
---|
508 | // Subtract POC adjustment value until now. |
---|
509 | pcSlice->setPOC( pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue() ); |
---|
510 | } |
---|
511 | else |
---|
512 | { |
---|
513 | // Check if this is the first slice in the picture |
---|
514 | // In the encoder, the POC values are copied along with copySliceInfo, so we only need |
---|
515 | // to do this for the first slice. |
---|
516 | Int pocAdjustValue = pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue(); |
---|
517 | if( pcSlice->getSliceIdx() == 0 ) |
---|
518 | { |
---|
519 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
520 | |
---|
521 | // Iterate through all picture in DPB |
---|
522 | while( iterPic != rcListPic.end() ) |
---|
523 | { |
---|
524 | TComPic *dpbPic = *iterPic; |
---|
525 | if( dpbPic->getPOC() == pocCurr ) |
---|
526 | { |
---|
527 | if( dpbPic->getReconMark() ) |
---|
528 | { |
---|
529 | assert( !( dpbPic->getSlice(0)->isReferenced() ) && !( dpbPic->getOutputMark() ) ); |
---|
530 | } |
---|
531 | } |
---|
532 | // Check if the picture pointed to by iterPic is either used for reference or |
---|
533 | // needed for output, are in the same layer, and not the current picture. |
---|
534 | if( /* ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) ) |
---|
535 | && */ ( dpbPic->getLayerId() == pcSlice->getLayerId() ) |
---|
536 | && ( dpbPic->getReconMark() ) |
---|
537 | ) |
---|
538 | { |
---|
539 | for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--) |
---|
540 | { |
---|
541 | TComSlice *slice = dpbPic->getSlice(i); |
---|
542 | TComReferencePictureSet *rps = slice->getRPS(); |
---|
543 | slice->setPOC( dpbPic->getSlice(i)->getPOC() - pocAdjustValue ); |
---|
544 | |
---|
545 | // Also adjust the POC value stored in the RPS of each such slice |
---|
546 | for(Int j = rps->getNumberOfPictures(); j >= 0; j--) |
---|
547 | { |
---|
548 | rps->setPOC( j, rps->getPOC(j) - pocAdjustValue ); |
---|
549 | } |
---|
550 | // Also adjust the value of refPOC |
---|
551 | for(Int k = 0; k < 2; k++) // For List 0 and List 1 |
---|
552 | { |
---|
553 | RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0; |
---|
554 | for(Int j = 0; j < slice->getNumRefIdx(list); j++) |
---|
555 | { |
---|
556 | slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j); |
---|
557 | } |
---|
558 | } |
---|
559 | } |
---|
560 | } |
---|
561 | iterPic++; |
---|
562 | } |
---|
563 | m_pcEncTop->setPocAdjustmentValue( m_pcEncTop->getPocAdjustmentValue() + pocAdjustValue ); |
---|
564 | } |
---|
565 | pcSlice->setPocValueBeforeReset( pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue() + pocAdjustValue ); |
---|
566 | pcSlice->setPOC( 0 ); |
---|
567 | } |
---|
568 | #endif |
---|
569 | #if M0040_ADAPTIVE_RESOLUTION_CHANGE |
---|
570 | if (m_pcEncTop->getAdaptiveResolutionChange() > 0 && m_layerId == 1 && pocCurr > m_pcEncTop->getAdaptiveResolutionChange()) |
---|
571 | { |
---|
572 | pcSlice->setActiveNumILRRefIdx(0); |
---|
573 | pcSlice->setInterLayerPredEnabledFlag(false); |
---|
574 | #if M0457_COL_PICTURE_SIGNALING |
---|
575 | pcSlice->setMFMEnabledFlag(false); |
---|
576 | #if !REMOVE_COL_PICTURE_SIGNALING |
---|
577 | pcSlice->setAltColIndicationFlag(false); |
---|
578 | #endif |
---|
579 | #endif |
---|
580 | } |
---|
581 | #endif |
---|
582 | |
---|
583 | #if M0457_IL_SAMPLE_PRED_ONLY_FLAG |
---|
584 | pcSlice->setNumSamplePredRefLayers( m_pcEncTop->getNumSamplePredRefLayers() ); |
---|
585 | pcSlice->setInterLayerSamplePredOnlyFlag( 0 ); |
---|
586 | if( pcSlice->getNumSamplePredRefLayers() > 0 && pcSlice->getActiveNumILRRefIdx() > 0 ) |
---|
587 | { |
---|
588 | if( m_pcEncTop->getIlSampleOnlyPred() > 0 ) |
---|
589 | { |
---|
590 | pcSlice->setInterLayerSamplePredOnlyFlag( true ); |
---|
591 | } |
---|
592 | } |
---|
593 | #endif |
---|
594 | |
---|
595 | #if IL_SL_SIGNALLING_N0371 |
---|
596 | m_pcEncTop->getScalingList()->setLayerId( m_layerId ); |
---|
597 | #endif |
---|
598 | |
---|
599 | pcSlice->setLastIDR(m_iLastIDR); |
---|
600 | pcSlice->setSliceIdx(0); |
---|
601 | //set default slice level flag to the same as SPS level flag |
---|
602 | pcSlice->setLFCrossSliceBoundaryFlag( pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() ); |
---|
603 | pcSlice->setScalingList ( m_pcEncTop->getScalingList() ); |
---|
604 | pcSlice->getScalingList()->setUseTransformSkip(m_pcEncTop->getPPS()->getUseTransformSkip()); |
---|
605 | if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF) |
---|
606 | { |
---|
607 | #if IL_SL_SIGNALLING_N0371 |
---|
608 | m_pcEncTop->getTrQuant()->setFlatScalingList( m_layerId ); |
---|
609 | #else |
---|
610 | m_pcEncTop->getTrQuant()->setFlatScalingList(); |
---|
611 | #endif |
---|
612 | m_pcEncTop->getTrQuant()->setUseScalingList(false); |
---|
613 | m_pcEncTop->getSPS()->setScalingListPresentFlag(false); |
---|
614 | m_pcEncTop->getPPS()->setScalingListPresentFlag(false); |
---|
615 | } |
---|
616 | else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_DEFAULT) |
---|
617 | { |
---|
618 | #if IL_SL_SIGNALLING_N0371 |
---|
619 | pcSlice->getScalingList()->setLayerId( m_layerId ); |
---|
620 | #endif |
---|
621 | |
---|
622 | #if IL_SL_SIGNALLING_N0371 |
---|
623 | pcSlice->setDefaultScalingList ( m_layerId ); |
---|
624 | #else |
---|
625 | pcSlice->setDefaultScalingList (); |
---|
626 | #endif |
---|
627 | |
---|
628 | m_pcEncTop->getSPS()->setScalingListPresentFlag(false); |
---|
629 | m_pcEncTop->getPPS()->setScalingListPresentFlag(false); |
---|
630 | m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList()); |
---|
631 | m_pcEncTop->getTrQuant()->setUseScalingList(true); |
---|
632 | } |
---|
633 | else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_FILE_READ) |
---|
634 | { |
---|
635 | #if IL_SL_SIGNALLING_N0371 |
---|
636 | pcSlice->getScalingList()->setLayerId( m_layerId ); |
---|
637 | #endif |
---|
638 | |
---|
639 | if(pcSlice->getScalingList()->xParseScalingList(m_pcCfg->getScalingListFile())) |
---|
640 | { |
---|
641 | #if IL_SL_SIGNALLING_N0371 |
---|
642 | pcSlice->setDefaultScalingList ( m_layerId ); |
---|
643 | #else |
---|
644 | pcSlice->setDefaultScalingList (); |
---|
645 | #endif |
---|
646 | } |
---|
647 | #if IL_SL_SIGNALLING_N0371 |
---|
648 | pcSlice->getScalingList()->checkDcOfMatrix( m_layerId ); |
---|
649 | #else |
---|
650 | pcSlice->getScalingList()->checkDcOfMatrix(); |
---|
651 | #endif |
---|
652 | m_pcEncTop->getSPS()->setScalingListPresentFlag(pcSlice->checkDefaultScalingList()); |
---|
653 | |
---|
654 | #if IL_SL_SIGNALLING_N0371 |
---|
655 | if( m_layerId > 0 ) |
---|
656 | { |
---|
657 | m_pcEncTop->getSPS()->setPredScalingListFlag (true); |
---|
658 | m_pcEncTop->getSPS()->setScalingListRefLayerId( 0 ); |
---|
659 | } |
---|
660 | #endif |
---|
661 | |
---|
662 | m_pcEncTop->getPPS()->setScalingListPresentFlag(false); |
---|
663 | |
---|
664 | #if IL_SL_SIGNALLING_N0371 |
---|
665 | if( m_layerId > 0 ) |
---|
666 | { |
---|
667 | m_pcEncTop->getPPS()->setPredScalingListFlag (false); |
---|
668 | m_pcEncTop->getPPS()->setScalingListRefLayerId( 0 ); |
---|
669 | } |
---|
670 | #endif |
---|
671 | |
---|
672 | m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList()); |
---|
673 | m_pcEncTop->getTrQuant()->setUseScalingList(true); |
---|
674 | } |
---|
675 | else |
---|
676 | { |
---|
677 | printf("error : ScalingList == %d no support\n",m_pcEncTop->getUseScalingListId()); |
---|
678 | assert(0); |
---|
679 | } |
---|
680 | |
---|
681 | if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='P') |
---|
682 | { |
---|
683 | pcSlice->setSliceType(P_SLICE); |
---|
684 | } |
---|
685 | // Set the nal unit type |
---|
686 | pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR)); |
---|
687 | #if SVC_EXTENSION |
---|
688 | #if ILR_RESTR && ILR_RESTR_FIX |
---|
689 | Int interLayerPredLayerIdcTmp[MAX_VPS_LAYER_ID_PLUS1]; |
---|
690 | Int activeNumILRRefIdxTmp = 0; |
---|
691 | #endif |
---|
692 | if (m_layerId > 0) |
---|
693 | { |
---|
694 | for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
---|
695 | { |
---|
696 | UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i); |
---|
697 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
698 | TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(refLayerIdc)->getListPic(); |
---|
699 | #else |
---|
700 | TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId-1]->getListPic(); |
---|
701 | #endif |
---|
702 | pcSlice->setBaseColPic( *cListPic, refLayerIdc ); |
---|
703 | |
---|
704 | #if ILR_RESTR && ILR_RESTR_FIX |
---|
705 | // Apply temporal layer restriction to inter-layer prediction |
---|
706 | Int maxTidIlRefPicsPlus1 = m_pcEncTop->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getLayerId()); |
---|
707 | if( ((Int)(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getRapPicFlag()) ) |
---|
708 | { |
---|
709 | interLayerPredLayerIdcTmp[activeNumILRRefIdxTmp++] = refLayerIdc; // add picture to the list of valid inter-layer pictures |
---|
710 | } |
---|
711 | else |
---|
712 | { |
---|
713 | continue; // ILP is not valid due to temporal layer restriction |
---|
714 | } |
---|
715 | #endif |
---|
716 | |
---|
717 | #if SCALED_REF_LAYER_OFFSETS |
---|
718 | const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow(refLayerIdc); |
---|
719 | |
---|
720 | Int widthBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth(); |
---|
721 | Int heightBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight(); |
---|
722 | |
---|
723 | Int widthEL = pcPic->getPicYuvRec()->getWidth() - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset(); |
---|
724 | Int heightEL = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset() - scalEL.getWindowBottomOffset(); |
---|
725 | #else |
---|
726 | const Window &confBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getConformanceWindow(); |
---|
727 | const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow(); |
---|
728 | |
---|
729 | Int widthBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset(); |
---|
730 | Int heightBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset(); |
---|
731 | |
---|
732 | Int widthEL = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset(); |
---|
733 | Int heightEL = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset(); |
---|
734 | #endif |
---|
735 | g_mvScalingFactor[refLayerIdc][0] = widthEL == widthBL ? 4096 : Clip3(-4096, 4095, ((widthEL << 8) + (widthBL >> 1)) / widthBL); |
---|
736 | g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL); |
---|
737 | |
---|
738 | g_posScalingFactor[refLayerIdc][0] = ((widthBL << 16) + (widthEL >> 1)) / widthEL; |
---|
739 | g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL; |
---|
740 | |
---|
741 | #if SVC_UPSAMPLING |
---|
742 | if( pcPic->isSpatialEnhLayer(refLayerIdc)) |
---|
743 | { |
---|
744 | #if SCALED_REF_LAYER_OFFSETS |
---|
745 | m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) ); |
---|
746 | #else |
---|
747 | m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec() ); |
---|
748 | #endif |
---|
749 | } |
---|
750 | else |
---|
751 | { |
---|
752 | pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() ); |
---|
753 | } |
---|
754 | pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) ); |
---|
755 | #endif |
---|
756 | } |
---|
757 | |
---|
758 | #if ILR_RESTR && ILR_RESTR_FIX |
---|
759 | // Update the list of active inter-layer pictures |
---|
760 | for ( Int i = 0; i < activeNumILRRefIdxTmp; i++) |
---|
761 | { |
---|
762 | pcSlice->setInterLayerPredLayerIdc( interLayerPredLayerIdcTmp[i], i ); |
---|
763 | } |
---|
764 | pcSlice->setActiveNumILRRefIdx( activeNumILRRefIdxTmp ); |
---|
765 | if ( pcSlice->getActiveNumILRRefIdx() == 0 ) |
---|
766 | { |
---|
767 | // No valid inter-layer pictures -> disable inter-layer prediction |
---|
768 | pcSlice->setInterLayerPredEnabledFlag(false); |
---|
769 | } |
---|
770 | #endif |
---|
771 | |
---|
772 | if( pocCurr % m_pcCfg->getIntraPeriod() == 0 ) |
---|
773 | { |
---|
774 | #if N0147_IRAP_ALIGN_FLAG |
---|
775 | if(pcSlice->getVPS()->getCrossLayerIrapAlignFlag()) |
---|
776 | { |
---|
777 | TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic(); |
---|
778 | TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() ); |
---|
779 | if(picLayer0) |
---|
780 | { |
---|
781 | pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType()); |
---|
782 | } |
---|
783 | else |
---|
784 | { |
---|
785 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA); |
---|
786 | } |
---|
787 | } |
---|
788 | else |
---|
789 | #endif |
---|
790 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA); |
---|
791 | |
---|
792 | #if IDR_ALIGNMENT |
---|
793 | TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic(); |
---|
794 | TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() ); |
---|
795 | if( picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
---|
796 | { |
---|
797 | pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType()); |
---|
798 | } |
---|
799 | else |
---|
800 | { |
---|
801 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA); |
---|
802 | } |
---|
803 | #endif |
---|
804 | } |
---|
805 | |
---|
806 | if( pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) |
---|
807 | { |
---|
808 | pcSlice->setSliceType(I_SLICE); |
---|
809 | } |
---|
810 | else if( !m_pcEncTop->getElRapSliceTypeB() ) |
---|
811 | { |
---|
812 | if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) && |
---|
813 | (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) && |
---|
814 | pcSlice->getSliceType() == B_SLICE ) |
---|
815 | { |
---|
816 | pcSlice->setSliceType(P_SLICE); |
---|
817 | } |
---|
818 | } |
---|
819 | } |
---|
820 | #endif //SVC_EXTENSION |
---|
821 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
822 | { |
---|
823 | if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R) |
---|
824 | { |
---|
825 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N); |
---|
826 | } |
---|
827 | if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RADL_R) |
---|
828 | { |
---|
829 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RADL_N); |
---|
830 | } |
---|
831 | if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RASL_R) |
---|
832 | { |
---|
833 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RASL_N); |
---|
834 | } |
---|
835 | } |
---|
836 | |
---|
837 | // Do decoding refresh marking if any |
---|
838 | pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic); |
---|
839 | m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid); |
---|
840 | pcSlice->getRPS()->setNumberOfLongtermPictures(0); |
---|
841 | |
---|
842 | #if FIX1071 |
---|
843 | if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP())) |
---|
844 | { |
---|
845 | pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP()); |
---|
846 | } |
---|
847 | #else |
---|
848 | if(pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) |
---|
849 | { |
---|
850 | pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS()); |
---|
851 | } |
---|
852 | #endif |
---|
853 | pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS()); |
---|
854 | |
---|
855 | if(pcSlice->getTLayer() > 0) |
---|
856 | { |
---|
857 | if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic) || pcSlice->getSPS()->getTemporalIdNestingFlag()) |
---|
858 | { |
---|
859 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
860 | { |
---|
861 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_N); |
---|
862 | } |
---|
863 | else |
---|
864 | { |
---|
865 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R); |
---|
866 | } |
---|
867 | #if ALIGN_TSA_STSA_PICS |
---|
868 | if( pcSlice->getLayerId() > 0 ) |
---|
869 | { |
---|
870 | for(Int i = 0; i < pcSlice->getLayerId(); i++) |
---|
871 | { |
---|
872 | TComList<TComPic*> *cListPic = m_ppcTEncTop[i]->getListPic(); |
---|
873 | TComPic* lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() ); |
---|
874 | if( lowerLayerPic ) // If picture exists in Layer i |
---|
875 | { |
---|
876 | assert( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ) || |
---|
877 | ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R ) ); |
---|
878 | // TSA pictures are aligned within an access unit. |
---|
879 | } |
---|
880 | } |
---|
881 | } |
---|
882 | #endif |
---|
883 | } |
---|
884 | else if(pcSlice->isStepwiseTemporalLayerSwitchingPointCandidate(rcListPic)) |
---|
885 | { |
---|
886 | Bool isSTSA=true; |
---|
887 | for(Int ii=iGOPid+1;(ii<m_pcCfg->getGOPSize() && isSTSA==true);ii++) |
---|
888 | { |
---|
889 | Int lTid= m_pcCfg->getGOPEntry(ii).m_temporalId; |
---|
890 | if(lTid==pcSlice->getTLayer()) |
---|
891 | { |
---|
892 | TComReferencePictureSet* nRPS = pcSlice->getSPS()->getRPSList()->getReferencePictureSet(ii); |
---|
893 | for(Int jj=0;jj<nRPS->getNumberOfPictures();jj++) |
---|
894 | { |
---|
895 | if(nRPS->getUsed(jj)) |
---|
896 | { |
---|
897 | Int tPoc=m_pcCfg->getGOPEntry(ii).m_POC+nRPS->getDeltaPOC(jj); |
---|
898 | Int kk=0; |
---|
899 | for(kk=0;kk<m_pcCfg->getGOPSize();kk++) |
---|
900 | { |
---|
901 | if(m_pcCfg->getGOPEntry(kk).m_POC==tPoc) |
---|
902 | break; |
---|
903 | } |
---|
904 | Int tTid=m_pcCfg->getGOPEntry(kk).m_temporalId; |
---|
905 | if(tTid >= pcSlice->getTLayer()) |
---|
906 | { |
---|
907 | isSTSA=false; |
---|
908 | break; |
---|
909 | } |
---|
910 | } |
---|
911 | } |
---|
912 | } |
---|
913 | } |
---|
914 | if(isSTSA==true) |
---|
915 | { |
---|
916 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
917 | { |
---|
918 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N); |
---|
919 | } |
---|
920 | else |
---|
921 | { |
---|
922 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R); |
---|
923 | } |
---|
924 | #if ALIGN_TSA_STSA_PICS |
---|
925 | if( pcSlice->getLayerId() > 0 ) |
---|
926 | { |
---|
927 | for(Int i = 0; i < pcSlice->getLayerId(); i++) |
---|
928 | { |
---|
929 | TComList<TComPic*> *cListPic = m_ppcTEncTop[i]->getListPic(); |
---|
930 | TComPic* lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() ); |
---|
931 | if( lowerLayerPic ) // If picture exists in Layer i |
---|
932 | { |
---|
933 | assert( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ) || |
---|
934 | ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R ) ); |
---|
935 | } |
---|
936 | // STSA pictures are aligned within an access unit. |
---|
937 | } |
---|
938 | } |
---|
939 | #endif |
---|
940 | } |
---|
941 | } |
---|
942 | } |
---|
943 | arrangeLongtermPicturesInRPS(pcSlice, rcListPic); |
---|
944 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
---|
945 | refPicListModification->setRefPicListModificationFlagL0(0); |
---|
946 | refPicListModification->setRefPicListModificationFlagL1(0); |
---|
947 | pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures())); |
---|
948 | pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures())); |
---|
949 | |
---|
950 | #if SVC_EXTENSION |
---|
951 | if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() ) |
---|
952 | { |
---|
953 | #if RESTR_CHK |
---|
954 | #if POC_RESET_FLAG |
---|
955 | if ( pocCurr > 0 && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL()) |
---|
956 | #else |
---|
957 | if (pcSlice->getPOC()>0 && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL()) |
---|
958 | #endif |
---|
959 | { |
---|
960 | #if JCTVC_M0458_INTERLAYER_RPS_SIG |
---|
961 | pcSlice->setActiveNumILRRefIdx(0); |
---|
962 | pcSlice->setInterLayerPredEnabledFlag(0); |
---|
963 | #else |
---|
964 | pcSlice->setNumILRRefIdx(0); |
---|
965 | #endif |
---|
966 | } |
---|
967 | #endif |
---|
968 | #if JCTVC_M0458_INTERLAYER_RPS_SIG |
---|
969 | if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) |
---|
970 | { |
---|
971 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getActiveNumILRRefIdx()); |
---|
972 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getActiveNumILRRefIdx()); |
---|
973 | } |
---|
974 | else |
---|
975 | { |
---|
976 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumRefIdx(REF_PIC_LIST_0)+pcSlice->getActiveNumILRRefIdx()); |
---|
977 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumRefIdx(REF_PIC_LIST_1)+pcSlice->getActiveNumILRRefIdx()); |
---|
978 | } |
---|
979 | #else |
---|
980 | if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) |
---|
981 | { |
---|
982 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumILRRefIdx()); |
---|
983 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumILRRefIdx()); |
---|
984 | } |
---|
985 | else |
---|
986 | { |
---|
987 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumRefIdx(REF_PIC_LIST_0)+pcSlice->getNumILRRefIdx()); |
---|
988 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumRefIdx(REF_PIC_LIST_1)+pcSlice->getNumILRRefIdx()); |
---|
989 | } |
---|
990 | #endif |
---|
991 | } |
---|
992 | #endif //SVC_EXTENSION |
---|
993 | |
---|
994 | #if ADAPTIVE_QP_SELECTION |
---|
995 | pcSlice->setTrQuant( m_pcEncTop->getTrQuant() ); |
---|
996 | #endif |
---|
997 | |
---|
998 | #if SVC_EXTENSION |
---|
999 | #if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING |
---|
1000 | if ( pcSlice->getSliceType() == B_SLICE && !(pcSlice->getActiveNumILRRefIdx() > 0 && m_pcEncTop->getNumMotionPredRefLayers() > 0) ) |
---|
1001 | #else |
---|
1002 | if( pcSlice->getSliceType() == B_SLICE ) |
---|
1003 | #endif |
---|
1004 | { |
---|
1005 | pcSlice->setColFromL0Flag(1-uiColDir); |
---|
1006 | } |
---|
1007 | |
---|
1008 | // Set reference list |
---|
1009 | if(m_layerId == 0 || ( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() == 0 ) ) |
---|
1010 | { |
---|
1011 | pcSlice->setRefPicList( rcListPic); |
---|
1012 | } |
---|
1013 | |
---|
1014 | if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() ) |
---|
1015 | { |
---|
1016 | m_pcEncTop->setILRPic(pcPic); |
---|
1017 | #if REF_IDX_MFM |
---|
1018 | #if M0457_COL_PICTURE_SIGNALING |
---|
1019 | if( pcSlice->getMFMEnabledFlag() ) |
---|
1020 | #else |
---|
1021 | if( pcSlice->getSPS()->getMFMEnabledFlag() ) |
---|
1022 | #endif |
---|
1023 | { |
---|
1024 | pcSlice->setRefPOCListILP(m_pcEncTop->getIlpList(), pcSlice->getBaseColPic()); |
---|
1025 | #if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING |
---|
1026 | pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice)); |
---|
1027 | #endif |
---|
1028 | } |
---|
1029 | #else |
---|
1030 | // Set reference list |
---|
1031 | pcSlice->setRefPicList ( rcListPic ); |
---|
1032 | #endif //SVC_EXTENSION |
---|
1033 | #if N0147_IRAP_ALIGN_FLAG |
---|
1034 | if(pcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1 || pcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1) |
---|
1035 | #endif |
---|
1036 | { |
---|
1037 | pcSlice->setRefPicListModificationSvc(); |
---|
1038 | } |
---|
1039 | pcSlice->setRefPicList( rcListPic, false, m_pcEncTop->getIlpList()); |
---|
1040 | |
---|
1041 | #if REF_IDX_MFM |
---|
1042 | #if M0457_COL_PICTURE_SIGNALING |
---|
1043 | #if REMOVE_COL_PICTURE_SIGNALING |
---|
1044 | if( pcSlice->getMFMEnabledFlag() ) |
---|
1045 | #else |
---|
1046 | if( pcSlice->getMFMEnabledFlag() && !(pcSlice->getActiveNumILRRefIdx() > 0 && m_pcEncTop->getNumMotionPredRefLayers() > 0) ) |
---|
1047 | #endif |
---|
1048 | #else |
---|
1049 | if( pcSlice->getSPS()->getMFMEnabledFlag() ) |
---|
1050 | #endif |
---|
1051 | { |
---|
1052 | Bool found = false; |
---|
1053 | UInt ColFromL0Flag = pcSlice->getColFromL0Flag(); |
---|
1054 | UInt ColRefIdx = pcSlice->getColRefIdx(); |
---|
1055 | for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) |
---|
1056 | { |
---|
1057 | if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) ) |
---|
1058 | { |
---|
1059 | ColRefIdx = colIdx; |
---|
1060 | found = true; |
---|
1061 | break; |
---|
1062 | } |
---|
1063 | } |
---|
1064 | |
---|
1065 | if( found == false ) |
---|
1066 | { |
---|
1067 | ColFromL0Flag = 1 - ColFromL0Flag; |
---|
1068 | for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) |
---|
1069 | { |
---|
1070 | if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) ) |
---|
1071 | { |
---|
1072 | ColRefIdx = colIdx; |
---|
1073 | found = true; |
---|
1074 | break; |
---|
1075 | } |
---|
1076 | } |
---|
1077 | } |
---|
1078 | |
---|
1079 | if(found == true) |
---|
1080 | { |
---|
1081 | pcSlice->setColFromL0Flag(ColFromL0Flag); |
---|
1082 | pcSlice->setColRefIdx(ColRefIdx); |
---|
1083 | } |
---|
1084 | } |
---|
1085 | #endif |
---|
1086 | } |
---|
1087 | #endif |
---|
1088 | |
---|
1089 | // Slice info. refinement |
---|
1090 | if ( (pcSlice->getSliceType() == B_SLICE) && (pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0) ) |
---|
1091 | { |
---|
1092 | pcSlice->setSliceType ( P_SLICE ); |
---|
1093 | } |
---|
1094 | |
---|
1095 | #if M0457_IL_SAMPLE_PRED_ONLY_FLAG |
---|
1096 | if (pcSlice->getSliceType() == B_SLICE && m_pcEncTop->getIlSampleOnlyPred() == 0) |
---|
1097 | #else |
---|
1098 | if (pcSlice->getSliceType() == B_SLICE) |
---|
1099 | #endif |
---|
1100 | { |
---|
1101 | #if !SVC_EXTENSION |
---|
1102 | pcSlice->setColFromL0Flag(1-uiColDir); |
---|
1103 | #endif |
---|
1104 | Bool bLowDelay = true; |
---|
1105 | Int iCurrPOC = pcSlice->getPOC(); |
---|
1106 | Int iRefIdx = 0; |
---|
1107 | |
---|
1108 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++) |
---|
1109 | { |
---|
1110 | if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC ) |
---|
1111 | { |
---|
1112 | bLowDelay = false; |
---|
1113 | } |
---|
1114 | } |
---|
1115 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++) |
---|
1116 | { |
---|
1117 | if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC ) |
---|
1118 | { |
---|
1119 | bLowDelay = false; |
---|
1120 | } |
---|
1121 | } |
---|
1122 | |
---|
1123 | pcSlice->setCheckLDC(bLowDelay); |
---|
1124 | } |
---|
1125 | else |
---|
1126 | { |
---|
1127 | pcSlice->setCheckLDC(true); |
---|
1128 | } |
---|
1129 | |
---|
1130 | uiColDir = 1-uiColDir; |
---|
1131 | |
---|
1132 | //------------------------------------------------------------- |
---|
1133 | pcSlice->setRefPOCList(); |
---|
1134 | |
---|
1135 | pcSlice->setList1IdxToList0Idx(); |
---|
1136 | |
---|
1137 | if (m_pcEncTop->getTMVPModeId() == 2) |
---|
1138 | { |
---|
1139 | if (iGOPid == 0) // first picture in SOP (i.e. forward B) |
---|
1140 | { |
---|
1141 | pcSlice->setEnableTMVPFlag(0); |
---|
1142 | } |
---|
1143 | else |
---|
1144 | { |
---|
1145 | // Note: pcSlice->getColFromL0Flag() is assumed to be always 0 and getcolRefIdx() is always 0. |
---|
1146 | pcSlice->setEnableTMVPFlag(1); |
---|
1147 | } |
---|
1148 | pcSlice->getSPS()->setTMVPFlagsPresent(1); |
---|
1149 | } |
---|
1150 | else if (m_pcEncTop->getTMVPModeId() == 1) |
---|
1151 | { |
---|
1152 | pcSlice->getSPS()->setTMVPFlagsPresent(1); |
---|
1153 | #if SVC_EXTENSION |
---|
1154 | if( pcSlice->getIdrPicFlag() ) |
---|
1155 | { |
---|
1156 | pcSlice->setEnableTMVPFlag(0); |
---|
1157 | } |
---|
1158 | else |
---|
1159 | #endif |
---|
1160 | pcSlice->setEnableTMVPFlag(1); |
---|
1161 | } |
---|
1162 | else |
---|
1163 | { |
---|
1164 | pcSlice->getSPS()->setTMVPFlagsPresent(0); |
---|
1165 | pcSlice->setEnableTMVPFlag(0); |
---|
1166 | } |
---|
1167 | /////////////////////////////////////////////////////////////////////////////////////////////////// Compress a slice |
---|
1168 | // Slice compression |
---|
1169 | if (m_pcCfg->getUseASR()) |
---|
1170 | { |
---|
1171 | m_pcSliceEncoder->setSearchRange(pcSlice); |
---|
1172 | } |
---|
1173 | |
---|
1174 | Bool bGPBcheck=false; |
---|
1175 | if ( pcSlice->getSliceType() == B_SLICE) |
---|
1176 | { |
---|
1177 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
1178 | { |
---|
1179 | bGPBcheck=true; |
---|
1180 | Int i; |
---|
1181 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
1182 | { |
---|
1183 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
1184 | { |
---|
1185 | bGPBcheck=false; |
---|
1186 | break; |
---|
1187 | } |
---|
1188 | } |
---|
1189 | } |
---|
1190 | } |
---|
1191 | if(bGPBcheck) |
---|
1192 | { |
---|
1193 | pcSlice->setMvdL1ZeroFlag(true); |
---|
1194 | } |
---|
1195 | else |
---|
1196 | { |
---|
1197 | pcSlice->setMvdL1ZeroFlag(false); |
---|
1198 | } |
---|
1199 | pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag()); |
---|
1200 | |
---|
1201 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
1202 | Double lambda = 0.0; |
---|
1203 | Int actualHeadBits = 0; |
---|
1204 | Int actualTotalBits = 0; |
---|
1205 | Int estimatedBits = 0; |
---|
1206 | Int tmpBitsBeforeWriting = 0; |
---|
1207 | if ( m_pcCfg->getUseRateCtrl() ) |
---|
1208 | { |
---|
1209 | Int frameLevel = m_pcRateCtrl->getRCSeq()->getGOPID2Level( iGOPid ); |
---|
1210 | if ( pcPic->getSlice(0)->getSliceType() == I_SLICE ) |
---|
1211 | { |
---|
1212 | frameLevel = 0; |
---|
1213 | } |
---|
1214 | m_pcRateCtrl->initRCPic( frameLevel ); |
---|
1215 | estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits(); |
---|
1216 | |
---|
1217 | Int sliceQP = m_pcCfg->getInitialQP(); |
---|
1218 | #if POC_RESET_FLAG |
---|
1219 | if ( ( pocCurr == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified |
---|
1220 | #else |
---|
1221 | if ( ( pcSlice->getPOC() == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified |
---|
1222 | #endif |
---|
1223 | { |
---|
1224 | Int NumberBFrames = ( m_pcCfg->getGOPSize() - 1 ); |
---|
1225 | Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames ); |
---|
1226 | Double dQPFactor = 0.57*dLambda_scale; |
---|
1227 | Int SHIFT_QP = 12; |
---|
1228 | Int bitdepth_luma_qp_scale = 0; |
---|
1229 | Double qp_temp = (Double) sliceQP + bitdepth_luma_qp_scale - SHIFT_QP; |
---|
1230 | lambda = dQPFactor*pow( 2.0, qp_temp/3.0 ); |
---|
1231 | } |
---|
1232 | else if ( frameLevel == 0 ) // intra case, but use the model |
---|
1233 | { |
---|
1234 | #if RATE_CONTROL_INTRA |
---|
1235 | m_pcSliceEncoder->calCostSliceI(pcPic); |
---|
1236 | #endif |
---|
1237 | if ( m_pcCfg->getIntraPeriod() != 1 ) // do not refine allocated bits for all intra case |
---|
1238 | { |
---|
1239 | Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits(); |
---|
1240 | #if RATE_CONTROL_INTRA |
---|
1241 | bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits ); |
---|
1242 | #else |
---|
1243 | bits = m_pcRateCtrl->getRCSeq()->getRefineBitsForIntra( bits ); |
---|
1244 | #endif |
---|
1245 | if ( bits < 200 ) |
---|
1246 | { |
---|
1247 | bits = 200; |
---|
1248 | } |
---|
1249 | m_pcRateCtrl->getRCPic()->setTargetBits( bits ); |
---|
1250 | } |
---|
1251 | |
---|
1252 | list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); |
---|
1253 | #if RATE_CONTROL_INTRA |
---|
1254 | m_pcRateCtrl->getRCPic()->getLCUInitTargetBits(); |
---|
1255 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); |
---|
1256 | #else |
---|
1257 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture ); |
---|
1258 | #endif |
---|
1259 | sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); |
---|
1260 | } |
---|
1261 | else // normal case |
---|
1262 | { |
---|
1263 | list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); |
---|
1264 | #if RATE_CONTROL_INTRA |
---|
1265 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); |
---|
1266 | #else |
---|
1267 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture ); |
---|
1268 | #endif |
---|
1269 | sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); |
---|
1270 | } |
---|
1271 | |
---|
1272 | #if REPN_FORMAT_IN_VPS |
---|
1273 | sliceQP = Clip3( -pcSlice->getQpBDOffsetY(), MAX_QP, sliceQP ); |
---|
1274 | #else |
---|
1275 | sliceQP = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, sliceQP ); |
---|
1276 | #endif |
---|
1277 | m_pcRateCtrl->getRCPic()->setPicEstQP( sliceQP ); |
---|
1278 | |
---|
1279 | m_pcSliceEncoder->resetQP( pcPic, sliceQP, lambda ); |
---|
1280 | } |
---|
1281 | #endif |
---|
1282 | |
---|
1283 | UInt uiNumSlices = 1; |
---|
1284 | |
---|
1285 | UInt uiInternalAddress = pcPic->getNumPartInCU()-4; |
---|
1286 | UInt uiExternalAddress = pcPic->getPicSym()->getNumberOfCUsInFrame()-1; |
---|
1287 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1288 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1289 | #if REPN_FORMAT_IN_VPS |
---|
1290 | UInt uiWidth = pcSlice->getPicWidthInLumaSamples(); |
---|
1291 | UInt uiHeight = pcSlice->getPicHeightInLumaSamples(); |
---|
1292 | #else |
---|
1293 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
1294 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
1295 | #endif |
---|
1296 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
1297 | { |
---|
1298 | uiInternalAddress--; |
---|
1299 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1300 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1301 | } |
---|
1302 | uiInternalAddress++; |
---|
1303 | if(uiInternalAddress==pcPic->getNumPartInCU()) |
---|
1304 | { |
---|
1305 | uiInternalAddress = 0; |
---|
1306 | uiExternalAddress++; |
---|
1307 | } |
---|
1308 | UInt uiRealEndAddress = uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress; |
---|
1309 | |
---|
1310 | UInt uiCummulativeTileWidth; |
---|
1311 | UInt uiCummulativeTileHeight; |
---|
1312 | Int p, j; |
---|
1313 | UInt uiEncCUAddr; |
---|
1314 | |
---|
1315 | //set NumColumnsMinus1 and NumRowsMinus1 |
---|
1316 | pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() ); |
---|
1317 | pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() ); |
---|
1318 | |
---|
1319 | //create the TComTileArray |
---|
1320 | pcPic->getPicSym()->xCreateTComTileArray(); |
---|
1321 | |
---|
1322 | if( pcSlice->getPPS()->getUniformSpacingFlag() == 1 ) |
---|
1323 | { |
---|
1324 | //set the width for each tile |
---|
1325 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
1326 | { |
---|
1327 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++) |
---|
1328 | { |
---|
1329 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )-> |
---|
1330 | setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) |
---|
1331 | - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) ); |
---|
1332 | } |
---|
1333 | } |
---|
1334 | |
---|
1335 | //set the height for each tile |
---|
1336 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
1337 | { |
---|
1338 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++) |
---|
1339 | { |
---|
1340 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )-> |
---|
1341 | setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) |
---|
1342 | - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) ); |
---|
1343 | } |
---|
1344 | } |
---|
1345 | } |
---|
1346 | else |
---|
1347 | { |
---|
1348 | //set the width for each tile |
---|
1349 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
1350 | { |
---|
1351 | uiCummulativeTileWidth = 0; |
---|
1352 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1(); p++) |
---|
1353 | { |
---|
1354 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->setTileWidth( pcSlice->getPPS()->getColumnWidth(p) ); |
---|
1355 | uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(p); |
---|
1356 | } |
---|
1357 | pcPic->getPicSym()->getTComTile(j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth ); |
---|
1358 | } |
---|
1359 | |
---|
1360 | //set the height for each tile |
---|
1361 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
1362 | { |
---|
1363 | uiCummulativeTileHeight = 0; |
---|
1364 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1(); p++) |
---|
1365 | { |
---|
1366 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->setTileHeight( pcSlice->getPPS()->getRowHeight(p) ); |
---|
1367 | uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(p); |
---|
1368 | } |
---|
1369 | pcPic->getPicSym()->getTComTile(p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight ); |
---|
1370 | } |
---|
1371 | } |
---|
1372 | //intialize each tile of the current picture |
---|
1373 | pcPic->getPicSym()->xInitTiles(); |
---|
1374 | |
---|
1375 | // Allocate some coders, now we know how many tiles there are. |
---|
1376 | Int iNumSubstreams = pcSlice->getPPS()->getNumSubstreams(); |
---|
1377 | |
---|
1378 | //generate the Coding Order Map and Inverse Coding Order Map |
---|
1379 | for(p=0, uiEncCUAddr=0; p<pcPic->getPicSym()->getNumberOfCUsInFrame(); p++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr)) |
---|
1380 | { |
---|
1381 | pcPic->getPicSym()->setCUOrderMap(p, uiEncCUAddr); |
---|
1382 | pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, p); |
---|
1383 | } |
---|
1384 | pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
1385 | pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
1386 | |
---|
1387 | // Allocate some coders, now we know how many tiles there are. |
---|
1388 | m_pcEncTop->createWPPCoders(iNumSubstreams); |
---|
1389 | pcSbacCoders = m_pcEncTop->getSbacCoders(); |
---|
1390 | pcSubstreamsOut = new TComOutputBitstream[iNumSubstreams]; |
---|
1391 | |
---|
1392 | UInt startCUAddrSliceIdx = 0; // used to index "m_uiStoredStartCUAddrForEncodingSlice" containing locations of slice boundaries |
---|
1393 | UInt startCUAddrSlice = 0; // used to keep track of current slice's starting CU addr. |
---|
1394 | pcSlice->setSliceCurStartCUAddr( startCUAddrSlice ); // Setting "start CU addr" for current slice |
---|
1395 | m_storedStartCUAddrForEncodingSlice.clear(); |
---|
1396 | |
---|
1397 | UInt startCUAddrSliceSegmentIdx = 0; // used to index "m_uiStoredStartCUAddrForEntropyEncodingSlice" containing locations of slice boundaries |
---|
1398 | UInt startCUAddrSliceSegment = 0; // used to keep track of current Dependent slice's starting CU addr. |
---|
1399 | pcSlice->setSliceSegmentCurStartCUAddr( startCUAddrSliceSegment ); // Setting "start CU addr" for current Dependent slice |
---|
1400 | |
---|
1401 | m_storedStartCUAddrForEncodingSliceSegment.clear(); |
---|
1402 | UInt nextCUAddr = 0; |
---|
1403 | m_storedStartCUAddrForEncodingSlice.push_back (nextCUAddr); |
---|
1404 | startCUAddrSliceIdx++; |
---|
1405 | m_storedStartCUAddrForEncodingSliceSegment.push_back(nextCUAddr); |
---|
1406 | startCUAddrSliceSegmentIdx++; |
---|
1407 | #if AVC_BASE |
---|
1408 | if( m_layerId == 0 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) |
---|
1409 | { |
---|
1410 | pcPic->getPicYuvOrg()->copyToPic( pcPic->getPicYuvRec() ); |
---|
1411 | #if AVC_SYNTAX |
---|
1412 | pcPic->readBLSyntax( m_ppcTEncTop[0]->getBLSyntaxFile(), SYNTAX_BYTES ); |
---|
1413 | #endif |
---|
1414 | return; |
---|
1415 | } |
---|
1416 | #endif |
---|
1417 | |
---|
1418 | while(nextCUAddr<uiRealEndAddress) // determine slice boundaries |
---|
1419 | { |
---|
1420 | pcSlice->setNextSlice ( false ); |
---|
1421 | pcSlice->setNextSliceSegment( false ); |
---|
1422 | assert(pcPic->getNumAllocatedSlice() == startCUAddrSliceIdx); |
---|
1423 | m_pcSliceEncoder->precompressSlice( pcPic ); |
---|
1424 | m_pcSliceEncoder->compressSlice ( pcPic ); |
---|
1425 | |
---|
1426 | Bool bNoBinBitConstraintViolated = (!pcSlice->isNextSlice() && !pcSlice->isNextSliceSegment()); |
---|
1427 | if (pcSlice->isNextSlice() || (bNoBinBitConstraintViolated && m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU)) |
---|
1428 | { |
---|
1429 | startCUAddrSlice = pcSlice->getSliceCurEndCUAddr(); |
---|
1430 | // Reconstruction slice |
---|
1431 | m_storedStartCUAddrForEncodingSlice.push_back(startCUAddrSlice); |
---|
1432 | startCUAddrSliceIdx++; |
---|
1433 | // Dependent slice |
---|
1434 | if (startCUAddrSliceSegmentIdx>0 && m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx-1] != startCUAddrSlice) |
---|
1435 | { |
---|
1436 | m_storedStartCUAddrForEncodingSliceSegment.push_back(startCUAddrSlice); |
---|
1437 | startCUAddrSliceSegmentIdx++; |
---|
1438 | } |
---|
1439 | |
---|
1440 | if (startCUAddrSlice < uiRealEndAddress) |
---|
1441 | { |
---|
1442 | pcPic->allocateNewSlice(); |
---|
1443 | pcPic->setCurrSliceIdx ( startCUAddrSliceIdx-1 ); |
---|
1444 | m_pcSliceEncoder->setSliceIdx ( startCUAddrSliceIdx-1 ); |
---|
1445 | pcSlice = pcPic->getSlice ( startCUAddrSliceIdx-1 ); |
---|
1446 | pcSlice->copySliceInfo ( pcPic->getSlice(0) ); |
---|
1447 | pcSlice->setSliceIdx ( startCUAddrSliceIdx-1 ); |
---|
1448 | pcSlice->setSliceCurStartCUAddr ( startCUAddrSlice ); |
---|
1449 | pcSlice->setSliceSegmentCurStartCUAddr ( startCUAddrSlice ); |
---|
1450 | pcSlice->setSliceBits(0); |
---|
1451 | uiNumSlices ++; |
---|
1452 | } |
---|
1453 | } |
---|
1454 | else if (pcSlice->isNextSliceSegment() || (bNoBinBitConstraintViolated && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)) |
---|
1455 | { |
---|
1456 | startCUAddrSliceSegment = pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
1457 | m_storedStartCUAddrForEncodingSliceSegment.push_back(startCUAddrSliceSegment); |
---|
1458 | startCUAddrSliceSegmentIdx++; |
---|
1459 | pcSlice->setSliceSegmentCurStartCUAddr( startCUAddrSliceSegment ); |
---|
1460 | } |
---|
1461 | else |
---|
1462 | { |
---|
1463 | startCUAddrSlice = pcSlice->getSliceCurEndCUAddr(); |
---|
1464 | startCUAddrSliceSegment = pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
1465 | } |
---|
1466 | |
---|
1467 | nextCUAddr = (startCUAddrSlice > startCUAddrSliceSegment) ? startCUAddrSlice : startCUAddrSliceSegment; |
---|
1468 | } |
---|
1469 | m_storedStartCUAddrForEncodingSlice.push_back( pcSlice->getSliceCurEndCUAddr()); |
---|
1470 | startCUAddrSliceIdx++; |
---|
1471 | m_storedStartCUAddrForEncodingSliceSegment.push_back(pcSlice->getSliceCurEndCUAddr()); |
---|
1472 | startCUAddrSliceSegmentIdx++; |
---|
1473 | |
---|
1474 | pcSlice = pcPic->getSlice(0); |
---|
1475 | |
---|
1476 | // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas |
---|
1477 | if( m_pcCfg->getSaoLcuBasedOptimization() && m_pcCfg->getSaoLcuBoundary() ) |
---|
1478 | { |
---|
1479 | m_pcSAO->resetStats(); |
---|
1480 | m_pcSAO->calcSaoStatsCu_BeforeDblk( pcPic ); |
---|
1481 | } |
---|
1482 | |
---|
1483 | //-- Loop filter |
---|
1484 | Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag(); |
---|
1485 | m_pcLoopFilter->setCfg(bLFCrossTileBoundary); |
---|
1486 | if ( m_pcCfg->getDeblockingFilterMetric() ) |
---|
1487 | { |
---|
1488 | dblMetric(pcPic, uiNumSlices); |
---|
1489 | } |
---|
1490 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
1491 | |
---|
1492 | pcSlice = pcPic->getSlice(0); |
---|
1493 | if(pcSlice->getSPS()->getUseSAO()) |
---|
1494 | { |
---|
1495 | std::vector<Bool> LFCrossSliceBoundaryFlag; |
---|
1496 | for(Int s=0; s< uiNumSlices; s++) |
---|
1497 | { |
---|
1498 | LFCrossSliceBoundaryFlag.push_back( ((uiNumSlices==1)?true:pcPic->getSlice(s)->getLFCrossSliceBoundaryFlag()) ); |
---|
1499 | } |
---|
1500 | m_storedStartCUAddrForEncodingSlice.resize(uiNumSlices+1); |
---|
1501 | pcPic->createNonDBFilterInfo(m_storedStartCUAddrForEncodingSlice, 0, &LFCrossSliceBoundaryFlag ,pcPic->getPicSym()->getNumTiles() ,bLFCrossTileBoundary); |
---|
1502 | } |
---|
1503 | |
---|
1504 | |
---|
1505 | pcSlice = pcPic->getSlice(0); |
---|
1506 | |
---|
1507 | if(pcSlice->getSPS()->getUseSAO()) |
---|
1508 | { |
---|
1509 | m_pcSAO->createPicSaoInfo(pcPic); |
---|
1510 | } |
---|
1511 | |
---|
1512 | /////////////////////////////////////////////////////////////////////////////////////////////////// File writing |
---|
1513 | // Set entropy coder |
---|
1514 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
1515 | |
---|
1516 | /* write various header sets. */ |
---|
1517 | if ( m_bSeqFirst ) |
---|
1518 | { |
---|
1519 | #if SVC_EXTENSION |
---|
1520 | #if VPS_NUH_LAYER_ID |
---|
1521 | OutputNALUnit nalu(NAL_UNIT_VPS, 0, 0 ); // The value of nuh_layer_id of VPS NAL unit shall be equal to 0. |
---|
1522 | #else |
---|
1523 | OutputNALUnit nalu(NAL_UNIT_VPS, 0, m_layerId); |
---|
1524 | #endif |
---|
1525 | #if AVC_BASE |
---|
1526 | if( ( m_layerId == 1 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) || ( m_layerId == 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) ) |
---|
1527 | #else |
---|
1528 | if( m_layerId == 0 ) |
---|
1529 | #endif |
---|
1530 | { |
---|
1531 | #else |
---|
1532 | OutputNALUnit nalu(NAL_UNIT_VPS); |
---|
1533 | #endif |
---|
1534 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1535 | m_pcEntropyCoder->encodeVPS(m_pcEncTop->getVPS()); |
---|
1536 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1537 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1538 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
1539 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
1540 | #endif |
---|
1541 | #if SVC_EXTENSION |
---|
1542 | } |
---|
1543 | #endif |
---|
1544 | |
---|
1545 | #if SVC_EXTENSION |
---|
1546 | nalu = NALUnit(NAL_UNIT_SPS, 0, m_layerId); |
---|
1547 | #if IL_SL_SIGNALLING_N0371 |
---|
1548 | pcSlice->getSPS()->setVPS( pcSlice->getVPS() ); |
---|
1549 | #endif |
---|
1550 | #else |
---|
1551 | nalu = NALUnit(NAL_UNIT_SPS); |
---|
1552 | #endif |
---|
1553 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1554 | if (m_bSeqFirst) |
---|
1555 | { |
---|
1556 | pcSlice->getSPS()->setNumLongTermRefPicSPS(m_numLongTermRefPicSPS); |
---|
1557 | for (Int k = 0; k < m_numLongTermRefPicSPS; k++) |
---|
1558 | { |
---|
1559 | pcSlice->getSPS()->setLtRefPicPocLsbSps(k, m_ltRefPicPocLsbSps[k]); |
---|
1560 | pcSlice->getSPS()->setUsedByCurrPicLtSPSFlag(k, m_ltRefPicUsedByCurrPicFlag[k]); |
---|
1561 | } |
---|
1562 | } |
---|
1563 | if( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) |
---|
1564 | { |
---|
1565 | UInt maxCU = m_pcCfg->getSliceArgument() >> ( pcSlice->getSPS()->getMaxCUDepth() << 1); |
---|
1566 | UInt numDU = ( m_pcCfg->getSliceMode() == 1 ) ? ( pcPic->getNumCUsInFrame() / maxCU ) : ( 0 ); |
---|
1567 | if( pcPic->getNumCUsInFrame() % maxCU != 0 || numDU == 0 ) |
---|
1568 | { |
---|
1569 | numDU ++; |
---|
1570 | } |
---|
1571 | pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->setNumDU( numDU ); |
---|
1572 | pcSlice->getSPS()->setHrdParameters( m_pcCfg->getFrameRate(), numDU, m_pcCfg->getTargetBitrate(), ( m_pcCfg->getIntraPeriod() > 0 ) ); |
---|
1573 | } |
---|
1574 | if( m_pcCfg->getBufferingPeriodSEIEnabled() || m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) |
---|
1575 | { |
---|
1576 | pcSlice->getSPS()->getVuiParameters()->setHrdParametersPresentFlag( true ); |
---|
1577 | } |
---|
1578 | m_pcEntropyCoder->encodeSPS(pcSlice->getSPS()); |
---|
1579 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1580 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1581 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
1582 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
1583 | #endif |
---|
1584 | |
---|
1585 | #if SVC_EXTENSION |
---|
1586 | nalu = NALUnit(NAL_UNIT_PPS, 0, m_layerId); |
---|
1587 | #else |
---|
1588 | nalu = NALUnit(NAL_UNIT_PPS); |
---|
1589 | #endif |
---|
1590 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1591 | m_pcEntropyCoder->encodePPS(pcSlice->getPPS()); |
---|
1592 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1593 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1594 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
1595 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
1596 | #endif |
---|
1597 | |
---|
1598 | xCreateLeadingSEIMessages(accessUnit, pcSlice->getSPS()); |
---|
1599 | |
---|
1600 | m_bSeqFirst = false; |
---|
1601 | } |
---|
1602 | |
---|
1603 | if (writeSOP) // write SOP description SEI (if enabled) at the beginning of GOP |
---|
1604 | { |
---|
1605 | Int SOPcurrPOC = pocCurr; |
---|
1606 | |
---|
1607 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
1608 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1609 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1610 | |
---|
1611 | SEISOPDescription SOPDescriptionSEI; |
---|
1612 | SOPDescriptionSEI.m_sopSeqParameterSetId = pcSlice->getSPS()->getSPSId(); |
---|
1613 | |
---|
1614 | UInt i = 0; |
---|
1615 | UInt prevEntryId = iGOPid; |
---|
1616 | for (j = iGOPid; j < m_iGopSize; j++) |
---|
1617 | { |
---|
1618 | Int deltaPOC = m_pcCfg->getGOPEntry(j).m_POC - m_pcCfg->getGOPEntry(prevEntryId).m_POC; |
---|
1619 | if ((SOPcurrPOC + deltaPOC) < m_pcCfg->getFramesToBeEncoded()) |
---|
1620 | { |
---|
1621 | SOPcurrPOC += deltaPOC; |
---|
1622 | SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR); |
---|
1623 | SOPDescriptionSEI.m_sopDescTemporalId[i] = m_pcCfg->getGOPEntry(j).m_temporalId; |
---|
1624 | SOPDescriptionSEI.m_sopDescStRpsIdx[i] = m_pcEncTop->getReferencePictureSetIdxForSOP(pcSlice, SOPcurrPOC, j); |
---|
1625 | SOPDescriptionSEI.m_sopDescPocDelta[i] = deltaPOC; |
---|
1626 | |
---|
1627 | prevEntryId = j; |
---|
1628 | i++; |
---|
1629 | } |
---|
1630 | } |
---|
1631 | |
---|
1632 | SOPDescriptionSEI.m_numPicsInSopMinus1 = i - 1; |
---|
1633 | |
---|
1634 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, SOPDescriptionSEI, pcSlice->getSPS()); |
---|
1635 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1636 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1637 | |
---|
1638 | writeSOP = false; |
---|
1639 | } |
---|
1640 | |
---|
1641 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
1642 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
1643 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
1644 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) |
---|
1645 | { |
---|
1646 | if( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getSubPicCpbParamsPresentFlag() ) |
---|
1647 | { |
---|
1648 | UInt numDU = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNumDU(); |
---|
1649 | pictureTimingSEI.m_numDecodingUnitsMinus1 = ( numDU - 1 ); |
---|
1650 | pictureTimingSEI.m_duCommonCpbRemovalDelayFlag = false; |
---|
1651 | |
---|
1652 | if( pictureTimingSEI.m_numNalusInDuMinus1 == NULL ) |
---|
1653 | { |
---|
1654 | pictureTimingSEI.m_numNalusInDuMinus1 = new UInt[ numDU ]; |
---|
1655 | } |
---|
1656 | if( pictureTimingSEI.m_duCpbRemovalDelayMinus1 == NULL ) |
---|
1657 | { |
---|
1658 | pictureTimingSEI.m_duCpbRemovalDelayMinus1 = new UInt[ numDU ]; |
---|
1659 | } |
---|
1660 | if( accumBitsDU == NULL ) |
---|
1661 | { |
---|
1662 | accumBitsDU = new UInt[ numDU ]; |
---|
1663 | } |
---|
1664 | if( accumNalsDU == NULL ) |
---|
1665 | { |
---|
1666 | accumNalsDU = new UInt[ numDU ]; |
---|
1667 | } |
---|
1668 | } |
---|
1669 | pictureTimingSEI.m_auCpbRemovalDelay = std::max<Int>(1, m_totalCoded - m_lastBPSEI); // Syntax element signalled as minus, hence the . |
---|
1670 | #if POC_RESET_FLAG |
---|
1671 | pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pocCurr - m_totalCoded; |
---|
1672 | #else |
---|
1673 | pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded; |
---|
1674 | #endif |
---|
1675 | Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2; |
---|
1676 | pictureTimingSEI.m_picDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay; |
---|
1677 | if( m_pcCfg->getDecodingUnitInfoSEIEnabled() ) |
---|
1678 | { |
---|
1679 | picSptDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay; |
---|
1680 | } |
---|
1681 | } |
---|
1682 | |
---|
1683 | if( ( m_pcCfg->getBufferingPeriodSEIEnabled() ) && ( pcSlice->getSliceType() == I_SLICE ) && |
---|
1684 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
1685 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
1686 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) |
---|
1687 | { |
---|
1688 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
1689 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1690 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1691 | |
---|
1692 | SEIBufferingPeriod sei_buffering_period; |
---|
1693 | |
---|
1694 | UInt uiInitialCpbRemovalDelay = (90000/2); // 0.5 sec |
---|
1695 | sei_buffering_period.m_initialCpbRemovalDelay [0][0] = uiInitialCpbRemovalDelay; |
---|
1696 | sei_buffering_period.m_initialCpbRemovalDelayOffset[0][0] = uiInitialCpbRemovalDelay; |
---|
1697 | sei_buffering_period.m_initialCpbRemovalDelay [0][1] = uiInitialCpbRemovalDelay; |
---|
1698 | sei_buffering_period.m_initialCpbRemovalDelayOffset[0][1] = uiInitialCpbRemovalDelay; |
---|
1699 | |
---|
1700 | Double dTmp = (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getNumUnitsInTick() / (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getTimeScale(); |
---|
1701 | |
---|
1702 | UInt uiTmp = (UInt)( dTmp * 90000.0 ); |
---|
1703 | uiInitialCpbRemovalDelay -= uiTmp; |
---|
1704 | uiInitialCpbRemovalDelay -= uiTmp / ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2 ); |
---|
1705 | sei_buffering_period.m_initialAltCpbRemovalDelay [0][0] = uiInitialCpbRemovalDelay; |
---|
1706 | sei_buffering_period.m_initialAltCpbRemovalDelayOffset[0][0] = uiInitialCpbRemovalDelay; |
---|
1707 | sei_buffering_period.m_initialAltCpbRemovalDelay [0][1] = uiInitialCpbRemovalDelay; |
---|
1708 | sei_buffering_period.m_initialAltCpbRemovalDelayOffset[0][1] = uiInitialCpbRemovalDelay; |
---|
1709 | |
---|
1710 | sei_buffering_period.m_rapCpbParamsPresentFlag = 0; |
---|
1711 | //for the concatenation, it can be set to one during splicing. |
---|
1712 | sei_buffering_period.m_concatenationFlag = 0; |
---|
1713 | //since the temporal layer HRD is not ready, we assumed it is fixed |
---|
1714 | sei_buffering_period.m_auCpbRemovalDelayDelta = 1; |
---|
1715 | sei_buffering_period.m_cpbDelayOffset = 0; |
---|
1716 | sei_buffering_period.m_dpbDelayOffset = 0; |
---|
1717 | |
---|
1718 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_buffering_period, pcSlice->getSPS()); |
---|
1719 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1720 | { |
---|
1721 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
1722 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU; // Insert BP SEI after APS SEI |
---|
1723 | AccessUnit::iterator it; |
---|
1724 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
1725 | { |
---|
1726 | it++; |
---|
1727 | } |
---|
1728 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
1729 | m_bufferingPeriodSEIPresentInAU = true; |
---|
1730 | } |
---|
1731 | |
---|
1732 | if (m_pcCfg->getScalableNestingSEIEnabled()) |
---|
1733 | { |
---|
1734 | OutputNALUnit naluTmp(NAL_UNIT_PREFIX_SEI); |
---|
1735 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1736 | m_pcEntropyCoder->setBitstream(&naluTmp.m_Bitstream); |
---|
1737 | scalableNestingSEI.m_nestedSEIs.clear(); |
---|
1738 | scalableNestingSEI.m_nestedSEIs.push_back(&sei_buffering_period); |
---|
1739 | m_seiWriter.writeSEImessage( naluTmp.m_Bitstream, scalableNestingSEI, pcSlice->getSPS()); |
---|
1740 | writeRBSPTrailingBits(naluTmp.m_Bitstream); |
---|
1741 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
1742 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU; // Insert BP SEI after non-nested APS, BP and PT SEIs |
---|
1743 | AccessUnit::iterator it; |
---|
1744 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
1745 | { |
---|
1746 | it++; |
---|
1747 | } |
---|
1748 | accessUnit.insert(it, new NALUnitEBSP(naluTmp)); |
---|
1749 | m_nestedBufferingPeriodSEIPresentInAU = true; |
---|
1750 | } |
---|
1751 | |
---|
1752 | m_lastBPSEI = m_totalCoded; |
---|
1753 | m_cpbRemovalDelay = 0; |
---|
1754 | } |
---|
1755 | m_cpbRemovalDelay ++; |
---|
1756 | if( ( m_pcEncTop->getRecoveryPointSEIEnabled() ) && ( pcSlice->getSliceType() == I_SLICE ) ) |
---|
1757 | { |
---|
1758 | if( m_pcEncTop->getGradualDecodingRefreshInfoEnabled() && !pcSlice->getRapPicFlag() ) |
---|
1759 | { |
---|
1760 | // Gradual decoding refresh SEI |
---|
1761 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
1762 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1763 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1764 | |
---|
1765 | SEIGradualDecodingRefreshInfo seiGradualDecodingRefreshInfo; |
---|
1766 | seiGradualDecodingRefreshInfo.m_gdrForegroundFlag = true; // Indicating all "foreground" |
---|
1767 | |
---|
1768 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, seiGradualDecodingRefreshInfo, pcSlice->getSPS() ); |
---|
1769 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1770 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1771 | } |
---|
1772 | // Recovery point SEI |
---|
1773 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
1774 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1775 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1776 | |
---|
1777 | SEIRecoveryPoint sei_recovery_point; |
---|
1778 | sei_recovery_point.m_recoveryPocCnt = 0; |
---|
1779 | #if POC_RESET_FLAG |
---|
1780 | sei_recovery_point.m_exactMatchingFlag = ( pocCurr == 0 ) ? (true) : (false); |
---|
1781 | #else |
---|
1782 | sei_recovery_point.m_exactMatchingFlag = ( pcSlice->getPOC() == 0 ) ? (true) : (false); |
---|
1783 | #endif |
---|
1784 | sei_recovery_point.m_brokenLinkFlag = false; |
---|
1785 | |
---|
1786 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_recovery_point, pcSlice->getSPS() ); |
---|
1787 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1788 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1789 | } |
---|
1790 | |
---|
1791 | /* use the main bitstream buffer for storing the marshalled picture */ |
---|
1792 | m_pcEntropyCoder->setBitstream(NULL); |
---|
1793 | |
---|
1794 | startCUAddrSliceIdx = 0; |
---|
1795 | startCUAddrSlice = 0; |
---|
1796 | |
---|
1797 | startCUAddrSliceSegmentIdx = 0; |
---|
1798 | startCUAddrSliceSegment = 0; |
---|
1799 | nextCUAddr = 0; |
---|
1800 | pcSlice = pcPic->getSlice(startCUAddrSliceIdx); |
---|
1801 | |
---|
1802 | Int processingState = (pcSlice->getSPS()->getUseSAO())?(EXECUTE_INLOOPFILTER):(ENCODE_SLICE); |
---|
1803 | Bool skippedSlice=false; |
---|
1804 | while (nextCUAddr < uiRealEndAddress) // Iterate over all slices |
---|
1805 | { |
---|
1806 | switch(processingState) |
---|
1807 | { |
---|
1808 | case ENCODE_SLICE: |
---|
1809 | { |
---|
1810 | pcSlice->setNextSlice ( false ); |
---|
1811 | pcSlice->setNextSliceSegment( false ); |
---|
1812 | if (nextCUAddr == m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx]) |
---|
1813 | { |
---|
1814 | pcSlice = pcPic->getSlice(startCUAddrSliceIdx); |
---|
1815 | if(startCUAddrSliceIdx > 0 && pcSlice->getSliceType()!= I_SLICE) |
---|
1816 | { |
---|
1817 | pcSlice->checkColRefIdx(startCUAddrSliceIdx, pcPic); |
---|
1818 | } |
---|
1819 | pcPic->setCurrSliceIdx(startCUAddrSliceIdx); |
---|
1820 | m_pcSliceEncoder->setSliceIdx(startCUAddrSliceIdx); |
---|
1821 | assert(startCUAddrSliceIdx == pcSlice->getSliceIdx()); |
---|
1822 | // Reconstruction slice |
---|
1823 | pcSlice->setSliceCurStartCUAddr( nextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
1824 | pcSlice->setSliceCurEndCUAddr ( m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx+1 ] ); |
---|
1825 | // Dependent slice |
---|
1826 | pcSlice->setSliceSegmentCurStartCUAddr( nextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
1827 | pcSlice->setSliceSegmentCurEndCUAddr ( m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx+1 ] ); |
---|
1828 | |
---|
1829 | pcSlice->setNextSlice ( true ); |
---|
1830 | |
---|
1831 | startCUAddrSliceIdx++; |
---|
1832 | startCUAddrSliceSegmentIdx++; |
---|
1833 | } |
---|
1834 | else if (nextCUAddr == m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx]) |
---|
1835 | { |
---|
1836 | // Dependent slice |
---|
1837 | pcSlice->setSliceSegmentCurStartCUAddr( nextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
1838 | pcSlice->setSliceSegmentCurEndCUAddr ( m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx+1 ] ); |
---|
1839 | |
---|
1840 | pcSlice->setNextSliceSegment( true ); |
---|
1841 | |
---|
1842 | startCUAddrSliceSegmentIdx++; |
---|
1843 | } |
---|
1844 | #if SVC_EXTENSION && M0457_COL_PICTURE_SIGNALING |
---|
1845 | pcSlice->setNumMotionPredRefLayers(m_pcEncTop->getNumMotionPredRefLayers()); |
---|
1846 | #endif |
---|
1847 | pcSlice->setRPS(pcPic->getSlice(0)->getRPS()); |
---|
1848 | pcSlice->setRPSidx(pcPic->getSlice(0)->getRPSidx()); |
---|
1849 | UInt uiDummyStartCUAddr; |
---|
1850 | UInt uiDummyBoundingCUAddr; |
---|
1851 | m_pcSliceEncoder->xDetermineStartAndBoundingCUAddr(uiDummyStartCUAddr,uiDummyBoundingCUAddr,pcPic,true); |
---|
1852 | |
---|
1853 | uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
---|
1854 | uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
---|
1855 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1856 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1857 | |
---|
1858 | #if REPN_FORMAT_IN_VPS |
---|
1859 | uiWidth = pcSlice->getPicWidthInLumaSamples(); |
---|
1860 | uiHeight = pcSlice->getPicHeightInLumaSamples(); |
---|
1861 | #else |
---|
1862 | uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
1863 | uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
1864 | #endif |
---|
1865 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
1866 | { |
---|
1867 | uiInternalAddress--; |
---|
1868 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1869 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1870 | } |
---|
1871 | uiInternalAddress++; |
---|
1872 | if(uiInternalAddress==pcPic->getNumPartInCU()) |
---|
1873 | { |
---|
1874 | uiInternalAddress = 0; |
---|
1875 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
---|
1876 | } |
---|
1877 | UInt endAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
---|
1878 | if(endAddress<=pcSlice->getSliceSegmentCurStartCUAddr()) |
---|
1879 | { |
---|
1880 | UInt boundingAddrSlice, boundingAddrSliceSegment; |
---|
1881 | boundingAddrSlice = m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx]; |
---|
1882 | boundingAddrSliceSegment = m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx]; |
---|
1883 | nextCUAddr = min(boundingAddrSlice, boundingAddrSliceSegment); |
---|
1884 | if(pcSlice->isNextSlice()) |
---|
1885 | { |
---|
1886 | skippedSlice=true; |
---|
1887 | } |
---|
1888 | continue; |
---|
1889 | } |
---|
1890 | if(skippedSlice) |
---|
1891 | { |
---|
1892 | pcSlice->setNextSlice ( true ); |
---|
1893 | pcSlice->setNextSliceSegment( false ); |
---|
1894 | } |
---|
1895 | skippedSlice=false; |
---|
1896 | pcSlice->allocSubstreamSizes( iNumSubstreams ); |
---|
1897 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
1898 | { |
---|
1899 | pcSubstreamsOut[ui].clear(); |
---|
1900 | } |
---|
1901 | |
---|
1902 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
1903 | m_pcEntropyCoder->resetEntropy (); |
---|
1904 | /* start slice NALunit */ |
---|
1905 | #if SVC_EXTENSION |
---|
1906 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer(), m_layerId ); |
---|
1907 | #else |
---|
1908 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer() ); |
---|
1909 | #endif |
---|
1910 | Bool sliceSegment = (!pcSlice->isNextSlice()); |
---|
1911 | if (!sliceSegment) |
---|
1912 | { |
---|
1913 | uiOneBitstreamPerSliceLength = 0; // start of a new slice |
---|
1914 | } |
---|
1915 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1916 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
1917 | tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1918 | #endif |
---|
1919 | |
---|
1920 | m_pcEntropyCoder->encodeSliceHeader(pcSlice); |
---|
1921 | |
---|
1922 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
1923 | actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting ); |
---|
1924 | #endif |
---|
1925 | |
---|
1926 | // is it needed? |
---|
1927 | { |
---|
1928 | if (!sliceSegment) |
---|
1929 | { |
---|
1930 | pcBitstreamRedirect->writeAlignOne(); |
---|
1931 | } |
---|
1932 | else |
---|
1933 | { |
---|
1934 | // We've not completed our slice header info yet, do the alignment later. |
---|
1935 | } |
---|
1936 | m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC ); |
---|
1937 | m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); |
---|
1938 | m_pcEntropyCoder->resetEntropy (); |
---|
1939 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ ) |
---|
1940 | { |
---|
1941 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
1942 | m_pcEntropyCoder->resetEntropy (); |
---|
1943 | } |
---|
1944 | } |
---|
1945 | |
---|
1946 | if(pcSlice->isNextSlice()) |
---|
1947 | { |
---|
1948 | // set entropy coder for writing |
---|
1949 | m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC ); |
---|
1950 | { |
---|
1951 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ ) |
---|
1952 | { |
---|
1953 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
1954 | m_pcEntropyCoder->resetEntropy (); |
---|
1955 | } |
---|
1956 | pcSbacCoders[0].load(m_pcSbacCoder); |
---|
1957 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[0], pcSlice ); //ALF is written in substream #0 with CABAC coder #0 (see ALF param encoding below) |
---|
1958 | } |
---|
1959 | m_pcEntropyCoder->resetEntropy (); |
---|
1960 | // File writing |
---|
1961 | if (!sliceSegment) |
---|
1962 | { |
---|
1963 | m_pcEntropyCoder->setBitstream(pcBitstreamRedirect); |
---|
1964 | } |
---|
1965 | else |
---|
1966 | { |
---|
1967 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1968 | } |
---|
1969 | // for now, override the TILES_DECODER setting in order to write substreams. |
---|
1970 | m_pcEntropyCoder->setBitstream ( &pcSubstreamsOut[0] ); |
---|
1971 | |
---|
1972 | } |
---|
1973 | pcSlice->setFinalized(true); |
---|
1974 | |
---|
1975 | m_pcSbacCoder->load( &pcSbacCoders[0] ); |
---|
1976 | |
---|
1977 | pcSlice->setTileOffstForMultES( uiOneBitstreamPerSliceLength ); |
---|
1978 | pcSlice->setTileLocationCount ( 0 ); |
---|
1979 | m_pcSliceEncoder->encodeSlice(pcPic, pcSubstreamsOut); |
---|
1980 | |
---|
1981 | { |
---|
1982 | // Construct the final bitstream by flushing and concatenating substreams. |
---|
1983 | // The final bitstream is either nalu.m_Bitstream or pcBitstreamRedirect; |
---|
1984 | UInt* puiSubstreamSizes = pcSlice->getSubstreamSizes(); |
---|
1985 | UInt uiTotalCodedSize = 0; // for padding calcs. |
---|
1986 | UInt uiNumSubstreamsPerTile = iNumSubstreams; |
---|
1987 | if (iNumSubstreams > 1) |
---|
1988 | { |
---|
1989 | uiNumSubstreamsPerTile /= pcPic->getPicSym()->getNumTiles(); |
---|
1990 | } |
---|
1991 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
1992 | { |
---|
1993 | // Flush all substreams -- this includes empty ones. |
---|
1994 | // Terminating bit and flush. |
---|
1995 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
1996 | m_pcEntropyCoder->setBitstream ( &pcSubstreamsOut[ui] ); |
---|
1997 | m_pcEntropyCoder->encodeTerminatingBit( 1 ); |
---|
1998 | m_pcEntropyCoder->encodeSliceFinish(); |
---|
1999 | |
---|
2000 | pcSubstreamsOut[ui].writeByteAlignment(); // Byte-alignment in slice_data() at end of sub-stream |
---|
2001 | // Byte alignment is necessary between tiles when tiles are independent. |
---|
2002 | uiTotalCodedSize += pcSubstreamsOut[ui].getNumberOfWrittenBits(); |
---|
2003 | |
---|
2004 | Bool bNextSubstreamInNewTile = ((ui+1) < iNumSubstreams)&& ((ui+1)%uiNumSubstreamsPerTile == 0); |
---|
2005 | if (bNextSubstreamInNewTile) |
---|
2006 | { |
---|
2007 | pcSlice->setTileLocation(ui/uiNumSubstreamsPerTile, pcSlice->getTileOffstForMultES()+(uiTotalCodedSize>>3)); |
---|
2008 | } |
---|
2009 | if (ui+1 < pcSlice->getPPS()->getNumSubstreams()) |
---|
2010 | { |
---|
2011 | puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits() + (pcSubstreamsOut[ui].countStartCodeEmulations()<<3); |
---|
2012 | } |
---|
2013 | } |
---|
2014 | |
---|
2015 | // Complete the slice header info. |
---|
2016 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
2017 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
2018 | m_pcEntropyCoder->encodeTilesWPPEntryPoint( pcSlice ); |
---|
2019 | |
---|
2020 | // Substreams... |
---|
2021 | TComOutputBitstream *pcOut = pcBitstreamRedirect; |
---|
2022 | Int offs = 0; |
---|
2023 | Int nss = pcSlice->getPPS()->getNumSubstreams(); |
---|
2024 | if (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) |
---|
2025 | { |
---|
2026 | // 1st line present for WPP. |
---|
2027 | offs = pcSlice->getSliceSegmentCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU()/pcSlice->getPic()->getFrameWidthInCU(); |
---|
2028 | nss = pcSlice->getNumEntryPointOffsets()+1; |
---|
2029 | } |
---|
2030 | for ( UInt ui = 0 ; ui < nss; ui++ ) |
---|
2031 | { |
---|
2032 | pcOut->addSubstream(&pcSubstreamsOut[ui+offs]); |
---|
2033 | } |
---|
2034 | } |
---|
2035 | |
---|
2036 | UInt boundingAddrSlice, boundingAddrSliceSegment; |
---|
2037 | boundingAddrSlice = m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx]; |
---|
2038 | boundingAddrSliceSegment = m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx]; |
---|
2039 | nextCUAddr = min(boundingAddrSlice, boundingAddrSliceSegment); |
---|
2040 | // If current NALU is the first NALU of slice (containing slice header) and more NALUs exist (due to multiple dependent slices) then buffer it. |
---|
2041 | // 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. |
---|
2042 | Bool bNALUAlignedWrittenToList = false; // used to ensure current NALU is not written more than once to the NALU list. |
---|
2043 | xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect); |
---|
2044 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
2045 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
2046 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
2047 | #endif |
---|
2048 | bNALUAlignedWrittenToList = true; |
---|
2049 | uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits(); // length of bitstream after byte-alignment |
---|
2050 | |
---|
2051 | if (!bNALUAlignedWrittenToList) |
---|
2052 | { |
---|
2053 | { |
---|
2054 | nalu.m_Bitstream.writeAlignZero(); |
---|
2055 | } |
---|
2056 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
2057 | uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits() + 24; // length of bitstream after byte-alignment + 3 byte startcode 0x000001 |
---|
2058 | } |
---|
2059 | |
---|
2060 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
2061 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
2062 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
2063 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) && |
---|
2064 | ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getSubPicCpbParamsPresentFlag() ) ) |
---|
2065 | { |
---|
2066 | UInt numNalus = 0; |
---|
2067 | UInt numRBSPBytes = 0; |
---|
2068 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
2069 | { |
---|
2070 | UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size()); |
---|
2071 | if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) |
---|
2072 | { |
---|
2073 | numRBSPBytes += numRBSPBytes_nal; |
---|
2074 | numNalus ++; |
---|
2075 | } |
---|
2076 | } |
---|
2077 | accumBitsDU[ pcSlice->getSliceIdx() ] = ( numRBSPBytes << 3 ); |
---|
2078 | accumNalsDU[ pcSlice->getSliceIdx() ] = numNalus; // SEI not counted for bit count; hence shouldn't be counted for # of NALUs - only for consistency |
---|
2079 | } |
---|
2080 | processingState = ENCODE_SLICE; |
---|
2081 | } |
---|
2082 | break; |
---|
2083 | case EXECUTE_INLOOPFILTER: |
---|
2084 | { |
---|
2085 | // set entropy coder for RD |
---|
2086 | m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); |
---|
2087 | if ( pcSlice->getSPS()->getUseSAO() ) |
---|
2088 | { |
---|
2089 | m_pcEntropyCoder->resetEntropy(); |
---|
2090 | m_pcEntropyCoder->setBitstream( m_pcBitCounter ); |
---|
2091 | m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcEncTop->getRDGoOnSbacCoder()); |
---|
2092 | SAOParam& cSaoParam = *pcSlice->getPic()->getPicSym()->getSaoParam(); |
---|
2093 | |
---|
2094 | #if SAO_CHROMA_LAMBDA |
---|
2095 | #if SAO_ENCODING_CHOICE |
---|
2096 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), pcPic->getSlice(0)->getDepth()); |
---|
2097 | #else |
---|
2098 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma()); |
---|
2099 | #endif |
---|
2100 | #else |
---|
2101 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambda()); |
---|
2102 | #endif |
---|
2103 | m_pcSAO->endSaoEnc(); |
---|
2104 | m_pcSAO->PCMLFDisableProcess(pcPic); |
---|
2105 | } |
---|
2106 | #if SAO_RDO |
---|
2107 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
2108 | #endif |
---|
2109 | processingState = ENCODE_SLICE; |
---|
2110 | |
---|
2111 | for(Int s=0; s< uiNumSlices; s++) |
---|
2112 | { |
---|
2113 | if (pcSlice->getSPS()->getUseSAO()) |
---|
2114 | { |
---|
2115 | pcPic->getSlice(s)->setSaoEnabledFlag((pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[0]==1)?true:false); |
---|
2116 | } |
---|
2117 | } |
---|
2118 | } |
---|
2119 | break; |
---|
2120 | default: |
---|
2121 | { |
---|
2122 | printf("Not a supported encoding state\n"); |
---|
2123 | assert(0); |
---|
2124 | exit(-1); |
---|
2125 | } |
---|
2126 | } |
---|
2127 | } // end iteration over slices |
---|
2128 | |
---|
2129 | if(pcSlice->getSPS()->getUseSAO()) |
---|
2130 | { |
---|
2131 | if(pcSlice->getSPS()->getUseSAO()) |
---|
2132 | { |
---|
2133 | m_pcSAO->destroyPicSaoInfo(); |
---|
2134 | } |
---|
2135 | pcPic->destroyNonDBFilterInfo(); |
---|
2136 | } |
---|
2137 | |
---|
2138 | pcPic->compressMotion(); |
---|
2139 | |
---|
2140 | //-- For time output for each slice |
---|
2141 | Double dEncTime = (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
2142 | |
---|
2143 | const Char* digestStr = NULL; |
---|
2144 | if (m_pcCfg->getDecodedPictureHashSEIEnabled()) |
---|
2145 | { |
---|
2146 | /* calculate MD5sum for entire reconstructed picture */ |
---|
2147 | SEIDecodedPictureHash sei_recon_picture_digest; |
---|
2148 | if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 1) |
---|
2149 | { |
---|
2150 | sei_recon_picture_digest.method = SEIDecodedPictureHash::MD5; |
---|
2151 | calcMD5(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
2152 | digestStr = digestToString(sei_recon_picture_digest.digest, 16); |
---|
2153 | } |
---|
2154 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 2) |
---|
2155 | { |
---|
2156 | sei_recon_picture_digest.method = SEIDecodedPictureHash::CRC; |
---|
2157 | calcCRC(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
2158 | digestStr = digestToString(sei_recon_picture_digest.digest, 2); |
---|
2159 | } |
---|
2160 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 3) |
---|
2161 | { |
---|
2162 | sei_recon_picture_digest.method = SEIDecodedPictureHash::CHECKSUM; |
---|
2163 | calcChecksum(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
2164 | digestStr = digestToString(sei_recon_picture_digest.digest, 4); |
---|
2165 | } |
---|
2166 | #if SVC_EXTENSION |
---|
2167 | OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer(), m_layerId); |
---|
2168 | #else |
---|
2169 | OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer()); |
---|
2170 | #endif |
---|
2171 | |
---|
2172 | /* write the SEI messages */ |
---|
2173 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
2174 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei_recon_picture_digest, pcSlice->getSPS()); |
---|
2175 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
2176 | |
---|
2177 | accessUnit.insert(accessUnit.end(), new NALUnitEBSP(nalu)); |
---|
2178 | } |
---|
2179 | if (m_pcCfg->getTemporalLevel0IndexSEIEnabled()) |
---|
2180 | { |
---|
2181 | SEITemporalLevel0Index sei_temporal_level0_index; |
---|
2182 | if (pcSlice->getRapPicFlag()) |
---|
2183 | { |
---|
2184 | m_tl0Idx = 0; |
---|
2185 | m_rapIdx = (m_rapIdx + 1) & 0xFF; |
---|
2186 | } |
---|
2187 | else |
---|
2188 | { |
---|
2189 | m_tl0Idx = (m_tl0Idx + (pcSlice->getTLayer() ? 0 : 1)) & 0xFF; |
---|
2190 | } |
---|
2191 | sei_temporal_level0_index.tl0Idx = m_tl0Idx; |
---|
2192 | sei_temporal_level0_index.rapIdx = m_rapIdx; |
---|
2193 | |
---|
2194 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
2195 | |
---|
2196 | /* write the SEI messages */ |
---|
2197 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
2198 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei_temporal_level0_index, pcSlice->getSPS()); |
---|
2199 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
2200 | |
---|
2201 | /* insert the SEI message NALUnit before any Slice NALUnits */ |
---|
2202 | AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice)); |
---|
2203 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
2204 | } |
---|
2205 | |
---|
2206 | xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime ); |
---|
2207 | |
---|
2208 | if (digestStr) |
---|
2209 | { |
---|
2210 | if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 1) |
---|
2211 | { |
---|
2212 | printf(" [MD5:%s]", digestStr); |
---|
2213 | } |
---|
2214 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 2) |
---|
2215 | { |
---|
2216 | printf(" [CRC:%s]", digestStr); |
---|
2217 | } |
---|
2218 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 3) |
---|
2219 | { |
---|
2220 | printf(" [Checksum:%s]", digestStr); |
---|
2221 | } |
---|
2222 | } |
---|
2223 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
2224 | if ( m_pcCfg->getUseRateCtrl() ) |
---|
2225 | { |
---|
2226 | #if !M0036_RC_IMPROVEMENT |
---|
2227 | Double effectivePercentage = m_pcRateCtrl->getRCPic()->getEffectivePercentage(); |
---|
2228 | #endif |
---|
2229 | Double avgQP = m_pcRateCtrl->getRCPic()->calAverageQP(); |
---|
2230 | Double avgLambda = m_pcRateCtrl->getRCPic()->calAverageLambda(); |
---|
2231 | if ( avgLambda < 0.0 ) |
---|
2232 | { |
---|
2233 | avgLambda = lambda; |
---|
2234 | } |
---|
2235 | #if M0036_RC_IMPROVEMENT |
---|
2236 | #if RATE_CONTROL_INTRA |
---|
2237 | m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, pcSlice->getSliceType()); |
---|
2238 | #else |
---|
2239 | m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda ); |
---|
2240 | #endif |
---|
2241 | #else |
---|
2242 | m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, effectivePercentage ); |
---|
2243 | #endif |
---|
2244 | m_pcRateCtrl->getRCPic()->addToPictureLsit( m_pcRateCtrl->getPicList() ); |
---|
2245 | |
---|
2246 | m_pcRateCtrl->getRCSeq()->updateAfterPic( actualTotalBits ); |
---|
2247 | if ( pcSlice->getSliceType() != I_SLICE ) |
---|
2248 | { |
---|
2249 | m_pcRateCtrl->getRCGOP()->updateAfterPicture( actualTotalBits ); |
---|
2250 | } |
---|
2251 | else // for intra picture, the estimated bits are used to update the current status in the GOP |
---|
2252 | { |
---|
2253 | m_pcRateCtrl->getRCGOP()->updateAfterPicture( estimatedBits ); |
---|
2254 | } |
---|
2255 | } |
---|
2256 | #else |
---|
2257 | if(m_pcCfg->getUseRateCtrl()) |
---|
2258 | { |
---|
2259 | UInt frameBits = m_vRVM_RP[m_vRVM_RP.size()-1]; |
---|
2260 | m_pcRateCtrl->updataRCFrameStatus((Int)frameBits, pcSlice->getSliceType()); |
---|
2261 | } |
---|
2262 | #endif |
---|
2263 | |
---|
2264 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
2265 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
2266 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
2267 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) |
---|
2268 | { |
---|
2269 | TComVUI *vui = pcSlice->getSPS()->getVuiParameters(); |
---|
2270 | TComHRD *hrd = vui->getHrdParameters(); |
---|
2271 | |
---|
2272 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
2273 | { |
---|
2274 | Int i; |
---|
2275 | UInt64 ui64Tmp; |
---|
2276 | UInt uiPrev = 0; |
---|
2277 | UInt numDU = ( pictureTimingSEI.m_numDecodingUnitsMinus1 + 1 ); |
---|
2278 | UInt *pCRD = &pictureTimingSEI.m_duCpbRemovalDelayMinus1[0]; |
---|
2279 | UInt maxDiff = ( hrd->getTickDivisorMinus2() + 2 ) - 1; |
---|
2280 | |
---|
2281 | for( i = 0; i < numDU; i ++ ) |
---|
2282 | { |
---|
2283 | pictureTimingSEI.m_numNalusInDuMinus1[ i ] = ( i == 0 ) ? ( accumNalsDU[ i ] - 1 ) : ( accumNalsDU[ i ] - accumNalsDU[ i - 1] - 1 ); |
---|
2284 | } |
---|
2285 | |
---|
2286 | if( numDU == 1 ) |
---|
2287 | { |
---|
2288 | pCRD[ 0 ] = 0; /* don't care */ |
---|
2289 | } |
---|
2290 | else |
---|
2291 | { |
---|
2292 | pCRD[ numDU - 1 ] = 0;/* by definition */ |
---|
2293 | UInt tmp = 0; |
---|
2294 | UInt accum = 0; |
---|
2295 | |
---|
2296 | for( i = ( numDU - 2 ); i >= 0; i -- ) |
---|
2297 | { |
---|
2298 | ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ] - accumBitsDU[ i ] ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
2299 | if( (UInt)ui64Tmp > maxDiff ) |
---|
2300 | { |
---|
2301 | tmp ++; |
---|
2302 | } |
---|
2303 | } |
---|
2304 | uiPrev = 0; |
---|
2305 | |
---|
2306 | UInt flag = 0; |
---|
2307 | for( i = ( numDU - 2 ); i >= 0; i -- ) |
---|
2308 | { |
---|
2309 | flag = 0; |
---|
2310 | ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ] - accumBitsDU[ i ] ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
2311 | |
---|
2312 | if( (UInt)ui64Tmp > maxDiff ) |
---|
2313 | { |
---|
2314 | if(uiPrev >= maxDiff - tmp) |
---|
2315 | { |
---|
2316 | ui64Tmp = uiPrev + 1; |
---|
2317 | flag = 1; |
---|
2318 | } |
---|
2319 | else ui64Tmp = maxDiff - tmp + 1; |
---|
2320 | } |
---|
2321 | pCRD[ i ] = (UInt)ui64Tmp - uiPrev - 1; |
---|
2322 | if( (Int)pCRD[ i ] < 0 ) |
---|
2323 | { |
---|
2324 | pCRD[ i ] = 0; |
---|
2325 | } |
---|
2326 | else if (tmp > 0 && flag == 1) |
---|
2327 | { |
---|
2328 | tmp --; |
---|
2329 | } |
---|
2330 | accum += pCRD[ i ] + 1; |
---|
2331 | uiPrev = accum; |
---|
2332 | } |
---|
2333 | } |
---|
2334 | } |
---|
2335 | if( m_pcCfg->getPictureTimingSEIEnabled() ) |
---|
2336 | { |
---|
2337 | { |
---|
2338 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer()); |
---|
2339 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
2340 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS()); |
---|
2341 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
2342 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
2343 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU |
---|
2344 | + m_bufferingPeriodSEIPresentInAU; // Insert PT SEI after APS and BP SEI |
---|
2345 | AccessUnit::iterator it; |
---|
2346 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
2347 | { |
---|
2348 | it++; |
---|
2349 | } |
---|
2350 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
2351 | m_pictureTimingSEIPresentInAU = true; |
---|
2352 | } |
---|
2353 | if ( m_pcCfg->getScalableNestingSEIEnabled() ) // put picture timing SEI into scalable nesting SEI |
---|
2354 | { |
---|
2355 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer()); |
---|
2356 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
2357 | scalableNestingSEI.m_nestedSEIs.clear(); |
---|
2358 | scalableNestingSEI.m_nestedSEIs.push_back(&pictureTimingSEI); |
---|
2359 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, scalableNestingSEI, pcSlice->getSPS()); |
---|
2360 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
2361 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
2362 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU |
---|
2363 | + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU + m_nestedBufferingPeriodSEIPresentInAU; // Insert PT SEI after APS and BP SEI |
---|
2364 | AccessUnit::iterator it; |
---|
2365 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
2366 | { |
---|
2367 | it++; |
---|
2368 | } |
---|
2369 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
2370 | m_nestedPictureTimingSEIPresentInAU = true; |
---|
2371 | } |
---|
2372 | } |
---|
2373 | if( m_pcCfg->getDecodingUnitInfoSEIEnabled() && hrd->getSubPicCpbParamsPresentFlag() ) |
---|
2374 | { |
---|
2375 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
2376 | for( Int i = 0; i < ( pictureTimingSEI.m_numDecodingUnitsMinus1 + 1 ); i ++ ) |
---|
2377 | { |
---|
2378 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer()); |
---|
2379 | |
---|
2380 | SEIDecodingUnitInfo tempSEI; |
---|
2381 | tempSEI.m_decodingUnitIdx = i; |
---|
2382 | tempSEI.m_duSptCpbRemovalDelay = pictureTimingSEI.m_duCpbRemovalDelayMinus1[i] + 1; |
---|
2383 | tempSEI.m_dpbOutputDuDelayPresentFlag = false; |
---|
2384 | tempSEI.m_picSptDpbOutputDuDelay = picSptDpbOutputDuDelay; |
---|
2385 | |
---|
2386 | AccessUnit::iterator it; |
---|
2387 | // Insert the first one in the right location, before the first slice |
---|
2388 | if(i == 0) |
---|
2389 | { |
---|
2390 | // Insert before the first slice. |
---|
2391 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, tempSEI, pcSlice->getSPS()); |
---|
2392 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
2393 | |
---|
2394 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
2395 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU |
---|
2396 | + m_bufferingPeriodSEIPresentInAU |
---|
2397 | + m_pictureTimingSEIPresentInAU; // Insert DU info SEI after APS, BP and PT SEI |
---|
2398 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
2399 | { |
---|
2400 | it++; |
---|
2401 | } |
---|
2402 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
2403 | } |
---|
2404 | else |
---|
2405 | { |
---|
2406 | Int ctr; |
---|
2407 | // For the second decoding unit onwards we know how many NALUs are present |
---|
2408 | for (ctr = 0, it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
2409 | { |
---|
2410 | if(ctr == accumNalsDU[ i - 1 ]) |
---|
2411 | { |
---|
2412 | // Insert before the first slice. |
---|
2413 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, tempSEI, pcSlice->getSPS()); |
---|
2414 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
2415 | |
---|
2416 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
2417 | break; |
---|
2418 | } |
---|
2419 | if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) |
---|
2420 | { |
---|
2421 | ctr++; |
---|
2422 | } |
---|
2423 | } |
---|
2424 | } |
---|
2425 | } |
---|
2426 | } |
---|
2427 | } |
---|
2428 | xResetNonNestedSEIPresentFlags(); |
---|
2429 | xResetNestedSEIPresentFlags(); |
---|
2430 | pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut); |
---|
2431 | |
---|
2432 | #if M0040_ADAPTIVE_RESOLUTION_CHANGE |
---|
2433 | pcPicYuvRecOut->setReconstructed(true); |
---|
2434 | #endif |
---|
2435 | |
---|
2436 | pcPic->setReconMark ( true ); |
---|
2437 | m_bFirst = false; |
---|
2438 | m_iNumPicCoded++; |
---|
2439 | m_totalCoded ++; |
---|
2440 | /* logging: insert a newline at end of picture period */ |
---|
2441 | printf("\n"); |
---|
2442 | fflush(stdout); |
---|
2443 | |
---|
2444 | delete[] pcSubstreamsOut; |
---|
2445 | } |
---|
2446 | #if !RATE_CONTROL_LAMBDA_DOMAIN |
---|
2447 | if(m_pcCfg->getUseRateCtrl()) |
---|
2448 | { |
---|
2449 | m_pcRateCtrl->updateRCGOPStatus(); |
---|
2450 | } |
---|
2451 | #endif |
---|
2452 | delete pcBitstreamRedirect; |
---|
2453 | |
---|
2454 | if( accumBitsDU != NULL) delete accumBitsDU; |
---|
2455 | if( accumNalsDU != NULL) delete accumNalsDU; |
---|
2456 | |
---|
2457 | #if SVC_EXTENSION |
---|
2458 | assert ( m_iNumPicCoded <= 1 ); |
---|
2459 | #else |
---|
2460 | assert ( m_iNumPicCoded == iNumPicRcvd ); |
---|
2461 | #endif |
---|
2462 | } |
---|
2463 | |
---|
2464 | #if !SVC_EXTENSION |
---|
2465 | Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded) |
---|
2466 | { |
---|
2467 | assert (uiNumAllPicCoded == m_gcAnalyzeAll.getNumPic()); |
---|
2468 | |
---|
2469 | |
---|
2470 | //--CFG_KDY |
---|
2471 | m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
2472 | m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
2473 | m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
2474 | m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
2475 | |
---|
2476 | //-- all |
---|
2477 | printf( "\n\nSUMMARY --------------------------------------------------------\n" ); |
---|
2478 | m_gcAnalyzeAll.printOut('a'); |
---|
2479 | |
---|
2480 | printf( "\n\nI Slices--------------------------------------------------------\n" ); |
---|
2481 | m_gcAnalyzeI.printOut('i'); |
---|
2482 | |
---|
2483 | printf( "\n\nP Slices--------------------------------------------------------\n" ); |
---|
2484 | m_gcAnalyzeP.printOut('p'); |
---|
2485 | |
---|
2486 | printf( "\n\nB Slices--------------------------------------------------------\n" ); |
---|
2487 | m_gcAnalyzeB.printOut('b'); |
---|
2488 | |
---|
2489 | #if _SUMMARY_OUT_ |
---|
2490 | m_gcAnalyzeAll.printSummaryOut(); |
---|
2491 | #endif |
---|
2492 | #if _SUMMARY_PIC_ |
---|
2493 | m_gcAnalyzeI.printSummary('I'); |
---|
2494 | m_gcAnalyzeP.printSummary('P'); |
---|
2495 | m_gcAnalyzeB.printSummary('B'); |
---|
2496 | #endif |
---|
2497 | |
---|
2498 | printf("\nRVM: %.3lf\n" , xCalculateRVM()); |
---|
2499 | } |
---|
2500 | #endif |
---|
2501 | |
---|
2502 | Void TEncGOP::preLoopFilterPicAll( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits ) |
---|
2503 | { |
---|
2504 | TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx()); |
---|
2505 | Bool bCalcDist = false; |
---|
2506 | m_pcLoopFilter->setCfg(m_pcCfg->getLFCrossTileBoundaryFlag()); |
---|
2507 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
2508 | |
---|
2509 | m_pcEntropyCoder->setEntropyCoder ( m_pcEncTop->getRDGoOnSbacCoder(), pcSlice ); |
---|
2510 | m_pcEntropyCoder->resetEntropy (); |
---|
2511 | m_pcEntropyCoder->setBitstream ( m_pcBitCounter ); |
---|
2512 | pcSlice = pcPic->getSlice(0); |
---|
2513 | if(pcSlice->getSPS()->getUseSAO()) |
---|
2514 | { |
---|
2515 | std::vector<Bool> LFCrossSliceBoundaryFlag(1, true); |
---|
2516 | std::vector<Int> sliceStartAddress; |
---|
2517 | sliceStartAddress.push_back(0); |
---|
2518 | sliceStartAddress.push_back(pcPic->getNumCUsInFrame()* pcPic->getNumPartInCU()); |
---|
2519 | pcPic->createNonDBFilterInfo(sliceStartAddress, 0, &LFCrossSliceBoundaryFlag); |
---|
2520 | } |
---|
2521 | |
---|
2522 | if( pcSlice->getSPS()->getUseSAO()) |
---|
2523 | { |
---|
2524 | pcPic->destroyNonDBFilterInfo(); |
---|
2525 | } |
---|
2526 | |
---|
2527 | m_pcEntropyCoder->resetEntropy (); |
---|
2528 | ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2529 | |
---|
2530 | if (!bCalcDist) |
---|
2531 | ruiDist = xFindDistortionFrame(pcPic->getPicYuvOrg(), pcPic->getPicYuvRec()); |
---|
2532 | } |
---|
2533 | |
---|
2534 | // ==================================================================================================================== |
---|
2535 | // Protected member functions |
---|
2536 | // ==================================================================================================================== |
---|
2537 | |
---|
2538 | Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut ) |
---|
2539 | { |
---|
2540 | assert( iNumPicRcvd > 0 ); |
---|
2541 | // Exception for the first frame |
---|
2542 | if ( iPOCLast == 0 ) |
---|
2543 | { |
---|
2544 | m_iGopSize = 1; |
---|
2545 | } |
---|
2546 | else |
---|
2547 | m_iGopSize = m_pcCfg->getGOPSize(); |
---|
2548 | |
---|
2549 | assert (m_iGopSize > 0); |
---|
2550 | |
---|
2551 | return; |
---|
2552 | } |
---|
2553 | |
---|
2554 | Void TEncGOP::xGetBuffer( TComList<TComPic*>& rcListPic, |
---|
2555 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
2556 | Int iNumPicRcvd, |
---|
2557 | Int iTimeOffset, |
---|
2558 | TComPic*& rpcPic, |
---|
2559 | TComPicYuv*& rpcPicYuvRecOut, |
---|
2560 | Int pocCurr ) |
---|
2561 | { |
---|
2562 | Int i; |
---|
2563 | // Rec. output |
---|
2564 | TComList<TComPicYuv*>::iterator iterPicYuvRec = rcListPicYuvRecOut.end(); |
---|
2565 | for ( i = 0; i < iNumPicRcvd - iTimeOffset + 1; i++ ) |
---|
2566 | { |
---|
2567 | iterPicYuvRec--; |
---|
2568 | } |
---|
2569 | |
---|
2570 | rpcPicYuvRecOut = *(iterPicYuvRec); |
---|
2571 | |
---|
2572 | // Current pic. |
---|
2573 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
2574 | while (iterPic != rcListPic.end()) |
---|
2575 | { |
---|
2576 | rpcPic = *(iterPic); |
---|
2577 | rpcPic->setCurrSliceIdx(0); |
---|
2578 | if (rpcPic->getPOC() == pocCurr) |
---|
2579 | { |
---|
2580 | break; |
---|
2581 | } |
---|
2582 | iterPic++; |
---|
2583 | } |
---|
2584 | |
---|
2585 | assert( rpcPic != NULL ); |
---|
2586 | assert( rpcPic->getPOC() == pocCurr ); |
---|
2587 | |
---|
2588 | return; |
---|
2589 | } |
---|
2590 | |
---|
2591 | UInt64 TEncGOP::xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1) |
---|
2592 | { |
---|
2593 | Int x, y; |
---|
2594 | Pel* pSrc0 = pcPic0 ->getLumaAddr(); |
---|
2595 | Pel* pSrc1 = pcPic1 ->getLumaAddr(); |
---|
2596 | UInt uiShift = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8); |
---|
2597 | Int iTemp; |
---|
2598 | |
---|
2599 | Int iStride = pcPic0->getStride(); |
---|
2600 | Int iWidth = pcPic0->getWidth(); |
---|
2601 | Int iHeight = pcPic0->getHeight(); |
---|
2602 | |
---|
2603 | UInt64 uiTotalDiff = 0; |
---|
2604 | |
---|
2605 | for( y = 0; y < iHeight; y++ ) |
---|
2606 | { |
---|
2607 | for( x = 0; x < iWidth; x++ ) |
---|
2608 | { |
---|
2609 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
2610 | } |
---|
2611 | pSrc0 += iStride; |
---|
2612 | pSrc1 += iStride; |
---|
2613 | } |
---|
2614 | |
---|
2615 | uiShift = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthC-8); |
---|
2616 | iHeight >>= 1; |
---|
2617 | iWidth >>= 1; |
---|
2618 | iStride >>= 1; |
---|
2619 | |
---|
2620 | pSrc0 = pcPic0->getCbAddr(); |
---|
2621 | pSrc1 = pcPic1->getCbAddr(); |
---|
2622 | |
---|
2623 | for( y = 0; y < iHeight; y++ ) |
---|
2624 | { |
---|
2625 | for( x = 0; x < iWidth; x++ ) |
---|
2626 | { |
---|
2627 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
2628 | } |
---|
2629 | pSrc0 += iStride; |
---|
2630 | pSrc1 += iStride; |
---|
2631 | } |
---|
2632 | |
---|
2633 | pSrc0 = pcPic0->getCrAddr(); |
---|
2634 | pSrc1 = pcPic1->getCrAddr(); |
---|
2635 | |
---|
2636 | for( y = 0; y < iHeight; y++ ) |
---|
2637 | { |
---|
2638 | for( x = 0; x < iWidth; x++ ) |
---|
2639 | { |
---|
2640 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
2641 | } |
---|
2642 | pSrc0 += iStride; |
---|
2643 | pSrc1 += iStride; |
---|
2644 | } |
---|
2645 | |
---|
2646 | return uiTotalDiff; |
---|
2647 | } |
---|
2648 | |
---|
2649 | #if VERBOSE_RATE |
---|
2650 | static const Char* nalUnitTypeToString(NalUnitType type) |
---|
2651 | { |
---|
2652 | switch (type) |
---|
2653 | { |
---|
2654 | case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R"; |
---|
2655 | case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N"; |
---|
2656 | case NAL_UNIT_CODED_SLICE_TSA_R: return "TSA_R"; |
---|
2657 | case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N"; |
---|
2658 | case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R"; |
---|
2659 | case NAL_UNIT_CODED_SLICE_STSA_N: return "STSA_N"; |
---|
2660 | case NAL_UNIT_CODED_SLICE_BLA_W_LP: return "BLA_W_LP"; |
---|
2661 | case NAL_UNIT_CODED_SLICE_BLA_W_RADL: return "BLA_W_RADL"; |
---|
2662 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: return "BLA_N_LP"; |
---|
2663 | case NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL"; |
---|
2664 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: return "IDR_N_LP"; |
---|
2665 | case NAL_UNIT_CODED_SLICE_CRA: return "CRA"; |
---|
2666 | case NAL_UNIT_CODED_SLICE_RADL_R: return "RADL_R"; |
---|
2667 | case NAL_UNIT_CODED_SLICE_RASL_R: return "RASL_R"; |
---|
2668 | case NAL_UNIT_VPS: return "VPS"; |
---|
2669 | case NAL_UNIT_SPS: return "SPS"; |
---|
2670 | case NAL_UNIT_PPS: return "PPS"; |
---|
2671 | case NAL_UNIT_ACCESS_UNIT_DELIMITER: return "AUD"; |
---|
2672 | case NAL_UNIT_EOS: return "EOS"; |
---|
2673 | case NAL_UNIT_EOB: return "EOB"; |
---|
2674 | case NAL_UNIT_FILLER_DATA: return "FILLER"; |
---|
2675 | case NAL_UNIT_PREFIX_SEI: return "SEI"; |
---|
2676 | case NAL_UNIT_SUFFIX_SEI: return "SEI"; |
---|
2677 | default: return "UNK"; |
---|
2678 | } |
---|
2679 | } |
---|
2680 | #endif |
---|
2681 | |
---|
2682 | Void TEncGOP::xCalculateAddPSNR( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit& accessUnit, Double dEncTime ) |
---|
2683 | { |
---|
2684 | Int x, y; |
---|
2685 | UInt64 uiSSDY = 0; |
---|
2686 | UInt64 uiSSDU = 0; |
---|
2687 | UInt64 uiSSDV = 0; |
---|
2688 | |
---|
2689 | Double dYPSNR = 0.0; |
---|
2690 | Double dUPSNR = 0.0; |
---|
2691 | Double dVPSNR = 0.0; |
---|
2692 | |
---|
2693 | //===== calculate PSNR ===== |
---|
2694 | Pel* pOrg = pcPic ->getPicYuvOrg()->getLumaAddr(); |
---|
2695 | Pel* pRec = pcPicD->getLumaAddr(); |
---|
2696 | Int iStride = pcPicD->getStride(); |
---|
2697 | |
---|
2698 | Int iWidth; |
---|
2699 | Int iHeight; |
---|
2700 | |
---|
2701 | iWidth = pcPicD->getWidth () - m_pcEncTop->getPad(0); |
---|
2702 | iHeight = pcPicD->getHeight() - m_pcEncTop->getPad(1); |
---|
2703 | |
---|
2704 | Int iSize = iWidth*iHeight; |
---|
2705 | |
---|
2706 | for( y = 0; y < iHeight; y++ ) |
---|
2707 | { |
---|
2708 | for( x = 0; x < iWidth; x++ ) |
---|
2709 | { |
---|
2710 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
2711 | uiSSDY += iDiff * iDiff; |
---|
2712 | } |
---|
2713 | pOrg += iStride; |
---|
2714 | pRec += iStride; |
---|
2715 | } |
---|
2716 | |
---|
2717 | iHeight >>= 1; |
---|
2718 | iWidth >>= 1; |
---|
2719 | iStride >>= 1; |
---|
2720 | pOrg = pcPic ->getPicYuvOrg()->getCbAddr(); |
---|
2721 | pRec = pcPicD->getCbAddr(); |
---|
2722 | |
---|
2723 | for( y = 0; y < iHeight; y++ ) |
---|
2724 | { |
---|
2725 | for( x = 0; x < iWidth; x++ ) |
---|
2726 | { |
---|
2727 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
2728 | uiSSDU += iDiff * iDiff; |
---|
2729 | } |
---|
2730 | pOrg += iStride; |
---|
2731 | pRec += iStride; |
---|
2732 | } |
---|
2733 | |
---|
2734 | pOrg = pcPic ->getPicYuvOrg()->getCrAddr(); |
---|
2735 | pRec = pcPicD->getCrAddr(); |
---|
2736 | |
---|
2737 | for( y = 0; y < iHeight; y++ ) |
---|
2738 | { |
---|
2739 | for( x = 0; x < iWidth; x++ ) |
---|
2740 | { |
---|
2741 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
2742 | uiSSDV += iDiff * iDiff; |
---|
2743 | } |
---|
2744 | pOrg += iStride; |
---|
2745 | pRec += iStride; |
---|
2746 | } |
---|
2747 | |
---|
2748 | Int maxvalY = 255 << (g_bitDepthY-8); |
---|
2749 | Int maxvalC = 255 << (g_bitDepthC-8); |
---|
2750 | Double fRefValueY = (Double) maxvalY * maxvalY * iSize; |
---|
2751 | Double fRefValueC = (Double) maxvalC * maxvalC * iSize / 4.0; |
---|
2752 | dYPSNR = ( uiSSDY ? 10.0 * log10( fRefValueY / (Double)uiSSDY ) : 99.99 ); |
---|
2753 | dUPSNR = ( uiSSDU ? 10.0 * log10( fRefValueC / (Double)uiSSDU ) : 99.99 ); |
---|
2754 | dVPSNR = ( uiSSDV ? 10.0 * log10( fRefValueC / (Double)uiSSDV ) : 99.99 ); |
---|
2755 | |
---|
2756 | /* calculate the size of the access unit, excluding: |
---|
2757 | * - any AnnexB contributions (start_code_prefix, zero_byte, etc.,) |
---|
2758 | * - SEI NAL units |
---|
2759 | */ |
---|
2760 | UInt numRBSPBytes = 0; |
---|
2761 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
2762 | { |
---|
2763 | UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size()); |
---|
2764 | #if VERBOSE_RATE |
---|
2765 | printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString((*it)->m_nalUnitType), numRBSPBytes_nal); |
---|
2766 | #endif |
---|
2767 | if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) |
---|
2768 | { |
---|
2769 | numRBSPBytes += numRBSPBytes_nal; |
---|
2770 | } |
---|
2771 | } |
---|
2772 | |
---|
2773 | UInt uibits = numRBSPBytes * 8; |
---|
2774 | m_vRVM_RP.push_back( uibits ); |
---|
2775 | |
---|
2776 | //===== add PSNR ===== |
---|
2777 | #if SVC_EXTENSION |
---|
2778 | m_gcAnalyzeAll[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2779 | TComSlice* pcSlice = pcPic->getSlice(0); |
---|
2780 | if (pcSlice->isIntra()) |
---|
2781 | { |
---|
2782 | m_gcAnalyzeI[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2783 | } |
---|
2784 | if (pcSlice->isInterP()) |
---|
2785 | { |
---|
2786 | m_gcAnalyzeP[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2787 | } |
---|
2788 | if (pcSlice->isInterB()) |
---|
2789 | { |
---|
2790 | m_gcAnalyzeB[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2791 | } |
---|
2792 | #else |
---|
2793 | m_gcAnalyzeAll.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2794 | TComSlice* pcSlice = pcPic->getSlice(0); |
---|
2795 | if (pcSlice->isIntra()) |
---|
2796 | { |
---|
2797 | m_gcAnalyzeI.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2798 | } |
---|
2799 | if (pcSlice->isInterP()) |
---|
2800 | { |
---|
2801 | m_gcAnalyzeP.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2802 | } |
---|
2803 | if (pcSlice->isInterB()) |
---|
2804 | { |
---|
2805 | m_gcAnalyzeB.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2806 | } |
---|
2807 | #endif |
---|
2808 | |
---|
2809 | Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B'); |
---|
2810 | if (!pcSlice->isReferenced()) c += 32; |
---|
2811 | |
---|
2812 | #if SVC_EXTENSION |
---|
2813 | #if ADAPTIVE_QP_SELECTION |
---|
2814 | printf("POC %4d LId: %1d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits", |
---|
2815 | pcSlice->getPOC(), |
---|
2816 | pcSlice->getLayerId(), |
---|
2817 | pcSlice->getTLayer(), |
---|
2818 | c, |
---|
2819 | pcSlice->getSliceQpBase(), |
---|
2820 | pcSlice->getSliceQp(), |
---|
2821 | uibits ); |
---|
2822 | #else |
---|
2823 | printf("POC %4d LId: %1d TId: %1d ( %c-SLICE, QP %d ) %10d bits", |
---|
2824 | pcSlice->getPOC()-pcSlice->getLastIDR(), |
---|
2825 | pcSlice->getLayerId(), |
---|
2826 | pcSlice->getTLayer(), |
---|
2827 | c, |
---|
2828 | pcSlice->getSliceQp(), |
---|
2829 | uibits ); |
---|
2830 | #endif |
---|
2831 | #else |
---|
2832 | #if ADAPTIVE_QP_SELECTION |
---|
2833 | printf("POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits", |
---|
2834 | pcSlice->getPOC(), |
---|
2835 | pcSlice->getTLayer(), |
---|
2836 | c, |
---|
2837 | pcSlice->getSliceQpBase(), |
---|
2838 | pcSlice->getSliceQp(), |
---|
2839 | uibits ); |
---|
2840 | #else |
---|
2841 | printf("POC %4d TId: %1d ( %c-SLICE, QP %d ) %10d bits", |
---|
2842 | pcSlice->getPOC()-pcSlice->getLastIDR(), |
---|
2843 | pcSlice->getTLayer(), |
---|
2844 | c, |
---|
2845 | pcSlice->getSliceQp(), |
---|
2846 | uibits ); |
---|
2847 | #endif |
---|
2848 | #endif |
---|
2849 | |
---|
2850 | printf(" [Y %6.4lf dB U %6.4lf dB V %6.4lf dB]", dYPSNR, dUPSNR, dVPSNR ); |
---|
2851 | printf(" [ET %5.0f ]", dEncTime ); |
---|
2852 | |
---|
2853 | for (Int iRefList = 0; iRefList < 2; iRefList++) |
---|
2854 | { |
---|
2855 | printf(" [L%d ", iRefList); |
---|
2856 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++) |
---|
2857 | { |
---|
2858 | #if SVC_EXTENSION |
---|
2859 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
2860 | if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR(m_layerId) ) |
---|
2861 | { |
---|
2862 | printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR(), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() ); |
---|
2863 | } |
---|
2864 | else |
---|
2865 | { |
---|
2866 | printf ("%d", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR()); |
---|
2867 | } |
---|
2868 | #endif |
---|
2869 | if( pcSlice->getEnableTMVPFlag() && iRefList == 1 - pcSlice->getColFromL0Flag() && iRefIndex == pcSlice->getColRefIdx() ) |
---|
2870 | { |
---|
2871 | printf( "c" ); |
---|
2872 | } |
---|
2873 | |
---|
2874 | printf( " " ); |
---|
2875 | #else |
---|
2876 | printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR()); |
---|
2877 | #endif |
---|
2878 | } |
---|
2879 | printf("]"); |
---|
2880 | } |
---|
2881 | } |
---|
2882 | |
---|
2883 | /** Function for deciding the nal_unit_type. |
---|
2884 | * \param pocCurr POC of the current picture |
---|
2885 | * \returns the nal unit type of the picture |
---|
2886 | * This function checks the configuration and returns the appropriate nal_unit_type for the picture. |
---|
2887 | */ |
---|
2888 | NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR) |
---|
2889 | { |
---|
2890 | if (pocCurr == 0) |
---|
2891 | { |
---|
2892 | return NAL_UNIT_CODED_SLICE_IDR_W_RADL; |
---|
2893 | } |
---|
2894 | if (pocCurr % m_pcCfg->getIntraPeriod() == 0) |
---|
2895 | { |
---|
2896 | if (m_pcCfg->getDecodingRefreshType() == 1) |
---|
2897 | { |
---|
2898 | return NAL_UNIT_CODED_SLICE_CRA; |
---|
2899 | } |
---|
2900 | else if (m_pcCfg->getDecodingRefreshType() == 2) |
---|
2901 | { |
---|
2902 | return NAL_UNIT_CODED_SLICE_IDR_W_RADL; |
---|
2903 | } |
---|
2904 | } |
---|
2905 | if(m_pocCRA>0) |
---|
2906 | { |
---|
2907 | if(pocCurr<m_pocCRA) |
---|
2908 | { |
---|
2909 | // All leading pictures are being marked as TFD pictures here since current encoder uses all |
---|
2910 | // reference pictures while encoding leading pictures. An encoder can ensure that a leading |
---|
2911 | // picture can be still decodable when random accessing to a CRA/CRANT/BLA/BLANT picture by |
---|
2912 | // controlling the reference pictures used for encoding that leading picture. Such a leading |
---|
2913 | // picture need not be marked as a TFD picture. |
---|
2914 | return NAL_UNIT_CODED_SLICE_RASL_R; |
---|
2915 | } |
---|
2916 | } |
---|
2917 | if (lastIDR>0) |
---|
2918 | { |
---|
2919 | if (pocCurr < lastIDR) |
---|
2920 | { |
---|
2921 | return NAL_UNIT_CODED_SLICE_RADL_R; |
---|
2922 | } |
---|
2923 | } |
---|
2924 | return NAL_UNIT_CODED_SLICE_TRAIL_R; |
---|
2925 | } |
---|
2926 | |
---|
2927 | Double TEncGOP::xCalculateRVM() |
---|
2928 | { |
---|
2929 | Double dRVM = 0; |
---|
2930 | |
---|
2931 | if( m_pcCfg->getGOPSize() == 1 && m_pcCfg->getIntraPeriod() != 1 && m_pcCfg->getFramesToBeEncoded() > RVM_VCEGAM10_M * 2 ) |
---|
2932 | { |
---|
2933 | // calculate RVM only for lowdelay configurations |
---|
2934 | std::vector<Double> vRL , vB; |
---|
2935 | size_t N = m_vRVM_RP.size(); |
---|
2936 | vRL.resize( N ); |
---|
2937 | vB.resize( N ); |
---|
2938 | |
---|
2939 | Int i; |
---|
2940 | Double dRavg = 0 , dBavg = 0; |
---|
2941 | vB[RVM_VCEGAM10_M] = 0; |
---|
2942 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
2943 | { |
---|
2944 | vRL[i] = 0; |
---|
2945 | for( Int j = i - RVM_VCEGAM10_M ; j <= i + RVM_VCEGAM10_M - 1 ; j++ ) |
---|
2946 | vRL[i] += m_vRVM_RP[j]; |
---|
2947 | vRL[i] /= ( 2 * RVM_VCEGAM10_M ); |
---|
2948 | vB[i] = vB[i-1] + m_vRVM_RP[i] - vRL[i]; |
---|
2949 | dRavg += m_vRVM_RP[i]; |
---|
2950 | dBavg += vB[i]; |
---|
2951 | } |
---|
2952 | |
---|
2953 | dRavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
2954 | dBavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
2955 | |
---|
2956 | Double dSigamB = 0; |
---|
2957 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
2958 | { |
---|
2959 | Double tmp = vB[i] - dBavg; |
---|
2960 | dSigamB += tmp * tmp; |
---|
2961 | } |
---|
2962 | dSigamB = sqrt( dSigamB / ( N - 2 * RVM_VCEGAM10_M ) ); |
---|
2963 | |
---|
2964 | Double f = sqrt( 12.0 * ( RVM_VCEGAM10_M - 1 ) / ( RVM_VCEGAM10_M + 1 ) ); |
---|
2965 | |
---|
2966 | dRVM = dSigamB / dRavg * f; |
---|
2967 | } |
---|
2968 | |
---|
2969 | return( dRVM ); |
---|
2970 | } |
---|
2971 | |
---|
2972 | /** Attaches the input bitstream to the stream in the output NAL unit |
---|
2973 | Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call. |
---|
2974 | * \param codedSliceData contains the coded slice data (bitstream) to be concatenated to rNalu |
---|
2975 | * \param rNalu target NAL unit |
---|
2976 | */ |
---|
2977 | Void TEncGOP::xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& codedSliceData) |
---|
2978 | { |
---|
2979 | // Byte-align |
---|
2980 | rNalu.m_Bitstream.writeByteAlignment(); // Slice header byte-alignment |
---|
2981 | |
---|
2982 | // Perform bitstream concatenation |
---|
2983 | if (codedSliceData->getNumberOfWrittenBits() > 0) |
---|
2984 | { |
---|
2985 | rNalu.m_Bitstream.addSubstream(codedSliceData); |
---|
2986 | } |
---|
2987 | |
---|
2988 | m_pcEntropyCoder->setBitstream(&rNalu.m_Bitstream); |
---|
2989 | |
---|
2990 | codedSliceData->clear(); |
---|
2991 | } |
---|
2992 | |
---|
2993 | // Function will arrange the long-term pictures in the decreasing order of poc_lsb_lt, |
---|
2994 | // and among the pictures with the same lsb, it arranges them in increasing delta_poc_msb_cycle_lt value |
---|
2995 | Void TEncGOP::arrangeLongtermPicturesInRPS(TComSlice *pcSlice, TComList<TComPic*>& rcListPic) |
---|
2996 | { |
---|
2997 | TComReferencePictureSet *rps = pcSlice->getRPS(); |
---|
2998 | if(!rps->getNumberOfLongtermPictures()) |
---|
2999 | { |
---|
3000 | return; |
---|
3001 | } |
---|
3002 | |
---|
3003 | // Arrange long-term reference pictures in the correct order of LSB and MSB, |
---|
3004 | // and assign values for pocLSBLT and MSB present flag |
---|
3005 | Int longtermPicsPoc[MAX_NUM_REF_PICS], longtermPicsLSB[MAX_NUM_REF_PICS], indices[MAX_NUM_REF_PICS]; |
---|
3006 | Int longtermPicsMSB[MAX_NUM_REF_PICS]; |
---|
3007 | Bool mSBPresentFlag[MAX_NUM_REF_PICS]; |
---|
3008 | ::memset(longtermPicsPoc, 0, sizeof(longtermPicsPoc)); // Store POC values of LTRP |
---|
3009 | ::memset(longtermPicsLSB, 0, sizeof(longtermPicsLSB)); // Store POC LSB values of LTRP |
---|
3010 | ::memset(longtermPicsMSB, 0, sizeof(longtermPicsMSB)); // Store POC LSB values of LTRP |
---|
3011 | ::memset(indices , 0, sizeof(indices)); // Indices to aid in tracking sorted LTRPs |
---|
3012 | ::memset(mSBPresentFlag , 0, sizeof(mSBPresentFlag)); // Indicate if MSB needs to be present |
---|
3013 | |
---|
3014 | // Get the long-term reference pictures |
---|
3015 | Int offset = rps->getNumberOfNegativePictures() + rps->getNumberOfPositivePictures(); |
---|
3016 | Int i, ctr = 0; |
---|
3017 | Int maxPicOrderCntLSB = 1 << pcSlice->getSPS()->getBitsForPOC(); |
---|
3018 | for(i = rps->getNumberOfPictures() - 1; i >= offset; i--, ctr++) |
---|
3019 | { |
---|
3020 | longtermPicsPoc[ctr] = rps->getPOC(i); // LTRP POC |
---|
3021 | longtermPicsLSB[ctr] = getLSB(longtermPicsPoc[ctr], maxPicOrderCntLSB); // LTRP POC LSB |
---|
3022 | indices[ctr] = i; |
---|
3023 | longtermPicsMSB[ctr] = longtermPicsPoc[ctr] - longtermPicsLSB[ctr]; |
---|
3024 | } |
---|
3025 | Int numLongPics = rps->getNumberOfLongtermPictures(); |
---|
3026 | assert(ctr == numLongPics); |
---|
3027 | |
---|
3028 | // Arrange pictures in decreasing order of MSB; |
---|
3029 | for(i = 0; i < numLongPics; i++) |
---|
3030 | { |
---|
3031 | for(Int j = 0; j < numLongPics - 1; j++) |
---|
3032 | { |
---|
3033 | if(longtermPicsMSB[j] < longtermPicsMSB[j+1]) |
---|
3034 | { |
---|
3035 | std::swap(longtermPicsPoc[j], longtermPicsPoc[j+1]); |
---|
3036 | std::swap(longtermPicsLSB[j], longtermPicsLSB[j+1]); |
---|
3037 | std::swap(longtermPicsMSB[j], longtermPicsMSB[j+1]); |
---|
3038 | std::swap(indices[j] , indices[j+1] ); |
---|
3039 | } |
---|
3040 | } |
---|
3041 | } |
---|
3042 | |
---|
3043 | for(i = 0; i < numLongPics; i++) |
---|
3044 | { |
---|
3045 | // Check if MSB present flag should be enabled. |
---|
3046 | // Check if the buffer contains any pictures that have the same LSB. |
---|
3047 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
3048 | TComPic* pcPic; |
---|
3049 | while ( iterPic != rcListPic.end() ) |
---|
3050 | { |
---|
3051 | pcPic = *iterPic; |
---|
3052 | if( (getLSB(pcPic->getPOC(), maxPicOrderCntLSB) == longtermPicsLSB[i]) && // Same LSB |
---|
3053 | (pcPic->getSlice(0)->isReferenced()) && // Reference picture |
---|
3054 | (pcPic->getPOC() != longtermPicsPoc[i]) ) // Not the LTRP itself |
---|
3055 | { |
---|
3056 | mSBPresentFlag[i] = true; |
---|
3057 | break; |
---|
3058 | } |
---|
3059 | iterPic++; |
---|
3060 | } |
---|
3061 | } |
---|
3062 | |
---|
3063 | // tempArray for usedByCurr flag |
---|
3064 | Bool tempArray[MAX_NUM_REF_PICS]; ::memset(tempArray, 0, sizeof(tempArray)); |
---|
3065 | for(i = 0; i < numLongPics; i++) |
---|
3066 | { |
---|
3067 | tempArray[i] = rps->getUsed(indices[i]); |
---|
3068 | } |
---|
3069 | // Now write the final values; |
---|
3070 | ctr = 0; |
---|
3071 | Int currMSB = 0, currLSB = 0; |
---|
3072 | // currPicPoc = currMSB + currLSB |
---|
3073 | currLSB = getLSB(pcSlice->getPOC(), maxPicOrderCntLSB); |
---|
3074 | currMSB = pcSlice->getPOC() - currLSB; |
---|
3075 | |
---|
3076 | for(i = rps->getNumberOfPictures() - 1; i >= offset; i--, ctr++) |
---|
3077 | { |
---|
3078 | rps->setPOC (i, longtermPicsPoc[ctr]); |
---|
3079 | rps->setDeltaPOC (i, - pcSlice->getPOC() + longtermPicsPoc[ctr]); |
---|
3080 | rps->setUsed (i, tempArray[ctr]); |
---|
3081 | rps->setPocLSBLT (i, longtermPicsLSB[ctr]); |
---|
3082 | rps->setDeltaPocMSBCycleLT (i, (currMSB - (longtermPicsPoc[ctr] - longtermPicsLSB[ctr])) / maxPicOrderCntLSB); |
---|
3083 | rps->setDeltaPocMSBPresentFlag(i, mSBPresentFlag[ctr]); |
---|
3084 | |
---|
3085 | assert(rps->getDeltaPocMSBCycleLT(i) >= 0); // Non-negative value |
---|
3086 | } |
---|
3087 | for(i = rps->getNumberOfPictures() - 1, ctr = 1; i >= offset; i--, ctr++) |
---|
3088 | { |
---|
3089 | for(Int j = rps->getNumberOfPictures() - 1 - ctr; j >= offset; j--) |
---|
3090 | { |
---|
3091 | // Here at the encoder we know that we have set the full POC value for the LTRPs, hence we |
---|
3092 | // don't have to check the MSB present flag values for this constraint. |
---|
3093 | assert( rps->getPOC(i) != rps->getPOC(j) ); // If assert fails, LTRP entry repeated in RPS!!! |
---|
3094 | } |
---|
3095 | } |
---|
3096 | } |
---|
3097 | |
---|
3098 | /** Function for finding the position to insert the first of APS and non-nested BP, PT, DU info SEI messages. |
---|
3099 | * \param accessUnit Access Unit of the current picture |
---|
3100 | * This function finds the position to insert the first of APS and non-nested BP, PT, DU info SEI messages. |
---|
3101 | */ |
---|
3102 | Int TEncGOP::xGetFirstSeiLocation(AccessUnit &accessUnit) |
---|
3103 | { |
---|
3104 | // Find the location of the first SEI message |
---|
3105 | AccessUnit::iterator it; |
---|
3106 | Int seiStartPos = 0; |
---|
3107 | for(it = accessUnit.begin(); it != accessUnit.end(); it++, seiStartPos++) |
---|
3108 | { |
---|
3109 | if ((*it)->isSei() || (*it)->isVcl()) |
---|
3110 | { |
---|
3111 | break; |
---|
3112 | } |
---|
3113 | } |
---|
3114 | // assert(it != accessUnit.end()); // Triggers with some legit configurations |
---|
3115 | return seiStartPos; |
---|
3116 | } |
---|
3117 | |
---|
3118 | Void TEncGOP::dblMetric( TComPic* pcPic, UInt uiNumSlices ) |
---|
3119 | { |
---|
3120 | TComPicYuv* pcPicYuvRec = pcPic->getPicYuvRec(); |
---|
3121 | Pel* Rec = pcPicYuvRec->getLumaAddr( 0 ); |
---|
3122 | Pel* tempRec = Rec; |
---|
3123 | Int stride = pcPicYuvRec->getStride(); |
---|
3124 | UInt log2maxTB = pcPic->getSlice(0)->getSPS()->getQuadtreeTULog2MaxSize(); |
---|
3125 | UInt maxTBsize = (1<<log2maxTB); |
---|
3126 | const UInt minBlockArtSize = 8; |
---|
3127 | const UInt picWidth = pcPicYuvRec->getWidth(); |
---|
3128 | const UInt picHeight = pcPicYuvRec->getHeight(); |
---|
3129 | const UInt noCol = (picWidth>>log2maxTB); |
---|
3130 | const UInt noRows = (picHeight>>log2maxTB); |
---|
3131 | assert(noCol > 1); |
---|
3132 | assert(noRows > 1); |
---|
3133 | UInt64 *colSAD = (UInt64*)malloc(noCol*sizeof(UInt64)); |
---|
3134 | UInt64 *rowSAD = (UInt64*)malloc(noRows*sizeof(UInt64)); |
---|
3135 | UInt colIdx = 0; |
---|
3136 | UInt rowIdx = 0; |
---|
3137 | Pel p0, p1, p2, q0, q1, q2; |
---|
3138 | |
---|
3139 | Int qp = pcPic->getSlice(0)->getSliceQp(); |
---|
3140 | Int bitdepthScale = 1 << (g_bitDepthY-8); |
---|
3141 | Int beta = TComLoopFilter::getBeta( qp ) * bitdepthScale; |
---|
3142 | const Int thr2 = (beta>>2); |
---|
3143 | const Int thr1 = 2*bitdepthScale; |
---|
3144 | UInt a = 0; |
---|
3145 | |
---|
3146 | memset(colSAD, 0, noCol*sizeof(UInt64)); |
---|
3147 | memset(rowSAD, 0, noRows*sizeof(UInt64)); |
---|
3148 | |
---|
3149 | if (maxTBsize > minBlockArtSize) |
---|
3150 | { |
---|
3151 | // Analyze vertical artifact edges |
---|
3152 | for(Int c = maxTBsize; c < picWidth; c += maxTBsize) |
---|
3153 | { |
---|
3154 | for(Int r = 0; r < picHeight; r++) |
---|
3155 | { |
---|
3156 | p2 = Rec[c-3]; |
---|
3157 | p1 = Rec[c-2]; |
---|
3158 | p0 = Rec[c-1]; |
---|
3159 | q0 = Rec[c]; |
---|
3160 | q1 = Rec[c+1]; |
---|
3161 | q2 = Rec[c+2]; |
---|
3162 | a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1); |
---|
3163 | if ( thr1 < a && a < thr2) |
---|
3164 | { |
---|
3165 | colSAD[colIdx] += abs(p0 - q0); |
---|
3166 | } |
---|
3167 | Rec += stride; |
---|
3168 | } |
---|
3169 | colIdx++; |
---|
3170 | Rec = tempRec; |
---|
3171 | } |
---|
3172 | |
---|
3173 | // Analyze horizontal artifact edges |
---|
3174 | for(Int r = maxTBsize; r < picHeight; r += maxTBsize) |
---|
3175 | { |
---|
3176 | for(Int c = 0; c < picWidth; c++) |
---|
3177 | { |
---|
3178 | p2 = Rec[c + (r-3)*stride]; |
---|
3179 | p1 = Rec[c + (r-2)*stride]; |
---|
3180 | p0 = Rec[c + (r-1)*stride]; |
---|
3181 | q0 = Rec[c + r*stride]; |
---|
3182 | q1 = Rec[c + (r+1)*stride]; |
---|
3183 | q2 = Rec[c + (r+2)*stride]; |
---|
3184 | a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1); |
---|
3185 | if (thr1 < a && a < thr2) |
---|
3186 | { |
---|
3187 | rowSAD[rowIdx] += abs(p0 - q0); |
---|
3188 | } |
---|
3189 | } |
---|
3190 | rowIdx++; |
---|
3191 | } |
---|
3192 | } |
---|
3193 | |
---|
3194 | UInt64 colSADsum = 0; |
---|
3195 | UInt64 rowSADsum = 0; |
---|
3196 | for(Int c = 0; c < noCol-1; c++) |
---|
3197 | { |
---|
3198 | colSADsum += colSAD[c]; |
---|
3199 | } |
---|
3200 | for(Int r = 0; r < noRows-1; r++) |
---|
3201 | { |
---|
3202 | rowSADsum += rowSAD[r]; |
---|
3203 | } |
---|
3204 | |
---|
3205 | colSADsum <<= 10; |
---|
3206 | rowSADsum <<= 10; |
---|
3207 | colSADsum /= (noCol-1); |
---|
3208 | colSADsum /= picHeight; |
---|
3209 | rowSADsum /= (noRows-1); |
---|
3210 | rowSADsum /= picWidth; |
---|
3211 | |
---|
3212 | UInt64 avgSAD = ((colSADsum + rowSADsum)>>1); |
---|
3213 | avgSAD >>= (g_bitDepthY-8); |
---|
3214 | |
---|
3215 | if ( avgSAD > 2048 ) |
---|
3216 | { |
---|
3217 | avgSAD >>= 9; |
---|
3218 | Int offset = Clip3(2,6,(Int)avgSAD); |
---|
3219 | for (Int i=0; i<uiNumSlices; i++) |
---|
3220 | { |
---|
3221 | pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true); |
---|
3222 | pcPic->getSlice(i)->setDeblockingFilterDisable(false); |
---|
3223 | pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( offset ); |
---|
3224 | pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( offset ); |
---|
3225 | } |
---|
3226 | } |
---|
3227 | else |
---|
3228 | { |
---|
3229 | for (Int i=0; i<uiNumSlices; i++) |
---|
3230 | { |
---|
3231 | pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(false); |
---|
3232 | pcPic->getSlice(i)->setDeblockingFilterDisable( pcPic->getSlice(i)->getPPS()->getPicDisableDeblockingFilterFlag() ); |
---|
3233 | pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterBetaOffsetDiv2() ); |
---|
3234 | pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterTcOffsetDiv2() ); |
---|
3235 | } |
---|
3236 | } |
---|
3237 | |
---|
3238 | free(colSAD); |
---|
3239 | free(rowSAD); |
---|
3240 | } |
---|
3241 | |
---|
3242 | #if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING |
---|
3243 | TComPic* TEncGOP::getMotionPredIlp(TComSlice* pcSlice) |
---|
3244 | { |
---|
3245 | TComPic* ilpPic = NULL; |
---|
3246 | Int activeMotionPredReflayerIdx = 0; |
---|
3247 | |
---|
3248 | for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
---|
3249 | { |
---|
3250 | UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i); |
---|
3251 | if( m_pcEncTop->getMotionPredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) ) ) |
---|
3252 | { |
---|
3253 | if (activeMotionPredReflayerIdx == pcSlice->getColRefLayerIdx()) |
---|
3254 | { |
---|
3255 | ilpPic = m_pcEncTop->getIlpList()[refLayerIdc]; |
---|
3256 | break; |
---|
3257 | } |
---|
3258 | else |
---|
3259 | { |
---|
3260 | activeMotionPredReflayerIdx++; |
---|
3261 | } |
---|
3262 | } |
---|
3263 | } |
---|
3264 | |
---|
3265 | assert(ilpPic != NULL); |
---|
3266 | |
---|
3267 | return ilpPic; |
---|
3268 | } |
---|
3269 | #endif |
---|
3270 | |
---|
3271 | //! \} |
---|