source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibDecoder/TDecSlice.cpp @ 1251

Last change on this file since 1251 was 1246, checked in by seregin, 9 years ago

port rev 4240

  • Property svn:eol-style set to native
File size: 9.7 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-2014, 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
63#if SVC_EXTENSION
64Void TDecSlice::init(TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder, UInt* saoMaxOffsetQVal)
65{
66  m_pcEntropyDecoder  = pcEntropyDecoder;
67  m_pcCuDecoder       = pcCuDecoder;
68  m_saoMaxOffsetQVal  = saoMaxOffsetQVal;
69}
70#else
71Void TDecSlice::init(TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder)
72{
73  m_pcEntropyDecoder  = pcEntropyDecoder;
74  m_pcCuDecoder       = pcCuDecoder;
75}
76#endif
77
78Void TDecSlice::decompressSlice(TComInputBitstream** ppcSubstreams, TComPic* pcPic, TDecSbac* pcSbacDecoder)
79{
80  TComSlice* pcSlice                 = pcPic->getSlice(pcPic->getCurrSliceIdx());
81
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
98#if ENC_DEC_TRACE
99  g_bJustDoIt = g_bEncDecTraceEnable;
100#endif
101  DTRACE_CABAC_VL( g_nSymbolCounter++ );
102  DTRACE_CABAC_T( "\tPOC: " );
103  DTRACE_CABAC_V( pcPic->getPOC() );
104  DTRACE_CABAC_T( "\n" );
105
106#if ENC_DEC_TRACE
107  g_bJustDoIt = g_bEncDecTraceDisable;
108#endif
109
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);
113
114
115  if (depSliceSegmentsEnabled)
116  {
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();
121
122    if( pcSlice->getDependentSliceSegmentFlag() && startCtuRsAddr != firstCtuRsAddrOfTile)
123    {
124      if ( pCurrentTile->getTileWidthInCtus() >= 2 || !wavefrontsEnabled)
125      {
126        pcSbacDecoder->loadContexts(&m_lastSliceSegmentEndContextState);
127      }
128    }
129  }
130
131  // for every CTU in the slice segment...
132
133  Bool isLastCtuOfSliceSegment = false;
134  for( UInt ctuTsAddr = startCtuTsAddr; !isLastCtuOfSliceSegment && ctuTsAddr < numCtusInFrame; ctuTsAddr++)
135  {
136    const UInt ctuRsAddr = pcPic->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddr);
137    const TComTile &currentTile = *(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)
151    {
152      if (ctuTsAddr != startCtuTsAddr) // if it is the first CTU, then the entropy coder has already been reset
153      {
154        m_pcEntropyDecoder->resetEntropy(pcSlice);
155      }
156    }
157    else if (ctuXPosInCtus == tileXPosInCtus && wavefrontsEnabled)
158    {
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
161      {
162        m_pcEntropyDecoder->resetEntropy(pcSlice);
163      }
164      TComDataCU *pCtuUp = pCtu->getCtuAbove();
165      if ( pCtuUp && ((ctuRsAddr%frameWidthInCtus+1) < frameWidthInCtus)  )
166      {
167        TComDataCU *pCtuTR = pcPic->getCtu( ctuRsAddr - frameWidthInCtus + 1 );
168        if ( pCtu->CUIsFromSameSliceAndTile(pCtuTR) )
169        {
170          // Top-right is available, so use it.
171          pcSbacDecoder->loadContexts( &m_entropyCodingSyncContextState );
172        }
173      }
174    }
175
176#if ENC_DEC_TRACE
177    g_bJustDoIt = g_bEncDecTraceEnable;
178#endif
179
180    if ( pcSlice->getSPS()->getUseSAO() )
181    {
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++)
186      {
187        ComponentID compId=ComponentID(comp);
188        sliceEnabled[compId] = pcSlice->getSaoEnabledFlag(toChannelType(compId)) && (comp < pcPic->getNumberValidComponents());
189        if (sliceEnabled[compId])
190        {
191          bIsSAOSliceEnabled=true;
192        }
193        saoblkParam[compId].modeIdc = SAO_MODE_OFF;
194      }
195      if (bIsSAOSliceEnabled)
196      {
197        Bool leftMergeAvail = false;
198        Bool aboveMergeAvail= false;
199
200        //merge left condition
201        Int rx = (ctuRsAddr % frameWidthInCtus);
202        if(rx > 0)
203        {
204          leftMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-1);
205        }
206        //merge up condition
207        Int ry = (ctuRsAddr / frameWidthInCtus);
208        if(ry > 0)
209        {
210          aboveMergeAvail = pcPic->getSAOMergeAvailability(ctuRsAddr, ctuRsAddr-frameWidthInCtus);
211        }
212#if SVC_EXTENSION
213        pcSbacDecoder->parseSAOBlkParam( saoblkParam, m_saoMaxOffsetQVal, sliceEnabled, leftMergeAvail, aboveMergeAvail);
214#else
215        pcSbacDecoder->parseSAOBlkParam( saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail);
216#endif     
217      }
218    }
219
220    m_pcCuDecoder->decodeCtu     ( pCtu, isLastCtuOfSliceSegment );
221    m_pcCuDecoder->decompressCtu ( pCtu );
222
223#if ENC_DEC_TRACE
224    g_bJustDoIt = g_bEncDecTraceDisable;
225#endif
226
227    //Store probabilities of second CTU in line into buffer
228    if ( ctuXPosInCtus == tileXPosInCtus+1 && wavefrontsEnabled)
229    {
230      m_entropyCodingSyncContextState.loadContexts( pcSbacDecoder );
231    }
232
233    if (isLastCtuOfSliceSegment)
234    {
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)
250      UInt binVal;
251      pcSbacDecoder->parseTerminatingBit( binVal );
252      assert( binVal );
253#if DECODER_CHECK_SUBSTREAM_AND_SLICE_TRAILING_BYTES
254      pcSbacDecoder->parseRemainingBytes(true);
255#endif
256    }
257
258  }
259
260  assert(isLastCtuOfSliceSegment == true);
261
262
263  if( depSliceSegmentsEnabled )
264  {
265    m_lastSliceSegmentEndContextState.loadContexts( pcSbacDecoder );//ctx end of dep.slice
266  }
267
268}
269
270//! \}
Note: See TracBrowser for help on using the repository browser.