HEVC Test Model (HM)  HM-16.3
TDecSlice.cpp
Go to the documentation of this file.
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-2015, 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 
38 #include "TDecSlice.h"
39 
42 
44 // Construction/Destruction
46 
48 {
49 }
50 
52 {
53 }
54 
56 {
57 }
58 
60 {
61 }
62 
63 Void TDecSlice::init(TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder)
64 {
65  m_pcEntropyDecoder = pcEntropyDecoder;
66  m_pcCuDecoder = pcCuDecoder;
67 }
68 
69 Void TDecSlice::decompressSlice(TComInputBitstream** ppcSubstreams, TComPic* pcPic, TDecSbac* pcSbacDecoder)
70 {
71  TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
72 
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] );
84 
85  // decoder doesn't need prediction & residual frame buffer
86  pcPic->setPicYuvPred( 0 );
87  pcPic->setPicYuvResi( 0 );
88 
89 #if ENC_DEC_TRACE
91 #endif
93  DTRACE_CABAC_T( "\tPOC: " );
94  DTRACE_CABAC_V( pcPic->getPOC() );
95  DTRACE_CABAC_T( "\n" );
96 
97 #if ENC_DEC_TRACE
99 #endif
100 
101  // The first CTU of the slice is the first coded substream, but the global substream number, as calculated by getSubstreamForCtuAddr may be higher.
102  // This calculates the common offset for all substreams in this slice.
103  const UInt subStreamOffset=pcPic->getSubstreamForCtuAddr(startCtuRsAddr, true, pcSlice);
104 
105 
106  if (depSliceSegmentsEnabled)
107  {
108  // modify initial contexts with previous slice segment if this is a dependent slice.
109  const UInt startTileIdx=pcPic->getPicSym()->getTileIdxMap(startCtuRsAddr);
110  const TComTile *pCurrentTile=pcPic->getPicSym()->getTComTile(startTileIdx);
111  const UInt firstCtuRsAddrOfTile = pCurrentTile->getFirstCtuRsAddr();
112 
113  if( pcSlice->getDependentSliceSegmentFlag() && startCtuRsAddr != firstCtuRsAddrOfTile)
114  {
115  if ( pCurrentTile->getTileWidthInCtus() >= 2 || !wavefrontsEnabled)
116  {
118  }
119  }
120  }
121 
122  // for every CTU in the slice segment...
123 
124  Bool isLastCtuOfSliceSegment = false;
125  for( UInt ctuTsAddr = startCtuTsAddr; !isLastCtuOfSliceSegment && ctuTsAddr < numCtusInFrame; ctuTsAddr++)
126  {
127  const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddr);
128  const TComTile &currentTile = *(pcPic->getPicSym()->getTComTile(pcPic->getPicSym()->getTileIdxMap(ctuRsAddr)));
129  const UInt firstCtuRsAddrOfTile = currentTile.getFirstCtuRsAddr();
130  const UInt tileXPosInCtus = firstCtuRsAddrOfTile % frameWidthInCtus;
131  const UInt tileYPosInCtus = firstCtuRsAddrOfTile / frameWidthInCtus;
132  const UInt ctuXPosInCtus = ctuRsAddr % frameWidthInCtus;
133  const UInt ctuYPosInCtus = ctuRsAddr / frameWidthInCtus;
134  const UInt uiSubStrm=pcPic->getSubstreamForCtuAddr(ctuRsAddr, true, pcSlice)-subStreamOffset;
135  TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr );
136  pCtu->initCtu( pcPic, ctuRsAddr );
137 
138  m_pcEntropyDecoder->setBitstream( ppcSubstreams[uiSubStrm] );
139 
140  // set up CABAC contexts' state for this CTU
141  if (ctuRsAddr == firstCtuRsAddrOfTile)
142  {
143  if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
144  {
146  }
147  }
148  else if (ctuXPosInCtus == tileXPosInCtus && wavefrontsEnabled)
149  {
150  // Synchronize cabac probabilities with upper-right CTU if it's available and at the start of a line.
151  if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
152  {
154  }
155  TComDataCU *pCtuUp = pCtu->getCtuAbove();
156  if ( pCtuUp && ((ctuRsAddr%frameWidthInCtus+1) < frameWidthInCtus) )
157  {
158  TComDataCU *pCtuTR = pcPic->getCtu( ctuRsAddr - frameWidthInCtus + 1 );
159  if ( pCtu->CUIsFromSameSliceAndTile(pCtuTR) )
160  {
161  // Top-right is available, so use it.
163  }
164  }
165  }
166 
167 #if ENC_DEC_TRACE
169 #endif
170 
171  if ( pcSlice->getSPS()->getUseSAO() )
172  {
173  SAOBlkParam& saoblkParam = (pcPic->getPicSym()->getSAOBlkParam())[ctuRsAddr];
174  Bool bIsSAOSliceEnabled = false;
175  Bool sliceEnabled[MAX_NUM_COMPONENT];
176  for(Int comp=0; comp < MAX_NUM_COMPONENT; comp++)
177  {
178  ComponentID compId=ComponentID(comp);
179  sliceEnabled[compId] = pcSlice->getSaoEnabledFlag(toChannelType(compId)) && (comp < pcPic->getNumberValidComponents());
180  if (sliceEnabled[compId])
181  {
182  bIsSAOSliceEnabled=true;
183  }
184  saoblkParam[compId].modeIdc = SAO_MODE_OFF;
185  }
186  if (bIsSAOSliceEnabled)
187  {
188  Bool leftMergeAvail = false;
189  Bool aboveMergeAvail= false;
190 
191  //merge left condition
192  Int rx = (ctuRsAddr % frameWidthInCtus);
193  if(rx > 0)
194  {
195  leftMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-1);
196  }
197  //merge up condition
198  Int ry = (ctuRsAddr / frameWidthInCtus);
199  if(ry > 0)
200  {
201  aboveMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-frameWidthInCtus);
202  }
203 
204  pcSbacDecoder->parseSAOBlkParam( saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail);
205  }
206  }
207 
208  m_pcCuDecoder->decodeCtu ( pCtu, isLastCtuOfSliceSegment );
209  m_pcCuDecoder->decompressCtu ( pCtu );
210 
211 #if ENC_DEC_TRACE
213 #endif
214 
215  //Store probabilities of second CTU in line into buffer
216  if ( ctuXPosInCtus == tileXPosInCtus+1 && wavefrontsEnabled)
217  {
219  }
220 
221  if (isLastCtuOfSliceSegment)
222  {
223 #if DECODER_CHECK_SUBSTREAM_AND_SLICE_TRAILING_BYTES
224  pcSbacDecoder->parseRemainingBytes(false);
225 #endif
226  if(!pcSlice->getDependentSliceSegmentFlag())
227  {
228  pcSlice->setSliceCurEndCtuTsAddr( ctuTsAddr+1 );
229  }
230  pcSlice->setSliceSegmentCurEndCtuTsAddr( ctuTsAddr+1 );
231  }
232  else if ( ctuXPosInCtus + 1 == tileXPosInCtus + currentTile.getTileWidthInCtus() &&
233  ( ctuYPosInCtus + 1 == tileYPosInCtus + currentTile.getTileHeightInCtus() || wavefrontsEnabled)
234  )
235  {
236  // The sub-stream/stream should be terminated after this CTU.
237  // (end of slice-segment, end of tile, end of wavefront-CTU-row)
238  UInt binVal;
239  pcSbacDecoder->parseTerminatingBit( binVal );
240  assert( binVal );
241 #if DECODER_CHECK_SUBSTREAM_AND_SLICE_TRAILING_BYTES
242  pcSbacDecoder->parseRemainingBytes(true);
243 #endif
244  }
245 
246  }
247 
248  assert(isLastCtuOfSliceSegment == true);
249 
250 
251  if( depSliceSegmentsEnabled )
252  {
253  m_lastSliceSegmentEndContextState.loadContexts( pcSbacDecoder );//ctx end of dep.slice
254  }
255 
256 }
257 
Void setSliceSegmentCurEndCtuTsAddr(UInt ctuTsAddr)
Definition: TComSlice.h:1479
Void loadContexts(const TDecSbac *pSrc)
Definition: TDecSbac.cpp:1847
Void decodeCtu(TComDataCU *pCtu, Bool &isLastCtuOfSliceSegment)
decode Ctu information
Definition: TDecCu.cpp:128
UInt getFirstCtuRsAddr() const
Definition: TComPicSym.h:79
UInt getCtuTsToRsAddrMap(Int ctuTsAddr) const
Definition: TComPicSym.h:150
Void parseTerminatingBit(UInt &ruiBit)
Definition: TDecSbac.cpp:171
CU data structure class.
Definition: TComDataCU.h:64
Void decompressSlice(TComInputBitstream **ppcSubstreams, TComPic *pcPic, TDecSbac *pcSbacDecoder)
Definition: TDecSlice.cpp:69
Void setPicYuvResi(TComPicYuv *pcPicYuv)
Definition: TComPic.h:114
UInt getNumberOfCtusInFrame() const
Definition: TComPic.h:116
picture class (symbol + YUV buffers)
Definition: TComPic.h:56
void Void
Definition: TypeDef.h:285
TDecEntropy * m_pcEntropyDecoder
Definition: TDecSlice.h:65
TComSlice * getSlice(Int i)
Definition: TComPic.h:103
Void setPicYuvPred(TComPicYuv *pcPicYuv)
Definition: TComPic.h:113
unsigned int UInt
Definition: TypeDef.h:297
Bool getUseSAO() const
Definition: TComSlice.h:893
Void initCtu(TComPic *pcPic, UInt ctuRsAddr)
Definition: TComDataCU.cpp:448
Void destroy()
Definition: TDecSlice.cpp:59
Int getNumberValidComponents() const
Definition: TComPic.h:129
UInt64 g_nSymbolCounter
Definition: TComRom.cpp:566
Void setBitstream(TComInputBitstream *p)
Definition: TDecEntropy.h:134
Bool getSaoEnabledFlag(ChannelType chType) const
Definition: TComSlice.h:1322
UInt getFrameWidthInCtus() const
Definition: TComPicSym.h:128
SBAC decoder class.
Definition: TDecSbac.h:63
Void resetEntropy(TComSlice *p)
Definition: TDecEntropy.h:135
Void setEntropyDecoder(TDecEntropyIf *p)
Definition: TDecEntropy.cpp:52
Bool getDependentSliceSegmentFlag() const
Definition: TComSlice.h:1340
UInt getTileWidthInCtus() const
Definition: TComPicSym.h:71
const Bool g_bEncDecTraceEnable
Definition: TComRom.cpp:562
#define DTRACE_CABAC_T(x)
Definition: TComRom.h:197
UInt getTileIdxMap(Int ctuRsAddr) const
Definition: TComPicSym.h:151
Void parseSAOBlkParam(SAOBlkParam &saoBlkParam, Bool *sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail)
Definition: TDecSbac.cpp:1683
Bool getSAOMergeAvailability(Int currAddr, Int mergeAddr)
Definition: TComPic.cpp:118
bool Bool
Definition: TypeDef.h:286
UInt getSubstreamForCtuAddr(const UInt ctuAddr, const Bool bAddressInRaster, TComSlice *pcSlice)
Definition: TComPic.cpp:125
CU decoder class.
Definition: TDecCu.h:56
Void create()
Definition: TDecSlice.cpp:55
Bool g_bJustDoIt
Definition: TComRom.cpp:565
static ChannelType toChannelType(const ComponentID id)
Void setSliceCurEndCtuTsAddr(UInt ctuTsAddr)
Definition: TComSlice.h:1468
TComPicSym * getPicSym()
Definition: TComPic.h:102
UInt getSliceSegmentCurStartCtuTsAddr() const
Definition: TComSlice.h:1478
virtual ~TDecSlice()
Definition: TDecSlice.cpp:51
const TComPPS * getPPS() const
Definition: TComSlice.h:1309
Bool CUIsFromSameSliceAndTile(const TComDataCU *pCU) const
Definition: TComDataCU.cpp:403
#define DTRACE_CABAC_V(x)
Definition: TComRom.h:195
Void init(TDecEntropy *pcEntropyDecoder, TDecCu *pcMbDecoder)
Definition: TDecSlice.cpp:63
entropy decoder class
Definition: TDecEntropy.h:116
TDecCu * m_pcCuDecoder
Definition: TDecSlice.h:66
UInt getCurrSliceIdx() const
Definition: TComPic.h:137
UInt getTileHeightInCtus() const
Definition: TComPicSym.h:73
Bool getEntropyCodingSyncEnabledFlag() const
Definition: TComSlice.h:1127
Int getPOC() const
Definition: TComPic.h:104
TComDataCU * getCtu(UInt ctuRsAddr)
Definition: TComPic.h:105
#define DTRACE_CABAC_VL(x)
Definition: TComRom.h:196
TDecSbac m_lastSliceSegmentEndContextState
context storage for state at the end of the previous slice-segment (used for dependent slices only)...
Definition: TDecSlice.h:68
TComDataCU * getCtuAbove()
Definition: TComDataCU.h:396
Bool getDependentSliceSegmentsEnabledFlag() const
Definition: TComSlice.h:1125
slice decoder class (header)
TComTile * getTComTile(UInt tileIdx)
Definition: TComPicSym.h:148
Void parseRemainingBytes(Bool noTrailingBytesExpected)
Definition: TDecSbac.cpp:186
int Int
Definition: TypeDef.h:296
TDecSbac m_entropyCodingSyncContextState
context storate for state of contexts at the wavefront/WPP/entropy-coding-sync second CTU of tile-row...
Definition: TDecSlice.h:69
ComponentID
Definition: TypeDef.h:368
const Bool g_bEncDecTraceDisable
Definition: TComRom.cpp:563
Void decompressCtu(TComDataCU *pCtu)
reconstruct Ctu information
Definition: TDecCu.cpp:148
slice header class
Definition: TComSlice.h:1198
const TComSPS * getSPS() const
Definition: TComSlice.h:1306
SAOBlkParam * getSAOBlkParam()
Definition: TComPicSym.h:153