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