[324] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
| 6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
| 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file TDecTop.cpp |
---|
| 35 | \brief decoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "NALread.h" |
---|
| 39 | #include "TDecTop.h" |
---|
| 40 | |
---|
[368] | 41 | #if H_MV |
---|
| 42 | ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder; |
---|
| 43 | #endif |
---|
[324] | 44 | //! \ingroup TLibDecoder |
---|
| 45 | //! \{ |
---|
| 46 | |
---|
| 47 | TDecTop::TDecTop() |
---|
| 48 | { |
---|
| 49 | m_pcPic = 0; |
---|
| 50 | m_iMaxRefPicNum = 0; |
---|
| 51 | #if ENC_DEC_TRACE |
---|
[401] | 52 | #if H_MV |
---|
| 53 | if ( g_hTrace == NULL ) |
---|
| 54 | { |
---|
| 55 | #endif |
---|
[324] | 56 | g_hTrace = fopen( "TraceDec.txt", "wb" ); |
---|
| 57 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
| 58 | g_nSymbolCounter = 0; |
---|
[401] | 59 | #if H_MV |
---|
| 60 | } |
---|
[324] | 61 | #endif |
---|
[401] | 62 | #endif |
---|
[324] | 63 | m_pocCRA = 0; |
---|
| 64 | m_prevRAPisBLA = false; |
---|
| 65 | m_pocRandomAccess = MAX_INT; |
---|
| 66 | m_prevPOC = MAX_INT; |
---|
| 67 | m_bFirstSliceInPicture = true; |
---|
| 68 | m_bFirstSliceInSequence = true; |
---|
[368] | 69 | #if H_MV |
---|
| 70 | m_layerId = 0; |
---|
| 71 | m_viewId = 0; |
---|
| 72 | #if H_3D |
---|
| 73 | m_isDepth = false; |
---|
| 74 | #endif |
---|
| 75 | #endif |
---|
[324] | 76 | } |
---|
| 77 | |
---|
| 78 | TDecTop::~TDecTop() |
---|
| 79 | { |
---|
| 80 | #if ENC_DEC_TRACE |
---|
| 81 | fclose( g_hTrace ); |
---|
| 82 | #endif |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | Void TDecTop::create() |
---|
| 86 | { |
---|
| 87 | m_cGopDecoder.create(); |
---|
| 88 | m_apcSlicePilot = new TComSlice; |
---|
| 89 | m_uiSliceIdx = 0; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | Void TDecTop::destroy() |
---|
| 93 | { |
---|
| 94 | m_cGopDecoder.destroy(); |
---|
| 95 | |
---|
| 96 | delete m_apcSlicePilot; |
---|
| 97 | m_apcSlicePilot = NULL; |
---|
| 98 | |
---|
| 99 | m_cSliceDecoder.destroy(); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | Void TDecTop::init() |
---|
| 103 | { |
---|
| 104 | // initialize ROM |
---|
[368] | 105 | #if !H_MV |
---|
[324] | 106 | initROM(); |
---|
[368] | 107 | #endif |
---|
[324] | 108 | m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO); |
---|
| 109 | m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder ); |
---|
| 110 | m_cEntropyDecoder.init(&m_cPrediction); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | Void TDecTop::deletePicBuffer ( ) |
---|
| 114 | { |
---|
| 115 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
| 116 | Int iSize = Int( m_cListPic.size() ); |
---|
| 117 | |
---|
| 118 | for (Int i = 0; i < iSize; i++ ) |
---|
| 119 | { |
---|
| 120 | TComPic* pcPic = *(iterPic++); |
---|
[368] | 121 | #if H_MV |
---|
| 122 | if( pcPic ) |
---|
| 123 | { |
---|
| 124 | #endif |
---|
[324] | 125 | pcPic->destroy(); |
---|
| 126 | |
---|
| 127 | delete pcPic; |
---|
| 128 | pcPic = NULL; |
---|
[368] | 129 | #if H_MV |
---|
| 130 | } |
---|
| 131 | #endif |
---|
[324] | 132 | } |
---|
| 133 | |
---|
| 134 | m_cSAO.destroy(); |
---|
| 135 | |
---|
| 136 | m_cLoopFilter. destroy(); |
---|
| 137 | |
---|
[368] | 138 | #if !H_MV |
---|
[324] | 139 | // destroy ROM |
---|
| 140 | destroyROM(); |
---|
[368] | 141 | #endif |
---|
[324] | 142 | } |
---|
| 143 | |
---|
| 144 | Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic ) |
---|
| 145 | { |
---|
| 146 | Int numReorderPics[MAX_TLAYER]; |
---|
| 147 | Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow(); |
---|
| 148 | Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window(); |
---|
| 149 | |
---|
| 150 | for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) |
---|
| 151 | { |
---|
| 152 | numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer); |
---|
| 153 | } |
---|
| 154 | |
---|
[362] | 155 | #if L0323_DPB |
---|
| 156 | m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()); // m_uiMaxDecPicBuffering has the space for the picture currently being decoded |
---|
| 157 | #else |
---|
[324] | 158 | m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded |
---|
[362] | 159 | #endif |
---|
[324] | 160 | if (m_cListPic.size() < (UInt)m_iMaxRefPicNum) |
---|
| 161 | { |
---|
| 162 | rpcPic = new TComPic(); |
---|
| 163 | |
---|
| 164 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
---|
| 165 | conformanceWindow, defaultDisplayWindow, numReorderPics, true); |
---|
| 166 | rpcPic->getPicSym()->allocSaoParam(&m_cSAO); |
---|
| 167 | m_cListPic.pushBack( rpcPic ); |
---|
| 168 | |
---|
| 169 | return; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | Bool bBufferIsAvailable = false; |
---|
| 173 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
| 174 | while (iterPic != m_cListPic.end()) |
---|
| 175 | { |
---|
| 176 | rpcPic = *(iterPic++); |
---|
| 177 | if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false) |
---|
| 178 | { |
---|
| 179 | rpcPic->setOutputMark(false); |
---|
| 180 | bBufferIsAvailable = true; |
---|
| 181 | break; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | if ( rpcPic->getSlice( 0 )->isReferenced() == false && rpcPic->getOutputMark() == false) |
---|
| 185 | { |
---|
| 186 | rpcPic->setOutputMark(false); |
---|
| 187 | rpcPic->setReconMark( false ); |
---|
| 188 | rpcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 189 | bBufferIsAvailable = true; |
---|
| 190 | break; |
---|
| 191 | } |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | if ( !bBufferIsAvailable ) |
---|
| 195 | { |
---|
| 196 | //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer. |
---|
| 197 | m_iMaxRefPicNum++; |
---|
| 198 | rpcPic = new TComPic(); |
---|
| 199 | m_cListPic.pushBack( rpcPic ); |
---|
| 200 | } |
---|
| 201 | rpcPic->destroy(); |
---|
| 202 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
---|
| 203 | conformanceWindow, defaultDisplayWindow, numReorderPics, true); |
---|
| 204 | rpcPic->getPicSym()->allocSaoParam(&m_cSAO); |
---|
| 205 | } |
---|
| 206 | |
---|
[368] | 207 | #if H_MV |
---|
| 208 | Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet ) |
---|
| 209 | #else |
---|
[324] | 210 | Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic) |
---|
[368] | 211 | #endif |
---|
[324] | 212 | { |
---|
| 213 | if (!m_pcPic) |
---|
| 214 | { |
---|
| 215 | /* nothing to deblock */ |
---|
| 216 | return; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | TComPic*& pcPic = m_pcPic; |
---|
| 220 | |
---|
| 221 | // Execute Deblock + Cleanup |
---|
| 222 | |
---|
| 223 | m_cGopDecoder.filterPicture(pcPic); |
---|
| 224 | |
---|
| 225 | TComSlice::sortPicList( m_cListPic ); // sorting for application output |
---|
| 226 | poc = pcPic->getSlice(m_uiSliceIdx-1)->getPOC(); |
---|
| 227 | rpcListPic = &m_cListPic; |
---|
| 228 | m_cCuDecoder.destroy(); |
---|
[368] | 229 | #if H_MV |
---|
| 230 | TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer ); |
---|
| 231 | TComSlice::markIvRefPicsAsUnused ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); |
---|
| 232 | #endif |
---|
[324] | 233 | m_bFirstSliceInPicture = true; |
---|
| 234 | |
---|
| 235 | return; |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | Void TDecTop::xCreateLostPicture(Int iLostPoc) |
---|
| 239 | { |
---|
| 240 | printf("\ninserting lost poc : %d\n",iLostPoc); |
---|
| 241 | TComSlice cFillSlice; |
---|
| 242 | cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() ); |
---|
| 243 | cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() ); |
---|
| 244 | cFillSlice.initSlice(); |
---|
| 245 | TComPic *cFillPic; |
---|
| 246 | xGetNewPicBuffer(&cFillSlice,cFillPic); |
---|
| 247 | cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() ); |
---|
| 248 | cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() ); |
---|
| 249 | cFillPic->getSlice(0)->initSlice(); |
---|
| 250 | |
---|
| 251 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
| 252 | Int closestPoc = 1000000; |
---|
| 253 | while ( iterPic != m_cListPic.end()) |
---|
| 254 | { |
---|
| 255 | TComPic * rpcPic = *(iterPic++); |
---|
| 256 | 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()) |
---|
| 257 | { |
---|
| 258 | closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc); |
---|
| 259 | } |
---|
| 260 | } |
---|
| 261 | iterPic = m_cListPic.begin(); |
---|
| 262 | while ( iterPic != m_cListPic.end()) |
---|
| 263 | { |
---|
| 264 | TComPic *rpcPic = *(iterPic++); |
---|
| 265 | if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC()) |
---|
| 266 | { |
---|
| 267 | printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC()); |
---|
| 268 | rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec()); |
---|
| 269 | break; |
---|
| 270 | } |
---|
| 271 | } |
---|
| 272 | cFillPic->setCurrSliceIdx(0); |
---|
| 273 | for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) |
---|
| 274 | { |
---|
| 275 | cFillPic->getCU(i)->initCU(cFillPic,i); |
---|
| 276 | } |
---|
| 277 | cFillPic->getSlice(0)->setReferenced(true); |
---|
| 278 | cFillPic->getSlice(0)->setPOC(iLostPoc); |
---|
| 279 | cFillPic->setReconMark(true); |
---|
| 280 | cFillPic->setOutputMark(true); |
---|
| 281 | if(m_pocRandomAccess == MAX_INT) |
---|
| 282 | { |
---|
| 283 | m_pocRandomAccess = iLostPoc; |
---|
| 284 | } |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | Void TDecTop::xActivateParameterSets() |
---|
| 289 | { |
---|
| 290 | m_parameterSetManagerDecoder.applyPrefetchedPS(); |
---|
| 291 | |
---|
| 292 | TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId()); |
---|
| 293 | assert (pps != 0); |
---|
| 294 | |
---|
| 295 | TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId()); |
---|
| 296 | assert (sps != 0); |
---|
| 297 | |
---|
[362] | 298 | if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP())) |
---|
[324] | 299 | { |
---|
| 300 | printf ("Parameter set activation failed!"); |
---|
| 301 | assert (0); |
---|
| 302 | } |
---|
| 303 | |
---|
[362] | 304 | if( pps->getDependentSliceSegmentsEnabledFlag() ) |
---|
| 305 | { |
---|
| 306 | Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1; |
---|
| 307 | |
---|
| 308 | if (m_cSliceDecoder.getCtxMemSize() != NumCtx) |
---|
| 309 | { |
---|
| 310 | m_cSliceDecoder.initCtxMem(NumCtx); |
---|
| 311 | for ( UInt st = 0; st < NumCtx; st++ ) |
---|
| 312 | { |
---|
| 313 | TDecSbac* ctx = NULL; |
---|
| 314 | ctx = new TDecSbac; |
---|
| 315 | ctx->init( &m_cBinCABAC ); |
---|
| 316 | m_cSliceDecoder.setCtxMem( ctx, st ); |
---|
| 317 | } |
---|
| 318 | } |
---|
| 319 | } |
---|
| 320 | |
---|
[324] | 321 | m_apcSlicePilot->setPPS(pps); |
---|
| 322 | m_apcSlicePilot->setSPS(sps); |
---|
[372] | 323 | #if H_MV |
---|
| 324 | m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getActiveVPS() ); |
---|
| 325 | #endif |
---|
[324] | 326 | pps->setSPS(sps); |
---|
| 327 | pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1); |
---|
| 328 | pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) ); |
---|
| 329 | |
---|
[362] | 330 | g_bitDepthY = sps->getBitDepthY(); |
---|
| 331 | g_bitDepthC = sps->getBitDepthC(); |
---|
| 332 | g_uiMaxCUWidth = sps->getMaxCUWidth(); |
---|
| 333 | g_uiMaxCUHeight = sps->getMaxCUHeight(); |
---|
| 334 | g_uiMaxCUDepth = sps->getMaxCUDepth(); |
---|
| 335 | g_uiAddCUDepth = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() ); |
---|
| 336 | |
---|
| 337 | for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++) |
---|
[324] | 338 | { |
---|
| 339 | sps->setAMPAcc( i, sps->getUseAMP() ); |
---|
| 340 | } |
---|
| 341 | |
---|
[362] | 342 | for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++) |
---|
[324] | 343 | { |
---|
| 344 | sps->setAMPAcc( i, 0 ); |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | m_cSAO.destroy(); |
---|
[362] | 348 | m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() ); |
---|
| 349 | m_cLoopFilter.create( sps->getMaxCUDepth() ); |
---|
[324] | 350 | } |
---|
| 351 | |
---|
[368] | 352 | #if H_MV |
---|
| 353 | Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag ) |
---|
| 354 | { |
---|
| 355 | assert( nalu.m_layerId == m_layerId ); |
---|
| 356 | |
---|
| 357 | #else |
---|
[324] | 358 | Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay ) |
---|
| 359 | { |
---|
[368] | 360 | #endif |
---|
[324] | 361 | TComPic*& pcPic = m_pcPic; |
---|
| 362 | m_apcSlicePilot->initSlice(); |
---|
| 363 | |
---|
| 364 | if (m_bFirstSliceInPicture) |
---|
| 365 | { |
---|
| 366 | m_uiSliceIdx = 0; |
---|
| 367 | } |
---|
| 368 | m_apcSlicePilot->setSliceIdx(m_uiSliceIdx); |
---|
| 369 | if (!m_bFirstSliceInPicture) |
---|
| 370 | { |
---|
| 371 | m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) ); |
---|
| 372 | } |
---|
| 373 | |
---|
| 374 | m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType); |
---|
[362] | 375 | Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N || |
---|
| 376 | m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N || |
---|
| 377 | m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N || |
---|
| 378 | m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N || |
---|
| 379 | m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N); |
---|
| 380 | m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag); |
---|
| 381 | |
---|
[324] | 382 | m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS |
---|
| 383 | m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId); |
---|
| 384 | |
---|
[368] | 385 | #if H_MV |
---|
| 386 | m_apcSlicePilot->setLayerId( nalu.m_layerId ); |
---|
| 387 | #endif |
---|
[324] | 388 | m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder); |
---|
| 389 | |
---|
[368] | 390 | #if H_MV |
---|
| 391 | TComVPS* vps = m_apcSlicePilot->getVPS(); |
---|
| 392 | Int layerIdInVps = vps->getLayerIdInVps( nalu.m_layerId ); |
---|
| 393 | |
---|
| 394 | setViewId( vps->getViewId( layerIdInVps ) ); |
---|
| 395 | m_apcSlicePilot->setViewId( getViewId() ); |
---|
| 396 | #if H_3D |
---|
| 397 | setIsDepth( vps->getDepthId( layerIdInVps ) == 1 ); |
---|
| 398 | m_apcSlicePilot->setIsDepth( getIsDepth() ); |
---|
| 399 | #endif |
---|
| 400 | #endif |
---|
[324] | 401 | // Skip pictures due to random access |
---|
| 402 | if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay)) |
---|
| 403 | { |
---|
| 404 | return false; |
---|
| 405 | } |
---|
| 406 | // Skip TFD pictures associated with BLA/BLANT pictures |
---|
| 407 | if (isSkipPictureForBLA(iPOCLastDisplay)) |
---|
| 408 | { |
---|
| 409 | return false; |
---|
| 410 | } |
---|
| 411 | |
---|
[362] | 412 | //we should only get a different poc for a new picture (with CTU address==0) |
---|
| 413 | if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0)) |
---|
| 414 | { |
---|
| 415 | printf ("Warning, the first slice of a picture might have been lost!\n"); |
---|
| 416 | } |
---|
[324] | 417 | // exit when a new picture is found |
---|
[362] | 418 | if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence ) |
---|
[324] | 419 | { |
---|
| 420 | if (m_prevPOC >= m_pocRandomAccess) |
---|
| 421 | { |
---|
| 422 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
| 423 | return true; |
---|
| 424 | } |
---|
| 425 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
| 426 | } |
---|
[368] | 427 | #if H_MV |
---|
| 428 | if ( newLayerFlag ) |
---|
| 429 | { |
---|
| 430 | return false; |
---|
| 431 | } |
---|
| 432 | #endif |
---|
[324] | 433 | // actual decoding starts here |
---|
| 434 | xActivateParameterSets(); |
---|
| 435 | |
---|
| 436 | if (m_apcSlicePilot->isNextSlice()) |
---|
| 437 | { |
---|
| 438 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
| 439 | } |
---|
| 440 | m_bFirstSliceInSequence = false; |
---|
| 441 | //detect lost reference picture and insert copy of earlier frame. |
---|
| 442 | Int lostPoc; |
---|
| 443 | while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0) |
---|
| 444 | { |
---|
| 445 | xCreateLostPicture(lostPoc-1); |
---|
| 446 | } |
---|
| 447 | if (m_bFirstSliceInPicture) |
---|
| 448 | { |
---|
| 449 | // Buffer initialize for prediction. |
---|
| 450 | m_cPrediction.initTempBuff(); |
---|
| 451 | m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS()); |
---|
[368] | 452 | #if H_MV |
---|
| 453 | m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); |
---|
| 454 | #endif |
---|
[324] | 455 | // Get a new picture buffer |
---|
| 456 | xGetNewPicBuffer (m_apcSlicePilot, pcPic); |
---|
| 457 | |
---|
| 458 | // transfer any SEI messages that have been received to the picture |
---|
| 459 | pcPic->setSEIs(m_SEIs); |
---|
| 460 | m_SEIs.clear(); |
---|
| 461 | |
---|
| 462 | // Recursive structure |
---|
| 463 | m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
| 464 | m_cCuDecoder.init ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction ); |
---|
| 465 | m_cTrQuant.init ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize()); |
---|
| 466 | |
---|
| 467 | m_cSliceDecoder.create(); |
---|
| 468 | } |
---|
| 469 | else |
---|
| 470 | { |
---|
| 471 | // Check if any new SEI has arrived |
---|
| 472 | if(!m_SEIs.empty()) |
---|
| 473 | { |
---|
| 474 | // Currently only decoding Unit SEI message occurring between VCL NALUs copied |
---|
| 475 | SEIMessages &picSEI = pcPic->getSEIs(); |
---|
| 476 | SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO); |
---|
| 477 | picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end()); |
---|
| 478 | deleteSEIs(m_SEIs); |
---|
| 479 | } |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | // Set picture slice pointer |
---|
| 483 | TComSlice* pcSlice = m_apcSlicePilot; |
---|
| 484 | Bool bNextSlice = pcSlice->isNextSlice(); |
---|
| 485 | |
---|
| 486 | UInt uiCummulativeTileWidth; |
---|
| 487 | UInt uiCummulativeTileHeight; |
---|
| 488 | UInt i, j, p; |
---|
| 489 | |
---|
| 490 | //set NumColumnsMins1 and NumRowsMinus1 |
---|
| 491 | pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() ); |
---|
| 492 | pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() ); |
---|
| 493 | |
---|
| 494 | //create the TComTileArray |
---|
| 495 | pcPic->getPicSym()->xCreateTComTileArray(); |
---|
| 496 | |
---|
| 497 | if( pcSlice->getPPS()->getUniformSpacingFlag() ) |
---|
| 498 | { |
---|
| 499 | //set the width for each tile |
---|
| 500 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
| 501 | { |
---|
| 502 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++) |
---|
| 503 | { |
---|
| 504 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )-> |
---|
| 505 | setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) |
---|
| 506 | - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) ); |
---|
| 507 | } |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | //set the height for each tile |
---|
| 511 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
| 512 | { |
---|
| 513 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++) |
---|
| 514 | { |
---|
| 515 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )-> |
---|
| 516 | setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) |
---|
| 517 | - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) ); |
---|
| 518 | } |
---|
| 519 | } |
---|
| 520 | } |
---|
| 521 | else |
---|
| 522 | { |
---|
| 523 | //set the width for each tile |
---|
| 524 | for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++) |
---|
| 525 | { |
---|
| 526 | uiCummulativeTileWidth = 0; |
---|
| 527 | for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++) |
---|
| 528 | { |
---|
| 529 | pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) ); |
---|
| 530 | uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i); |
---|
| 531 | } |
---|
| 532 | pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth ); |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | //set the height for each tile |
---|
| 536 | for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++) |
---|
| 537 | { |
---|
| 538 | uiCummulativeTileHeight = 0; |
---|
| 539 | for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++) |
---|
| 540 | { |
---|
| 541 | pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) ); |
---|
| 542 | uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i); |
---|
| 543 | } |
---|
| 544 | pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight ); |
---|
| 545 | } |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | pcPic->getPicSym()->xInitTiles(); |
---|
| 549 | |
---|
| 550 | //generate the Coding Order Map and Inverse Coding Order Map |
---|
| 551 | UInt uiEncCUAddr; |
---|
| 552 | for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr)) |
---|
| 553 | { |
---|
| 554 | pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr); |
---|
| 555 | pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i); |
---|
| 556 | } |
---|
| 557 | pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
| 558 | pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
| 559 | |
---|
| 560 | //convert the start and end CU addresses of the slice and dependent slice into encoding order |
---|
| 561 | pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) ); |
---|
| 562 | pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) ); |
---|
| 563 | if(pcSlice->isNextSlice()) |
---|
| 564 | { |
---|
| 565 | pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr())); |
---|
| 566 | pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr())); |
---|
| 567 | } |
---|
| 568 | |
---|
| 569 | if (m_bFirstSliceInPicture) |
---|
| 570 | { |
---|
| 571 | if(pcPic->getNumAllocatedSlice() != 1) |
---|
| 572 | { |
---|
| 573 | pcPic->clearSliceBuffer(); |
---|
| 574 | } |
---|
| 575 | } |
---|
| 576 | else |
---|
| 577 | { |
---|
| 578 | pcPic->allocateNewSlice(); |
---|
| 579 | } |
---|
| 580 | assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1)); |
---|
| 581 | m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); |
---|
| 582 | pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx); |
---|
| 583 | |
---|
| 584 | pcPic->setTLayer(nalu.m_temporalId); |
---|
| 585 | |
---|
[368] | 586 | #if H_MV |
---|
| 587 | pcPic->setLayerId( nalu.m_layerId ); |
---|
| 588 | pcPic->setViewId ( getViewId() ); |
---|
| 589 | #if H_3D |
---|
| 590 | pcPic->setIsDepth( getIsDepth() ); |
---|
| 591 | #endif |
---|
| 592 | #endif |
---|
[324] | 593 | if (bNextSlice) |
---|
| 594 | { |
---|
[362] | 595 | pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic ); |
---|
[324] | 596 | // Set reference list |
---|
[368] | 597 | #if H_MV |
---|
| 598 | pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true ); |
---|
| 599 | #else |
---|
[362] | 600 | #if FIX1071 |
---|
| 601 | pcSlice->setRefPicList( m_cListPic, true ); |
---|
| 602 | #else |
---|
[324] | 603 | pcSlice->setRefPicList( m_cListPic ); |
---|
| 604 | #endif |
---|
| 605 | |
---|
[368] | 606 | #endif |
---|
[324] | 607 | // For generalized B |
---|
| 608 | // note: maybe not existed case (always L0 is copied to L1 if L1 is empty) |
---|
| 609 | if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0) |
---|
| 610 | { |
---|
| 611 | Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0); |
---|
| 612 | pcSlice->setNumRefIdx ( REF_PIC_LIST_1, iNumRefIdx ); |
---|
| 613 | |
---|
| 614 | for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++) |
---|
| 615 | { |
---|
| 616 | pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx); |
---|
| 617 | } |
---|
| 618 | } |
---|
| 619 | if (!pcSlice->isIntra()) |
---|
| 620 | { |
---|
| 621 | Bool bLowDelay = true; |
---|
| 622 | Int iCurrPOC = pcSlice->getPOC(); |
---|
| 623 | Int iRefIdx = 0; |
---|
| 624 | |
---|
| 625 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++) |
---|
| 626 | { |
---|
| 627 | if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC ) |
---|
| 628 | { |
---|
| 629 | bLowDelay = false; |
---|
| 630 | } |
---|
| 631 | } |
---|
| 632 | if (pcSlice->isInterB()) |
---|
| 633 | { |
---|
| 634 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++) |
---|
| 635 | { |
---|
| 636 | if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC ) |
---|
| 637 | { |
---|
| 638 | bLowDelay = false; |
---|
| 639 | } |
---|
| 640 | } |
---|
| 641 | } |
---|
| 642 | |
---|
| 643 | pcSlice->setCheckLDC(bLowDelay); |
---|
| 644 | } |
---|
| 645 | |
---|
| 646 | //--------------- |
---|
| 647 | pcSlice->setRefPOCList(); |
---|
[362] | 648 | #if !L0034_COMBINED_LIST_CLEANUP |
---|
[324] | 649 | pcSlice->setNoBackPredFlag( false ); |
---|
| 650 | if ( pcSlice->getSliceType() == B_SLICE ) |
---|
| 651 | { |
---|
| 652 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
| 653 | { |
---|
| 654 | pcSlice->setNoBackPredFlag( true ); |
---|
| 655 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
| 656 | { |
---|
| 657 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
| 658 | { |
---|
| 659 | pcSlice->setNoBackPredFlag( false ); |
---|
| 660 | break; |
---|
| 661 | } |
---|
| 662 | } |
---|
| 663 | } |
---|
| 664 | } |
---|
[362] | 665 | #endif |
---|
[324] | 666 | } |
---|
| 667 | |
---|
| 668 | pcPic->setCurrSliceIdx(m_uiSliceIdx); |
---|
| 669 | if(pcSlice->getSPS()->getScalingListFlag()) |
---|
| 670 | { |
---|
| 671 | pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList() ); |
---|
| 672 | if(pcSlice->getPPS()->getScalingListPresentFlag()) |
---|
| 673 | { |
---|
| 674 | pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList() ); |
---|
| 675 | } |
---|
| 676 | pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip()); |
---|
| 677 | if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag()) |
---|
| 678 | { |
---|
| 679 | pcSlice->setDefaultScalingList(); |
---|
| 680 | } |
---|
| 681 | m_cTrQuant.setScalingListDec(pcSlice->getScalingList()); |
---|
| 682 | m_cTrQuant.setUseScalingList(true); |
---|
| 683 | } |
---|
| 684 | else |
---|
| 685 | { |
---|
| 686 | m_cTrQuant.setFlatScalingList(); |
---|
| 687 | m_cTrQuant.setUseScalingList(false); |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | // Decode a picture |
---|
| 691 | m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic); |
---|
| 692 | |
---|
| 693 | m_bFirstSliceInPicture = false; |
---|
| 694 | m_uiSliceIdx++; |
---|
| 695 | |
---|
| 696 | return false; |
---|
| 697 | } |
---|
| 698 | |
---|
| 699 | Void TDecTop::xDecodeVPS() |
---|
| 700 | { |
---|
| 701 | TComVPS* vps = new TComVPS(); |
---|
| 702 | |
---|
| 703 | m_cEntropyDecoder.decodeVPS( vps ); |
---|
| 704 | m_parameterSetManagerDecoder.storePrefetchedVPS(vps); |
---|
| 705 | } |
---|
| 706 | |
---|
| 707 | Void TDecTop::xDecodeSPS() |
---|
| 708 | { |
---|
| 709 | TComSPS* sps = new TComSPS(); |
---|
| 710 | m_cEntropyDecoder.decodeSPS( sps ); |
---|
| 711 | m_parameterSetManagerDecoder.storePrefetchedSPS(sps); |
---|
| 712 | } |
---|
| 713 | |
---|
| 714 | Void TDecTop::xDecodePPS() |
---|
| 715 | { |
---|
| 716 | TComPPS* pps = new TComPPS(); |
---|
| 717 | m_cEntropyDecoder.decodePPS( pps ); |
---|
| 718 | m_parameterSetManagerDecoder.storePrefetchedPPS( pps ); |
---|
| 719 | } |
---|
| 720 | |
---|
| 721 | Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType ) |
---|
| 722 | { |
---|
[362] | 723 | if(nalUnitType == NAL_UNIT_SUFFIX_SEI) |
---|
[324] | 724 | { |
---|
| 725 | m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() ); |
---|
| 726 | } |
---|
| 727 | else |
---|
| 728 | { |
---|
| 729 | m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() ); |
---|
| 730 | SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS); |
---|
| 731 | if (activeParamSets.size()>0) |
---|
| 732 | { |
---|
| 733 | SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin()); |
---|
| 734 | m_parameterSetManagerDecoder.applyPrefetchedPS(); |
---|
| 735 | assert(seiAps->activeSeqParamSetId.size()>0); |
---|
| 736 | if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] )) |
---|
| 737 | { |
---|
| 738 | printf ("Warning SPS activation with Active parameter set SEI failed"); |
---|
| 739 | } |
---|
| 740 | } |
---|
| 741 | } |
---|
| 742 | } |
---|
| 743 | |
---|
[368] | 744 | #if H_MV |
---|
| 745 | Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag) |
---|
| 746 | #else |
---|
[324] | 747 | Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay) |
---|
[368] | 748 | #endif |
---|
[324] | 749 | { |
---|
| 750 | // Initialize entropy decoder |
---|
| 751 | m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder); |
---|
| 752 | m_cEntropyDecoder.setBitstream (nalu.m_Bitstream); |
---|
| 753 | |
---|
| 754 | switch (nalu.m_nalUnitType) |
---|
| 755 | { |
---|
| 756 | case NAL_UNIT_VPS: |
---|
| 757 | xDecodeVPS(); |
---|
| 758 | return false; |
---|
| 759 | |
---|
| 760 | case NAL_UNIT_SPS: |
---|
| 761 | xDecodeSPS(); |
---|
| 762 | return false; |
---|
| 763 | |
---|
| 764 | case NAL_UNIT_PPS: |
---|
| 765 | xDecodePPS(); |
---|
| 766 | return false; |
---|
| 767 | |
---|
[362] | 768 | case NAL_UNIT_PREFIX_SEI: |
---|
| 769 | case NAL_UNIT_SUFFIX_SEI: |
---|
[324] | 770 | xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType ); |
---|
| 771 | return false; |
---|
| 772 | |
---|
| 773 | case NAL_UNIT_CODED_SLICE_TRAIL_R: |
---|
| 774 | case NAL_UNIT_CODED_SLICE_TRAIL_N: |
---|
[362] | 775 | case NAL_UNIT_CODED_SLICE_TLA_R: |
---|
[324] | 776 | case NAL_UNIT_CODED_SLICE_TSA_N: |
---|
| 777 | case NAL_UNIT_CODED_SLICE_STSA_R: |
---|
| 778 | case NAL_UNIT_CODED_SLICE_STSA_N: |
---|
[362] | 779 | case NAL_UNIT_CODED_SLICE_BLA_W_LP: |
---|
| 780 | case NAL_UNIT_CODED_SLICE_BLA_W_RADL: |
---|
[324] | 781 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: |
---|
[362] | 782 | case NAL_UNIT_CODED_SLICE_IDR_W_RADL: |
---|
[324] | 783 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: |
---|
| 784 | case NAL_UNIT_CODED_SLICE_CRA: |
---|
| 785 | case NAL_UNIT_CODED_SLICE_RADL_N: |
---|
[362] | 786 | case NAL_UNIT_CODED_SLICE_RADL_R: |
---|
[324] | 787 | case NAL_UNIT_CODED_SLICE_RASL_N: |
---|
[362] | 788 | case NAL_UNIT_CODED_SLICE_RASL_R: |
---|
[368] | 789 | #if H_MV |
---|
| 790 | return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag); |
---|
| 791 | #else |
---|
[324] | 792 | return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay); |
---|
[368] | 793 | #endif |
---|
[324] | 794 | break; |
---|
| 795 | default: |
---|
| 796 | assert (1); |
---|
| 797 | } |
---|
| 798 | |
---|
| 799 | return false; |
---|
| 800 | } |
---|
| 801 | |
---|
| 802 | /** Function for checking if picture should be skipped because of association with a previous BLA picture |
---|
| 803 | * \param iPOCLastDisplay POC of last picture displayed |
---|
| 804 | * \returns true if the picture should be skipped |
---|
| 805 | * This function skips all TFD pictures that follow a BLA picture |
---|
| 806 | * in decoding order and precede it in output order. |
---|
| 807 | */ |
---|
| 808 | Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay) |
---|
| 809 | { |
---|
[362] | 810 | if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N)) |
---|
[324] | 811 | { |
---|
| 812 | iPOCLastDisplay++; |
---|
| 813 | return true; |
---|
| 814 | } |
---|
| 815 | return false; |
---|
| 816 | } |
---|
| 817 | |
---|
| 818 | /** Function for checking if picture should be skipped because of random access |
---|
| 819 | * \param iSkipFrame skip frame counter |
---|
| 820 | * \param iPOCLastDisplay POC of last picture displayed |
---|
| 821 | * \returns true if the picture shold be skipped in the random access. |
---|
| 822 | * This function checks the skipping of pictures in the case of -s option random access. |
---|
| 823 | * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped. |
---|
| 824 | * It also checks the type of Nal unit type at the random access point. |
---|
| 825 | * 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. |
---|
| 826 | * If the random access point is IDR all pictures after the random access point are decoded. |
---|
| 827 | * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC |
---|
| 828 | * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random |
---|
| 829 | * access point there is no guarantee that the decoder will not crash. |
---|
| 830 | */ |
---|
| 831 | Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame, Int& iPOCLastDisplay) |
---|
| 832 | { |
---|
| 833 | if (iSkipFrame) |
---|
| 834 | { |
---|
| 835 | iSkipFrame--; // decrement the counter |
---|
| 836 | return true; |
---|
| 837 | } |
---|
| 838 | else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet. |
---|
| 839 | { |
---|
| 840 | if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA |
---|
[362] | 841 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
[324] | 842 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
[362] | 843 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ) |
---|
[324] | 844 | { |
---|
| 845 | // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT. |
---|
| 846 | m_pocRandomAccess = m_apcSlicePilot->getPOC(); |
---|
| 847 | } |
---|
[362] | 848 | else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
---|
[324] | 849 | { |
---|
| 850 | m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable. |
---|
| 851 | } |
---|
| 852 | else |
---|
| 853 | { |
---|
| 854 | static Bool warningMessage = false; |
---|
| 855 | if(!warningMessage) |
---|
| 856 | { |
---|
| 857 | printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture"); |
---|
| 858 | warningMessage = true; |
---|
| 859 | } |
---|
| 860 | return true; |
---|
| 861 | } |
---|
| 862 | } |
---|
| 863 | // skip the reordered pictures, if necessary |
---|
[362] | 864 | 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)) |
---|
[324] | 865 | { |
---|
| 866 | iPOCLastDisplay++; |
---|
| 867 | return true; |
---|
| 868 | } |
---|
| 869 | // if we reach here, then the picture is not skipped. |
---|
| 870 | return false; |
---|
| 871 | } |
---|
| 872 | |
---|
[368] | 873 | #if H_MV |
---|
| 874 | TComPic* TDecTop::getPic( Int poc ) |
---|
| 875 | { |
---|
| 876 | xGetPic( m_layerId, poc ); |
---|
| 877 | TComList<TComPic*>* listPic = getListPic(); |
---|
| 878 | TComPic* pcPic = NULL; |
---|
| 879 | for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++) |
---|
| 880 | { |
---|
| 881 | if( (*it)->getPOC() == poc ) |
---|
| 882 | { |
---|
| 883 | pcPic = *it ; |
---|
| 884 | break ; |
---|
| 885 | } |
---|
| 886 | } |
---|
| 887 | return pcPic; |
---|
| 888 | } |
---|
| 889 | |
---|
| 890 | TComPic* TDecTop::xGetPic( Int layerId, Int poc ) |
---|
| 891 | { |
---|
| 892 | return m_ivPicLists->getPic( layerId, poc ) ; |
---|
| 893 | } |
---|
| 894 | |
---|
| 895 | #endif |
---|
[324] | 896 | //! \} |
---|