[5] | 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 |
---|
[1313] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[1313] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[5] | 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. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 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 | */ |
---|
[2] | 33 | |
---|
| 34 | /** \file TDecSlice.cpp |
---|
| 35 | \brief slice decoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TDecSlice.h" |
---|
| 39 | |
---|
[56] | 40 | //! \ingroup TLibDecoder |
---|
| 41 | //! \{ |
---|
| 42 | |
---|
[2] | 43 | ////////////////////////////////////////////////////////////////////// |
---|
| 44 | // Construction/Destruction |
---|
| 45 | ////////////////////////////////////////////////////////////////////// |
---|
| 46 | |
---|
| 47 | TDecSlice::TDecSlice() |
---|
| 48 | { |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | TDecSlice::~TDecSlice() |
---|
| 52 | { |
---|
| 53 | } |
---|
| 54 | |
---|
[608] | 55 | Void TDecSlice::create() |
---|
[2] | 56 | { |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | Void TDecSlice::destroy() |
---|
| 60 | { |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | Void TDecSlice::init(TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder) |
---|
| 64 | { |
---|
| 65 | m_pcEntropyDecoder = pcEntropyDecoder; |
---|
| 66 | m_pcCuDecoder = pcCuDecoder; |
---|
| 67 | } |
---|
| 68 | |
---|
[1313] | 69 | Void TDecSlice::decompressSlice(TComInputBitstream** ppcSubstreams, TComPic* pcPic, TDecSbac* pcSbacDecoder) |
---|
[2] | 70 | { |
---|
[1313] | 71 | TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx()); |
---|
[2] | 72 | |
---|
[1313] | 73 | const Int startCtuTsAddr = pcSlice->getSliceSegmentCurStartCtuTsAddr(); |
---|
| 74 | const Int startCtuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(startCtuTsAddr); |
---|
| 75 | const UInt numCtusInFrame = pcPic->getNumberOfCtusInFrame(); |
---|
| 76 | |
---|
| 77 | const UInt frameWidthInCtus = pcPic->getPicSym()->getFrameWidthInCtus(); |
---|
| 78 | const Bool depSliceSegmentsEnabled = pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag(); |
---|
| 79 | const Bool wavefrontsEnabled = pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag(); |
---|
| 80 | |
---|
| 81 | m_pcEntropyDecoder->setEntropyDecoder ( pcSbacDecoder ); |
---|
| 82 | m_pcEntropyDecoder->setBitstream ( ppcSubstreams[0] ); |
---|
| 83 | m_pcEntropyDecoder->resetEntropy (pcSlice); |
---|
| 84 | |
---|
| 85 | // decoder doesn't need prediction & residual frame buffer |
---|
| 86 | pcPic->setPicYuvPred( 0 ); |
---|
| 87 | pcPic->setPicYuvResi( 0 ); |
---|
| 88 | |
---|
[2] | 89 | #if ENC_DEC_TRACE |
---|
| 90 | g_bJustDoIt = g_bEncDecTraceEnable; |
---|
| 91 | #endif |
---|
[1313] | 92 | #if H_MV_ENC_DEC_TRAC |
---|
| 93 | #if ENC_DEC_TRACE |
---|
| 94 | incSymbolCounter(); |
---|
| 95 | #endif |
---|
| 96 | DTRACE_CABAC_VL( g_nSymbolCounter ); |
---|
| 97 | #else |
---|
[56] | 98 | DTRACE_CABAC_VL( g_nSymbolCounter++ ); |
---|
[1313] | 99 | #endif |
---|
[2] | 100 | DTRACE_CABAC_T( "\tPOC: " ); |
---|
[1313] | 101 | DTRACE_CABAC_V( pcPic->getPOC() ); |
---|
[608] | 102 | #if H_MV_ENC_DEC_TRAC |
---|
| 103 | DTRACE_CABAC_T( " Layer: " ); |
---|
[1313] | 104 | DTRACE_CABAC_V( pcPic->getLayerId() ); |
---|
[608] | 105 | #endif |
---|
[2] | 106 | DTRACE_CABAC_T( "\n" ); |
---|
| 107 | |
---|
| 108 | #if ENC_DEC_TRACE |
---|
| 109 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
| 110 | #endif |
---|
| 111 | |
---|
[1313] | 112 | // The first CTU of the slice is the first coded substream, but the global substream number, as calculated by getSubstreamForCtuAddr may be higher. |
---|
| 113 | // This calculates the common offset for all substreams in this slice. |
---|
| 114 | const UInt subStreamOffset=pcPic->getSubstreamForCtuAddr(startCtuRsAddr, true, pcSlice); |
---|
[56] | 115 | |
---|
| 116 | |
---|
[1313] | 117 | if (depSliceSegmentsEnabled) |
---|
[608] | 118 | { |
---|
[1313] | 119 | // modify initial contexts with previous slice segment if this is a dependent slice. |
---|
| 120 | const UInt startTileIdx=pcPic->getPicSym()->getTileIdxMap(startCtuRsAddr); |
---|
| 121 | const TComTile *pCurrentTile=pcPic->getPicSym()->getTComTile(startTileIdx); |
---|
| 122 | const UInt firstCtuRsAddrOfTile = pCurrentTile->getFirstCtuRsAddr(); |
---|
[608] | 123 | |
---|
[1313] | 124 | if( pcSlice->getDependentSliceSegmentFlag() && startCtuRsAddr != firstCtuRsAddrOfTile) |
---|
[608] | 125 | { |
---|
[1313] | 126 | if ( pCurrentTile->getTileWidthInCtus() >= 2 || !wavefrontsEnabled) |
---|
[608] | 127 | { |
---|
[1313] | 128 | pcSbacDecoder->loadContexts(&m_lastSliceSegmentEndContextState); |
---|
[608] | 129 | } |
---|
| 130 | } |
---|
| 131 | } |
---|
[1313] | 132 | #if NH_3D_DLT |
---|
[950] | 133 | if( pcSlice->getPPS()->getDLT() != NULL ) |
---|
| 134 | { |
---|
[1313] | 135 | assert( pcSlice->getSPS()->getBitDepth( CHANNEL_TYPE_LUMA ) == pcSlice->getPPS()->getDLT()->getDepthViewBitDepth() ); |
---|
[950] | 136 | } |
---|
| 137 | #endif |
---|
[1313] | 138 | |
---|
| 139 | // for every CTU in the slice segment... |
---|
| 140 | |
---|
| 141 | Bool isLastCtuOfSliceSegment = false; |
---|
| 142 | for( UInt ctuTsAddr = startCtuTsAddr; !isLastCtuOfSliceSegment && ctuTsAddr < numCtusInFrame; ctuTsAddr++) |
---|
[56] | 143 | { |
---|
[1313] | 144 | const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddr); |
---|
| 145 | const TComTile ¤tTile = *(pcPic->getPicSym()->getTComTile(pcPic->getPicSym()->getTileIdxMap(ctuRsAddr))); |
---|
| 146 | const UInt firstCtuRsAddrOfTile = currentTile.getFirstCtuRsAddr(); |
---|
| 147 | const UInt tileXPosInCtus = firstCtuRsAddrOfTile % frameWidthInCtus; |
---|
| 148 | const UInt tileYPosInCtus = firstCtuRsAddrOfTile / frameWidthInCtus; |
---|
| 149 | const UInt ctuXPosInCtus = ctuRsAddr % frameWidthInCtus; |
---|
| 150 | const UInt ctuYPosInCtus = ctuRsAddr / frameWidthInCtus; |
---|
| 151 | const UInt uiSubStrm=pcPic->getSubstreamForCtuAddr(ctuRsAddr, true, pcSlice)-subStreamOffset; |
---|
| 152 | TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr ); |
---|
| 153 | pCtu->initCtu( pcPic, ctuRsAddr ); |
---|
| 154 | |
---|
| 155 | m_pcEntropyDecoder->setBitstream( ppcSubstreams[uiSubStrm] ); |
---|
| 156 | |
---|
| 157 | // set up CABAC contexts' state for this CTU |
---|
| 158 | if (ctuRsAddr == firstCtuRsAddrOfTile) |
---|
[56] | 159 | { |
---|
[1313] | 160 | if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset |
---|
[56] | 161 | { |
---|
[1313] | 162 | m_pcEntropyDecoder->resetEntropy(pcSlice); |
---|
[56] | 163 | } |
---|
| 164 | } |
---|
[1313] | 165 | else if (ctuXPosInCtus == tileXPosInCtus && wavefrontsEnabled) |
---|
[56] | 166 | { |
---|
[1313] | 167 | // Synchronize cabac probabilities with upper-right CTU if it's available and at the start of a line. |
---|
| 168 | if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset |
---|
[56] | 169 | { |
---|
[1313] | 170 | m_pcEntropyDecoder->resetEntropy(pcSlice); |
---|
[56] | 171 | } |
---|
[1313] | 172 | TComDataCU *pCtuUp = pCtu->getCtuAbove(); |
---|
| 173 | if ( pCtuUp && ((ctuRsAddr%frameWidthInCtus+1) < frameWidthInCtus) ) |
---|
[56] | 174 | { |
---|
[1313] | 175 | TComDataCU *pCtuTR = pcPic->getCtu( ctuRsAddr - frameWidthInCtus + 1 ); |
---|
| 176 | if ( pCtu->CUIsFromSameSliceAndTile(pCtuTR) ) |
---|
[56] | 177 | { |
---|
[1313] | 178 | // Top-right is available, so use it. |
---|
| 179 | pcSbacDecoder->loadContexts( &m_entropyCodingSyncContextState ); |
---|
[56] | 180 | } |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | |
---|
[2] | 184 | #if ENC_DEC_TRACE |
---|
| 185 | g_bJustDoIt = g_bEncDecTraceEnable; |
---|
| 186 | #endif |
---|
[872] | 187 | |
---|
| 188 | if ( pcSlice->getSPS()->getUseSAO() ) |
---|
[1313] | 189 | { |
---|
| 190 | SAOBlkParam& saoblkParam = (pcPic->getPicSym()->getSAOBlkParam())[ctuRsAddr]; |
---|
| 191 | Bool bIsSAOSliceEnabled = false; |
---|
| 192 | Bool sliceEnabled[MAX_NUM_COMPONENT]; |
---|
| 193 | for(Int comp=0; comp < MAX_NUM_COMPONENT; comp++) |
---|
[608] | 194 | { |
---|
[1313] | 195 | ComponentID compId=ComponentID(comp); |
---|
| 196 | sliceEnabled[compId] = pcSlice->getSaoEnabledFlag(toChannelType(compId)) && (comp < pcPic->getNumberValidComponents()); |
---|
| 197 | if (sliceEnabled[compId]) |
---|
| 198 | { |
---|
| 199 | bIsSAOSliceEnabled=true; |
---|
| 200 | } |
---|
| 201 | saoblkParam[compId].modeIdc = SAO_MODE_OFF; |
---|
| 202 | } |
---|
| 203 | if (bIsSAOSliceEnabled) |
---|
[608] | 204 | { |
---|
[872] | 205 | Bool leftMergeAvail = false; |
---|
| 206 | Bool aboveMergeAvail= false; |
---|
| 207 | |
---|
| 208 | //merge left condition |
---|
[1313] | 209 | Int rx = (ctuRsAddr % frameWidthInCtus); |
---|
[872] | 210 | if(rx > 0) |
---|
[443] | 211 | { |
---|
[1313] | 212 | leftMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-1); |
---|
[443] | 213 | } |
---|
[872] | 214 | //merge up condition |
---|
[1313] | 215 | Int ry = (ctuRsAddr / frameWidthInCtus); |
---|
[872] | 216 | if(ry > 0) |
---|
[443] | 217 | { |
---|
[1313] | 218 | aboveMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-frameWidthInCtus); |
---|
| 219 | } |
---|
[872] | 220 | |
---|
[1313] | 221 | pcSbacDecoder->parseSAOBlkParam( saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail, pcSlice->getSPS()->getBitDepths()); |
---|
[56] | 222 | } |
---|
| 223 | } |
---|
[1313] | 224 | |
---|
| 225 | m_pcCuDecoder->decodeCtu ( pCtu, isLastCtuOfSliceSegment ); |
---|
| 226 | m_pcCuDecoder->decompressCtu ( pCtu ); |
---|
| 227 | |
---|
[2] | 228 | #if ENC_DEC_TRACE |
---|
| 229 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
| 230 | #endif |
---|
[608] | 231 | |
---|
[1313] | 232 | //Store probabilities of second CTU in line into buffer |
---|
| 233 | if ( ctuXPosInCtus == tileXPosInCtus+1 && wavefrontsEnabled) |
---|
[56] | 234 | { |
---|
[1313] | 235 | m_entropyCodingSyncContextState.loadContexts( pcSbacDecoder ); |
---|
[608] | 236 | } |
---|
[56] | 237 | |
---|
[1313] | 238 | if (isLastCtuOfSliceSegment) |
---|
[608] | 239 | { |
---|
[1313] | 240 | #if DECODER_CHECK_SUBSTREAM_AND_SLICE_TRAILING_BYTES |
---|
| 241 | pcSbacDecoder->parseRemainingBytes(false); |
---|
| 242 | #endif |
---|
| 243 | if(!pcSlice->getDependentSliceSegmentFlag()) |
---|
| 244 | { |
---|
| 245 | pcSlice->setSliceCurEndCtuTsAddr( ctuTsAddr+1 ); |
---|
| 246 | } |
---|
| 247 | pcSlice->setSliceSegmentCurEndCtuTsAddr( ctuTsAddr+1 ); |
---|
[56] | 248 | } |
---|
[1313] | 249 | else if ( ctuXPosInCtus + 1 == tileXPosInCtus + currentTile.getTileWidthInCtus() && |
---|
| 250 | ( ctuYPosInCtus + 1 == tileYPosInCtus + currentTile.getTileHeightInCtus() || wavefrontsEnabled) |
---|
| 251 | ) |
---|
[608] | 252 | { |
---|
[1313] | 253 | // The sub-stream/stream should be terminated after this CTU. |
---|
| 254 | // (end of slice-segment, end of tile, end of wavefront-CTU-row) |
---|
| 255 | UInt binVal; |
---|
| 256 | pcSbacDecoder->parseTerminatingBit( binVal ); |
---|
| 257 | assert( binVal ); |
---|
| 258 | #if DECODER_CHECK_SUBSTREAM_AND_SLICE_TRAILING_BYTES |
---|
| 259 | pcSbacDecoder->parseRemainingBytes(true); |
---|
| 260 | #endif |
---|
[608] | 261 | } |
---|
[2] | 262 | |
---|
[77] | 263 | } |
---|
| 264 | |
---|
[1313] | 265 | assert(isLastCtuOfSliceSegment == true); |
---|
[608] | 266 | |
---|
[56] | 267 | |
---|
[1313] | 268 | if( depSliceSegmentsEnabled ) |
---|
[56] | 269 | { |
---|
[1313] | 270 | m_lastSliceSegmentEndContextState.loadContexts( pcSbacDecoder );//ctx end of dep.slice |
---|
[56] | 271 | } |
---|
| 272 | |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | //! \} |
---|