| 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 | |
|---|
| 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 | #endif |
|---|
| 46 | |
|---|
| 47 | //! \ingroup TLibDecoder |
|---|
| 48 | //! \{ |
|---|
| 49 | |
|---|
| 50 | TDecTop::TDecTop() |
|---|
| 51 | { |
|---|
| 52 | m_pcPic = 0; |
|---|
| 53 | m_iMaxRefPicNum = 0; |
|---|
| 54 | #if ENC_DEC_TRACE |
|---|
| 55 | g_hTrace = fopen( "TraceDec.txt", "wb" ); |
|---|
| 56 | g_bJustDoIt = g_bEncDecTraceDisable; |
|---|
| 57 | g_nSymbolCounter = 0; |
|---|
| 58 | #endif |
|---|
| 59 | m_pocCRA = 0; |
|---|
| 60 | m_prevRAPisBLA = false; |
|---|
| 61 | m_pocRandomAccess = MAX_INT; |
|---|
| 62 | #if !SVC_EXTENSION |
|---|
| 63 | m_prevPOC = MAX_INT; |
|---|
| 64 | #endif |
|---|
| 65 | m_bFirstSliceInPicture = true; |
|---|
| 66 | #if !SVC_EXTENSION |
|---|
| 67 | m_bFirstSliceInSequence = true; |
|---|
| 68 | #endif |
|---|
| 69 | #if SVC_EXTENSION |
|---|
| 70 | m_layerId = 0; |
|---|
| 71 | #if AVC_BASE |
|---|
| 72 | m_pBLReconFile = NULL; |
|---|
| 73 | #endif |
|---|
| 74 | memset(m_cIlpPic, 0, sizeof(m_cIlpPic)); |
|---|
| 75 | #endif |
|---|
| 76 | #if AVC_SYNTAX || SYNTAX_OUTPUT |
|---|
| 77 | m_pBLSyntaxFile = NULL; |
|---|
| 78 | #endif |
|---|
| 79 | #if HM12_RANDOM_ACCESS |
|---|
| 80 | m_prevSliceSkipped = false; |
|---|
| 81 | m_skippedPOC = 0; |
|---|
| 82 | #endif |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | TDecTop::~TDecTop() |
|---|
| 86 | { |
|---|
| 87 | #if ENC_DEC_TRACE |
|---|
| 88 | fclose( g_hTrace ); |
|---|
| 89 | #endif |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | Void TDecTop::create() |
|---|
| 93 | { |
|---|
| 94 | #if SVC_EXTENSION |
|---|
| 95 | m_cGopDecoder.create( m_layerId ); |
|---|
| 96 | #else |
|---|
| 97 | m_cGopDecoder.create(); |
|---|
| 98 | #endif |
|---|
| 99 | m_apcSlicePilot = new TComSlice; |
|---|
| 100 | m_uiSliceIdx = 0; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | Void TDecTop::destroy() |
|---|
| 104 | { |
|---|
| 105 | m_cGopDecoder.destroy(); |
|---|
| 106 | |
|---|
| 107 | delete m_apcSlicePilot; |
|---|
| 108 | m_apcSlicePilot = NULL; |
|---|
| 109 | |
|---|
| 110 | m_cSliceDecoder.destroy(); |
|---|
| 111 | #if SVC_EXTENSION |
|---|
| 112 | for(Int i=0; i<MAX_NUM_REF; i++) |
|---|
| 113 | { |
|---|
| 114 | if(m_cIlpPic[i]) |
|---|
| 115 | { |
|---|
| 116 | m_cIlpPic[i]->destroy(); |
|---|
| 117 | delete m_cIlpPic[i]; |
|---|
| 118 | m_cIlpPic[i] = NULL; |
|---|
| 119 | } |
|---|
| 120 | } |
|---|
| 121 | #endif |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | Void TDecTop::init() |
|---|
| 125 | { |
|---|
| 126 | #if !SVC_EXTENSION |
|---|
| 127 | // initialize ROM |
|---|
| 128 | initROM(); |
|---|
| 129 | #endif |
|---|
| 130 | #if SVC_EXTENSION |
|---|
| 131 | m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO); |
|---|
| 132 | m_cSliceDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cCuDecoder ); |
|---|
| 133 | #else |
|---|
| 134 | m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO); |
|---|
| 135 | m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder ); |
|---|
| 136 | #endif |
|---|
| 137 | m_cEntropyDecoder.init(&m_cPrediction); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | #if SVC_EXTENSION |
|---|
| 141 | #if !REPN_FORMAT_IN_VPS |
|---|
| 142 | Void TDecTop::xInitILRP(TComSPS *pcSPS) |
|---|
| 143 | #else |
|---|
| 144 | Void TDecTop::xInitILRP(TComSlice *slice) |
|---|
| 145 | #endif |
|---|
| 146 | { |
|---|
| 147 | #if REPN_FORMAT_IN_VPS |
|---|
| 148 | TComSPS* pcSPS = slice->getSPS(); |
|---|
| 149 | Int bitDepthY = slice->getBitDepthY(); |
|---|
| 150 | Int bitDepthC = slice->getBitDepthC(); |
|---|
| 151 | Int picWidth = slice->getPicWidthInLumaSamples(); |
|---|
| 152 | Int picHeight = slice->getPicHeightInLumaSamples(); |
|---|
| 153 | #endif |
|---|
| 154 | if(m_layerId>0) |
|---|
| 155 | { |
|---|
| 156 | #if REPN_FORMAT_IN_VPS |
|---|
| 157 | g_bitDepthY = bitDepthY; |
|---|
| 158 | g_bitDepthC = bitDepthC; |
|---|
| 159 | #else |
|---|
| 160 | g_bitDepthY = pcSPS->getBitDepthY(); |
|---|
| 161 | g_bitDepthC = pcSPS->getBitDepthC(); |
|---|
| 162 | #endif |
|---|
| 163 | g_uiMaxCUWidth = pcSPS->getMaxCUWidth(); |
|---|
| 164 | g_uiMaxCUHeight = pcSPS->getMaxCUHeight(); |
|---|
| 165 | g_uiMaxCUDepth = pcSPS->getMaxCUDepth(); |
|---|
| 166 | g_uiAddCUDepth = max (0, pcSPS->getLog2MinCodingBlockSize() - (Int)pcSPS->getQuadtreeTULog2MinSize() ); |
|---|
| 167 | |
|---|
| 168 | Int numReorderPics[MAX_TLAYER]; |
|---|
| 169 | Window &conformanceWindow = pcSPS->getConformanceWindow(); |
|---|
| 170 | Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window(); |
|---|
| 171 | |
|---|
| 172 | for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) |
|---|
| 173 | { |
|---|
| 174 | numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer); |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | if (m_cIlpPic[0] == NULL) |
|---|
| 178 | { |
|---|
| 179 | for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++) // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]] |
|---|
| 180 | { |
|---|
| 181 | |
|---|
| 182 | m_cIlpPic[j] = new TComPic; |
|---|
| 183 | #if REPN_FORMAT_IN_VPS |
|---|
| 184 | #if SVC_UPSAMPLING |
|---|
| 185 | m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true); |
|---|
| 186 | #else |
|---|
| 187 | m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true); |
|---|
| 188 | #endif |
|---|
| 189 | #else |
|---|
| 190 | #if SVC_UPSAMPLING |
|---|
| 191 | m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true); |
|---|
| 192 | #else |
|---|
| 193 | m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true); |
|---|
| 194 | #endif |
|---|
| 195 | #endif |
|---|
| 196 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++) |
|---|
| 197 | { |
|---|
| 198 | m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i); |
|---|
| 199 | } |
|---|
| 200 | } |
|---|
| 201 | } |
|---|
| 202 | } |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | Void TDecTop::setILRPic(TComPic *pcPic) |
|---|
| 208 | { |
|---|
| 209 | for( Int i = 0; i < pcPic->getSlice(0)->getActiveNumILRRefIdx(); i++ ) |
|---|
| 210 | { |
|---|
| 211 | Int refLayerIdc = pcPic->getSlice(0)->getInterLayerPredLayerIdc(i); |
|---|
| 212 | |
|---|
| 213 | if(m_cIlpPic[refLayerIdc]) |
|---|
| 214 | { |
|---|
| 215 | m_cIlpPic[refLayerIdc]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(refLayerIdc), m_cIlpPic[refLayerIdc]->getPicYuvRec()); |
|---|
| 216 | m_cIlpPic[refLayerIdc]->getSlice(0)->setPOC(pcPic->getPOC()); |
|---|
| 217 | m_cIlpPic[refLayerIdc]->setLayerId(pcPic->getSlice(0)->getBaseColPic(refLayerIdc)->getLayerId()); //set reference layerId |
|---|
| 218 | m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false); |
|---|
| 219 | m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder(); |
|---|
| 220 | for (Int j=0; j<m_cIlpPic[refLayerIdc]->getPicSym()->getNumberOfCUsInFrame(); j++) // set reference CU layerId |
|---|
| 221 | { |
|---|
| 222 | m_cIlpPic[refLayerIdc]->getPicSym()->getCU(j)->setLayerId(m_cIlpPic[refLayerIdc]->getLayerId()); |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | } |
|---|
| 226 | } |
|---|
| 227 | #endif |
|---|
| 228 | |
|---|
| 229 | Void TDecTop::deletePicBuffer ( ) |
|---|
| 230 | { |
|---|
| 231 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
|---|
| 232 | Int iSize = Int( m_cListPic.size() ); |
|---|
| 233 | |
|---|
| 234 | for (Int i = 0; i < iSize; i++ ) |
|---|
| 235 | { |
|---|
| 236 | TComPic* pcPic = *(iterPic++); |
|---|
| 237 | #if SVC_EXTENSION |
|---|
| 238 | if( pcPic ) |
|---|
| 239 | { |
|---|
| 240 | pcPic->destroy(); |
|---|
| 241 | |
|---|
| 242 | delete pcPic; |
|---|
| 243 | pcPic = NULL; |
|---|
| 244 | } |
|---|
| 245 | #else |
|---|
| 246 | pcPic->destroy(); |
|---|
| 247 | |
|---|
| 248 | delete pcPic; |
|---|
| 249 | pcPic = NULL; |
|---|
| 250 | #endif |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | m_cSAO.destroy(); |
|---|
| 254 | |
|---|
| 255 | m_cLoopFilter. destroy(); |
|---|
| 256 | |
|---|
| 257 | #if !SVC_EXTENSION |
|---|
| 258 | // destroy ROM |
|---|
| 259 | destroyROM(); |
|---|
| 260 | #endif |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic ) |
|---|
| 264 | { |
|---|
| 265 | Int numReorderPics[MAX_TLAYER]; |
|---|
| 266 | Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow(); |
|---|
| 267 | Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window(); |
|---|
| 268 | |
|---|
| 269 | for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) |
|---|
| 270 | { |
|---|
| 271 | numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer); |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer()); // m_uiMaxDecPicBuffering has the space for the picture currently being decoded |
|---|
| 275 | |
|---|
| 276 | #if SVC_EXTENSION |
|---|
| 277 | m_iMaxRefPicNum += 1; // it should be updated if more than 1 resampling picture is used |
|---|
| 278 | #endif |
|---|
| 279 | |
|---|
| 280 | if (m_cListPic.size() < (UInt)m_iMaxRefPicNum) |
|---|
| 281 | { |
|---|
| 282 | rpcPic = new TComPic(); |
|---|
| 283 | |
|---|
| 284 | #if SVC_EXTENSION //Temporal solution, should be modified |
|---|
| 285 | if(m_layerId > 0) |
|---|
| 286 | { |
|---|
| 287 | for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ ) |
|---|
| 288 | { |
|---|
| 289 | const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(i); |
|---|
| 290 | Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 ); |
|---|
| 291 | |
|---|
| 292 | #if VPS_EXTN_DIRECT_REF_LAYERS |
|---|
| 293 | TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i ); |
|---|
| 294 | #else |
|---|
| 295 | TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 ); |
|---|
| 296 | #endif |
|---|
| 297 | //TComPic* pcPic = *(pcTDecTopBase->getListPic()->begin()); |
|---|
| 298 | TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); |
|---|
| 299 | #if REPN_FORMAT_IN_VPS |
|---|
| 300 | if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets ) |
|---|
| 301 | #else |
|---|
| 302 | if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() || !zeroOffsets ) |
|---|
| 303 | #endif |
|---|
| 304 | { |
|---|
| 305 | rpcPic->setSpatialEnhLayerFlag( i, true ); |
|---|
| 306 | |
|---|
| 307 | //only for scalable extension |
|---|
| 308 | #if SCALABILITY_MASK_E0104 |
|---|
| 309 | assert( pcSlice->getVPS()->getScalabilityMask(2) == true ); |
|---|
| 310 | #else |
|---|
| 311 | assert( pcSlice->getVPS()->getScalabilityMask(1) == true ); |
|---|
| 312 | #endif |
|---|
| 313 | } |
|---|
| 314 | #if MAX_ONE_RESAMPLING_DIRECT_LAYERS |
|---|
| 315 | #if SCALABILITY_MASK_E0104 |
|---|
| 316 | if(pcSlice->getVPS()->getScalabilityMask(2)) |
|---|
| 317 | #else |
|---|
| 318 | if(pcSlice->getVPS()->getScalabilityMask(1)) |
|---|
| 319 | #endif |
|---|
| 320 | { |
|---|
| 321 | pcSlice->setPic(rpcPic); |
|---|
| 322 | } |
|---|
| 323 | #endif |
|---|
| 324 | } |
|---|
| 325 | } |
|---|
| 326 | #endif |
|---|
| 327 | |
|---|
| 328 | #if REPN_FORMAT_IN_VPS |
|---|
| 329 | #if SVC_UPSAMPLING |
|---|
| 330 | rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
|---|
| 331 | conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true); |
|---|
| 332 | #else |
|---|
| 333 | rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
|---|
| 334 | conformanceWindow, defaultDisplayWindow, numReorderPics, true); |
|---|
| 335 | #endif |
|---|
| 336 | #else |
|---|
| 337 | #if SVC_UPSAMPLING |
|---|
| 338 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
|---|
| 339 | conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true); |
|---|
| 340 | #else |
|---|
| 341 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
|---|
| 342 | conformanceWindow, defaultDisplayWindow, numReorderPics, true); |
|---|
| 343 | #endif |
|---|
| 344 | #endif |
|---|
| 345 | |
|---|
| 346 | rpcPic->getPicSym()->allocSaoParam(&m_cSAO); |
|---|
| 347 | m_cListPic.pushBack( rpcPic ); |
|---|
| 348 | |
|---|
| 349 | return; |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | Bool bBufferIsAvailable = false; |
|---|
| 353 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
|---|
| 354 | while (iterPic != m_cListPic.end()) |
|---|
| 355 | { |
|---|
| 356 | rpcPic = *(iterPic++); |
|---|
| 357 | if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false) |
|---|
| 358 | { |
|---|
| 359 | rpcPic->setOutputMark(false); |
|---|
| 360 | bBufferIsAvailable = true; |
|---|
| 361 | break; |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | if ( rpcPic->getSlice( 0 )->isReferenced() == false && rpcPic->getOutputMark() == false) |
|---|
| 365 | { |
|---|
| 366 | #if !SVC_EXTENSION |
|---|
| 367 | rpcPic->setOutputMark(false); |
|---|
| 368 | #endif |
|---|
| 369 | rpcPic->setReconMark( false ); |
|---|
| 370 | rpcPic->getPicYuvRec()->setBorderExtension( false ); |
|---|
| 371 | bBufferIsAvailable = true; |
|---|
| 372 | break; |
|---|
| 373 | } |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | if ( !bBufferIsAvailable ) |
|---|
| 377 | { |
|---|
| 378 | //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer. |
|---|
| 379 | m_iMaxRefPicNum++; |
|---|
| 380 | rpcPic = new TComPic(); |
|---|
| 381 | m_cListPic.pushBack( rpcPic ); |
|---|
| 382 | } |
|---|
| 383 | rpcPic->destroy(); |
|---|
| 384 | |
|---|
| 385 | #if REPN_FORMAT_IN_VPS |
|---|
| 386 | #if SVC_UPSAMPLING |
|---|
| 387 | rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
|---|
| 388 | conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true); |
|---|
| 389 | |
|---|
| 390 | #else |
|---|
| 391 | rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
|---|
| 392 | conformanceWindow, defaultDisplayWindow, numReorderPics, true); |
|---|
| 393 | #endif |
|---|
| 394 | #else |
|---|
| 395 | #if SVC_UPSAMPLING |
|---|
| 396 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
|---|
| 397 | conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true); |
|---|
| 398 | |
|---|
| 399 | #else |
|---|
| 400 | rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
|---|
| 401 | conformanceWindow, defaultDisplayWindow, numReorderPics, true); |
|---|
| 402 | #endif |
|---|
| 403 | #endif |
|---|
| 404 | rpcPic->getPicSym()->allocSaoParam(&m_cSAO); |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic) |
|---|
| 408 | { |
|---|
| 409 | if (!m_pcPic) |
|---|
| 410 | { |
|---|
| 411 | /* nothing to deblock */ |
|---|
| 412 | return; |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | TComPic*& pcPic = m_pcPic; |
|---|
| 416 | |
|---|
| 417 | // Execute Deblock + Cleanup |
|---|
| 418 | |
|---|
| 419 | m_cGopDecoder.filterPicture(pcPic); |
|---|
| 420 | |
|---|
| 421 | #if SYNTAX_OUTPUT |
|---|
| 422 | pcPic->wrireBLSyntax( getBLSyntaxFile(), SYNTAX_BYTES ); |
|---|
| 423 | #endif |
|---|
| 424 | TComSlice::sortPicList( m_cListPic ); // sorting for application output |
|---|
| 425 | poc = pcPic->getSlice(m_uiSliceIdx-1)->getPOC(); |
|---|
| 426 | rpcListPic = &m_cListPic; |
|---|
| 427 | m_cCuDecoder.destroy(); |
|---|
| 428 | m_bFirstSliceInPicture = true; |
|---|
| 429 | |
|---|
| 430 | return; |
|---|
| 431 | } |
|---|
| 432 | |
|---|
| 433 | #if EARLY_REF_PIC_MARKING |
|---|
| 434 | Void TDecTop::earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdSet) |
|---|
| 435 | { |
|---|
| 436 | UInt currTid = m_pcPic->getTLayer(); |
|---|
| 437 | UInt highestTid = (maxTemporalLayer >= 0) ? maxTemporalLayer : (m_pcPic->getSlice(0)->getSPS()->getMaxTLayers() - 1); |
|---|
| 438 | UInt latestDecLayerId = m_layerId; |
|---|
| 439 | UInt numTargetDecLayers = 0; |
|---|
| 440 | Int targetDecLayerIdList[MAX_LAYERS]; |
|---|
| 441 | UInt latestDecIdx = 0; |
|---|
| 442 | TComSlice* pcSlice = m_pcPic->getSlice(0); |
|---|
| 443 | |
|---|
| 444 | if ( currTid != highestTid ) // Marking process is only applicaple for highest decoded TLayer |
|---|
| 445 | { |
|---|
| 446 | return; |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | // currPic must be marked as "used for reference" and must be a sub-layer non-reference picture |
|---|
| 450 | if ( !((pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N || |
|---|
| 451 | pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N || |
|---|
| 452 | pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N || |
|---|
| 453 | pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N || |
|---|
| 454 | pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || |
|---|
| 455 | pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N10 || |
|---|
| 456 | pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N12 || |
|---|
| 457 | pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N14) && pcSlice->isReferenced())) |
|---|
| 458 | { |
|---|
| 459 | return; |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | if ( targetDecLayerIdSet.size() == 0 ) // Cannot mark if we don't know the number of scalable layers |
|---|
| 463 | { |
|---|
| 464 | return; |
|---|
| 465 | } |
|---|
| 466 | |
|---|
| 467 | for (std::vector<Int>::iterator it = targetDecLayerIdSet.begin(); it != targetDecLayerIdSet.end(); it++) |
|---|
| 468 | { |
|---|
| 469 | if ( latestDecLayerId == (*it) ) |
|---|
| 470 | { |
|---|
| 471 | latestDecIdx = numTargetDecLayers; |
|---|
| 472 | } |
|---|
| 473 | targetDecLayerIdList[numTargetDecLayers++] = (*it); |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | Int remainingInterLayerReferencesFlag = 0; |
|---|
| 477 | if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId) - 1 ) |
|---|
| 478 | { |
|---|
| 479 | for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ ) |
|---|
| 480 | { |
|---|
| 481 | for ( Int k = 0; k < m_ppcTDecTop[targetDecLayerIdList[j]]->getNumDirectRefLayers(); k++ ) |
|---|
| 482 | { |
|---|
| 483 | if ( latestDecIdx == m_ppcTDecTop[targetDecLayerIdList[j]]->getRefLayerId(k) ) |
|---|
| 484 | { |
|---|
| 485 | remainingInterLayerReferencesFlag = 1; |
|---|
| 486 | } |
|---|
| 487 | } |
|---|
| 488 | } |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | if ( remainingInterLayerReferencesFlag == 0 ) |
|---|
| 492 | { |
|---|
| 493 | pcSlice->setReferenced(false); |
|---|
| 494 | } |
|---|
| 495 | } |
|---|
| 496 | #endif |
|---|
| 497 | |
|---|
| 498 | Void TDecTop::xCreateLostPicture(Int iLostPoc) |
|---|
| 499 | { |
|---|
| 500 | printf("\ninserting lost poc : %d\n",iLostPoc); |
|---|
| 501 | TComSlice cFillSlice; |
|---|
| 502 | #if SVC_EXTENSION |
|---|
| 503 | cFillSlice.setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() ); |
|---|
| 504 | cFillSlice.setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() ); |
|---|
| 505 | cFillSlice.setVPS( m_parameterSetManagerDecoder[m_layerId].getFirstVPS() ); |
|---|
| 506 | cFillSlice.initSlice( m_layerId ); |
|---|
| 507 | #else |
|---|
| 508 | cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() ); |
|---|
| 509 | cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() ); |
|---|
| 510 | cFillSlice.initSlice(); |
|---|
| 511 | #endif |
|---|
| 512 | TComPic *cFillPic; |
|---|
| 513 | xGetNewPicBuffer(&cFillSlice,cFillPic); |
|---|
| 514 | #if SVC_EXTENSION |
|---|
| 515 | cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() ); |
|---|
| 516 | cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() ); |
|---|
| 517 | cFillPic->getSlice(0)->setVPS( m_parameterSetManagerDecoder[m_layerId].getFirstVPS() ); |
|---|
| 518 | cFillPic->getSlice(0)->initSlice( m_layerId ); |
|---|
| 519 | #else |
|---|
| 520 | cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() ); |
|---|
| 521 | cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() ); |
|---|
| 522 | cFillPic->getSlice(0)->initSlice(); |
|---|
| 523 | #endif |
|---|
| 524 | |
|---|
| 525 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
|---|
| 526 | Int closestPoc = 1000000; |
|---|
| 527 | while ( iterPic != m_cListPic.end()) |
|---|
| 528 | { |
|---|
| 529 | TComPic * rpcPic = *(iterPic++); |
|---|
| 530 | 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()) |
|---|
| 531 | { |
|---|
| 532 | closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc); |
|---|
| 533 | } |
|---|
| 534 | } |
|---|
| 535 | iterPic = m_cListPic.begin(); |
|---|
| 536 | while ( iterPic != m_cListPic.end()) |
|---|
| 537 | { |
|---|
| 538 | TComPic *rpcPic = *(iterPic++); |
|---|
| 539 | if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC()) |
|---|
| 540 | { |
|---|
| 541 | printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC()); |
|---|
| 542 | rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec()); |
|---|
| 543 | break; |
|---|
| 544 | } |
|---|
| 545 | } |
|---|
| 546 | cFillPic->setCurrSliceIdx(0); |
|---|
| 547 | for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) |
|---|
| 548 | { |
|---|
| 549 | cFillPic->getCU(i)->initCU(cFillPic,i); |
|---|
| 550 | } |
|---|
| 551 | cFillPic->getSlice(0)->setReferenced(true); |
|---|
| 552 | cFillPic->getSlice(0)->setPOC(iLostPoc); |
|---|
| 553 | cFillPic->setReconMark(true); |
|---|
| 554 | cFillPic->setOutputMark(true); |
|---|
| 555 | if(m_pocRandomAccess == MAX_INT) |
|---|
| 556 | { |
|---|
| 557 | m_pocRandomAccess = iLostPoc; |
|---|
| 558 | } |
|---|
| 559 | } |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | Void TDecTop::xActivateParameterSets() |
|---|
| 563 | { |
|---|
| 564 | #if SVC_EXTENSION |
|---|
| 565 | m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS(); |
|---|
| 566 | |
|---|
| 567 | TComPPS *pps = m_parameterSetManagerDecoder[m_layerId].getPPS(m_apcSlicePilot->getPPSId()); |
|---|
| 568 | assert (pps != 0); |
|---|
| 569 | |
|---|
| 570 | TComSPS *sps = m_parameterSetManagerDecoder[m_layerId].getSPS(pps->getSPSId()); |
|---|
| 571 | assert (sps != 0); |
|---|
| 572 | |
|---|
| 573 | if( false == m_parameterSetManagerDecoder[m_layerId].activatePPS(m_apcSlicePilot->getPPSId(), m_apcSlicePilot->isIRAP()) ) |
|---|
| 574 | #else |
|---|
| 575 | m_parameterSetManagerDecoder.applyPrefetchedPS(); |
|---|
| 576 | |
|---|
| 577 | TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId()); |
|---|
| 578 | assert (pps != 0); |
|---|
| 579 | |
|---|
| 580 | TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId()); |
|---|
| 581 | assert (sps != 0); |
|---|
| 582 | |
|---|
| 583 | if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP())) |
|---|
| 584 | #endif |
|---|
| 585 | { |
|---|
| 586 | printf ("Parameter set activation failed!"); |
|---|
| 587 | assert (0); |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | if( pps->getDependentSliceSegmentsEnabledFlag() ) |
|---|
| 591 | { |
|---|
| 592 | Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1; |
|---|
| 593 | |
|---|
| 594 | if (m_cSliceDecoder.getCtxMemSize() != NumCtx) |
|---|
| 595 | { |
|---|
| 596 | m_cSliceDecoder.initCtxMem(NumCtx); |
|---|
| 597 | for ( UInt st = 0; st < NumCtx; st++ ) |
|---|
| 598 | { |
|---|
| 599 | TDecSbac* ctx = NULL; |
|---|
| 600 | ctx = new TDecSbac; |
|---|
| 601 | ctx->init( &m_cBinCABAC ); |
|---|
| 602 | m_cSliceDecoder.setCtxMem( ctx, st ); |
|---|
| 603 | } |
|---|
| 604 | } |
|---|
| 605 | } |
|---|
| 606 | |
|---|
| 607 | m_apcSlicePilot->setPPS(pps); |
|---|
| 608 | m_apcSlicePilot->setSPS(sps); |
|---|
| 609 | pps->setSPS(sps); |
|---|
| 610 | #if REPN_FORMAT_IN_VPS |
|---|
| 611 | pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1); |
|---|
| 612 | #else |
|---|
| 613 | pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1); |
|---|
| 614 | #endif |
|---|
| 615 | pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) ); |
|---|
| 616 | |
|---|
| 617 | #if REPN_FORMAT_IN_VPS |
|---|
| 618 | g_bitDepthY = m_apcSlicePilot->getBitDepthY(); |
|---|
| 619 | g_bitDepthC = m_apcSlicePilot->getBitDepthC(); |
|---|
| 620 | #else |
|---|
| 621 | g_bitDepthY = sps->getBitDepthY(); |
|---|
| 622 | g_bitDepthC = sps->getBitDepthC(); |
|---|
| 623 | #endif |
|---|
| 624 | g_uiMaxCUWidth = sps->getMaxCUWidth(); |
|---|
| 625 | g_uiMaxCUHeight = sps->getMaxCUHeight(); |
|---|
| 626 | g_uiMaxCUDepth = sps->getMaxCUDepth(); |
|---|
| 627 | g_uiAddCUDepth = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() ); |
|---|
| 628 | |
|---|
| 629 | for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++) |
|---|
| 630 | { |
|---|
| 631 | sps->setAMPAcc( i, sps->getUseAMP() ); |
|---|
| 632 | } |
|---|
| 633 | |
|---|
| 634 | for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++) |
|---|
| 635 | { |
|---|
| 636 | sps->setAMPAcc( i, 0 ); |
|---|
| 637 | } |
|---|
| 638 | |
|---|
| 639 | m_cSAO.destroy(); |
|---|
| 640 | #if REPN_FORMAT_IN_VPS |
|---|
| 641 | m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() ); |
|---|
| 642 | #else |
|---|
| 643 | m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() ); |
|---|
| 644 | #endif |
|---|
| 645 | m_cLoopFilter.create( sps->getMaxCUDepth() ); |
|---|
| 646 | } |
|---|
| 647 | |
|---|
| 648 | #if SVC_EXTENSION |
|---|
| 649 | Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC ) |
|---|
| 650 | #else |
|---|
| 651 | Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay ) |
|---|
| 652 | #endif |
|---|
| 653 | { |
|---|
| 654 | TComPic*& pcPic = m_pcPic; |
|---|
| 655 | #if SVC_EXTENSION |
|---|
| 656 | m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder[m_layerId].getPrefetchedVPS(0) ); |
|---|
| 657 | m_apcSlicePilot->initSlice( nalu.m_layerId ); |
|---|
| 658 | #else |
|---|
| 659 | m_apcSlicePilot->initSlice(); |
|---|
| 660 | #endif |
|---|
| 661 | |
|---|
| 662 | if (m_bFirstSliceInPicture) |
|---|
| 663 | { |
|---|
| 664 | m_uiSliceIdx = 0; |
|---|
| 665 | } |
|---|
| 666 | m_apcSlicePilot->setSliceIdx(m_uiSliceIdx); |
|---|
| 667 | if (!m_bFirstSliceInPicture) |
|---|
| 668 | { |
|---|
| 669 | m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) ); |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType); |
|---|
| 673 | Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N || |
|---|
| 674 | m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N || |
|---|
| 675 | m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N || |
|---|
| 676 | m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N || |
|---|
| 677 | m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N); |
|---|
| 678 | m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag); |
|---|
| 679 | |
|---|
| 680 | m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS |
|---|
| 681 | m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId); |
|---|
| 682 | |
|---|
| 683 | #if SVC_EXTENSION |
|---|
| 684 | #if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS |
|---|
| 685 | setRefLayerParams(m_apcSlicePilot->getVPS()); |
|---|
| 686 | #endif |
|---|
| 687 | #if M0457_COL_PICTURE_SIGNALING |
|---|
| 688 | m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers); |
|---|
| 689 | #endif |
|---|
| 690 | #if M0457_IL_SAMPLE_PRED_ONLY_FLAG |
|---|
| 691 | m_apcSlicePilot->setNumSamplePredRefLayers( getNumSamplePredRefLayers() ); |
|---|
| 692 | #endif |
|---|
| 693 | m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder[m_layerId]); |
|---|
| 694 | #else |
|---|
| 695 | m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder); |
|---|
| 696 | #endif |
|---|
| 697 | |
|---|
| 698 | #if HM12_RANDOM_ACCESS |
|---|
| 699 | // set POC for dependent slices in skipped pictures |
|---|
| 700 | if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) |
|---|
| 701 | { |
|---|
| 702 | m_apcSlicePilot->setPOC(m_skippedPOC); |
|---|
| 703 | } |
|---|
| 704 | #endif |
|---|
| 705 | |
|---|
| 706 | // Skip pictures due to random access |
|---|
| 707 | if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay)) |
|---|
| 708 | { |
|---|
| 709 | #if HM12_RANDOM_ACCESS |
|---|
| 710 | m_prevSliceSkipped = true; |
|---|
| 711 | m_skippedPOC = m_apcSlicePilot->getPOC(); |
|---|
| 712 | #endif |
|---|
| 713 | return false; |
|---|
| 714 | } |
|---|
| 715 | // Skip TFD pictures associated with BLA/BLANT pictures |
|---|
| 716 | if (isSkipPictureForBLA(iPOCLastDisplay)) |
|---|
| 717 | { |
|---|
| 718 | #if HM12_RANDOM_ACCESS |
|---|
| 719 | m_prevSliceSkipped = true; |
|---|
| 720 | m_skippedPOC = m_apcSlicePilot->getPOC(); |
|---|
| 721 | #endif |
|---|
| 722 | return false; |
|---|
| 723 | } |
|---|
| 724 | |
|---|
| 725 | #if HM12_RANDOM_ACCESS |
|---|
| 726 | // clear previous slice skipped flag |
|---|
| 727 | m_prevSliceSkipped = false; |
|---|
| 728 | #endif |
|---|
| 729 | |
|---|
| 730 | // exit when a new picture is found |
|---|
| 731 | #if SVC_EXTENSION |
|---|
| 732 | bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC); |
|---|
| 733 | if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence ) |
|---|
| 734 | { |
|---|
| 735 | m_prevPOC = m_apcSlicePilot->getPOC(); |
|---|
| 736 | curLayerId = m_uiPrevLayerId; |
|---|
| 737 | m_uiPrevLayerId = m_layerId; |
|---|
| 738 | return true; |
|---|
| 739 | } |
|---|
| 740 | #else |
|---|
| 741 | //we should only get a different poc for a new picture (with CTU address==0) |
|---|
| 742 | if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0)) |
|---|
| 743 | { |
|---|
| 744 | printf ("Warning, the first slice of a picture might have been lost!\n"); |
|---|
| 745 | } |
|---|
| 746 | // exit when a new picture is found |
|---|
| 747 | if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence ) |
|---|
| 748 | { |
|---|
| 749 | if (m_prevPOC >= m_pocRandomAccess) |
|---|
| 750 | { |
|---|
| 751 | m_prevPOC = m_apcSlicePilot->getPOC(); |
|---|
| 752 | return true; |
|---|
| 753 | } |
|---|
| 754 | m_prevPOC = m_apcSlicePilot->getPOC(); |
|---|
| 755 | } |
|---|
| 756 | #endif |
|---|
| 757 | // actual decoding starts here |
|---|
| 758 | xActivateParameterSets(); |
|---|
| 759 | #if REPN_FORMAT_IN_VPS |
|---|
| 760 | // Initialize ILRP if needed, only for the current layer |
|---|
| 761 | // ILRP intialization should go along with activation of parameters sets, |
|---|
| 762 | // although activation of parameter sets itself need not be done for each and every slice!!! |
|---|
| 763 | xInitILRP(m_apcSlicePilot); |
|---|
| 764 | #endif |
|---|
| 765 | if (m_apcSlicePilot->isNextSlice()) |
|---|
| 766 | { |
|---|
| 767 | m_prevPOC = m_apcSlicePilot->getPOC(); |
|---|
| 768 | #if SVC_EXTENSION |
|---|
| 769 | curLayerId = m_layerId; |
|---|
| 770 | m_uiPrevLayerId = m_layerId; |
|---|
| 771 | #endif |
|---|
| 772 | } |
|---|
| 773 | m_bFirstSliceInSequence = false; |
|---|
| 774 | //detect lost reference picture and insert copy of earlier frame. |
|---|
| 775 | Int lostPoc; |
|---|
| 776 | while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0) |
|---|
| 777 | { |
|---|
| 778 | xCreateLostPicture(lostPoc-1); |
|---|
| 779 | } |
|---|
| 780 | if (m_bFirstSliceInPicture) |
|---|
| 781 | { |
|---|
| 782 | #if AVC_BASE |
|---|
| 783 | if( m_layerId == 1 && m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() ) |
|---|
| 784 | { |
|---|
| 785 | TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin()); |
|---|
| 786 | fstream* pFile = m_ppcTDecTop[0]->getBLReconFile(); |
|---|
| 787 | UInt uiWidth = pBLPic->getPicYuvRec()->getWidth(); |
|---|
| 788 | UInt uiHeight = pBLPic->getPicYuvRec()->getHeight(); |
|---|
| 789 | |
|---|
| 790 | if( pFile->good() ) |
|---|
| 791 | { |
|---|
| 792 | UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2; |
|---|
| 793 | |
|---|
| 794 | pFile->seekg((UInt)uiPos, ios::beg ); |
|---|
| 795 | |
|---|
| 796 | Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr(); |
|---|
| 797 | UInt uiStride = pBLPic->getPicYuvRec()->getStride(); |
|---|
| 798 | for( Int i = 0; i < uiHeight; i++ ) |
|---|
| 799 | { |
|---|
| 800 | for( Int j = 0; j < uiWidth; j++ ) |
|---|
| 801 | { |
|---|
| 802 | pPel[j] = pFile->get(); |
|---|
| 803 | } |
|---|
| 804 | pPel += uiStride; |
|---|
| 805 | } |
|---|
| 806 | |
|---|
| 807 | pPel = pBLPic->getPicYuvRec()->getCbAddr(); |
|---|
| 808 | uiStride = pBLPic->getPicYuvRec()->getCStride(); |
|---|
| 809 | for( Int i = 0; i < uiHeight/2; i++ ) |
|---|
| 810 | { |
|---|
| 811 | for( Int j = 0; j < uiWidth/2; j++ ) |
|---|
| 812 | { |
|---|
| 813 | pPel[j] = pFile->get(); |
|---|
| 814 | } |
|---|
| 815 | pPel += uiStride; |
|---|
| 816 | } |
|---|
| 817 | |
|---|
| 818 | pPel = pBLPic->getPicYuvRec()->getCrAddr(); |
|---|
| 819 | uiStride = pBLPic->getPicYuvRec()->getCStride(); |
|---|
| 820 | for( Int i = 0; i < uiHeight/2; i++ ) |
|---|
| 821 | { |
|---|
| 822 | for( Int j = 0; j < uiWidth/2; j++ ) |
|---|
| 823 | { |
|---|
| 824 | pPel[j] = pFile->get(); |
|---|
| 825 | } |
|---|
| 826 | pPel += uiStride; |
|---|
| 827 | } |
|---|
| 828 | } |
|---|
| 829 | } |
|---|
| 830 | #endif |
|---|
| 831 | |
|---|
| 832 | // Buffer initialize for prediction. |
|---|
| 833 | m_cPrediction.initTempBuff(); |
|---|
| 834 | m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS()); |
|---|
| 835 | // Get a new picture buffer |
|---|
| 836 | xGetNewPicBuffer (m_apcSlicePilot, pcPic); |
|---|
| 837 | |
|---|
| 838 | // transfer any SEI messages that have been received to the picture |
|---|
| 839 | pcPic->setSEIs(m_SEIs); |
|---|
| 840 | m_SEIs.clear(); |
|---|
| 841 | |
|---|
| 842 | // Recursive structure |
|---|
| 843 | m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight ); |
|---|
| 844 | #if SVC_EXTENSION |
|---|
| 845 | m_cCuDecoder.init ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId ); |
|---|
| 846 | #else |
|---|
| 847 | m_cCuDecoder.init ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction ); |
|---|
| 848 | #endif |
|---|
| 849 | m_cTrQuant.init ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize()); |
|---|
| 850 | |
|---|
| 851 | m_cSliceDecoder.create(); |
|---|
| 852 | } |
|---|
| 853 | else |
|---|
| 854 | { |
|---|
| 855 | // Check if any new SEI has arrived |
|---|
| 856 | if(!m_SEIs.empty()) |
|---|
| 857 | { |
|---|
| 858 | // Currently only decoding Unit SEI message occurring between VCL NALUs copied |
|---|
| 859 | SEIMessages &picSEI = pcPic->getSEIs(); |
|---|
| 860 | SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO); |
|---|
| 861 | picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end()); |
|---|
| 862 | deleteSEIs(m_SEIs); |
|---|
| 863 | } |
|---|
| 864 | } |
|---|
| 865 | |
|---|
| 866 | // Set picture slice pointer |
|---|
| 867 | TComSlice* pcSlice = m_apcSlicePilot; |
|---|
| 868 | Bool bNextSlice = pcSlice->isNextSlice(); |
|---|
| 869 | |
|---|
| 870 | UInt uiCummulativeTileWidth; |
|---|
| 871 | UInt uiCummulativeTileHeight; |
|---|
| 872 | UInt i, j, p; |
|---|
| 873 | |
|---|
| 874 | //set NumColumnsMins1 and NumRowsMinus1 |
|---|
| 875 | pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() ); |
|---|
| 876 | pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() ); |
|---|
| 877 | |
|---|
| 878 | //create the TComTileArray |
|---|
| 879 | pcPic->getPicSym()->xCreateTComTileArray(); |
|---|
| 880 | |
|---|
| 881 | if( pcSlice->getPPS()->getUniformSpacingFlag() ) |
|---|
| 882 | { |
|---|
| 883 | //set the width for each tile |
|---|
| 884 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
|---|
| 885 | { |
|---|
| 886 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++) |
|---|
| 887 | { |
|---|
| 888 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )-> |
|---|
| 889 | setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) |
|---|
| 890 | - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) ); |
|---|
| 891 | } |
|---|
| 892 | } |
|---|
| 893 | |
|---|
| 894 | //set the height for each tile |
|---|
| 895 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
|---|
| 896 | { |
|---|
| 897 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++) |
|---|
| 898 | { |
|---|
| 899 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )-> |
|---|
| 900 | setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) |
|---|
| 901 | - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) ); |
|---|
| 902 | } |
|---|
| 903 | } |
|---|
| 904 | } |
|---|
| 905 | else |
|---|
| 906 | { |
|---|
| 907 | //set the width for each tile |
|---|
| 908 | for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++) |
|---|
| 909 | { |
|---|
| 910 | uiCummulativeTileWidth = 0; |
|---|
| 911 | for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++) |
|---|
| 912 | { |
|---|
| 913 | pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) ); |
|---|
| 914 | uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i); |
|---|
| 915 | } |
|---|
| 916 | pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth ); |
|---|
| 917 | } |
|---|
| 918 | |
|---|
| 919 | //set the height for each tile |
|---|
| 920 | for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++) |
|---|
| 921 | { |
|---|
| 922 | uiCummulativeTileHeight = 0; |
|---|
| 923 | for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++) |
|---|
| 924 | { |
|---|
| 925 | pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) ); |
|---|
| 926 | uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i); |
|---|
| 927 | } |
|---|
| 928 | pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight ); |
|---|
| 929 | } |
|---|
| 930 | } |
|---|
| 931 | |
|---|
| 932 | pcPic->getPicSym()->xInitTiles(); |
|---|
| 933 | |
|---|
| 934 | //generate the Coding Order Map and Inverse Coding Order Map |
|---|
| 935 | UInt uiEncCUAddr; |
|---|
| 936 | for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr)) |
|---|
| 937 | { |
|---|
| 938 | pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr); |
|---|
| 939 | pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i); |
|---|
| 940 | } |
|---|
| 941 | pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
|---|
| 942 | pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
|---|
| 943 | |
|---|
| 944 | //convert the start and end CU addresses of the slice and dependent slice into encoding order |
|---|
| 945 | pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) ); |
|---|
| 946 | pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) ); |
|---|
| 947 | if(pcSlice->isNextSlice()) |
|---|
| 948 | { |
|---|
| 949 | pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr())); |
|---|
| 950 | pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr())); |
|---|
| 951 | } |
|---|
| 952 | |
|---|
| 953 | if (m_bFirstSliceInPicture) |
|---|
| 954 | { |
|---|
| 955 | if(pcPic->getNumAllocatedSlice() != 1) |
|---|
| 956 | { |
|---|
| 957 | pcPic->clearSliceBuffer(); |
|---|
| 958 | } |
|---|
| 959 | } |
|---|
| 960 | else |
|---|
| 961 | { |
|---|
| 962 | pcPic->allocateNewSlice(); |
|---|
| 963 | } |
|---|
| 964 | assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1)); |
|---|
| 965 | m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); |
|---|
| 966 | pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx); |
|---|
| 967 | |
|---|
| 968 | pcPic->setTLayer(nalu.m_temporalId); |
|---|
| 969 | |
|---|
| 970 | #if SVC_EXTENSION |
|---|
| 971 | pcPic->setLayerId(nalu.m_layerId); |
|---|
| 972 | pcSlice->setLayerId(nalu.m_layerId); |
|---|
| 973 | #endif |
|---|
| 974 | |
|---|
| 975 | if (bNextSlice) |
|---|
| 976 | { |
|---|
| 977 | pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic ); |
|---|
| 978 | // Set reference list |
|---|
| 979 | #if SVC_EXTENSION |
|---|
| 980 | if (m_layerId == 0) |
|---|
| 981 | #endif |
|---|
| 982 | #if FIX1071 |
|---|
| 983 | pcSlice->setRefPicList( m_cListPic, true ); |
|---|
| 984 | #else |
|---|
| 985 | pcSlice->setRefPicList( m_cListPic ); |
|---|
| 986 | #endif |
|---|
| 987 | |
|---|
| 988 | #if SVC_EXTENSION |
|---|
| 989 | if(m_layerId > 0) |
|---|
| 990 | { |
|---|
| 991 | for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
|---|
| 992 | { |
|---|
| 993 | UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i); |
|---|
| 994 | #if AVC_BASE |
|---|
| 995 | if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder[0].getActiveVPS()->getAvcBaseLayerFlag() ) |
|---|
| 996 | { |
|---|
| 997 | pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() ); |
|---|
| 998 | #if AVC_SYNTAX |
|---|
| 999 | TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc); |
|---|
| 1000 | if( pcSlice->getPOC() == 0 ) |
|---|
| 1001 | { |
|---|
| 1002 | // initialize partition order. |
|---|
| 1003 | UInt* piTmp = &g_auiZscanToRaster[0]; |
|---|
| 1004 | initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp ); |
|---|
| 1005 | initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 ); |
|---|
| 1006 | } |
|---|
| 1007 | pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice ); |
|---|
| 1008 | pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES ); |
|---|
| 1009 | #endif |
|---|
| 1010 | } |
|---|
| 1011 | else |
|---|
| 1012 | { |
|---|
| 1013 | #if VPS_EXTN_DIRECT_REF_LAYERS |
|---|
| 1014 | TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc ); |
|---|
| 1015 | #else |
|---|
| 1016 | TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 ); |
|---|
| 1017 | #endif |
|---|
| 1018 | TComList<TComPic*> *cListPic = pcTDecTop->getListPic(); |
|---|
| 1019 | pcSlice->setBaseColPic ( *cListPic, refLayerIdc ); |
|---|
| 1020 | } |
|---|
| 1021 | #else |
|---|
| 1022 | #if VPS_EXTN_DIRECT_REF_LAYERS |
|---|
| 1023 | TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc ); |
|---|
| 1024 | #else |
|---|
| 1025 | TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 ); |
|---|
| 1026 | #endif |
|---|
| 1027 | TComList<TComPic*> *cListPic = pcTDecTop->getListPic(); |
|---|
| 1028 | pcSlice->setBaseColPic ( *cListPic, refLayerIdc ); |
|---|
| 1029 | #endif |
|---|
| 1030 | |
|---|
| 1031 | #if SCALED_REF_LAYER_OFFSETS |
|---|
| 1032 | const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc); |
|---|
| 1033 | |
|---|
| 1034 | |
|---|
| 1035 | Int widthBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth(); |
|---|
| 1036 | Int heightBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight(); |
|---|
| 1037 | |
|---|
| 1038 | Int widthEL = pcPic->getPicYuvRec()->getWidth() - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset(); |
|---|
| 1039 | Int heightEL = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset() - scalEL.getWindowBottomOffset(); |
|---|
| 1040 | #else |
|---|
| 1041 | const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow(); |
|---|
| 1042 | const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow(); |
|---|
| 1043 | |
|---|
| 1044 | Int widthBL = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset(); |
|---|
| 1045 | Int heightBL = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset(); |
|---|
| 1046 | |
|---|
| 1047 | Int widthEL = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset(); |
|---|
| 1048 | Int heightEL = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset(); |
|---|
| 1049 | #endif |
|---|
| 1050 | g_mvScalingFactor[refLayerIdc][0] = widthEL == widthBL ? 4096 : Clip3(-4096, 4095, ((widthEL << 8) + (widthBL >> 1)) / widthBL); |
|---|
| 1051 | g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL); |
|---|
| 1052 | |
|---|
| 1053 | g_posScalingFactor[refLayerIdc][0] = ((widthBL << 16) + (widthEL >> 1)) / widthEL; |
|---|
| 1054 | g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL; |
|---|
| 1055 | |
|---|
| 1056 | #if SVC_UPSAMPLING |
|---|
| 1057 | if( pcPic->isSpatialEnhLayer(refLayerIdc) ) |
|---|
| 1058 | { |
|---|
| 1059 | #if SCALED_REF_LAYER_OFFSETS |
|---|
| 1060 | m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) ); |
|---|
| 1061 | #else |
|---|
| 1062 | m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec() ); |
|---|
| 1063 | #endif |
|---|
| 1064 | } |
|---|
| 1065 | else |
|---|
| 1066 | { |
|---|
| 1067 | pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() ); |
|---|
| 1068 | } |
|---|
| 1069 | pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) ); |
|---|
| 1070 | #endif |
|---|
| 1071 | } |
|---|
| 1072 | } |
|---|
| 1073 | |
|---|
| 1074 | if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() ) |
|---|
| 1075 | { |
|---|
| 1076 | setILRPic(pcPic); |
|---|
| 1077 | #if REF_IDX_MFM |
|---|
| 1078 | #if M0457_COL_PICTURE_SIGNALING |
|---|
| 1079 | if( pcSlice->getMFMEnabledFlag() ) |
|---|
| 1080 | #else |
|---|
| 1081 | if( pcSlice->getSPS()->getMFMEnabledFlag() ) |
|---|
| 1082 | #endif |
|---|
| 1083 | { |
|---|
| 1084 | pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic()); |
|---|
| 1085 | #if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING |
|---|
| 1086 | pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice)); |
|---|
| 1087 | #endif |
|---|
| 1088 | } |
|---|
| 1089 | pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic); |
|---|
| 1090 | } |
|---|
| 1091 | #if M0040_ADAPTIVE_RESOLUTION_CHANGE |
|---|
| 1092 | else if ( m_layerId > 0 ) |
|---|
| 1093 | { |
|---|
| 1094 | pcSlice->setRefPicList( m_cListPic, false, NULL); |
|---|
| 1095 | } |
|---|
| 1096 | #endif |
|---|
| 1097 | #endif |
|---|
| 1098 | |
|---|
| 1099 | #endif //SVC_EXTENSION |
|---|
| 1100 | |
|---|
| 1101 | // For generalized B |
|---|
| 1102 | // note: maybe not existed case (always L0 is copied to L1 if L1 is empty) |
|---|
| 1103 | if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0) |
|---|
| 1104 | { |
|---|
| 1105 | Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0); |
|---|
| 1106 | pcSlice->setNumRefIdx ( REF_PIC_LIST_1, iNumRefIdx ); |
|---|
| 1107 | |
|---|
| 1108 | for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++) |
|---|
| 1109 | { |
|---|
| 1110 | pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx); |
|---|
| 1111 | } |
|---|
| 1112 | } |
|---|
| 1113 | if (!pcSlice->isIntra()) |
|---|
| 1114 | { |
|---|
| 1115 | Bool bLowDelay = true; |
|---|
| 1116 | Int iCurrPOC = pcSlice->getPOC(); |
|---|
| 1117 | Int iRefIdx = 0; |
|---|
| 1118 | |
|---|
| 1119 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++) |
|---|
| 1120 | { |
|---|
| 1121 | if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC ) |
|---|
| 1122 | { |
|---|
| 1123 | bLowDelay = false; |
|---|
| 1124 | } |
|---|
| 1125 | } |
|---|
| 1126 | if (pcSlice->isInterB()) |
|---|
| 1127 | { |
|---|
| 1128 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++) |
|---|
| 1129 | { |
|---|
| 1130 | if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC ) |
|---|
| 1131 | { |
|---|
| 1132 | bLowDelay = false; |
|---|
| 1133 | } |
|---|
| 1134 | } |
|---|
| 1135 | } |
|---|
| 1136 | |
|---|
| 1137 | pcSlice->setCheckLDC(bLowDelay); |
|---|
| 1138 | } |
|---|
| 1139 | |
|---|
| 1140 | //--------------- |
|---|
| 1141 | pcSlice->setRefPOCList(); |
|---|
| 1142 | } |
|---|
| 1143 | |
|---|
| 1144 | pcPic->setCurrSliceIdx(m_uiSliceIdx); |
|---|
| 1145 | if(pcSlice->getSPS()->getScalingListFlag()) |
|---|
| 1146 | { |
|---|
| 1147 | pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList() ); |
|---|
| 1148 | if(pcSlice->getPPS()->getScalingListPresentFlag()) |
|---|
| 1149 | { |
|---|
| 1150 | pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList() ); |
|---|
| 1151 | } |
|---|
| 1152 | pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip()); |
|---|
| 1153 | if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag()) |
|---|
| 1154 | { |
|---|
| 1155 | pcSlice->setDefaultScalingList(); |
|---|
| 1156 | } |
|---|
| 1157 | m_cTrQuant.setScalingListDec(pcSlice->getScalingList()); |
|---|
| 1158 | m_cTrQuant.setUseScalingList(true); |
|---|
| 1159 | } |
|---|
| 1160 | else |
|---|
| 1161 | { |
|---|
| 1162 | m_cTrQuant.setFlatScalingList(); |
|---|
| 1163 | m_cTrQuant.setUseScalingList(false); |
|---|
| 1164 | } |
|---|
| 1165 | |
|---|
| 1166 | // Decode a picture |
|---|
| 1167 | m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic); |
|---|
| 1168 | |
|---|
| 1169 | m_bFirstSliceInPicture = false; |
|---|
| 1170 | m_uiSliceIdx++; |
|---|
| 1171 | |
|---|
| 1172 | return false; |
|---|
| 1173 | } |
|---|
| 1174 | |
|---|
| 1175 | Void TDecTop::xDecodeVPS() |
|---|
| 1176 | { |
|---|
| 1177 | TComVPS* vps = new TComVPS(); |
|---|
| 1178 | |
|---|
| 1179 | m_cEntropyDecoder.decodeVPS( vps ); |
|---|
| 1180 | #if SVC_EXTENSION |
|---|
| 1181 | m_parameterSetManagerDecoder[0].storePrefetchedVPS(vps); |
|---|
| 1182 | #else |
|---|
| 1183 | m_parameterSetManagerDecoder.storePrefetchedVPS(vps); |
|---|
| 1184 | #endif |
|---|
| 1185 | } |
|---|
| 1186 | |
|---|
| 1187 | Void TDecTop::xDecodeSPS() |
|---|
| 1188 | { |
|---|
| 1189 | TComSPS* sps = new TComSPS(); |
|---|
| 1190 | #if SVC_EXTENSION |
|---|
| 1191 | sps->setLayerId(m_layerId); |
|---|
| 1192 | #endif |
|---|
| 1193 | #if SPS_SUB_LAYER_INFO |
|---|
| 1194 | m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder[0] ); |
|---|
| 1195 | #else |
|---|
| 1196 | m_cEntropyDecoder.decodeSPS( sps ); |
|---|
| 1197 | #endif |
|---|
| 1198 | #if SVC_EXTENSION |
|---|
| 1199 | m_parameterSetManagerDecoder[m_layerId].storePrefetchedSPS(sps); |
|---|
| 1200 | #else |
|---|
| 1201 | m_parameterSetManagerDecoder.storePrefetchedSPS(sps); |
|---|
| 1202 | #endif |
|---|
| 1203 | #if SVC_EXTENSION |
|---|
| 1204 | #if !REPN_FORMAT_IN_VPS // ILRP can only be initialized at activation |
|---|
| 1205 | if(m_numLayer>0) |
|---|
| 1206 | { |
|---|
| 1207 | xInitILRP(sps); |
|---|
| 1208 | } |
|---|
| 1209 | #endif |
|---|
| 1210 | #endif |
|---|
| 1211 | } |
|---|
| 1212 | |
|---|
| 1213 | Void TDecTop::xDecodePPS() |
|---|
| 1214 | { |
|---|
| 1215 | TComPPS* pps = new TComPPS(); |
|---|
| 1216 | m_cEntropyDecoder.decodePPS( pps ); |
|---|
| 1217 | #if SVC_EXTENSION |
|---|
| 1218 | m_parameterSetManagerDecoder[m_layerId].storePrefetchedPPS( pps ); |
|---|
| 1219 | #else |
|---|
| 1220 | m_parameterSetManagerDecoder.storePrefetchedPPS( pps ); |
|---|
| 1221 | #endif |
|---|
| 1222 | |
|---|
| 1223 | if( pps->getDependentSliceSegmentsEnabledFlag() ) |
|---|
| 1224 | { |
|---|
| 1225 | Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1; |
|---|
| 1226 | m_cSliceDecoder.initCtxMem(NumCtx); |
|---|
| 1227 | for ( UInt st = 0; st < NumCtx; st++ ) |
|---|
| 1228 | { |
|---|
| 1229 | TDecSbac* ctx = NULL; |
|---|
| 1230 | ctx = new TDecSbac; |
|---|
| 1231 | ctx->init( &m_cBinCABAC ); |
|---|
| 1232 | m_cSliceDecoder.setCtxMem( ctx, st ); |
|---|
| 1233 | } |
|---|
| 1234 | } |
|---|
| 1235 | } |
|---|
| 1236 | |
|---|
| 1237 | Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType ) |
|---|
| 1238 | { |
|---|
| 1239 | #if SVC_EXTENSION |
|---|
| 1240 | if(nalUnitType == NAL_UNIT_SUFFIX_SEI) |
|---|
| 1241 | { |
|---|
| 1242 | #if RANDOM_ACCESS_SEI_FIX |
|---|
| 1243 | if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit |
|---|
| 1244 | { |
|---|
| 1245 | return; |
|---|
| 1246 | } |
|---|
| 1247 | #endif |
|---|
| 1248 | #if M0043_LAYERS_PRESENT_SEI |
|---|
| 1249 | m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveVPS(), m_parameterSetManagerDecoder[m_layerId].getActiveSPS() ); |
|---|
| 1250 | #else |
|---|
| 1251 | m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() ); |
|---|
| 1252 | #endif |
|---|
| 1253 | } |
|---|
| 1254 | else |
|---|
| 1255 | { |
|---|
| 1256 | #if M0043_LAYERS_PRESENT_SEI |
|---|
| 1257 | m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveVPS(), m_parameterSetManagerDecoder[m_layerId].getActiveSPS() ); |
|---|
| 1258 | #else |
|---|
| 1259 | m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() ); |
|---|
| 1260 | #endif |
|---|
| 1261 | SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS); |
|---|
| 1262 | if (activeParamSets.size()>0) |
|---|
| 1263 | { |
|---|
| 1264 | SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin()); |
|---|
| 1265 | m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS(); |
|---|
| 1266 | assert(seiAps->activeSeqParamSetId.size()>0); |
|---|
| 1267 | if (! m_parameterSetManagerDecoder[m_layerId].activateSPSWithSEI(seiAps->activeSeqParamSetId[0] )) |
|---|
| 1268 | { |
|---|
| 1269 | printf ("Warning SPS activation with Active parameter set SEI failed"); |
|---|
| 1270 | } |
|---|
| 1271 | } |
|---|
| 1272 | } |
|---|
| 1273 | #else |
|---|
| 1274 | if(nalUnitType == NAL_UNIT_SUFFIX_SEI) |
|---|
| 1275 | { |
|---|
| 1276 | #if M0043_LAYERS_PRESENT_SEI |
|---|
| 1277 | m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() ); |
|---|
| 1278 | #else |
|---|
| 1279 | m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() ); |
|---|
| 1280 | #endif |
|---|
| 1281 | } |
|---|
| 1282 | else |
|---|
| 1283 | { |
|---|
| 1284 | #if M0043_LAYERS_PRESENT_SEI |
|---|
| 1285 | m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() ); |
|---|
| 1286 | #else |
|---|
| 1287 | m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() ); |
|---|
| 1288 | #endif |
|---|
| 1289 | SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS); |
|---|
| 1290 | if (activeParamSets.size()>0) |
|---|
| 1291 | { |
|---|
| 1292 | SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin()); |
|---|
| 1293 | m_parameterSetManagerDecoder.applyPrefetchedPS(); |
|---|
| 1294 | assert(seiAps->activeSeqParamSetId.size()>0); |
|---|
| 1295 | if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] )) |
|---|
| 1296 | { |
|---|
| 1297 | printf ("Warning SPS activation with Active parameter set SEI failed"); |
|---|
| 1298 | } |
|---|
| 1299 | } |
|---|
| 1300 | } |
|---|
| 1301 | #endif |
|---|
| 1302 | } |
|---|
| 1303 | |
|---|
| 1304 | #if SVC_EXTENSION |
|---|
| 1305 | Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC) |
|---|
| 1306 | #else |
|---|
| 1307 | Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay) |
|---|
| 1308 | #endif |
|---|
| 1309 | { |
|---|
| 1310 | // Initialize entropy decoder |
|---|
| 1311 | m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder); |
|---|
| 1312 | m_cEntropyDecoder.setBitstream (nalu.m_Bitstream); |
|---|
| 1313 | |
|---|
| 1314 | switch (nalu.m_nalUnitType) |
|---|
| 1315 | { |
|---|
| 1316 | case NAL_UNIT_VPS: |
|---|
| 1317 | xDecodeVPS(); |
|---|
| 1318 | #if AVC_BASE |
|---|
| 1319 | if( m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() ) |
|---|
| 1320 | { |
|---|
| 1321 | if( !m_ppcTDecTop[0]->getBLReconFile()->good() ) |
|---|
| 1322 | { |
|---|
| 1323 | printf( "Base layer YUV input reading error\n" ); |
|---|
| 1324 | exit(EXIT_FAILURE); |
|---|
| 1325 | } |
|---|
| 1326 | #if AVC_SYNTAX |
|---|
| 1327 | if( !m_ppcTDecTop[0]->getBLSyntaxFile()->good() ) |
|---|
| 1328 | { |
|---|
| 1329 | printf( "Base layer syntax input reading error\n" ); |
|---|
| 1330 | exit(EXIT_FAILURE); |
|---|
| 1331 | } |
|---|
| 1332 | #endif |
|---|
| 1333 | } |
|---|
| 1334 | else |
|---|
| 1335 | { |
|---|
| 1336 | TComList<TComPic*> *cListPic = m_ppcTDecTop[0]->getListPic(); |
|---|
| 1337 | cListPic->clear(); |
|---|
| 1338 | } |
|---|
| 1339 | #endif |
|---|
| 1340 | return false; |
|---|
| 1341 | |
|---|
| 1342 | case NAL_UNIT_SPS: |
|---|
| 1343 | xDecodeSPS(); |
|---|
| 1344 | #if AVC_BASE |
|---|
| 1345 | if( m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() ) |
|---|
| 1346 | { |
|---|
| 1347 | TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin()); |
|---|
| 1348 | if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL ) |
|---|
| 1349 | { |
|---|
| 1350 | // using EL SPS with spsId = 1 |
|---|
| 1351 | TComSPS* sps = m_parameterSetManagerDecoder[nalu.m_layerId].getPrefetchedSPS(1); |
|---|
| 1352 | Int numReorderPics[MAX_TLAYER]; |
|---|
| 1353 | Window &conformanceWindow = sps->getConformanceWindow(); |
|---|
| 1354 | Window defaultDisplayWindow = sps->getVuiParametersPresentFlag() ? sps->getVuiParameters()->getDefaultDisplayWindow() : Window(); |
|---|
| 1355 | #if SVC_UPSAMPLING |
|---|
| 1356 | #if AVC_SYNTAX |
|---|
| 1357 | |
|---|
| 1358 | pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true); |
|---|
| 1359 | #else |
|---|
| 1360 | pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true); |
|---|
| 1361 | #endif |
|---|
| 1362 | #else |
|---|
| 1363 | pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true); |
|---|
| 1364 | #endif |
|---|
| 1365 | } |
|---|
| 1366 | } |
|---|
| 1367 | #endif |
|---|
| 1368 | return false; |
|---|
| 1369 | |
|---|
| 1370 | case NAL_UNIT_PPS: |
|---|
| 1371 | xDecodePPS(); |
|---|
| 1372 | return false; |
|---|
| 1373 | |
|---|
| 1374 | case NAL_UNIT_PREFIX_SEI: |
|---|
| 1375 | case NAL_UNIT_SUFFIX_SEI: |
|---|
| 1376 | xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType ); |
|---|
| 1377 | return false; |
|---|
| 1378 | |
|---|
| 1379 | case NAL_UNIT_CODED_SLICE_TRAIL_R: |
|---|
| 1380 | case NAL_UNIT_CODED_SLICE_TRAIL_N: |
|---|
| 1381 | case NAL_UNIT_CODED_SLICE_TLA_R: |
|---|
| 1382 | case NAL_UNIT_CODED_SLICE_TSA_N: |
|---|
| 1383 | case NAL_UNIT_CODED_SLICE_STSA_R: |
|---|
| 1384 | case NAL_UNIT_CODED_SLICE_STSA_N: |
|---|
| 1385 | case NAL_UNIT_CODED_SLICE_BLA_W_LP: |
|---|
| 1386 | case NAL_UNIT_CODED_SLICE_BLA_W_RADL: |
|---|
| 1387 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: |
|---|
| 1388 | case NAL_UNIT_CODED_SLICE_IDR_W_RADL: |
|---|
| 1389 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: |
|---|
| 1390 | case NAL_UNIT_CODED_SLICE_CRA: |
|---|
| 1391 | case NAL_UNIT_CODED_SLICE_RADL_N: |
|---|
| 1392 | case NAL_UNIT_CODED_SLICE_RADL_R: |
|---|
| 1393 | case NAL_UNIT_CODED_SLICE_RASL_N: |
|---|
| 1394 | case NAL_UNIT_CODED_SLICE_RASL_R: |
|---|
| 1395 | #if SVC_EXTENSION |
|---|
| 1396 | return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC); |
|---|
| 1397 | #else |
|---|
| 1398 | return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay); |
|---|
| 1399 | #endif |
|---|
| 1400 | break; |
|---|
| 1401 | default: |
|---|
| 1402 | assert (1); |
|---|
| 1403 | } |
|---|
| 1404 | |
|---|
| 1405 | return false; |
|---|
| 1406 | } |
|---|
| 1407 | |
|---|
| 1408 | /** Function for checking if picture should be skipped because of association with a previous BLA picture |
|---|
| 1409 | * \param iPOCLastDisplay POC of last picture displayed |
|---|
| 1410 | * \returns true if the picture should be skipped |
|---|
| 1411 | * This function skips all TFD pictures that follow a BLA picture |
|---|
| 1412 | * in decoding order and precede it in output order. |
|---|
| 1413 | */ |
|---|
| 1414 | Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay) |
|---|
| 1415 | { |
|---|
| 1416 | 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)) |
|---|
| 1417 | { |
|---|
| 1418 | iPOCLastDisplay++; |
|---|
| 1419 | return true; |
|---|
| 1420 | } |
|---|
| 1421 | return false; |
|---|
| 1422 | } |
|---|
| 1423 | |
|---|
| 1424 | /** Function for checking if picture should be skipped because of random access |
|---|
| 1425 | * \param iSkipFrame skip frame counter |
|---|
| 1426 | * \param iPOCLastDisplay POC of last picture displayed |
|---|
| 1427 | * \returns true if the picture shold be skipped in the random access. |
|---|
| 1428 | * This function checks the skipping of pictures in the case of -s option random access. |
|---|
| 1429 | * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped. |
|---|
| 1430 | * It also checks the type of Nal unit type at the random access point. |
|---|
| 1431 | * 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. |
|---|
| 1432 | * If the random access point is IDR all pictures after the random access point are decoded. |
|---|
| 1433 | * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC |
|---|
| 1434 | * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random |
|---|
| 1435 | * access point there is no guarantee that the decoder will not crash. |
|---|
| 1436 | */ |
|---|
| 1437 | Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame, Int& iPOCLastDisplay) |
|---|
| 1438 | { |
|---|
| 1439 | if (iSkipFrame) |
|---|
| 1440 | { |
|---|
| 1441 | iSkipFrame--; // decrement the counter |
|---|
| 1442 | return true; |
|---|
| 1443 | } |
|---|
| 1444 | else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet. |
|---|
| 1445 | { |
|---|
| 1446 | if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA |
|---|
| 1447 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
|---|
| 1448 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
|---|
| 1449 | || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ) |
|---|
| 1450 | { |
|---|
| 1451 | // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT. |
|---|
| 1452 | m_pocRandomAccess = m_apcSlicePilot->getPOC(); |
|---|
| 1453 | } |
|---|
| 1454 | else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
|---|
| 1455 | { |
|---|
| 1456 | m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable. |
|---|
| 1457 | } |
|---|
| 1458 | else |
|---|
| 1459 | { |
|---|
| 1460 | static Bool warningMessage = false; |
|---|
| 1461 | if(!warningMessage) |
|---|
| 1462 | { |
|---|
| 1463 | printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture"); |
|---|
| 1464 | warningMessage = true; |
|---|
| 1465 | } |
|---|
| 1466 | return true; |
|---|
| 1467 | } |
|---|
| 1468 | } |
|---|
| 1469 | // skip the reordered pictures, if necessary |
|---|
| 1470 | 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)) |
|---|
| 1471 | { |
|---|
| 1472 | iPOCLastDisplay++; |
|---|
| 1473 | return true; |
|---|
| 1474 | } |
|---|
| 1475 | // if we reach here, then the picture is not skipped. |
|---|
| 1476 | return false; |
|---|
| 1477 | } |
|---|
| 1478 | |
|---|
| 1479 | #if VPS_EXTN_DIRECT_REF_LAYERS |
|---|
| 1480 | TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc ) |
|---|
| 1481 | { |
|---|
| 1482 | TComVPS* vps = m_parameterSetManagerDecoder[0].getActiveVPS(); |
|---|
| 1483 | if( vps->getNumDirectRefLayers( m_layerId ) <= 0 ) |
|---|
| 1484 | { |
|---|
| 1485 | return (TDecTop *)getLayerDec( 0 ); |
|---|
| 1486 | } |
|---|
| 1487 | |
|---|
| 1488 | return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdc ) ); |
|---|
| 1489 | } |
|---|
| 1490 | #endif |
|---|
| 1491 | |
|---|
| 1492 | #if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS |
|---|
| 1493 | |
|---|
| 1494 | Void TDecTop::setRefLayerParams( TComVPS* vps ) |
|---|
| 1495 | { |
|---|
| 1496 | for(UInt layer = 0; layer < m_numLayer; layer++) |
|---|
| 1497 | { |
|---|
| 1498 | TDecTop *decTop = (TDecTop *)getLayerDec(layer); |
|---|
| 1499 | decTop->setNumSamplePredRefLayers(0); |
|---|
| 1500 | decTop->setNumMotionPredRefLayers(0); |
|---|
| 1501 | decTop->setNumDirectRefLayers(0); |
|---|
| 1502 | for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++) |
|---|
| 1503 | { |
|---|
| 1504 | decTop->setSamplePredEnabledFlag(i, false); |
|---|
| 1505 | decTop->setMotionPredEnabledFlag(i, false); |
|---|
| 1506 | decTop->setSamplePredRefLayerId(i, 0); |
|---|
| 1507 | decTop->setMotionPredRefLayerId(i, 0); |
|---|
| 1508 | } |
|---|
| 1509 | for(Int j = 0; j < layer; j++) |
|---|
| 1510 | { |
|---|
| 1511 | if (vps->getDirectDependencyFlag(layer, j)) |
|---|
| 1512 | { |
|---|
| 1513 | decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layer)); |
|---|
| 1514 | decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1); |
|---|
| 1515 | |
|---|
| 1516 | Int samplePredEnabledFlag = (vps->getDirectDependencyType(layer, j) + 1) & 1; |
|---|
| 1517 | decTop->setSamplePredEnabledFlag(j, samplePredEnabledFlag == 1 ? true : false); |
|---|
| 1518 | decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag); |
|---|
| 1519 | |
|---|
| 1520 | Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layer, j) + 1) & 2) >> 1; |
|---|
| 1521 | decTop->setMotionPredEnabledFlag(j, motionPredEnabledFlag == 1 ? true : false); |
|---|
| 1522 | decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag); |
|---|
| 1523 | } |
|---|
| 1524 | } |
|---|
| 1525 | } |
|---|
| 1526 | for ( Int i = 1, mIdx = 0, sIdx = 0; i < m_numLayer; i++ ) |
|---|
| 1527 | { |
|---|
| 1528 | Int iNuhLId = vps->getLayerIdInNuh(i); |
|---|
| 1529 | TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId); |
|---|
| 1530 | for ( Int j = 0; j < i; j++ ) |
|---|
| 1531 | { |
|---|
| 1532 | if (decTop->getMotionPredEnabledFlag(j)) |
|---|
| 1533 | { |
|---|
| 1534 | decTop->setMotionPredRefLayerId(mIdx++, vps->getLayerIdInNuh(j)); |
|---|
| 1535 | } |
|---|
| 1536 | if (decTop->getSamplePredEnabledFlag(j)) |
|---|
| 1537 | { |
|---|
| 1538 | decTop->setSamplePredRefLayerId(sIdx++, vps->getLayerIdInNuh(j)); |
|---|
| 1539 | } |
|---|
| 1540 | } |
|---|
| 1541 | } |
|---|
| 1542 | } |
|---|
| 1543 | |
|---|
| 1544 | #endif |
|---|
| 1545 | |
|---|
| 1546 | #if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING |
|---|
| 1547 | TComPic* TDecTop::getMotionPredIlp(TComSlice* pcSlice) |
|---|
| 1548 | { |
|---|
| 1549 | TComPic* ilpPic = NULL; |
|---|
| 1550 | Int activeMotionPredReflayerIdx = 0; |
|---|
| 1551 | |
|---|
| 1552 | for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
|---|
| 1553 | { |
|---|
| 1554 | UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i); |
|---|
| 1555 | if( getMotionPredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) ) ) |
|---|
| 1556 | { |
|---|
| 1557 | if (activeMotionPredReflayerIdx == pcSlice->getColRefLayerIdx()) |
|---|
| 1558 | { |
|---|
| 1559 | ilpPic = m_cIlpPic[refLayerIdc]; |
|---|
| 1560 | break; |
|---|
| 1561 | } |
|---|
| 1562 | else |
|---|
| 1563 | { |
|---|
| 1564 | activeMotionPredReflayerIdx++; |
|---|
| 1565 | } |
|---|
| 1566 | } |
|---|
| 1567 | } |
|---|
| 1568 | |
|---|
| 1569 | assert(ilpPic != NULL); |
|---|
| 1570 | |
|---|
| 1571 | return ilpPic; |
|---|
| 1572 | } |
|---|
| 1573 | #endif |
|---|
| 1574 | |
|---|
| 1575 | //! \} |
|---|