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

Last change on this file since 1510 was 642, checked in by seregin, 11 years ago

fix compiler warning

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