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-2015, 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 TDecTop.cpp |
---|
35 | \brief decoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "NALread.h" |
---|
39 | #include "TDecTop.h" |
---|
40 | |
---|
41 | #if SVC_EXTENSION |
---|
42 | UInt TDecTop::m_prevPOC = MAX_UINT; |
---|
43 | UInt TDecTop::m_uiPrevLayerId = MAX_UINT; |
---|
44 | Bool TDecTop::m_bFirstSliceInSequence = true; |
---|
45 | Bool TDecTop::m_checkPocRestrictionsForCurrAu = false; |
---|
46 | Int TDecTop::m_pocResetIdcOrCurrAu = -1; |
---|
47 | Bool TDecTop::m_baseLayerIdrFlag = false; |
---|
48 | Bool TDecTop::m_baseLayerPicPresentFlag = false; |
---|
49 | Bool TDecTop::m_baseLayerIrapFlag = false; |
---|
50 | Bool TDecTop::m_nonBaseIdrPresentFlag = false; |
---|
51 | Int TDecTop::m_nonBaseIdrType = -1; |
---|
52 | Bool TDecTop::m_picNonIdrWithRadlPresentFlag = false; |
---|
53 | Bool TDecTop::m_picNonIdrNoLpPresentFlag = false; |
---|
54 | Int TDecTop::m_crossLayerPocResetPeriodId = -1; |
---|
55 | Int TDecTop::m_crossLayerPocResetIdc = -1; |
---|
56 | std::vector<UInt> TDecTop::m_targetDecLayerIdList; // list of layers to be decoded according to the OLS index |
---|
57 | #endif |
---|
58 | |
---|
59 | //! \ingroup TLibDecoder |
---|
60 | //! \{ |
---|
61 | |
---|
62 | TDecTop::TDecTop() |
---|
63 | : m_iMaxRefPicNum(0) |
---|
64 | , m_associatedIRAPType(NAL_UNIT_INVALID) |
---|
65 | , m_pocCRA(0) |
---|
66 | , m_pocRandomAccess(MAX_INT) |
---|
67 | , m_cListPic() |
---|
68 | , m_parameterSetManager() |
---|
69 | , m_apcSlicePilot(NULL) |
---|
70 | , m_SEIs() |
---|
71 | , m_cPrediction() |
---|
72 | , m_cTrQuant() |
---|
73 | , m_cGopDecoder() |
---|
74 | , m_cSliceDecoder() |
---|
75 | , m_cCuDecoder() |
---|
76 | , m_cEntropyDecoder() |
---|
77 | , m_cCavlcDecoder() |
---|
78 | , m_cSbacDecoder() |
---|
79 | , m_cBinCABAC() |
---|
80 | , m_seiReader() |
---|
81 | , m_cLoopFilter() |
---|
82 | , m_cSAO() |
---|
83 | , m_pcPic(NULL) |
---|
84 | #if !SVC_EXTENSION |
---|
85 | , m_prevPOC(MAX_INT) |
---|
86 | #endif |
---|
87 | , m_prevTid0POC(0) |
---|
88 | , m_bFirstSliceInPicture(true) |
---|
89 | #if !SVC_EXTENSION |
---|
90 | , m_bFirstSliceInSequence(true) |
---|
91 | #endif |
---|
92 | , m_prevSliceSkipped(false) |
---|
93 | , m_skippedPOC(0) |
---|
94 | , m_bFirstSliceInBitstream(true) |
---|
95 | , m_lastPOCNoOutputPriorPics(-1) |
---|
96 | , m_isNoOutputPriorPics(false) |
---|
97 | , m_craNoRaslOutputFlag(false) |
---|
98 | #if O0043_BEST_EFFORT_DECODING |
---|
99 | , m_forceDecodeBitDepth(8) |
---|
100 | #endif |
---|
101 | , m_pDecodedSEIOutputStream(NULL) |
---|
102 | , m_warningMessageSkipPicture(false) |
---|
103 | , m_prefixSEINALUs() |
---|
104 | { |
---|
105 | #if ENC_DEC_TRACE |
---|
106 | if (g_hTrace == NULL) |
---|
107 | { |
---|
108 | g_hTrace = fopen( "TraceDec.txt", "wb" ); |
---|
109 | } |
---|
110 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
111 | g_nSymbolCounter = 0; |
---|
112 | #endif |
---|
113 | |
---|
114 | #if SVC_EXTENSION |
---|
115 | m_layerId = 0; |
---|
116 | m_smallestLayerId = 0; |
---|
117 | #if AVC_BASE |
---|
118 | m_pBLReconFile = NULL; |
---|
119 | #endif |
---|
120 | memset(m_cIlpPic, 0, sizeof(m_cIlpPic)); |
---|
121 | m_isLastNALWasEos = false; |
---|
122 | m_lastPicHasEos = false; |
---|
123 | #if NO_CLRAS_OUTPUT_FLAG |
---|
124 | m_noClrasOutputFlag = false; |
---|
125 | m_layerInitializedFlag = false; |
---|
126 | m_firstPicInLayerDecodedFlag = false; |
---|
127 | #endif |
---|
128 | m_parseIdc = -1; |
---|
129 | m_lastPocPeriodId = -1; |
---|
130 | m_prevPicOrderCnt = 0; |
---|
131 | #if CGS_3D_ASYMLUT |
---|
132 | m_pColorMappedPic = NULL; |
---|
133 | #endif |
---|
134 | |
---|
135 | resetPocRestrictionCheckParameters(); |
---|
136 | m_pocResettingFlag = false; |
---|
137 | m_pocDecrementedInDPBFlag = false; |
---|
138 | #if CONFORMANCE_BITSTREAM_MODE |
---|
139 | m_confModeFlag = false; |
---|
140 | #endif |
---|
141 | m_isOutputLayerFlag = false; |
---|
142 | #endif //SVC_EXTENSION |
---|
143 | } |
---|
144 | |
---|
145 | TDecTop::~TDecTop() |
---|
146 | { |
---|
147 | #if ENC_DEC_TRACE |
---|
148 | if (g_hTrace != stdout) |
---|
149 | { |
---|
150 | fclose( g_hTrace ); |
---|
151 | } |
---|
152 | #endif |
---|
153 | while (!m_prefixSEINALUs.empty()) |
---|
154 | { |
---|
155 | delete m_prefixSEINALUs.front(); |
---|
156 | m_prefixSEINALUs.pop_front(); |
---|
157 | } |
---|
158 | #if CGS_3D_ASYMLUT |
---|
159 | if(m_pColorMappedPic) |
---|
160 | { |
---|
161 | m_pColorMappedPic->destroy(); |
---|
162 | delete m_pColorMappedPic; |
---|
163 | m_pColorMappedPic = NULL; |
---|
164 | } |
---|
165 | #endif |
---|
166 | } |
---|
167 | |
---|
168 | Void TDecTop::create() |
---|
169 | { |
---|
170 | m_cGopDecoder.create(); |
---|
171 | m_apcSlicePilot = new TComSlice; |
---|
172 | m_uiSliceIdx = 0; |
---|
173 | } |
---|
174 | |
---|
175 | Void TDecTop::destroy() |
---|
176 | { |
---|
177 | m_cGopDecoder.destroy(); |
---|
178 | |
---|
179 | delete m_apcSlicePilot; |
---|
180 | m_apcSlicePilot = NULL; |
---|
181 | |
---|
182 | m_cSliceDecoder.destroy(); |
---|
183 | #if SVC_EXTENSION |
---|
184 | for(Int i=0; i<MAX_NUM_REF; i++) |
---|
185 | { |
---|
186 | if(m_cIlpPic[i]) |
---|
187 | { |
---|
188 | m_cIlpPic[i]->destroy(); |
---|
189 | delete m_cIlpPic[i]; |
---|
190 | m_cIlpPic[i] = NULL; |
---|
191 | } |
---|
192 | } |
---|
193 | #endif |
---|
194 | } |
---|
195 | |
---|
196 | Void TDecTop::init() |
---|
197 | { |
---|
198 | #if !SVC_EXTENSION |
---|
199 | // initialize ROM |
---|
200 | initROM(); |
---|
201 | #endif |
---|
202 | #if SVC_EXTENSION |
---|
203 | m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO); |
---|
204 | #else |
---|
205 | m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO); |
---|
206 | #endif |
---|
207 | m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder ); |
---|
208 | m_cEntropyDecoder.init(&m_cPrediction); |
---|
209 | } |
---|
210 | |
---|
211 | Void TDecTop::deletePicBuffer ( ) |
---|
212 | { |
---|
213 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
214 | Int iSize = Int( m_cListPic.size() ); |
---|
215 | |
---|
216 | for (Int i = 0; i < iSize; i++ ) |
---|
217 | { |
---|
218 | TComPic* pcPic = *(iterPic++); |
---|
219 | #if SVC_EXTENSION |
---|
220 | if( pcPic ) |
---|
221 | { |
---|
222 | pcPic->destroy(); |
---|
223 | |
---|
224 | delete pcPic; |
---|
225 | pcPic = NULL; |
---|
226 | } |
---|
227 | #else |
---|
228 | pcPic->destroy(); |
---|
229 | |
---|
230 | delete pcPic; |
---|
231 | pcPic = NULL; |
---|
232 | #endif |
---|
233 | } |
---|
234 | |
---|
235 | m_cSAO.destroy(); |
---|
236 | |
---|
237 | m_cLoopFilter. destroy(); |
---|
238 | |
---|
239 | #if !SVC_EXTENSION |
---|
240 | // destroy ROM |
---|
241 | destroyROM(); |
---|
242 | #endif |
---|
243 | } |
---|
244 | |
---|
245 | #if SVC_EXTENSION |
---|
246 | Void TDecTop::xGetNewPicBuffer( const TComVPS &vps, const TComSPS &sps, const TComPPS &pps, TComPic*& rpcPic, const UInt temporalLayer ) |
---|
247 | #else |
---|
248 | Void TDecTop::xGetNewPicBuffer ( const TComSPS &sps, const TComPPS &pps, TComPic*& rpcPic, const UInt temporalLayer ) |
---|
249 | #endif |
---|
250 | { |
---|
251 | #if SVC_EXTENSION |
---|
252 | if( m_commonDecoderParams->getTargetOutputLayerSetIdx() == 0 ) |
---|
253 | { |
---|
254 | assert( m_layerId == 0 ); |
---|
255 | m_iMaxRefPicNum = sps.getMaxDecPicBuffering(temporalLayer); // m_uiMaxDecPicBuffering has the space for the picture currently being decoded |
---|
256 | } |
---|
257 | else |
---|
258 | { |
---|
259 | m_iMaxRefPicNum = vps.getMaxVpsDecPicBufferingMinus1( m_commonDecoderParams->getTargetOutputLayerSetIdx(), vps.getLayerIdcForOls( vps.getOutputLayerSetIdx( m_commonDecoderParams->getTargetOutputLayerSetIdx()), m_layerId ), temporalLayer ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded |
---|
260 | } |
---|
261 | |
---|
262 | m_iMaxRefPicNum += 1; // SHM: it should be updated if more than 1 resampling picture is used |
---|
263 | #else |
---|
264 | m_iMaxRefPicNum = sps.getMaxDecPicBuffering(temporalLayer); // m_uiMaxDecPicBuffering has the space for the picture currently being decoded |
---|
265 | #endif |
---|
266 | |
---|
267 | if (m_cListPic.size() < (UInt)m_iMaxRefPicNum) |
---|
268 | { |
---|
269 | rpcPic = new TComPic(); |
---|
270 | |
---|
271 | #if SVC_EXTENSION |
---|
272 | if(m_layerId > 0) |
---|
273 | { |
---|
274 | xSetSpatialEnhLayerFlag( vps, sps, pps, rpcPic ); |
---|
275 | } |
---|
276 | |
---|
277 | rpcPic->create( vps, sps, pps, true, m_layerId); |
---|
278 | #else //SVC_EXTENSION |
---|
279 | rpcPic->create ( sps, pps, true); |
---|
280 | #endif //SVC_EXTENSION |
---|
281 | |
---|
282 | m_cListPic.pushBack( rpcPic ); |
---|
283 | |
---|
284 | return; |
---|
285 | } |
---|
286 | |
---|
287 | Bool bBufferIsAvailable = false; |
---|
288 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
289 | while (iterPic != m_cListPic.end()) |
---|
290 | { |
---|
291 | rpcPic = *(iterPic++); |
---|
292 | if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false) |
---|
293 | { |
---|
294 | rpcPic->setOutputMark(false); |
---|
295 | bBufferIsAvailable = true; |
---|
296 | break; |
---|
297 | } |
---|
298 | |
---|
299 | if ( rpcPic->getSlice( 0 )->isReferenced() == false && rpcPic->getOutputMark() == false) |
---|
300 | { |
---|
301 | #if !SVC_EXTENSION |
---|
302 | rpcPic->setOutputMark(false); |
---|
303 | #endif |
---|
304 | rpcPic->setReconMark( false ); |
---|
305 | rpcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
306 | bBufferIsAvailable = true; |
---|
307 | break; |
---|
308 | } |
---|
309 | } |
---|
310 | |
---|
311 | if ( !bBufferIsAvailable ) |
---|
312 | { |
---|
313 | //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer. |
---|
314 | m_iMaxRefPicNum++; |
---|
315 | rpcPic = new TComPic(); |
---|
316 | m_cListPic.pushBack( rpcPic ); |
---|
317 | } |
---|
318 | rpcPic->destroy(); |
---|
319 | |
---|
320 | #if SVC_EXTENSION |
---|
321 | if( m_layerId > 0 ) |
---|
322 | { |
---|
323 | xSetSpatialEnhLayerFlag( vps, sps, pps, rpcPic ); |
---|
324 | } |
---|
325 | |
---|
326 | rpcPic->create( vps, sps, pps, true, m_layerId); |
---|
327 | #else //SVC_EXTENSION |
---|
328 | rpcPic->create ( sps, pps, true); |
---|
329 | #endif //SVC_EXTENSION |
---|
330 | } |
---|
331 | |
---|
332 | Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic) |
---|
333 | { |
---|
334 | if (!m_pcPic) |
---|
335 | { |
---|
336 | /* nothing to deblock */ |
---|
337 | return; |
---|
338 | } |
---|
339 | |
---|
340 | TComPic* pcPic = m_pcPic; |
---|
341 | |
---|
342 | // Execute Deblock + Cleanup |
---|
343 | |
---|
344 | m_cGopDecoder.filterPicture(pcPic); |
---|
345 | |
---|
346 | #if SVC_EXTENSION |
---|
347 | if( this->getLayerDec(pcPic->getLayerId())->m_isOutputLayerFlag == false ) |
---|
348 | { |
---|
349 | pcPic->setOutputMark( false ); |
---|
350 | } |
---|
351 | #endif |
---|
352 | |
---|
353 | TComSlice::sortPicList( m_cListPic ); // sorting for application output |
---|
354 | poc = pcPic->getSlice(m_uiSliceIdx-1)->getPOC(); |
---|
355 | rpcListPic = &m_cListPic; |
---|
356 | m_cCuDecoder.destroy(); |
---|
357 | m_bFirstSliceInPicture = true; |
---|
358 | |
---|
359 | return; |
---|
360 | } |
---|
361 | |
---|
362 | Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>* pcListPic) |
---|
363 | { |
---|
364 | if (!pcListPic || !m_isNoOutputPriorPics) |
---|
365 | { |
---|
366 | return; |
---|
367 | } |
---|
368 | |
---|
369 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
370 | |
---|
371 | while (iterPic != pcListPic->end()) |
---|
372 | { |
---|
373 | TComPic* pcPicTmp = *(iterPic++); |
---|
374 | if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC()) |
---|
375 | { |
---|
376 | pcPicTmp->setOutputMark(false); |
---|
377 | } |
---|
378 | } |
---|
379 | } |
---|
380 | |
---|
381 | Void TDecTop::xCreateLostPicture(Int iLostPoc) |
---|
382 | { |
---|
383 | printf("\ninserting lost poc : %d\n",iLostPoc); |
---|
384 | TComPic *cFillPic; |
---|
385 | #if SVC_EXTENSION |
---|
386 | xGetNewPicBuffer(*(m_parameterSetManager.getFirstVPS()), *(m_parameterSetManager.getFirstSPS()), *(m_parameterSetManager.getFirstPPS()), cFillPic, 0); |
---|
387 | cFillPic->getSlice(0)->initSlice( m_layerId ); |
---|
388 | #else |
---|
389 | xGetNewPicBuffer(*(m_parameterSetManager.getFirstSPS()), *(m_parameterSetManager.getFirstPPS()), cFillPic, 0); |
---|
390 | cFillPic->getSlice(0)->initSlice(); |
---|
391 | #endif |
---|
392 | |
---|
393 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
394 | Int closestPoc = 1000000; |
---|
395 | while ( iterPic != m_cListPic.end()) |
---|
396 | { |
---|
397 | TComPic * rpcPic = *(iterPic++); |
---|
398 | if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)<closestPoc&&abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)!=0&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC()) |
---|
399 | { |
---|
400 | closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc); |
---|
401 | } |
---|
402 | } |
---|
403 | iterPic = m_cListPic.begin(); |
---|
404 | while ( iterPic != m_cListPic.end()) |
---|
405 | { |
---|
406 | TComPic *rpcPic = *(iterPic++); |
---|
407 | if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC()) |
---|
408 | { |
---|
409 | printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC()); |
---|
410 | rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec()); |
---|
411 | break; |
---|
412 | } |
---|
413 | } |
---|
414 | cFillPic->setCurrSliceIdx(0); |
---|
415 | for(Int ctuRsAddr=0; ctuRsAddr<cFillPic->getNumberOfCtusInFrame(); ctuRsAddr++) |
---|
416 | { |
---|
417 | cFillPic->getCtu(ctuRsAddr)->initCtu(cFillPic, ctuRsAddr); |
---|
418 | } |
---|
419 | cFillPic->getSlice(0)->setReferenced(true); |
---|
420 | cFillPic->getSlice(0)->setPOC(iLostPoc); |
---|
421 | xUpdatePreviousTid0POC(cFillPic->getSlice(0)); |
---|
422 | cFillPic->setReconMark(true); |
---|
423 | cFillPic->setOutputMark(true); |
---|
424 | if(m_pocRandomAccess == MAX_INT) |
---|
425 | { |
---|
426 | m_pocRandomAccess = iLostPoc; |
---|
427 | } |
---|
428 | } |
---|
429 | |
---|
430 | |
---|
431 | Void TDecTop::xActivateParameterSets() |
---|
432 | { |
---|
433 | if (m_bFirstSliceInPicture) |
---|
434 | { |
---|
435 | const TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId()); // this is a temporary PPS object. Do not store this value |
---|
436 | assert (pps != 0); |
---|
437 | |
---|
438 | #if SVC_EXTENSION |
---|
439 | TComSPS *updateSPS = m_parameterSetManager.getSPS(pps->getSPSId()); // this is a temporary SPS object. Do not store this value |
---|
440 | #endif |
---|
441 | const TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId()); // this is a temporary SPS object. Do not store this value |
---|
442 | assert (sps != 0); |
---|
443 | |
---|
444 | m_parameterSetManager.clearSPSChangedFlag(sps->getSPSId()); |
---|
445 | m_parameterSetManager.clearPPSChangedFlag(pps->getPPSId()); |
---|
446 | |
---|
447 | if (false == m_parameterSetManager.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP())) |
---|
448 | { |
---|
449 | printf ("Parameter set activation failed!"); |
---|
450 | assert (0); |
---|
451 | } |
---|
452 | |
---|
453 | xParsePrefixSEImessages(); |
---|
454 | |
---|
455 | #if RExt__HIGH_BIT_DEPTH_SUPPORT==0 |
---|
456 | if (sps->getSpsRangeExtension().getExtendedPrecisionProcessingFlag() || sps->getBitDepth(CHANNEL_TYPE_LUMA)>12 || sps->getBitDepth(CHANNEL_TYPE_CHROMA)>12 ) |
---|
457 | { |
---|
458 | printf("High bit depth support must be enabled at compile-time in order to decode this bitstream\n"); |
---|
459 | assert (0); |
---|
460 | exit(1); |
---|
461 | } |
---|
462 | #endif |
---|
463 | |
---|
464 | #if SVC_EXTENSION |
---|
465 | // scaling list settings and checks |
---|
466 | TComVPS *vps = m_parameterSetManager.getVPS(sps->getVPSId()); |
---|
467 | assert (vps != 0); |
---|
468 | |
---|
469 | m_parameterSetManager.clearVPSChangedFlag(sps->getVPSId()); |
---|
470 | |
---|
471 | if( sps->getInferScalingListFlag() ) |
---|
472 | { |
---|
473 | UInt refLayerId = sps->getScalingListRefLayerId(); |
---|
474 | const TComSPS *refSps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActiveSPS(); assert( refSps != NULL ); |
---|
475 | |
---|
476 | // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0 |
---|
477 | if( vps->getNonHEVCBaseLayerFlag() ) |
---|
478 | { |
---|
479 | assert( refLayerId > 0 ); |
---|
480 | } |
---|
481 | |
---|
482 | // reference layer active SPS (specified by sps_scaling_list_ref_layer_id or pps_scaling_list_ref_layer_id) shall have scaling_list_enabled_flag equal to 1. |
---|
483 | assert( refSps->getScalingListFlag() == true ); |
---|
484 | |
---|
485 | // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and |
---|
486 | // sps_infer_scaling_list_flag in the SPS is equal to 1, sps_infer_scaling_list_flag shall be equal to 0 for the SPS that is active for the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id |
---|
487 | assert( refSps->getInferScalingListFlag() == false ); |
---|
488 | |
---|
489 | // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB, |
---|
490 | // the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB |
---|
491 | assert( vps->getRecursiveRefLayerFlag( sps->getLayerId(), refLayerId ) == true ); |
---|
492 | } |
---|
493 | |
---|
494 | if( pps->getInferScalingListFlag() ) |
---|
495 | { |
---|
496 | UInt refLayerId = pps->getScalingListRefLayerId(); |
---|
497 | const TComPPS *refPps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActivePPS(); assert( refPps != NULL ); |
---|
498 | |
---|
499 | // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0 |
---|
500 | if( vps->getNonHEVCBaseLayerFlag() ) |
---|
501 | { |
---|
502 | assert( refLayerId > 0 ); |
---|
503 | } |
---|
504 | |
---|
505 | // It is a requirement of bitstream conformance that, when an PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and |
---|
506 | // pps_infer_scaling_list_flag in the PPS is equal to 1, pps_infer_scaling_list_flag shall be equal to 0 for the PPS that is active for the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id |
---|
507 | assert( refPps->getInferScalingListFlag() == false ); |
---|
508 | |
---|
509 | // It is a requirement of bitstream conformance that, when an PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB, |
---|
510 | // the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB |
---|
511 | assert( vps->getRecursiveRefLayerFlag( pps->getLayerId(), refLayerId ) == true ); |
---|
512 | } |
---|
513 | |
---|
514 | #if AVC_BASE |
---|
515 | if( vps->getNonHEVCBaseLayerFlag() ) |
---|
516 | { |
---|
517 | TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin()); |
---|
518 | if( m_layerId > 0 && pBLPic->getPicYuvRec() == NULL ) |
---|
519 | { |
---|
520 | UInt refLayerId = 0; |
---|
521 | |
---|
522 | pBLPic->create( *vps, *sps, *pps, true, refLayerId); |
---|
523 | |
---|
524 | // it is needed where the VPS is accessed through the slice |
---|
525 | pBLPic->getSlice(0)->setVPS( vps ); |
---|
526 | } |
---|
527 | } |
---|
528 | #endif |
---|
529 | |
---|
530 | if( m_layerId > 0 ) |
---|
531 | { |
---|
532 | // When not present sps_max_sub_layers_minus1 is inferred to be equal to vps_max_sub_layers_minus1. |
---|
533 | updateSPS->setMaxTLayers( vps->getMaxTLayers() ); |
---|
534 | |
---|
535 | // When not present sps_temporal_id_nesting_flag is inferred to be equal to vps_temporal_id_nesting_flag |
---|
536 | updateSPS->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true ); |
---|
537 | |
---|
538 | // When sps_max_dec_pic_buffering_minus1[ i ] is not present for i in the range of 0 to sps_max_sub_layers_minus1, inclusive, due to nuh_layer_id being greater than 0, |
---|
539 | // it is inferred to be equal to max_vps_dec_pic_buffering_minus1[ TargetOptLayerSetIdx ][ currLayerId ][ i ] of the active VPS, where currLayerId is the nuh_layer_id of the layer that refers to the SPS. |
---|
540 | for(UInt i=0; i < sps->getMaxTLayers(); i++) |
---|
541 | { |
---|
542 | // to avoid compiler warning "array subscript is above array bounds" |
---|
543 | assert( i < MAX_TLAYER ); |
---|
544 | |
---|
545 | // When sps_max_dec_pic_buffering_minus1[ i ] is not present for i in the range of 0 to sps_max_sub_layers_minus1, inclusive, |
---|
546 | // due to MultiLayerExtSpsFlag being equal to 1, for a layer that refers to the SPS and has nuh_layer_id equal to currLayerId, |
---|
547 | // the value of sps_max_dec_pic_buffering_minus1[ i ] is inferred to be equal to max_vps_dec_pic_buffering_minus1[ TargetOlsIdx ][ layerIdx ][ i ] of the active VPS, |
---|
548 | // where layerIdx is equal to the value such that LayerSetLayerIdList[ TargetDecLayerSetIdx ][ layerIdx ] is equal to currLayerId. |
---|
549 | if( sps->getMultiLayerExtSpsFlag() ) |
---|
550 | { |
---|
551 | updateSPS->setMaxDecPicBuffering( vps->getMaxVpsDecPicBufferingMinus1( m_commonDecoderParams->getTargetOutputLayerSetIdx(), vps->getLayerIdcForOls( vps->getOutputLayerSetIdx( m_commonDecoderParams->getTargetOutputLayerSetIdx() ), m_layerId ), i) + 1, i); |
---|
552 | } |
---|
553 | |
---|
554 | // The value of sps_max_dec_pic_buffering_minus1[ i ] shall be less than or equal to vps_max_dec_pic_buffering_minus1[ i ] for each value of i. |
---|
555 | assert( sps->getMaxDecPicBuffering(i) <= vps->getMaxDecPicBuffering(i) ); |
---|
556 | } |
---|
557 | |
---|
558 | UInt layerIdx = vps->getLayerIdxInVps( m_layerId ); |
---|
559 | |
---|
560 | if( vps->getBaseLayerPSCompatibilityFlag(layerIdx) ) |
---|
561 | { |
---|
562 | const RepFormat* repFormat = vps->getVpsRepFormat(vps->getVpsRepFormatIdx(layerIdx)); |
---|
563 | |
---|
564 | assert( pps->getLayerId() == 0 ); |
---|
565 | assert( sps->getLayerId() == 0 ); |
---|
566 | assert( repFormat->getChromaFormatVpsIdc() == sps->getChromaFormatIdc() ); |
---|
567 | assert( repFormat->getSeparateColourPlaneVpsFlag() == 0 ); |
---|
568 | assert( repFormat->getPicHeightVpsInLumaSamples() == sps->getPicHeightInLumaSamples() ); |
---|
569 | assert( repFormat->getPicWidthVpsInLumaSamples() == sps->getPicWidthInLumaSamples() ); |
---|
570 | assert( repFormat->getBitDepthVpsLuma() == sps->getBitDepth(CHANNEL_TYPE_LUMA) ); |
---|
571 | assert( repFormat->getBitDepthVpsChroma() == sps->getBitDepth(CHANNEL_TYPE_CHROMA) ); |
---|
572 | assert( repFormat->getConformanceWindowVps().getWindowLeftOffset() == sps->getConformanceWindow().getWindowLeftOffset() ); |
---|
573 | assert( repFormat->getConformanceWindowVps().getWindowRightOffset() == sps->getConformanceWindow().getWindowRightOffset() ); |
---|
574 | assert( repFormat->getConformanceWindowVps().getWindowTopOffset() == sps->getConformanceWindow().getWindowTopOffset() ); |
---|
575 | assert( repFormat->getConformanceWindowVps().getWindowBottomOffset() == sps->getConformanceWindow().getWindowBottomOffset() ); |
---|
576 | } |
---|
577 | } |
---|
578 | |
---|
579 | //Conformance checking for rep format -- rep format of current picture of current layer shall never be greater rep format defined in VPS for the current layer |
---|
580 | UInt layerIdx = vps->getLayerIdxInVps(m_apcSlicePilot->getLayerId()); |
---|
581 | |
---|
582 | if ( vps->getVpsExtensionFlag() == 1 && (m_apcSlicePilot->getLayerId() == 0 || sps->getV1CompatibleSPSFlag() == 1) ) |
---|
583 | { |
---|
584 | assert( sps->getPicWidthInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getPicWidthVpsInLumaSamples() ); |
---|
585 | assert( sps->getPicHeightInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getPicHeightVpsInLumaSamples() ); |
---|
586 | assert( sps->getChromaFormatIdc() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getChromaFormatVpsIdc() ); |
---|
587 | assert( sps->getBitDepth(CHANNEL_TYPE_LUMA) <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsLuma() ); |
---|
588 | assert( sps->getBitDepth(CHANNEL_TYPE_CHROMA) <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsChroma() ); |
---|
589 | } |
---|
590 | else if ( vps->getVpsExtensionFlag() == 1 ) |
---|
591 | { |
---|
592 | assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples()); |
---|
593 | assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples()); |
---|
594 | assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc()); |
---|
595 | assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma()); |
---|
596 | assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma()); |
---|
597 | } |
---|
598 | #endif //SVC_EXTENSION |
---|
599 | |
---|
600 | // NOTE: globals were set up here originally. You can now use: |
---|
601 | // g_uiMaxCUDepth = sps->getMaxTotalCUDepth(); |
---|
602 | // g_uiAddCUDepth = sps->getMaxTotalCUDepth() - sps->getLog2DiffMaxMinCodingBlockSize() |
---|
603 | |
---|
604 | // Get a new picture buffer. This will also set up m_pcPic, and therefore give us a SPS and PPS pointer that we can use. |
---|
605 | #if SVC_EXTENSION |
---|
606 | xGetNewPicBuffer( *(vps), *(sps), *(pps), m_pcPic, m_apcSlicePilot->getTLayer() ); |
---|
607 | #else |
---|
608 | xGetNewPicBuffer (*(sps), *(pps), m_pcPic, m_apcSlicePilot->getTLayer()); |
---|
609 | #endif |
---|
610 | |
---|
611 | #if ALIGNED_BUMPING |
---|
612 | m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic); |
---|
613 | #else |
---|
614 | m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS()); |
---|
615 | #endif |
---|
616 | |
---|
617 | // make the slice-pilot a real slice, and set up the slice-pilot for the next slice |
---|
618 | assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1)); |
---|
619 | m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx); |
---|
620 | |
---|
621 | // we now have a real slice: |
---|
622 | TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx); |
---|
623 | |
---|
624 | // Update the PPS and SPS pointers with the ones of the picture. |
---|
625 | pps=pSlice->getPPS(); |
---|
626 | sps=pSlice->getSPS(); |
---|
627 | |
---|
628 | // Initialise the various objects for the new set of settings |
---|
629 | #if SVC_EXTENSION |
---|
630 | m_cSAO.create( pSlice->getPicWidthInLumaSamples(), pSlice->getPicHeightInLumaSamples(), pSlice->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxTotalCUDepth(), pps->getPpsRangeExtension().getLog2SaoOffsetScale(CHANNEL_TYPE_LUMA), pps->getPpsRangeExtension().getLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA) ); |
---|
631 | #else |
---|
632 | m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxTotalCUDepth(), pps->getPpsRangeExtension().getLog2SaoOffsetScale(CHANNEL_TYPE_LUMA), pps->getPpsRangeExtension().getLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA) ); |
---|
633 | #endif |
---|
634 | m_cLoopFilter.create( sps->getMaxTotalCUDepth() ); |
---|
635 | m_cPrediction.initTempBuff(sps->getChromaFormatIdc()); |
---|
636 | |
---|
637 | |
---|
638 | Bool isField = false; |
---|
639 | Bool isTopField = false; |
---|
640 | |
---|
641 | if(!m_SEIs.empty()) |
---|
642 | { |
---|
643 | // Check if any new Picture Timing SEI has arrived |
---|
644 | SEIMessages pictureTimingSEIs = getSeisByType(m_SEIs, SEI::PICTURE_TIMING); |
---|
645 | if (pictureTimingSEIs.size()>0) |
---|
646 | { |
---|
647 | SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin()); |
---|
648 | isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2) || (pictureTiming->m_picStruct == 9) || (pictureTiming->m_picStruct == 10) || (pictureTiming->m_picStruct == 11) || (pictureTiming->m_picStruct == 12); |
---|
649 | isTopField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 9) || (pictureTiming->m_picStruct == 11); |
---|
650 | } |
---|
651 | |
---|
652 | #if Q0189_TMVP_CONSTRAINTS |
---|
653 | // Check if any new temporal motion vector prediction constraints SEI has arrived |
---|
654 | SEIMessages seiTMVPConstrainsList = extractSeisByType (m_SEIs, SEI::TMVP_CONSTRAINTS); |
---|
655 | if (seiTMVPConstrainsList.size() > 0) |
---|
656 | { |
---|
657 | assert ( m_pcPic->getTLayer() == 0 ); //this SEI can present only for AU with Tid equal to 0 |
---|
658 | SEITMVPConstrains* tmvpConstraintSEI = (SEITMVPConstrains*) *(seiTMVPConstrainsList.begin()); |
---|
659 | if ( tmvpConstraintSEI->prev_pics_not_used_flag == 1 ) |
---|
660 | { |
---|
661 | //update all pics in the DPB such that they cannot be used for TMPV ref |
---|
662 | TComList<TComPic*>::iterator iterRefPic = m_cListPic.begin(); |
---|
663 | while( iterRefPic != m_cListPic.end() ) |
---|
664 | { |
---|
665 | TComPic *refPic = *iterRefPic; |
---|
666 | if( ( refPic->getLayerId() == m_pcPic->getLayerId() ) && refPic->getReconMark() ) |
---|
667 | { |
---|
668 | for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--) |
---|
669 | { |
---|
670 | TComSlice *refSlice = refPic->getSlice(i); |
---|
671 | refSlice->setAvailableForTMVPRefFlag( false ); |
---|
672 | } |
---|
673 | } |
---|
674 | iterRefPic++; |
---|
675 | } |
---|
676 | } |
---|
677 | } |
---|
678 | #endif |
---|
679 | } |
---|
680 | |
---|
681 | //Set Field/Frame coding mode |
---|
682 | m_pcPic->setField(isField); |
---|
683 | m_pcPic->setTopField(isTopField); |
---|
684 | |
---|
685 | // transfer any SEI messages that have been received to the picture |
---|
686 | m_pcPic->setSEIs(m_SEIs); |
---|
687 | m_SEIs.clear(); |
---|
688 | |
---|
689 | // Recursive structure |
---|
690 | #if SVC_EXTENSION |
---|
691 | m_cCuDecoder.create ( sps->getMaxTotalCUDepth(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), pSlice->getChromaFormatIdc() ); |
---|
692 | m_cCuDecoder.init ( m_ppcTDecTop, &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, m_layerId ); |
---|
693 | #else |
---|
694 | m_cCuDecoder.create ( sps->getMaxTotalCUDepth(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getChromaFormatIdc() ); |
---|
695 | m_cCuDecoder.init ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction ); |
---|
696 | #endif |
---|
697 | m_cTrQuant.init ( sps->getMaxTrSize() ); |
---|
698 | |
---|
699 | m_cSliceDecoder.create(); |
---|
700 | } |
---|
701 | else |
---|
702 | { |
---|
703 | // make the slice-pilot a real slice, and set up the slice-pilot for the next slice |
---|
704 | m_pcPic->allocateNewSlice(); |
---|
705 | assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1)); |
---|
706 | m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx); |
---|
707 | |
---|
708 | TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx); // we now have a real slice. |
---|
709 | |
---|
710 | const TComSPS *sps = pSlice->getSPS(); |
---|
711 | const TComPPS *pps = pSlice->getPPS(); |
---|
712 | |
---|
713 | // check that the current active PPS has not changed... |
---|
714 | if (m_parameterSetManager.getSPSChangedFlag(sps->getSPSId()) ) |
---|
715 | { |
---|
716 | printf("Error - a new SPS has been decoded while processing a picture\n"); |
---|
717 | exit(1); |
---|
718 | } |
---|
719 | if (m_parameterSetManager.getPPSChangedFlag(pps->getPPSId()) ) |
---|
720 | { |
---|
721 | printf("Error - a new PPS has been decoded while processing a picture\n"); |
---|
722 | exit(1); |
---|
723 | } |
---|
724 | |
---|
725 | xParsePrefixSEImessages(); |
---|
726 | |
---|
727 | // Check if any new SEI has arrived |
---|
728 | if(!m_SEIs.empty()) |
---|
729 | { |
---|
730 | // Currently only decoding Unit SEI message occurring between VCL NALUs copied |
---|
731 | SEIMessages &picSEI = m_pcPic->getSEIs(); |
---|
732 | SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO); |
---|
733 | picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end()); |
---|
734 | deleteSEIs(m_SEIs); |
---|
735 | } |
---|
736 | } |
---|
737 | } |
---|
738 | |
---|
739 | |
---|
740 | Void TDecTop::xParsePrefixSEIsForUnknownVCLNal() |
---|
741 | { |
---|
742 | while (!m_prefixSEINALUs.empty()) |
---|
743 | { |
---|
744 | // do nothing? |
---|
745 | printf("Discarding Prefix SEI associated with unknown VCL NAL unit.\n"); |
---|
746 | delete m_prefixSEINALUs.front(); |
---|
747 | } |
---|
748 | // TODO: discard following suffix SEIs as well? |
---|
749 | } |
---|
750 | |
---|
751 | |
---|
752 | Void TDecTop::xParsePrefixSEImessages() |
---|
753 | { |
---|
754 | #if SVC_EXTENSION |
---|
755 | if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit |
---|
756 | { |
---|
757 | return; |
---|
758 | } |
---|
759 | #endif |
---|
760 | |
---|
761 | while (!m_prefixSEINALUs.empty()) |
---|
762 | { |
---|
763 | InputNALUnit &nalu=*m_prefixSEINALUs.front(); |
---|
764 | #if LAYERS_NOT_PRESENT_SEI |
---|
765 | m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveVPS(), m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream ); |
---|
766 | #else |
---|
767 | m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream ); |
---|
768 | #endif |
---|
769 | delete m_prefixSEINALUs.front(); |
---|
770 | m_prefixSEINALUs.pop_front(); |
---|
771 | } |
---|
772 | } |
---|
773 | |
---|
774 | #if SVC_EXTENSION |
---|
775 | Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC ) |
---|
776 | #else |
---|
777 | Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay ) |
---|
778 | #endif |
---|
779 | { |
---|
780 | #if SVC_EXTENSION |
---|
781 | m_apcSlicePilot->initSlice( nalu.m_nuhLayerId ); |
---|
782 | m_apcSlicePilot->setTLayer( nalu.m_temporalId ); |
---|
783 | #else //SVC_EXTENSION |
---|
784 | m_apcSlicePilot->initSlice(); // the slice pilot is an object to prepare for a new slice |
---|
785 | // it is not associated with picture, sps or pps structures. |
---|
786 | #endif |
---|
787 | |
---|
788 | if (m_bFirstSliceInPicture) |
---|
789 | { |
---|
790 | m_uiSliceIdx = 0; |
---|
791 | } |
---|
792 | else |
---|
793 | { |
---|
794 | m_apcSlicePilot->copySliceInfo( m_pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) ); |
---|
795 | } |
---|
796 | m_apcSlicePilot->setSliceIdx(m_uiSliceIdx); |
---|
797 | |
---|
798 | m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType); |
---|
799 | |
---|
800 | Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N || |
---|
801 | m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N || |
---|
802 | m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N || |
---|
803 | m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N || |
---|
804 | m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N); |
---|
805 | m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag); |
---|
806 | m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS |
---|
807 | m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId); |
---|
808 | |
---|
809 | #if ENC_DEC_TRACE |
---|
810 | const UInt64 originalSymbolCount = g_nSymbolCounter; |
---|
811 | #endif |
---|
812 | |
---|
813 | m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManager, m_prevTid0POC); |
---|
814 | |
---|
815 | #if SVC_EXTENSION |
---|
816 | const TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId()); |
---|
817 | assert (pps != 0); |
---|
818 | const TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId()); |
---|
819 | assert (sps != 0); |
---|
820 | const TComVPS *vps = m_parameterSetManager.getVPS(sps->getVPSId()); |
---|
821 | assert (vps != 0); |
---|
822 | |
---|
823 | // Following check should go wherever the VPS is activated |
---|
824 | if( !vps->getBaseLayerAvailableFlag() ) |
---|
825 | { |
---|
826 | assert( nalu.m_nuhLayerId != 0 ); |
---|
827 | assert( vps->getNumAddLayerSets() > 0 ); |
---|
828 | |
---|
829 | if( m_commonDecoderParams->getTargetOutputLayerSetIdx() >= 0 ) |
---|
830 | { |
---|
831 | UInt layerIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() ); |
---|
832 | assert( layerIdx > vps->getVpsNumLayerSetsMinus1() ); |
---|
833 | } |
---|
834 | } |
---|
835 | |
---|
836 | setRefLayerParams(vps); |
---|
837 | m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers); |
---|
838 | |
---|
839 | // set motion mapping flag |
---|
840 | m_apcSlicePilot->setMFMEnabledFlag( ( m_apcSlicePilot->getNumMotionPredRefLayers() > 0 && m_apcSlicePilot->getActiveNumILRRefIdx() && !m_apcSlicePilot->isIntra() ) ? true : false ); |
---|
841 | #endif |
---|
842 | |
---|
843 | // set POC for dependent slices in skipped pictures |
---|
844 | if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) |
---|
845 | { |
---|
846 | m_apcSlicePilot->setPOC(m_skippedPOC); |
---|
847 | } |
---|
848 | |
---|
849 | #if !CONFORMANCE_BITSTREAM_FIX //This update previous Tid0 POC is moved down and invoke only after the POC derivation has been finalized |
---|
850 | xUpdatePreviousTid0POC(m_apcSlicePilot); |
---|
851 | #endif |
---|
852 | |
---|
853 | m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA); |
---|
854 | m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType); |
---|
855 | |
---|
856 | //For inference of NoOutputOfPriorPicsFlag |
---|
857 | if (m_apcSlicePilot->getRapPicFlag()) |
---|
858 | { |
---|
859 | if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || |
---|
860 | (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) || |
---|
861 | (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag())) |
---|
862 | { |
---|
863 | m_apcSlicePilot->setNoRaslOutputFlag(true); |
---|
864 | } |
---|
865 | //the inference for NoOutputPriorPicsFlag |
---|
866 | if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag()) |
---|
867 | { |
---|
868 | if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA) |
---|
869 | { |
---|
870 | m_apcSlicePilot->setNoOutputPriorPicsFlag(true); |
---|
871 | } |
---|
872 | } |
---|
873 | else |
---|
874 | { |
---|
875 | m_apcSlicePilot->setNoOutputPriorPicsFlag(false); |
---|
876 | } |
---|
877 | |
---|
878 | if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA) |
---|
879 | { |
---|
880 | m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag(); |
---|
881 | } |
---|
882 | } |
---|
883 | if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag()) |
---|
884 | { |
---|
885 | m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC(); |
---|
886 | m_isNoOutputPriorPics = true; |
---|
887 | } |
---|
888 | else |
---|
889 | { |
---|
890 | m_isNoOutputPriorPics = false; |
---|
891 | } |
---|
892 | |
---|
893 | //For inference of PicOutputFlag |
---|
894 | if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R) |
---|
895 | { |
---|
896 | if ( m_craNoRaslOutputFlag ) |
---|
897 | { |
---|
898 | m_apcSlicePilot->setPicOutputFlag(false); |
---|
899 | } |
---|
900 | } |
---|
901 | |
---|
902 | if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1 |
---|
903 | { |
---|
904 | #if !SVC_EXTENSION |
---|
905 | TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId()); |
---|
906 | assert (pps != 0); |
---|
907 | TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId()); |
---|
908 | assert (sps != 0); |
---|
909 | #endif |
---|
910 | Int iMaxPOClsb = 1 << sps->getBitsForPOC(); |
---|
911 | m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) ); |
---|
912 | #if !CONFORMANCE_BITSTREAM_FIX //This update previous Tid0 POC is moved down and invoke only after the POC derivation has been finalized |
---|
913 | xUpdatePreviousTid0POC(m_apcSlicePilot); |
---|
914 | #endif |
---|
915 | } |
---|
916 | |
---|
917 | // Skip pictures due to random access |
---|
918 | |
---|
919 | if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay)) |
---|
920 | { |
---|
921 | m_prevSliceSkipped = true; |
---|
922 | m_skippedPOC = m_apcSlicePilot->getPOC(); |
---|
923 | return false; |
---|
924 | } |
---|
925 | // Skip TFD pictures associated with BLA/BLANT pictures |
---|
926 | if (isSkipPictureForBLA(iPOCLastDisplay)) |
---|
927 | { |
---|
928 | m_prevSliceSkipped = true; |
---|
929 | m_skippedPOC = m_apcSlicePilot->getPOC(); |
---|
930 | return false; |
---|
931 | } |
---|
932 | |
---|
933 | // clear previous slice skipped flag |
---|
934 | m_prevSliceSkipped = false; |
---|
935 | |
---|
936 | // exit when a new picture is found |
---|
937 | #if SVC_EXTENSION |
---|
938 | bNewPOC = m_apcSlicePilot->getPOC() != m_prevPOC || ( m_apcSlicePilot->getFirstSliceInPic() && m_parseIdc == -1 ); |
---|
939 | |
---|
940 | #if NO_CLRAS_OUTPUT_FLAG |
---|
941 | if( m_layerId == m_smallestLayerId && m_apcSlicePilot->getRapPicFlag() ) |
---|
942 | { |
---|
943 | if( m_bFirstSliceInSequence ) |
---|
944 | { |
---|
945 | setNoClrasOutputFlag(true); |
---|
946 | } |
---|
947 | else if( m_lastPicHasEos ) |
---|
948 | { |
---|
949 | setNoClrasOutputFlag(true); |
---|
950 | } |
---|
951 | else if( m_apcSlicePilot->getBlaPicFlag() ) |
---|
952 | { |
---|
953 | setNoClrasOutputFlag(true); |
---|
954 | } |
---|
955 | else if( m_apcSlicePilot->getIdrPicFlag() && m_apcSlicePilot->getCrossLayerBLAFlag() ) |
---|
956 | { |
---|
957 | setNoClrasOutputFlag(true); |
---|
958 | } |
---|
959 | else |
---|
960 | { |
---|
961 | setNoClrasOutputFlag(false); |
---|
962 | } |
---|
963 | } |
---|
964 | else |
---|
965 | { |
---|
966 | setNoClrasOutputFlag(false); |
---|
967 | } |
---|
968 | |
---|
969 | m_apcSlicePilot->decodingRefreshMarking( m_cListPic, m_noClrasOutputFlag, m_smallestLayerId ); |
---|
970 | #endif |
---|
971 | |
---|
972 | // Derive the value of NoOutputOfPriorPicsFlag |
---|
973 | if( bNewPOC || m_layerId!=m_uiPrevLayerId ) // i.e. new coded picture |
---|
974 | { |
---|
975 | if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getNoRaslOutputFlag() ) |
---|
976 | { |
---|
977 | this->setNoOutputPriorPicsFlag( true ); |
---|
978 | } |
---|
979 | else if( m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag() ) |
---|
980 | { |
---|
981 | this->setNoOutputPriorPicsFlag( m_apcSlicePilot->getNoOutputPriorPicsFlag() ); |
---|
982 | } |
---|
983 | else |
---|
984 | { |
---|
985 | if( this->m_ppcTDecTop[0]->getNoClrasOutputFlag() ) |
---|
986 | { |
---|
987 | this->setNoOutputPriorPicsFlag( true ); |
---|
988 | } |
---|
989 | } |
---|
990 | } |
---|
991 | |
---|
992 | #if SVC_POC |
---|
993 | if( m_parseIdc != -1 ) // Second pass for a POC resetting picture |
---|
994 | { |
---|
995 | m_parseIdc++; // Proceed to POC decoding and RPS derivation |
---|
996 | } |
---|
997 | |
---|
998 | if( m_parseIdc == 2 ) |
---|
999 | { |
---|
1000 | bNewPOC = false; |
---|
1001 | } |
---|
1002 | |
---|
1003 | if( (bNewPOC || m_layerId!=m_uiPrevLayerId) && (m_parseIdc == -1) ) // Will be true at the first pass |
---|
1004 | { |
---|
1005 | //if (bNewPOC || m_layerId!=m_uiPrevLayerId) |
---|
1006 | // Check if new reset period has started - this is needed just so that the SHM decoder which calls slice header decoding twice |
---|
1007 | // does not invoke the output twice |
---|
1008 | //if( m_lastPocPeriodId[m_apcSlicePilot->getLayerId()] == m_apcSlicePilot->getPocResetPeriodId() ) |
---|
1009 | // Update CurrAU marking |
---|
1010 | if(( m_layerId < m_uiPrevLayerId) ||( ( m_layerId == m_uiPrevLayerId) && bNewPOC)) // Decoding a lower layer than or same layer as previous - mark all earlier pictures as not in current AU |
---|
1011 | { |
---|
1012 | // New access unit; reset all variables related to POC reset restrictions |
---|
1013 | resetPocRestrictionCheckParameters(); |
---|
1014 | |
---|
1015 | markAllPicsAsNoCurrAu(vps); |
---|
1016 | |
---|
1017 | for( UInt i = 0; i < MAX_LAYERS; i++ ) |
---|
1018 | { |
---|
1019 | m_ppcTDecTop[vps->getLayerIdInNuh(i)]->m_pocDecrementedInDPBFlag = false; |
---|
1020 | } |
---|
1021 | } |
---|
1022 | |
---|
1023 | m_pocResettingFlag = false; |
---|
1024 | |
---|
1025 | if( m_apcSlicePilot->getPocResetIdc() != 0 ) |
---|
1026 | { |
---|
1027 | if( vps->getVpsPocLsbAlignedFlag() ) |
---|
1028 | { |
---|
1029 | m_pocResettingFlag = true; |
---|
1030 | } |
---|
1031 | else if (m_pocDecrementedInDPBFlag) |
---|
1032 | { |
---|
1033 | m_pocResettingFlag = false; |
---|
1034 | } |
---|
1035 | else |
---|
1036 | { |
---|
1037 | m_pocResettingFlag = true; |
---|
1038 | } |
---|
1039 | } |
---|
1040 | |
---|
1041 | #if CONFORMANCE_BITSTREAM_FIX |
---|
1042 | if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getFirstSliceInPic() ) |
---|
1043 | #else |
---|
1044 | if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getSliceIdx() == 0 ) |
---|
1045 | #endif |
---|
1046 | { |
---|
1047 | Int pocResetPeriodId = m_apcSlicePilot->getPocResetPeriodId(); |
---|
1048 | if ( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 || |
---|
1049 | ( m_apcSlicePilot->getPocResetIdc() == 3 && pocResetPeriodId != getLastPocPeriodId() ) ) |
---|
1050 | { |
---|
1051 | setLastPocPeriodId(pocResetPeriodId); |
---|
1052 | m_parseIdc = 0; |
---|
1053 | } |
---|
1054 | |
---|
1055 | // Check if the POC Reset period ID matches with the Reset Period ID |
---|
1056 | if( pocResetPeriodId == m_crossLayerPocResetPeriodId ) |
---|
1057 | { |
---|
1058 | // If matching, and current poc_reset_idc = 3, then the values should match |
---|
1059 | if( m_apcSlicePilot->getPocResetIdc() == 3 ) |
---|
1060 | { |
---|
1061 | assert( ( m_apcSlicePilot->getFullPocResetFlag() == false && m_crossLayerPocResetIdc == 1 ) || |
---|
1062 | ( m_apcSlicePilot->getFullPocResetFlag() == true && m_crossLayerPocResetIdc == 2 ) ); |
---|
1063 | } |
---|
1064 | } |
---|
1065 | else |
---|
1066 | { |
---|
1067 | // This is the first picture of a POC resetting access unit |
---|
1068 | m_crossLayerPocResetPeriodId = pocResetPeriodId; |
---|
1069 | if( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 ) |
---|
1070 | { |
---|
1071 | m_crossLayerPocResetIdc = m_apcSlicePilot->getPocResetIdc(); |
---|
1072 | } |
---|
1073 | else |
---|
1074 | { // poc_reset_idc = 3 |
---|
1075 | // In this case, the entire POC resetting access unit has been lost. |
---|
1076 | // Need more checking to ensure poc_reset_idc = 3 works. |
---|
1077 | assert ( 0 ); |
---|
1078 | } |
---|
1079 | } |
---|
1080 | } |
---|
1081 | else |
---|
1082 | { |
---|
1083 | m_parseIdc = 3; // Proceed to decoding POC and RPS |
---|
1084 | } |
---|
1085 | } |
---|
1086 | #endif |
---|
1087 | |
---|
1088 | #if ALIGNED_BUMPING |
---|
1089 | UInt affectedLayerList[MAX_LAYERS]; |
---|
1090 | Int numAffectedLayers; |
---|
1091 | |
---|
1092 | affectedLayerList[0] = m_apcSlicePilot->getLayerId(); |
---|
1093 | numAffectedLayers = 1; |
---|
1094 | |
---|
1095 | if( vps->getVpsPocLsbAlignedFlag() ) |
---|
1096 | { |
---|
1097 | for( UInt j = 0; j < vps->getNumPredictedLayers(m_apcSlicePilot->getLayerId()); j++ ) |
---|
1098 | { |
---|
1099 | affectedLayerList[j + 1] = vps->getPredictedLayerId(m_apcSlicePilot->getLayerId(), j); |
---|
1100 | } |
---|
1101 | numAffectedLayers = vps->getNumPredictedLayers(m_apcSlicePilot->getLayerId()) + 1; |
---|
1102 | } |
---|
1103 | |
---|
1104 | if( m_parseIdc == 1 && m_pocResettingFlag ) |
---|
1105 | { |
---|
1106 | // Invoke output of pictures if the current picture is a POC reset picture |
---|
1107 | bNewPOC = true; |
---|
1108 | /* Include reset of all POCs in the layer */ |
---|
1109 | |
---|
1110 | // This operation would do the following: |
---|
1111 | // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture. |
---|
1112 | // 2. Update the value of m_pocCRA. |
---|
1113 | // 3. Reset the POC values at the decoder for the current picture to be zero - will be done later |
---|
1114 | // 4. update value of POCLastDisplay |
---|
1115 | |
---|
1116 | //Do the reset stuff here |
---|
1117 | Int maxPocLsb = 1 << sps->getBitsForPOC(); |
---|
1118 | Int pocLsbVal; |
---|
1119 | if( m_apcSlicePilot->getPocResetIdc() == 3 ) |
---|
1120 | { |
---|
1121 | pocLsbVal = m_apcSlicePilot->getPocLsbVal() ; |
---|
1122 | } |
---|
1123 | else |
---|
1124 | { |
---|
1125 | pocLsbVal = (m_apcSlicePilot->getPOC() % maxPocLsb); |
---|
1126 | } |
---|
1127 | |
---|
1128 | Int pocMsbDelta = 0; |
---|
1129 | if( m_apcSlicePilot->getPocMsbValPresentFlag() ) |
---|
1130 | { |
---|
1131 | pocMsbDelta = m_apcSlicePilot->getPocMsbVal() * maxPocLsb; |
---|
1132 | } |
---|
1133 | else |
---|
1134 | { |
---|
1135 | //This MSB derivation can be made into one function. Item to do next. |
---|
1136 | Int prevPoc = this->getPrevPicOrderCnt(); |
---|
1137 | Int prevPocLsb = prevPoc & (maxPocLsb - 1); |
---|
1138 | Int prevPocMsb = prevPoc - prevPocLsb; |
---|
1139 | |
---|
1140 | pocMsbDelta = m_apcSlicePilot->getCurrMsb( pocLsbVal, prevPocLsb, prevPocMsb, maxPocLsb ); |
---|
1141 | } |
---|
1142 | |
---|
1143 | Int pocLsbDelta; |
---|
1144 | if( m_apcSlicePilot->getPocResetIdc() == 2 || ( m_apcSlicePilot->getPocResetIdc() == 3 && m_apcSlicePilot->getFullPocResetFlag() )) |
---|
1145 | { |
---|
1146 | pocLsbDelta = pocLsbVal; |
---|
1147 | } |
---|
1148 | else |
---|
1149 | { |
---|
1150 | pocLsbDelta = 0; |
---|
1151 | } |
---|
1152 | |
---|
1153 | Int deltaPocVal = pocMsbDelta + pocLsbDelta; |
---|
1154 | |
---|
1155 | for( UInt layerIdx = 0; layerIdx < numAffectedLayers; layerIdx++ ) |
---|
1156 | { |
---|
1157 | if (!m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag) |
---|
1158 | { |
---|
1159 | m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag = true; |
---|
1160 | TComList<TComPic*>::iterator iterPic = m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->begin(); |
---|
1161 | |
---|
1162 | while (iterPic != m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->end()) |
---|
1163 | { |
---|
1164 | TComPic *dpbPic = *iterPic; |
---|
1165 | // Check if the picture pointed to by iterPic is either used for reference or |
---|
1166 | // needed for output, are in the same layer, and not the current picture. |
---|
1167 | assert(dpbPic->getLayerId() == affectedLayerList[layerIdx]); |
---|
1168 | |
---|
1169 | if( (dpbPic->getReconMark()) && (dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag()) ) |
---|
1170 | { |
---|
1171 | for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--) |
---|
1172 | { |
---|
1173 | |
---|
1174 | TComSlice *slice = dpbPic->getSlice(i); |
---|
1175 | TComReferencePictureSet *rps = slice->getLocalRPS(); |
---|
1176 | slice->setPOC( slice->getPOC() - deltaPocVal ); |
---|
1177 | |
---|
1178 | // Also adjust the POC value stored in the RPS of each such slice |
---|
1179 | for(Int j = rps->getNumberOfPictures(); j >= 0; j--) |
---|
1180 | { |
---|
1181 | rps->setPOC( j, rps->getPOC(j) - deltaPocVal ); |
---|
1182 | } |
---|
1183 | |
---|
1184 | slice->setRPS(rps); |
---|
1185 | |
---|
1186 | // Also adjust the value of refPOC |
---|
1187 | for(Int k = 0; k < 2; k++) // For List 0 and List 1 |
---|
1188 | { |
---|
1189 | RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0; |
---|
1190 | for(Int j = 0; j < slice->getNumRefIdx(list); j++) |
---|
1191 | { |
---|
1192 | slice->setRefPOC( slice->getRefPOC(list, j) - deltaPocVal, list, j); |
---|
1193 | } |
---|
1194 | } |
---|
1195 | } |
---|
1196 | } |
---|
1197 | iterPic++; |
---|
1198 | } |
---|
1199 | // Update the value of pocCRA |
---|
1200 | m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocCRA -= deltaPocVal; |
---|
1201 | } |
---|
1202 | } |
---|
1203 | |
---|
1204 | // Update value of POCLastDisplay |
---|
1205 | iPOCLastDisplay -= deltaPocVal; |
---|
1206 | } |
---|
1207 | Int maxPocLsb = 1 << sps->getBitsForPOC(); |
---|
1208 | Int slicePicOrderCntLsb = m_apcSlicePilot->getPicOrderCntLsb(); |
---|
1209 | |
---|
1210 | if( m_pocResettingFlag && (m_parseIdc == 1 || m_parseIdc == 2) ) |
---|
1211 | { |
---|
1212 | // Set poc for current slice |
---|
1213 | if( m_apcSlicePilot->getPocResetIdc() == 1 ) |
---|
1214 | { |
---|
1215 | m_apcSlicePilot->setPOC( slicePicOrderCntLsb ); |
---|
1216 | } |
---|
1217 | else if( m_apcSlicePilot->getPocResetIdc() == 2 ) |
---|
1218 | { |
---|
1219 | m_apcSlicePilot->setPOC( 0 ); |
---|
1220 | } |
---|
1221 | else |
---|
1222 | { |
---|
1223 | Int picOrderCntMsb = m_apcSlicePilot->getCurrMsb( slicePicOrderCntLsb, m_apcSlicePilot->getFullPocResetFlag() ? 0 : m_apcSlicePilot->getPocLsbVal(), 0 , maxPocLsb ); |
---|
1224 | m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb ); |
---|
1225 | } |
---|
1226 | } |
---|
1227 | else if (m_parseIdc == 3) |
---|
1228 | { |
---|
1229 | Int picOrderCntMsb = 0; |
---|
1230 | if( m_apcSlicePilot->getPocMsbValPresentFlag() ) |
---|
1231 | { |
---|
1232 | picOrderCntMsb = m_apcSlicePilot->getPocMsbVal() * maxPocLsb; |
---|
1233 | } |
---|
1234 | else if( m_apcSlicePilot->getIdrPicFlag() ) |
---|
1235 | { |
---|
1236 | picOrderCntMsb = 0; |
---|
1237 | } |
---|
1238 | else |
---|
1239 | { |
---|
1240 | Int prevPicOrderCntLsb = this->getPrevPicOrderCnt() & ( maxPocLsb - 1); |
---|
1241 | Int prevPicOrderCntMsb = this->getPrevPicOrderCnt() - prevPicOrderCntLsb; |
---|
1242 | picOrderCntMsb = m_apcSlicePilot->getCurrMsb(slicePicOrderCntLsb, prevPicOrderCntLsb, prevPicOrderCntMsb, maxPocLsb ); |
---|
1243 | } |
---|
1244 | m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb ); |
---|
1245 | } |
---|
1246 | |
---|
1247 | #if CONFORMANCE_BITSTREAM_FIX |
---|
1248 | xUpdatePreviousTid0POC(m_apcSlicePilot); |
---|
1249 | #endif |
---|
1250 | |
---|
1251 | //detect lost reference picture and insert copy of earlier frame. |
---|
1252 | { |
---|
1253 | Int lostPoc; |
---|
1254 | while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0) |
---|
1255 | { |
---|
1256 | xCreateLostPicture(lostPoc-1); |
---|
1257 | } |
---|
1258 | } |
---|
1259 | |
---|
1260 | if( m_parseIdc == 1 || m_parseIdc == 3) |
---|
1261 | { |
---|
1262 | // Adjust prevPicOrderCnt |
---|
1263 | if( !m_apcSlicePilot->getRaslPicFlag() |
---|
1264 | && !m_apcSlicePilot->getRadlPicFlag() |
---|
1265 | && (m_apcSlicePilot->getNalUnitType() % 2 == 1 |
---|
1266 | #if CONFORMANCE_BITSTREAM_FIX |
---|
1267 | || (m_apcSlicePilot->getNalUnitType() > 15 && m_apcSlicePilot->getNalUnitType() < 24)) |
---|
1268 | #else |
---|
1269 | ) |
---|
1270 | #endif |
---|
1271 | && ( nalu.m_temporalId == 0 ) |
---|
1272 | && !m_apcSlicePilot->getDiscardableFlag() ) |
---|
1273 | { |
---|
1274 | for( UInt i = 0; i < numAffectedLayers; i++ ) |
---|
1275 | { |
---|
1276 | m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt(m_apcSlicePilot->getPOC()); |
---|
1277 | } |
---|
1278 | } |
---|
1279 | else if( m_apcSlicePilot->getPocResetIdc() == 3 ) |
---|
1280 | { |
---|
1281 | if( !m_firstPicInLayerDecodedFlag || (m_firstPicInLayerDecodedFlag && m_pocResettingFlag) ) |
---|
1282 | { |
---|
1283 | for( UInt i = 0; i < numAffectedLayers; i++ ) |
---|
1284 | { |
---|
1285 | m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag() ? 0 : m_apcSlicePilot->getPocLsbVal() ); |
---|
1286 | } |
---|
1287 | } |
---|
1288 | } |
---|
1289 | m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS()); |
---|
1290 | } |
---|
1291 | |
---|
1292 | if( !m_apcSlicePilot->getDependentSliceSegmentFlag() && (bNewPOC || m_layerId!=m_uiPrevLayerId || m_parseIdc == 1) && !m_bFirstSliceInSequence ) |
---|
1293 | #else |
---|
1294 | if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence ) |
---|
1295 | #endif |
---|
1296 | { |
---|
1297 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
1298 | #if ENC_DEC_TRACE |
---|
1299 | //rewind the trace counter since we didn't actually decode the slice |
---|
1300 | g_nSymbolCounter = originalSymbolCount; |
---|
1301 | #endif |
---|
1302 | curLayerId = m_uiPrevLayerId; |
---|
1303 | m_uiPrevLayerId = m_layerId; |
---|
1304 | return true; |
---|
1305 | } |
---|
1306 | |
---|
1307 | m_parseIdc = -1; |
---|
1308 | |
---|
1309 | if( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 ) |
---|
1310 | { |
---|
1311 | //update all pics in the DPB such that they cannot be used for TMPV ref |
---|
1312 | TComList<TComPic*>::iterator iterRefPic = m_cListPic.begin(); |
---|
1313 | |
---|
1314 | while( iterRefPic != m_cListPic.end() ) |
---|
1315 | { |
---|
1316 | TComPic *refPic = *iterRefPic; |
---|
1317 | if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() ) |
---|
1318 | { |
---|
1319 | for( Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i-- ) |
---|
1320 | { |
---|
1321 | |
---|
1322 | TComSlice *refSlice = refPic->getSlice(i); |
---|
1323 | refSlice->setAvailableForTMVPRefFlag( false ); |
---|
1324 | } |
---|
1325 | } |
---|
1326 | iterRefPic++; |
---|
1327 | } |
---|
1328 | } |
---|
1329 | m_apcSlicePilot->setAvailableForTMVPRefFlag( true ); |
---|
1330 | |
---|
1331 | // Initialize ILRP if needed, only for the current layer |
---|
1332 | // ILRP intialization should go along with activation of parameters sets, |
---|
1333 | // although activation of parameter sets itself need not be done for each and every slice!!! |
---|
1334 | xInitILRP(m_apcSlicePilot); |
---|
1335 | |
---|
1336 | #else //SVC_EXTENSION |
---|
1337 | //we should only get a different poc for a new picture (with CTU address==0) |
---|
1338 | if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() != 0)) |
---|
1339 | { |
---|
1340 | printf ("Warning, the first slice of a picture might have been lost!\n"); |
---|
1341 | } |
---|
1342 | |
---|
1343 | // exit when a new picture is found |
---|
1344 | if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() == 0 && !m_bFirstSliceInPicture) ) |
---|
1345 | { |
---|
1346 | if (m_prevPOC >= m_pocRandomAccess) |
---|
1347 | { |
---|
1348 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
1349 | #if ENC_DEC_TRACE |
---|
1350 | //rewind the trace counter since we didn't actually decode the slice |
---|
1351 | g_nSymbolCounter = originalSymbolCount; |
---|
1352 | #endif |
---|
1353 | return true; |
---|
1354 | } |
---|
1355 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
1356 | } |
---|
1357 | |
---|
1358 | //detect lost reference picture and insert copy of earlier frame. |
---|
1359 | { |
---|
1360 | Int lostPoc; |
---|
1361 | while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0) |
---|
1362 | { |
---|
1363 | xCreateLostPicture(lostPoc-1); |
---|
1364 | } |
---|
1365 | } |
---|
1366 | #endif //SVC_EXTENSION |
---|
1367 | |
---|
1368 | if (!m_apcSlicePilot->getDependentSliceSegmentFlag()) |
---|
1369 | { |
---|
1370 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
1371 | #if SVC_EXTENSION |
---|
1372 | curLayerId = m_layerId; |
---|
1373 | m_uiPrevLayerId = m_layerId; |
---|
1374 | #endif |
---|
1375 | } |
---|
1376 | |
---|
1377 | // actual decoding starts here |
---|
1378 | xActivateParameterSets(); |
---|
1379 | |
---|
1380 | m_bFirstSliceInSequence = false; |
---|
1381 | m_bFirstSliceInBitstream = false; |
---|
1382 | |
---|
1383 | TComSlice* pcSlice = m_pcPic->getPicSym()->getSlice(m_uiSliceIdx); |
---|
1384 | |
---|
1385 | #if SVC_EXTENSION |
---|
1386 | if (m_bFirstSliceInPicture) |
---|
1387 | { |
---|
1388 | #if AVC_BASE |
---|
1389 | if( m_layerId > 0 && vps->getNonHEVCBaseLayerFlag() ) |
---|
1390 | { |
---|
1391 | TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin()); |
---|
1392 | pBLPic->getSlice(0)->setReferenced(true); |
---|
1393 | fstream* pFile = m_ppcTDecTop[0]->getBLReconFile(); |
---|
1394 | |
---|
1395 | if( pFile->good() ) |
---|
1396 | { |
---|
1397 | Bool is16bit = pBLPic->getSlice(0)->getBitDepth(CHANNEL_TYPE_LUMA) > 8 || pBLPic->getSlice(0)->getBitDepth(CHANNEL_TYPE_CHROMA) > 8; |
---|
1398 | UInt uiWidth = pBLPic->getPicYuvRec()->getWidth(COMPONENT_Y); |
---|
1399 | UInt uiHeight = pBLPic->getPicYuvRec()->getHeight(COMPONENT_Y); |
---|
1400 | |
---|
1401 | Int len = uiWidth * (is16bit ? 2 : 1); |
---|
1402 | UChar *buf = new UChar[len]; |
---|
1403 | |
---|
1404 | UInt64 uiPos = (UInt64) pcSlice->getPOC() * uiWidth * uiHeight * 3 / 2; |
---|
1405 | if( is16bit ) |
---|
1406 | { |
---|
1407 | uiPos <<= 1; |
---|
1408 | } |
---|
1409 | |
---|
1410 | pFile->seekg((UInt)uiPos, ios::beg ); |
---|
1411 | |
---|
1412 | // read Y component |
---|
1413 | Pel* pPel = pBLPic->getPicYuvRec()->getAddr(COMPONENT_Y); |
---|
1414 | UInt uiStride = pBLPic->getPicYuvRec()->getStride(COMPONENT_Y); |
---|
1415 | for( Int i = 0; i < uiHeight; i++ ) |
---|
1416 | { |
---|
1417 | pFile->read(reinterpret_cast<TChar*>(buf), len); |
---|
1418 | |
---|
1419 | if( !is16bit ) |
---|
1420 | { |
---|
1421 | for (Int x = 0; x < uiWidth; x++) |
---|
1422 | { |
---|
1423 | pPel[x] = buf[x]; |
---|
1424 | } |
---|
1425 | } |
---|
1426 | else |
---|
1427 | { |
---|
1428 | for (Int x = 0; x < uiWidth; x++) |
---|
1429 | { |
---|
1430 | pPel[x] = (buf[2*x+1] << 8) | buf[2*x]; |
---|
1431 | } |
---|
1432 | } |
---|
1433 | |
---|
1434 | pPel += uiStride; |
---|
1435 | } |
---|
1436 | |
---|
1437 | len >>= 1; |
---|
1438 | uiWidth >>= 1; |
---|
1439 | uiHeight >>= 1; |
---|
1440 | |
---|
1441 | // read Cb component |
---|
1442 | pPel = pBLPic->getPicYuvRec()->getAddr(COMPONENT_Cb); |
---|
1443 | uiStride = pBLPic->getPicYuvRec()->getStride(COMPONENT_Cb); |
---|
1444 | for( Int i = 0; i < uiHeight; i++ ) |
---|
1445 | { |
---|
1446 | pFile->read(reinterpret_cast<TChar*>(buf), len); |
---|
1447 | |
---|
1448 | if( !is16bit ) |
---|
1449 | { |
---|
1450 | for( Int x = 0; x < uiWidth; x++ ) |
---|
1451 | { |
---|
1452 | pPel[x] = buf[x]; |
---|
1453 | } |
---|
1454 | } |
---|
1455 | else |
---|
1456 | { |
---|
1457 | for( Int x = 0; x < uiWidth; x++ ) |
---|
1458 | { |
---|
1459 | pPel[x] = (buf[2*x+1] << 8) | buf[2*x]; |
---|
1460 | } |
---|
1461 | } |
---|
1462 | |
---|
1463 | pPel += uiStride; |
---|
1464 | } |
---|
1465 | |
---|
1466 | // read Cr component |
---|
1467 | pPel = pBLPic->getPicYuvRec()->getAddr(COMPONENT_Cr); |
---|
1468 | uiStride = pBLPic->getPicYuvRec()->getStride(COMPONENT_Cr); |
---|
1469 | for( Int i = 0; i < uiHeight; i++ ) |
---|
1470 | { |
---|
1471 | pFile->read(reinterpret_cast<TChar*>(buf), len); |
---|
1472 | |
---|
1473 | if( !is16bit ) |
---|
1474 | { |
---|
1475 | for( Int x = 0; x < uiWidth; x++ ) |
---|
1476 | { |
---|
1477 | pPel[x] = buf[x]; |
---|
1478 | } |
---|
1479 | } |
---|
1480 | else |
---|
1481 | { |
---|
1482 | for( Int x = 0; x < uiWidth; x++ ) |
---|
1483 | { |
---|
1484 | pPel[x] = (buf[2*x+1] << 8) | buf[2*x]; |
---|
1485 | } |
---|
1486 | } |
---|
1487 | |
---|
1488 | pPel += uiStride; |
---|
1489 | } |
---|
1490 | |
---|
1491 | delete[] buf; |
---|
1492 | } |
---|
1493 | } |
---|
1494 | #endif |
---|
1495 | |
---|
1496 | if ( m_layerId == 0 && pcSlice->getRapPicFlag() && getNoClrasOutputFlag() ) |
---|
1497 | { |
---|
1498 | for (UInt i = 0; i < vps->getMaxLayers(); i++) |
---|
1499 | { |
---|
1500 | m_ppcTDecTop[i]->setLayerInitializedFlag(false); |
---|
1501 | m_ppcTDecTop[i]->setFirstPicInLayerDecodedFlag(false); |
---|
1502 | } |
---|
1503 | } |
---|
1504 | |
---|
1505 | xCheckLayerReset(); |
---|
1506 | xSetLayerInitializedFlag(); |
---|
1507 | |
---|
1508 | #if SVC_POC |
---|
1509 | m_pcPic->setCurrAuFlag( true ); |
---|
1510 | |
---|
1511 | if( m_pcPic->getLayerId() > 0 && pcSlice->isIDR() && !m_nonBaseIdrPresentFlag ) |
---|
1512 | { |
---|
1513 | // IDR picture with nuh_layer_id > 0 present |
---|
1514 | m_nonBaseIdrPresentFlag = true; |
---|
1515 | m_nonBaseIdrType = (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL); |
---|
1516 | } |
---|
1517 | else |
---|
1518 | { |
---|
1519 | if( pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL ) |
---|
1520 | { |
---|
1521 | // Picture with nal_unit_type not equal IDR_W_RADL present |
---|
1522 | m_picNonIdrWithRadlPresentFlag = true; |
---|
1523 | } |
---|
1524 | if( pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
---|
1525 | { |
---|
1526 | // Picture with nal_unit_type not equal IDR_N_LP present |
---|
1527 | m_picNonIdrNoLpPresentFlag = true; |
---|
1528 | } |
---|
1529 | } |
---|
1530 | if( !m_checkPocRestrictionsForCurrAu ) // Will be true for the first slice/picture of the AU |
---|
1531 | { |
---|
1532 | m_checkPocRestrictionsForCurrAu = true; |
---|
1533 | m_pocResetIdcOrCurrAu = pcSlice->getPocResetIdc(); |
---|
1534 | if( m_pcPic->getLayerId() == 0 ) |
---|
1535 | { |
---|
1536 | // Base layer picture is present |
---|
1537 | m_baseLayerPicPresentFlag = true; |
---|
1538 | if( pcSlice->isIRAP() ) |
---|
1539 | { |
---|
1540 | // Base layer picture is IRAP |
---|
1541 | m_baseLayerIrapFlag = true; |
---|
1542 | } |
---|
1543 | if( pcSlice->isIDR() ) |
---|
1544 | { |
---|
1545 | // Base layer picture is IDR |
---|
1546 | m_baseLayerIdrFlag = true; |
---|
1547 | } |
---|
1548 | else |
---|
1549 | { |
---|
1550 | if( vps->getBaseLayerInternalFlag()) |
---|
1551 | { |
---|
1552 | /* When the picture with nuh_layer_id equal to 0 in an access unit is not an IDR picture |
---|
1553 | and vps_base_layer_internal_flag is equal to 1, the value of poc_reset_idc shall not be equal to 2 |
---|
1554 | for any picture in the access unit. */ |
---|
1555 | assert( pcSlice->getPocResetIdc() != 2 ); |
---|
1556 | } |
---|
1557 | } |
---|
1558 | } |
---|
1559 | } |
---|
1560 | else |
---|
1561 | { |
---|
1562 | // The value of poc_reset_idc of all coded pictures that are present in the bitstream in an access unit shall be the same. |
---|
1563 | assert( m_pocResetIdcOrCurrAu == pcSlice->getPocResetIdc() ); |
---|
1564 | |
---|
1565 | /* When the picture in an access unit with nuh_layer_id equal to 0 is an IRAP picture and vps_base_layer_internal_flag is equal to 1 |
---|
1566 | and there is at least one other picture in the same access unit that is not an IRAP picture, |
---|
1567 | the value of poc_reset_idc shall be equal to 1 or 2 for all pictures in the access unit. */ |
---|
1568 | if( m_baseLayerPicPresentFlag && m_baseLayerIrapFlag && !pcSlice->isIRAP() && vps->getBaseLayerInternalFlag() ) |
---|
1569 | { |
---|
1570 | assert( pcSlice->getPocResetIdc() == 1 || pcSlice->getPocResetIdc() == 2 ); |
---|
1571 | } |
---|
1572 | |
---|
1573 | /* When the picture with nuh_layer_id equal to 0 in an access unit is an IDR picture and |
---|
1574 | vps_base_layer_internal_flag is equal to 1 and there is at least one non-IDR picture in the same access unit, |
---|
1575 | the value of poc_reset_idc shall be equal to 2 for all pictures in the access unit. */ |
---|
1576 | if( m_baseLayerPicPresentFlag && m_baseLayerIdrFlag && !pcSlice->isIDR() && vps->getBaseLayerInternalFlag() ) |
---|
1577 | { |
---|
1578 | assert( pcSlice->getPocResetIdc() == 2 ); |
---|
1579 | } |
---|
1580 | |
---|
1581 | /* When there is at least one picture that has nuh_layer_id greater than 0 and that is an IDR picture |
---|
1582 | with a particular value of nal_unit_type in an access unit and there is at least one other coded picture |
---|
1583 | that is present in the bitstream in the same access unit with a different value of nal_unit_type, |
---|
1584 | the value of poc_reset_idc shall be equal to 1 or 2 for all pictures in the access unit. */ |
---|
1585 | if( m_nonBaseIdrPresentFlag && ( |
---|
1586 | ( m_nonBaseIdrType == 1 && m_picNonIdrWithRadlPresentFlag ) || |
---|
1587 | ( m_nonBaseIdrType == 0 && m_picNonIdrNoLpPresentFlag ) |
---|
1588 | )) |
---|
1589 | { |
---|
1590 | assert( pcSlice->getPocResetIdc() == 1 || pcSlice->getPocResetIdc() == 2 ); |
---|
1591 | } |
---|
1592 | } |
---|
1593 | #endif |
---|
1594 | } |
---|
1595 | #endif //SVC_EXTENSION |
---|
1596 | |
---|
1597 | // When decoding the slice header, the stored start and end addresses were actually RS addresses, not TS addresses. |
---|
1598 | // Now, having set up the maps, convert them to the correct form. |
---|
1599 | pcSlice->setSliceSegmentCurStartCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()) ); |
---|
1600 | pcSlice->setSliceSegmentCurEndCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurEndCtuTsAddr()) ); |
---|
1601 | if(!pcSlice->getDependentSliceSegmentFlag()) |
---|
1602 | { |
---|
1603 | pcSlice->setSliceCurStartCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurStartCtuTsAddr())); |
---|
1604 | pcSlice->setSliceCurEndCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurEndCtuTsAddr())); |
---|
1605 | } |
---|
1606 | |
---|
1607 | m_pcPic->setTLayer(nalu.m_temporalId); |
---|
1608 | |
---|
1609 | #if SVC_EXTENSION |
---|
1610 | m_pcPic->setLayerId(nalu.m_nuhLayerId); |
---|
1611 | pcSlice->setLayerId(nalu.m_nuhLayerId); |
---|
1612 | pcSlice->setPic(m_pcPic); |
---|
1613 | #endif |
---|
1614 | |
---|
1615 | if (!pcSlice->getDependentSliceSegmentFlag()) |
---|
1616 | { |
---|
1617 | pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic ); |
---|
1618 | // Set reference list |
---|
1619 | #if SVC_EXTENSION |
---|
1620 | if (m_layerId == 0) |
---|
1621 | #endif |
---|
1622 | pcSlice->setRefPicList( m_cListPic, true ); |
---|
1623 | |
---|
1624 | #if SVC_EXTENSION |
---|
1625 | // Create upsampling reference layer pictures for all possible dependent layers and do it only once for the first slice. |
---|
1626 | // Other slices might choose which reference pictures to be used for inter-layer prediction |
---|
1627 | if( m_layerId > 0 && m_uiSliceIdx == 0 && ( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || pcSlice->isIRAP() ) ) |
---|
1628 | { |
---|
1629 | // create buffers for scaling factors |
---|
1630 | if( pcSlice->getNumILRRefIdx() ) |
---|
1631 | { |
---|
1632 | m_pcPic->createMvScalingFactor(pcSlice->getNumILRRefIdx()); |
---|
1633 | m_pcPic->createPosScalingFactor(pcSlice->getNumILRRefIdx()); |
---|
1634 | } |
---|
1635 | |
---|
1636 | for( Int i = 0; i < pcSlice->getNumILRRefIdx(); i++ ) |
---|
1637 | { |
---|
1638 | UInt refLayerIdc = i; |
---|
1639 | UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc); |
---|
1640 | #if AVC_BASE |
---|
1641 | if( refLayerId == 0 && m_parameterSetManager.getActiveVPS()->getNonHEVCBaseLayerFlag() ) |
---|
1642 | { |
---|
1643 | TComPic* pic = *m_ppcTDecTop[0]->getListPic()->begin(); |
---|
1644 | |
---|
1645 | if( pic ) |
---|
1646 | { |
---|
1647 | pcSlice->setBaseColPic ( refLayerIdc, pic ); |
---|
1648 | } |
---|
1649 | else |
---|
1650 | { |
---|
1651 | continue; |
---|
1652 | } |
---|
1653 | } |
---|
1654 | else |
---|
1655 | { |
---|
1656 | TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc ); |
---|
1657 | TComList<TComPic*> *cListPic = pcTDecTop->getListPic(); |
---|
1658 | if( !pcSlice->setBaseColPic ( *cListPic, refLayerIdc ) ) |
---|
1659 | { |
---|
1660 | continue; |
---|
1661 | } |
---|
1662 | } |
---|
1663 | #else |
---|
1664 | TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc ); |
---|
1665 | TComList<TComPic*> *cListPic = pcTDecTop->getListPic(); |
---|
1666 | pcSlice->setBaseColPic ( *cListPic, refLayerIdc ); |
---|
1667 | #endif |
---|
1668 | |
---|
1669 | const Window &scalEL = pcSlice->getPPS()->getScaledRefLayerWindowForLayer(refLayerId); |
---|
1670 | const Window &windowRL = pcSlice->getPPS()->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc)); |
---|
1671 | Int widthBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth(COMPONENT_Y) - windowRL.getWindowLeftOffset() - windowRL.getWindowRightOffset(); |
---|
1672 | Int heightBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight(COMPONENT_Y) - windowRL.getWindowTopOffset() - windowRL.getWindowBottomOffset(); |
---|
1673 | Int widthEL = m_pcPic->getPicYuvRec()->getWidth(COMPONENT_Y) - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset(); |
---|
1674 | Int heightEL = m_pcPic->getPicYuvRec()->getHeight(COMPONENT_Y) - scalEL.getWindowTopOffset() - scalEL.getWindowBottomOffset(); |
---|
1675 | |
---|
1676 | // conformance check: the values of RefLayerRegionWidthInSamplesY, RefLayerRegionHeightInSamplesY, ScaledRefRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater than 0 |
---|
1677 | assert(widthEL > 0 && heightEL > 0 && widthBL > 0 && widthEL > 0); |
---|
1678 | |
---|
1679 | // conformance check: ScaledRefRegionWidthInSamplesY shall be greater or equal to RefLayerRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater or equal to RefLayerRegionHeightInSamplesY |
---|
1680 | assert(widthEL >= widthBL && heightEL >= heightBL); |
---|
1681 | |
---|
1682 | // conformance check: when ScaledRefRegionWidthInSamplesY is equal to RefLayerRegionWidthInSamplesY, PhaseHorY shall be equal to 0, when ScaledRefRegionWidthInSamplesC is equal to RefLayerRegionWidthInSamplesC, PhaseHorC shall be equal to 0, when ScaledRefRegionHeightInSamplesY is equal to RefLayerRegionHeightInSamplesY, PhaseVerY shall be equal to 0, and when ScaledRefRegionHeightInSamplesC is equal to RefLayerRegionHeightInSamplesC, PhaseVerC shall be equal to 0. |
---|
1683 | const ResamplingPhase &resamplingPhase = pcSlice->getPPS()->getResamplingPhase( refLayerId ); |
---|
1684 | |
---|
1685 | assert( ( (widthEL != widthBL) || (resamplingPhase.phaseHorLuma == 0 && resamplingPhase.phaseHorChroma == 0) ) |
---|
1686 | && ( (heightEL != heightBL) || (resamplingPhase.phaseVerLuma == 0 && resamplingPhase.phaseVerChroma == 0) ) ); |
---|
1687 | |
---|
1688 | m_pcPic->setMvScalingFactor( refLayerIdc, |
---|
1689 | widthEL == widthBL ? MV_SCALING_FACTOR_1X : Clip3(-4096, 4095, ((widthEL << 8) + (widthBL >> 1)) / widthBL), |
---|
1690 | heightEL == heightBL ? MV_SCALING_FACTOR_1X : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL) ); |
---|
1691 | |
---|
1692 | m_pcPic->setPosScalingFactor( refLayerIdc, |
---|
1693 | ((widthBL << 16) + (widthEL >> 1)) / widthEL, |
---|
1694 | ((heightBL << 16) + (heightEL >> 1)) / heightEL ); |
---|
1695 | #if CGS_3D_ASYMLUT |
---|
1696 | TComPicYuv* pBaseColRec = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(); |
---|
1697 | if( pcSlice->getPPS()->getCGSFlag() && m_c3DAsymLUTPPS.isRefLayer( pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc) ) ) |
---|
1698 | { |
---|
1699 | assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepth(CHANNEL_TYPE_LUMA) == m_c3DAsymLUTPPS.getInputBitDepthY() ); |
---|
1700 | assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepth(CHANNEL_TYPE_CHROMA) == m_c3DAsymLUTPPS.getInputBitDepthC() ); |
---|
1701 | assert( pcSlice->getBitDepth(CHANNEL_TYPE_LUMA) >= m_c3DAsymLUTPPS.getOutputBitDepthY() ); |
---|
1702 | assert( pcSlice->getBitDepth(CHANNEL_TYPE_LUMA) >= m_c3DAsymLUTPPS.getOutputBitDepthC() ); |
---|
1703 | |
---|
1704 | if( !m_pColorMappedPic ) |
---|
1705 | { |
---|
1706 | initAsymLut(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)); |
---|
1707 | } |
---|
1708 | |
---|
1709 | m_c3DAsymLUTPPS.colorMapping( pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), m_pColorMappedPic ); |
---|
1710 | pBaseColRec = m_pColorMappedPic; |
---|
1711 | } |
---|
1712 | #endif |
---|
1713 | |
---|
1714 | if( m_pcPic->isSpatialEnhLayer(refLayerIdc) ) |
---|
1715 | { |
---|
1716 | // check for the sample prediction picture type |
---|
1717 | if( pcSlice->getVPS()->isSamplePredictionType( pcSlice->getVPS()->getLayerIdxInVps(m_layerId), pcSlice->getVPS()->getLayerIdxInVps(refLayerId) ) ) |
---|
1718 | { |
---|
1719 | m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepth(CHANNEL_TYPE_LUMA), pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepth(CHANNEL_TYPE_CHROMA)); |
---|
1720 | } |
---|
1721 | } |
---|
1722 | else |
---|
1723 | { |
---|
1724 | m_pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() ); |
---|
1725 | } |
---|
1726 | pcSlice->setFullPelBaseRec ( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc) ); |
---|
1727 | } |
---|
1728 | } |
---|
1729 | |
---|
1730 | if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() ) |
---|
1731 | { |
---|
1732 | for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
---|
1733 | { |
---|
1734 | UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i); |
---|
1735 | #if AVC_BASE |
---|
1736 | if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && pcSlice->getVPS()->getNonHEVCBaseLayerFlag() ) |
---|
1737 | { |
---|
1738 | pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() ); |
---|
1739 | } |
---|
1740 | else |
---|
1741 | { |
---|
1742 | TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc ); |
---|
1743 | TComList<TComPic*> *cListPic = pcTDecTop->getListPic(); |
---|
1744 | pcSlice->setBaseColPic ( *cListPic, refLayerIdc ); |
---|
1745 | } |
---|
1746 | #else |
---|
1747 | TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc ); |
---|
1748 | TComList<TComPic*> *cListPic = pcTDecTop->getListPic(); |
---|
1749 | pcSlice->setBaseColPic ( *cListPic, refLayerIdc ); |
---|
1750 | #endif |
---|
1751 | |
---|
1752 | pcSlice->setFullPelBaseRec ( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc) ); |
---|
1753 | } |
---|
1754 | |
---|
1755 | pcSlice->setILRPic( m_cIlpPic ); |
---|
1756 | |
---|
1757 | pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic); |
---|
1758 | } |
---|
1759 | else if ( m_layerId > 0 ) |
---|
1760 | { |
---|
1761 | pcSlice->setRefPicList( m_cListPic, false, NULL); |
---|
1762 | } |
---|
1763 | |
---|
1764 | // motion field mapping constraint |
---|
1765 | if( pcSlice->getMFMEnabledFlag() ) |
---|
1766 | { |
---|
1767 | TComPic* refPic = pcSlice->getRefPic( pcSlice->getSliceType() == B_SLICE ? ( RefPicList )( 1 - pcSlice->getColFromL0Flag() ) : REF_PIC_LIST_0 , pcSlice->getColRefIdx() ); |
---|
1768 | |
---|
1769 | assert( refPic ); |
---|
1770 | |
---|
1771 | Int refLayerId = refPic->getLayerId(); |
---|
1772 | |
---|
1773 | if( refLayerId != pcSlice->getLayerId() ) |
---|
1774 | { |
---|
1775 | TComPic* pColBasePic = pcSlice->getBaseColPic( *m_ppcTDecTop[refLayerId]->getListPic() ); |
---|
1776 | assert( pColBasePic->checkSameRefInfo() == true ); |
---|
1777 | } |
---|
1778 | } |
---|
1779 | |
---|
1780 | if( m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag() && ( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || pcSlice->isIRAP() ) ) |
---|
1781 | { |
---|
1782 | for(Int dependentLayerIdx = 0; dependentLayerIdx < pcSlice->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++) |
---|
1783 | { |
---|
1784 | TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic(); |
---|
1785 | TComPic* refpicLayer = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() ); |
---|
1786 | if(refpicLayer && pcSlice->isIRAP()) |
---|
1787 | { |
---|
1788 | assert(pcSlice->getNalUnitType() == refpicLayer->getSlice(0)->getNalUnitType()); |
---|
1789 | } |
---|
1790 | } |
---|
1791 | } |
---|
1792 | |
---|
1793 | if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() ) |
---|
1794 | { |
---|
1795 | TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx()); |
---|
1796 | |
---|
1797 | assert( refPic ); |
---|
1798 | assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true ); |
---|
1799 | |
---|
1800 | // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture, |
---|
1801 | // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture. |
---|
1802 | if( refPic->isILR(pcSlice->getLayerId()) ) |
---|
1803 | { |
---|
1804 | assert( pcSlice->getVPS()->isMotionPredictionType( pcSlice->getVPS()->getLayerIdxInVps(m_layerId), refPic->getLayerIdx() ) ); |
---|
1805 | } |
---|
1806 | } |
---|
1807 | #endif //SVC_EXTENSION |
---|
1808 | |
---|
1809 | // For generalized B |
---|
1810 | // note: maybe not existed case (always L0 is copied to L1 if L1 is empty) |
---|
1811 | if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0) |
---|
1812 | { |
---|
1813 | Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0); |
---|
1814 | pcSlice->setNumRefIdx ( REF_PIC_LIST_1, iNumRefIdx ); |
---|
1815 | |
---|
1816 | for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++) |
---|
1817 | { |
---|
1818 | pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx); |
---|
1819 | } |
---|
1820 | } |
---|
1821 | if (!pcSlice->isIntra()) |
---|
1822 | { |
---|
1823 | Bool bLowDelay = true; |
---|
1824 | Int iCurrPOC = pcSlice->getPOC(); |
---|
1825 | Int iRefIdx = 0; |
---|
1826 | |
---|
1827 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++) |
---|
1828 | { |
---|
1829 | if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC ) |
---|
1830 | { |
---|
1831 | bLowDelay = false; |
---|
1832 | } |
---|
1833 | } |
---|
1834 | if (pcSlice->isInterB()) |
---|
1835 | { |
---|
1836 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++) |
---|
1837 | { |
---|
1838 | if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC ) |
---|
1839 | { |
---|
1840 | bLowDelay = false; |
---|
1841 | } |
---|
1842 | } |
---|
1843 | } |
---|
1844 | |
---|
1845 | pcSlice->setCheckLDC(bLowDelay); |
---|
1846 | } |
---|
1847 | |
---|
1848 | //--------------- |
---|
1849 | pcSlice->setRefPOCList(); |
---|
1850 | } |
---|
1851 | |
---|
1852 | m_pcPic->setCurrSliceIdx(m_uiSliceIdx); |
---|
1853 | if(pcSlice->getSPS()->getScalingListFlag()) |
---|
1854 | { |
---|
1855 | TComScalingList scalingList; |
---|
1856 | |
---|
1857 | #if SVC_EXTENSION |
---|
1858 | if( pcSlice->getPPS()->getInferScalingListFlag() ) |
---|
1859 | { |
---|
1860 | const TComPPS *refPps = m_ppcTDecTop[pcSlice->getPPS()->getScalingListRefLayerId()]->getParameterSetManager()->getActivePPS(); assert( refPps != NULL ); |
---|
1861 | scalingList = refPps->getScalingList(); |
---|
1862 | } |
---|
1863 | else |
---|
1864 | #endif |
---|
1865 | if(pcSlice->getPPS()->getScalingListPresentFlag()) |
---|
1866 | { |
---|
1867 | scalingList = pcSlice->getPPS()->getScalingList(); |
---|
1868 | } |
---|
1869 | #if SVC_EXTENSION |
---|
1870 | else if( pcSlice->getSPS()->getInferScalingListFlag() ) |
---|
1871 | { |
---|
1872 | const TComSPS *refSps = m_ppcTDecTop[pcSlice->getSPS()->getScalingListRefLayerId()]->getParameterSetManager()->getActiveSPS(); assert( refSps != NULL ); |
---|
1873 | scalingList = refSps->getScalingList(); |
---|
1874 | } |
---|
1875 | #endif |
---|
1876 | else if (pcSlice->getSPS()->getScalingListPresentFlag()) |
---|
1877 | { |
---|
1878 | scalingList = pcSlice->getSPS()->getScalingList(); |
---|
1879 | } |
---|
1880 | else |
---|
1881 | { |
---|
1882 | scalingList.setDefaultScalingList(); |
---|
1883 | } |
---|
1884 | m_cTrQuant.setScalingListDec(scalingList); |
---|
1885 | m_cTrQuant.setUseScalingList(true); |
---|
1886 | } |
---|
1887 | else |
---|
1888 | { |
---|
1889 | const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] = |
---|
1890 | { |
---|
1891 | pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA), |
---|
1892 | pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA) |
---|
1893 | }; |
---|
1894 | #if SVC_EXTENSION |
---|
1895 | m_cTrQuant.setFlatScalingList(maxLog2TrDynamicRange, pcSlice->getBitDepths()); |
---|
1896 | #else |
---|
1897 | m_cTrQuant.setFlatScalingList(maxLog2TrDynamicRange, pcSlice->getSPS()->getBitDepths()); |
---|
1898 | #endif |
---|
1899 | m_cTrQuant.setUseScalingList(false); |
---|
1900 | } |
---|
1901 | |
---|
1902 | // Decode a picture |
---|
1903 | m_cGopDecoder.decompressSlice(&(nalu.getBitstream()), m_pcPic); |
---|
1904 | |
---|
1905 | #if SVC_EXTENSION |
---|
1906 | setFirstPicInLayerDecodedFlag(true); |
---|
1907 | m_lastPicHasEos = false; |
---|
1908 | #endif |
---|
1909 | |
---|
1910 | m_bFirstSliceInPicture = false; |
---|
1911 | m_uiSliceIdx++; |
---|
1912 | |
---|
1913 | return false; |
---|
1914 | } |
---|
1915 | |
---|
1916 | Void TDecTop::xDecodeVPS(const std::vector<UChar> &naluData) |
---|
1917 | { |
---|
1918 | TComVPS* vps = new TComVPS(); |
---|
1919 | |
---|
1920 | m_cEntropyDecoder.decodeVPS( vps ); |
---|
1921 | m_parameterSetManager.storeVPS(vps, naluData); |
---|
1922 | #if SVC_EXTENSION |
---|
1923 | checkValueOfTargetOutputLayerSetIdx(vps); |
---|
1924 | |
---|
1925 | #if AVC_BASE |
---|
1926 | if( vps->getNonHEVCBaseLayerFlag() ) |
---|
1927 | { |
---|
1928 | m_ppcTDecTop[0]->getListPic()->pushBack( m_ppcTDecTop[0]->getBlPic() ); |
---|
1929 | |
---|
1930 | if( !m_ppcTDecTop[0]->getBLReconFile()->good() ) |
---|
1931 | { |
---|
1932 | printf( "Base layer YUV input reading error\n" ); |
---|
1933 | exit(EXIT_FAILURE); |
---|
1934 | } |
---|
1935 | } |
---|
1936 | #endif |
---|
1937 | |
---|
1938 | xDeriveSmallestLayerId(vps); |
---|
1939 | #endif |
---|
1940 | } |
---|
1941 | |
---|
1942 | Void TDecTop::xDecodeSPS(const std::vector<UChar> &naluData) |
---|
1943 | { |
---|
1944 | TComSPS* sps = new TComSPS(); |
---|
1945 | #if O0043_BEST_EFFORT_DECODING |
---|
1946 | sps->setForceDecodeBitDepth(m_forceDecodeBitDepth); |
---|
1947 | #endif |
---|
1948 | #if SVC_EXTENSION |
---|
1949 | sps->setLayerId(m_layerId); |
---|
1950 | #endif |
---|
1951 | m_cEntropyDecoder.decodeSPS( sps ); |
---|
1952 | m_parameterSetManager.storeSPS(sps, naluData); |
---|
1953 | } |
---|
1954 | |
---|
1955 | #if CGS_3D_ASYMLUT |
---|
1956 | Void TDecTop::xDecodePPS( const std::vector<UChar> &naluData, TCom3DAsymLUT * pc3DAsymLUT ) |
---|
1957 | #else |
---|
1958 | Void TDecTop::xDecodePPS(const std::vector<UChar> &naluData) |
---|
1959 | #endif |
---|
1960 | { |
---|
1961 | TComPPS* pps = new TComPPS(); |
---|
1962 | |
---|
1963 | #if SVC_EXTENSION |
---|
1964 | pps->setLayerId( m_layerId ); |
---|
1965 | #endif |
---|
1966 | #if CGS_3D_ASYMLUT |
---|
1967 | m_cEntropyDecoder.decodePPS( pps, pc3DAsymLUT, m_layerId ); |
---|
1968 | #else |
---|
1969 | m_cEntropyDecoder.decodePPS( pps ); |
---|
1970 | #endif |
---|
1971 | m_parameterSetManager.storePPS( pps, naluData); |
---|
1972 | } |
---|
1973 | |
---|
1974 | #if SVC_EXTENSION |
---|
1975 | Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC) |
---|
1976 | #else |
---|
1977 | Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay) |
---|
1978 | #endif |
---|
1979 | { |
---|
1980 | #if !SVC_EXTENSION |
---|
1981 | // ignore all NAL units of layers > 0 |
---|
1982 | if (nalu.m_nuhLayerId > 0) |
---|
1983 | { |
---|
1984 | fprintf (stderr, "Warning: found NAL unit with nuh_layer_id equal to %d. Ignoring.\n", nalu.m_nuhLayerId); |
---|
1985 | return false; |
---|
1986 | } |
---|
1987 | #endif |
---|
1988 | // Initialize entropy decoder |
---|
1989 | m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder); |
---|
1990 | m_cEntropyDecoder.setBitstream (&(nalu.getBitstream())); |
---|
1991 | |
---|
1992 | #if SVC_EXTENSION |
---|
1993 | // ignore any NAL units with nuh_layer_id == 63 |
---|
1994 | if( nalu.m_nuhLayerId == 63 ) |
---|
1995 | { |
---|
1996 | return false; |
---|
1997 | } |
---|
1998 | |
---|
1999 | // skip NAL units of the layers not needed to be decoded specified by OLS |
---|
2000 | if( nalu.m_nalUnitType != NAL_UNIT_VPS && nalu.m_nalUnitType != NAL_UNIT_SPS && nalu.m_nalUnitType != NAL_UNIT_PPS && |
---|
2001 | m_targetDecLayerIdList.size() && std::find( m_targetDecLayerIdList.begin(), m_targetDecLayerIdList.end(), nalu.m_nuhLayerId ) == m_targetDecLayerIdList.end() ) |
---|
2002 | { |
---|
2003 | return false; |
---|
2004 | } |
---|
2005 | #endif |
---|
2006 | switch (nalu.m_nalUnitType) |
---|
2007 | { |
---|
2008 | case NAL_UNIT_VPS: |
---|
2009 | #if SVC_EXTENSION |
---|
2010 | assert( nalu.m_nuhLayerId == 0 ); // Non-conforming bitstream. The value of nuh_layer_id of VPS NAL unit shall be equal to 0. |
---|
2011 | #endif |
---|
2012 | xDecodeVPS(nalu.getBitstream().getFifo()); |
---|
2013 | #if SVC_EXTENSION |
---|
2014 | m_isLastNALWasEos = false; |
---|
2015 | #endif |
---|
2016 | return false; |
---|
2017 | |
---|
2018 | case NAL_UNIT_SPS: |
---|
2019 | xDecodeSPS(nalu.getBitstream().getFifo()); |
---|
2020 | return false; |
---|
2021 | |
---|
2022 | case NAL_UNIT_PPS: |
---|
2023 | #if CGS_3D_ASYMLUT |
---|
2024 | xDecodePPS( nalu.getBitstream().getFifo(), &m_c3DAsymLUTPPS ); |
---|
2025 | #else |
---|
2026 | xDecodePPS(nalu.getBitstream().getFifo()); |
---|
2027 | #endif |
---|
2028 | return false; |
---|
2029 | |
---|
2030 | case NAL_UNIT_PREFIX_SEI: |
---|
2031 | // Buffer up prefix SEI messages until SPS of associated VCL is known. |
---|
2032 | m_prefixSEINALUs.push_back(new InputNALUnit(nalu)); |
---|
2033 | return false; |
---|
2034 | |
---|
2035 | case NAL_UNIT_SUFFIX_SEI: |
---|
2036 | #if SVC_EXTENSION |
---|
2037 | if( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI ) |
---|
2038 | { |
---|
2039 | assert( m_isLastNALWasEos == false ); |
---|
2040 | } |
---|
2041 | #endif |
---|
2042 | if (m_pcPic) |
---|
2043 | { |
---|
2044 | #if SVC_EXTENSION |
---|
2045 | m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveVPS(), m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream ); |
---|
2046 | #else |
---|
2047 | m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream ); |
---|
2048 | #endif |
---|
2049 | } |
---|
2050 | else |
---|
2051 | { |
---|
2052 | printf ("Note: received suffix SEI but no picture currently active.\n"); |
---|
2053 | } |
---|
2054 | return false; |
---|
2055 | |
---|
2056 | case NAL_UNIT_CODED_SLICE_TRAIL_R: |
---|
2057 | case NAL_UNIT_CODED_SLICE_TRAIL_N: |
---|
2058 | case NAL_UNIT_CODED_SLICE_TSA_R: |
---|
2059 | case NAL_UNIT_CODED_SLICE_TSA_N: |
---|
2060 | case NAL_UNIT_CODED_SLICE_STSA_R: |
---|
2061 | case NAL_UNIT_CODED_SLICE_STSA_N: |
---|
2062 | case NAL_UNIT_CODED_SLICE_BLA_W_LP: |
---|
2063 | case NAL_UNIT_CODED_SLICE_BLA_W_RADL: |
---|
2064 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: |
---|
2065 | case NAL_UNIT_CODED_SLICE_IDR_W_RADL: |
---|
2066 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: |
---|
2067 | case NAL_UNIT_CODED_SLICE_CRA: |
---|
2068 | case NAL_UNIT_CODED_SLICE_RADL_N: |
---|
2069 | case NAL_UNIT_CODED_SLICE_RADL_R: |
---|
2070 | case NAL_UNIT_CODED_SLICE_RASL_N: |
---|
2071 | case NAL_UNIT_CODED_SLICE_RASL_R: |
---|
2072 | #if SVC_EXTENSION |
---|
2073 | if( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N || |
---|
2074 | nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N || |
---|
2075 | nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N || |
---|
2076 | nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N || |
---|
2077 | nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ) |
---|
2078 | { |
---|
2079 | assert( m_isLastNALWasEos == false ); |
---|
2080 | } |
---|
2081 | else |
---|
2082 | { |
---|
2083 | m_isLastNALWasEos = false; |
---|
2084 | } |
---|
2085 | |
---|
2086 | return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC); |
---|
2087 | #else |
---|
2088 | return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay); |
---|
2089 | #endif |
---|
2090 | break; |
---|
2091 | |
---|
2092 | case NAL_UNIT_EOS: |
---|
2093 | #if SVC_EXTENSION |
---|
2094 | assert( m_isLastNALWasEos == false ); |
---|
2095 | |
---|
2096 | m_isLastNALWasEos = true; |
---|
2097 | m_lastPicHasEos = true; |
---|
2098 | #endif |
---|
2099 | m_associatedIRAPType = NAL_UNIT_INVALID; |
---|
2100 | m_pocCRA = 0; |
---|
2101 | m_pocRandomAccess = MAX_INT; |
---|
2102 | m_prevPOC = MAX_INT; |
---|
2103 | m_prevSliceSkipped = false; |
---|
2104 | m_skippedPOC = 0; |
---|
2105 | return false; |
---|
2106 | |
---|
2107 | case NAL_UNIT_ACCESS_UNIT_DELIMITER: |
---|
2108 | { |
---|
2109 | AUDReader audReader; |
---|
2110 | UInt picType; |
---|
2111 | audReader.parseAccessUnitDelimiter(&(nalu.getBitstream()),picType); |
---|
2112 | printf ("Note: found NAL_UNIT_ACCESS_UNIT_DELIMITER\n"); |
---|
2113 | return false; |
---|
2114 | } |
---|
2115 | |
---|
2116 | case NAL_UNIT_EOB: |
---|
2117 | #if SVC_EXTENSION |
---|
2118 | //Check layer id of the nalu. if it is not 0, give a warning message. |
---|
2119 | if (nalu.m_nuhLayerId > 0) |
---|
2120 | { |
---|
2121 | printf( "\n\nThis bitstream is ended with EOB NALU that has layer id greater than 0\n" ); |
---|
2122 | } |
---|
2123 | #endif |
---|
2124 | return false; |
---|
2125 | |
---|
2126 | case NAL_UNIT_FILLER_DATA: |
---|
2127 | { |
---|
2128 | FDReader fdReader; |
---|
2129 | UInt size; |
---|
2130 | fdReader.parseFillerData(&(nalu.getBitstream()),size); |
---|
2131 | printf ("Note: found NAL_UNIT_FILLER_DATA with %u bytes payload.\n", size); |
---|
2132 | #if SVC_EXTENSION |
---|
2133 | assert( m_isLastNALWasEos == false ); |
---|
2134 | #endif |
---|
2135 | return false; |
---|
2136 | } |
---|
2137 | |
---|
2138 | case NAL_UNIT_RESERVED_VCL_N10: |
---|
2139 | case NAL_UNIT_RESERVED_VCL_R11: |
---|
2140 | case NAL_UNIT_RESERVED_VCL_N12: |
---|
2141 | case NAL_UNIT_RESERVED_VCL_R13: |
---|
2142 | case NAL_UNIT_RESERVED_VCL_N14: |
---|
2143 | case NAL_UNIT_RESERVED_VCL_R15: |
---|
2144 | |
---|
2145 | case NAL_UNIT_RESERVED_IRAP_VCL22: |
---|
2146 | case NAL_UNIT_RESERVED_IRAP_VCL23: |
---|
2147 | |
---|
2148 | case NAL_UNIT_RESERVED_VCL24: |
---|
2149 | case NAL_UNIT_RESERVED_VCL25: |
---|
2150 | case NAL_UNIT_RESERVED_VCL26: |
---|
2151 | case NAL_UNIT_RESERVED_VCL27: |
---|
2152 | case NAL_UNIT_RESERVED_VCL28: |
---|
2153 | case NAL_UNIT_RESERVED_VCL29: |
---|
2154 | case NAL_UNIT_RESERVED_VCL30: |
---|
2155 | case NAL_UNIT_RESERVED_VCL31: |
---|
2156 | printf ("Note: found reserved VCL NAL unit.\n"); |
---|
2157 | xParsePrefixSEIsForUnknownVCLNal(); |
---|
2158 | return false; |
---|
2159 | |
---|
2160 | case NAL_UNIT_RESERVED_NVCL41: |
---|
2161 | case NAL_UNIT_RESERVED_NVCL42: |
---|
2162 | case NAL_UNIT_RESERVED_NVCL43: |
---|
2163 | case NAL_UNIT_RESERVED_NVCL44: |
---|
2164 | case NAL_UNIT_RESERVED_NVCL45: |
---|
2165 | case NAL_UNIT_RESERVED_NVCL46: |
---|
2166 | case NAL_UNIT_RESERVED_NVCL47: |
---|
2167 | printf ("Note: found reserved NAL unit.\n"); |
---|
2168 | return false; |
---|
2169 | case NAL_UNIT_UNSPECIFIED_48: |
---|
2170 | case NAL_UNIT_UNSPECIFIED_49: |
---|
2171 | case NAL_UNIT_UNSPECIFIED_50: |
---|
2172 | case NAL_UNIT_UNSPECIFIED_51: |
---|
2173 | case NAL_UNIT_UNSPECIFIED_52: |
---|
2174 | case NAL_UNIT_UNSPECIFIED_53: |
---|
2175 | case NAL_UNIT_UNSPECIFIED_54: |
---|
2176 | case NAL_UNIT_UNSPECIFIED_55: |
---|
2177 | case NAL_UNIT_UNSPECIFIED_56: |
---|
2178 | case NAL_UNIT_UNSPECIFIED_57: |
---|
2179 | case NAL_UNIT_UNSPECIFIED_58: |
---|
2180 | case NAL_UNIT_UNSPECIFIED_59: |
---|
2181 | case NAL_UNIT_UNSPECIFIED_60: |
---|
2182 | case NAL_UNIT_UNSPECIFIED_61: |
---|
2183 | case NAL_UNIT_UNSPECIFIED_62: |
---|
2184 | case NAL_UNIT_UNSPECIFIED_63: |
---|
2185 | printf ("Note: found unspecified NAL unit.\n"); |
---|
2186 | return false; |
---|
2187 | default: |
---|
2188 | assert (0); |
---|
2189 | break; |
---|
2190 | } |
---|
2191 | |
---|
2192 | return false; |
---|
2193 | } |
---|
2194 | |
---|
2195 | /** Function for checking if picture should be skipped because of association with a previous BLA picture |
---|
2196 | * \param iPOCLastDisplay POC of last picture displayed |
---|
2197 | * \returns true if the picture should be skipped |
---|
2198 | * This function skips all TFD pictures that follow a BLA picture |
---|
2199 | * in decoding order and precede it in output order. |
---|
2200 | */ |
---|
2201 | Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay) |
---|
2202 | { |
---|
2203 | if ((m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_N_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_RADL) && |
---|
2204 | m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N)) |
---|
2205 | { |
---|
2206 | iPOCLastDisplay++; |
---|
2207 | return true; |
---|
2208 | } |
---|
2209 | return false; |
---|
2210 | } |
---|
2211 | |
---|
2212 | /** Function for checking if picture should be skipped because of random access |
---|
2213 | * \param iSkipFrame skip frame counter |
---|
2214 | * \param iPOCLastDisplay POC of last picture displayed |
---|
2215 | * \returns true if the picture shold be skipped in the random access. |
---|
2216 | * This function checks the skipping of pictures in the case of -s option random access. |
---|
2217 | * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped. |
---|
2218 | * It also checks the type of Nal unit type at the random access point. |
---|
2219 | * If the random access point is CRA/CRANT/BLA/BLANT, TFD pictures with POC less than the POC of the random access point are skipped. |
---|
2220 | * If the random access point is IDR all pictures after the random access point are decoded. |
---|
2221 | * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC |
---|
2222 | * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random |
---|
2223 | * access point there is no guarantee that the decoder will not crash. |
---|
2224 | */ |
---|
2225 | Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame, Int& iPOCLastDisplay) |
---|
2226 | { |
---|
2227 | if (iSkipFrame) |
---|
2228 | { |
---|
2229 | iSkipFrame--; // decrement the counter |
---|
2230 | return true; |
---|
2231 | } |
---|
2232 | else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet. |
---|
2233 | { |
---|
2234 | if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA |
---|
2235 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
2236 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
2237 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ) |
---|
2238 | { |
---|
2239 | // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT. |
---|
2240 | m_pocRandomAccess = m_apcSlicePilot->getPOC(); |
---|
2241 | } |
---|
2242 | else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
---|
2243 | { |
---|
2244 | m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable. |
---|
2245 | } |
---|
2246 | else |
---|
2247 | { |
---|
2248 | if(!m_warningMessageSkipPicture) |
---|
2249 | { |
---|
2250 | printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture"); |
---|
2251 | m_warningMessageSkipPicture = true; |
---|
2252 | } |
---|
2253 | return true; |
---|
2254 | } |
---|
2255 | } |
---|
2256 | // skip the reordered pictures, if necessary |
---|
2257 | else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N)) |
---|
2258 | { |
---|
2259 | iPOCLastDisplay++; |
---|
2260 | return true; |
---|
2261 | } |
---|
2262 | // if we reach here, then the picture is not skipped. |
---|
2263 | return false; |
---|
2264 | } |
---|
2265 | |
---|
2266 | #if SVC_EXTENSION |
---|
2267 | Void TDecTop::xInitILRP(TComSlice *slice) |
---|
2268 | { |
---|
2269 | const TComVPS* vps = slice->getVPS(); |
---|
2270 | const TComSPS* sps = slice->getSPS(); |
---|
2271 | |
---|
2272 | if( m_layerId > 0 ) |
---|
2273 | { |
---|
2274 | if (m_cIlpPic[0] == NULL) |
---|
2275 | { |
---|
2276 | for (Int j=0; j < m_numDirectRefLayers; j++) |
---|
2277 | { |
---|
2278 | m_cIlpPic[j] = new TComPic; |
---|
2279 | |
---|
2280 | m_cIlpPic[j]->create(*vps, *sps, *slice->getPPS(), true, m_layerId); |
---|
2281 | |
---|
2282 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCtusInFrame(); i++) |
---|
2283 | { |
---|
2284 | m_cIlpPic[j]->getPicSym()->getCtu(i)->initCtu(m_cIlpPic[j], i); |
---|
2285 | } |
---|
2286 | } |
---|
2287 | } |
---|
2288 | } |
---|
2289 | } |
---|
2290 | |
---|
2291 | TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdx ) |
---|
2292 | { |
---|
2293 | const TComVPS* vps = m_parameterSetManager.getActiveVPS(); |
---|
2294 | if( vps->getNumDirectRefLayers( m_layerId ) <= 0 ) |
---|
2295 | { |
---|
2296 | return (TDecTop *)getLayerDec( 0 ); |
---|
2297 | } |
---|
2298 | |
---|
2299 | return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdx ) ); |
---|
2300 | } |
---|
2301 | |
---|
2302 | Void TDecTop::setRefLayerParams( const TComVPS* vps ) |
---|
2303 | { |
---|
2304 | for(UInt layerIdx = 0; layerIdx < m_numLayer; layerIdx++) |
---|
2305 | { |
---|
2306 | TDecTop *decTop = (TDecTop *)getLayerDec(vps->getLayerIdInNuh(layerIdx)); |
---|
2307 | decTop->setNumSamplePredRefLayers(0); |
---|
2308 | decTop->setNumMotionPredRefLayers(0); |
---|
2309 | decTop->setNumDirectRefLayers(0); |
---|
2310 | |
---|
2311 | for(Int j = 0; j < layerIdx; j++) |
---|
2312 | { |
---|
2313 | if (vps->getDirectDependencyFlag(layerIdx, j)) |
---|
2314 | { |
---|
2315 | decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layerIdx)); |
---|
2316 | decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1); |
---|
2317 | |
---|
2318 | Int samplePredEnabledFlag = (vps->getDirectDependencyType(layerIdx, j) + 1) & 1; |
---|
2319 | decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag); |
---|
2320 | |
---|
2321 | Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layerIdx, j) + 1) & 2) >> 1; |
---|
2322 | decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag); |
---|
2323 | } |
---|
2324 | } |
---|
2325 | } |
---|
2326 | } |
---|
2327 | |
---|
2328 | Void TDecTop::checkValueOfTargetOutputLayerSetIdx(TComVPS *vps) |
---|
2329 | { |
---|
2330 | CommonDecoderParams* params = this->getCommonDecoderParams(); |
---|
2331 | |
---|
2332 | if( params->getValueCheckedFlag() ) |
---|
2333 | { |
---|
2334 | return; // Already checked |
---|
2335 | } |
---|
2336 | |
---|
2337 | if( params->getTargetOutputLayerSetIdx() == -1 ) // Output layer set index not specified |
---|
2338 | { |
---|
2339 | if( params->getTargetLayerId() > vps->getMaxLayerId() ) |
---|
2340 | { |
---|
2341 | printf( "Warning: specified target layerId %d is greater than max layerId %d. Target layerId is set equal to max layerId %d.\n", params->getTargetLayerId(), vps->getMaxLayerId(), vps->getMaxLayerId() ); |
---|
2342 | params->setTargetLayerId( vps->getMaxLayerId() ); |
---|
2343 | } |
---|
2344 | |
---|
2345 | Bool layerSetMatchFound = false; |
---|
2346 | // Output layer set index not assigned. |
---|
2347 | // Based on the value of targetLayerId, check if any of the output layer matches |
---|
2348 | // Currently, the target layer ID in the encoder assumes that all the layers are decoded |
---|
2349 | // Check if any of the output layer sets match this description |
---|
2350 | for( Int i = 0; i < vps->getNumOutputLayerSets(); i++ ) |
---|
2351 | { |
---|
2352 | Bool layerSetMatchFlag = false; |
---|
2353 | Int layerSetIdx = vps->getOutputLayerSetIdx( i ); |
---|
2354 | |
---|
2355 | for( Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++ ) |
---|
2356 | { |
---|
2357 | if( vps->getLayerSetLayerIdList( layerSetIdx, j ) == params->getTargetLayerId() ) |
---|
2358 | { |
---|
2359 | layerSetMatchFlag = true; |
---|
2360 | break; |
---|
2361 | } |
---|
2362 | } |
---|
2363 | |
---|
2364 | if( layerSetMatchFlag ) // Potential output layer set candidate found |
---|
2365 | { |
---|
2366 | // If target dec layer ID list is also included - check if they match |
---|
2367 | if( params->getTargetDecLayerIdSet() ) |
---|
2368 | { |
---|
2369 | if( params->getTargetDecLayerIdSet()->size() ) |
---|
2370 | { |
---|
2371 | for( Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++ ) |
---|
2372 | { |
---|
2373 | if( *(params->getTargetDecLayerIdSet()->begin() + j) != vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, j ))) |
---|
2374 | { |
---|
2375 | layerSetMatchFlag = false; |
---|
2376 | } |
---|
2377 | } |
---|
2378 | } |
---|
2379 | } |
---|
2380 | if( layerSetMatchFlag ) // The target dec layer ID list also matches, if present |
---|
2381 | { |
---|
2382 | // Match found |
---|
2383 | layerSetMatchFound = true; |
---|
2384 | params->setTargetOutputLayerSetIdx( i ); |
---|
2385 | params->setValueCheckedFlag( true ); |
---|
2386 | break; |
---|
2387 | } |
---|
2388 | } |
---|
2389 | } |
---|
2390 | assert( layerSetMatchFound ); // No output layer set matched the value of either targetLayerId or targetdeclayerIdlist |
---|
2391 | } |
---|
2392 | else // Output layer set index is assigned - check if the values match |
---|
2393 | { |
---|
2394 | // Check if the target decoded layer is the highest layer in the list |
---|
2395 | assert( params->getTargetOutputLayerSetIdx() < vps->getNumOutputLayerSets() ); |
---|
2396 | #if !CONFORMANCE_BITSTREAM_MODE |
---|
2397 | assert( params->getTargetOutputLayerSetIdx() < vps->getNumLayerSets() ); |
---|
2398 | #endif |
---|
2399 | Int layerSetIdx = vps->getOutputLayerSetIdx( params->getTargetOutputLayerSetIdx() ); // Index to the layer set |
---|
2400 | #if !CONFORMANCE_BITSTREAM_MODE |
---|
2401 | assert( params->getTargetLayerId() == vps->getNumLayersInIdList( layerSetIdx ) - 1); |
---|
2402 | #endif |
---|
2403 | |
---|
2404 | // Check if the targetdeclayerIdlist matches the output layer set |
---|
2405 | if( params->getTargetDecLayerIdSet() ) |
---|
2406 | { |
---|
2407 | if( params->getTargetDecLayerIdSet()->size() ) |
---|
2408 | { |
---|
2409 | for(Int i = 0; i < vps->getNumLayersInIdList( layerSetIdx ); i++) |
---|
2410 | { |
---|
2411 | assert( *(params->getTargetDecLayerIdSet()->begin() + i) == vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, i ))); |
---|
2412 | } |
---|
2413 | } |
---|
2414 | } |
---|
2415 | params->setValueCheckedFlag( true ); |
---|
2416 | |
---|
2417 | } |
---|
2418 | |
---|
2419 | // Set correct value of targetLayerId |
---|
2420 | Int targetOlsIdx = params->getTargetOutputLayerSetIdx(); |
---|
2421 | Int targetLsIdx = vps->getOutputLayerSetIdx( targetOlsIdx ); |
---|
2422 | params->setTargetLayerId( vps->getLayerSetLayerIdList( targetLsIdx, vps->getNumLayersInIdList(targetLsIdx)-1 ) ); |
---|
2423 | |
---|
2424 | // Check if the current layer is an output layer |
---|
2425 | for( Int i = 0; i < vps->getNumLayersInIdList( targetLsIdx ); i++ ) |
---|
2426 | { |
---|
2427 | if( vps->getOutputLayerFlag( targetOlsIdx, i ) ) |
---|
2428 | { |
---|
2429 | m_ppcTDecTop[vps->getLayerSetLayerIdList( targetLsIdx, i )]->m_isOutputLayerFlag = true; |
---|
2430 | } |
---|
2431 | } |
---|
2432 | } |
---|
2433 | |
---|
2434 | Void TDecTop::markAllPicsAsNoCurrAu( const TComVPS *vps ) |
---|
2435 | { |
---|
2436 | for(Int i = 0; i < MAX_LAYERS; i++) |
---|
2437 | { |
---|
2438 | TComList<TComPic*>* listPic = m_ppcTDecTop[vps->getLayerIdInNuh(i)]->getListPic(); |
---|
2439 | TComList<TComPic*>::iterator iterPic = listPic->begin(); |
---|
2440 | while ( iterPic != listPic->end() ) |
---|
2441 | { |
---|
2442 | TComPic *pcPic = *(iterPic); |
---|
2443 | pcPic->setCurrAuFlag( false ); |
---|
2444 | iterPic++; |
---|
2445 | } |
---|
2446 | } |
---|
2447 | } |
---|
2448 | |
---|
2449 | #if CGS_3D_ASYMLUT |
---|
2450 | Void TDecTop::initAsymLut(TComSlice *pcSlice) |
---|
2451 | { |
---|
2452 | if( m_layerId > 0 ) |
---|
2453 | { |
---|
2454 | if( !m_pColorMappedPic ) |
---|
2455 | { |
---|
2456 | m_pColorMappedPic = new TComPicYuv; |
---|
2457 | m_pColorMappedPic->create( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc()/*CHROMA_420*/, pcSlice->getSPS()->getMaxCUWidth(), pcSlice->getSPS()->getMaxCUHeight(), pcSlice->getSPS()->getMaxTotalCUDepth(), true, NULL ); |
---|
2458 | } |
---|
2459 | } |
---|
2460 | } |
---|
2461 | #endif |
---|
2462 | |
---|
2463 | Void TDecTop::resetPocRestrictionCheckParameters() |
---|
2464 | { |
---|
2465 | TDecTop::m_checkPocRestrictionsForCurrAu = false; |
---|
2466 | TDecTop::m_pocResetIdcOrCurrAu = -1; |
---|
2467 | TDecTop::m_baseLayerIdrFlag = false; |
---|
2468 | TDecTop::m_baseLayerPicPresentFlag = false; |
---|
2469 | TDecTop::m_baseLayerIrapFlag = false; |
---|
2470 | TDecTop::m_nonBaseIdrPresentFlag = false; |
---|
2471 | TDecTop::m_nonBaseIdrType = -1; |
---|
2472 | TDecTop::m_picNonIdrWithRadlPresentFlag = false; |
---|
2473 | TDecTop::m_picNonIdrNoLpPresentFlag = false; |
---|
2474 | } |
---|
2475 | |
---|
2476 | Void TDecTop::xCheckLayerReset() |
---|
2477 | { |
---|
2478 | if (m_apcSlicePilot->isIRAP() && m_layerId > m_smallestLayerId) |
---|
2479 | { |
---|
2480 | Bool layerResetFlag; |
---|
2481 | UInt dolLayerId; |
---|
2482 | if (m_lastPicHasEos) |
---|
2483 | { |
---|
2484 | layerResetFlag = true; |
---|
2485 | dolLayerId = m_layerId; |
---|
2486 | } |
---|
2487 | else if ((m_apcSlicePilot->isCRA() && m_apcSlicePilot->getHandleCraAsBlaFlag()) || |
---|
2488 | (m_apcSlicePilot->isIDR() && m_apcSlicePilot->getCrossLayerBLAFlag()) || m_apcSlicePilot->isBLA()) |
---|
2489 | { |
---|
2490 | layerResetFlag = true; |
---|
2491 | dolLayerId = m_layerId; |
---|
2492 | } |
---|
2493 | else |
---|
2494 | { |
---|
2495 | layerResetFlag = false; |
---|
2496 | } |
---|
2497 | |
---|
2498 | if (layerResetFlag) |
---|
2499 | { |
---|
2500 | for (Int i = 0; i < m_apcSlicePilot->getVPS()->getNumPredictedLayers(dolLayerId); i++) |
---|
2501 | { |
---|
2502 | UInt iLayerId = m_apcSlicePilot->getVPS()->getPredictedLayerId(dolLayerId, i); |
---|
2503 | m_ppcTDecTop[iLayerId]->m_layerInitializedFlag = false; |
---|
2504 | m_ppcTDecTop[iLayerId]->m_firstPicInLayerDecodedFlag = false; |
---|
2505 | } |
---|
2506 | |
---|
2507 | for (TComList<TComPic*>::iterator i = m_cListPic.begin(); i != m_cListPic.end(); i++) |
---|
2508 | { |
---|
2509 | if ((*i)->getPOC() != m_apcSlicePilot->getPOC()) |
---|
2510 | { |
---|
2511 | (*i)->getSlice(0)->setReferenced(false); |
---|
2512 | } |
---|
2513 | } |
---|
2514 | |
---|
2515 | for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getNumPredictedLayers(dolLayerId); i++) |
---|
2516 | { |
---|
2517 | UInt predLId = m_apcSlicePilot->getVPS()->getPredictedLayerId(dolLayerId, i); |
---|
2518 | for (TComList<TComPic*>::iterator pic = m_ppcTDecTop[predLId]->getListPic()->begin(); pic != m_ppcTDecTop[predLId]->getListPic()->end(); pic++) |
---|
2519 | { |
---|
2520 | if ((*pic)->getSlice(0)->getPOC() != m_apcSlicePilot->getPOC()) |
---|
2521 | { |
---|
2522 | (*pic)->getSlice(0)->setReferenced(false); |
---|
2523 | } |
---|
2524 | } |
---|
2525 | } |
---|
2526 | } |
---|
2527 | } |
---|
2528 | } |
---|
2529 | |
---|
2530 | Void TDecTop::xSetLayerInitializedFlag() |
---|
2531 | { |
---|
2532 | if (m_apcSlicePilot->isIRAP() && m_apcSlicePilot->getNoRaslOutputFlag()) |
---|
2533 | { |
---|
2534 | if (m_layerId == 0) |
---|
2535 | { |
---|
2536 | m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true); |
---|
2537 | } |
---|
2538 | else if (!m_ppcTDecTop[m_layerId]->getLayerInitializedFlag() && m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId) == 0) |
---|
2539 | { |
---|
2540 | m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true); |
---|
2541 | } |
---|
2542 | else if (!m_ppcTDecTop[m_layerId]->getLayerInitializedFlag()) |
---|
2543 | { |
---|
2544 | Bool refLayersInitialized = true; |
---|
2545 | for (UInt j = 0; j < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); j++) |
---|
2546 | { |
---|
2547 | UInt refLayerId = m_apcSlicePilot->getVPS()->getRefLayerId(m_layerId, j); |
---|
2548 | if (!m_ppcTDecTop[refLayerId]->getLayerInitializedFlag()) |
---|
2549 | { |
---|
2550 | refLayersInitialized = false; |
---|
2551 | } |
---|
2552 | } |
---|
2553 | if (refLayersInitialized) |
---|
2554 | { |
---|
2555 | m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true); |
---|
2556 | } |
---|
2557 | } |
---|
2558 | } |
---|
2559 | } |
---|
2560 | |
---|
2561 | Void TDecTop::xDeriveSmallestLayerId(TComVPS* vps) |
---|
2562 | { |
---|
2563 | UInt smallestLayerId; |
---|
2564 | Int targetOlsIdx = m_commonDecoderParams->getTargetOutputLayerSetIdx(); |
---|
2565 | assert( targetOlsIdx >= 0 ); |
---|
2566 | |
---|
2567 | // list of layers to be decoded is not built yet |
---|
2568 | m_targetDecLayerIdList.resize(0); |
---|
2569 | |
---|
2570 | UInt targetDecLayerSetIdx = vps->getOutputLayerSetIdx(targetOlsIdx); |
---|
2571 | UInt lsIdx = targetDecLayerSetIdx; |
---|
2572 | |
---|
2573 | for (UInt i = 0; i < vps->getNumLayersInIdList(lsIdx); i++) |
---|
2574 | { |
---|
2575 | if (vps->getNecessaryLayerFlag(targetOlsIdx, i)) |
---|
2576 | { |
---|
2577 | m_targetDecLayerIdList.push_back( vps->getLayerSetLayerIdList(lsIdx, i) ); |
---|
2578 | } |
---|
2579 | } |
---|
2580 | |
---|
2581 | if (targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1()) |
---|
2582 | { |
---|
2583 | smallestLayerId = 0; |
---|
2584 | } |
---|
2585 | else if (vps->getNumLayersInIdList(targetDecLayerSetIdx) == 1) |
---|
2586 | { |
---|
2587 | smallestLayerId = 0; |
---|
2588 | } |
---|
2589 | else |
---|
2590 | { |
---|
2591 | smallestLayerId = m_targetDecLayerIdList[0]; |
---|
2592 | } |
---|
2593 | |
---|
2594 | for( UInt layerId = 0; layerId < MAX_VPS_LAYER_IDX_PLUS1; layerId++ ) |
---|
2595 | { |
---|
2596 | m_ppcTDecTop[layerId]->m_smallestLayerId = smallestLayerId; |
---|
2597 | } |
---|
2598 | } |
---|
2599 | |
---|
2600 | Void TDecTop::xSetSpatialEnhLayerFlag( const TComVPS &vps, const TComSPS &sps, const TComPPS &pps, TComPic* pic ) |
---|
2601 | { |
---|
2602 | for(UInt i = 0; i < vps.getNumDirectRefLayers( m_layerId ); i++ ) |
---|
2603 | { |
---|
2604 | const Window scalEL = pps.getScaledRefLayerWindowForLayer(vps.getRefLayerId(m_layerId, i)); |
---|
2605 | const Window refEL = pps.getRefLayerWindowForLayer(vps.getRefLayerId(m_layerId, i)); |
---|
2606 | Bool equalOffsets = scalEL.hasEqualOffset(refEL); |
---|
2607 | Bool zeroPhase = pps.hasZeroResamplingPhase(vps.getRefLayerId(m_layerId, i)); |
---|
2608 | |
---|
2609 | TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i ); |
---|
2610 | TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); |
---|
2611 | |
---|
2612 | const Int bitDepthLuma = vps.getBitDepth(CHANNEL_TYPE_LUMA, &sps, m_layerId); |
---|
2613 | const Int bitDepthChroma = vps.getBitDepth(CHANNEL_TYPE_CHROMA, &sps, m_layerId); |
---|
2614 | const Int refBitDepthLuma = (*(pcTDecTopBase->getListPic()->begin()))->getSlice(0)->getBitDepth(CHANNEL_TYPE_LUMA); |
---|
2615 | const Int refBitDepthChroma = (*(pcTDecTopBase->getListPic()->begin()))->getSlice(0)->getBitDepth(CHANNEL_TYPE_CHROMA); |
---|
2616 | |
---|
2617 | Bool sameBitDepths = ( bitDepthLuma == refBitDepthLuma ) && ( bitDepthChroma == refBitDepthChroma ); |
---|
2618 | |
---|
2619 | if( pcPicYuvRecBase->getWidth(COMPONENT_Y) == vps.getPicWidthInLumaSamples(&sps, m_layerId) && pcPicYuvRecBase->getHeight(COMPONENT_Y) == vps.getPicHeightInLumaSamples(&sps, m_layerId) && equalOffsets && zeroPhase ) |
---|
2620 | { |
---|
2621 | pic->setEqualPictureSizeAndOffsetFlag( i, true ); |
---|
2622 | } |
---|
2623 | |
---|
2624 | if( !pic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths |
---|
2625 | #if CGS_3D_ASYMLUT |
---|
2626 | || pps.getCGSFlag() > 0 |
---|
2627 | #endif |
---|
2628 | ) |
---|
2629 | { |
---|
2630 | pic->setSpatialEnhLayerFlag( i, true ); |
---|
2631 | |
---|
2632 | //only for scalable extension |
---|
2633 | assert( vps.getScalabilityMask( SCALABILITY_ID ) == true ); |
---|
2634 | } |
---|
2635 | } |
---|
2636 | } |
---|
2637 | |
---|
2638 | #endif //SVC_EXTENSION |
---|
2639 | |
---|
2640 | |
---|
2641 | //! \} |
---|