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