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

Last change on this file since 820 was 820, checked in by seregin, 10 years ago

remove macros SYNTAX_BYTES, SYNTAX_OUTPUT, and AVC_SYNTAX

  • Property svn:eol-style set to native
File size: 107.3 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2014, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecTop.cpp
35    \brief    decoder class
36*/
37
38#include "NALread.h"
39#include "TDecTop.h"
40
41#if SVC_EXTENSION
42UInt  TDecTop::m_prevPOC = MAX_UINT;
43UInt  TDecTop::m_uiPrevLayerId = MAX_UINT;
44Bool  TDecTop::m_bFirstSliceInSequence = true;
45#endif
46
47//! \ingroup TLibDecoder
48//! \{
49
50TDecTop::TDecTop()
51{
52  m_pcPic = 0;
53  m_iMaxRefPicNum = 0;
54#if ENC_DEC_TRACE
55  g_hTrace = fopen( "TraceDec.txt", "wb" );
56  g_bJustDoIt = g_bEncDecTraceDisable;
57  g_nSymbolCounter = 0;
58#endif
59  m_associatedIRAPType = NAL_UNIT_INVALID;
60  m_pocCRA = 0;
61  m_pocRandomAccess = MAX_INT;         
62#if !SVC_EXTENSION
63  m_prevPOC                = MAX_INT;
64#endif
65  m_bFirstSliceInPicture    = true;
66#if !SVC_EXTENSION
67  m_bFirstSliceInSequence   = true;
68#endif
69#if SVC_EXTENSION
70  m_layerId = 0;
71#if AVC_BASE
72  m_pBLReconFile = NULL;
73#endif
74  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
75#endif
76  m_prevSliceSkipped = false;
77  m_skippedPOC = 0;
78#if SETTING_NO_OUT_PIC_PRIOR
79  m_bFirstSliceInBitstream  = true;
80  m_lastPOCNoOutputPriorPics = -1;
81  m_craNoRaslOutputFlag = false;
82  m_isNoOutputPriorPics = false;
83#endif
84#if Q0177_EOS_CHECKS
85  m_isLastNALWasEos = false;
86#endif
87#if NO_CLRAS_OUTPUT_FLAG
88  m_noClrasOutputFlag          = false;
89  m_layerInitializedFlag       = false;
90  m_firstPicInLayerDecodedFlag = false; 
91#endif
92#if RESOLUTION_BASED_DPB
93  m_subDpbIdx = -1;
94#endif
95#if POC_RESET_IDC_DECODER
96  m_parseIdc = -1;
97  m_lastPocPeriodId = -1;
98  m_prevPicOrderCnt = 0;
99#endif
100#if Q0048_CGS_3D_ASYMLUT
101  m_pColorMappedPic = NULL;
102#endif
103
104#if Q0074_SEI_COLOR_MAPPING
105  m_ColorMapping = new TDecColorMapping();
106#endif
107}
108
109TDecTop::~TDecTop()
110{
111#if Q0078_ADD_LAYER_SETS
112  for (Int psId = 0; psId < MAX_NUM_SPS; psId++)
113  {
114    TComSPS* sps = m_parameterSetManagerDecoder.getSPS(psId);
115    if (sps != NULL)
116    {
117      // Remove parameter set from other layers to prevent multiple deletes of the same object
118      for (Int lId = 0; lId < m_numLayer; lId++)
119      {
120        if (m_ppcTDecTop[lId] != this)
121        {
122          m_parameterSetManagerDecoder.removeSPS(psId);
123        }
124      }
125    }
126  }
127  for (Int psId = 0; psId < MAX_NUM_PPS; psId++)
128  {
129    TComPPS* pps = m_parameterSetManagerDecoder.getPPS(psId);
130    if (pps != NULL)
131    {
132      // Remove parameter set from other layers to prevent multiple deletes of the same object
133      for (Int lId = 0; lId < m_numLayer; lId++)
134      {
135        if (m_ppcTDecTop[lId] != this)
136        {
137          m_parameterSetManagerDecoder.removePPS(psId);
138        }
139      }
140    }
141  }
142#endif
143#if ENC_DEC_TRACE
144  fclose( g_hTrace );
145#endif
146#if Q0048_CGS_3D_ASYMLUT
147  if(m_pColorMappedPic)
148  {
149    m_pColorMappedPic->destroy();
150    delete m_pColorMappedPic;
151    m_pColorMappedPic = NULL;
152  }
153#endif
154#if Q0074_SEI_COLOR_MAPPING
155  if ( m_ColorMapping )  delete m_ColorMapping;
156#endif
157}
158
159Void TDecTop::create()
160{
161#if SVC_EXTENSION
162  m_cGopDecoder.create( m_layerId );
163#else
164  m_cGopDecoder.create();
165#endif
166  m_apcSlicePilot = new TComSlice;
167  m_uiSliceIdx = 0;
168}
169
170Void TDecTop::destroy()
171{
172  m_cGopDecoder.destroy();
173 
174  delete m_apcSlicePilot;
175  m_apcSlicePilot = NULL;
176 
177  m_cSliceDecoder.destroy();
178#if SVC_EXTENSION
179  for(Int i=0; i<MAX_NUM_REF; i++)
180  {
181    if(m_cIlpPic[i])
182    {
183      m_cIlpPic[i]->destroy();
184      delete m_cIlpPic[i];
185      m_cIlpPic[i] = NULL;
186    }
187  }   
188#endif
189}
190
191Void TDecTop::init()
192{
193#if !SVC_EXTENSION
194  // initialize ROM
195  initROM();
196#endif
197#if SVC_EXTENSION
198  m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
199  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder, m_cSAO.getSaoMaxOffsetQVal() );
200#else
201  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
202  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
203#endif
204  m_cEntropyDecoder.init(&m_cPrediction);
205}
206
207#if SVC_EXTENSION
208#if !REPN_FORMAT_IN_VPS
209Void TDecTop::xInitILRP(TComSPS *pcSPS)
210#else
211Void TDecTop::xInitILRP(TComSlice *slice)
212#endif
213{
214#if REPN_FORMAT_IN_VPS
215  TComSPS* pcSPS = slice->getSPS();
216  Int bitDepthY   = slice->getBitDepthY();
217  Int bitDepthC   = slice->getBitDepthC();
218  Int picWidth    = slice->getPicWidthInLumaSamples();
219  Int picHeight   = slice->getPicHeightInLumaSamples();
220#endif
221  if(m_layerId>0)
222  {
223#if REPN_FORMAT_IN_VPS
224    g_bitDepthY     = bitDepthY;
225    g_bitDepthC     = bitDepthC;
226#else
227    g_bitDepthY     = pcSPS->getBitDepthY();
228    g_bitDepthC     = pcSPS->getBitDepthC();
229#endif
230    g_uiMaxCUWidth  = pcSPS->getMaxCUWidth();
231    g_uiMaxCUHeight = pcSPS->getMaxCUHeight();
232    g_uiMaxCUDepth  = pcSPS->getMaxCUDepth();
233    g_uiAddCUDepth  = max (0, pcSPS->getLog2MinCodingBlockSize() - (Int)pcSPS->getQuadtreeTULog2MinSize() );
234
235    Int  numReorderPics[MAX_TLAYER];
236    Window &conformanceWindow = pcSPS->getConformanceWindow();
237    Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window();
238
239    for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
240    {
241#if USE_DPB_SIZE_TABLE
242      if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
243      {
244        assert( this->getLayerId() == 0 );
245        numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
246      }
247      else
248      {
249        TComVPS *vps = slice->getVPS();
250        // SHM decoders will use DPB size table in the VPS to determine the number of reorder pictures.
251        numReorderPics[temporalLayer] = vps->getMaxVpsNumReorderPics( getCommonDecoderParams()->getTargetOutputLayerSetIdx() , temporalLayer);
252      }
253#else
254      numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
255#endif
256    }
257
258    if (m_cIlpPic[0] == NULL)
259    {
260      for (Int j=0; j < m_numDirectRefLayers; j++)
261      {
262
263        m_cIlpPic[j] = new  TComPic;
264
265#if AUXILIARY_PICTURES
266#if REPN_FORMAT_IN_VPS
267        m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
268#else
269        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
270#endif
271#else
272#if REPN_FORMAT_IN_VPS
273        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
274#else
275        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
276#endif
277#endif
278        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
279        {
280          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
281        }
282      }
283    }
284  }
285}
286#endif
287
288Void TDecTop::deletePicBuffer ( )
289{
290  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
291  Int iSize = Int( m_cListPic.size() );
292 
293  for (Int i = 0; i < iSize; i++ )
294  {
295    TComPic* pcPic = *(iterPic++);
296#if SVC_EXTENSION
297    if( pcPic )
298    {
299      pcPic->destroy();
300
301      delete pcPic;
302      pcPic = NULL;
303    }
304#else
305    pcPic->destroy();
306   
307    delete pcPic;
308    pcPic = NULL;
309#endif
310  }
311 
312  m_cSAO.destroy();
313 
314  m_cLoopFilter.        destroy();
315 
316#if !SVC_EXTENSION
317  // destroy ROM
318  destroyROM();
319#endif
320}
321
322Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
323{
324  Int  numReorderPics[MAX_TLAYER];
325  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
326  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
327
328  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
329  {
330#if USE_DPB_SIZE_TABLE
331    if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
332    {
333      assert( this->getLayerId() == 0 );
334      numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
335    }
336    else
337    {
338      TComVPS *vps = pcSlice->getVPS();
339      // SHM decoders will use DPB size table in the VPS to determine the number of reorder pictures.
340      numReorderPics[temporalLayer] = vps->getMaxVpsNumReorderPics( getCommonDecoderParams()->getTargetOutputLayerSetIdx() , temporalLayer);
341    }
342#else
343    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
344#endif
345  }
346
347#if USE_DPB_SIZE_TABLE
348  if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
349  {
350    assert( this->getLayerId() == 0 );
351    m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
352  }
353  else
354  {
355#if RESOLUTION_BASED_DPB
356    Int layerSetIdxForOutputLayerSet = pcSlice->getVPS()->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
357    Int layerIdx = pcSlice->getVPS()->findLayerIdxInLayerSet( layerSetIdxForOutputLayerSet, pcSlice->getLayerId() );  assert( layerIdx != -1 );
358    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxVpsLayerDecPicBuffMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), layerIdx, pcSlice->getTLayer() ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
359#else
360    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), pcSlice->getLayerId(), pcSlice->getTLayer() ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
361#endif
362  }
363#else
364  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
365#endif
366
367#if SVC_EXTENSION
368  m_iMaxRefPicNum += 1; // it should be updated if more than 1 resampling picture is used
369#endif
370
371  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
372  {
373    rpcPic = new TComPic();
374
375#if SVC_EXTENSION //Temporal solution, should be modified
376    if(m_layerId > 0)
377    {
378      for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
379      {
380#if O0098_SCALED_REF_LAYER_ID
381        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
382#else
383        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(i);
384#endif
385        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
386
387#if VPS_EXTN_DIRECT_REF_LAYERS
388        TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i );
389#else
390        TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
391#endif
392        //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin());
393        TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
394#if REPN_FORMAT_IN_VPS
395#if O0194_DIFFERENT_BITDEPTH_EL_BL
396        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, i);
397        Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
398
399        if( pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets || !sameBitDepths
400#if Q0048_CGS_3D_ASYMLUT
401          || pcSlice->getPPS()->getCGSFlag() > 0
402#endif
403#if LAYER_CTB
404          || pcTDecTopBase->getActiveSPS()->getMaxCUWidth() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUWidth() || pcTDecTopBase->getActiveSPS()->getMaxCUHeight() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUHeight() || pcTDecTopBase->getActiveSPS()->getMaxCUDepth() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUDepth()
405#endif
406          )
407#else
408        if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets )
409#endif
410#else
411        if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() || !zeroOffsets )
412#endif
413        {
414          rpcPic->setSpatialEnhLayerFlag( i, true );
415
416          //only for scalable extension
417          assert( pcSlice->getVPS()->getScalabilityMask( SCALABILITY_ID ) == true );
418        }
419      }
420    }
421
422#if AUXILIARY_PICTURES
423#if REPN_FORMAT_IN_VPS
424    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
425                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
426#else
427    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
428                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
429#endif
430#else
431#if REPN_FORMAT_IN_VPS
432    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
433                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
434#else
435    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
436                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
437#endif
438#endif
439
440#else //SVC_EXTENSION
441    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
442                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
443#endif //SVC_EXTENSION
444   
445    m_cListPic.pushBack( rpcPic );
446   
447    return;
448  }
449 
450  Bool bBufferIsAvailable = false;
451  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
452  while (iterPic != m_cListPic.end())
453  {
454    rpcPic = *(iterPic++);
455    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
456    {
457      rpcPic->setOutputMark(false);
458      bBufferIsAvailable = true;
459      break;
460    }
461
462    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
463    {
464#if !SVC_EXTENSION
465      rpcPic->setOutputMark(false);
466#endif
467      rpcPic->setReconMark( false );
468      rpcPic->getPicYuvRec()->setBorderExtension( false );
469      bBufferIsAvailable = true;
470      break;
471    }
472  }
473 
474  if ( !bBufferIsAvailable )
475  {
476    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
477    m_iMaxRefPicNum++;
478    rpcPic = new TComPic();
479    m_cListPic.pushBack( rpcPic );
480  }
481  rpcPic->destroy();
482
483#if SVC_EXTENSION
484#if AUXILIARY_PICTURES
485#if REPN_FORMAT_IN_VPS
486  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
487                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
488#else
489  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
490                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
491#endif
492#else
493#if REPN_FORMAT_IN_VPS
494  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
495                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
496
497#else
498  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
499                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
500#endif
501#endif
502#else  //SVC_EXTENSION
503  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
504                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
505#endif //SVC_EXTENSION
506}
507
508Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
509{
510  if (!m_pcPic)
511  {
512    /* nothing to deblock */
513    return;
514  }
515 
516  TComPic*&   pcPic         = m_pcPic;
517
518  // Execute Deblock + Cleanup
519  m_cGopDecoder.filterPicture(pcPic);
520
521  TComSlice::sortPicList( m_cListPic ); // sorting for application output
522  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
523  rpcListPic          = &m_cListPic; 
524  m_cCuDecoder.destroy();       
525  m_bFirstSliceInPicture  = true;
526
527  return;
528}
529
530#if SETTING_NO_OUT_PIC_PRIOR
531Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic)
532{
533  if (!rpcListPic || !m_isNoOutputPriorPics) return;
534
535  TComList<TComPic*>::iterator  iterPic   = rpcListPic->begin();
536
537  while (iterPic != rpcListPic->end())
538  {
539    TComPic*& pcPicTmp = *(iterPic++);
540    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
541    {
542      pcPicTmp->setOutputMark(false);
543    }
544  }
545}
546#endif
547
548#if EARLY_REF_PIC_MARKING
549Void TDecTop::earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdSet)
550{
551  UInt currTid = m_pcPic->getTLayer();
552  UInt highestTid = (maxTemporalLayer >= 0) ? maxTemporalLayer : (m_pcPic->getSlice(0)->getSPS()->getMaxTLayers() - 1);
553  UInt latestDecLayerId = m_layerId;
554  UInt numTargetDecLayers = 0;
555  Int targetDecLayerIdList[MAX_LAYERS];
556  UInt latestDecIdx = 0;
557  TComSlice* pcSlice = m_pcPic->getSlice(0);
558
559  if ( currTid != highestTid )  // Marking  process is only applicaple for highest decoded TLayer
560  {
561    return;
562  }
563
564  // currPic must be marked as "used for reference" and must be a sub-layer non-reference picture
565  if ( !((pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N  ||
566          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N    ||
567          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N   ||
568          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N   ||
569          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N   ||
570          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N10     ||
571          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N12     ||
572          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N14) && pcSlice->isReferenced()))
573  {
574    return;
575  }
576
577  if ( targetDecLayerIdSet.size() == 0 ) // Cannot mark if we don't know the number of scalable layers
578  {
579    return;
580  }
581
582  for (std::vector<Int>::iterator it = targetDecLayerIdSet.begin(); it != targetDecLayerIdSet.end(); it++)
583  {
584    if ( latestDecLayerId == (*it) )
585    {
586      latestDecIdx = numTargetDecLayers;
587    }
588    targetDecLayerIdList[numTargetDecLayers++] = (*it);
589  }
590
591  Int remainingInterLayerReferencesFlag = 0;
592#if O0225_MAX_TID_FOR_REF_LAYERS
593  for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
594  {
595    Int jLidx = pcSlice->getVPS()->getLayerIdInVps(targetDecLayerIdList[j]);
596    if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId,jLidx) - 1 )
597    {
598#else
599  if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId) - 1 )
600  {
601    for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
602    {
603#endif
604      for ( Int k = 0; k < m_ppcTDecTop[targetDecLayerIdList[j]]->getNumDirectRefLayers(); k++ )
605      {
606        if ( latestDecIdx == m_ppcTDecTop[targetDecLayerIdList[j]]->getRefLayerId(k) )
607        {
608          remainingInterLayerReferencesFlag = 1;
609        }
610      }
611    }
612  }
613
614  if ( remainingInterLayerReferencesFlag == 0 )
615  {
616    pcSlice->setReferenced(false);
617  }
618}
619#endif
620
621Void TDecTop::xCreateLostPicture(Int iLostPoc) 
622{
623  printf("\ninserting lost poc : %d\n",iLostPoc);
624  TComSlice cFillSlice;
625  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
626  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
627#if SVC_EXTENSION
628  cFillSlice.setVPS( m_parameterSetManagerDecoder.getFirstVPS() );
629  cFillSlice.initSlice( m_layerId );
630#else
631  cFillSlice.initSlice();
632#endif
633  TComPic *cFillPic;
634  xGetNewPicBuffer(&cFillSlice,cFillPic);
635  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
636  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
637#if SVC_EXTENSION
638  cFillPic->getSlice(0)->setVPS( m_parameterSetManagerDecoder.getFirstVPS() );
639  cFillPic->getSlice(0)->initSlice( m_layerId );
640#else
641  cFillPic->getSlice(0)->initSlice();
642#endif
643 
644  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
645  Int closestPoc = 1000000;
646  while ( iterPic != m_cListPic.end())
647  {
648    TComPic * rpcPic = *(iterPic++);
649    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())
650    {
651      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
652    }
653  }
654  iterPic = m_cListPic.begin();
655  while ( iterPic != m_cListPic.end())
656  {
657    TComPic *rpcPic = *(iterPic++);
658    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
659    {
660      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
661      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
662      break;
663    }
664  }
665  cFillPic->setCurrSliceIdx(0);
666  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
667  {
668    cFillPic->getCU(i)->initCU(cFillPic,i);
669  }
670  cFillPic->getSlice(0)->setReferenced(true);
671  cFillPic->getSlice(0)->setPOC(iLostPoc);
672  cFillPic->setReconMark(true);
673  cFillPic->setOutputMark(true);
674  if(m_pocRandomAccess == MAX_INT)
675  {
676    m_pocRandomAccess = iLostPoc;
677  }
678}
679
680
681Void TDecTop::xActivateParameterSets()
682{
683  m_parameterSetManagerDecoder.applyPrefetchedPS();
684 
685  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
686  assert (pps != 0);
687
688  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
689  assert (sps != 0);
690
691  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
692  {
693    printf ("Parameter set activation failed!");
694    assert (0);
695  }
696
697#if SCALINGLIST_INFERRING
698  // scaling list settings and checks
699  TComVPS *activeVPS = m_parameterSetManagerDecoder.getActiveVPS();
700  TComSPS *activeSPS = m_parameterSetManagerDecoder.getActiveSPS();
701  TComPPS *activePPS = m_parameterSetManagerDecoder.getActivePPS();
702
703  if( activeSPS->getInferScalingListFlag() )
704  {
705    UInt refLayerId = activeSPS->getScalingListRefLayerId();
706    TComSPS *refSps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActiveSPS(); assert( refSps != NULL );
707
708    // 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
709    if( activeVPS->getAvcBaseLayerFlag() )
710    {
711      assert( refLayerId > 0 );
712    }
713
714    // 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
715    // 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
716    assert( refSps->getInferScalingListFlag() == false );
717
718    // 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,
719    // 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
720    assert( activeVPS->getRecursiveRefLayerFlag( activeSPS->getLayerId(), refLayerId ) == true );
721   
722    if( activeSPS->getScalingList() != refSps->getScalingList() )
723    {
724      // delete created instance of scaling list since it will be inferred
725      delete activeSPS->getScalingList();
726
727      // infer scaling list
728      activeSPS->setScalingList( refSps->getScalingList() );
729    }
730  }
731
732  if( activePPS->getInferScalingListFlag() )
733  {
734    UInt refLayerId = activePPS->getScalingListRefLayerId();
735    TComPPS *refPps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActivePPS(); assert( refPps != NULL );
736
737    // 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
738    if( activeVPS->getAvcBaseLayerFlag() )
739    {
740      assert( refLayerId > 0 );
741    }
742
743    // 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
744    // 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
745    assert( refPps->getInferScalingListFlag() == false );
746
747    // 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,
748    // 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
749    assert( activeVPS->getRecursiveRefLayerFlag( activePPS->getLayerId(), refLayerId ) == true );
750   
751    if( activePPS->getScalingList() != refPps->getScalingList() )
752    {
753      // delete created instance of scaling list since it will be inferred
754      delete activePPS->getScalingList();
755
756      // infer scaling list
757      activePPS->setScalingList( refPps->getScalingList() );
758    }
759
760  }
761#endif
762
763#if AVC_BASE
764  if( activeVPS->getAvcBaseLayerFlag() )
765  {
766    TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
767    if( m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
768    {
769      UInt refLayerId = 0;
770      RepFormat* repFormat = activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(refLayerId) );
771
772      Int  numReorderPics[MAX_TLAYER];
773      Window conformanceWindow;
774      Window defaultDisplayWindow;
775
776#if AUXILIARY_PICTURES
777      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
778#else
779      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
780#endif
781      // it is needed where the VPS is accessed through the slice
782      pBLPic->getSlice(0)->setVPS( activeVPS );
783
784#if O0194_DIFFERENT_BITDEPTH_EL_BL
785      g_bitDepthYLayer[0] = repFormat->getBitDepthVpsLuma();
786      g_bitDepthCLayer[0] = repFormat->getBitDepthVpsChroma();
787#endif
788    }
789  }
790#endif
791
792#if P0312_VERT_PHASE_ADJ
793  if( activeVPS->getVpsVuiVertPhaseInUseFlag() == 0 )
794  {   
795    for(Int i = 0; i < activeSPS->getNumScaledRefLayerOffsets(); i++)
796    {
797      UInt scaledRefLayerId = activeSPS->getScaledRefLayerId(i);
798      if( activeSPS->getVertPhasePositionEnableFlag( scaledRefLayerId ) )
799      {
800        printf("\nWarning: LayerId = %d: vert_phase_position_enable_flag[%d] = 1, however indication vert_phase_position_in_use_flag = 0\n", m_layerId, scaledRefLayerId );
801        break;
802      }
803    }
804  }
805#endif
806
807#if SPS_DPB_PARAMS
808  if( m_layerId > 0 )
809  {
810    // When not present sps_max_sub_layers_minus1 is inferred to be equal to vps_max_sub_layers_minus1.
811    sps->setMaxTLayers( activeVPS->getMaxTLayers() );
812
813    // When not present sps_temporal_id_nesting_flag is inferred to be equal to vps_temporal_id_nesting_flag
814#if Q0177_SPS_TEMP_NESTING_FIX
815    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? activeVPS->getTemporalNestingFlag() : true );
816#else
817    sps->setTemporalIdNestingFlag( activeVPS->getTemporalNestingFlag() );
818#endif
819
820    // When sps_max_dec_pic_buffering_minus1[ i ] is not present for i in the range of 0 to sps_max_sub_layers_minus1, inclusive, due to nuh_layer_id being greater than 0,
821    // it is inferred to be equal to max_vps_dec_pic_buffering_minus1[ TargetOptLayerSetIdx ][ currLayerId ][ i ] of the active VPS, where currLayerId is the nuh_layer_id of the layer that refers to the SPS.
822    for(UInt i=0; i < sps->getMaxTLayers(); i++)
823    {
824      // to avoid compiler warning "array subscript is above array bounds"
825      assert( i < MAX_TLAYER );
826#if LAYER_DECPICBUFF_PARAM && RESOLUTION_BASED_DPB
827      sps->setMaxDecPicBuffering( activeVPS->getMaxVpsLayerDecPicBuffMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), sps->getLayerId(), i) + 1, i);
828#else
829      sps->setMaxDecPicBuffering( activeVPS->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), sps->getLayerId(), i) + 1, i);
830#endif
831    }
832  }
833#endif
834
835  if( pps->getDependentSliceSegmentsEnabledFlag() )
836  {
837    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
838
839    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
840    {
841      m_cSliceDecoder.initCtxMem(NumCtx);
842      for ( UInt st = 0; st < NumCtx; st++ )
843      {
844        TDecSbac* ctx = NULL;
845        ctx = new TDecSbac;
846        ctx->init( &m_cBinCABAC );
847        m_cSliceDecoder.setCtxMem( ctx, st );
848      }
849    }
850  }
851
852  m_apcSlicePilot->setPPS(pps);
853  m_apcSlicePilot->setSPS(sps);
854  pps->setSPS(sps);
855#if REPN_FORMAT_IN_VPS
856  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
857#else
858  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
859#endif
860  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
861
862#if REPN_FORMAT_IN_VPS
863  g_bitDepthY     = m_apcSlicePilot->getBitDepthY();
864  g_bitDepthC     = m_apcSlicePilot->getBitDepthC();
865#else
866  g_bitDepthY     = sps->getBitDepthY();
867  g_bitDepthC     = sps->getBitDepthC();
868#endif
869  g_uiMaxCUWidth  = sps->getMaxCUWidth();
870  g_uiMaxCUHeight = sps->getMaxCUHeight();
871  g_uiMaxCUDepth  = sps->getMaxCUDepth();
872  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
873
874#if Q0074_SEI_COLOR_MAPPING
875  for(Int compID=0; compID<3; compID++)
876  {
877    m_ColorMapping->setColorMapping( compID ? g_bitDepthC : g_bitDepthY, compID );
878  }
879#endif
880
881  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
882  {
883    sps->setAMPAcc( i, sps->getUseAMP() );
884  }
885
886  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
887  {
888    sps->setAMPAcc( i, 0 );
889  }
890
891  m_cSAO.destroy();
892#if REPN_FORMAT_IN_VPS
893#if AUXILIARY_PICTURES
894  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
895#else
896  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
897#endif
898#else
899  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
900#endif
901  m_cLoopFilter.create( sps->getMaxCUDepth() );
902}
903
904#if SVC_EXTENSION
905#if POC_RESET_FLAG
906Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int &iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
907#else
908Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
909#endif
910#else
911Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
912#endif
913{
914  TComPic*&   pcPic         = m_pcPic;
915#if SVC_EXTENSION
916  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getPrefetchedVPS(0) );
917#if OUTPUT_LAYER_SET_INDEX
918  // Following check should go wherever the VPS is activated
919  checkValueOfTargetOutputLayerSetIdx( m_apcSlicePilot->getVPS());
920#endif
921#if RESOLUTION_BASED_DPB
922  // Following assignment should go wherever a new VPS is activated
923  assignSubDpbs(m_apcSlicePilot->getVPS());
924#endif
925  m_apcSlicePilot->initSlice( nalu.m_layerId );
926#else //SVC_EXTENSION
927  m_apcSlicePilot->initSlice();
928#endif
929
930  if (m_bFirstSliceInPicture)
931  {
932    m_uiSliceIdx     = 0;
933  }
934  else
935  {
936    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
937  }
938  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
939
940  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
941  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
942                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
943                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
944                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
945                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
946  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
947 
948  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
949  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
950
951#if SVC_EXTENSION
952#if VPS_EXTN_DIRECT_REF_LAYERS
953  setRefLayerParams(m_apcSlicePilot->getVPS());
954#endif
955  m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers);
956#endif
957  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
958
959  // set POC for dependent slices in skipped pictures
960  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
961  {
962    m_apcSlicePilot->setPOC(m_skippedPOC);
963  }
964
965  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
966  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
967
968#if SETTING_NO_OUT_PIC_PRIOR
969  //For inference of NoOutputOfPriorPicsFlag
970  if (m_apcSlicePilot->getRapPicFlag())
971  {
972    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
973        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
974        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
975    {
976      m_apcSlicePilot->setNoRaslOutputFlag(true);
977    }
978    //the inference for NoOutputPriorPicsFlag
979    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
980    {
981      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
982      {
983        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
984      }
985    }
986    else
987    {
988      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
989    }
990
991    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
992    {
993      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
994    }
995  }
996  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
997  {
998    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
999    m_isNoOutputPriorPics = true;
1000  }
1001  else
1002  {
1003    m_isNoOutputPriorPics = false;
1004  }
1005
1006  //For inference of PicOutputFlag
1007  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
1008  {
1009    if ( m_craNoRaslOutputFlag )
1010    {
1011      m_apcSlicePilot->setPicOutputFlag(false);
1012    }
1013  }
1014#endif
1015
1016#if FIX_POC_CRA_NORASL_OUTPUT
1017  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
1018  {
1019    Int iMaxPOClsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
1020    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
1021  }
1022#endif
1023
1024  // Skip pictures due to random access
1025  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
1026  {
1027    m_prevSliceSkipped = true;
1028    m_skippedPOC = m_apcSlicePilot->getPOC();
1029    return false;
1030  }
1031  // Skip TFD pictures associated with BLA/BLANT pictures
1032  if (isSkipPictureForBLA(iPOCLastDisplay))
1033  {
1034    m_prevSliceSkipped = true;
1035    m_skippedPOC = m_apcSlicePilot->getPOC();
1036    return false;
1037  }
1038
1039  // clear previous slice skipped flag
1040  m_prevSliceSkipped = false;
1041
1042  // exit when a new picture is found
1043#if SVC_EXTENSION
1044  bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC);
1045
1046#if NO_OUTPUT_OF_PRIOR_PICS
1047#if NO_CLRAS_OUTPUT_FLAG
1048  if (m_layerId == 0 && m_apcSlicePilot->getRapPicFlag() )
1049  {
1050    if (m_bFirstSliceInSequence)
1051    {
1052      setNoClrasOutputFlag(true);
1053    }
1054    else if ( m_apcSlicePilot->getBlaPicFlag() )
1055    {
1056      setNoClrasOutputFlag(true);
1057    }
1058#if O0149_CROSS_LAYER_BLA_FLAG
1059    else if (m_apcSlicePilot->getIdrPicFlag() && m_apcSlicePilot->getCrossLayerBLAFlag())
1060    {
1061      setNoClrasOutputFlag(true);
1062    }
1063#endif
1064    else
1065    {
1066      setNoClrasOutputFlag(false);
1067    }     
1068  }
1069  else
1070  {
1071    setNoClrasOutputFlag(false);
1072  }
1073
1074  m_apcSlicePilot->decodingRefreshMarking( m_cListPic, m_noClrasOutputFlag );
1075#endif
1076
1077  // Derive the value of NoOutputOfPriorPicsFlag
1078  if( bNewPOC || m_layerId!=m_uiPrevLayerId )   // i.e. new coded picture
1079  {
1080    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getNoRaslOutputFlag() )
1081    {
1082      this->setNoOutputPriorPicsFlag( true );
1083    }
1084    else if( m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag() )
1085    {
1086      this->setNoOutputPriorPicsFlag( m_apcSlicePilot->getNoOutputPriorPicsFlag() );
1087    }
1088    else
1089    {
1090      if( this->m_ppcTDecTop[0]->getNoClrasOutputFlag() )
1091      {
1092        this->setNoOutputPriorPicsFlag( true );
1093      }
1094    }
1095  }
1096#endif
1097#if POC_RESET_IDC_DECODER
1098  if( m_parseIdc != -1 ) // Second pass for a POC resetting picture
1099  {
1100    m_parseIdc++; // Proceed to POC decoding and RPS derivation
1101  }
1102 
1103  if( m_parseIdc == 2 )
1104  {
1105    bNewPOC = false;
1106  }
1107
1108  if( (bNewPOC || m_layerId!=m_uiPrevLayerId) && (m_parseIdc == -1) ) // Will be true at the first pass
1109  {
1110  //if (bNewPOC || m_layerId!=m_uiPrevLayerId)
1111  // Check if new reset period has started - this is needed just so that the SHM decoder which calls slice header decoding twice
1112  // does not invoke the output twice
1113  //if( m_lastPocPeriodId[m_apcSlicePilot->getLayerId()] == m_apcSlicePilot->getPocResetPeriodId() )
1114    // Update CurrAU marking
1115    if(( m_layerId < m_uiPrevLayerId) ||( ( m_layerId == m_uiPrevLayerId) && bNewPOC)) // Decoding a lower layer than or same layer as previous - mark all earlier pictures as not in current AU
1116    {
1117      markAllPicsAsNoCurrAu();
1118    }
1119
1120    if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getSliceIdx() == 0 )
1121    {
1122      Int pocResetPeriodId = m_apcSlicePilot->getPocResetPeriodId();
1123      if ( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 ||
1124        ( m_apcSlicePilot->getPocResetIdc() == 3 && pocResetPeriodId != getLastPocPeriodId() ) )
1125      {
1126        setLastPocPeriodId(pocResetPeriodId);
1127        m_parseIdc = 0;
1128      }
1129    }
1130    else
1131    {
1132      m_parseIdc = 3; // Proceed to decoding POC and RPS
1133    } 
1134  }
1135#endif
1136
1137#if ALIGNED_BUMPING
1138#if POC_RESET_IDC_DECODER
1139  //if(  (bNewPOC || m_layerId != m_uiPrevLayerId) && ( m_parseIdc != 1) )
1140  if( m_parseIdc == 1 )
1141  {
1142    // Invoke output of pictures if the current picture is a POC reset picture
1143    bNewPOC = true;
1144    /* Include reset of all POCs in the layer */
1145
1146  // This operation would do the following:
1147  // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
1148  // 2. Update the value of m_pocCRA.
1149  // 3. Reset the POC values at the decoder for the current picture to be zero - will be done later
1150  // 4. update value of POCLastDisplay
1151     
1152  //Do the reset stuff here
1153    Int maxPocLsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
1154    Int pocLsbVal;
1155    if( m_apcSlicePilot->getPocResetIdc() == 3 )
1156    {
1157      pocLsbVal = m_apcSlicePilot->getPocLsbVal() ;
1158    }
1159    else
1160    {
1161      pocLsbVal = (m_apcSlicePilot->getPOC() % maxPocLsb);
1162    }
1163
1164    Int pocMsbDelta = 0;
1165    if ( m_apcSlicePilot->getPocMsbValPresentFlag() ) 
1166    {
1167      pocMsbDelta = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
1168    }
1169    else
1170    {
1171      //This MSB derivation can be made into one function. Item to do next.
1172      Int prevPoc     = this->getPrevPicOrderCnt();
1173      Int prevPocLsb  = prevPoc & (maxPocLsb - 1);
1174      Int prevPocMsb  = prevPoc - prevPocLsb;
1175
1176      pocMsbDelta = m_apcSlicePilot->getCurrMsb( pocLsbVal, prevPocLsb, prevPocMsb, maxPocLsb );
1177    }
1178
1179    Int pocLsbDelta;
1180    if( m_apcSlicePilot->getPocResetIdc() == 2 ||  ( m_apcSlicePilot->getPocResetIdc() == 3 && m_apcSlicePilot->getFullPocResetFlag() ))
1181    {
1182      pocLsbDelta = pocLsbVal;
1183    }
1184    else
1185    {
1186      pocLsbDelta = 0; 
1187    }
1188
1189    Int deltaPocVal  =  pocMsbDelta + pocLsbDelta;
1190
1191    //Reset all POC for DPB -> basically do it for each slice in the picutre
1192    TComList<TComPic*>::iterator  iterPic = m_cListPic.begin(); 
1193
1194    // Iterate through all picture in DPB
1195    while( iterPic != m_cListPic.end() )
1196    {
1197      TComPic *dpbPic = *iterPic;
1198      // Check if the picture pointed to by iterPic is either used for reference or
1199      // needed for output, are in the same layer, and not the current picture.
1200      if( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
1201          &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
1202            && ( dpbPic->getReconMark() ) && ( dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag() ))
1203      {
1204        for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
1205        {
1206
1207          TComSlice *slice = dpbPic->getSlice(i);
1208          TComReferencePictureSet *rps = slice->getRPS();
1209          slice->setPOC( slice->getPOC() - deltaPocVal );
1210
1211          // Also adjust the POC value stored in the RPS of each such slice
1212          for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
1213          {
1214            rps->setPOC( j, rps->getPOC(j) - deltaPocVal );
1215          }
1216          // Also adjust the value of refPOC
1217          for(Int k = 0; k < 2; k++)  // For List 0 and List 1
1218          {
1219            RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
1220            for(Int j = 0; j < slice->getNumRefIdx(list); j++)
1221            {
1222              slice->setRefPOC( slice->getRefPOC(list, j) - deltaPocVal, list, j);
1223            }
1224          }
1225        }
1226      }
1227      iterPic++;
1228    }
1229    // Update the value of pocCRA
1230    m_pocCRA -= deltaPocVal;
1231
1232    // Update value of POCLastDisplay
1233    iPOCLastDisplay -= deltaPocVal;
1234  }
1235  Int maxPocLsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
1236  Int slicePicOrderCntLsb = m_apcSlicePilot->getPicOrderCntLsb();
1237
1238  if( m_parseIdc == 1 || m_parseIdc == 2 ) // TODO This should be replaced by pocResettingFlag.
1239  {
1240    // Set poc for current slice
1241    if( m_apcSlicePilot->getPocResetIdc() == 1 )
1242    {       
1243      m_apcSlicePilot->setPOC( slicePicOrderCntLsb );
1244    }
1245    else if( m_apcSlicePilot->getPocResetIdc() == 2 )
1246    {
1247      m_apcSlicePilot->setPOC( 0 );
1248    }
1249    else 
1250    {
1251      Int picOrderCntMsb = m_apcSlicePilot->getCurrMsb( slicePicOrderCntLsb, m_apcSlicePilot->getFullPocResetFlag() ? 0 : m_apcSlicePilot->getPocLsbVal(), 0 , maxPocLsb );
1252      m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
1253    }
1254  }
1255  else if (m_parseIdc == 3)
1256  {
1257    Int picOrderCntMsb = 0;
1258    if( m_apcSlicePilot->getPocMsbValPresentFlag() )
1259    {
1260      picOrderCntMsb = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
1261    }
1262    else if( m_apcSlicePilot->getIdrPicFlag() )
1263    {
1264      picOrderCntMsb = 0;
1265    }
1266    else
1267    {
1268      Int prevPicOrderCntLsb = this->getPrevPicOrderCnt() & ( maxPocLsb - 1);
1269      Int prevPicOrderCntMsb  = this->getPrevPicOrderCnt() - prevPicOrderCntLsb;
1270      picOrderCntMsb = m_apcSlicePilot->getCurrMsb(slicePicOrderCntLsb, prevPicOrderCntLsb, prevPicOrderCntMsb, maxPocLsb );
1271    }
1272    m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
1273  }
1274
1275  if( m_parseIdc == 1 || m_parseIdc == 3)
1276  {
1277    // Adjust prevPicOrderCnt
1278    if(    !m_apcSlicePilot->getRaslPicFlag() 
1279        && !m_apcSlicePilot->getRadlPicFlag()
1280        && (m_apcSlicePilot->getNalUnitType() % 2 == 1)
1281        && ( nalu.m_temporalId == 0 )
1282        && !m_apcSlicePilot->getDiscardableFlag() )
1283    {
1284      this->setPrevPicOrderCnt( m_apcSlicePilot->getPOC() );
1285    }
1286    else if ( m_apcSlicePilot->getPocResetIdc() == 3 )
1287    {
1288      this->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag() 
1289                                            ? 0 : m_apcSlicePilot->getPocLsbVal() );
1290    }
1291#else
1292  if (bNewPOC || m_layerId!=m_uiPrevLayerId)
1293  {
1294#endif
1295    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
1296  }
1297#endif
1298#if POC_RESET_IDC_DECODER
1299  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId || m_parseIdc == 1) && !m_bFirstSliceInSequence )
1300#else
1301  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
1302#endif
1303  {
1304    m_prevPOC = m_apcSlicePilot->getPOC();
1305    curLayerId = m_uiPrevLayerId; 
1306    m_uiPrevLayerId = m_layerId;
1307    return true;
1308  }
1309
1310#if POC_RESET_IDC_DECODER
1311  m_parseIdc = -1;
1312#endif
1313
1314  // actual decoding starts here
1315    xActivateParameterSets();
1316
1317#if REPN_FORMAT_IN_VPS
1318  // Initialize ILRP if needed, only for the current layer 
1319  // ILRP intialization should go along with activation of parameters sets,
1320  // although activation of parameter sets itself need not be done for each and every slice!!!
1321  xInitILRP(m_apcSlicePilot);
1322#endif
1323  if (m_apcSlicePilot->isNextSlice()) 
1324  {
1325    m_prevPOC = m_apcSlicePilot->getPOC();
1326    curLayerId = m_layerId;
1327    m_uiPrevLayerId = m_layerId;
1328  }
1329  m_bFirstSliceInSequence = false;
1330#if SETTING_NO_OUT_PIC_PRIOR 
1331  m_bFirstSliceInBitstream  = false;
1332#endif
1333#if POC_RESET_FLAG
1334  // This operation would do the following:
1335  // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
1336  // 2. Update the value of m_pocCRA.
1337  // 3. Reset the POC values at the decoder for the current picture to be zero.
1338  // 4. update value of POCLastDisplay
1339  if( m_apcSlicePilot->getPocResetFlag() )
1340  {
1341    if( m_apcSlicePilot->getSliceIdx() == 0 )
1342    {
1343      Int pocAdjustValue = m_apcSlicePilot->getPOC();
1344
1345#if PREVTID0_POC_RESET
1346      m_apcSlicePilot->adjustPrevTid0POC(pocAdjustValue);
1347#endif
1348      // If poc reset flag is set to 1, reset all POC for DPB -> basically do it for each slice in the picutre
1349      TComList<TComPic*>::iterator  iterPic = m_cListPic.begin(); 
1350
1351      // Iterate through all picture in DPB
1352      while( iterPic != m_cListPic.end() )
1353      {
1354        TComPic *dpbPic = *iterPic;
1355        // Check if the picture pointed to by iterPic is either used for reference or
1356        // needed for output, are in the same layer, and not the current picture.
1357        if( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
1358            &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
1359              && ( dpbPic->getReconMark() ) 
1360          )
1361        {
1362          for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
1363          {
1364
1365            TComSlice *slice = dpbPic->getSlice(i);
1366            TComReferencePictureSet *rps = slice->getRPS();
1367            slice->setPOC( slice->getPOC() - pocAdjustValue );
1368
1369            // Also adjust the POC value stored in the RPS of each such slice
1370            for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
1371            {
1372              rps->setPOC( j, rps->getPOC(j) - pocAdjustValue );
1373            }
1374            // Also adjust the value of refPOC
1375            for(Int k = 0; k < 2; k++)  // For List 0 and List 1
1376            {
1377              RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
1378              for(Int j = 0; j < slice->getNumRefIdx(list); j++)
1379              {
1380                slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j);
1381              }
1382            }
1383          }
1384        }
1385        iterPic++;
1386      }
1387      // Update the value of pocCRA
1388      m_pocCRA -= pocAdjustValue;
1389      // Update value of POCLastDisplay
1390      iPOCLastDisplay -= pocAdjustValue;
1391    }
1392    // Reset current poc for current slice and RPS
1393    m_apcSlicePilot->setPOC( 0 );
1394  }
1395#endif
1396  // Alignment of TSA and STSA pictures across AU
1397#if !Q0108_TSA_STSA
1398  if( m_apcSlicePilot->getLayerId() > 0 )
1399  {
1400    // Check for TSA alignment
1401    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
1402        m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R
1403         )
1404    {
1405      for(Int dependentLayerIdx = 0; dependentLayerIdx < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1406      {
1407        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1408        TComPic* refpicLayer = m_apcSlicePilot->getRefPic(*cListPic, m_apcSlicePilot->getPOC() );
1409        if( refpicLayer )
1410        {
1411          assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
1412                    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R );    // TSA pictures should be aligned among depenedent layers
1413        } 
1414      }
1415    }
1416    // Check for STSA alignment
1417    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ||
1418         m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R
1419         )
1420    {
1421      for(Int dependentLayerIdx = 0; dependentLayerIdx < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1422      {
1423        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1424        TComPic* refpicLayer = m_apcSlicePilot->getRefPic(*cListPic, m_apcSlicePilot->getPOC() ); // STSA pictures should be aligned among dependent layers
1425        if( refpicLayer )
1426
1427        {
1428          assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ||
1429                    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R );
1430        }
1431      }
1432    }
1433  }
1434#endif
1435
1436#else //SVC_EXTENSION
1437  //we should only get a different poc for a new picture (with CTU address==0)
1438  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
1439  {
1440    printf ("Warning, the first slice of a picture might have been lost!\n");
1441  }
1442  // exit when a new picture is found
1443  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
1444  {
1445    if (m_prevPOC >= m_pocRandomAccess)
1446    {
1447      m_prevPOC = m_apcSlicePilot->getPOC();
1448      return true;
1449    }
1450    m_prevPOC = m_apcSlicePilot->getPOC();
1451  }
1452
1453  // actual decoding starts here
1454  xActivateParameterSets();
1455
1456  if (m_apcSlicePilot->isNextSlice()) 
1457  {
1458    m_prevPOC = m_apcSlicePilot->getPOC();
1459  }
1460  m_bFirstSliceInSequence = false;
1461#endif //SVC_EXTENSION
1462  //detect lost reference picture and insert copy of earlier frame.
1463  Int lostPoc;
1464  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
1465  {
1466    xCreateLostPicture(lostPoc-1);
1467  }
1468  if (m_bFirstSliceInPicture)
1469  {
1470#if AVC_BASE
1471    if( m_layerId == 1 && m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1472    {
1473      TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
1474      pBLPic->getSlice(0)->setReferenced(true);
1475      fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
1476
1477      if( pFile->good() )
1478      {
1479        Bool is16bit  = g_bitDepthYLayer[0] > 8 || g_bitDepthCLayer[0] > 8;
1480        UInt uiWidth  = pBLPic->getPicYuvRec()->getWidth();
1481        UInt uiHeight = pBLPic->getPicYuvRec()->getHeight();
1482
1483        Int len = uiWidth * (is16bit ? 2 : 1);
1484        UChar *buf = new UChar[len];
1485
1486        UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
1487        if( is16bit )
1488        {
1489            uiPos <<= 1;
1490        }
1491
1492        pFile->seekg((UInt)uiPos, ios::beg );
1493
1494        // read Y component
1495        Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
1496        UInt uiStride = pBLPic->getPicYuvRec()->getStride();
1497        for( Int i = 0; i < uiHeight; i++ )
1498        {
1499          pFile->read(reinterpret_cast<Char*>(buf), len);
1500
1501          if( !is16bit )
1502          {
1503            for (Int x = 0; x < uiWidth; x++)
1504            {
1505              pPel[x] = buf[x];
1506            }
1507          }
1508          else
1509          {
1510            for (Int x = 0; x < uiWidth; x++)
1511            {
1512              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
1513            }
1514          }
1515     
1516          pPel += uiStride;
1517        }
1518
1519        len >>= 1;
1520        uiWidth >>= 1;
1521        uiHeight >>= 1;
1522
1523        // read Cb component
1524        pPel = pBLPic->getPicYuvRec()->getCbAddr();
1525        uiStride = pBLPic->getPicYuvRec()->getCStride();
1526        for( Int i = 0; i < uiHeight; i++ )
1527        {
1528          pFile->read(reinterpret_cast<Char*>(buf), len);
1529
1530          if( !is16bit )
1531          {
1532            for( Int x = 0; x < uiWidth; x++ )
1533            {
1534              pPel[x] = buf[x];
1535            }
1536          }
1537          else
1538          {
1539            for( Int x = 0; x < uiWidth; x++ )
1540            {
1541              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
1542            }
1543          }
1544     
1545          pPel += uiStride;
1546        }
1547
1548        // read Cr component
1549        pPel = pBLPic->getPicYuvRec()->getCrAddr();
1550        uiStride = pBLPic->getPicYuvRec()->getCStride();
1551        for( Int i = 0; i < uiHeight; i++ )
1552        {
1553          pFile->read(reinterpret_cast<Char*>(buf), len);
1554
1555          if( !is16bit )
1556          {
1557            for( Int x = 0; x < uiWidth; x++ )
1558            {
1559              pPel[x] = buf[x];
1560            }
1561          }
1562          else
1563          {
1564            for( Int x = 0; x < uiWidth; x++ )
1565            {
1566              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
1567            }
1568          }
1569     
1570          pPel += uiStride;
1571        }
1572
1573        delete[] buf;
1574      }
1575    }
1576#endif
1577
1578#if NO_OUTPUT_OF_PRIOR_PICS
1579    if ( m_layerId == 0 && m_apcSlicePilot->getRapPicFlag() && getNoClrasOutputFlag() )
1580    {
1581      for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getMaxLayers(); i++)
1582      {
1583        m_ppcTDecTop[i]->setLayerInitializedFlag(false);
1584        m_ppcTDecTop[i]->setFirstPicInLayerDecodedFlag(false);
1585      }
1586    }
1587#endif
1588    // Buffer initialize for prediction.
1589    m_cPrediction.initTempBuff();
1590#if ALIGNED_BUMPING
1591    m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic);
1592#else
1593    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
1594#endif
1595    //  Get a new picture buffer
1596    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
1597
1598#if POC_RESET_IDC_DECODER
1599  pcPic->setCurrAuFlag( true );
1600#endif
1601
1602    Bool isField = false;
1603    Bool isTff = false;
1604   
1605    if(!m_SEIs.empty())
1606    {
1607      // Check if any new Picture Timing SEI has arrived
1608      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
1609      if (pictureTimingSEIs.size()>0)
1610      {
1611        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
1612        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
1613        isTff =  (pictureTiming->m_picStruct == 1);
1614      }
1615    }
1616   
1617    //Set Field/Frame coding mode
1618    m_pcPic->setField(isField);
1619    m_pcPic->setTopField(isTff);
1620
1621    // transfer any SEI messages that have been received to the picture
1622    pcPic->setSEIs(m_SEIs);
1623    m_SEIs.clear();
1624
1625    // Recursive structure
1626    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
1627#if SVC_EXTENSION
1628    m_cCuDecoder.init   ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId );
1629#else
1630    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
1631#endif
1632    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
1633
1634    m_cSliceDecoder.create();
1635  }
1636  else
1637  {
1638    // Check if any new SEI has arrived
1639    if(!m_SEIs.empty())
1640    {
1641      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
1642      SEIMessages &picSEI = pcPic->getSEIs();
1643      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
1644      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
1645      deleteSEIs(m_SEIs);
1646    }
1647  }
1648 
1649  //  Set picture slice pointer
1650  TComSlice*  pcSlice = m_apcSlicePilot;
1651  Bool bNextSlice     = pcSlice->isNextSlice();
1652
1653  UInt uiCummulativeTileWidth;
1654  UInt uiCummulativeTileHeight;
1655  UInt i, j, p;
1656
1657  //set NumColumnsMins1 and NumRowsMinus1
1658  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
1659  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
1660
1661  //create the TComTileArray
1662  pcPic->getPicSym()->xCreateTComTileArray();
1663
1664  if( pcSlice->getPPS()->getUniformSpacingFlag() )
1665  {
1666    //set the width for each tile
1667    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
1668    {
1669      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
1670      {
1671        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
1672          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
1673          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
1674      }
1675    }
1676
1677    //set the height for each tile
1678    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
1679    {
1680      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
1681      {
1682        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
1683          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
1684          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
1685      }
1686    }
1687  }
1688  else
1689  {
1690    //set the width for each tile
1691    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
1692    {
1693      uiCummulativeTileWidth = 0;
1694      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
1695      {
1696        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
1697        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
1698      }
1699      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
1700    }
1701
1702    //set the height for each tile
1703    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
1704    {
1705      uiCummulativeTileHeight = 0;
1706      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
1707      { 
1708        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
1709        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
1710      }
1711      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
1712    }
1713  }
1714
1715  pcPic->getPicSym()->xInitTiles();
1716
1717  //generate the Coding Order Map and Inverse Coding Order Map
1718  UInt uiEncCUAddr;
1719  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
1720  {
1721    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
1722    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
1723  }
1724  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1725  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1726
1727  //convert the start and end CU addresses of the slice and dependent slice into encoding order
1728  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
1729  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
1730  if(pcSlice->isNextSlice())
1731  {
1732    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
1733    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
1734  }
1735
1736  if (m_bFirstSliceInPicture) 
1737  {
1738    if(pcPic->getNumAllocatedSlice() != 1)
1739    {
1740      pcPic->clearSliceBuffer();
1741    }
1742  }
1743  else
1744  {
1745    pcPic->allocateNewSlice();
1746  }
1747  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
1748  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
1749  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
1750
1751  pcPic->setTLayer(nalu.m_temporalId);
1752
1753#if SVC_EXTENSION
1754  pcPic->setLayerId(nalu.m_layerId);
1755  pcSlice->setLayerId(nalu.m_layerId);
1756  pcSlice->setPic(pcPic);
1757#endif
1758
1759  if (bNextSlice)
1760  {
1761    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
1762    // Set reference list
1763#if SVC_EXTENSION
1764    if (m_layerId == 0)
1765#endif
1766    pcSlice->setRefPicList( m_cListPic, true );
1767
1768#if SVC_EXTENSION
1769    // Create upsampling reference layer pictures for all possible dependent layers and do it only once for the first slice.
1770    // Other slices might choose which reference pictures to be used for inter-layer prediction
1771    if( m_layerId > 0 && m_uiSliceIdx == 0 )
1772    {     
1773#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1774      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
1775#endif
1776      for( i = 0; i < pcSlice->getNumILRRefIdx(); i++ )
1777      {
1778        UInt refLayerIdc = i;
1779        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc);
1780#if AVC_BASE
1781        if( refLayerId == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
1782        {         
1783          TComPic* pic = *m_ppcTDecTop[0]->getListPic()->begin();
1784
1785          if( pic )
1786          {
1787            pcSlice->setBaseColPic ( refLayerIdc, pic );
1788          }
1789          else
1790          {
1791            continue;
1792          }
1793        }
1794        else
1795        {
1796#if VPS_EXTN_DIRECT_REF_LAYERS
1797          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1798#else
1799          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1800#endif
1801          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1802          if( !pcSlice->setBaseColPic ( *cListPic, refLayerIdc ) )
1803          {
1804            continue;
1805          }
1806        }
1807#else
1808#if VPS_EXTN_DIRECT_REF_LAYERS
1809        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1810#else
1811        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1812#endif
1813        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1814        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1815#endif
1816
1817#if O0098_SCALED_REF_LAYER_ID
1818        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
1819#else
1820        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
1821#endif
1822
1823        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
1824        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
1825#if Q0200_CONFORMANCE_BL_SIZE
1826        Int chromaFormatIdc = pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getChromaFormatIdc();
1827        const Window &confBL = pcSlice->getBaseColPic(refLayerIdc)->getConformanceWindow(); 
1828        widthBL  -= ( confBL.getWindowLeftOffset() + confBL.getWindowRightOffset() ) * TComSPS::getWinUnitX( chromaFormatIdc );
1829        heightBL -= ( confBL.getWindowTopOffset() + confBL.getWindowBottomOffset() ) * TComSPS::getWinUnitY( chromaFormatIdc );
1830#endif
1831        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
1832        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
1833
1834        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
1835        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
1836
1837        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
1838        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
1839
1840#if Q0048_CGS_3D_ASYMLUT
1841        TComPicYuv* pBaseColRec = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec();
1842        if( pcSlice->getPPS()->getCGSFlag() )
1843        {
1844          if(!m_pColorMappedPic)
1845          {
1846            initAsymLut(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0));
1847          }
1848          m_c3DAsymLUTPPS.colorMapping( pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(),  m_pColorMappedPic );
1849          pBaseColRec = m_pColorMappedPic;
1850        }
1851#endif
1852#if SVC_EXTENSION
1853        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
1854        {
1855          // check for the sample prediction picture type
1856          if( m_ppcTDecTop[m_layerId]->getSamplePredEnabledFlag(refLayerId) )
1857          {
1858#if O0215_PHASE_ALIGNMENT
1859#if O0194_JOINT_US_BITSHIFT
1860#if Q0048_CGS_3D_ASYMLUT
1861            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
1862#else
1863            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
1864#endif
1865#else
1866#if Q0048_CGS_3D_ASYMLUT
1867            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
1868#else
1869            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
1870#endif
1871#endif
1872#else
1873#if O0194_JOINT_US_BITSHIFT
1874#if Q0048_CGS_3D_ASYMLUT
1875            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
1876#else
1877            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
1878#endif
1879#else
1880#if Q0048_CGS_3D_ASYMLUT
1881            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
1882#else
1883            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
1884#endif
1885#endif
1886#endif
1887          }
1888        }
1889        else
1890        {
1891          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
1892        }
1893        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
1894#endif //SVC_EXTENSION
1895      }
1896    }
1897
1898    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
1899    {
1900      for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
1901      {
1902        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
1903#if AVC_BASE
1904        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
1905        {
1906          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
1907        }
1908        else
1909        {
1910#if VPS_EXTN_DIRECT_REF_LAYERS
1911          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1912#else
1913          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1914#endif
1915          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1916          pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1917        }
1918#else
1919#if VPS_EXTN_DIRECT_REF_LAYERS
1920        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1921#else
1922        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1923#endif
1924        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1925        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1926#endif
1927
1928        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
1929      }
1930
1931      pcSlice->setILRPic( m_cIlpPic );
1932
1933#if REF_IDX_MFM
1934      if( pcSlice->getMFMEnabledFlag() )
1935      {
1936        pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
1937      }
1938      pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
1939    }
1940#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1941    else if ( m_layerId > 0 )
1942    {
1943      pcSlice->setRefPicList( m_cListPic, false, NULL);
1944    }
1945#endif
1946#if MFM_ENCCONSTRAINT
1947    if( pcSlice->getMFMEnabledFlag() )
1948    {
1949      TComPic* refPic = pcSlice->getRefPic( pcSlice->getSliceType() == B_SLICE ? ( RefPicList )( 1 - pcSlice->getColFromL0Flag() ) : REF_PIC_LIST_0 , pcSlice->getColRefIdx() );
1950
1951      assert( refPic );
1952
1953      Int refLayerId = refPic->getLayerId();
1954
1955      if( refLayerId != pcSlice->getLayerId() )
1956      {
1957        TComPic* pColBasePic = pcSlice->getBaseColPic( *m_ppcTDecTop[refLayerId]->getListPic() );
1958        assert( pColBasePic->checkSameRefInfo() == true );
1959      }
1960    }
1961#endif
1962#endif
1963   
1964    if( m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag() )
1965    {
1966#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1967      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
1968#endif
1969      for(Int dependentLayerIdx = 0; dependentLayerIdx < pcSlice->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1970      {
1971        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1972        TComPic* refpicLayer = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
1973        if(refpicLayer && pcSlice->isIRAP())
1974        {                 
1975          assert(pcSlice->getNalUnitType() == refpicLayer->getSlice(0)->getNalUnitType());
1976        }
1977      }
1978    }
1979
1980    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
1981    {
1982      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
1983
1984      assert( refPic );
1985
1986      // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture,
1987      // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture.
1988      if( refPic->isILR(pcSlice->getLayerId()) )
1989      {
1990        assert( m_ppcTDecTop[m_layerId]->getMotionPredEnabledFlag(refPic->getLayerId()) );
1991      }
1992    }
1993#endif //SVC_EXTENSION
1994   
1995    // For generalized B
1996    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1997    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1998    {
1999      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
2000      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
2001
2002      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
2003      {
2004        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
2005      }
2006    }
2007    if (!pcSlice->isIntra())
2008    {
2009      Bool bLowDelay = true;
2010      Int  iCurrPOC  = pcSlice->getPOC();
2011      Int iRefIdx = 0;
2012
2013      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
2014      {
2015        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
2016        {
2017          bLowDelay = false;
2018        }
2019      }
2020      if (pcSlice->isInterB())
2021      {
2022        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
2023        {
2024          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
2025          {
2026            bLowDelay = false;
2027          }
2028        }       
2029      }
2030
2031      pcSlice->setCheckLDC(bLowDelay);           
2032    }
2033
2034    //---------------
2035    pcSlice->setRefPOCList();
2036  }
2037
2038  pcPic->setCurrSliceIdx(m_uiSliceIdx);
2039  if(pcSlice->getSPS()->getScalingListFlag())
2040  {
2041    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
2042    if(pcSlice->getPPS()->getScalingListPresentFlag())
2043    {
2044      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
2045    }
2046#if SCALINGLIST_INFERRING
2047    if( m_layerId == 0 || ( m_layerId > 0 && !pcSlice->getPPS()->getInferScalingListFlag() && !pcSlice->getSPS()->getInferScalingListFlag() ) )
2048#endif
2049    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
2050    {
2051      pcSlice->setDefaultScalingList();
2052    }
2053    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
2054    m_cTrQuant.setUseScalingList(true);
2055  }
2056  else
2057  {
2058    m_cTrQuant.setFlatScalingList();
2059    m_cTrQuant.setUseScalingList(false);
2060  }
2061
2062  //  Decode a picture
2063  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
2064
2065  m_bFirstSliceInPicture = false;
2066  m_uiSliceIdx++;
2067
2068  return false;
2069}
2070
2071Void TDecTop::xDecodeVPS()
2072{
2073  TComVPS* vps = new TComVPS();
2074 
2075  m_cEntropyDecoder.decodeVPS( vps );
2076  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
2077}
2078
2079Void TDecTop::xDecodeSPS()
2080{
2081  TComSPS* sps = new TComSPS();
2082#if SVC_EXTENSION
2083  sps->setLayerId(m_layerId);
2084#if SPS_DPB_PARAMS
2085  m_cEntropyDecoder.decodeSPS( sps ); // it should be removed after macro clean up
2086#else
2087  m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder );
2088#endif
2089  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
2090#if Q0078_ADD_LAYER_SETS
2091  // Store SPS for all layers
2092  for (Int lId = 0; lId < m_numLayer; lId++)
2093  {
2094    if (m_ppcTDecTop[lId] != this)
2095    {
2096      m_ppcTDecTop[lId]->getParameterSetManager()->storePrefetchedSPS(sps);
2097    }
2098  }
2099#endif
2100#if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation 
2101  if(m_numLayer>0)
2102  {
2103    xInitILRP(sps);
2104  }
2105#endif
2106#else //SVC_EXTENSION
2107  m_cEntropyDecoder.decodeSPS( sps );
2108  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
2109#endif //SVC_EXTENSION
2110}
2111
2112Void TDecTop::xDecodePPS(
2113#if Q0048_CGS_3D_ASYMLUT
2114  TCom3DAsymLUT * pc3DAsymLUT
2115#endif
2116  )
2117{
2118  TComPPS* pps = new TComPPS();
2119
2120#if SCALINGLIST_INFERRING
2121  pps->setLayerId( m_layerId );
2122#endif
2123
2124  m_cEntropyDecoder.decodePPS( pps
2125#if Q0048_CGS_3D_ASYMLUT
2126    , pc3DAsymLUT , m_layerId
2127#endif
2128    );
2129  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
2130#if Q0078_ADD_LAYER_SETS
2131  // Store PPS for all layers
2132  for (Int lId = 0; lId < m_numLayer; lId++)
2133  {
2134    if (m_ppcTDecTop[lId] != this)
2135    {
2136      m_ppcTDecTop[lId]->getParameterSetManager()->storePrefetchedPPS(pps);
2137    }
2138  }
2139#endif
2140
2141  if( pps->getDependentSliceSegmentsEnabledFlag() )
2142  {
2143    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
2144    m_cSliceDecoder.initCtxMem(NumCtx);
2145    for ( UInt st = 0; st < NumCtx; st++ )
2146    {
2147      TDecSbac* ctx = NULL;
2148      ctx = new TDecSbac;
2149      ctx->init( &m_cBinCABAC );
2150      m_cSliceDecoder.setCtxMem( ctx, st );
2151    }
2152  }
2153}
2154
2155Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
2156{
2157#if SVC_EXTENSION
2158  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
2159  {
2160    if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
2161    {
2162      return;
2163    }
2164#if LAYERS_NOT_PRESENT_SEI
2165    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
2166#else
2167    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
2168#endif
2169  }
2170  else
2171  {
2172#if LAYERS_NOT_PRESENT_SEI
2173    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
2174#else
2175    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
2176#endif
2177    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
2178    if (activeParamSets.size()>0)
2179    {
2180      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
2181      m_parameterSetManagerDecoder.applyPrefetchedPS();
2182      assert(seiAps->activeSeqParameterSetId.size()>0);
2183      if( !m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[0] ) )
2184      {
2185        printf ("Warning SPS activation with Active parameter set SEI failed");
2186      }
2187    }
2188#if Q0074_SEI_COLOR_MAPPING
2189    m_ColorMapping->setColorMapping( m_SEIs );
2190#endif
2191  }
2192#else
2193  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
2194  {
2195#if LAYERS_NOT_PRESENT_SEI
2196    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
2197#else
2198    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
2199#endif
2200  }
2201  else
2202  {
2203#if LAYERS_NOT_PRESENT_SEI
2204    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
2205#else
2206    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
2207#endif
2208    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
2209    if (activeParamSets.size()>0)
2210    {
2211      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
2212      m_parameterSetManagerDecoder.applyPrefetchedPS();
2213      assert(seiAps->activeSeqParameterSetId.size()>0);
2214      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
2215      {
2216        printf ("Warning SPS activation with Active parameter set SEI failed");
2217      }
2218    }
2219  }
2220#endif
2221}
2222
2223#if SVC_EXTENSION
2224Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
2225#else
2226Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
2227#endif
2228{
2229  // Initialize entropy decoder
2230  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
2231  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
2232
2233#if O0137_MAX_LAYERID
2234  // ignore any NAL units with nuh_layer_id == 63
2235  if (nalu.m_layerId == 63 )
2236  { 
2237    return false;
2238  }
2239#endif
2240  switch (nalu.m_nalUnitType)
2241  {
2242    case NAL_UNIT_VPS:
2243#if SVC_EXTENSION
2244      assert( nalu.m_layerId == 0 ); // Non-conforming bitstream. The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
2245#endif
2246      xDecodeVPS();
2247#if Q0177_EOS_CHECKS
2248      m_isLastNALWasEos = false;
2249#endif
2250#if AVC_BASE
2251      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
2252      {
2253        if( !m_ppcTDecTop[0]->getBLReconFile()->good() )
2254        {
2255          printf( "Base layer YUV input reading error\n" );
2256          exit(EXIT_FAILURE);
2257        }       
2258      }
2259      else
2260      {
2261        TComList<TComPic*> *cListPic = m_ppcTDecTop[0]->getListPic();
2262        cListPic->clear();
2263      }
2264#endif
2265      return false;
2266     
2267    case NAL_UNIT_SPS:
2268      xDecodeSPS();
2269      return false;
2270
2271    case NAL_UNIT_PPS:
2272      xDecodePPS(
2273#if Q0048_CGS_3D_ASYMLUT
2274        &m_c3DAsymLUTPPS
2275#endif
2276        );
2277      return false;
2278     
2279    case NAL_UNIT_PREFIX_SEI:
2280    case NAL_UNIT_SUFFIX_SEI:
2281#if Q0177_EOS_CHECKS
2282      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
2283      {
2284        assert( m_isLastNALWasEos == false );
2285      }
2286#endif
2287      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
2288      return false;
2289
2290    case NAL_UNIT_CODED_SLICE_TRAIL_R:
2291    case NAL_UNIT_CODED_SLICE_TRAIL_N:
2292    case NAL_UNIT_CODED_SLICE_TSA_R:
2293    case NAL_UNIT_CODED_SLICE_TSA_N:
2294    case NAL_UNIT_CODED_SLICE_STSA_R:
2295    case NAL_UNIT_CODED_SLICE_STSA_N:
2296    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
2297    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
2298    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
2299    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
2300    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
2301    case NAL_UNIT_CODED_SLICE_CRA:
2302    case NAL_UNIT_CODED_SLICE_RADL_N:
2303    case NAL_UNIT_CODED_SLICE_RADL_R:
2304    case NAL_UNIT_CODED_SLICE_RASL_N:
2305    case NAL_UNIT_CODED_SLICE_RASL_R:
2306#if Q0177_EOS_CHECKS
2307      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
2308          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
2309          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
2310          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
2311          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
2312      {
2313        assert( m_isLastNALWasEos == false );
2314      }
2315      else
2316      {
2317        m_isLastNALWasEos = false;
2318      }
2319#endif
2320#if SVC_EXTENSION
2321      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
2322#else
2323      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
2324#endif
2325      break;
2326     
2327    case NAL_UNIT_EOS:
2328#if Q0177_EOS_CHECKS
2329      assert( m_isLastNALWasEos == false );
2330      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
2331      if (nalu.m_layerId > 0)
2332      {
2333        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
2334        return false;
2335      }
2336      m_isLastNALWasEos = true;
2337#endif
2338      m_associatedIRAPType = NAL_UNIT_INVALID;
2339      m_pocCRA = 0;
2340      m_pocRandomAccess = MAX_INT;
2341      m_prevPOC = MAX_INT;
2342      m_bFirstSliceInPicture = true;
2343      m_bFirstSliceInSequence = true;
2344      m_prevSliceSkipped = false;
2345      m_skippedPOC = 0;
2346      return false;
2347     
2348    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
2349      // TODO: process AU delimiter
2350      return false;
2351     
2352    case NAL_UNIT_EOB:
2353#if P0130_EOB
2354      //Check layer id of the nalu. if it is not 0, give a warning message.
2355      if (nalu.m_layerId > 0)
2356      {
2357        printf( "\n\nThis bitstream is ended with EOB NALU that has layer id greater than 0\n" );
2358      }
2359#endif
2360      return false;
2361     
2362    case NAL_UNIT_FILLER_DATA:
2363#if Q0177_EOS_CHECKS
2364      assert( m_isLastNALWasEos == false );
2365#endif
2366      return false;
2367     
2368    case NAL_UNIT_RESERVED_VCL_N10:
2369    case NAL_UNIT_RESERVED_VCL_R11:
2370    case NAL_UNIT_RESERVED_VCL_N12:
2371    case NAL_UNIT_RESERVED_VCL_R13:
2372    case NAL_UNIT_RESERVED_VCL_N14:
2373    case NAL_UNIT_RESERVED_VCL_R15:
2374     
2375    case NAL_UNIT_RESERVED_IRAP_VCL22:
2376    case NAL_UNIT_RESERVED_IRAP_VCL23:
2377     
2378    case NAL_UNIT_RESERVED_VCL24:
2379    case NAL_UNIT_RESERVED_VCL25:
2380    case NAL_UNIT_RESERVED_VCL26:
2381    case NAL_UNIT_RESERVED_VCL27:
2382    case NAL_UNIT_RESERVED_VCL28:
2383    case NAL_UNIT_RESERVED_VCL29:
2384    case NAL_UNIT_RESERVED_VCL30:
2385    case NAL_UNIT_RESERVED_VCL31:
2386     
2387    case NAL_UNIT_RESERVED_NVCL41:
2388    case NAL_UNIT_RESERVED_NVCL42:
2389    case NAL_UNIT_RESERVED_NVCL43:
2390    case NAL_UNIT_RESERVED_NVCL44:
2391    case NAL_UNIT_RESERVED_NVCL45:
2392    case NAL_UNIT_RESERVED_NVCL46:
2393    case NAL_UNIT_RESERVED_NVCL47:
2394    case NAL_UNIT_UNSPECIFIED_48:
2395    case NAL_UNIT_UNSPECIFIED_49:
2396    case NAL_UNIT_UNSPECIFIED_50:
2397    case NAL_UNIT_UNSPECIFIED_51:
2398    case NAL_UNIT_UNSPECIFIED_52:
2399    case NAL_UNIT_UNSPECIFIED_53:
2400    case NAL_UNIT_UNSPECIFIED_54:
2401    case NAL_UNIT_UNSPECIFIED_55:
2402    case NAL_UNIT_UNSPECIFIED_56:
2403    case NAL_UNIT_UNSPECIFIED_57:
2404    case NAL_UNIT_UNSPECIFIED_58:
2405    case NAL_UNIT_UNSPECIFIED_59:
2406    case NAL_UNIT_UNSPECIFIED_60:
2407    case NAL_UNIT_UNSPECIFIED_61:
2408    case NAL_UNIT_UNSPECIFIED_62:
2409    case NAL_UNIT_UNSPECIFIED_63:
2410
2411    default:
2412      assert (0);
2413  }
2414
2415  return false;
2416}
2417
2418/** Function for checking if picture should be skipped because of association with a previous BLA picture
2419 * \param iPOCLastDisplay POC of last picture displayed
2420 * \returns true if the picture should be skipped
2421 * This function skips all TFD pictures that follow a BLA picture
2422 * in decoding order and precede it in output order.
2423 */
2424Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
2425{
2426  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) && 
2427       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
2428  {
2429    iPOCLastDisplay++;
2430    return true;
2431  }
2432  return false;
2433}
2434
2435/** Function for checking if picture should be skipped because of random access
2436 * \param iSkipFrame skip frame counter
2437 * \param iPOCLastDisplay POC of last picture displayed
2438 * \returns true if the picture shold be skipped in the random access.
2439 * This function checks the skipping of pictures in the case of -s option random access.
2440 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
2441 * It also checks the type of Nal unit type at the random access point.
2442 * 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.
2443 * If the random access point is IDR all pictures after the random access point are decoded.
2444 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
2445 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
2446 * access point there is no guarantee that the decoder will not crash.
2447 */
2448Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
2449{
2450  if (iSkipFrame) 
2451  {
2452    iSkipFrame--;   // decrement the counter
2453    return true;
2454  }
2455  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
2456  {
2457    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
2458        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2459        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
2460        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
2461    {
2462      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
2463      m_pocRandomAccess = m_apcSlicePilot->getPOC();
2464    }
2465    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
2466    {
2467      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
2468    }
2469    else 
2470    {
2471      static Bool warningMessage = false;
2472      if(!warningMessage)
2473      {
2474        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
2475        warningMessage = true;
2476      }
2477      return true;
2478    }
2479  }
2480  // skip the reordered pictures, if necessary
2481  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))
2482  {
2483    iPOCLastDisplay++;
2484    return true;
2485  }
2486  // if we reach here, then the picture is not skipped.
2487  return false; 
2488}
2489
2490#if SVC_EXTENSION
2491#if VPS_EXTN_DIRECT_REF_LAYERS
2492TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc )
2493{
2494  TComVPS* vps = m_parameterSetManagerDecoder.getActiveVPS();
2495  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
2496  {
2497    return (TDecTop *)getLayerDec( 0 );
2498  }
2499 
2500  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdc ) );
2501}
2502#endif
2503
2504#if VPS_EXTN_DIRECT_REF_LAYERS
2505Void TDecTop::setRefLayerParams( TComVPS* vps )
2506{
2507  for(UInt layer = 0; layer < m_numLayer; layer++)
2508  {
2509    TDecTop *decTop = (TDecTop *)getLayerDec(layer);
2510    decTop->setNumSamplePredRefLayers(0);
2511    decTop->setNumMotionPredRefLayers(0);
2512    decTop->setNumDirectRefLayers(0);
2513    for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++)
2514    {
2515      decTop->setSamplePredEnabledFlag(i, false);
2516      decTop->setMotionPredEnabledFlag(i, false);
2517      decTop->setSamplePredRefLayerId(i, 0);
2518      decTop->setMotionPredRefLayerId(i, 0);
2519    }
2520    for(Int j = 0; j < layer; j++)
2521    {
2522      if (vps->getDirectDependencyFlag(layer, j))
2523      {
2524        decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layer));
2525        decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1);
2526
2527        Int samplePredEnabledFlag = (vps->getDirectDependencyType(layer, j) + 1) & 1;
2528        decTop->setSamplePredEnabledFlag(j, samplePredEnabledFlag == 1 ? true : false);
2529        decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag);
2530
2531        Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layer, j) + 1) & 2) >> 1;
2532        decTop->setMotionPredEnabledFlag(j, motionPredEnabledFlag == 1 ? true : false);
2533        decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag);
2534      }
2535    }
2536  }
2537  for( Int i = 1; i < m_numLayer; i++ )
2538  {
2539    Int mIdx = 0, sIdx = 0;
2540    Int iNuhLId = vps->getLayerIdInNuh(i);
2541    TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId);
2542    for ( Int j = 0; j < i; j++ )
2543    {
2544      if (decTop->getMotionPredEnabledFlag(j))
2545      {
2546        decTop->setMotionPredRefLayerId(mIdx++, vps->getLayerIdInNuh(j));
2547      }
2548      if (decTop->getSamplePredEnabledFlag(j))
2549      {
2550        decTop->setSamplePredRefLayerId(sIdx++, vps->getLayerIdInNuh(j));
2551      }
2552    }
2553  }
2554}
2555
2556#endif
2557
2558#if OUTPUT_LAYER_SET_INDEX
2559Void TDecTop::checkValueOfTargetOutputLayerSetIdx(TComVPS *vps)
2560{
2561  CommonDecoderParams* params = this->getCommonDecoderParams();
2562
2563  assert( params->getTargetLayerId() < vps->getMaxLayers() );
2564
2565  if( params->getValueCheckedFlag() )
2566  {
2567    return; // Already checked
2568  }
2569  if( params->getTargetOutputLayerSetIdx() == -1 )  // Output layer set index not specified
2570  {
2571    Bool layerSetMatchFound = false;
2572    // Output layer set index not assigned.
2573    // Based on the value of targetLayerId, check if any of the output layer matches
2574    // Currently, the target layer ID in the encoder assumes that all the layers are decoded   
2575    // Check if any of the output layer sets match this description
2576    for(Int i = 0; i < vps->getNumOutputLayerSets(); i++)
2577    {
2578      Bool layerSetMatchFlag = true;
2579      Int layerSetIdx = vps->getOutputLayerSetIdx( i );
2580      if( vps->getNumLayersInIdList( layerSetIdx ) == params->getTargetLayerId() + 1 )
2581      {
2582        for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
2583        {
2584          if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
2585          {
2586            layerSetMatchFlag = false;
2587            break;
2588          }
2589        }
2590      }
2591      else
2592      {
2593        layerSetMatchFlag = false;
2594      }
2595     
2596      if( layerSetMatchFlag ) // Potential output layer set candidate found
2597      {
2598        // If target dec layer ID list is also included - check if they match
2599        if( params->getTargetDecLayerIdSet() )
2600        {
2601          if( params->getTargetDecLayerIdSet()->size() ) 
2602          {
2603            for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
2604            {
2605              if( *(params->getTargetDecLayerIdSet()->begin() + j) != vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, j )))
2606              {
2607                layerSetMatchFlag = false;
2608              }
2609            }
2610          }
2611        }
2612        if( layerSetMatchFlag ) // The target dec layer ID list also matches, if present
2613        {
2614          // Match found
2615          layerSetMatchFound = true;
2616          params->setTargetOutputLayerSetIdx( i );
2617          params->setValueCheckedFlag( true );
2618          break;
2619        }
2620      }
2621    }
2622    assert( layerSetMatchFound ); // No output layer set matched the value of either targetLayerId or targetdeclayerIdlist
2623  }   
2624  else // Output layer set index is assigned - check if the values match
2625  {
2626    // Check if the target decoded layer is the highest layer in the list
2627    assert( params->getTargetOutputLayerSetIdx() < vps->getNumLayerSets() );
2628    Int layerSetIdx = vps->getOutputLayerSetIdx( params->getTargetOutputLayerSetIdx() );  // Index to the layer set
2629    assert( params->getTargetLayerId() == vps->getNumLayersInIdList( layerSetIdx ) - 1);
2630
2631    Bool layerSetMatchFlag = true;
2632    for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
2633    {
2634      if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
2635      {
2636        layerSetMatchFlag = false;
2637        break;
2638      }
2639    }
2640
2641    assert(layerSetMatchFlag);    // Signaled output layer set index does not match targetOutputLayerId.
2642   
2643    // Check if the targetdeclayerIdlist matches the output layer set
2644    if( params->getTargetDecLayerIdSet() )
2645    {
2646      if( params->getTargetDecLayerIdSet()->size() ) 
2647      {
2648        for(Int i = 0; i < vps->getNumLayersInIdList( layerSetIdx ); i++)
2649        {
2650          assert( *(params->getTargetDecLayerIdSet()->begin() + i) == vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, i )));
2651        }
2652      }
2653    }
2654    params->setValueCheckedFlag( true );
2655
2656  }
2657}
2658#endif
2659#if RESOLUTION_BASED_DPB
2660Void TDecTop::assignSubDpbs(TComVPS *vps)
2661{
2662  if( m_subDpbIdx == -1 ) // Sub-DPB index is not already assigned
2663  {
2664    Int lsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
2665
2666    Int layerIdx = vps->findLayerIdxInLayerSet( lsIdx, getLayerId() );
2667    assert( layerIdx != -1 ); // Current layer should be found in the layer set.
2668
2669    // Copy from the active VPS based on the layer ID.
2670    m_subDpbIdx = vps->getSubDpbAssigned( lsIdx, layerIdx );
2671  }
2672}
2673#endif
2674#if POC_RESET_IDC_DECODER
2675Void TDecTop::markAllPicsAsNoCurrAu()
2676{
2677  for(Int i = 0; i < MAX_LAYERS; i++)
2678  {
2679    TComList<TComPic*>* listPic = this->getLayerDec(i)->getListPic();
2680    TComList<TComPic*>::iterator  iterPic = listPic->begin();
2681    while ( iterPic != listPic->end() )
2682    {
2683      TComPic *pcPic = *(iterPic);
2684      pcPic->setCurrAuFlag( false );
2685      iterPic++;
2686    }
2687  }
2688}
2689#endif
2690#if Q0048_CGS_3D_ASYMLUT
2691Void TDecTop::initAsymLut(TComSlice *pcSlice)
2692{
2693  if(m_layerId>0)
2694  {
2695    if(!m_pColorMappedPic)
2696    {
2697      Int picWidth    = pcSlice->getPicWidthInLumaSamples();
2698      Int picHeight   = pcSlice->getPicHeightInLumaSamples();
2699      m_pColorMappedPic = new TComPicYuv;
2700      m_pColorMappedPic->create( picWidth, picHeight, pcSlice->getChromaFormatIdc()/*CHROMA_420*/, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
2701    }
2702  }
2703}
2704#endif
2705
2706#endif //SVC_EXTENSION
2707
2708#if Q0074_SEI_COLOR_MAPPING
2709TDecColorMapping::TDecColorMapping()
2710{
2711  m_pcColorMappingPic[0]   = NULL;
2712  m_pcColorMappingPic[1]   = NULL;
2713
2714  m_colorMapCancelFlag  = true;
2715
2716  for( Int i=0 ; i<3 ; i++ )
2717  {
2718    m_lut1d_computed[i]             = false;
2719    m_lut1d_input[i]                = NULL;
2720    m_coded_input_pivot_value[i]    = NULL;
2721    m_target_input_pivot_value[i]   = NULL;
2722  }
2723  for( Int i=0 ; i<3 ; i++ )
2724  {
2725    m_lut1d_output[i]               = NULL;
2726    m_coded_output_pivot_value[i]   = NULL;
2727    m_target_output_pivot_value[i]  = NULL;
2728  }
2729}
2730
2731TDecColorMapping::~TDecColorMapping()
2732{
2733  if ( m_pcColorMappingPic[0] )  delete m_pcColorMappingPic[0];
2734  if ( m_pcColorMappingPic[1] )  delete m_pcColorMappingPic[1];
2735
2736  for( Int i=0 ; i<3 ; i++ )
2737  {
2738    if ( m_lut1d_input[i] )               delete  m_lut1d_input[i];
2739    if ( m_coded_input_pivot_value[i] )   delete  m_coded_input_pivot_value[i];
2740    if ( m_target_input_pivot_value[i] )  delete  m_target_input_pivot_value[i];
2741  }
2742  for( Int i=0 ; i<3 ; i++ )
2743  {
2744    if ( m_lut1d_output[i] )               delete  m_lut1d_output[i];
2745    if ( m_coded_output_pivot_value[i] )   delete  m_coded_output_pivot_value[i];
2746    if ( m_target_output_pivot_value[i] )  delete  m_target_output_pivot_value[i];
2747  }
2748}
2749
2750Void  TDecColorMapping::setColorMapping( SEIMessages m_SEIs )
2751{
2752  SEIMessages colorMappingInfo = getSeisByType(m_SEIs, SEI::COLOR_MAPPING_INFO) ;
2753  SEIColorMappingInfo *seiColorMappingInfo = NULL;
2754  if (colorMappingInfo.size() !=0)
2755  {
2756    seiColorMappingInfo = (SEIColorMappingInfo*)(*colorMappingInfo.begin());
2757
2758    m_colorMapId                              = seiColorMappingInfo->m_colorMapId;
2759    m_colorMapCancelFlag                      = seiColorMappingInfo->m_colorMapCancelFlag;
2760    if( !m_colorMapCancelFlag )
2761    {
2762      m_colorMapPersistenceFlag                 = seiColorMappingInfo->m_colorMapPersistenceFlag;
2763      m_colorMap_video_signal_type_present_flag = seiColorMappingInfo->m_colorMap_video_signal_type_present_flag;
2764      m_colorMap_video_full_range_flag          = seiColorMappingInfo->m_colorMap_video_full_range_flag;
2765      m_colorMap_primaries                      = seiColorMappingInfo->m_colorMap_primaries;
2766      m_colorMap_transfer_characteristics       = seiColorMappingInfo->m_colorMap_transfer_characteristics;
2767      m_colorMap_matrix_coeffs                  = seiColorMappingInfo->m_colorMap_matrix_coeffs;
2768      m_colorMapModelId                         = seiColorMappingInfo->m_colorMapModelId;
2769
2770      m_colour_map_coded_data_bit_depth         = seiColorMappingInfo->m_colour_map_coded_data_bit_depth;
2771      m_colour_map_target_bit_depth             = seiColorMappingInfo->m_colour_map_target_bit_depth;
2772
2773      for( Int i=0 ; i<3 ; i++ )
2774      {
2775        m_num_input_pivots[i]                 = seiColorMappingInfo->m_num_input_pivots[i];
2776        if ( m_coded_input_pivot_value[i] )   delete  m_coded_input_pivot_value[i];
2777        if ( m_target_input_pivot_value[i] )  delete  m_target_input_pivot_value[i];
2778        m_coded_input_pivot_value[i]          = new Int[ m_num_input_pivots[i] ];
2779        m_target_input_pivot_value[i]         = new Int[ m_num_input_pivots[i] ];
2780        for( Int j=0 ; j<m_num_input_pivots[i] ; j++ )
2781        {
2782          m_coded_input_pivot_value[i][j]     = seiColorMappingInfo->m_coded_input_pivot_value[i][j];
2783          m_target_input_pivot_value[i][j]    = seiColorMappingInfo->m_target_input_pivot_value[i][j];
2784        }
2785      }
2786
2787      m_matrix_flag       = seiColorMappingInfo->m_matrix_flag;
2788      m_log2_matrix_denom = m_matrix_flag ? (seiColorMappingInfo->m_log2_matrix_denom) : (0) ;
2789      for( Int i=0 ; i<3 ; i++ )
2790      {
2791        for( Int j=0 ; j<3 ; j++ )
2792        {
2793          m_matrix_coef[i][j]  = seiColorMappingInfo->m_matrix_coef[i][j];
2794        }
2795      }
2796
2797      for( Int i=0 ; i<3 ; i++ )
2798      {
2799        m_num_output_pivots[i]                 = seiColorMappingInfo->m_num_output_pivots[i];
2800        if ( m_coded_output_pivot_value[i] )   delete  m_coded_output_pivot_value[i];
2801        if ( m_target_output_pivot_value[i] )  delete  m_target_output_pivot_value[i];
2802        m_coded_output_pivot_value[i]          = new Int[ m_num_output_pivots[i] ];
2803        m_target_output_pivot_value[i]         = new Int[ m_num_output_pivots[i] ];
2804        for( Int j=0 ; j<m_num_output_pivots[i] ; j++ )
2805        {
2806          m_coded_output_pivot_value[i][j]     = seiColorMappingInfo->m_coded_output_pivot_value[i][j];
2807          m_target_output_pivot_value[i][j]    = seiColorMappingInfo->m_target_output_pivot_value[i][j];
2808        }
2809      }
2810
2811      memset( m_lut1d_computed, 0, sizeof( m_lut1d_computed ) );
2812    }
2813  }
2814
2815}
2816
2817Void  TDecColorMapping::setColorMapping( Int bitDepth, Int iComp )
2818{
2819  if( !m_colorMapCancelFlag && !m_lut1d_computed[iComp] )
2820  {
2821
2822    if ( m_lut1d_input[iComp] )   delete m_lut1d_input[iComp];
2823    if ( m_lut1d_output[iComp] )  delete m_lut1d_output[iComp];
2824
2825    m_lut1d_input[iComp]  = new Int[ 1 << bitDepth ];
2826    m_lut1d_output[iComp] = new Int[ 1 << bitDepth ];
2827
2828    Int iShift      = (m_colour_map_coded_data_bit_depth >= bitDepth) ? (m_colour_map_coded_data_bit_depth - bitDepth) : (0);
2829    Int iShiftPivot = (m_colour_map_coded_data_bit_depth >= bitDepth) ? (0) : (bitDepth - m_colour_map_coded_data_bit_depth);
2830
2831    for( Int k=0 ; k<(1<<bitDepth) ; k++ )
2832    {
2833      Int iSample = k << iShift ;
2834      if( m_num_input_pivots[iComp] > 1 )
2835      {
2836        for( Int iPivot=0 ; iPivot<m_num_input_pivots[iComp] ; iPivot++ )
2837        {
2838          Int iCodedPrev  = m_coded_input_pivot_value[iComp][iPivot]     << iShiftPivot;
2839          Int iCodedNext  = m_coded_input_pivot_value[iComp][iPivot+1]   << iShiftPivot;
2840          Int iTargetPrev = m_target_input_pivot_value[iComp][iPivot]    << iShiftPivot;
2841          Int iTargetNext = m_target_input_pivot_value[iComp][iPivot+1]  << iShiftPivot;
2842          if ( iCodedPrev <= iSample && iSample < iCodedNext )
2843          {
2844            Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) / (Float)(iCodedNext - iCodedPrev) ;
2845            m_lut1d_input[iComp][k]  = (Int)( 0.5 + fInterpol );
2846            iPivot = m_num_input_pivots[iComp]; // stop
2847          }
2848        }
2849      }
2850      else
2851      {
2852        m_lut1d_input[iComp][k]  = k;
2853      }
2854    }
2855
2856    iShift      = ( (m_colour_map_coded_data_bit_depth >= bitDepth) ? (m_colour_map_coded_data_bit_depth - bitDepth) : (0) );
2857    Int iOffset = iShift ? (1 << (iShift - 1)) : (0) ;
2858    iShiftPivot = (m_colour_map_target_bit_depth >= bitDepth) ? (0) : (bitDepth - m_colour_map_target_bit_depth) ;
2859    for( Int k=0 ; k<(1<<bitDepth) ; k++ )
2860    {
2861      Int iSample = k << iShift;
2862      if ( m_num_output_pivots[iComp]>1 )
2863      {
2864        for( Int iPivot=0 ; iPivot<m_num_output_pivots[iComp] ; iPivot++ )
2865        {
2866          Int iCodedPrev  = m_coded_output_pivot_value[iComp][iPivot]     << iShiftPivot;
2867          Int iCodedNext  = m_coded_output_pivot_value[iComp][iPivot+1]   << iShiftPivot;
2868          Int iTargetPrev = m_target_output_pivot_value[iComp][iPivot]    << iShiftPivot;
2869          Int iTargetNext = m_target_output_pivot_value[iComp][iPivot+1]  << iShiftPivot;
2870          if ( iCodedPrev <= iSample && iSample < iCodedNext )
2871          {
2872            Float fInterpol =  (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) / (Float)(iCodedNext - iCodedPrev) ;
2873            m_lut1d_output[iComp][k]  = ( (Int)(0.5 + fInterpol) + iOffset ) >> iShift ;
2874            iPivot = m_num_output_pivots[iComp]; // stop
2875          }
2876        }
2877      }
2878      else
2879      {
2880        m_lut1d_output[iComp][k]  = k;
2881      }
2882    }
2883
2884    m_lut1d_computed[iComp] = true;
2885  }
2886
2887}
2888
2889TComPicYuv* TDecColorMapping::getColorMapping( TComPicYuv* pPicYuvRec, Int iTop, Int curlayerId )
2890{
2891  if( !m_colorMapCancelFlag )
2892  {
2893    if( !m_pcColorMappingPic[iTop] )
2894    {
2895      m_pcColorMappingPic[iTop] = new TComPicYuv;
2896#if SVC_EXTENSION
2897      m_pcColorMappingPic[iTop]->create( pPicYuvRec->getWidth(), pPicYuvRec->getHeight(), pPicYuvRec->getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
2898#else
2899      m_pcColorMappingPic[iTop]->create( pPicYuvRec->getWidth(), pPicYuvRec->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
2900#endif
2901    }
2902
2903    Int iHeight   = pPicYuvRec->getHeight();
2904    Int iWidth    = pPicYuvRec->getWidth();
2905    Int iStride   = pPicYuvRec->getStride();
2906    Int iCStride  = pPicYuvRec->getCStride();
2907
2908    Pel* Lum0   = pPicYuvRec->getLumaAddr();
2909    Pel* Cb0    = pPicYuvRec->getCbAddr();
2910    Pel* Cr0    = pPicYuvRec->getCrAddr();
2911    Pel* Lum1   = m_pcColorMappingPic[iTop]->getLumaAddr();
2912    Pel* Cb1    = m_pcColorMappingPic[iTop]->getCbAddr();
2913    Pel* Cr1    = m_pcColorMappingPic[iTop]->getCrAddr();
2914
2915#if SVC_EXTENSION
2916    Int bitDepthY = g_bitDepthYLayer[curlayerId];
2917    Int bitDepthC = g_bitDepthCLayer[curlayerId];
2918
2919    assert( g_bitDepthY == bitDepthY );
2920    assert( g_bitDepthC == bitDepthC );
2921#else
2922    Int bitDepthY = g_bitDepthY;
2923    Int bitDepthC = g_bitDepthC;
2924#endif
2925
2926    Int iYShift = (m_colour_map_target_bit_depth >= bitDepthY) ? (m_colour_map_target_bit_depth - bitDepthY) : (0) ;
2927    Int iCShift = (m_colour_map_target_bit_depth >= bitDepthC) ? (m_colour_map_target_bit_depth - bitDepthC) : (0) ;
2928    Int offsetY = (1 << (m_log2_matrix_denom+iYShift - 1));
2929    Int offsetC = (1 << (m_log2_matrix_denom+iCShift - 1));
2930
2931    Int   cShift  = 1 ;
2932
2933    //Pel*  LumPrev0 = Lum0;
2934    for( Int y = 0; y < iHeight ; y++ )
2935    {
2936      Bool  bDoChroma = (y % 2);
2937      for( Int x = 0; x < iWidth ; x++ )
2938      {
2939        Int s1Y = m_lut1d_input[0][ Lum0[x]   ];
2940        Int s1U = m_lut1d_input[1][ Cb0[x>>1] ];
2941        Int s1V = m_lut1d_input[2][ Cr0[x>>1] ];
2942
2943        Int s2Y, s2U, s2V;
2944        if( m_matrix_flag )
2945        {
2946          s2Y = ( m_matrix_coef[0][0]*s1Y + m_matrix_coef[0][1]*s1U + m_matrix_coef[0][2]*s1V + offsetY ) >> ( m_log2_matrix_denom + iYShift );
2947          //s2Y = ClipBD( s2Y , bitDepthY );
2948          s2Y = ClipY( s2Y );
2949          Lum1[x]   = m_lut1d_output[0][ s2Y ];
2950        }
2951        else
2952        {
2953          s1Y       = ( s1Y + offsetY ) >> iYShift ;
2954          //s1Y = ClipBD( s1Y , bitDepthY );
2955          s1Y = ClipY( s1Y );
2956          Lum1[x]   = m_lut1d_output[0][ s1Y ];
2957        }
2958
2959        if( bDoChroma && (x%2) )
2960        {
2961          if( m_matrix_flag )
2962          {
2963            //s1Y = ( m_lut1d_input[0][ Lum0[x] ] + m_lut1d_input[0][ Lum0[x+1] ] + m_lut1d_input[0][ LumPrev0[x] ] + m_lut1d_input[0][ LumPrev0[x+1] ] + 2 ) >> 2 ;
2964            //s1Y = m_lut1d_input[0][ (Lum0[x] + Lum0[x+1] + LumPrev0[x] + LumPrev0[x+1] + 2)>>2 ] ;
2965            s1Y = m_lut1d_input[0][ Lum0[x] ];
2966
2967            s2U = ( m_matrix_coef[1][0]*s1Y + m_matrix_coef[1][1]*s1U + m_matrix_coef[1][2]*s1V + offsetC ) >> ( m_log2_matrix_denom + iCShift ) ;
2968            s2V = ( m_matrix_coef[2][0]*s1Y + m_matrix_coef[2][1]*s1U + m_matrix_coef[2][2]*s1V + offsetC ) >> ( m_log2_matrix_denom + iCShift ) ;
2969            //s2U = ClipBD( s2U , bitDepthC );
2970            //s2V = ClipBD( s2V , bitDepthC );
2971            s2U = ClipC( s2U );
2972            s2V = ClipC( s2V );
2973            Cb1[x>>cShift] = m_lut1d_output[1][ s2U ];
2974            Cr1[x>>cShift] = m_lut1d_output[2][ s2V ];
2975          }
2976          else
2977          {
2978            s1U       = ( s1U + offsetC ) >> iCShift ;
2979            s1V       = ( s1V + offsetC ) >> iCShift ;
2980            //s1U = ClipBD( s1U , bitDepthC );
2981            //s1V = ClipBD( s1V , bitDepthC );
2982            s1U = ClipC( s1U );
2983            s1V = ClipC( s1V );
2984            Cb1[x>>cShift] = m_lut1d_output[1][ s1U ];
2985            Cr1[x>>cShift] = m_lut1d_output[2][ s1V ];
2986          }
2987        }
2988
2989      }
2990
2991      //LumPrev0 = Lum0;
2992      Lum0  += iStride;
2993      Lum1  += iStride;
2994      if( bDoChroma )
2995      {
2996        Cb0 += iCStride;
2997        Cr0 += iCStride;
2998        Cb1 += iCStride;
2999        Cr1 += iCStride;
3000      }
3001    }
3002
3003    return m_pcColorMappingPic[iTop];
3004  }
3005
3006  return pPicYuvRec; 
3007}
3008#endif
3009
3010//! \}
Note: See TracBrowser for help on using the repository browser.