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