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