source: SHVCSoftware/branches/SHM-6-dev/source/Lib/TLibDecoder/TDecTop.cpp @ 653

Last change on this file since 653 was 652, checked in by seregin, 11 years ago

update to HM-14.0

  • Property svn:eol-style set to native
File size: 85.3 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     TDecTop.cpp
35    \brief    decoder class
36*/
37
38#include "NALread.h"
39#include "TDecTop.h"
40
41#if SVC_EXTENSION
42UInt  TDecTop::m_prevPOC = MAX_UINT;
43UInt  TDecTop::m_uiPrevLayerId = MAX_UINT;
44Bool  TDecTop::m_bFirstSliceInSequence = true;
45#endif
46
47//! \ingroup TLibDecoder
48//! \{
49
50TDecTop::TDecTop()
51{
52  m_pcPic = 0;
53  m_iMaxRefPicNum = 0;
54#if ENC_DEC_TRACE
55  g_hTrace = fopen( "TraceDec.txt", "wb" );
56  g_bJustDoIt = g_bEncDecTraceDisable;
57  g_nSymbolCounter = 0;
58#endif
59  m_associatedIRAPType = NAL_UNIT_INVALID;
60  m_pocCRA = 0;
61  m_pocRandomAccess = MAX_INT;         
62#if !SVC_EXTENSION
63  m_prevPOC                = MAX_INT;
64#endif
65  m_bFirstSliceInPicture    = true;
66#if !SVC_EXTENSION
67  m_bFirstSliceInSequence   = true;
68#endif
69#if SVC_EXTENSION
70  m_layerId = 0;
71#if AVC_BASE
72  m_pBLReconFile = NULL;
73#endif
74  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
75#endif
76#if AVC_SYNTAX || SYNTAX_OUTPUT
77  m_pBLSyntaxFile = NULL;
78#endif
79  m_prevSliceSkipped = false;
80  m_skippedPOC = 0;
81#if SETTING_NO_OUT_PIC_PRIOR
82  m_bFirstSliceInBitstream  = true;
83  m_lastPOCNoOutputPriorPics = -1;
84  m_craNoRaslOutputFlag = false;
85  m_isNoOutputPriorPics = false;
86#endif
87#if NO_CLRAS_OUTPUT_FLAG 
88  m_layerInitializedFlag       = false;
89  m_firstPicInLayerDecodedFlag = false; 
90  m_bRefreshPending            = false;
91#endif
92#if RESOLUTION_BASED_DPB
93  m_subDpbIdx = -1;
94#endif
95}
96
97TDecTop::~TDecTop()
98{
99#if ENC_DEC_TRACE
100  fclose( g_hTrace );
101#endif
102}
103
104Void TDecTop::create()
105{
106#if SVC_EXTENSION
107  m_cGopDecoder.create( m_layerId );
108#else
109  m_cGopDecoder.create();
110#endif
111  m_apcSlicePilot = new TComSlice;
112  m_uiSliceIdx = 0;
113}
114
115Void TDecTop::destroy()
116{
117  m_cGopDecoder.destroy();
118 
119  delete m_apcSlicePilot;
120  m_apcSlicePilot = NULL;
121 
122  m_cSliceDecoder.destroy();
123#if SVC_EXTENSION
124  for(Int i=0; i<MAX_NUM_REF; i++)
125  {
126    if(m_cIlpPic[i])
127    {
128      m_cIlpPic[i]->destroy();
129      delete m_cIlpPic[i];
130      m_cIlpPic[i] = NULL;
131    }
132  }   
133#endif
134}
135
136Void TDecTop::init()
137{
138#if !SVC_EXTENSION
139  // initialize ROM
140  initROM();
141#endif
142#if SVC_EXTENSION
143  m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
144  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder, m_cSAO.getSaoMaxOffsetQVal() );
145#else
146  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
147  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
148#endif
149  m_cEntropyDecoder.init(&m_cPrediction);
150}
151
152#if SVC_EXTENSION
153#if !REPN_FORMAT_IN_VPS
154Void TDecTop::xInitILRP(TComSPS *pcSPS)
155#else
156Void TDecTop::xInitILRP(TComSlice *slice)
157#endif
158{
159#if REPN_FORMAT_IN_VPS
160  TComSPS* pcSPS = slice->getSPS();
161  Int bitDepthY   = slice->getBitDepthY();
162  Int bitDepthC   = slice->getBitDepthC();
163  Int picWidth    = slice->getPicWidthInLumaSamples();
164  Int picHeight   = slice->getPicHeightInLumaSamples();
165#endif
166  if(m_layerId>0)
167  {
168#if REPN_FORMAT_IN_VPS
169    g_bitDepthY     = bitDepthY;
170    g_bitDepthC     = bitDepthC;
171#else
172    g_bitDepthY     = pcSPS->getBitDepthY();
173    g_bitDepthC     = pcSPS->getBitDepthC();
174#endif
175    g_uiMaxCUWidth  = pcSPS->getMaxCUWidth();
176    g_uiMaxCUHeight = pcSPS->getMaxCUHeight();
177    g_uiMaxCUDepth  = pcSPS->getMaxCUDepth();
178    g_uiAddCUDepth  = max (0, pcSPS->getLog2MinCodingBlockSize() - (Int)pcSPS->getQuadtreeTULog2MinSize() );
179
180    Int  numReorderPics[MAX_TLAYER];
181    Window &conformanceWindow = pcSPS->getConformanceWindow();
182    Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window();
183
184    for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
185    {
186#if USE_DPB_SIZE_TABLE
187      if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
188      {
189        assert( this->getLayerId() == 0 );
190        numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
191      }
192      else
193      {
194        TComVPS *vps = slice->getVPS();
195        // SHM decoders will use DPB size table in the VPS to determine the number of reorder pictures.
196        numReorderPics[temporalLayer] = vps->getMaxVpsNumReorderPics( getCommonDecoderParams()->getTargetOutputLayerSetIdx() , temporalLayer);
197      }
198#else
199      numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
200#endif
201    }
202
203    if (m_cIlpPic[0] == NULL)
204    {
205      for (Int j=0; j < m_numDirectRefLayers; j++)
206      {
207
208        m_cIlpPic[j] = new  TComPic;
209#if AUXILIARY_PICTURES
210#if REPN_FORMAT_IN_VPS
211#if SVC_UPSAMPLING
212        m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
213#else
214        m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
215#endif
216#else
217#if SVC_UPSAMPLING
218        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
219#else
220        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
221#endif
222#endif
223#else
224#if REPN_FORMAT_IN_VPS
225#if SVC_UPSAMPLING
226        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
227#else
228        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
229#endif
230#else
231#if SVC_UPSAMPLING
232        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
233#else
234        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
235#endif
236#endif
237#endif
238        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
239        {
240          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
241        }
242      }
243    }
244  }
245}
246#endif
247
248Void TDecTop::deletePicBuffer ( )
249{
250  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
251  Int iSize = Int( m_cListPic.size() );
252 
253  for (Int i = 0; i < iSize; i++ )
254  {
255    TComPic* pcPic = *(iterPic++);
256#if SVC_EXTENSION
257    if( pcPic )
258    {
259      pcPic->destroy();
260
261      delete pcPic;
262      pcPic = NULL;
263    }
264#else
265    pcPic->destroy();
266   
267    delete pcPic;
268    pcPic = NULL;
269#endif
270  }
271 
272  m_cSAO.destroy();
273 
274  m_cLoopFilter.        destroy();
275 
276#if !SVC_EXTENSION
277  // destroy ROM
278  destroyROM();
279#endif
280}
281
282Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
283{
284  Int  numReorderPics[MAX_TLAYER];
285  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
286  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
287
288  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
289  {
290#if USE_DPB_SIZE_TABLE
291    if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
292    {
293      assert( this->getLayerId() == 0 );
294      numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
295    }
296    else
297    {
298      TComVPS *vps = pcSlice->getVPS();
299      // SHM decoders will use DPB size table in the VPS to determine the number of reorder pictures.
300      numReorderPics[temporalLayer] = vps->getMaxVpsNumReorderPics( getCommonDecoderParams()->getTargetOutputLayerSetIdx() , temporalLayer);
301    }
302#else
303    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
304#endif
305  }
306
307#if USE_DPB_SIZE_TABLE
308  if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
309  {
310    assert( this->getLayerId() == 0 );
311    m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
312  }
313  else
314  {
315#if RESOLUTION_BASED_DPB
316    Int layerSetIdxForOutputLayerSet = pcSlice->getVPS()->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
317    Int layerIdx = pcSlice->getVPS()->findLayerIdxInLayerSet( layerSetIdxForOutputLayerSet, pcSlice->getLayerId() );  assert( layerIdx != -1 );
318    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxVpsLayerDecPicBuffMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), layerIdx, pcSlice->getTLayer() ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
319#else
320    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), pcSlice->getLayerId(), pcSlice->getTLayer() ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
321#endif
322  }
323#else
324  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
325#endif
326
327#if SVC_EXTENSION
328  m_iMaxRefPicNum += 1; // it should be updated if more than 1 resampling picture is used
329#endif
330
331  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
332  {
333    rpcPic = new TComPic();
334
335#if SVC_EXTENSION //Temporal solution, should be modified
336    if(m_layerId > 0)
337    {
338      for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
339      {
340#if O0098_SCALED_REF_LAYER_ID
341        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
342#else
343        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(i);
344#endif
345        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
346
347#if VPS_EXTN_DIRECT_REF_LAYERS
348        TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i );
349#else
350        TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
351#endif
352        //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin());
353        TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
354#if REPN_FORMAT_IN_VPS
355#if O0194_DIFFERENT_BITDEPTH_EL_BL
356        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, i);
357        Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
358
359        if( pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets || !sameBitDepths )
360#else
361        if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets )
362#endif
363#else
364        if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() || !zeroOffsets )
365#endif
366        {
367          rpcPic->setSpatialEnhLayerFlag( i, true );
368
369          //only for scalable extension
370#if SCALABILITY_MASK_E0104
371          assert( pcSlice->getVPS()->getScalabilityMask(2) == true );
372#else
373          assert( pcSlice->getVPS()->getScalabilityMask(1) == true );
374#endif
375        }
376      }
377    }
378#endif
379   
380#if AUXILIARY_PICTURES
381#if REPN_FORMAT_IN_VPS
382#if SVC_UPSAMPLING
383    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
384                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
385#else
386    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
387                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
388#endif
389#else
390#if SVC_UPSAMPLING
391    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
392                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
393#else
394    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
395                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
396#endif
397#endif
398#else
399#if REPN_FORMAT_IN_VPS
400#if SVC_UPSAMPLING
401    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
402                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
403#else
404    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
405                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
406#endif
407#else
408#if SVC_UPSAMPLING
409    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
410                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
411#else
412    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
413                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
414#endif
415#endif
416#endif
417    m_cListPic.pushBack( rpcPic );
418   
419    return;
420  }
421 
422  Bool bBufferIsAvailable = false;
423  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
424  while (iterPic != m_cListPic.end())
425  {
426    rpcPic = *(iterPic++);
427    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
428    {
429      rpcPic->setOutputMark(false);
430      bBufferIsAvailable = true;
431      break;
432    }
433
434    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
435    {
436#if !SVC_EXTENSION
437      rpcPic->setOutputMark(false);
438#endif
439      rpcPic->setReconMark( false );
440      rpcPic->getPicYuvRec()->setBorderExtension( false );
441      bBufferIsAvailable = true;
442      break;
443    }
444  }
445 
446  if ( !bBufferIsAvailable )
447  {
448    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
449    m_iMaxRefPicNum++;
450    rpcPic = new TComPic();
451    m_cListPic.pushBack( rpcPic );
452  }
453  rpcPic->destroy();
454
455#if AUXILIARY_PICTURES
456#if REPN_FORMAT_IN_VPS
457#if SVC_UPSAMPLING
458  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
459                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
460
461#else
462  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
463                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
464#endif
465#else
466#if SVC_UPSAMPLING
467  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
468                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
469
470#else
471  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
472                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
473#endif
474#endif
475#else
476#if REPN_FORMAT_IN_VPS
477#if SVC_UPSAMPLING
478  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
479                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
480
481#else
482  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
483                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
484#endif
485#else
486#if SVC_UPSAMPLING
487  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
488                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
489
490#else
491  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
492                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
493#endif
494#endif
495#endif
496}
497
498Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
499{
500  if (!m_pcPic)
501  {
502    /* nothing to deblock */
503    return;
504  }
505 
506  TComPic*&   pcPic         = m_pcPic;
507
508  // Execute Deblock + Cleanup
509  m_cGopDecoder.filterPicture(pcPic);
510
511#if SYNTAX_OUTPUT
512  pcPic->wrireBLSyntax( getBLSyntaxFile(), SYNTAX_BYTES );
513#endif
514  TComSlice::sortPicList( m_cListPic ); // sorting for application output
515  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
516  rpcListPic          = &m_cListPic; 
517  m_cCuDecoder.destroy();       
518  m_bFirstSliceInPicture  = true;
519
520  return;
521}
522
523#if SETTING_NO_OUT_PIC_PRIOR
524Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic)
525{
526  if (!rpcListPic || !m_isNoOutputPriorPics) return;
527
528  TComList<TComPic*>::iterator  iterPic   = rpcListPic->begin();
529
530  while (iterPic != rpcListPic->end())
531  {
532    TComPic*& pcPicTmp = *(iterPic++);
533    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
534    {
535      pcPicTmp->setOutputMark(false);
536    }
537  }
538}
539#endif
540
541#if EARLY_REF_PIC_MARKING
542Void TDecTop::earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdSet)
543{
544  UInt currTid = m_pcPic->getTLayer();
545  UInt highestTid = (maxTemporalLayer >= 0) ? maxTemporalLayer : (m_pcPic->getSlice(0)->getSPS()->getMaxTLayers() - 1);
546  UInt latestDecLayerId = m_layerId;
547  UInt numTargetDecLayers = 0;
548  Int targetDecLayerIdList[MAX_LAYERS];
549  UInt latestDecIdx = 0;
550  TComSlice* pcSlice = m_pcPic->getSlice(0);
551
552  if ( currTid != highestTid )  // Marking  process is only applicaple for highest decoded TLayer
553  {
554    return;
555  }
556
557  // currPic must be marked as "used for reference" and must be a sub-layer non-reference picture
558  if ( !((pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N  ||
559          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N    ||
560          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N   ||
561          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N   ||
562          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N   ||
563          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N10     ||
564          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N12     ||
565          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N14) && pcSlice->isReferenced()))
566  {
567    return;
568  }
569
570  if ( targetDecLayerIdSet.size() == 0 ) // Cannot mark if we don't know the number of scalable layers
571  {
572    return;
573  }
574
575  for (std::vector<Int>::iterator it = targetDecLayerIdSet.begin(); it != targetDecLayerIdSet.end(); it++)
576  {
577    if ( latestDecLayerId == (*it) )
578    {
579      latestDecIdx = numTargetDecLayers;
580    }
581    targetDecLayerIdList[numTargetDecLayers++] = (*it);
582  }
583
584  Int remainingInterLayerReferencesFlag = 0;
585#if O0225_MAX_TID_FOR_REF_LAYERS
586  for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
587  {
588    Int jLidx = pcSlice->getVPS()->getLayerIdInVps(targetDecLayerIdList[j]);
589    if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId,jLidx) - 1 )
590    {
591#else
592  if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId) - 1 )
593  {
594    for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
595    {
596#endif
597      for ( Int k = 0; k < m_ppcTDecTop[targetDecLayerIdList[j]]->getNumDirectRefLayers(); k++ )
598      {
599        if ( latestDecIdx == m_ppcTDecTop[targetDecLayerIdList[j]]->getRefLayerId(k) )
600        {
601          remainingInterLayerReferencesFlag = 1;
602        }
603      }
604    }
605  }
606
607  if ( remainingInterLayerReferencesFlag == 0 )
608  {
609    pcSlice->setReferenced(false);
610  }
611}
612#endif
613
614Void TDecTop::xCreateLostPicture(Int iLostPoc) 
615{
616  printf("\ninserting lost poc : %d\n",iLostPoc);
617  TComSlice cFillSlice;
618  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
619  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
620#if SVC_EXTENSION
621  cFillSlice.setVPS( m_parameterSetManagerDecoder.getFirstVPS() );
622  cFillSlice.initSlice( m_layerId );
623#else
624  cFillSlice.initSlice();
625#endif
626  TComPic *cFillPic;
627  xGetNewPicBuffer(&cFillSlice,cFillPic);
628  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
629  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
630#if SVC_EXTENSION
631  cFillPic->getSlice(0)->setVPS( m_parameterSetManagerDecoder.getFirstVPS() );
632  cFillPic->getSlice(0)->initSlice( m_layerId );
633#else
634  cFillPic->getSlice(0)->initSlice();
635#endif
636 
637  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
638  Int closestPoc = 1000000;
639  while ( iterPic != m_cListPic.end())
640  {
641    TComPic * rpcPic = *(iterPic++);
642    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)<closestPoc&&abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)!=0&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
643    {
644      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
645    }
646  }
647  iterPic = m_cListPic.begin();
648  while ( iterPic != m_cListPic.end())
649  {
650    TComPic *rpcPic = *(iterPic++);
651    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
652    {
653      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
654      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
655      break;
656    }
657  }
658  cFillPic->setCurrSliceIdx(0);
659  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
660  {
661    cFillPic->getCU(i)->initCU(cFillPic,i);
662  }
663  cFillPic->getSlice(0)->setReferenced(true);
664  cFillPic->getSlice(0)->setPOC(iLostPoc);
665  cFillPic->setReconMark(true);
666  cFillPic->setOutputMark(true);
667  if(m_pocRandomAccess == MAX_INT)
668  {
669    m_pocRandomAccess = iLostPoc;
670  }
671}
672
673
674Void TDecTop::xActivateParameterSets()
675{
676  m_parameterSetManagerDecoder.applyPrefetchedPS();
677 
678  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
679  assert (pps != 0);
680
681  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
682  assert (sps != 0);
683
684  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
685  {
686    printf ("Parameter set activation failed!");
687    assert (0);
688  }
689
690#if SCALINGLIST_INFERRING
691  // scaling list settings and checks
692  TComVPS *activeVPS = m_parameterSetManagerDecoder.getActiveVPS();
693  TComSPS *activeSPS = m_parameterSetManagerDecoder.getActiveSPS();
694  TComPPS *activePPS = m_parameterSetManagerDecoder.getActivePPS();
695
696  if( activeSPS->getInferScalingListFlag() )
697  {
698    UInt refLayerId = activeSPS->getScalingListRefLayerId();
699    TComSPS *refSps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActiveSPS(); assert( refSps != NULL );
700
701    // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
702    if( activeVPS->getAvcBaseLayerFlag() )
703    {
704      assert( refLayerId > 0 );
705    }
706
707    // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
708    // sps_infer_scaling_list_flag in the SPS is equal to 1, sps_infer_scaling_list_flag shall be equal to 0 for the SPS that is active for the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id
709    assert( refSps->getInferScalingListFlag() == false );
710
711    // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
712    // the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
713    assert( activeVPS->getRecursiveRefLayerFlag( activeSPS->getLayerId(), refLayerId ) == true );
714   
715    if( activeSPS->getScalingList() != refSps->getScalingList() )
716    {
717      // delete created instance of scaling list since it will be inferred
718      delete activeSPS->getScalingList();
719
720      // infer scaling list
721      activeSPS->setScalingList( refSps->getScalingList() );
722    }
723  }
724
725  if( activePPS->getInferScalingListFlag() )
726  {
727    UInt refLayerId = activePPS->getScalingListRefLayerId();
728    TComPPS *refPps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActivePPS(); assert( refPps != NULL );
729
730    // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
731    if( activeVPS->getAvcBaseLayerFlag() )
732    {
733      assert( refLayerId > 0 );
734    }
735
736    // It is a requirement of bitstream conformance that, when an PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
737    // pps_infer_scaling_list_flag in the PPS is equal to 1, pps_infer_scaling_list_flag shall be equal to 0 for the PPS that is active for the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id
738    assert( refPps->getInferScalingListFlag() == false );
739
740    // It is a requirement of bitstream conformance that, when an PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
741    // the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
742    assert( activeVPS->getRecursiveRefLayerFlag( activePPS->getLayerId(), refLayerId ) == true );
743   
744    if( activePPS->getScalingList() != refPps->getScalingList() )
745    {
746      // delete created instance of scaling list since it will be inferred
747      delete activePPS->getScalingList();
748
749      // infer scaling list
750      activePPS->setScalingList( refPps->getScalingList() );
751    }
752
753  }
754#endif
755
756#if P0312_VERT_PHASE_ADJ
757  if( activeVPS->getVpsVuiVertPhaseInUseFlag() == 0 )
758  {   
759    for(Int i = 0; i < activeSPS->getNumScaledRefLayerOffsets(); i++)
760    {
761      UInt scaledRefLayerId = activeSPS->getScaledRefLayerId(i);
762      if( activeSPS->getVertPhasePositionEnableFlag( scaledRefLayerId ) )
763      {
764        printf("\nWarning: LayerId = %d: vert_phase_position_enable_flag[%d] = 1, however indication vert_phase_position_in_use_flag = 0\n", m_layerId, scaledRefLayerId );
765        break;
766      }
767    }
768  }
769#endif
770
771#if SPS_DPB_PARAMS
772  if( m_layerId > 0 )
773  {
774    // When not present sps_max_sub_layers_minus1 is inferred to be equal to vps_max_sub_layers_minus1.
775    sps->setMaxTLayers( activeVPS->getMaxTLayers() );
776
777    // When not present sps_temporal_id_nesting_flag is inferred to be equal to vps_temporal_id_nesting_flag
778    sps->setTemporalIdNestingFlag( activeVPS->getTemporalNestingFlag() );
779
780    // When sps_max_dec_pic_buffering_minus1[ i ] is not present for i in the range of 0 to sps_max_sub_layers_minus1, inclusive, due to nuh_layer_id being greater than 0,
781    // it is inferred to be equal to max_vps_dec_pic_buffering_minus1[ TargetOptLayerSetIdx ][ currLayerId ][ i ] of the active VPS, where currLayerId is the nuh_layer_id of the layer that refers to the SPS.
782    for(UInt i=0; i < sps->getMaxTLayers(); i++)
783    {
784      // to avoid compiler warning "array subscript is above array bounds"
785      assert( i < MAX_TLAYER );
786
787      sps->setMaxDecPicBuffering( activeVPS->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), sps->getLayerId(), i) + 1, i);
788    }
789  }
790#endif
791
792  if( pps->getDependentSliceSegmentsEnabledFlag() )
793  {
794    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
795
796    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
797    {
798      m_cSliceDecoder.initCtxMem(NumCtx);
799      for ( UInt st = 0; st < NumCtx; st++ )
800      {
801        TDecSbac* ctx = NULL;
802        ctx = new TDecSbac;
803        ctx->init( &m_cBinCABAC );
804        m_cSliceDecoder.setCtxMem( ctx, st );
805      }
806    }
807  }
808
809  m_apcSlicePilot->setPPS(pps);
810  m_apcSlicePilot->setSPS(sps);
811  pps->setSPS(sps);
812#if REPN_FORMAT_IN_VPS
813  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
814#else
815  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
816#endif
817  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
818
819#if REPN_FORMAT_IN_VPS
820  g_bitDepthY     = m_apcSlicePilot->getBitDepthY();
821  g_bitDepthC     = m_apcSlicePilot->getBitDepthC();
822#else
823  g_bitDepthY     = sps->getBitDepthY();
824  g_bitDepthC     = sps->getBitDepthC();
825#endif
826  g_uiMaxCUWidth  = sps->getMaxCUWidth();
827  g_uiMaxCUHeight = sps->getMaxCUHeight();
828  g_uiMaxCUDepth  = sps->getMaxCUDepth();
829  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
830
831  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
832  {
833    sps->setAMPAcc( i, sps->getUseAMP() );
834  }
835
836  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
837  {
838    sps->setAMPAcc( i, 0 );
839  }
840
841  m_cSAO.destroy();
842#if REPN_FORMAT_IN_VPS
843#if AUXILIARY_PICTURES
844  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
845#else
846  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
847#endif
848#else
849  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
850#endif
851  m_cLoopFilter.create( sps->getMaxCUDepth() );
852}
853
854#if SVC_EXTENSION
855#if POC_RESET_FLAG
856Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int &iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
857#else
858Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
859#endif
860#else
861Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
862#endif
863{
864  TComPic*&   pcPic         = m_pcPic;
865#if SVC_EXTENSION
866  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getPrefetchedVPS(0) );
867#if OUTPUT_LAYER_SET_INDEX
868  // Following check should go wherever the VPS is activated
869  checkValueOfTargetOutputLayerSetIdx( m_apcSlicePilot->getVPS());
870#endif
871#if RESOLUTION_BASED_DPB
872  // Following assignment should go wherever a new VPS is activated
873  assignSubDpbs(m_apcSlicePilot->getVPS());
874#endif
875  m_apcSlicePilot->initSlice( nalu.m_layerId );
876#else //SVC_EXTENSION
877  m_apcSlicePilot->initSlice();
878#endif
879
880  if (m_bFirstSliceInPicture)
881  {
882    m_uiSliceIdx     = 0;
883  }
884  else
885  {
886    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
887  }
888  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
889
890  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
891  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
892                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
893                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
894                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
895                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
896  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
897 
898  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
899  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
900
901#if SVC_EXTENSION
902#if VPS_EXTN_DIRECT_REF_LAYERS
903  setRefLayerParams(m_apcSlicePilot->getVPS());
904#endif
905  m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers);
906#endif
907  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
908
909  // set POC for dependent slices in skipped pictures
910  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
911  {
912    m_apcSlicePilot->setPOC(m_skippedPOC);
913  }
914
915  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
916  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
917
918#if SETTING_NO_OUT_PIC_PRIOR
919  //For inference of NoOutputOfPriorPicsFlag
920  if (m_apcSlicePilot->getRapPicFlag())
921  {
922    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
923        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
924        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
925    {
926      m_apcSlicePilot->setNoRaslOutputFlag(true);
927    }
928    //the inference for NoOutputPriorPicsFlag
929    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
930    {
931      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
932      {
933        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
934      }
935    }
936    else
937    {
938      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
939    }
940
941    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
942    {
943      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
944    }
945  }
946  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
947  {
948    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
949    m_isNoOutputPriorPics = true;
950  }
951  else
952  {
953    m_isNoOutputPriorPics = false;
954  }
955
956  //For inference of PicOutputFlag
957  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
958  {
959    if ( m_craNoRaslOutputFlag )
960    {
961      m_apcSlicePilot->setPicOutputFlag(false);
962    }
963  }
964#endif
965
966#if FIX_POC_CRA_NORASL_OUTPUT
967  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
968  {
969    Int iMaxPOClsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
970    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
971  }
972#endif
973
974  // Skip pictures due to random access
975  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
976  {
977    m_prevSliceSkipped = true;
978    m_skippedPOC = m_apcSlicePilot->getPOC();
979    return false;
980  }
981  // Skip TFD pictures associated with BLA/BLANT pictures
982  if (isSkipPictureForBLA(iPOCLastDisplay))
983  {
984    m_prevSliceSkipped = true;
985    m_skippedPOC = m_apcSlicePilot->getPOC();
986    return false;
987  }
988
989  // clear previous slice skipped flag
990  m_prevSliceSkipped = false;
991
992  // exit when a new picture is found
993#if SVC_EXTENSION
994  bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC);
995
996#if NO_OUTPUT_OF_PRIOR_PICS
997#if NO_CLRAS_OUTPUT_FLAG
998  if (m_layerId == 0 && m_apcSlicePilot->getRapPicFlag() )
999  {
1000    if (m_bFirstSliceInSequence)
1001    {
1002      setNoClrasOutputFlag(true);
1003    }
1004    else if ( m_apcSlicePilot->getBlaPicFlag() )
1005    {
1006      setNoClrasOutputFlag(true);
1007    }
1008#if O0149_CROSS_LAYER_BLA_FLAG
1009    else if (m_apcSlicePilot->getIdrPicFlag() && m_apcSlicePilot->getCrossLayerBLAFlag())
1010    {
1011      setNoClrasOutputFlag(true);
1012    }
1013#endif
1014    else
1015    {
1016      setNoClrasOutputFlag(false);
1017    }     
1018  }
1019  else
1020  {
1021    setNoClrasOutputFlag(false);
1022  }
1023
1024  m_apcSlicePilot->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, m_cListPic, getNoClrasOutputFlag());
1025#endif
1026
1027  // Derive the value of NoOutputOfPriorPicsFlag
1028  if( bNewPOC || m_layerId!=m_uiPrevLayerId )   // i.e. new coded picture
1029  {
1030    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getNoRaslOutputFlag() )
1031    {
1032      this->setNoOutputPriorPicsFlag( true );
1033    }
1034    else if( m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag() )
1035    {
1036      this->setNoOutputPriorPicsFlag( m_apcSlicePilot->getNoOutputPriorPicsFlag() );
1037    }
1038    else
1039    {
1040      if( this->m_ppcTDecTop[0]->getNoClrasOutputFlag() )
1041      {
1042        this->setNoOutputPriorPicsFlag( true );
1043      }
1044    }
1045  }
1046#endif
1047
1048#if ALIGNED_BUMPING
1049  if (bNewPOC || m_layerId!=m_uiPrevLayerId)
1050  {
1051    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
1052  }
1053#endif
1054  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
1055  {
1056    m_prevPOC = m_apcSlicePilot->getPOC();
1057    curLayerId = m_uiPrevLayerId; 
1058    m_uiPrevLayerId = m_layerId;
1059    return true;
1060  }
1061#else
1062  //we should only get a different poc for a new picture (with CTU address==0)
1063  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
1064  {
1065    printf ("Warning, the first slice of a picture might have been lost!\n");
1066  }
1067  // exit when a new picture is found
1068  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
1069  {
1070    if (m_prevPOC >= m_pocRandomAccess)
1071    {
1072      m_prevPOC = m_apcSlicePilot->getPOC();
1073      return true;
1074    }
1075    m_prevPOC = m_apcSlicePilot->getPOC();
1076  }
1077#endif
1078  // actual decoding starts here
1079  xActivateParameterSets();
1080#if !O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS && N0147_IRAP_ALIGN_FLAG
1081  //Note setting O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS to 0 may cause decoder to crash.
1082  //When cross_layer_irap_aligned_flag is equal to 0, num_extra_slice_header_bits >=1
1083  if(!m_apcSlicePilot->getVPS()->getCrossLayerIrapAlignFlag() )
1084  {
1085    assert( m_apcSlicePilot->getPPS()->getNumExtraSliceHeaderBits() > 0);
1086  }
1087  //When cross_layer_irap_aligned_flag is equal to 1, the value of poc_reset_flag shall be equal to 0 
1088  if( m_apcSlicePilot->getVPS()->getCrossLayerIrapAlignFlag() )
1089  {
1090    assert( m_apcSlicePilot->getPocResetFlag() == 0);
1091  }
1092#endif
1093#if REPN_FORMAT_IN_VPS
1094  // Initialize ILRP if needed, only for the current layer 
1095  // ILRP intialization should go along with activation of parameters sets,
1096  // although activation of parameter sets itself need not be done for each and every slice!!!
1097  xInitILRP(m_apcSlicePilot);
1098#endif
1099  if (m_apcSlicePilot->isNextSlice()) 
1100  {
1101    m_prevPOC = m_apcSlicePilot->getPOC();
1102#if SVC_EXTENSION
1103    curLayerId = m_layerId;
1104    m_uiPrevLayerId = m_layerId;
1105#endif
1106  }
1107  m_bFirstSliceInSequence = false;
1108#if SETTING_NO_OUT_PIC_PRIOR 
1109  m_bFirstSliceInBitstream  = false;
1110#endif
1111#if POC_RESET_FLAG
1112  // This operation would do the following:
1113  // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
1114  // 2. Update the value of m_pocCRA.
1115  // 3. Reset the POC values at the decoder for the current picture to be zero.
1116  // 4. update value of POCLastDisplay
1117  if( m_apcSlicePilot->getPocResetFlag() )
1118  {
1119    if( m_apcSlicePilot->getSliceIdx() == 0 )
1120    {
1121      Int pocAdjustValue = m_apcSlicePilot->getPOC();
1122
1123#if PREVTID0_POC_RESET
1124      m_apcSlicePilot->adjustPrevTid0POC(pocAdjustValue);
1125#endif
1126      // If poc reset flag is set to 1, reset all POC for DPB -> basically do it for each slice in the picutre
1127      TComList<TComPic*>::iterator  iterPic = m_cListPic.begin(); 
1128
1129      // Iterate through all picture in DPB
1130      while( iterPic != m_cListPic.end() )
1131      {
1132        TComPic *dpbPic = *iterPic;
1133        // Check if the picture pointed to by iterPic is either used for reference or
1134        // needed for output, are in the same layer, and not the current picture.
1135        if( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
1136            &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
1137              && ( dpbPic->getReconMark() ) 
1138          )
1139        {
1140          for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
1141          {
1142
1143            TComSlice *slice = dpbPic->getSlice(i);
1144            TComReferencePictureSet *rps = slice->getRPS();
1145            slice->setPOC( slice->getPOC() - pocAdjustValue );
1146
1147            // Also adjust the POC value stored in the RPS of each such slice
1148            for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
1149            {
1150              rps->setPOC( j, rps->getPOC(j) - pocAdjustValue );
1151            }
1152            // Also adjust the value of refPOC
1153            for(Int k = 0; k < 2; k++)  // For List 0 and List 1
1154            {
1155              RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
1156              for(Int j = 0; j < slice->getNumRefIdx(list); j++)
1157              {
1158                slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j);
1159              }
1160            }
1161          }
1162        }
1163        iterPic++;
1164      }
1165      // Update the value of pocCRA
1166      m_pocCRA -= pocAdjustValue;
1167      // Update value of POCLastDisplay
1168      iPOCLastDisplay -= pocAdjustValue;
1169    }
1170    // Reset current poc for current slice and RPS
1171    m_apcSlicePilot->setPOC( 0 );
1172  }
1173#endif
1174#if ALIGN_TSA_STSA_PICS
1175  if( m_apcSlicePilot->getLayerId() > 0 )
1176  {
1177    // Check for TSA alignment
1178    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
1179        m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R
1180         )
1181    {
1182      for(Int dependentLayerIdx = 0; dependentLayerIdx < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1183      {
1184        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1185        TComPic* refpicLayer = m_apcSlicePilot->getRefPic(*cListPic, m_apcSlicePilot->getPOC() );
1186        if( refpicLayer )
1187        {
1188          assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
1189                    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R );    // TSA pictures should be aligned among depenedent layers
1190        } 
1191      }
1192    }
1193    // Check for STSA alignment
1194    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ||
1195         m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R
1196         )
1197    {
1198      for(Int dependentLayerIdx = 0; dependentLayerIdx < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1199      {
1200        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1201        TComPic* refpicLayer = m_apcSlicePilot->getRefPic(*cListPic, m_apcSlicePilot->getPOC() ); // STSA pictures should be aligned among dependent layers
1202        if( refpicLayer )
1203
1204        {
1205          assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ||
1206                    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R );
1207        }
1208      }
1209    }
1210  }
1211#endif
1212  //detect lost reference picture and insert copy of earlier frame.
1213  Int lostPoc;
1214  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
1215  {
1216    xCreateLostPicture(lostPoc-1);
1217  }
1218  if (m_bFirstSliceInPicture)
1219  {
1220#if AVC_BASE
1221    if( m_layerId == 1 && m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1222    {
1223      TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
1224      pBLPic->getSlice(0)->setReferenced(true);
1225      fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
1226      UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth();
1227      UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight();
1228
1229      if( pFile->good() )
1230      {
1231        UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
1232
1233        pFile->seekg((UInt)uiPos, ios::beg );
1234
1235        Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
1236        UInt uiStride = pBLPic->getPicYuvRec()->getStride();
1237        for( Int i = 0; i < uiHeight; i++ )
1238        {
1239          for( Int j = 0; j < uiWidth; j++ )
1240          {
1241            pPel[j] = pFile->get();
1242          }
1243          pPel += uiStride;
1244        }
1245
1246        pPel = pBLPic->getPicYuvRec()->getCbAddr();
1247        uiStride = pBLPic->getPicYuvRec()->getCStride();
1248        for( Int i = 0; i < uiHeight/2; i++ )
1249        {
1250          for( Int j = 0; j < uiWidth/2; j++ )
1251          {
1252            pPel[j] = pFile->get();
1253          }
1254          pPel += uiStride;
1255        }
1256
1257        pPel = pBLPic->getPicYuvRec()->getCrAddr();
1258        uiStride = pBLPic->getPicYuvRec()->getCStride();
1259        for( Int i = 0; i < uiHeight/2; i++ )
1260        {
1261          for( Int j = 0; j < uiWidth/2; j++ )
1262          {
1263            pPel[j] = pFile->get();
1264          }
1265          pPel += uiStride;
1266        }
1267      }
1268    }
1269#endif
1270
1271#if NO_OUTPUT_OF_PRIOR_PICS
1272    if ( m_layerId == 0 && m_apcSlicePilot->getRapPicFlag() && getNoClrasOutputFlag() )
1273    {
1274      for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getMaxLayers(); i++)
1275      {
1276        m_ppcTDecTop[i]->setLayerInitializedFlag(false);
1277        m_ppcTDecTop[i]->setFirstPicInLayerDecodedFlag(false);
1278      }
1279    }
1280#endif
1281    // Buffer initialize for prediction.
1282    m_cPrediction.initTempBuff();
1283#if ALIGNED_BUMPING
1284    m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic);
1285#else
1286    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
1287#endif
1288    //  Get a new picture buffer
1289    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
1290
1291    Bool isField = false;
1292    Bool isTff = false;
1293   
1294    if(!m_SEIs.empty())
1295    {
1296      // Check if any new Picture Timing SEI has arrived
1297      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
1298      if (pictureTimingSEIs.size()>0)
1299      {
1300        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
1301        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
1302        isTff =  (pictureTiming->m_picStruct == 1);
1303      }
1304    }
1305   
1306    //Set Field/Frame coding mode
1307    m_pcPic->setField(isField);
1308    m_pcPic->setTopField(isTff);
1309
1310    // transfer any SEI messages that have been received to the picture
1311    pcPic->setSEIs(m_SEIs);
1312    m_SEIs.clear();
1313
1314    // Recursive structure
1315    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
1316#if SVC_EXTENSION
1317    m_cCuDecoder.init   ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId );
1318#else
1319    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
1320#endif
1321    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
1322
1323    m_cSliceDecoder.create();
1324  }
1325  else
1326  {
1327    // Check if any new SEI has arrived
1328    if(!m_SEIs.empty())
1329    {
1330      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
1331      SEIMessages &picSEI = pcPic->getSEIs();
1332      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
1333      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
1334      deleteSEIs(m_SEIs);
1335    }
1336  }
1337 
1338  //  Set picture slice pointer
1339  TComSlice*  pcSlice = m_apcSlicePilot;
1340  Bool bNextSlice     = pcSlice->isNextSlice();
1341
1342  UInt uiCummulativeTileWidth;
1343  UInt uiCummulativeTileHeight;
1344  UInt i, j, p;
1345
1346  //set NumColumnsMins1 and NumRowsMinus1
1347  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
1348  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
1349
1350  //create the TComTileArray
1351  pcPic->getPicSym()->xCreateTComTileArray();
1352
1353  if( pcSlice->getPPS()->getUniformSpacingFlag() )
1354  {
1355    //set the width for each tile
1356    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
1357    {
1358      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
1359      {
1360        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
1361          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
1362          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
1363      }
1364    }
1365
1366    //set the height for each tile
1367    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
1368    {
1369      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
1370      {
1371        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
1372          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
1373          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
1374      }
1375    }
1376  }
1377  else
1378  {
1379    //set the width for each tile
1380    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
1381    {
1382      uiCummulativeTileWidth = 0;
1383      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
1384      {
1385        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
1386        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
1387      }
1388      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
1389    }
1390
1391    //set the height for each tile
1392    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
1393    {
1394      uiCummulativeTileHeight = 0;
1395      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
1396      { 
1397        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
1398        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
1399      }
1400      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
1401    }
1402  }
1403
1404  pcPic->getPicSym()->xInitTiles();
1405
1406  //generate the Coding Order Map and Inverse Coding Order Map
1407  UInt uiEncCUAddr;
1408  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
1409  {
1410    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
1411    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
1412  }
1413  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1414  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1415
1416  //convert the start and end CU addresses of the slice and dependent slice into encoding order
1417  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
1418  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
1419  if(pcSlice->isNextSlice())
1420  {
1421    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
1422    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
1423  }
1424
1425  if (m_bFirstSliceInPicture) 
1426  {
1427    if(pcPic->getNumAllocatedSlice() != 1)
1428    {
1429      pcPic->clearSliceBuffer();
1430    }
1431  }
1432  else
1433  {
1434    pcPic->allocateNewSlice();
1435  }
1436  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
1437  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
1438  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
1439
1440  pcPic->setTLayer(nalu.m_temporalId);
1441
1442#if SVC_EXTENSION
1443  pcPic->setLayerId(nalu.m_layerId);
1444  pcSlice->setLayerId(nalu.m_layerId);
1445  pcSlice->setPic(pcPic);
1446#endif
1447
1448  if (bNextSlice)
1449  {
1450    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
1451    // Set reference list
1452#if SVC_EXTENSION
1453    if (m_layerId == 0)
1454#endif
1455    pcSlice->setRefPicList( m_cListPic, true );
1456
1457#if SVC_EXTENSION
1458    // Create upsampling reference layer pictures for all possible dependent layers and do it only once for the first slice.
1459    // Other slices might choose which reference pictures to be used for inter-layer prediction
1460    if( m_layerId > 0 && m_uiSliceIdx == 0 )
1461    {     
1462#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1463      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
1464#endif
1465      for( i = 0; i < pcSlice->getNumILRRefIdx(); i++ )
1466      {
1467        UInt refLayerIdc = i;
1468#if AVC_BASE
1469        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
1470        {         
1471          TComPic* pic = *m_ppcTDecTop[0]->getListPic()->begin();
1472
1473          if( pic )
1474          {
1475            pcSlice->setBaseColPic ( refLayerIdc, pic );
1476          }
1477          else
1478          {
1479            continue;
1480          }
1481#if AVC_SYNTAX
1482          TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
1483          if( pcSlice->getPOC() == 0 )
1484          {
1485            // initialize partition order.
1486            UInt* piTmp = &g_auiZscanToRaster[0];
1487            initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
1488            initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
1489          }     
1490          pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
1491          pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
1492#endif
1493        }
1494        else
1495        {
1496#if VPS_EXTN_DIRECT_REF_LAYERS
1497          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1498#else
1499          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1500#endif
1501          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1502          if( !pcSlice->setBaseColPic ( *cListPic, refLayerIdc ) )
1503          {
1504            continue;
1505          }
1506        }
1507#else
1508#if VPS_EXTN_DIRECT_REF_LAYERS
1509        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1510#else
1511        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1512#endif
1513        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1514        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1515#endif
1516
1517#if O0098_SCALED_REF_LAYER_ID
1518        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
1519#else
1520        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
1521#endif
1522
1523        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
1524        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
1525
1526        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
1527        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
1528
1529        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
1530        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
1531
1532        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
1533        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
1534
1535#if SVC_UPSAMPLING
1536        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
1537        {   
1538/*#if O0098_SCALED_REF_LAYER_ID
1539          Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
1540#else
1541          Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
1542#endif*/
1543#if O0215_PHASE_ALIGNMENT
1544#if O0194_JOINT_US_BITSHIFT
1545          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
1546#else
1547          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
1548#endif
1549#else
1550#if O0194_JOINT_US_BITSHIFT
1551          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
1552#else
1553          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
1554#endif
1555#endif
1556        }
1557        else
1558        {
1559          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
1560        }
1561        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
1562#endif
1563      }
1564    }
1565
1566    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
1567    {
1568      for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
1569      {
1570        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
1571#if AVC_BASE
1572        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
1573        {
1574          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
1575#if AVC_SYNTAX
1576          TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
1577          if( pcSlice->getPOC() == 0 )
1578          {
1579            // initialize partition order.
1580            UInt* piTmp = &g_auiZscanToRaster[0];
1581            initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
1582            initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
1583          }     
1584          pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
1585          pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
1586#endif
1587        }
1588        else
1589        {
1590#if VPS_EXTN_DIRECT_REF_LAYERS
1591          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1592#else
1593          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1594#endif
1595          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1596          pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1597        }
1598#else
1599#if VPS_EXTN_DIRECT_REF_LAYERS
1600        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1601#else
1602        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1603#endif
1604        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1605        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1606#endif
1607
1608        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
1609      }
1610
1611      pcSlice->setILRPic( m_cIlpPic );
1612
1613#if REF_IDX_MFM
1614      if( pcSlice->getMFMEnabledFlag() )
1615      {
1616        pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
1617      }
1618      pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
1619    }
1620#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1621    else if ( m_layerId > 0 )
1622    {
1623      pcSlice->setRefPicList( m_cListPic, false, NULL);
1624    }
1625#endif
1626#if MFM_ENCCONSTRAINT
1627    if( pcSlice->getMFMEnabledFlag() )
1628    {
1629      Int refLayerId = pcSlice->getRefPic( pcSlice->getSliceType() == B_SLICE ? ( RefPicList )( 1 - pcSlice->getColFromL0Flag() ) : REF_PIC_LIST_0 , pcSlice->getColRefIdx() )->getLayerId();
1630      if( refLayerId != pcSlice->getLayerId() )
1631      {
1632        TComPic* pColBasePic = pcSlice->getBaseColPic( *m_ppcTDecTop[refLayerId]->getListPic() );
1633        assert( pColBasePic->checkSameRefInfo() == true );
1634      }
1635    }
1636#endif
1637#endif
1638   
1639#if N0147_IRAP_ALIGN_FLAG
1640    if( m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag() )
1641    {
1642#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1643      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
1644#endif
1645      for(Int dependentLayerIdx = 0; dependentLayerIdx < pcSlice->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1646      {
1647        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1648        TComPic* refpicLayer = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
1649        if(refpicLayer && pcSlice->isIRAP())
1650        {                 
1651          assert(pcSlice->getNalUnitType() == refpicLayer->getSlice(0)->getNalUnitType());
1652        }
1653      }
1654    }
1655#endif
1656#endif //SVC_EXTENSION
1657   
1658    // For generalized B
1659    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1660    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1661    {
1662      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1663      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1664
1665      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1666      {
1667        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1668      }
1669    }
1670    if (!pcSlice->isIntra())
1671    {
1672      Bool bLowDelay = true;
1673      Int  iCurrPOC  = pcSlice->getPOC();
1674      Int iRefIdx = 0;
1675
1676      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1677      {
1678        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1679        {
1680          bLowDelay = false;
1681        }
1682      }
1683      if (pcSlice->isInterB())
1684      {
1685        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1686        {
1687          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1688          {
1689            bLowDelay = false;
1690          }
1691        }       
1692      }
1693
1694      pcSlice->setCheckLDC(bLowDelay);           
1695    }
1696
1697    //---------------
1698    pcSlice->setRefPOCList();
1699  }
1700
1701  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1702  if(pcSlice->getSPS()->getScalingListFlag())
1703  {
1704    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
1705    if(pcSlice->getPPS()->getScalingListPresentFlag())
1706    {
1707      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
1708    }
1709#if SCALINGLIST_INFERRING
1710    if( m_layerId == 0 || ( m_layerId > 0 && !pcSlice->getPPS()->getInferScalingListFlag() && !pcSlice->getSPS()->getInferScalingListFlag() ) )
1711#endif
1712    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1713    {
1714      pcSlice->setDefaultScalingList();
1715    }
1716    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1717    m_cTrQuant.setUseScalingList(true);
1718  }
1719  else
1720  {
1721    m_cTrQuant.setFlatScalingList();
1722    m_cTrQuant.setUseScalingList(false);
1723  }
1724
1725  //  Decode a picture
1726  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1727
1728  m_bFirstSliceInPicture = false;
1729  m_uiSliceIdx++;
1730
1731  return false;
1732}
1733
1734Void TDecTop::xDecodeVPS()
1735{
1736  TComVPS* vps = new TComVPS();
1737 
1738  m_cEntropyDecoder.decodeVPS( vps );
1739  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1740}
1741
1742Void TDecTop::xDecodeSPS()
1743{
1744  TComSPS* sps = new TComSPS();
1745#if SVC_EXTENSION
1746  sps->setLayerId(m_layerId);
1747#if SPS_DPB_PARAMS
1748  m_cEntropyDecoder.decodeSPS( sps ); // it should be removed after macro clean up
1749#else
1750  m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder );
1751#endif
1752  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1753#if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation 
1754  if(m_numLayer>0)
1755  {
1756    xInitILRP(sps);
1757  }
1758#endif
1759#else //SVC_EXTENSION
1760  m_cEntropyDecoder.decodeSPS( sps );
1761  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1762#endif //SVC_EXTENSION
1763}
1764
1765Void TDecTop::xDecodePPS()
1766{
1767  TComPPS* pps = new TComPPS();
1768
1769#if SCALINGLIST_INFERRING
1770  pps->setLayerId( m_layerId );
1771#endif
1772
1773  m_cEntropyDecoder.decodePPS( pps );
1774  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1775
1776  if( pps->getDependentSliceSegmentsEnabledFlag() )
1777  {
1778    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
1779    m_cSliceDecoder.initCtxMem(NumCtx);
1780    for ( UInt st = 0; st < NumCtx; st++ )
1781    {
1782      TDecSbac* ctx = NULL;
1783      ctx = new TDecSbac;
1784      ctx->init( &m_cBinCABAC );
1785      m_cSliceDecoder.setCtxMem( ctx, st );
1786    }
1787  }
1788}
1789
1790Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1791{
1792#if SVC_EXTENSION
1793  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1794  {
1795#if RANDOM_ACCESS_SEI_FIX
1796    if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
1797    {
1798      return;
1799    }
1800#endif
1801#if LAYERS_NOT_PRESENT_SEI
1802    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1803#else
1804    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1805#endif
1806  }
1807  else
1808  {
1809#if LAYERS_NOT_PRESENT_SEI
1810    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1811#else
1812    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1813#endif
1814    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1815    if (activeParamSets.size()>0)
1816    {
1817      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1818      m_parameterSetManagerDecoder.applyPrefetchedPS();
1819      assert(seiAps->activeSeqParameterSetId.size()>0);
1820      if( !m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[0] ) )
1821      {
1822        printf ("Warning SPS activation with Active parameter set SEI failed");
1823      }
1824    }
1825  }
1826#else
1827  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1828  {
1829#if LAYERS_NOT_PRESENT_SEI
1830    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1831#else
1832    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1833#endif
1834  }
1835  else
1836  {
1837#if LAYERS_NOT_PRESENT_SEI
1838    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1839#else
1840    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1841#endif
1842    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1843    if (activeParamSets.size()>0)
1844    {
1845      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1846      m_parameterSetManagerDecoder.applyPrefetchedPS();
1847      assert(seiAps->activeSeqParameterSetId.size()>0);
1848      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
1849      {
1850        printf ("Warning SPS activation with Active parameter set SEI failed");
1851      }
1852    }
1853  }
1854#endif
1855}
1856
1857#if SVC_EXTENSION
1858Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
1859#else
1860Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1861#endif
1862{
1863  // Initialize entropy decoder
1864  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1865  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1866
1867#if O0137_MAX_LAYERID
1868  // ignore any NAL units with nuh_layer_id == 63
1869  if (nalu.m_layerId == 63 )
1870  { 
1871    return false;
1872  }
1873#endif
1874  switch (nalu.m_nalUnitType)
1875  {
1876    case NAL_UNIT_VPS:
1877#if VPS_NUH_LAYER_ID
1878      assert( nalu.m_layerId == 0 ); // Non-conforming bitstream. The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
1879#endif
1880      xDecodeVPS();
1881#if AVC_BASE
1882      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1883      {
1884        if( !m_ppcTDecTop[0]->getBLReconFile()->good() )
1885        {
1886          printf( "Base layer YUV input reading error\n" );
1887          exit(EXIT_FAILURE);
1888        }       
1889#if AVC_SYNTAX
1890        if( !m_ppcTDecTop[0]->getBLSyntaxFile()->good() )
1891        {
1892          printf( "Base layer syntax input reading error\n" );
1893          exit(EXIT_FAILURE);
1894        }
1895#endif
1896      }
1897      else
1898      {
1899        TComList<TComPic*> *cListPic = m_ppcTDecTop[0]->getListPic();
1900        cListPic->clear();
1901      }
1902#endif
1903      return false;
1904     
1905    case NAL_UNIT_SPS:
1906      xDecodeSPS();
1907#if AVC_BASE
1908      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1909      {
1910        TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
1911        if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
1912        {
1913          // using EL SPS with spsId = 1
1914          TComSPS* sps = m_parameterSetManagerDecoder.getPrefetchedSPS(1);
1915          Int  numReorderPics[MAX_TLAYER];
1916          Window &conformanceWindow = sps->getConformanceWindow();
1917          Window defaultDisplayWindow = sps->getVuiParametersPresentFlag() ? sps->getVuiParameters()->getDefaultDisplayWindow() : Window();
1918#if AUXILIARY_PICTURES
1919#if SVC_UPSAMPLING
1920#if AVC_SYNTAX
1921          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
1922#else
1923          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
1924#endif
1925#else
1926          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
1927#endif
1928#else
1929#if SVC_UPSAMPLING
1930#if AVC_SYNTAX
1931          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
1932#else
1933          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
1934#endif
1935#else
1936          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
1937#endif
1938#endif
1939
1940#if O0194_DIFFERENT_BITDEPTH_EL_BL
1941          // set AVC BL bit depth, can be an input parameter from the command line
1942          g_bitDepthYLayer[0] = 8;
1943          g_bitDepthCLayer[0] = 8;
1944#endif
1945        }
1946      }
1947#endif
1948      return false;
1949
1950    case NAL_UNIT_PPS:
1951      xDecodePPS();
1952      return false;
1953     
1954    case NAL_UNIT_PREFIX_SEI:
1955    case NAL_UNIT_SUFFIX_SEI:
1956      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1957      return false;
1958
1959    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1960    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1961    case NAL_UNIT_CODED_SLICE_TSA_R:
1962    case NAL_UNIT_CODED_SLICE_TSA_N:
1963    case NAL_UNIT_CODED_SLICE_STSA_R:
1964    case NAL_UNIT_CODED_SLICE_STSA_N:
1965    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1966    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1967    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1968    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1969    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1970    case NAL_UNIT_CODED_SLICE_CRA:
1971    case NAL_UNIT_CODED_SLICE_RADL_N:
1972    case NAL_UNIT_CODED_SLICE_RADL_R:
1973    case NAL_UNIT_CODED_SLICE_RASL_N:
1974    case NAL_UNIT_CODED_SLICE_RASL_R:
1975#if SVC_EXTENSION
1976      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
1977#else
1978      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1979#endif
1980      break;
1981     
1982    case NAL_UNIT_EOS:
1983      m_associatedIRAPType = NAL_UNIT_INVALID;
1984      m_pocCRA = 0;
1985      m_pocRandomAccess = MAX_INT;
1986      m_prevPOC = MAX_INT;
1987      m_bFirstSliceInPicture = true;
1988      m_bFirstSliceInSequence = true;
1989      m_prevSliceSkipped = false;
1990      m_skippedPOC = 0;
1991      return false;
1992     
1993    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
1994      // TODO: process AU delimiter
1995      return false;
1996     
1997    case NAL_UNIT_EOB:
1998#if P0130_EOB
1999      //Check layer id of the nalu. if it is not 0, give a warning message.
2000      if (nalu.m_layerId > 0)
2001      {
2002        printf( "\n\nThis bitstream is ended with EOB NALU that has layer id greater than 0\n" );
2003      }
2004#endif
2005      return false;
2006     
2007    case NAL_UNIT_FILLER_DATA:
2008      return false;
2009     
2010    case NAL_UNIT_RESERVED_VCL_N10:
2011    case NAL_UNIT_RESERVED_VCL_R11:
2012    case NAL_UNIT_RESERVED_VCL_N12:
2013    case NAL_UNIT_RESERVED_VCL_R13:
2014    case NAL_UNIT_RESERVED_VCL_N14:
2015    case NAL_UNIT_RESERVED_VCL_R15:
2016     
2017    case NAL_UNIT_RESERVED_IRAP_VCL22:
2018    case NAL_UNIT_RESERVED_IRAP_VCL23:
2019     
2020    case NAL_UNIT_RESERVED_VCL24:
2021    case NAL_UNIT_RESERVED_VCL25:
2022    case NAL_UNIT_RESERVED_VCL26:
2023    case NAL_UNIT_RESERVED_VCL27:
2024    case NAL_UNIT_RESERVED_VCL28:
2025    case NAL_UNIT_RESERVED_VCL29:
2026    case NAL_UNIT_RESERVED_VCL30:
2027    case NAL_UNIT_RESERVED_VCL31:
2028     
2029    case NAL_UNIT_RESERVED_NVCL41:
2030    case NAL_UNIT_RESERVED_NVCL42:
2031    case NAL_UNIT_RESERVED_NVCL43:
2032    case NAL_UNIT_RESERVED_NVCL44:
2033    case NAL_UNIT_RESERVED_NVCL45:
2034    case NAL_UNIT_RESERVED_NVCL46:
2035    case NAL_UNIT_RESERVED_NVCL47:
2036    case NAL_UNIT_UNSPECIFIED_48:
2037    case NAL_UNIT_UNSPECIFIED_49:
2038    case NAL_UNIT_UNSPECIFIED_50:
2039    case NAL_UNIT_UNSPECIFIED_51:
2040    case NAL_UNIT_UNSPECIFIED_52:
2041    case NAL_UNIT_UNSPECIFIED_53:
2042    case NAL_UNIT_UNSPECIFIED_54:
2043    case NAL_UNIT_UNSPECIFIED_55:
2044    case NAL_UNIT_UNSPECIFIED_56:
2045    case NAL_UNIT_UNSPECIFIED_57:
2046    case NAL_UNIT_UNSPECIFIED_58:
2047    case NAL_UNIT_UNSPECIFIED_59:
2048    case NAL_UNIT_UNSPECIFIED_60:
2049    case NAL_UNIT_UNSPECIFIED_61:
2050    case NAL_UNIT_UNSPECIFIED_62:
2051    case NAL_UNIT_UNSPECIFIED_63:
2052
2053    default:
2054      assert (0);
2055  }
2056
2057  return false;
2058}
2059
2060/** Function for checking if picture should be skipped because of association with a previous BLA picture
2061 * \param iPOCLastDisplay POC of last picture displayed
2062 * \returns true if the picture should be skipped
2063 * This function skips all TFD pictures that follow a BLA picture
2064 * in decoding order and precede it in output order.
2065 */
2066Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
2067{
2068  if ((m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_N_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_RADL) && 
2069       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
2070  {
2071    iPOCLastDisplay++;
2072    return true;
2073  }
2074  return false;
2075}
2076
2077/** Function for checking if picture should be skipped because of random access
2078 * \param iSkipFrame skip frame counter
2079 * \param iPOCLastDisplay POC of last picture displayed
2080 * \returns true if the picture shold be skipped in the random access.
2081 * This function checks the skipping of pictures in the case of -s option random access.
2082 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
2083 * It also checks the type of Nal unit type at the random access point.
2084 * If the random access point is CRA/CRANT/BLA/BLANT, TFD pictures with POC less than the POC of the random access point are skipped.
2085 * If the random access point is IDR all pictures after the random access point are decoded.
2086 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
2087 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
2088 * access point there is no guarantee that the decoder will not crash.
2089 */
2090Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
2091{
2092  if (iSkipFrame) 
2093  {
2094    iSkipFrame--;   // decrement the counter
2095    return true;
2096  }
2097  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
2098  {
2099    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
2100        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2101        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
2102        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
2103    {
2104      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
2105      m_pocRandomAccess = m_apcSlicePilot->getPOC();
2106    }
2107    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
2108    {
2109      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
2110    }
2111    else 
2112    {
2113      static Bool warningMessage = false;
2114      if(!warningMessage)
2115      {
2116        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
2117        warningMessage = true;
2118      }
2119      return true;
2120    }
2121  }
2122  // skip the reordered pictures, if necessary
2123  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
2124  {
2125    iPOCLastDisplay++;
2126    return true;
2127  }
2128  // if we reach here, then the picture is not skipped.
2129  return false; 
2130}
2131
2132#if SVC_EXTENSION
2133#if VPS_EXTN_DIRECT_REF_LAYERS
2134TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc )
2135{
2136  TComVPS* vps = m_parameterSetManagerDecoder.getActiveVPS();
2137  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
2138  {
2139    return (TDecTop *)getLayerDec( 0 );
2140  }
2141 
2142  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdc ) );
2143}
2144#endif
2145
2146#if VPS_EXTN_DIRECT_REF_LAYERS
2147Void TDecTop::setRefLayerParams( TComVPS* vps )
2148{
2149  for(UInt layer = 0; layer < m_numLayer; layer++)
2150  {
2151    TDecTop *decTop = (TDecTop *)getLayerDec(layer);
2152    decTop->setNumSamplePredRefLayers(0);
2153    decTop->setNumMotionPredRefLayers(0);
2154    decTop->setNumDirectRefLayers(0);
2155    for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++)
2156    {
2157      decTop->setSamplePredEnabledFlag(i, false);
2158      decTop->setMotionPredEnabledFlag(i, false);
2159      decTop->setSamplePredRefLayerId(i, 0);
2160      decTop->setMotionPredRefLayerId(i, 0);
2161    }
2162    for(Int j = 0; j < layer; j++)
2163    {
2164      if (vps->getDirectDependencyFlag(layer, j))
2165      {
2166        decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layer));
2167        decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1);
2168
2169        Int samplePredEnabledFlag = (vps->getDirectDependencyType(layer, j) + 1) & 1;
2170        decTop->setSamplePredEnabledFlag(j, samplePredEnabledFlag == 1 ? true : false);
2171        decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag);
2172
2173        Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layer, j) + 1) & 2) >> 1;
2174        decTop->setMotionPredEnabledFlag(j, motionPredEnabledFlag == 1 ? true : false);
2175        decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag);
2176      }
2177    }
2178  }
2179  for ( Int i = 1, mIdx = 0, sIdx = 0; i < m_numLayer; i++ )
2180  {
2181    Int iNuhLId = vps->getLayerIdInNuh(i);
2182    TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId);
2183    for ( Int j = 0; j < i; j++ )
2184    {
2185      if (decTop->getMotionPredEnabledFlag(j))
2186      {
2187        decTop->setMotionPredRefLayerId(mIdx++, vps->getLayerIdInNuh(j));
2188      }
2189      if (decTop->getSamplePredEnabledFlag(j))
2190      {
2191        decTop->setSamplePredRefLayerId(sIdx++, vps->getLayerIdInNuh(j));
2192      }
2193    }
2194  }
2195}
2196
2197#endif
2198
2199#if OUTPUT_LAYER_SET_INDEX
2200Void TDecTop::checkValueOfTargetOutputLayerSetIdx(TComVPS *vps)
2201{
2202  CommonDecoderParams* params = this->getCommonDecoderParams();
2203
2204  assert( params->getTargetLayerId() < vps->getMaxLayers() );
2205
2206  if( params->getValueCheckedFlag() )
2207  {
2208    return; // Already checked
2209  }
2210  if( params->getTargetOutputLayerSetIdx() == -1 )  // Output layer set index not specified
2211  {
2212    Bool layerSetMatchFound = false;
2213    // Output layer set index not assigned.
2214    // Based on the value of targetLayerId, check if any of the output layer matches
2215    // Currently, the target layer ID in the encoder assumes that all the layers are decoded   
2216    // Check if any of the output layer sets match this description
2217    for(Int i = 0; i < vps->getNumOutputLayerSets(); i++)
2218    {
2219      Bool layerSetMatchFlag = true;
2220      Int layerSetIdx = vps->getOutputLayerSetIdx( i );
2221      if( vps->getNumLayersInIdList( layerSetIdx ) == params->getTargetLayerId() + 1 )
2222      {
2223        for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
2224        {
2225          if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
2226          {
2227            layerSetMatchFlag = false;
2228            break;
2229          }
2230        }
2231      }
2232      else
2233      {
2234        layerSetMatchFlag = false;
2235      }
2236     
2237      if( layerSetMatchFlag ) // Potential output layer set candidate found
2238      {
2239        // If target dec layer ID list is also included - check if they match
2240        if( params->getTargetDecLayerIdSet() )
2241        {
2242          if( params->getTargetDecLayerIdSet()->size() ) 
2243          {
2244            for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
2245            {
2246              if( *(params->getTargetDecLayerIdSet()->begin() + j) != vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, j )))
2247              {
2248                layerSetMatchFlag = false;
2249              }
2250            }
2251          }
2252        }
2253        if( layerSetMatchFlag ) // The target dec layer ID list also matches, if present
2254        {
2255          // Match found
2256          layerSetMatchFound = true;
2257          params->setTargetOutputLayerSetIdx( i );
2258          params->setValueCheckedFlag( true );
2259          break;
2260        }
2261      }
2262    }
2263    assert( layerSetMatchFound ); // No output layer set matched the value of either targetLayerId or targetdeclayerIdlist
2264  }   
2265  else // Output layer set index is assigned - check if the values match
2266  {
2267    // Check if the target decoded layer is the highest layer in the list
2268    assert( params->getTargetOutputLayerSetIdx() < vps->getNumLayerSets() );
2269    Int layerSetIdx = vps->getOutputLayerSetIdx( params->getTargetOutputLayerSetIdx() );  // Index to the layer set
2270    assert( params->getTargetLayerId() == vps->getNumLayersInIdList( layerSetIdx ) - 1);
2271
2272    Bool layerSetMatchFlag = true;
2273    for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
2274    {
2275      if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
2276      {
2277        layerSetMatchFlag = false;
2278        break;
2279      }
2280    }
2281
2282    assert(layerSetMatchFlag);    // Signaled output layer set index does not match targetOutputLayerId.
2283   
2284    // Check if the targetdeclayerIdlist matches the output layer set
2285    if( params->getTargetDecLayerIdSet() )
2286    {
2287      if( params->getTargetDecLayerIdSet()->size() ) 
2288      {
2289        for(Int i = 0; i < vps->getNumLayersInIdList( layerSetIdx ); i++)
2290        {
2291          assert( *(params->getTargetDecLayerIdSet()->begin() + i) == vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, i )));
2292        }
2293      }
2294    }
2295    params->setValueCheckedFlag( true );
2296
2297  }
2298}
2299#endif
2300#if RESOLUTION_BASED_DPB
2301Void TDecTop::assignSubDpbs(TComVPS *vps)
2302{
2303  if( m_subDpbIdx == -1 ) // Sub-DPB index is not already assigned
2304  {
2305    Int lsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
2306
2307    Int layerIdx = vps->findLayerIdxInLayerSet( lsIdx, getLayerId() );
2308    assert( layerIdx != -1 ); // Current layer should be found in the layer set.
2309
2310    // Copy from the active VPS based on the layer ID.
2311    m_subDpbIdx = vps->getSubDpbAssigned( lsIdx, layerIdx );
2312  }
2313}
2314#endif
2315#endif //SVC_EXTENSION
2316//! \}
Note: See TracBrowser for help on using the repository browser.