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

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

add scaled_ref_layer_id[ i ] into vert_phase_position_enable_flag, RefPicLayerId[ i ]] into vert_phase_position_flag, and encoder setting for vert_phase_position_in_use_flag

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