source: 3DVCSoftware/branches/HTM-16.2-dev/source/Lib/TLibDecoder/TDecSlice.cpp @ 1412

Last change on this file since 1412 was 1412, checked in by tech, 7 years ago
  • Update HM-16.18
  • Cleanups
  • Encoder Extension

-- Representation formats
-- Parameter set sharing
-- GOP configuration

  • Property svn:eol-style set to native
File size: 10.4 KB
Line 
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
34/** \file     TDecSlice.cpp
35    \brief    slice decoder class
36*/
37
38#include "TDecSlice.h"
39#include "TDecConformance.h"
40
41//! \ingroup TLibDecoder
42//! \{
43
44//////////////////////////////////////////////////////////////////////
45// Construction/Destruction
46//////////////////////////////////////////////////////////////////////
47
48TDecSlice::TDecSlice()
49{
50}
51
52TDecSlice::~TDecSlice()
53{
54}
55
56Void TDecSlice::create()
57{
58}
59
60Void TDecSlice::destroy()
61{
62}
63
64Void TDecSlice::init(TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder, TDecConformanceCheck *pDecConformanceCheck)
65{
66  m_pcEntropyDecoder  = pcEntropyDecoder;
67  m_pcCuDecoder       = pcCuDecoder;
68  m_pDecConformanceCheck = pDecConformanceCheck;
69}
70
71Void 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] );
85  m_pcEntropyDecoder->resetEntropy      (pcSlice);
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#if NH_MV_ENC_DEC_TRAC
95#if ENC_DEC_TRACE
96  incSymbolCounter(); 
97#endif
98  DTRACE_CABAC_VL( g_nSymbolCounter );
99#else
100  DTRACE_CABAC_VL( g_nSymbolCounter++ );
101#endif
102  DTRACE_CABAC_T( "\tPOC: " );
103  DTRACE_CABAC_V( pcPic->getPOC() );
104#if NH_MV_ENC_DEC_TRAC
105  DTRACE_CABAC_T( " Layer: " );
106  DTRACE_CABAC_V( pcPic->getLayerId() );
107#endif
108  DTRACE_CABAC_T( "\n" );
109
110#if ENC_DEC_TRACE
111  g_bJustDoIt = g_bEncDecTraceDisable;
112#endif
113
114  // The first CTU of the slice is the first coded substream, but the global substream number, as calculated by getSubstreamForCtuAddr may be higher.
115  // This calculates the common offset for all substreams in this slice.
116  const UInt subStreamOffset=pcPic->getSubstreamForCtuAddr(startCtuRsAddr, true, pcSlice);
117
118
119  if (depSliceSegmentsEnabled)
120  {
121    // modify initial contexts with previous slice segment if this is a dependent slice.
122    const UInt startTileIdx=pcPic->getPicSym()->getTileIdxMap(startCtuRsAddr);
123    const TComTile *pCurrentTile=pcPic->getPicSym()->getTComTile(startTileIdx);
124    const UInt firstCtuRsAddrOfTile = pCurrentTile->getFirstCtuRsAddr();
125
126    if( pcSlice->getDependentSliceSegmentFlag() && startCtuRsAddr != firstCtuRsAddrOfTile)
127    {
128      if ( pCurrentTile->getTileWidthInCtus() >= 2 || !wavefrontsEnabled)
129      {
130        pcSbacDecoder->loadContexts(&m_lastSliceSegmentEndContextState);
131      }
132    }
133  }
134#if  NH_3D
135  if( pcSlice->getPPS()->getDLT() != NULL )
136  {
137      assert( pcSlice->getSPS()->getBitDepth( CHANNEL_TYPE_LUMA ) == pcSlice->getPPS()->getDLT()->getDepthViewBitDepth() );
138  }
139#endif
140
141  // for every CTU in the slice segment...
142
143  Bool isLastCtuOfSliceSegment = false;
144  for( UInt ctuTsAddr = startCtuTsAddr; !isLastCtuOfSliceSegment && ctuTsAddr < numCtusInFrame; ctuTsAddr++)
145  {
146    const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddr);
147    const TComTile &currentTile = *(pcPic->getPicSym()->getTComTile(pcPic->getPicSym()->getTileIdxMap(ctuRsAddr)));
148    const UInt firstCtuRsAddrOfTile = currentTile.getFirstCtuRsAddr();
149    const UInt tileXPosInCtus = firstCtuRsAddrOfTile % frameWidthInCtus;
150    const UInt tileYPosInCtus = firstCtuRsAddrOfTile / frameWidthInCtus;
151    const UInt ctuXPosInCtus  = ctuRsAddr % frameWidthInCtus;
152    const UInt ctuYPosInCtus  = ctuRsAddr / frameWidthInCtus;
153    const UInt uiSubStrm=pcPic->getSubstreamForCtuAddr(ctuRsAddr, true, pcSlice)-subStreamOffset;
154    TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr );
155    pCtu->initCtu( pcPic, ctuRsAddr );
156
157    m_pcEntropyDecoder->setBitstream( ppcSubstreams[uiSubStrm] );
158
159    // set up CABAC contexts' state for this CTU
160    if (ctuRsAddr == firstCtuRsAddrOfTile)
161    {
162      if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
163      {
164        m_pcEntropyDecoder->resetEntropy(pcSlice);
165      }
166    }
167    else if (ctuXPosInCtus == tileXPosInCtus && wavefrontsEnabled)
168    {
169      // Synchronize cabac probabilities with upper-right CTU if it's available and at the start of a line.
170      if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
171      {
172        m_pcEntropyDecoder->resetEntropy(pcSlice);
173      }
174      TComDataCU *pCtuUp = pCtu->getCtuAbove();
175      if ( pCtuUp && ((ctuRsAddr%frameWidthInCtus+1) < frameWidthInCtus)  )
176      {
177        TComDataCU *pCtuTR = pcPic->getCtu( ctuRsAddr - frameWidthInCtus + 1 );
178        if ( pCtu->CUIsFromSameSliceAndTile(pCtuTR) )
179        {
180          // Top-right is available, so use it.
181          pcSbacDecoder->loadContexts( &m_entropyCodingSyncContextState );
182        }
183      }
184    }
185
186#if ENC_DEC_TRACE
187    g_bJustDoIt = g_bEncDecTraceEnable;
188#endif
189
190#if DECODER_PARTIAL_CONFORMANCE_CHECK != 0
191    const UInt numRemainingBitsPriorToCtu=ppcSubstreams[uiSubStrm]->getNumBitsLeft();
192#endif
193
194    if ( pcSlice->getSPS()->getUseSAO() )
195    {
196      SAOBlkParam& saoblkParam = (pcPic->getPicSym()->getSAOBlkParam())[ctuRsAddr];
197      Bool bIsSAOSliceEnabled = false;
198      Bool sliceEnabled[MAX_NUM_COMPONENT];
199      for(Int comp=0; comp < MAX_NUM_COMPONENT; comp++)
200      {
201        ComponentID compId=ComponentID(comp);
202        sliceEnabled[compId] = pcSlice->getSaoEnabledFlag(toChannelType(compId)) && (comp < pcPic->getNumberValidComponents());
203        if (sliceEnabled[compId])
204        {
205          bIsSAOSliceEnabled=true;
206        }
207        saoblkParam[compId].modeIdc = SAO_MODE_OFF;
208      }
209      if (bIsSAOSliceEnabled)
210      {
211        Bool leftMergeAvail = false;
212        Bool aboveMergeAvail= false;
213
214        //merge left condition
215        Int rx = (ctuRsAddr % frameWidthInCtus);
216        if(rx > 0)
217        {
218          leftMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-1);
219        }
220        //merge up condition
221        Int ry = (ctuRsAddr / frameWidthInCtus);
222        if(ry > 0)
223        {
224          aboveMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-frameWidthInCtus);
225        }
226
227        pcSbacDecoder->parseSAOBlkParam( saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail, pcSlice->getSPS()->getBitDepths());
228      }
229    }
230
231    m_pcCuDecoder->decodeCtu     ( pCtu, isLastCtuOfSliceSegment );
232
233#if DECODER_PARTIAL_CONFORMANCE_CHECK != 0
234    const UInt numRemainingBitsPostCtu=ppcSubstreams[uiSubStrm]->getNumBitsLeft(); // NOTE: Does not account for changes in buffered bits in CABAC decoder, although it's probably good enough.
235    if (TDecConformanceCheck::doChecking() && m_pDecConformanceCheck)
236    {
237      m_pDecConformanceCheck->checkCtuDecoding(numRemainingBitsPriorToCtu-numRemainingBitsPostCtu);
238    }
239#endif
240
241    m_pcCuDecoder->decompressCtu ( pCtu );
242
243#if ENC_DEC_TRACE
244    g_bJustDoIt = g_bEncDecTraceDisable;
245#endif
246
247    //Store probabilities of second CTU in line into buffer
248    if ( ctuXPosInCtus == tileXPosInCtus+1 && wavefrontsEnabled)
249    {
250      m_entropyCodingSyncContextState.loadContexts( pcSbacDecoder );
251    }
252
253    if (isLastCtuOfSliceSegment)
254    {
255#if DECODER_CHECK_SUBSTREAM_AND_SLICE_TRAILING_BYTES
256      pcSbacDecoder->parseRemainingBytes(false);
257#endif
258      if(!pcSlice->getDependentSliceSegmentFlag())
259      {
260        pcSlice->setSliceCurEndCtuTsAddr( ctuTsAddr+1 );
261      }
262      pcSlice->setSliceSegmentCurEndCtuTsAddr( ctuTsAddr+1 );
263    }
264    else if (  ctuXPosInCtus + 1 == tileXPosInCtus + currentTile.getTileWidthInCtus() &&
265             ( ctuYPosInCtus + 1 == tileYPosInCtus + currentTile.getTileHeightInCtus() || wavefrontsEnabled)
266            )
267    {
268      // The sub-stream/stream should be terminated after this CTU.
269      // (end of slice-segment, end of tile, end of wavefront-CTU-row)
270      UInt binVal;
271      pcSbacDecoder->parseTerminatingBit( binVal );
272      assert( binVal );
273#if DECODER_CHECK_SUBSTREAM_AND_SLICE_TRAILING_BYTES
274      pcSbacDecoder->parseRemainingBytes(true);
275#endif
276    }
277
278  }
279
280  assert(isLastCtuOfSliceSegment == true);
281
282
283  if( depSliceSegmentsEnabled )
284  {
285    m_lastSliceSegmentEndContextState.loadContexts( pcSbacDecoder );//ctx end of dep.slice
286  }
287
288}
289
290//! \}
Note: See TracBrowser for help on using the repository browser.