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