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