source: 3DVCSoftware/branches/HTM-16.0-MV-draft-5/source/Lib/TLibDecoder/TDecSlice.cpp

Last change on this file was 1390, checked in by tech, 9 years ago

Removed 3D.

  • Property svn:eol-style set to native
File size: 9.5 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-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
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
47TDecSlice::TDecSlice()
48{
49}
50
51TDecSlice::~TDecSlice()
52{
53}
54
55Void TDecSlice::create()
56{
57}
58
59Void TDecSlice::destroy()
60{
61}
62
63Void TDecSlice::init(TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder)
64{
65  m_pcEntropyDecoder  = pcEntropyDecoder;
66  m_pcCuDecoder       = pcCuDecoder;
67}
68
69Void 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] );
83  m_pcEntropyDecoder->resetEntropy      (pcSlice);
84
85  // decoder doesn't need prediction & residual frame buffer
86  pcPic->setPicYuvPred( 0 );
87  pcPic->setPicYuvResi( 0 );
88
89#if ENC_DEC_TRACE
90  g_bJustDoIt = g_bEncDecTraceEnable;
91#endif
92#if NH_MV_ENC_DEC_TRAC
93#if ENC_DEC_TRACE
94  incSymbolCounter(); 
95#endif
96  DTRACE_CABAC_VL( g_nSymbolCounter );
97#else
98  DTRACE_CABAC_VL( g_nSymbolCounter++ );
99#endif
100  DTRACE_CABAC_T( "\tPOC: " );
101  DTRACE_CABAC_V( pcPic->getPOC() );
102#if NH_MV_ENC_DEC_TRAC
103  DTRACE_CABAC_T( " Layer: " );
104  DTRACE_CABAC_V( pcPic->getLayerId() );
105#endif
106  DTRACE_CABAC_T( "\n" );
107
108#if ENC_DEC_TRACE
109  g_bJustDoIt = g_bEncDecTraceDisable;
110#endif
111
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);
115
116
117  if (depSliceSegmentsEnabled)
118  {
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();
123
124    if( pcSlice->getDependentSliceSegmentFlag() && startCtuRsAddr != firstCtuRsAddrOfTile)
125    {
126      if ( pCurrentTile->getTileWidthInCtus() >= 2 || !wavefrontsEnabled)
127      {
128        pcSbacDecoder->loadContexts(&m_lastSliceSegmentEndContextState);
129      }
130    }
131  }
132
133  // for every CTU in the slice segment...
134
135  Bool isLastCtuOfSliceSegment = false;
136  for( UInt ctuTsAddr = startCtuTsAddr; !isLastCtuOfSliceSegment && ctuTsAddr < numCtusInFrame; ctuTsAddr++)
137  {
138    const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddr);
139    const TComTile &currentTile = *(pcPic->getPicSym()->getTComTile(pcPic->getPicSym()->getTileIdxMap(ctuRsAddr)));
140    const UInt firstCtuRsAddrOfTile = currentTile.getFirstCtuRsAddr();
141    const UInt tileXPosInCtus = firstCtuRsAddrOfTile % frameWidthInCtus;
142    const UInt tileYPosInCtus = firstCtuRsAddrOfTile / frameWidthInCtus;
143    const UInt ctuXPosInCtus  = ctuRsAddr % frameWidthInCtus;
144    const UInt ctuYPosInCtus  = ctuRsAddr / frameWidthInCtus;
145    const UInt uiSubStrm=pcPic->getSubstreamForCtuAddr(ctuRsAddr, true, pcSlice)-subStreamOffset;
146    TComDataCU* pCtu = pcPic->getCtu( ctuRsAddr );
147    pCtu->initCtu( pcPic, ctuRsAddr );
148
149    m_pcEntropyDecoder->setBitstream( ppcSubstreams[uiSubStrm] );
150
151    // set up CABAC contexts' state for this CTU
152    if (ctuRsAddr == firstCtuRsAddrOfTile)
153    {
154      if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
155      {
156        m_pcEntropyDecoder->resetEntropy(pcSlice);
157      }
158    }
159    else if (ctuXPosInCtus == tileXPosInCtus && wavefrontsEnabled)
160    {
161      // Synchronize cabac probabilities with upper-right CTU if it's available and at the start of a line.
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      TComDataCU *pCtuUp = pCtu->getCtuAbove();
167      if ( pCtuUp && ((ctuRsAddr%frameWidthInCtus+1) < frameWidthInCtus)  )
168      {
169        TComDataCU *pCtuTR = pcPic->getCtu( ctuRsAddr - frameWidthInCtus + 1 );
170        if ( pCtu->CUIsFromSameSliceAndTile(pCtuTR) )
171        {
172          // Top-right is available, so use it.
173          pcSbacDecoder->loadContexts( &m_entropyCodingSyncContextState );
174        }
175      }
176    }
177
178#if ENC_DEC_TRACE
179    g_bJustDoIt = g_bEncDecTraceEnable;
180#endif
181
182    if ( pcSlice->getSPS()->getUseSAO() )
183    {
184      SAOBlkParam& saoblkParam = (pcPic->getPicSym()->getSAOBlkParam())[ctuRsAddr];
185      Bool bIsSAOSliceEnabled = false;
186      Bool sliceEnabled[MAX_NUM_COMPONENT];
187      for(Int comp=0; comp < MAX_NUM_COMPONENT; comp++)
188      {
189        ComponentID compId=ComponentID(comp);
190        sliceEnabled[compId] = pcSlice->getSaoEnabledFlag(toChannelType(compId)) && (comp < pcPic->getNumberValidComponents());
191        if (sliceEnabled[compId])
192        {
193          bIsSAOSliceEnabled=true;
194        }
195        saoblkParam[compId].modeIdc = SAO_MODE_OFF;
196      }
197      if (bIsSAOSliceEnabled)
198      {
199        Bool leftMergeAvail = false;
200        Bool aboveMergeAvail= false;
201
202        //merge left condition
203        Int rx = (ctuRsAddr % frameWidthInCtus);
204        if(rx > 0)
205        {
206          leftMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-1);
207        }
208        //merge up condition
209        Int ry = (ctuRsAddr / frameWidthInCtus);
210        if(ry > 0)
211        {
212          aboveMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-frameWidthInCtus);
213        }
214
215        pcSbacDecoder->parseSAOBlkParam( saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail, pcSlice->getSPS()->getBitDepths());
216      }
217    }
218
219    m_pcCuDecoder->decodeCtu     ( pCtu, isLastCtuOfSliceSegment );
220    m_pcCuDecoder->decompressCtu ( pCtu );
221
222#if ENC_DEC_TRACE
223    g_bJustDoIt = g_bEncDecTraceDisable;
224#endif
225
226    //Store probabilities of second CTU in line into buffer
227    if ( ctuXPosInCtus == tileXPosInCtus+1 && wavefrontsEnabled)
228    {
229      m_entropyCodingSyncContextState.loadContexts( pcSbacDecoder );
230    }
231
232    if (isLastCtuOfSliceSegment)
233    {
234#if DECODER_CHECK_SUBSTREAM_AND_SLICE_TRAILING_BYTES
235      pcSbacDecoder->parseRemainingBytes(false);
236#endif
237      if(!pcSlice->getDependentSliceSegmentFlag())
238      {
239        pcSlice->setSliceCurEndCtuTsAddr( ctuTsAddr+1 );
240      }
241      pcSlice->setSliceSegmentCurEndCtuTsAddr( ctuTsAddr+1 );
242    }
243    else if (  ctuXPosInCtus + 1 == tileXPosInCtus + currentTile.getTileWidthInCtus() &&
244             ( ctuYPosInCtus + 1 == tileYPosInCtus + currentTile.getTileHeightInCtus() || wavefrontsEnabled)
245            )
246    {
247      // The sub-stream/stream should be terminated after this CTU.
248      // (end of slice-segment, end of tile, end of wavefront-CTU-row)
249      UInt binVal;
250      pcSbacDecoder->parseTerminatingBit( binVal );
251      assert( binVal );
252#if DECODER_CHECK_SUBSTREAM_AND_SLICE_TRAILING_BYTES
253      pcSbacDecoder->parseRemainingBytes(true);
254#endif
255    }
256
257  }
258
259  assert(isLastCtuOfSliceSegment == true);
260
261
262  if( depSliceSegmentsEnabled )
263  {
264    m_lastSliceSegmentEndContextState.loadContexts( pcSbacDecoder );//ctx end of dep.slice
265  }
266
267}
268
269//! \}
Note: See TracBrowser for help on using the repository browser.