source: SHVCSoftware/branches/SHM-5.1-dev/source/Lib/TLibDecoder/TDecTop.cpp @ 620

Last change on this file since 620 was 620, checked in by qualcomm, 11 years ago

Bug-fix in r612 and other bug-fix in SHM in case of IDR refresh.

From: Adarsh K. Ramasubramonian <aramasub@…>

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