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