[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 TDecSlice.cpp |
---|
| 35 | \brief slice decoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TDecSlice.h" |
---|
| 39 | |
---|
| 40 | //! \ingroup TLibDecoder |
---|
| 41 | //! \{ |
---|
| 42 | |
---|
| 43 | ////////////////////////////////////////////////////////////////////// |
---|
| 44 | // Construction/Destruction |
---|
| 45 | ////////////////////////////////////////////////////////////////////// |
---|
| 46 | |
---|
| 47 | TDecSlice::TDecSlice() |
---|
| 48 | { |
---|
| 49 | m_pcBufferSbacDecoders = NULL; |
---|
| 50 | m_pcBufferBinCABACs = NULL; |
---|
| 51 | m_pcBufferLowLatSbacDecoders = NULL; |
---|
| 52 | m_pcBufferLowLatBinCABACs = NULL; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | TDecSlice::~TDecSlice() |
---|
| 56 | { |
---|
| 57 | #if DEPENDENT_SLICES |
---|
| 58 | for (std::vector<TDecSbac*>::iterator i = CTXMem.begin(); i != CTXMem.end(); i++) |
---|
| 59 | { |
---|
| 60 | delete (*i); |
---|
| 61 | } |
---|
| 62 | CTXMem.clear(); |
---|
| 63 | #endif |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | #if DEPENDENT_SLICES |
---|
| 67 | Void TDecSlice::initCtxMem( UInt i ) |
---|
| 68 | { |
---|
| 69 | for (std::vector<TDecSbac*>::iterator j = CTXMem.begin(); j != CTXMem.end(); j++) |
---|
| 70 | { |
---|
| 71 | delete (*j); |
---|
| 72 | } |
---|
| 73 | CTXMem.clear(); |
---|
| 74 | CTXMem.resize(i); |
---|
| 75 | } |
---|
| 76 | #endif |
---|
| 77 | |
---|
| 78 | Void TDecSlice::create( TComSlice* pcSlice, Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth ) |
---|
| 79 | { |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | Void TDecSlice::destroy() |
---|
| 83 | { |
---|
| 84 | if ( m_pcBufferSbacDecoders ) |
---|
| 85 | { |
---|
| 86 | delete[] m_pcBufferSbacDecoders; |
---|
| 87 | m_pcBufferSbacDecoders = NULL; |
---|
| 88 | } |
---|
| 89 | if ( m_pcBufferBinCABACs ) |
---|
| 90 | { |
---|
| 91 | delete[] m_pcBufferBinCABACs; |
---|
| 92 | m_pcBufferBinCABACs = NULL; |
---|
| 93 | } |
---|
| 94 | if ( m_pcBufferLowLatSbacDecoders ) |
---|
| 95 | { |
---|
| 96 | delete[] m_pcBufferLowLatSbacDecoders; |
---|
| 97 | m_pcBufferLowLatSbacDecoders = NULL; |
---|
| 98 | } |
---|
| 99 | if ( m_pcBufferLowLatBinCABACs ) |
---|
| 100 | { |
---|
| 101 | delete[] m_pcBufferLowLatBinCABACs; |
---|
| 102 | m_pcBufferLowLatBinCABACs = NULL; |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | #if SVC_EXTENSION |
---|
| 107 | Void TDecSlice::init(TDecTop** ppcDecTop,TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder) |
---|
| 108 | #else |
---|
| 109 | Void TDecSlice::init(TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder) |
---|
| 110 | #endif |
---|
| 111 | { |
---|
| 112 | m_pcEntropyDecoder = pcEntropyDecoder; |
---|
| 113 | m_pcCuDecoder = pcCuDecoder; |
---|
| 114 | #if SVC_EXTENSION |
---|
| 115 | m_ppcTDecTop = ppcDecTop; |
---|
| 116 | #endif |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | Void TDecSlice::decompressSlice(TComInputBitstream* pcBitstream, TComInputBitstream** ppcSubstreams, TComPic*& rpcPic, TDecSbac* pcSbacDecoder, TDecSbac* pcSbacDecoders) |
---|
| 120 | { |
---|
| 121 | TComDataCU* pcCU; |
---|
| 122 | UInt uiIsLast = 0; |
---|
| 123 | Int iStartCUEncOrder = max(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU(), rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getDependentSliceCurStartCUAddr()/rpcPic->getNumPartInCU()); |
---|
| 124 | Int iStartCUAddr = rpcPic->getPicSym()->getCUOrderMap(iStartCUEncOrder); |
---|
| 125 | |
---|
| 126 | // decoder don't need prediction & residual frame buffer |
---|
| 127 | rpcPic->setPicYuvPred( 0 ); |
---|
| 128 | rpcPic->setPicYuvResi( 0 ); |
---|
| 129 | |
---|
| 130 | #if ENC_DEC_TRACE |
---|
| 131 | g_bJustDoIt = g_bEncDecTraceEnable; |
---|
| 132 | #endif |
---|
| 133 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
| 134 | DTRACE_CABAC_T( "\tPOC: " ); |
---|
| 135 | DTRACE_CABAC_V( rpcPic->getPOC() ); |
---|
| 136 | DTRACE_CABAC_T( "\n" ); |
---|
| 137 | |
---|
| 138 | #if ENC_DEC_TRACE |
---|
| 139 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
| 140 | #endif |
---|
| 141 | |
---|
| 142 | UInt uiTilesAcross = rpcPic->getPicSym()->getNumColumnsMinus1()+1; |
---|
| 143 | TComSlice* pcSlice = rpcPic->getSlice(rpcPic->getCurrSliceIdx()); |
---|
| 144 | Int iNumSubstreams = pcSlice->getPPS()->getNumSubstreams(); |
---|
| 145 | |
---|
| 146 | // delete decoders if already allocated in previous slice |
---|
| 147 | if (m_pcBufferSbacDecoders) |
---|
| 148 | { |
---|
| 149 | delete [] m_pcBufferSbacDecoders; |
---|
| 150 | } |
---|
| 151 | if (m_pcBufferBinCABACs) |
---|
| 152 | { |
---|
| 153 | delete [] m_pcBufferBinCABACs; |
---|
| 154 | } |
---|
| 155 | // allocate new decoders based on tile numbaer |
---|
| 156 | m_pcBufferSbacDecoders = new TDecSbac [uiTilesAcross]; |
---|
| 157 | m_pcBufferBinCABACs = new TDecBinCABAC[uiTilesAcross]; |
---|
| 158 | for (UInt ui = 0; ui < uiTilesAcross; ui++) |
---|
| 159 | { |
---|
| 160 | m_pcBufferSbacDecoders[ui].init(&m_pcBufferBinCABACs[ui]); |
---|
| 161 | } |
---|
| 162 | //save init. state |
---|
| 163 | for (UInt ui = 0; ui < uiTilesAcross; ui++) |
---|
| 164 | { |
---|
| 165 | m_pcBufferSbacDecoders[ui].load(pcSbacDecoder); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | // free memory if already allocated in previous call |
---|
| 169 | if (m_pcBufferLowLatSbacDecoders) |
---|
| 170 | { |
---|
| 171 | delete [] m_pcBufferLowLatSbacDecoders; |
---|
| 172 | } |
---|
| 173 | if (m_pcBufferLowLatBinCABACs) |
---|
| 174 | { |
---|
| 175 | delete [] m_pcBufferLowLatBinCABACs; |
---|
| 176 | } |
---|
| 177 | m_pcBufferLowLatSbacDecoders = new TDecSbac [uiTilesAcross]; |
---|
| 178 | m_pcBufferLowLatBinCABACs = new TDecBinCABAC[uiTilesAcross]; |
---|
| 179 | for (UInt ui = 0; ui < uiTilesAcross; ui++) |
---|
| 180 | { |
---|
| 181 | m_pcBufferLowLatSbacDecoders[ui].init(&m_pcBufferLowLatBinCABACs[ui]); |
---|
| 182 | } |
---|
| 183 | //save init. state |
---|
| 184 | for (UInt ui = 0; ui < uiTilesAcross; ui++) |
---|
| 185 | { |
---|
| 186 | m_pcBufferLowLatSbacDecoders[ui].load(pcSbacDecoder); |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | UInt uiWidthInLCUs = rpcPic->getPicSym()->getFrameWidthInCU(); |
---|
| 190 | //UInt uiHeightInLCUs = rpcPic->getPicSym()->getFrameHeightInCU(); |
---|
| 191 | UInt uiCol=0, uiLin=0, uiSubStrm=0; |
---|
| 192 | |
---|
| 193 | UInt uiTileCol; |
---|
| 194 | UInt uiTileStartLCU; |
---|
| 195 | UInt uiTileLCUX; |
---|
| 196 | UInt uiTileLCUY; |
---|
| 197 | UInt uiTileWidth; |
---|
| 198 | UInt uiTileHeight; |
---|
| 199 | Int iNumSubstreamsPerTile = 1; // if independent. |
---|
| 200 | |
---|
| 201 | #if INTRA_BL |
---|
| 202 | m_pcCuDecoder->setBaseRecPic( rpcPic->getLayerId() > 0 ? rpcPic->getFullPelBaseRec() : NULL); |
---|
| 203 | #endif |
---|
| 204 | #if DEPENDENT_SLICES |
---|
| 205 | Bool bAllowDependence = false; |
---|
| 206 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
| 207 | if( rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceEnabledFlag()&& (!rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getEntropySliceEnabledFlag()) ) |
---|
| 208 | #else |
---|
| 209 | if( rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceEnabledFlag()&& (!rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getCabacIndependentFlag()) ) |
---|
| 210 | #endif |
---|
| 211 | { |
---|
| 212 | bAllowDependence = true; |
---|
| 213 | } |
---|
| 214 | if( bAllowDependence ) |
---|
| 215 | { |
---|
| 216 | if( !rpcPic->getSlice(rpcPic->getCurrSliceIdx())->isNextSlice() ) |
---|
| 217 | { |
---|
| 218 | uiTileCol = 0; |
---|
| 219 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
| 220 | if(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) |
---|
| 221 | #else |
---|
| 222 | if(pcSlice->getPPS()->getTilesOrEntropyCodingSyncIdc()==2) |
---|
| 223 | #endif |
---|
| 224 | { |
---|
| 225 | m_pcBufferSbacDecoders[uiTileCol].loadContexts( CTXMem[1] );//2.LCU |
---|
| 226 | } |
---|
| 227 | pcSbacDecoder->loadContexts(CTXMem[0] ); //end of depSlice-1 |
---|
| 228 | pcSbacDecoders[uiSubStrm].loadContexts(pcSbacDecoder); |
---|
| 229 | } |
---|
| 230 | else |
---|
| 231 | { |
---|
| 232 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
| 233 | if(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) |
---|
| 234 | #else |
---|
| 235 | if(pcSlice->getPPS()->getTilesOrEntropyCodingSyncIdc()==2) |
---|
| 236 | #endif |
---|
| 237 | { |
---|
| 238 | CTXMem[1]->loadContexts(pcSbacDecoder); |
---|
| 239 | } |
---|
| 240 | CTXMem[0]->loadContexts(pcSbacDecoder); |
---|
| 241 | } |
---|
| 242 | } |
---|
| 243 | #endif |
---|
| 244 | for( Int iCUAddr = iStartCUAddr; !uiIsLast && iCUAddr < rpcPic->getNumCUsInFrame(); iCUAddr = rpcPic->getPicSym()->xCalculateNxtCUAddr(iCUAddr) ) |
---|
| 245 | { |
---|
| 246 | pcCU = rpcPic->getCU( iCUAddr ); |
---|
| 247 | pcCU->initCU( rpcPic, iCUAddr ); |
---|
| 248 | uiTileCol = rpcPic->getPicSym()->getTileIdxMap(iCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in? |
---|
| 249 | uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getFirstCUAddr(); |
---|
| 250 | uiTileLCUX = uiTileStartLCU % uiWidthInLCUs; |
---|
| 251 | uiTileLCUY = uiTileStartLCU / uiWidthInLCUs; |
---|
| 252 | uiTileWidth = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getTileWidth(); |
---|
| 253 | uiTileHeight = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getTileHeight(); |
---|
| 254 | uiCol = iCUAddr % uiWidthInLCUs; |
---|
| 255 | // The 'line' is now relative to the 1st line in the slice, not the 1st line in the picture. |
---|
| 256 | uiLin = (iCUAddr/uiWidthInLCUs)-(iStartCUAddr/uiWidthInLCUs); |
---|
| 257 | // inherit from TR if necessary, select substream to use. |
---|
| 258 | #if DEPENDENT_SLICES |
---|
| 259 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
| 260 | if( (pcSlice->getPPS()->getNumSubstreams() > 1) || ( bAllowDependence && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) )) |
---|
| 261 | #else |
---|
| 262 | if( (pcSlice->getPPS()->getNumSubstreams() > 1) || ( bAllowDependence && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getTilesOrEntropyCodingSyncIdc()==2) )) |
---|
| 263 | #endif |
---|
| 264 | #else |
---|
| 265 | if( pcSlice->getPPS()->getNumSubstreams() > 1 ) |
---|
| 266 | #endif |
---|
| 267 | { |
---|
| 268 | // independent tiles => substreams are "per tile". iNumSubstreams has already been multiplied. |
---|
| 269 | iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles(); |
---|
| 270 | uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(iCUAddr)*iNumSubstreamsPerTile |
---|
| 271 | + uiLin%iNumSubstreamsPerTile; |
---|
| 272 | m_pcEntropyDecoder->setBitstream( ppcSubstreams[uiSubStrm] ); |
---|
| 273 | // Synchronize cabac probabilities with upper-right LCU if it's available and we're at the start of a line. |
---|
| 274 | #if DEPENDENT_SLICES |
---|
| 275 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
| 276 | if (((pcSlice->getPPS()->getNumSubstreams() > 1) || bAllowDependence ) && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag())) |
---|
| 277 | #else |
---|
| 278 | if (((pcSlice->getPPS()->getNumSubstreams() > 1) || bAllowDependence ) && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getTilesOrEntropyCodingSyncIdc()==2)) |
---|
| 279 | #endif |
---|
| 280 | #else |
---|
| 281 | if (pcSlice->getPPS()->getNumSubstreams() > 1 && uiCol == uiTileLCUX) |
---|
| 282 | #endif |
---|
| 283 | { |
---|
| 284 | // We'll sync if the TR is available. |
---|
| 285 | TComDataCU *pcCUUp = pcCU->getCUAbove(); |
---|
| 286 | UInt uiWidthInCU = rpcPic->getFrameWidthInCU(); |
---|
| 287 | TComDataCU *pcCUTR = NULL; |
---|
| 288 | if ( pcCUUp && ((iCUAddr%uiWidthInCU+1) < uiWidthInCU) ) |
---|
| 289 | { |
---|
| 290 | pcCUTR = rpcPic->getCU( iCUAddr - uiWidthInCU + 1 ); |
---|
| 291 | } |
---|
| 292 | UInt uiMaxParts = 1<<(pcSlice->getSPS()->getMaxCUDepth()<<1); |
---|
| 293 | |
---|
| 294 | if ( (true/*bEnforceSliceRestriction*/ && |
---|
| 295 | ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) || |
---|
| 296 | ((pcCUTR->getSCUAddr()+uiMaxParts-1) < pcSlice->getSliceCurStartCUAddr()) || |
---|
| 297 | ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(iCUAddr))) |
---|
| 298 | ))|| |
---|
| 299 | (true/*bEnforceDependentSliceRestriction*/ && |
---|
| 300 | ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) || |
---|
| 301 | ((pcCUTR->getSCUAddr()+uiMaxParts-1) < pcSlice->getDependentSliceCurStartCUAddr()) || |
---|
| 302 | ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(iCUAddr))) |
---|
| 303 | )) |
---|
| 304 | ) |
---|
| 305 | { |
---|
| 306 | #if DEPENDENT_SLICES |
---|
| 307 | if( (iCUAddr!=0) && ((pcCUTR->getSCUAddr()+uiMaxParts-1) >= pcSlice->getSliceCurStartCUAddr()) && bAllowDependence) |
---|
| 308 | { |
---|
| 309 | pcSbacDecoders[uiSubStrm].loadContexts( &m_pcBufferSbacDecoders[uiTileCol] ); |
---|
| 310 | } |
---|
| 311 | #endif |
---|
| 312 | // TR not available. |
---|
| 313 | } |
---|
| 314 | else |
---|
| 315 | { |
---|
| 316 | // TR is available, we use it. |
---|
| 317 | pcSbacDecoders[uiSubStrm].loadContexts( &m_pcBufferSbacDecoders[uiTileCol] ); |
---|
| 318 | } |
---|
| 319 | } |
---|
| 320 | pcSbacDecoder->load(&pcSbacDecoders[uiSubStrm]); //this load is used to simplify the code (avoid to change all the call to pcSbacDecoders) |
---|
| 321 | } |
---|
| 322 | else if ( pcSlice->getPPS()->getNumSubstreams() <= 1 ) |
---|
| 323 | { |
---|
| 324 | // Set variables to appropriate values to avoid later code change. |
---|
| 325 | iNumSubstreamsPerTile = 1; |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | if ( (iCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getFirstCUAddr()) && // 1st in tile. |
---|
| 329 | (iCUAddr!=0) && (iCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceCurStartCUAddr())/rpcPic->getNumPartInCU()) |
---|
| 330 | #if DEPENDENT_SLICES |
---|
| 331 | && (iCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getDependentSliceCurStartCUAddr())/rpcPic->getNumPartInCU()) |
---|
| 332 | #endif |
---|
| 333 | ) // !1st in frame && !1st in slice |
---|
| 334 | { |
---|
| 335 | if (pcSlice->getPPS()->getNumSubstreams() > 1) |
---|
| 336 | { |
---|
| 337 | // We're crossing into another tile, tiles are independent. |
---|
| 338 | // When tiles are independent, we have "substreams per tile". Each substream has already been terminated, and we no longer |
---|
| 339 | // have to perform it here. |
---|
| 340 | // For TILES_DECODER, there can be a header at the start of the 1st substream in a tile. These are read when the substreams |
---|
| 341 | // are extracted, not here. |
---|
| 342 | } |
---|
| 343 | else |
---|
| 344 | { |
---|
| 345 | SliceType sliceType = pcSlice->getSliceType(); |
---|
| 346 | if (pcSlice->getCabacInitFlag()) |
---|
| 347 | { |
---|
| 348 | switch (sliceType) |
---|
| 349 | { |
---|
| 350 | case P_SLICE: // change initialization table to B_SLICE intialization |
---|
| 351 | sliceType = B_SLICE; |
---|
| 352 | break; |
---|
| 353 | case B_SLICE: // change initialization table to P_SLICE intialization |
---|
| 354 | sliceType = P_SLICE; |
---|
| 355 | break; |
---|
| 356 | default : // should not occur |
---|
| 357 | assert(0); |
---|
| 358 | } |
---|
| 359 | } |
---|
| 360 | m_pcEntropyDecoder->updateContextTables( sliceType, pcSlice->getSliceQp() ); |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | #if ENC_DEC_TRACE |
---|
| 366 | g_bJustDoIt = g_bEncDecTraceEnable; |
---|
| 367 | #endif |
---|
| 368 | #if !SAO_LUM_CHROMA_ONOFF_FLAGS |
---|
| 369 | if ( pcSlice->getSPS()->getUseSAO() && pcSlice->getSaoEnabledFlag() ) |
---|
| 370 | #else |
---|
| 371 | if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) ) |
---|
| 372 | #endif |
---|
| 373 | { |
---|
| 374 | #if REMOVE_APS |
---|
| 375 | SAOParam *saoParam = rpcPic->getPicSym()->getSaoParam(); |
---|
| 376 | #else |
---|
| 377 | SAOParam *saoParam = pcSlice->getAPS()->getSaoParam(); |
---|
| 378 | #endif |
---|
| 379 | saoParam->bSaoFlag[0] = pcSlice->getSaoEnabledFlag(); |
---|
| 380 | if (iCUAddr == iStartCUAddr) |
---|
| 381 | { |
---|
| 382 | #if SAO_TYPE_SHARING |
---|
| 383 | saoParam->bSaoFlag[1] = pcSlice->getSaoEnabledFlagChroma(); |
---|
| 384 | #else |
---|
| 385 | saoParam->bSaoFlag[1] = pcSlice->getSaoEnabledFlagCb(); |
---|
| 386 | saoParam->bSaoFlag[2] = pcSlice->getSaoEnabledFlagCr(); |
---|
| 387 | #endif |
---|
| 388 | } |
---|
| 389 | Int numCuInWidth = saoParam->numCuInWidth; |
---|
| 390 | Int cuAddrInSlice = iCUAddr - rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU()); |
---|
| 391 | Int cuAddrUpInSlice = cuAddrInSlice - numCuInWidth; |
---|
| 392 | Int rx = iCUAddr % numCuInWidth; |
---|
| 393 | Int ry = iCUAddr / numCuInWidth; |
---|
| 394 | Int allowMergeLeft = 1; |
---|
| 395 | Int allowMergeUp = 1; |
---|
| 396 | if (rx!=0) |
---|
| 397 | { |
---|
| 398 | if (rpcPic->getPicSym()->getTileIdxMap(iCUAddr-1) != rpcPic->getPicSym()->getTileIdxMap(iCUAddr)) |
---|
| 399 | { |
---|
| 400 | allowMergeLeft = 0; |
---|
| 401 | } |
---|
| 402 | } |
---|
| 403 | if (ry!=0) |
---|
| 404 | { |
---|
| 405 | if (rpcPic->getPicSym()->getTileIdxMap(iCUAddr-numCuInWidth) != rpcPic->getPicSym()->getTileIdxMap(iCUAddr)) |
---|
| 406 | { |
---|
| 407 | allowMergeUp = 0; |
---|
| 408 | } |
---|
| 409 | } |
---|
| 410 | pcSbacDecoder->parseSaoOneLcuInterleaving(rx, ry, saoParam,pcCU, cuAddrInSlice, cuAddrUpInSlice, allowMergeLeft, allowMergeUp); |
---|
| 411 | } |
---|
| 412 | #if !REMOVE_ALF |
---|
| 413 | if(pcSlice->getSPS()->getUseALF()) |
---|
| 414 | { |
---|
| 415 | UInt alfEnabledFlag; |
---|
| 416 | for(Int compIdx=0; compIdx< 3; compIdx++) |
---|
| 417 | { |
---|
| 418 | alfEnabledFlag = 0; |
---|
| 419 | if(pcSlice->getAlfEnabledFlag(compIdx)) |
---|
| 420 | { |
---|
| 421 | pcSbacDecoder->parseAlfCtrlFlag(compIdx, alfEnabledFlag); |
---|
| 422 | } |
---|
| 423 | pcCU->setAlfLCUEnabled((alfEnabledFlag==1)?true:false, compIdx); |
---|
| 424 | } |
---|
| 425 | } |
---|
| 426 | #endif |
---|
| 427 | m_pcCuDecoder->decodeCU ( pcCU, uiIsLast ); |
---|
| 428 | m_pcCuDecoder->decompressCU ( pcCU ); |
---|
| 429 | |
---|
| 430 | #if ENC_DEC_TRACE |
---|
| 431 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
| 432 | #endif |
---|
| 433 | /*If at the end of a LCU line but not at the end of a substream, perform CABAC flush*/ |
---|
| 434 | if (!uiIsLast && pcSlice->getPPS()->getNumSubstreams() > 1) |
---|
| 435 | { |
---|
| 436 | if ((uiCol == uiTileLCUX+uiTileWidth-1) && (uiLin+iNumSubstreamsPerTile < uiTileLCUY+uiTileHeight)) |
---|
| 437 | { |
---|
| 438 | m_pcEntropyDecoder->decodeFlush(); |
---|
| 439 | } |
---|
| 440 | } |
---|
| 441 | pcSbacDecoders[uiSubStrm].load(pcSbacDecoder); |
---|
| 442 | |
---|
| 443 | //Store probabilities of second LCU in line into buffer |
---|
| 444 | #if DEPENDENT_SLICES |
---|
| 445 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
| 446 | if ( (uiCol == uiTileLCUX+1)&& (bAllowDependence || (pcSlice->getPPS()->getNumSubstreams() > 1)) && (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) ) |
---|
| 447 | #else |
---|
| 448 | if ( (uiCol == uiTileLCUX+1)&& (bAllowDependence || (pcSlice->getPPS()->getNumSubstreams() > 1)) && (pcSlice->getPPS()->getTilesOrEntropyCodingSyncIdc() == 2)) |
---|
| 449 | #endif |
---|
| 450 | #else |
---|
| 451 | if (pcSlice->getPPS()->getNumSubstreams() > 1 && (uiCol == uiTileLCUX+1)) |
---|
| 452 | #endif |
---|
| 453 | { |
---|
| 454 | m_pcBufferSbacDecoders[uiTileCol].loadContexts( &pcSbacDecoders[uiSubStrm] ); |
---|
| 455 | } |
---|
| 456 | #if DEPENDENT_SLICES |
---|
| 457 | if( uiIsLast && bAllowDependence ) |
---|
| 458 | { |
---|
| 459 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
| 460 | if (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) |
---|
| 461 | #else |
---|
| 462 | if (pcSlice->getPPS()->getTilesOrEntropyCodingSyncIdc()==2) |
---|
| 463 | #endif |
---|
| 464 | { |
---|
| 465 | CTXMem[1]->loadContexts( &m_pcBufferSbacDecoders[uiTileCol] );//ctx 2.LCU |
---|
| 466 | } |
---|
| 467 | CTXMem[0]->loadContexts( pcSbacDecoder );//ctx end of dep.slice |
---|
| 468 | return; |
---|
| 469 | } |
---|
| 470 | #endif |
---|
| 471 | } |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | ParameterSetManagerDecoder::ParameterSetManagerDecoder() |
---|
| 475 | : m_vpsBuffer(MAX_NUM_VPS) |
---|
| 476 | ,m_spsBuffer(256) |
---|
| 477 | , m_ppsBuffer(16) |
---|
| 478 | #if !REMOVE_APS |
---|
| 479 | , m_apsBuffer(64) |
---|
| 480 | #endif |
---|
| 481 | { |
---|
| 482 | |
---|
| 483 | } |
---|
| 484 | |
---|
| 485 | ParameterSetManagerDecoder::~ParameterSetManagerDecoder() |
---|
| 486 | { |
---|
| 487 | |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | TComVPS* ParameterSetManagerDecoder::getPrefetchedVPS (Int vpsId) |
---|
| 491 | { |
---|
| 492 | if (m_vpsBuffer.getPS(vpsId) != NULL ) |
---|
| 493 | { |
---|
| 494 | return m_vpsBuffer.getPS(vpsId); |
---|
| 495 | } |
---|
| 496 | else |
---|
| 497 | { |
---|
| 498 | return getVPS(vpsId); |
---|
| 499 | } |
---|
| 500 | } |
---|
| 501 | |
---|
| 502 | |
---|
| 503 | TComSPS* ParameterSetManagerDecoder::getPrefetchedSPS (Int spsId) |
---|
| 504 | { |
---|
| 505 | if (m_spsBuffer.getPS(spsId) != NULL ) |
---|
| 506 | { |
---|
| 507 | return m_spsBuffer.getPS(spsId); |
---|
| 508 | } |
---|
| 509 | else |
---|
| 510 | { |
---|
| 511 | return getSPS(spsId); |
---|
| 512 | } |
---|
| 513 | } |
---|
| 514 | |
---|
| 515 | TComPPS* ParameterSetManagerDecoder::getPrefetchedPPS (Int ppsId) |
---|
| 516 | { |
---|
| 517 | if (m_ppsBuffer.getPS(ppsId) != NULL ) |
---|
| 518 | { |
---|
| 519 | return m_ppsBuffer.getPS(ppsId); |
---|
| 520 | } |
---|
| 521 | else |
---|
| 522 | { |
---|
| 523 | return getPPS(ppsId); |
---|
| 524 | } |
---|
| 525 | } |
---|
| 526 | |
---|
| 527 | #if !REMOVE_APS |
---|
| 528 | TComAPS* ParameterSetManagerDecoder::getPrefetchedAPS (Int apsId) |
---|
| 529 | { |
---|
| 530 | if (m_apsBuffer.getPS(apsId) != NULL ) |
---|
| 531 | { |
---|
| 532 | return m_apsBuffer.getPS(apsId); |
---|
| 533 | } |
---|
| 534 | else |
---|
| 535 | { |
---|
| 536 | return getAPS(apsId); |
---|
| 537 | } |
---|
| 538 | } |
---|
| 539 | #endif |
---|
| 540 | |
---|
| 541 | Void ParameterSetManagerDecoder::applyPrefetchedPS() |
---|
| 542 | { |
---|
| 543 | m_vpsMap.mergePSList(m_vpsBuffer); |
---|
| 544 | #if !REMOVE_APS |
---|
| 545 | m_apsMap.mergePSList(m_apsBuffer); |
---|
| 546 | #endif |
---|
| 547 | m_ppsMap.mergePSList(m_ppsBuffer); |
---|
| 548 | m_spsMap.mergePSList(m_spsBuffer); |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | //! \} |
---|