HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2017, 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 #include "TDecConformance.h"
40 
43 
45 // Construction/Destruction
47 
49 {
50 }
51 
53 {
54 }
55 
57 {
58 }
59 
61 {
62 }
63 
64 Void TDecSlice::init(TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder, TDecConformanceCheck *pDecConformanceCheck)
65 {
66  m_pcEntropyDecoder = pcEntropyDecoder;
67  m_pcCuDecoder = pcCuDecoder;
68  m_pDecConformanceCheck = pDecConformanceCheck;
69 }
70 
71 Void TDecSlice::decompressSlice(TComInputBitstream** ppcSubstreams, TComPic* pcPic, TDecSbac* pcSbacDecoder)
72 {
73  TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
74 
75  const Int startCtuTsAddr = pcSlice->getSliceSegmentCurStartCtuTsAddr();
76  const Int startCtuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(startCtuTsAddr);
77  const UInt numCtusInFrame = pcPic->getNumberOfCtusInFrame();
78 
79  const UInt frameWidthInCtus = pcPic->getPicSym()->getFrameWidthInCtus();
80  const Bool depSliceSegmentsEnabled = pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag();
81  const Bool wavefrontsEnabled = pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag();
82 
83  m_pcEntropyDecoder->setEntropyDecoder ( pcSbacDecoder );
84  m_pcEntropyDecoder->setBitstream ( ppcSubstreams[0] );
86 
87  // decoder doesn't need prediction & residual frame buffer
88  pcPic->setPicYuvPred( 0 );
89  pcPic->setPicYuvResi( 0 );
90 
91 #if ENC_DEC_TRACE
92  g_bJustDoIt = g_bEncDecTraceEnable;
93 #endif
94  DTRACE_CABAC_VL( g_nSymbolCounter++ );
95  DTRACE_CABAC_T( "\tPOC: " );
96  DTRACE_CABAC_V( pcPic->getPOC() );
97  DTRACE_CABAC_T( "\n" );
98 
99 #if ENC_DEC_TRACE
100  g_bJustDoIt = g_bEncDecTraceDisable;
101 #endif
102 
103  // The first CTU of the slice is the first coded substream, but the global substream number, as calculated by getSubstreamForCtuAddr may be higher.
104  // This calculates the common offset for all substreams in this slice.
105  const UInt subStreamOffset=pcPic->getSubstreamForCtuAddr(startCtuRsAddr, true, pcSlice);
106 
107 
108  if (depSliceSegmentsEnabled)
109  {
110  // modify initial contexts with previous slice segment if this is a dependent slice.
111  const UInt startTileIdx=pcPic->getPicSym()->getTileIdxMap(startCtuRsAddr);
112  const TComTile *pCurrentTile=pcPic->getPicSym()->getTComTile(startTileIdx);
113  const UInt firstCtuRsAddrOfTile = pCurrentTile->getFirstCtuRsAddr();
114 
115  if( pcSlice->getDependentSliceSegmentFlag() && startCtuRsAddr != firstCtuRsAddrOfTile)
116  {
117  if ( pCurrentTile->getTileWidthInCtus() >= 2 || !wavefrontsEnabled)
118  {
120  }
121  }
122  }
123 
124  // for every CTU in the slice segment...
125 
126  Bool isLastCtuOfSliceSegment = false;
127  for( UInt ctuTsAddr = startCtuTsAddr; !isLastCtuOfSliceSegment && ctuTsAddr < numCtusInFrame; ctuTsAddr++)
128  {
129  const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddr);
130  const TComTile &currentTile = *(pcPic->getPicSym()->getTComTile(pcPic->getPicSym()->getTileIdxMap(ctuRsAddr)));
131  const UInt firstCtuRsAddrOfTile = currentTile.getFirstCtuRsAddr();
132  const UInt tileXPosInCtus = firstCtuRsAddrOfTile % frameWidthInCtus;
133  const UInt tileYPosInCtus = firstCtuRsAddrOfTile / frameWidthInCtus;
134  const UInt ctuXPosInCtus = ctuRsAddr % frameWidthInCtus;
135  const UInt ctuYPosInCtus = ctuRsAddr / frameWidthInCtus;
136  const UInt uiSubStrm=pcPic->getSubstreamForCtuAddr(ctuRsAddr, true, pcSlice)-subStreamOffset;
137  TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr );
138  pCtu->initCtu( pcPic, ctuRsAddr );
139 
140  m_pcEntropyDecoder->setBitstream( ppcSubstreams[uiSubStrm] );
141 
142  // set up CABAC contexts' state for this CTU
143  if (ctuRsAddr == firstCtuRsAddrOfTile)
144  {
145  if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
146  {
148  }
149  }
150  else if (ctuXPosInCtus == tileXPosInCtus && wavefrontsEnabled)
151  {
152  // Synchronize cabac probabilities with upper-right CTU if it's available and at the start of a line.
153  if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
154  {
156  }
157  TComDataCU *pCtuUp = pCtu->getCtuAbove();
158  if ( pCtuUp && ((ctuRsAddr%frameWidthInCtus+1) < frameWidthInCtus) )
159  {
160  TComDataCU *pCtuTR = pcPic->getCtu( ctuRsAddr - frameWidthInCtus + 1 );
161  if ( pCtu->CUIsFromSameSliceAndTile(pCtuTR) )
162  {
163  // Top-right is available, so use it.
165  }
166  }
167  }
168 
169 #if ENC_DEC_TRACE
170  g_bJustDoIt = g_bEncDecTraceEnable;
171 #endif
172 
173 #if DECODER_PARTIAL_CONFORMANCE_CHECK != 0
174  const UInt numRemainingBitsPriorToCtu=ppcSubstreams[uiSubStrm]->getNumBitsLeft();
175 #endif
176 
177  if ( pcSlice->getSPS()->getUseSAO() )
178  {
179  SAOBlkParam& saoblkParam = (pcPic->getPicSym()->getSAOBlkParam())[ctuRsAddr];
180  Bool bIsSAOSliceEnabled = false;
181  Bool sliceEnabled[MAX_NUM_COMPONENT];
182  for(Int comp=0; comp < MAX_NUM_COMPONENT; comp++)
183  {
184  ComponentID compId=ComponentID(comp);
185  sliceEnabled[compId] = pcSlice->getSaoEnabledFlag(toChannelType(compId)) && (comp < pcPic->getNumberValidComponents());
186  if (sliceEnabled[compId])
187  {
188  bIsSAOSliceEnabled=true;
189  }
190  saoblkParam[compId].modeIdc = SAO_MODE_OFF;
191  }
192  if (bIsSAOSliceEnabled)
193  {
194  Bool leftMergeAvail = false;
195  Bool aboveMergeAvail= false;
196 
197  //merge left condition
198  Int rx = (ctuRsAddr % frameWidthInCtus);
199  if(rx > 0)
200  {
201  leftMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-1);
202  }
203  //merge up condition
204  Int ry = (ctuRsAddr / frameWidthInCtus);
205  if(ry > 0)
206  {
207  aboveMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-frameWidthInCtus);
208  }
209 
210  pcSbacDecoder->parseSAOBlkParam( saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail, pcSlice->getSPS()->getBitDepths());
211  }
212  }
213 
214  m_pcCuDecoder->decodeCtu ( pCtu, isLastCtuOfSliceSegment );
215 
216 #if DECODER_PARTIAL_CONFORMANCE_CHECK != 0
217  const UInt numRemainingBitsPostCtu=ppcSubstreams[uiSubStrm]->getNumBitsLeft(); // NOTE: Does not account for changes in buffered bits in CABAC decoder, although it's probably good enough.
219  {
220  m_pDecConformanceCheck->checkCtuDecoding(numRemainingBitsPriorToCtu-numRemainingBitsPostCtu);
221  }
222 #endif
223 
224  m_pcCuDecoder->decompressCtu ( pCtu );
225 
226 #if ENC_DEC_TRACE
227  g_bJustDoIt = g_bEncDecTraceDisable;
228 #endif
229 
230  //Store probabilities of second CTU in line into buffer
231  if ( ctuXPosInCtus == tileXPosInCtus+1 && wavefrontsEnabled)
232  {
234  }
235 
236  if (isLastCtuOfSliceSegment)
237  {
238 #if DECODER_CHECK_SUBSTREAM_AND_SLICE_TRAILING_BYTES
239  pcSbacDecoder->parseRemainingBytes(false);
240 #endif
241  if(!pcSlice->getDependentSliceSegmentFlag())
242  {
243  pcSlice->setSliceCurEndCtuTsAddr( ctuTsAddr+1 );
244  }
245  pcSlice->setSliceSegmentCurEndCtuTsAddr( ctuTsAddr+1 );
246  }
247  else if ( ctuXPosInCtus + 1 == tileXPosInCtus + currentTile.getTileWidthInCtus() &&
248  ( ctuYPosInCtus + 1 == tileYPosInCtus + currentTile.getTileHeightInCtus() || wavefrontsEnabled)
249  )
250  {
251  // The sub-stream/stream should be terminated after this CTU.
252  // (end of slice-segment, end of tile, end of wavefront-CTU-row)
253  UInt binVal;
254  pcSbacDecoder->parseTerminatingBit( binVal );
255  assert( binVal );
256 #if DECODER_CHECK_SUBSTREAM_AND_SLICE_TRAILING_BYTES
257  pcSbacDecoder->parseRemainingBytes(true);
258 #endif
259  }
260 
261  }
262 
263  assert(isLastCtuOfSliceSegment == true);
264 
265 
266  if( depSliceSegmentsEnabled )
267  {
268  m_lastSliceSegmentEndContextState.loadContexts( pcSbacDecoder );//ctx end of dep.slice
269  }
270 
271 }
272 
Void setSliceSegmentCurEndCtuTsAddr(UInt ctuTsAddr)
Definition: TComSlice.h:1493
Void loadContexts(const TDecSbac *pSrc)
Definition: TDecSbac.cpp:1853
Void decodeCtu(TComDataCU *pCtu, Bool &isLastCtuOfSliceSegment)
decode Ctu information
Definition: TDecCu.cpp:142
UInt getFirstCtuRsAddr() const
Definition: TComPicSym.h:79
UInt getCtuTsToRsAddrMap(Int ctuTsAddr) const
Definition: TComPicSym.h:183
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:71
Void setPicYuvResi(TComPicYuv *pcPicYuv)
Definition: TComPic.h:125
UInt getNumberOfCtusInFrame() const
Definition: TComPic.h:127
picture class (symbol + YUV buffers)
Definition: TComPic.h:56
void Void
Definition: TypeDef.h:203
TDecEntropy * m_pcEntropyDecoder
Definition: TDecSlice.h:67
Void initCtu(TComPic *pcPic, UInt ctuRsAddr)
Definition: TComDataCU.cpp:422
TComSlice * getSlice(Int i)
Definition: TComPic.h:113
Void setPicYuvPred(TComPicYuv *pcPicYuv)
Definition: TComPic.h:124
unsigned int UInt
Definition: TypeDef.h:212
Bool getUseSAO() const
Definition: TComSlice.h:908
Void destroy()
Definition: TDecSlice.cpp:60
Int getNumberValidComponents() const
Definition: TComPic.h:140
Void setBitstream(TComInputBitstream *p)
Definition: TDecEntropy.h:142
Bool getSaoEnabledFlag(ChannelType chType) const
Definition: TComSlice.h:1339
UInt getFrameWidthInCtus() const
Definition: TComPicSym.h:156
SBAC decoder class.
Definition: TDecSbac.h:63
Void resetEntropy(TComSlice *p)
Definition: TDecEntropy.h:143
Void setEntropyDecoder(TDecEntropyIf *p)
Definition: TDecEntropy.cpp:51
Bool getDependentSliceSegmentFlag() const
Definition: TComSlice.h:1357
UInt getTileWidthInCtus() const
Definition: TComPicSym.h:71
UInt getTileIdxMap(Int ctuRsAddr) const
Definition: TComPicSym.h:184
Bool getSAOMergeAvailability(Int currAddr, Int mergeAddr)
Definition: TComPic.cpp:216
bool Bool
Definition: TypeDef.h:204
UInt getSubstreamForCtuAddr(const UInt ctuAddr, const Bool bAddressInRaster, TComSlice *pcSlice)
Definition: TComPic.cpp:223
CU decoder class.
Definition: TDecCu.h:57
Void create()
Definition: TDecSlice.cpp:56
static ChannelType toChannelType(const ComponentID id)
Void setSliceCurEndCtuTsAddr(UInt ctuTsAddr)
Definition: TComSlice.h:1482
TComPicSym * getPicSym()
Definition: TComPic.h:111
#define DTRACE_CABAC_VL(x)
Definition: TComRom.h:153
Void parseSAOBlkParam(SAOBlkParam &saoBlkParam, Bool *sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, const BitDepths &bitDepths)
Definition: TDecSbac.cpp:1691
const BitDepths & getBitDepths() const
Definition: TComSlice.h:900
UInt getSliceSegmentCurStartCtuTsAddr() const
Definition: TComSlice.h:1492
virtual ~TDecSlice()
Definition: TDecSlice.cpp:52
const TComPPS * getPPS() const
Definition: TComSlice.h:1332
#define DTRACE_CABAC_T(x)
Definition: TComRom.h:154
entropy decoder class
Definition: TDecEntropy.h:117
TDecCu * m_pcCuDecoder
Definition: TDecSlice.h:68
UInt getCurrSliceIdx() const
Definition: TComPic.h:148
UInt getTileHeightInCtus() const
Definition: TComPicSym.h:73
Bool getEntropyCodingSyncEnabledFlag() const
Definition: TComSlice.h:1151
Int getPOC() const
Definition: TComPic.h:115
TComDataCU * getCtu(UInt ctuRsAddr)
Definition: TComPic.h:116
TDecSbac m_lastSliceSegmentEndContextState
context storage for state at the end of the previous slice-segment (used for dependent slices only)...
Definition: TDecSlice.h:71
TComDataCU * getCtuAbove()
Definition: TComDataCU.h:400
Bool getDependentSliceSegmentsEnabledFlag() const
Definition: TComSlice.h:1149
slice decoder class (header)
TComTile * getTComTile(UInt tileIdx)
Definition: TComPicSym.h:181
Void parseRemainingBytes(Bool noTrailingBytesExpected)
Definition: TDecSbac.cpp:186
#define DTRACE_CABAC_V(x)
Definition: TComRom.h:152
int Int
Definition: TypeDef.h:211
Bool CUIsFromSameSliceAndTile(const TComDataCU *pCU) const
Definition: TComDataCU.cpp:378
TDecSbac m_entropyCodingSyncContextState
context storate for state of contexts at the wavefront/WPP/entropy-coding-sync second CTU of tile-row...
Definition: TDecSlice.h:72
ComponentID
Definition: TypeDef.h:308
Void decompressCtu(TComDataCU *pCtu)
reconstruct Ctu information
Definition: TDecCu.cpp:162
static Bool doChecking()
Void init(TDecEntropy *pcEntropyDecoder, TDecCu *pcMbDecoder, TDecConformanceCheck *pDecConformanceCheck)
Definition: TDecSlice.cpp:64
slice header class
Definition: TComSlice.h:1225
Void checkCtuDecoding(const UInt numUsedBits)
Decoder conformance functions (header)
TDecConformanceCheck * m_pDecConformanceCheck
Definition: TDecSlice.h:69
const TComSPS * getSPS() const
Definition: TComSlice.h:1329
SAOBlkParam * getSAOBlkParam()
Definition: TComPicSym.h:186