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