[2] | 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-2012, 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 | ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder; // storage for parameter sets |
---|
| 43 | UInt TDecTop::m_prevPOC = MAX_UINT; |
---|
| 44 | UInt TDecTop::m_uiPrevLayerId = MAX_UINT; |
---|
| 45 | Bool TDecTop::m_bFirstSliceInSequence = true; |
---|
| 46 | #endif |
---|
| 47 | |
---|
| 48 | //! \ingroup TLibDecoder |
---|
| 49 | //! \{ |
---|
| 50 | |
---|
| 51 | TDecTop::TDecTop() |
---|
| 52 | : m_SEIs(0) |
---|
| 53 | { |
---|
| 54 | m_pcPic = 0; |
---|
| 55 | m_iGopSize = 0; |
---|
| 56 | m_bGopSizeSet = false; |
---|
| 57 | m_iMaxRefPicNum = 0; |
---|
| 58 | #if ENC_DEC_TRACE |
---|
| 59 | g_hTrace = fopen( "TraceDec.txt", "wb" ); |
---|
| 60 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
| 61 | g_nSymbolCounter = 0; |
---|
| 62 | #endif |
---|
| 63 | m_bRefreshPending = 0; |
---|
| 64 | m_pocCRA = 0; |
---|
| 65 | m_prevRAPisBLA = false; |
---|
| 66 | m_pocRandomAccess = MAX_INT; |
---|
| 67 | #if !SVC_EXTENSION |
---|
| 68 | m_prevPOC = MAX_INT; |
---|
| 69 | #endif |
---|
| 70 | m_bFirstSliceInPicture = true; |
---|
| 71 | #if !SVC_EXTENSION |
---|
| 72 | m_bFirstSliceInSequence = true; |
---|
| 73 | #endif |
---|
| 74 | #if SVC_EXTENSION |
---|
| 75 | m_layerId = 0; |
---|
| 76 | #if AVC_BASE |
---|
| 77 | m_pBLReconFile = NULL; |
---|
| 78 | #endif |
---|
| 79 | #endif |
---|
| 80 | #if REF_IDX_FRAMEWORK |
---|
| 81 | memset(m_cIlpPic, 0, sizeof(m_cIlpPic)); |
---|
| 82 | #endif |
---|
| 83 | |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | TDecTop::~TDecTop() |
---|
| 87 | { |
---|
| 88 | #if ENC_DEC_TRACE |
---|
| 89 | fclose( g_hTrace ); |
---|
| 90 | #endif |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | Void TDecTop::create() |
---|
| 94 | { |
---|
| 95 | #if SVC_EXTENSION |
---|
| 96 | m_cGopDecoder.create( m_layerId ); |
---|
| 97 | #else |
---|
| 98 | m_cGopDecoder.create(); |
---|
| 99 | #endif |
---|
| 100 | m_apcSlicePilot = new TComSlice; |
---|
| 101 | m_uiSliceIdx = 0; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | Void TDecTop::destroy() |
---|
| 105 | { |
---|
| 106 | m_cGopDecoder.destroy(); |
---|
| 107 | |
---|
| 108 | delete m_apcSlicePilot; |
---|
| 109 | m_apcSlicePilot = NULL; |
---|
| 110 | |
---|
| 111 | m_cSliceDecoder.destroy(); |
---|
| 112 | #if REF_IDX_FRAMEWORK |
---|
| 113 | for(Int i=0; i<MAX_NUM_REF; i++) |
---|
| 114 | { |
---|
| 115 | if(m_cIlpPic[i]) |
---|
| 116 | { |
---|
| 117 | //m_cIlpPic[i]->setPicYuvRec(NULL); |
---|
| 118 | m_cIlpPic[i]->destroy(); |
---|
| 119 | delete m_cIlpPic[i]; |
---|
| 120 | m_cIlpPic[i] = NULL; |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | #endif |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | Void TDecTop::init() |
---|
| 127 | { |
---|
| 128 | #if !SVC_EXTENSION |
---|
| 129 | // initialize ROM |
---|
| 130 | initROM(); |
---|
| 131 | #endif |
---|
| 132 | #if SVC_EXTENSION |
---|
| 133 | #if REMOVE_ALF |
---|
| 134 | m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO); |
---|
| 135 | #else |
---|
| 136 | m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO); |
---|
| 137 | #endif |
---|
| 138 | m_cSliceDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cCuDecoder ); |
---|
| 139 | #else |
---|
| 140 | #if REMOVE_ALF |
---|
| 141 | m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO); |
---|
| 142 | #else |
---|
| 143 | m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO); |
---|
| 144 | #endif |
---|
| 145 | m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder ); |
---|
| 146 | #endif |
---|
| 147 | m_cEntropyDecoder.init(&m_cPrediction); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | #if REF_IDX_FRAMEWORK |
---|
| 151 | Void TDecTop::xInitILRP(TComSPS *pcSPS) |
---|
| 152 | { |
---|
| 153 | if(m_layerId>0) |
---|
| 154 | { |
---|
| 155 | if (m_cIlpPic[0] == NULL) |
---|
| 156 | { |
---|
| 157 | for (Int j=0; j<1/*MAX_NUM_REF*/; j++) |
---|
| 158 | { |
---|
| 159 | m_cIlpPic[j] = new TComPic; |
---|
| 160 | //m_cIlpPic[j]->createWithOutYuv(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, &m_cSPS, true); |
---|
[6] | 161 | #if SVC_UPSAMPLING |
---|
[2] | 162 | m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, pcSPS, true); |
---|
[6] | 163 | #else |
---|
| 164 | m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true); |
---|
| 165 | #endif |
---|
[2] | 166 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++) |
---|
| 167 | { |
---|
| 168 | m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i); |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | Void TDecTop::setILRPic(TComPic *pcPic) |
---|
| 176 | { |
---|
| 177 | if(m_cIlpPic[0]) |
---|
| 178 | { |
---|
| 179 | //m_cIlpPic[0]->setPicYuvRec(pcPic->getFullPelBaseRec()); |
---|
| 180 | m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec()); |
---|
| 181 | m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC()); |
---|
| 182 | m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false); |
---|
| 183 | m_cIlpPic[0]->getPicYuvRec()->extendPicBorder(); |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | #endif |
---|
| 187 | |
---|
| 188 | Void TDecTop::deletePicBuffer ( ) |
---|
| 189 | { |
---|
| 190 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
| 191 | Int iSize = Int( m_cListPic.size() ); |
---|
| 192 | |
---|
| 193 | for (Int i = 0; i < iSize; i++ ) |
---|
| 194 | { |
---|
| 195 | TComPic* pcPic = *(iterPic++); |
---|
| 196 | #if SVC_EXTENSION |
---|
| 197 | if( pcPic ) |
---|
| 198 | { |
---|
| 199 | pcPic->destroy(); |
---|
| 200 | |
---|
| 201 | delete pcPic; |
---|
| 202 | pcPic = NULL; |
---|
| 203 | } |
---|
| 204 | #else |
---|
| 205 | pcPic->destroy(); |
---|
| 206 | |
---|
| 207 | delete pcPic; |
---|
| 208 | pcPic = NULL; |
---|
| 209 | #endif |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | #if !REMOVE_ALF |
---|
| 213 | // destroy ALF temporary buffers |
---|
| 214 | m_cAdaptiveLoopFilter.destroy(); |
---|
| 215 | #endif |
---|
| 216 | |
---|
| 217 | m_cSAO.destroy(); |
---|
| 218 | |
---|
| 219 | m_cLoopFilter. destroy(); |
---|
| 220 | |
---|
| 221 | #if !SVC_EXTENSION |
---|
| 222 | // destroy ROM |
---|
| 223 | destroyROM(); |
---|
| 224 | #endif |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | Void TDecTop::xUpdateGopSize (TComSlice* pcSlice) |
---|
| 228 | { |
---|
| 229 | if ( !pcSlice->isIntra() && !m_bGopSizeSet) |
---|
| 230 | { |
---|
| 231 | m_iGopSize = pcSlice->getPOC(); |
---|
| 232 | m_bGopSizeSet = true; |
---|
| 233 | |
---|
| 234 | m_cGopDecoder.setGopSize(m_iGopSize); |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic ) |
---|
| 239 | { |
---|
| 240 | xUpdateGopSize(pcSlice); |
---|
| 241 | |
---|
| 242 | m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded |
---|
| 243 | if (m_cListPic.size() < (UInt)m_iMaxRefPicNum) |
---|
| 244 | { |
---|
| 245 | rpcPic = new TComPic(); |
---|
| 246 | |
---|
| 247 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
| 248 | if(m_layerId > 0) |
---|
| 249 | { |
---|
| 250 | TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 ); |
---|
| 251 | //TComPic* pcPic = *(pcTDecTopBase->getListPic()->begin()); |
---|
| 252 | TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); |
---|
| 253 | if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() ) |
---|
| 254 | { |
---|
| 255 | rpcPic->setSpatialEnhLayerFlag( true ); |
---|
| 256 | } |
---|
| 257 | } |
---|
| 258 | #endif |
---|
| 259 | |
---|
| 260 | #if SVC_UPSAMPLING |
---|
| 261 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, pcSlice->getSPS(), true); |
---|
| 262 | #else |
---|
| 263 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true); |
---|
| 264 | #endif |
---|
| 265 | |
---|
| 266 | #if REMOVE_APS |
---|
| 267 | rpcPic->getPicSym()->allocSaoParam(&m_cSAO); |
---|
| 268 | #endif |
---|
| 269 | m_cListPic.pushBack( rpcPic ); |
---|
| 270 | |
---|
| 271 | return; |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | Bool bBufferIsAvailable = false; |
---|
| 275 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
| 276 | while (iterPic != m_cListPic.end()) |
---|
| 277 | { |
---|
| 278 | rpcPic = *(iterPic++); |
---|
| 279 | if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false) |
---|
| 280 | { |
---|
| 281 | rpcPic->setOutputMark(false); |
---|
| 282 | bBufferIsAvailable = true; |
---|
| 283 | break; |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | if ( rpcPic->getSlice( 0 )->isReferenced() == false && rpcPic->getOutputMark() == false) |
---|
| 287 | { |
---|
| 288 | #if !SVC_EXTENSION |
---|
| 289 | rpcPic->setOutputMark(false); |
---|
| 290 | #endif |
---|
| 291 | rpcPic->setReconMark( false ); |
---|
| 292 | rpcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 293 | bBufferIsAvailable = true; |
---|
| 294 | break; |
---|
| 295 | } |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | if ( !bBufferIsAvailable ) |
---|
| 299 | { |
---|
| 300 | //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer. |
---|
| 301 | m_iMaxRefPicNum++; |
---|
| 302 | rpcPic = new TComPic(); |
---|
| 303 | m_cListPic.pushBack( rpcPic ); |
---|
| 304 | } |
---|
| 305 | rpcPic->destroy(); |
---|
| 306 | |
---|
| 307 | #if SVC_UPSAMPLING |
---|
| 308 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, pcSlice->getSPS(), true); |
---|
| 309 | #else |
---|
| 310 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true); |
---|
| 311 | #endif |
---|
| 312 | #if REMOVE_APS |
---|
| 313 | rpcPic->getPicSym()->allocSaoParam(&m_cSAO); |
---|
| 314 | #endif |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | Void TDecTop::executeDeblockAndAlf(UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame, Int& iPOCLastDisplay) |
---|
| 318 | { |
---|
| 319 | if (!m_pcPic) |
---|
| 320 | { |
---|
| 321 | /* nothing to deblock */ |
---|
| 322 | return; |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | TComPic*& pcPic = m_pcPic; |
---|
| 326 | |
---|
| 327 | // Execute Deblock and ALF only + Cleanup |
---|
| 328 | |
---|
| 329 | m_cGopDecoder.filterPicture(pcPic); |
---|
| 330 | |
---|
| 331 | TComSlice::sortPicList( m_cListPic ); // sorting for application output |
---|
| 332 | ruiPOC = pcPic->getSlice(m_uiSliceIdx-1)->getPOC(); |
---|
| 333 | rpcListPic = &m_cListPic; |
---|
| 334 | m_cCuDecoder.destroy(); |
---|
| 335 | m_bFirstSliceInPicture = true; |
---|
| 336 | |
---|
| 337 | return; |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | Void TDecTop::xCreateLostPicture(Int iLostPoc) |
---|
| 341 | { |
---|
| 342 | printf("\ninserting lost poc : %d\n",iLostPoc); |
---|
| 343 | TComSlice cFillSlice; |
---|
| 344 | cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() ); |
---|
| 345 | cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() ); |
---|
| 346 | cFillSlice.initSlice(); |
---|
| 347 | TComPic *cFillPic; |
---|
| 348 | xGetNewPicBuffer(&cFillSlice,cFillPic); |
---|
| 349 | cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() ); |
---|
| 350 | cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() ); |
---|
| 351 | cFillPic->getSlice(0)->initSlice(); |
---|
| 352 | |
---|
| 353 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
| 354 | Int closestPoc = 1000000; |
---|
| 355 | while ( iterPic != m_cListPic.end()) |
---|
| 356 | { |
---|
| 357 | TComPic * rpcPic = *(iterPic++); |
---|
| 358 | 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()) |
---|
| 359 | { |
---|
| 360 | closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc); |
---|
| 361 | } |
---|
| 362 | } |
---|
| 363 | iterPic = m_cListPic.begin(); |
---|
| 364 | while ( iterPic != m_cListPic.end()) |
---|
| 365 | { |
---|
| 366 | TComPic *rpcPic = *(iterPic++); |
---|
| 367 | if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC()) |
---|
| 368 | { |
---|
| 369 | printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC()); |
---|
| 370 | rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec()); |
---|
| 371 | break; |
---|
| 372 | } |
---|
| 373 | } |
---|
| 374 | cFillPic->setCurrSliceIdx(0); |
---|
| 375 | for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) |
---|
| 376 | { |
---|
| 377 | cFillPic->getCU(i)->initCU(cFillPic,i); |
---|
| 378 | } |
---|
| 379 | cFillPic->getSlice(0)->setReferenced(true); |
---|
| 380 | cFillPic->getSlice(0)->setPOC(iLostPoc); |
---|
| 381 | cFillPic->setReconMark(true); |
---|
| 382 | cFillPic->setOutputMark(true); |
---|
| 383 | if(m_pocRandomAccess == MAX_INT) |
---|
| 384 | { |
---|
| 385 | m_pocRandomAccess = iLostPoc; |
---|
| 386 | } |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | |
---|
| 390 | Void TDecTop::xActivateParameterSets() |
---|
| 391 | { |
---|
| 392 | m_parameterSetManagerDecoder.applyPrefetchedPS(); |
---|
| 393 | |
---|
| 394 | TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId()); |
---|
| 395 | assert (pps != 0); |
---|
| 396 | |
---|
| 397 | TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId()); |
---|
| 398 | assert (sps != 0); |
---|
| 399 | |
---|
| 400 | m_apcSlicePilot->setPPS(pps); |
---|
| 401 | m_apcSlicePilot->setSPS(sps); |
---|
| 402 | pps->setSPS(sps); |
---|
| 403 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
| 404 | pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1); |
---|
| 405 | #else |
---|
| 406 | pps->setNumSubstreams(pps->getTilesOrEntropyCodingSyncIdc() == 2 ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1); |
---|
| 407 | #endif |
---|
| 408 | #if !REMOVE_APS |
---|
| 409 | #if REMOVE_ALF |
---|
| 410 | if(sps->getUseSAO()) |
---|
| 411 | #else |
---|
| 412 | if(sps->getUseSAO() || sps->getUseALF()) |
---|
| 413 | #endif |
---|
| 414 | { |
---|
| 415 | m_apcSlicePilot->setAPS( m_parameterSetManagerDecoder.getAPS(m_apcSlicePilot->getAPSId()) ); |
---|
| 416 | } |
---|
| 417 | #endif |
---|
| 418 | pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) ); |
---|
| 419 | |
---|
| 420 | for (Int i = 0; i < sps->getMaxCUDepth() - g_uiAddCUDepth; i++) |
---|
| 421 | { |
---|
| 422 | sps->setAMPAcc( i, sps->getUseAMP() ); |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | for (Int i = sps->getMaxCUDepth() - g_uiAddCUDepth; i < sps->getMaxCUDepth(); i++) |
---|
| 426 | { |
---|
| 427 | sps->setAMPAcc( i, 0 ); |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | m_cSAO.destroy(); |
---|
| 431 | m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 432 | m_cLoopFilter. create( g_uiMaxCUDepth ); |
---|
| 433 | } |
---|
| 434 | |
---|
| 435 | #if SVC_EXTENSION |
---|
| 436 | Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC ) |
---|
| 437 | #else |
---|
| 438 | Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay ) |
---|
| 439 | #endif |
---|
| 440 | { |
---|
| 441 | TComPic*& pcPic = m_pcPic; |
---|
| 442 | m_apcSlicePilot->initSlice(); |
---|
| 443 | |
---|
| 444 | if (m_bFirstSliceInPicture) |
---|
| 445 | { |
---|
| 446 | m_uiSliceIdx = 0; |
---|
| 447 | } |
---|
| 448 | m_apcSlicePilot->setSliceIdx(m_uiSliceIdx); |
---|
| 449 | if (!m_bFirstSliceInPicture) |
---|
| 450 | { |
---|
| 451 | m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) ); |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType); |
---|
| 455 | #if TEMPORAL_LAYER_NON_REFERENCE |
---|
| 456 | if((m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N) || |
---|
| 457 | (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N) || |
---|
| 458 | (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N)) |
---|
| 459 | { |
---|
| 460 | m_apcSlicePilot->setTemporalLayerNonReferenceFlag(true); |
---|
| 461 | } |
---|
| 462 | #endif |
---|
| 463 | #if REMOVE_NAL_REF_FLAG |
---|
| 464 | m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS |
---|
| 465 | #else |
---|
| 466 | m_apcSlicePilot->setReferenced(nalu.m_nalRefFlag); |
---|
| 467 | #endif |
---|
| 468 | m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId); |
---|
| 469 | m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder); |
---|
| 470 | #if !BYTE_ALIGNMENT |
---|
| 471 | // byte align |
---|
| 472 | { |
---|
| 473 | Int numBitsForByteAlignment = nalu.m_Bitstream->getNumBitsUntilByteAligned(); |
---|
| 474 | if ( numBitsForByteAlignment > 0 ) |
---|
| 475 | { |
---|
| 476 | UInt bitsForByteAlignment; |
---|
| 477 | nalu.m_Bitstream->read( numBitsForByteAlignment, bitsForByteAlignment ); |
---|
| 478 | assert( bitsForByteAlignment == ( ( 1 << numBitsForByteAlignment ) - 1 ) ); |
---|
| 479 | } |
---|
| 480 | } |
---|
| 481 | #endif |
---|
| 482 | // exit when a new picture is found |
---|
| 483 | #if SVC_EXTENSION |
---|
| 484 | bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC); |
---|
| 485 | if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) |
---|
| 486 | && !m_bFirstSliceInSequence ) |
---|
| 487 | { |
---|
| 488 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
| 489 | curLayerId = m_uiPrevLayerId; |
---|
| 490 | m_uiPrevLayerId = m_layerId; |
---|
| 491 | return true; |
---|
| 492 | } |
---|
| 493 | #else |
---|
| 494 | if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence) |
---|
| 495 | { |
---|
| 496 | if (m_prevPOC >= m_pocRandomAccess) |
---|
| 497 | { |
---|
| 498 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
| 499 | return true; |
---|
| 500 | } |
---|
| 501 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
| 502 | } |
---|
| 503 | #endif |
---|
| 504 | // actual decoding starts here |
---|
| 505 | xActivateParameterSets(); |
---|
| 506 | |
---|
| 507 | if (m_apcSlicePilot->isNextSlice()) |
---|
| 508 | { |
---|
| 509 | m_prevPOC = m_apcSlicePilot->getPOC(); |
---|
| 510 | #if SVC_EXTENSION |
---|
| 511 | curLayerId = m_layerId; |
---|
| 512 | m_uiPrevLayerId = m_layerId; |
---|
| 513 | #endif |
---|
| 514 | } |
---|
| 515 | m_bFirstSliceInSequence = false; |
---|
| 516 | if (m_apcSlicePilot->isNextSlice()) |
---|
| 517 | { |
---|
| 518 | // Skip pictures due to random access |
---|
| 519 | if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay)) |
---|
| 520 | { |
---|
| 521 | return false; |
---|
| 522 | } |
---|
| 523 | // Skip TFD pictures associated with BLA/BLANT pictures |
---|
| 524 | if (isSkipPictureForBLA(iPOCLastDisplay)) |
---|
| 525 | { |
---|
| 526 | return false; |
---|
| 527 | } |
---|
| 528 | } |
---|
| 529 | //detect lost reference picture and insert copy of earlier frame. |
---|
| 530 | Int lostPoc; |
---|
| 531 | while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0) |
---|
| 532 | { |
---|
| 533 | xCreateLostPicture(lostPoc-1); |
---|
| 534 | } |
---|
| 535 | if (m_bFirstSliceInPicture) |
---|
| 536 | { |
---|
| 537 | |
---|
| 538 | #if AVC_BASE |
---|
| 539 | if( m_layerId == 1 ) |
---|
| 540 | { |
---|
| 541 | TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin()); |
---|
| 542 | FILE* pFile = m_ppcTDecTop[0]->getBLReconFile(); |
---|
| 543 | UInt uiWidth = pBLPic->getPicYuvRec()->getWidth(); |
---|
| 544 | UInt uiHeight = pBLPic->getPicYuvRec()->getHeight(); |
---|
| 545 | |
---|
| 546 | if( pFile ) |
---|
| 547 | { |
---|
| 548 | fseek( pFile, m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2, SEEK_SET ); |
---|
| 549 | |
---|
| 550 | Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr(); |
---|
| 551 | UInt uiStride = pBLPic->getPicYuvRec()->getStride(); |
---|
| 552 | for( Int i = 0; i < uiHeight; i++ ) |
---|
| 553 | { |
---|
| 554 | for( Int j = 0; j < uiWidth; j++ ) |
---|
| 555 | { |
---|
| 556 | pPel[j] = fgetc( pFile ); |
---|
| 557 | } |
---|
| 558 | pPel += uiStride; |
---|
| 559 | } |
---|
| 560 | |
---|
| 561 | pPel = pBLPic->getPicYuvRec()->getCbAddr(); |
---|
| 562 | uiStride = pBLPic->getPicYuvRec()->getCStride(); |
---|
| 563 | for( Int i = 0; i < uiHeight/2; i++ ) |
---|
| 564 | { |
---|
| 565 | for( Int j = 0; j < uiWidth/2; j++ ) |
---|
| 566 | { |
---|
| 567 | pPel[j] = fgetc( pFile ); |
---|
| 568 | } |
---|
| 569 | pPel += uiStride; |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | pPel = pBLPic->getPicYuvRec()->getCrAddr(); |
---|
| 573 | uiStride = pBLPic->getPicYuvRec()->getCStride(); |
---|
| 574 | for( Int i = 0; i < uiHeight/2; i++ ) |
---|
| 575 | { |
---|
| 576 | for( Int j = 0; j < uiWidth/2; j++ ) |
---|
| 577 | { |
---|
| 578 | pPel[j] = fgetc( pFile ); |
---|
| 579 | } |
---|
| 580 | pPel += uiStride; |
---|
| 581 | } |
---|
| 582 | } |
---|
| 583 | } |
---|
| 584 | #endif |
---|
| 585 | |
---|
| 586 | // Buffer initialize for prediction. |
---|
| 587 | m_cPrediction.initTempBuff(); |
---|
| 588 | m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS()); |
---|
| 589 | // Get a new picture buffer |
---|
| 590 | xGetNewPicBuffer (m_apcSlicePilot, pcPic); |
---|
| 591 | |
---|
| 592 | /* transfer any SEI messages that have been received to the picture */ |
---|
| 593 | pcPic->setSEIs(m_SEIs); |
---|
| 594 | m_SEIs = NULL; |
---|
| 595 | |
---|
| 596 | // Recursive structure |
---|
| 597 | m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
| 598 | #if SVC_EXTENSION |
---|
| 599 | m_cCuDecoder.init ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId ); |
---|
| 600 | #else |
---|
| 601 | m_cCuDecoder.init ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction ); |
---|
| 602 | #endif |
---|
| 603 | m_cTrQuant.init ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize()); |
---|
| 604 | |
---|
| 605 | m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | // Set picture slice pointer |
---|
| 609 | TComSlice* pcSlice = m_apcSlicePilot; |
---|
| 610 | Bool bNextSlice = pcSlice->isNextSlice(); |
---|
| 611 | |
---|
| 612 | UInt uiCummulativeTileWidth; |
---|
| 613 | UInt uiCummulativeTileHeight; |
---|
| 614 | UInt i, j, p; |
---|
| 615 | |
---|
| 616 | //set NumColumnsMins1 and NumRowsMinus1 |
---|
| 617 | pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() ); |
---|
| 618 | pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() ); |
---|
| 619 | |
---|
| 620 | //create the TComTileArray |
---|
| 621 | pcPic->getPicSym()->xCreateTComTileArray(); |
---|
| 622 | |
---|
| 623 | if( pcSlice->getPPS()->getUniformSpacingFlag() ) |
---|
| 624 | { |
---|
| 625 | //set the width for each tile |
---|
| 626 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
| 627 | { |
---|
| 628 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++) |
---|
| 629 | { |
---|
| 630 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )-> |
---|
| 631 | setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) |
---|
| 632 | - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) ); |
---|
| 633 | } |
---|
| 634 | } |
---|
| 635 | |
---|
| 636 | //set the height for each tile |
---|
| 637 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
| 638 | { |
---|
| 639 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++) |
---|
| 640 | { |
---|
| 641 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )-> |
---|
| 642 | setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) |
---|
| 643 | - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) ); |
---|
| 644 | } |
---|
| 645 | } |
---|
| 646 | } |
---|
| 647 | else |
---|
| 648 | { |
---|
| 649 | //set the width for each tile |
---|
| 650 | for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++) |
---|
| 651 | { |
---|
| 652 | uiCummulativeTileWidth = 0; |
---|
| 653 | for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++) |
---|
| 654 | { |
---|
| 655 | pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) ); |
---|
| 656 | uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i); |
---|
| 657 | } |
---|
| 658 | pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth ); |
---|
| 659 | } |
---|
| 660 | |
---|
| 661 | //set the height for each tile |
---|
| 662 | for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++) |
---|
| 663 | { |
---|
| 664 | uiCummulativeTileHeight = 0; |
---|
| 665 | for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++) |
---|
| 666 | { |
---|
| 667 | pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) ); |
---|
| 668 | uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i); |
---|
| 669 | } |
---|
| 670 | pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight ); |
---|
| 671 | } |
---|
| 672 | } |
---|
| 673 | |
---|
| 674 | pcPic->getPicSym()->xInitTiles(); |
---|
| 675 | |
---|
| 676 | //generate the Coding Order Map and Inverse Coding Order Map |
---|
| 677 | UInt uiEncCUAddr; |
---|
| 678 | for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr)) |
---|
| 679 | { |
---|
| 680 | pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr); |
---|
| 681 | pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i); |
---|
| 682 | } |
---|
| 683 | pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
| 684 | pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
| 685 | |
---|
| 686 | //convert the start and end CU addresses of the slice and dependent slice into encoding order |
---|
| 687 | pcSlice->setDependentSliceCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getDependentSliceCurStartCUAddr()) ); |
---|
| 688 | pcSlice->setDependentSliceCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getDependentSliceCurEndCUAddr()) ); |
---|
| 689 | if(pcSlice->isNextSlice()) |
---|
| 690 | { |
---|
| 691 | pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr())); |
---|
| 692 | pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr())); |
---|
| 693 | } |
---|
| 694 | |
---|
| 695 | if (m_bFirstSliceInPicture) |
---|
| 696 | { |
---|
| 697 | if(pcPic->getNumAllocatedSlice() != 1) |
---|
| 698 | { |
---|
| 699 | pcPic->clearSliceBuffer(); |
---|
| 700 | } |
---|
| 701 | } |
---|
| 702 | else |
---|
| 703 | { |
---|
| 704 | pcPic->allocateNewSlice(); |
---|
| 705 | } |
---|
| 706 | assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1)); |
---|
| 707 | m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); |
---|
| 708 | pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx); |
---|
| 709 | |
---|
| 710 | pcPic->setTLayer(nalu.m_temporalId); |
---|
| 711 | |
---|
| 712 | #if SVC_EXTENSION |
---|
| 713 | pcPic->setLayerId(nalu.m_layerId); |
---|
| 714 | pcSlice->setLayerId(nalu.m_layerId); |
---|
| 715 | #endif |
---|
| 716 | |
---|
| 717 | if (bNextSlice) |
---|
| 718 | { |
---|
| 719 | pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic); |
---|
| 720 | #if !REF_IDX_FRAMEWORK |
---|
| 721 | // Set reference list |
---|
| 722 | pcSlice->setRefPicList( m_cListPic ); |
---|
| 723 | #endif |
---|
| 724 | |
---|
| 725 | #if SVC_EXTENSION |
---|
| 726 | if(m_layerId > 0) |
---|
| 727 | { |
---|
| 728 | #if AVC_BASE |
---|
| 729 | pcSlice->setBaseColPic ( *m_ppcTDecTop[0]->getListPic()->begin() ); |
---|
| 730 | #else |
---|
| 731 | TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 ); |
---|
| 732 | TComList<TComPic*> *cListPic = pcTDecTop->getListPic(); |
---|
| 733 | pcSlice->setBaseColPic ( *cListPic, m_layerId ); |
---|
| 734 | #endif |
---|
| 735 | #if SVC_UPSAMPLING |
---|
| 736 | if ( pcPic->isSpatialEnhLayer()) |
---|
| 737 | { |
---|
| 738 | m_cPrediction.upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec() ); |
---|
| 739 | } |
---|
| 740 | else |
---|
| 741 | { |
---|
| 742 | pcPic->setFullPelBaseRec( pcSlice->getBaseColPic()->getPicYuvRec() ); |
---|
| 743 | } |
---|
| 744 | pcSlice->setFullPelBaseRec ( pcPic->getFullPelBaseRec() ); |
---|
| 745 | #endif |
---|
| 746 | } |
---|
| 747 | #endif |
---|
| 748 | |
---|
| 749 | #if REF_IDX_FRAMEWORK |
---|
| 750 | // Set reference list |
---|
| 751 | pcSlice->setRefPicList( m_cListPic ); |
---|
| 752 | if(m_layerId > 0) |
---|
| 753 | { |
---|
| 754 | setILRPic(pcPic); |
---|
| 755 | pcSlice->addRefPicList ( m_cIlpPic, |
---|
| 756 | 1, |
---|
| 757 | ((pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) && |
---|
| 758 | (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)) ? 0: -1); |
---|
| 759 | } |
---|
| 760 | #endif |
---|
| 761 | |
---|
| 762 | // For generalized B |
---|
| 763 | // note: maybe not existed case (always L0 is copied to L1 if L1 is empty) |
---|
| 764 | if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0) |
---|
| 765 | { |
---|
| 766 | Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0); |
---|
| 767 | pcSlice->setNumRefIdx ( REF_PIC_LIST_1, iNumRefIdx ); |
---|
| 768 | |
---|
| 769 | for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++) |
---|
| 770 | { |
---|
| 771 | pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx); |
---|
| 772 | } |
---|
| 773 | } |
---|
| 774 | if (pcSlice->isInterB()) |
---|
| 775 | { |
---|
| 776 | Bool bLowDelay = true; |
---|
| 777 | Int iCurrPOC = pcSlice->getPOC(); |
---|
| 778 | Int iRefIdx = 0; |
---|
| 779 | |
---|
| 780 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++) |
---|
| 781 | { |
---|
| 782 | if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC ) |
---|
| 783 | { |
---|
| 784 | bLowDelay = false; |
---|
| 785 | } |
---|
| 786 | } |
---|
| 787 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++) |
---|
| 788 | { |
---|
| 789 | if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC ) |
---|
| 790 | { |
---|
| 791 | bLowDelay = false; |
---|
| 792 | } |
---|
| 793 | } |
---|
| 794 | |
---|
| 795 | pcSlice->setCheckLDC(bLowDelay); |
---|
| 796 | } |
---|
| 797 | |
---|
| 798 | //--------------- |
---|
| 799 | pcSlice->setRefPOCList(); |
---|
| 800 | pcSlice->setNoBackPredFlag( false ); |
---|
| 801 | if ( pcSlice->getSliceType() == B_SLICE ) |
---|
| 802 | { |
---|
| 803 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
| 804 | { |
---|
| 805 | pcSlice->setNoBackPredFlag( true ); |
---|
| 806 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
| 807 | { |
---|
| 808 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
| 809 | { |
---|
| 810 | pcSlice->setNoBackPredFlag( false ); |
---|
| 811 | break; |
---|
| 812 | } |
---|
| 813 | } |
---|
| 814 | } |
---|
| 815 | } |
---|
| 816 | } |
---|
| 817 | |
---|
| 818 | pcPic->setCurrSliceIdx(m_uiSliceIdx); |
---|
| 819 | if(pcSlice->getSPS()->getScalingListFlag()) |
---|
| 820 | { |
---|
| 821 | pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList() ); |
---|
| 822 | if(pcSlice->getPPS()->getScalingListPresentFlag()) |
---|
| 823 | { |
---|
| 824 | pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList() ); |
---|
| 825 | } |
---|
| 826 | #if TS_FLAT_QUANTIZATION_MATRIX |
---|
| 827 | pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip()); |
---|
| 828 | #endif |
---|
| 829 | if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag()) |
---|
| 830 | { |
---|
| 831 | pcSlice->setDefaultScalingList(); |
---|
| 832 | } |
---|
| 833 | m_cTrQuant.setScalingListDec(pcSlice->getScalingList()); |
---|
| 834 | m_cTrQuant.setUseScalingList(true); |
---|
| 835 | } |
---|
| 836 | else |
---|
| 837 | { |
---|
| 838 | m_cTrQuant.setFlatScalingList(); |
---|
| 839 | m_cTrQuant.setUseScalingList(false); |
---|
| 840 | } |
---|
| 841 | |
---|
| 842 | // Decode a picture |
---|
| 843 | m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic); |
---|
| 844 | |
---|
| 845 | m_bFirstSliceInPicture = false; |
---|
| 846 | m_uiSliceIdx++; |
---|
| 847 | |
---|
| 848 | return false; |
---|
| 849 | } |
---|
| 850 | |
---|
| 851 | Void TDecTop::xDecodeVPS() |
---|
| 852 | { |
---|
| 853 | TComVPS* vps = new TComVPS(); |
---|
| 854 | |
---|
| 855 | m_cEntropyDecoder.decodeVPS( vps ); |
---|
| 856 | m_parameterSetManagerDecoder.storePrefetchedVPS(vps); |
---|
| 857 | } |
---|
| 858 | |
---|
| 859 | Void TDecTop::xDecodeSPS() |
---|
| 860 | { |
---|
| 861 | TComSPS* sps = new TComSPS(); |
---|
| 862 | #if SVC_EXTENSION |
---|
| 863 | sps->setLayerId(m_layerId); |
---|
| 864 | #endif |
---|
| 865 | m_cEntropyDecoder.decodeSPS( sps ); |
---|
| 866 | m_parameterSetManagerDecoder.storePrefetchedSPS(sps); |
---|
| 867 | #if !REMOVE_ALF |
---|
| 868 | m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 869 | #endif |
---|
| 870 | #if REF_IDX_FRAMEWORK |
---|
| 871 | if(m_numLayer>0) |
---|
| 872 | { |
---|
| 873 | xInitILRP(sps); |
---|
| 874 | } |
---|
| 875 | #endif |
---|
| 876 | } |
---|
| 877 | |
---|
| 878 | Void TDecTop::xDecodePPS() |
---|
| 879 | { |
---|
| 880 | TComPPS* pps = new TComPPS(); |
---|
| 881 | m_cEntropyDecoder.decodePPS( pps, &m_parameterSetManagerDecoder ); |
---|
| 882 | m_parameterSetManagerDecoder.storePrefetchedPPS( pps ); |
---|
| 883 | |
---|
| 884 | #if DEPENDENT_SLICES |
---|
| 885 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
| 886 | if( pps->getDependentSliceEnabledFlag() && (!pps->getEntropySliceEnabledFlag()) ) |
---|
| 887 | #else |
---|
| 888 | if( pps->getDependentSliceEnabledFlag() && (!pps->getCabacIndependentFlag()) ) |
---|
| 889 | #endif |
---|
| 890 | { |
---|
| 891 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
| 892 | int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1; |
---|
| 893 | #else |
---|
| 894 | int NumCtx = (pps->getTilesOrEntropyCodingSyncIdc() == 2)?2:1; |
---|
| 895 | #endif |
---|
| 896 | m_cSliceDecoder.initCtxMem(NumCtx); |
---|
| 897 | for ( UInt st = 0; st < NumCtx; st++ ) |
---|
| 898 | { |
---|
| 899 | TDecSbac* ctx = NULL; |
---|
| 900 | ctx = new TDecSbac; |
---|
| 901 | ctx->init( &m_cBinCABAC ); |
---|
| 902 | m_cSliceDecoder.setCtxMem( ctx, st ); |
---|
| 903 | } |
---|
| 904 | } |
---|
| 905 | #endif |
---|
| 906 | } |
---|
| 907 | |
---|
| 908 | #if !REMOVE_APS |
---|
| 909 | Void TDecTop::xDecodeAPS() |
---|
| 910 | { |
---|
| 911 | TComAPS *aps = new TComAPS(); |
---|
| 912 | allocAPS (aps); |
---|
| 913 | decodeAPS(aps); |
---|
| 914 | m_parameterSetManagerDecoder.storePrefetchedAPS(aps); |
---|
| 915 | } |
---|
| 916 | #endif |
---|
| 917 | |
---|
| 918 | Void TDecTop::xDecodeSEI( TComInputBitstream* bs ) |
---|
| 919 | { |
---|
| 920 | #if RECOVERY_POINT_SEI || BUFFERING_PERIOD_AND_TIMING_SEI |
---|
| 921 | if ( m_SEIs == NULL ) |
---|
| 922 | #endif |
---|
| 923 | m_SEIs = new SEImessages; |
---|
| 924 | #if BUFFERING_PERIOD_AND_TIMING_SEI |
---|
| 925 | m_SEIs->m_pSPS = m_parameterSetManagerDecoder.getSPS(0); |
---|
| 926 | #endif |
---|
| 927 | m_seiReader.parseSEImessage( bs, *m_SEIs ); |
---|
| 928 | } |
---|
| 929 | |
---|
| 930 | #if SVC_EXTENSION |
---|
| 931 | Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC) |
---|
| 932 | #else |
---|
| 933 | Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay) |
---|
| 934 | #endif |
---|
| 935 | { |
---|
| 936 | // Initialize entropy decoder |
---|
| 937 | m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder); |
---|
| 938 | m_cEntropyDecoder.setBitstream (nalu.m_Bitstream); |
---|
| 939 | |
---|
| 940 | switch (nalu.m_nalUnitType) |
---|
| 941 | { |
---|
| 942 | case NAL_UNIT_VPS: |
---|
| 943 | xDecodeVPS(); |
---|
| 944 | return false; |
---|
| 945 | |
---|
| 946 | case NAL_UNIT_SPS: |
---|
| 947 | xDecodeSPS(); |
---|
| 948 | #if AVC_BASE |
---|
| 949 | { |
---|
| 950 | TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin()); |
---|
| 951 | if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL ) |
---|
| 952 | { |
---|
| 953 | #if SVC_UPSAMPLING |
---|
| 954 | pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL, true); |
---|
| 955 | #else |
---|
| 956 | pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true); |
---|
| 957 | #endif |
---|
| 958 | } |
---|
| 959 | } |
---|
| 960 | #endif |
---|
| 961 | return false; |
---|
| 962 | |
---|
| 963 | case NAL_UNIT_PPS: |
---|
| 964 | xDecodePPS(); |
---|
| 965 | return false; |
---|
| 966 | #if !REMOVE_APS |
---|
| 967 | case NAL_UNIT_APS: |
---|
| 968 | xDecodeAPS(); |
---|
| 969 | return false; |
---|
| 970 | #endif |
---|
| 971 | |
---|
| 972 | case NAL_UNIT_SEI: |
---|
| 973 | xDecodeSEI( nalu.m_Bitstream ); |
---|
| 974 | return false; |
---|
| 975 | |
---|
| 976 | #if NAL_UNIT_TYPES_J1003_D7 |
---|
| 977 | case NAL_UNIT_CODED_SLICE_TRAIL_R: |
---|
| 978 | case NAL_UNIT_CODED_SLICE_TRAIL_N: |
---|
| 979 | case NAL_UNIT_CODED_SLICE_TLA: |
---|
| 980 | case NAL_UNIT_CODED_SLICE_TSA_N: |
---|
| 981 | case NAL_UNIT_CODED_SLICE_STSA_R: |
---|
| 982 | case NAL_UNIT_CODED_SLICE_STSA_N: |
---|
| 983 | case NAL_UNIT_CODED_SLICE_BLA: |
---|
| 984 | case NAL_UNIT_CODED_SLICE_BLANT: |
---|
| 985 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: |
---|
| 986 | case NAL_UNIT_CODED_SLICE_IDR: |
---|
| 987 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: |
---|
| 988 | case NAL_UNIT_CODED_SLICE_CRA: |
---|
| 989 | case NAL_UNIT_CODED_SLICE_DLP: |
---|
| 990 | case NAL_UNIT_CODED_SLICE_TFD: |
---|
| 991 | #else |
---|
| 992 | case NAL_UNIT_CODED_SLICE: |
---|
| 993 | case NAL_UNIT_CODED_SLICE_TFD: |
---|
| 994 | case NAL_UNIT_CODED_SLICE_TLA: |
---|
| 995 | case NAL_UNIT_CODED_SLICE_CRA: |
---|
| 996 | case NAL_UNIT_CODED_SLICE_CRANT: |
---|
| 997 | case NAL_UNIT_CODED_SLICE_BLA: |
---|
| 998 | case NAL_UNIT_CODED_SLICE_BLANT: |
---|
| 999 | case NAL_UNIT_CODED_SLICE_IDR: |
---|
| 1000 | #endif |
---|
| 1001 | #if SVC_EXTENSION |
---|
| 1002 | return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC); |
---|
| 1003 | #else |
---|
| 1004 | return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay); |
---|
| 1005 | #endif |
---|
| 1006 | break; |
---|
| 1007 | default: |
---|
| 1008 | assert (1); |
---|
| 1009 | } |
---|
| 1010 | |
---|
| 1011 | return false; |
---|
| 1012 | } |
---|
| 1013 | |
---|
| 1014 | /** Function for checking if picture should be skipped because of association with a previous BLA picture |
---|
| 1015 | * \param iPOCLastDisplay POC of last picture displayed |
---|
| 1016 | * \returns true if the picture should be skipped |
---|
| 1017 | * This function skips all TFD pictures that follow a BLA picture |
---|
| 1018 | * in decoding order and precede it in output order. |
---|
| 1019 | */ |
---|
| 1020 | Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay) |
---|
| 1021 | { |
---|
| 1022 | if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TFD) |
---|
| 1023 | { |
---|
| 1024 | iPOCLastDisplay++; |
---|
| 1025 | return true; |
---|
| 1026 | } |
---|
| 1027 | return false; |
---|
| 1028 | } |
---|
| 1029 | |
---|
| 1030 | /** Function for checking if picture should be skipped because of random access |
---|
| 1031 | * \param iSkipFrame skip frame counter |
---|
| 1032 | * \param iPOCLastDisplay POC of last picture displayed |
---|
| 1033 | * \returns true if the picture shold be skipped in the random access. |
---|
| 1034 | * This function checks the skipping of pictures in the case of -s option random access. |
---|
| 1035 | * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped. |
---|
| 1036 | * It also checks the type of Nal unit type at the random access point. |
---|
| 1037 | * 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. |
---|
| 1038 | * If the random access point is IDR all pictures after the random access point are decoded. |
---|
| 1039 | * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC |
---|
| 1040 | * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random |
---|
| 1041 | * access point there is no guarantee that the decoder will not crash. |
---|
| 1042 | */ |
---|
| 1043 | Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame, Int& iPOCLastDisplay) |
---|
| 1044 | { |
---|
| 1045 | if (iSkipFrame) |
---|
| 1046 | { |
---|
| 1047 | iSkipFrame--; // decrement the counter |
---|
| 1048 | return true; |
---|
| 1049 | } |
---|
| 1050 | else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet. |
---|
| 1051 | { |
---|
| 1052 | if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA |
---|
| 1053 | #if !NAL_UNIT_TYPES_J1003_D7 |
---|
| 1054 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRANT |
---|
| 1055 | #endif |
---|
| 1056 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
| 1057 | #if SUPPORT_FOR_RAP_N_LP |
---|
| 1058 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
| 1059 | #endif |
---|
| 1060 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT ) |
---|
| 1061 | { |
---|
| 1062 | // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT. |
---|
| 1063 | m_pocRandomAccess = m_apcSlicePilot->getPOC(); |
---|
| 1064 | } |
---|
| 1065 | #if SUPPORT_FOR_RAP_N_LP |
---|
| 1066 | else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
---|
| 1067 | #else |
---|
| 1068 | else if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR) |
---|
| 1069 | #endif |
---|
| 1070 | { |
---|
| 1071 | m_pocRandomAccess = 0; // no need to skip the reordered pictures in IDR, they are decodable. |
---|
| 1072 | } |
---|
| 1073 | else |
---|
| 1074 | { |
---|
| 1075 | static bool warningMessage = false; |
---|
| 1076 | if(!warningMessage) |
---|
| 1077 | { |
---|
| 1078 | printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture"); |
---|
| 1079 | warningMessage = true; |
---|
| 1080 | } |
---|
| 1081 | return true; |
---|
| 1082 | } |
---|
| 1083 | } |
---|
| 1084 | // skip the reordered pictures, if necessary |
---|
| 1085 | else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TFD) |
---|
| 1086 | { |
---|
| 1087 | iPOCLastDisplay++; |
---|
| 1088 | return true; |
---|
| 1089 | } |
---|
| 1090 | // if we reach here, then the picture is not skipped. |
---|
| 1091 | return false; |
---|
| 1092 | } |
---|
| 1093 | |
---|
| 1094 | #if !REMOVE_APS |
---|
| 1095 | Void TDecTop::allocAPS (TComAPS* pAPS) |
---|
| 1096 | { |
---|
| 1097 | // we don't know the SPS before it has been activated. These fields could exist |
---|
| 1098 | // depending on the corresponding flags in the APS, but SAO/ALF allocation functions will |
---|
| 1099 | // have to be moved for that |
---|
| 1100 | pAPS->createSaoParam(); |
---|
| 1101 | m_cSAO.allocSaoParam(pAPS->getSaoParam()); |
---|
| 1102 | #if !REMOVE_ALF |
---|
| 1103 | pAPS->createAlfParam(); |
---|
| 1104 | #endif |
---|
| 1105 | } |
---|
| 1106 | #endif |
---|
| 1107 | |
---|
| 1108 | //! \} |
---|