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