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

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

Integration of R0151(R0151_CGS_3D_ASYMLUT_IMPROVE), R0150 (R0150_CGS_SIGNAL_CONSTRAINTS), and R0164 (R0164_CGS_LUT_BUGFIX)

  • Property svn:eol-style set to native
File size: 105.1 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->getNumTileColumnsMinus1() + 1) : 1);
857#else
858  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 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 i;
1654  pcPic->getPicSym()->initTiles(pcSlice->getPPS());
1655
1656  //generate the Coding Order Map and Inverse Coding Order Map
1657  UInt uiEncCUAddr;
1658  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
1659  {
1660    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
1661    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
1662  }
1663  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1664  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1665
1666  //convert the start and end CU addresses of the slice and dependent slice into encoding order
1667  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
1668  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
1669  if(pcSlice->isNextSlice())
1670  {
1671    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
1672    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
1673  }
1674
1675  if (m_bFirstSliceInPicture) 
1676  {
1677    if(pcPic->getNumAllocatedSlice() != 1)
1678    {
1679      pcPic->clearSliceBuffer();
1680    }
1681  }
1682  else
1683  {
1684    pcPic->allocateNewSlice();
1685  }
1686  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
1687  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
1688  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
1689
1690  pcPic->setTLayer(nalu.m_temporalId);
1691
1692#if SVC_EXTENSION
1693  pcPic->setLayerId(nalu.m_layerId);
1694  pcSlice->setLayerId(nalu.m_layerId);
1695  pcSlice->setPic(pcPic);
1696#endif
1697
1698  if (bNextSlice)
1699  {
1700    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
1701    // Set reference list
1702#if SVC_EXTENSION
1703    if (m_layerId == 0)
1704#endif
1705    pcSlice->setRefPicList( m_cListPic, true );
1706
1707#if SVC_EXTENSION
1708    // Create upsampling reference layer pictures for all possible dependent layers and do it only once for the first slice.
1709    // Other slices might choose which reference pictures to be used for inter-layer prediction
1710    if( m_layerId > 0 && m_uiSliceIdx == 0 )
1711    {     
1712#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1713      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
1714#endif
1715      for( i = 0; i < pcSlice->getNumILRRefIdx(); i++ )
1716      {
1717        UInt refLayerIdc = i;
1718        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc);
1719#if AVC_BASE
1720        if( refLayerId == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
1721        {         
1722          TComPic* pic = *m_ppcTDecTop[0]->getListPic()->begin();
1723
1724          if( pic )
1725          {
1726            pcSlice->setBaseColPic ( refLayerIdc, pic );
1727          }
1728          else
1729          {
1730            continue;
1731          }
1732        }
1733        else
1734        {
1735#if VPS_EXTN_DIRECT_REF_LAYERS
1736          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1737#else
1738          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1739#endif
1740          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1741          if( !pcSlice->setBaseColPic ( *cListPic, refLayerIdc ) )
1742          {
1743            continue;
1744          }
1745        }
1746#else
1747#if VPS_EXTN_DIRECT_REF_LAYERS
1748        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1749#else
1750        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1751#endif
1752        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1753        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1754#endif
1755
1756#if O0098_SCALED_REF_LAYER_ID
1757        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
1758#else
1759        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
1760#endif
1761
1762        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
1763        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
1764#if Q0200_CONFORMANCE_BL_SIZE
1765        Int chromaFormatIdc = pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getChromaFormatIdc();
1766        const Window &confBL = pcSlice->getBaseColPic(refLayerIdc)->getConformanceWindow(); 
1767        widthBL  -= ( confBL.getWindowLeftOffset() + confBL.getWindowRightOffset() ) * TComSPS::getWinUnitX( chromaFormatIdc );
1768        heightBL -= ( confBL.getWindowTopOffset() + confBL.getWindowBottomOffset() ) * TComSPS::getWinUnitY( chromaFormatIdc );
1769#endif
1770        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
1771        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
1772
1773        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
1774        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
1775
1776        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
1777        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
1778
1779#if Q0048_CGS_3D_ASYMLUT
1780        TComPicYuv* pBaseColRec = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec();
1781        if( pcSlice->getPPS()->getCGSFlag() 
1782#if R0150_CGS_SIGNAL_CONSTRAINTS
1783          && m_c3DAsymLUTPPS.isRefLayer( pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc) )
1784#endif
1785          )
1786        {
1787#if R0150_CGS_SIGNAL_CONSTRAINTS
1788          assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepthY() == m_c3DAsymLUTPPS.getInputBitDepthY() );
1789          assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepthC() == m_c3DAsymLUTPPS.getInputBitDepthC() );
1790          assert( pcSlice->getBitDepthY() >= m_c3DAsymLUTPPS.getOutputBitDepthY() );
1791          assert( pcSlice->getBitDepthY() >= m_c3DAsymLUTPPS.getOutputBitDepthC() );
1792#endif
1793          if(!m_pColorMappedPic)
1794          {
1795            initAsymLut(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0));
1796          }
1797          m_c3DAsymLUTPPS.colorMapping( pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(),  m_pColorMappedPic );
1798          pBaseColRec = m_pColorMappedPic;
1799        }
1800#endif
1801#if SVC_EXTENSION
1802        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
1803        {
1804          // check for the sample prediction picture type
1805          if( m_ppcTDecTop[m_layerId]->getSamplePredEnabledFlag(refLayerId) )
1806          {
1807#if O0215_PHASE_ALIGNMENT
1808#if O0194_JOINT_US_BITSHIFT
1809#if Q0048_CGS_3D_ASYMLUT
1810            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
1811#else
1812            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
1813#endif
1814#else
1815#if Q0048_CGS_3D_ASYMLUT
1816            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
1817#else
1818            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
1819#endif
1820#endif
1821#else
1822#if O0194_JOINT_US_BITSHIFT
1823#if Q0048_CGS_3D_ASYMLUT
1824            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
1825#else
1826            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
1827#endif
1828#else
1829#if Q0048_CGS_3D_ASYMLUT
1830            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
1831#else
1832            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
1833#endif
1834#endif
1835#endif
1836          }
1837        }
1838        else
1839        {
1840          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
1841        }
1842        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
1843#endif //SVC_EXTENSION
1844      }
1845    }
1846
1847    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
1848    {
1849      for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
1850      {
1851        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
1852#if AVC_BASE
1853        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
1854        {
1855          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
1856        }
1857        else
1858        {
1859#if VPS_EXTN_DIRECT_REF_LAYERS
1860          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1861#else
1862          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1863#endif
1864          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1865          pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1866        }
1867#else
1868#if VPS_EXTN_DIRECT_REF_LAYERS
1869        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1870#else
1871        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1872#endif
1873        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1874        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1875#endif
1876
1877        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
1878      }
1879
1880      pcSlice->setILRPic( m_cIlpPic );
1881
1882#if REF_IDX_MFM
1883      pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
1884    }
1885#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1886    else if ( m_layerId > 0 )
1887    {
1888      pcSlice->setRefPicList( m_cListPic, false, NULL);
1889    }
1890#endif
1891#if MFM_ENCCONSTRAINT
1892    if( pcSlice->getMFMEnabledFlag() )
1893    {
1894      TComPic* refPic = pcSlice->getRefPic( pcSlice->getSliceType() == B_SLICE ? ( RefPicList )( 1 - pcSlice->getColFromL0Flag() ) : REF_PIC_LIST_0 , pcSlice->getColRefIdx() );
1895
1896      assert( refPic );
1897
1898      Int refLayerId = refPic->getLayerId();
1899
1900      if( refLayerId != pcSlice->getLayerId() )
1901      {
1902        TComPic* pColBasePic = pcSlice->getBaseColPic( *m_ppcTDecTop[refLayerId]->getListPic() );
1903        assert( pColBasePic->checkSameRefInfo() == true );
1904      }
1905    }
1906#endif
1907#endif
1908   
1909    if( m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag() )
1910    {
1911#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1912      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
1913#endif
1914      for(Int dependentLayerIdx = 0; dependentLayerIdx < pcSlice->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1915      {
1916        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1917        TComPic* refpicLayer = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
1918        if(refpicLayer && pcSlice->isIRAP())
1919        {                 
1920          assert(pcSlice->getNalUnitType() == refpicLayer->getSlice(0)->getNalUnitType());
1921        }
1922      }
1923    }
1924
1925    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
1926    {
1927      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
1928
1929      assert( refPic );
1930
1931      // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture,
1932      // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture.
1933      if( refPic->isILR(pcSlice->getLayerId()) )
1934      {
1935        assert( m_ppcTDecTop[m_layerId]->getMotionPredEnabledFlag(refPic->getLayerId()) );
1936      }
1937    }
1938#endif //SVC_EXTENSION
1939   
1940    // For generalized B
1941    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1942    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1943    {
1944      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1945      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1946
1947      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1948      {
1949        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1950      }
1951    }
1952    if (!pcSlice->isIntra())
1953    {
1954      Bool bLowDelay = true;
1955      Int  iCurrPOC  = pcSlice->getPOC();
1956      Int iRefIdx = 0;
1957
1958      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1959      {
1960        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1961        {
1962          bLowDelay = false;
1963        }
1964      }
1965      if (pcSlice->isInterB())
1966      {
1967        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1968        {
1969          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1970          {
1971            bLowDelay = false;
1972          }
1973        }       
1974      }
1975
1976      pcSlice->setCheckLDC(bLowDelay);           
1977    }
1978
1979    //---------------
1980    pcSlice->setRefPOCList();
1981  }
1982
1983  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1984  if(pcSlice->getSPS()->getScalingListFlag())
1985  {
1986    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
1987    if(pcSlice->getPPS()->getScalingListPresentFlag())
1988    {
1989      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
1990    }
1991#if SCALINGLIST_INFERRING
1992    if( m_layerId == 0 || ( m_layerId > 0 && !pcSlice->getPPS()->getInferScalingListFlag() && !pcSlice->getSPS()->getInferScalingListFlag() ) )
1993#endif
1994    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1995    {
1996      pcSlice->setDefaultScalingList();
1997    }
1998    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1999    m_cTrQuant.setUseScalingList(true);
2000  }
2001  else
2002  {
2003    m_cTrQuant.setFlatScalingList();
2004    m_cTrQuant.setUseScalingList(false);
2005  }
2006
2007  //  Decode a picture
2008  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
2009
2010  m_bFirstSliceInPicture = false;
2011  m_uiSliceIdx++;
2012
2013  return false;
2014}
2015
2016Void TDecTop::xDecodeVPS()
2017{
2018  TComVPS* vps = new TComVPS();
2019 
2020  m_cEntropyDecoder.decodeVPS( vps );
2021  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
2022}
2023
2024Void TDecTop::xDecodeSPS()
2025{
2026  TComSPS* sps = new TComSPS();
2027#if SVC_EXTENSION
2028  sps->setLayerId(m_layerId);
2029#if SPS_DPB_PARAMS
2030  m_cEntropyDecoder.decodeSPS( sps ); // it should be removed after macro clean up
2031#else
2032  m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder );
2033#endif
2034  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
2035#if Q0078_ADD_LAYER_SETS
2036  // Store SPS for all layers
2037  for (Int lId = 0; lId < m_numLayer; lId++)
2038  {
2039    if (m_ppcTDecTop[lId] != this)
2040    {
2041      m_ppcTDecTop[lId]->getParameterSetManager()->storePrefetchedSPS(sps);
2042    }
2043  }
2044#endif
2045#if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation 
2046  if(m_numLayer>0)
2047  {
2048    xInitILRP(sps);
2049  }
2050#endif
2051#else //SVC_EXTENSION
2052  m_cEntropyDecoder.decodeSPS( sps );
2053  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
2054#endif //SVC_EXTENSION
2055}
2056
2057Void TDecTop::xDecodePPS(
2058#if Q0048_CGS_3D_ASYMLUT
2059  TCom3DAsymLUT * pc3DAsymLUT
2060#endif
2061  )
2062{
2063  TComPPS* pps = new TComPPS();
2064
2065#if SCALINGLIST_INFERRING
2066  pps->setLayerId( m_layerId );
2067#endif
2068
2069  m_cEntropyDecoder.decodePPS( pps
2070#if Q0048_CGS_3D_ASYMLUT
2071    , pc3DAsymLUT , m_layerId
2072#endif
2073    );
2074  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
2075#if Q0078_ADD_LAYER_SETS
2076  // Store PPS for all layers
2077  for (Int lId = 0; lId < m_numLayer; lId++)
2078  {
2079    if (m_ppcTDecTop[lId] != this)
2080    {
2081      m_ppcTDecTop[lId]->getParameterSetManager()->storePrefetchedPPS(pps);
2082    }
2083  }
2084#endif
2085
2086  if( pps->getDependentSliceSegmentsEnabledFlag() )
2087  {
2088    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
2089    m_cSliceDecoder.initCtxMem(NumCtx);
2090    for ( UInt st = 0; st < NumCtx; st++ )
2091    {
2092      TDecSbac* ctx = NULL;
2093      ctx = new TDecSbac;
2094      ctx->init( &m_cBinCABAC );
2095      m_cSliceDecoder.setCtxMem( ctx, st );
2096    }
2097  }
2098}
2099
2100Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
2101{
2102#if SVC_EXTENSION
2103  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
2104  {
2105    if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
2106    {
2107      return;
2108    }
2109#if LAYERS_NOT_PRESENT_SEI
2110    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
2111#else
2112    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
2113#endif
2114  }
2115  else
2116  {
2117#if LAYERS_NOT_PRESENT_SEI
2118    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
2119#else
2120    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
2121#endif
2122    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
2123    if (activeParamSets.size()>0)
2124    {
2125      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
2126      m_parameterSetManagerDecoder.applyPrefetchedPS();
2127      assert(seiAps->activeSeqParameterSetId.size()>0);
2128      if( !m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[0] ) )
2129      {
2130        printf ("Warning SPS activation with Active parameter set SEI failed");
2131      }
2132    }
2133#if Q0074_SEI_COLOR_MAPPING
2134    m_ColorMapping->setColorMapping( m_SEIs );
2135#endif
2136  }
2137#else
2138  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
2139  {
2140#if LAYERS_NOT_PRESENT_SEI
2141    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
2142#else
2143    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
2144#endif
2145  }
2146  else
2147  {
2148#if LAYERS_NOT_PRESENT_SEI
2149    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
2150#else
2151    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
2152#endif
2153    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
2154    if (activeParamSets.size()>0)
2155    {
2156      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
2157      m_parameterSetManagerDecoder.applyPrefetchedPS();
2158      assert(seiAps->activeSeqParameterSetId.size()>0);
2159      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
2160      {
2161        printf ("Warning SPS activation with Active parameter set SEI failed");
2162      }
2163    }
2164  }
2165#endif
2166}
2167
2168#if SVC_EXTENSION
2169Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
2170#else
2171Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
2172#endif
2173{
2174  // Initialize entropy decoder
2175  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
2176  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
2177
2178#if O0137_MAX_LAYERID
2179  // ignore any NAL units with nuh_layer_id == 63
2180  if (nalu.m_layerId == 63 )
2181  { 
2182    return false;
2183  }
2184#endif
2185  switch (nalu.m_nalUnitType)
2186  {
2187    case NAL_UNIT_VPS:
2188#if SVC_EXTENSION
2189      assert( nalu.m_layerId == 0 ); // Non-conforming bitstream. The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
2190#endif
2191      xDecodeVPS();
2192#if Q0177_EOS_CHECKS
2193      m_isLastNALWasEos = false;
2194#endif
2195#if AVC_BASE
2196      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
2197      {
2198        if( !m_ppcTDecTop[0]->getBLReconFile()->good() )
2199        {
2200          printf( "Base layer YUV input reading error\n" );
2201          exit(EXIT_FAILURE);
2202        }       
2203      }
2204      else
2205      {
2206        TComList<TComPic*> *cListPic = m_ppcTDecTop[0]->getListPic();
2207        cListPic->clear();
2208      }
2209#endif
2210      return false;
2211     
2212    case NAL_UNIT_SPS:
2213      xDecodeSPS();
2214      return false;
2215
2216    case NAL_UNIT_PPS:
2217      xDecodePPS(
2218#if Q0048_CGS_3D_ASYMLUT
2219        &m_c3DAsymLUTPPS
2220#endif
2221        );
2222      return false;
2223     
2224    case NAL_UNIT_PREFIX_SEI:
2225    case NAL_UNIT_SUFFIX_SEI:
2226#if Q0177_EOS_CHECKS
2227      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
2228      {
2229        assert( m_isLastNALWasEos == false );
2230      }
2231#endif
2232      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
2233      return false;
2234
2235    case NAL_UNIT_CODED_SLICE_TRAIL_R:
2236    case NAL_UNIT_CODED_SLICE_TRAIL_N:
2237    case NAL_UNIT_CODED_SLICE_TSA_R:
2238    case NAL_UNIT_CODED_SLICE_TSA_N:
2239    case NAL_UNIT_CODED_SLICE_STSA_R:
2240    case NAL_UNIT_CODED_SLICE_STSA_N:
2241    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
2242    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
2243    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
2244    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
2245    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
2246    case NAL_UNIT_CODED_SLICE_CRA:
2247    case NAL_UNIT_CODED_SLICE_RADL_N:
2248    case NAL_UNIT_CODED_SLICE_RADL_R:
2249    case NAL_UNIT_CODED_SLICE_RASL_N:
2250    case NAL_UNIT_CODED_SLICE_RASL_R:
2251#if Q0177_EOS_CHECKS
2252      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
2253          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
2254          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
2255          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
2256          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
2257      {
2258        assert( m_isLastNALWasEos == false );
2259      }
2260      else
2261      {
2262        m_isLastNALWasEos = false;
2263      }
2264#endif
2265#if SVC_EXTENSION
2266      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
2267#else
2268      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
2269#endif
2270      break;
2271     
2272    case NAL_UNIT_EOS:
2273#if Q0177_EOS_CHECKS
2274      assert( m_isLastNALWasEos == false );
2275      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
2276      if (nalu.m_layerId > 0)
2277      {
2278        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
2279        return false;
2280      }
2281      m_isLastNALWasEos = true;
2282#endif
2283      m_associatedIRAPType = NAL_UNIT_INVALID;
2284      m_pocCRA = 0;
2285      m_pocRandomAccess = MAX_INT;
2286      m_prevPOC = MAX_INT;
2287      m_bFirstSliceInPicture = true;
2288      m_bFirstSliceInSequence = true;
2289      m_prevSliceSkipped = false;
2290      m_skippedPOC = 0;
2291      return false;
2292     
2293    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
2294      // TODO: process AU delimiter
2295      return false;
2296     
2297    case NAL_UNIT_EOB:
2298#if P0130_EOB
2299      //Check layer id of the nalu. if it is not 0, give a warning message.
2300      if (nalu.m_layerId > 0)
2301      {
2302        printf( "\n\nThis bitstream is ended with EOB NALU that has layer id greater than 0\n" );
2303      }
2304#endif
2305      return false;
2306     
2307    case NAL_UNIT_FILLER_DATA:
2308#if Q0177_EOS_CHECKS
2309      assert( m_isLastNALWasEos == false );
2310#endif
2311      return false;
2312     
2313    case NAL_UNIT_RESERVED_VCL_N10:
2314    case NAL_UNIT_RESERVED_VCL_R11:
2315    case NAL_UNIT_RESERVED_VCL_N12:
2316    case NAL_UNIT_RESERVED_VCL_R13:
2317    case NAL_UNIT_RESERVED_VCL_N14:
2318    case NAL_UNIT_RESERVED_VCL_R15:
2319     
2320    case NAL_UNIT_RESERVED_IRAP_VCL22:
2321    case NAL_UNIT_RESERVED_IRAP_VCL23:
2322     
2323    case NAL_UNIT_RESERVED_VCL24:
2324    case NAL_UNIT_RESERVED_VCL25:
2325    case NAL_UNIT_RESERVED_VCL26:
2326    case NAL_UNIT_RESERVED_VCL27:
2327    case NAL_UNIT_RESERVED_VCL28:
2328    case NAL_UNIT_RESERVED_VCL29:
2329    case NAL_UNIT_RESERVED_VCL30:
2330    case NAL_UNIT_RESERVED_VCL31:
2331     
2332    case NAL_UNIT_RESERVED_NVCL41:
2333    case NAL_UNIT_RESERVED_NVCL42:
2334    case NAL_UNIT_RESERVED_NVCL43:
2335    case NAL_UNIT_RESERVED_NVCL44:
2336    case NAL_UNIT_RESERVED_NVCL45:
2337    case NAL_UNIT_RESERVED_NVCL46:
2338    case NAL_UNIT_RESERVED_NVCL47:
2339    case NAL_UNIT_UNSPECIFIED_48:
2340    case NAL_UNIT_UNSPECIFIED_49:
2341    case NAL_UNIT_UNSPECIFIED_50:
2342    case NAL_UNIT_UNSPECIFIED_51:
2343    case NAL_UNIT_UNSPECIFIED_52:
2344    case NAL_UNIT_UNSPECIFIED_53:
2345    case NAL_UNIT_UNSPECIFIED_54:
2346    case NAL_UNIT_UNSPECIFIED_55:
2347    case NAL_UNIT_UNSPECIFIED_56:
2348    case NAL_UNIT_UNSPECIFIED_57:
2349    case NAL_UNIT_UNSPECIFIED_58:
2350    case NAL_UNIT_UNSPECIFIED_59:
2351    case NAL_UNIT_UNSPECIFIED_60:
2352    case NAL_UNIT_UNSPECIFIED_61:
2353    case NAL_UNIT_UNSPECIFIED_62:
2354    case NAL_UNIT_UNSPECIFIED_63:
2355
2356    default:
2357      assert (0);
2358  }
2359
2360  return false;
2361}
2362
2363/** Function for checking if picture should be skipped because of association with a previous BLA picture
2364 * \param iPOCLastDisplay POC of last picture displayed
2365 * \returns true if the picture should be skipped
2366 * This function skips all TFD pictures that follow a BLA picture
2367 * in decoding order and precede it in output order.
2368 */
2369Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
2370{
2371  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) && 
2372       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
2373  {
2374    iPOCLastDisplay++;
2375    return true;
2376  }
2377  return false;
2378}
2379
2380/** Function for checking if picture should be skipped because of random access
2381 * \param iSkipFrame skip frame counter
2382 * \param iPOCLastDisplay POC of last picture displayed
2383 * \returns true if the picture shold be skipped in the random access.
2384 * This function checks the skipping of pictures in the case of -s option random access.
2385 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
2386 * It also checks the type of Nal unit type at the random access point.
2387 * 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.
2388 * If the random access point is IDR all pictures after the random access point are decoded.
2389 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
2390 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
2391 * access point there is no guarantee that the decoder will not crash.
2392 */
2393Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
2394{
2395  if (iSkipFrame) 
2396  {
2397    iSkipFrame--;   // decrement the counter
2398    return true;
2399  }
2400  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
2401  {
2402    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
2403        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2404        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
2405        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
2406    {
2407      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
2408      m_pocRandomAccess = m_apcSlicePilot->getPOC();
2409    }
2410    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
2411    {
2412      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
2413    }
2414    else 
2415    {
2416      static Bool warningMessage = false;
2417      if(!warningMessage)
2418      {
2419        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
2420        warningMessage = true;
2421      }
2422      return true;
2423    }
2424  }
2425  // skip the reordered pictures, if necessary
2426  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))
2427  {
2428    iPOCLastDisplay++;
2429    return true;
2430  }
2431  // if we reach here, then the picture is not skipped.
2432  return false; 
2433}
2434
2435#if SVC_EXTENSION
2436#if VPS_EXTN_DIRECT_REF_LAYERS
2437TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc )
2438{
2439  TComVPS* vps = m_parameterSetManagerDecoder.getActiveVPS();
2440  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
2441  {
2442    return (TDecTop *)getLayerDec( 0 );
2443  }
2444 
2445  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdc ) );
2446}
2447#endif
2448
2449#if VPS_EXTN_DIRECT_REF_LAYERS
2450Void TDecTop::setRefLayerParams( TComVPS* vps )
2451{
2452  for(UInt layer = 0; layer < m_numLayer; layer++)
2453  {
2454    TDecTop *decTop = (TDecTop *)getLayerDec(layer);
2455    decTop->setNumSamplePredRefLayers(0);
2456    decTop->setNumMotionPredRefLayers(0);
2457    decTop->setNumDirectRefLayers(0);
2458    for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++)
2459    {
2460      decTop->setSamplePredEnabledFlag(i, false);
2461      decTop->setMotionPredEnabledFlag(i, false);
2462      decTop->setSamplePredRefLayerId(i, 0);
2463      decTop->setMotionPredRefLayerId(i, 0);
2464    }
2465    for(Int j = 0; j < layer; j++)
2466    {
2467      if (vps->getDirectDependencyFlag(layer, j))
2468      {
2469        decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layer));
2470        decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1);
2471
2472        Int samplePredEnabledFlag = (vps->getDirectDependencyType(layer, j) + 1) & 1;
2473        decTop->setSamplePredEnabledFlag(j, samplePredEnabledFlag == 1 ? true : false);
2474        decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag);
2475
2476        Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layer, j) + 1) & 2) >> 1;
2477        decTop->setMotionPredEnabledFlag(j, motionPredEnabledFlag == 1 ? true : false);
2478        decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag);
2479      }
2480    }
2481  }
2482  for( Int i = 1; i < m_numLayer; i++ )
2483  {
2484    Int mIdx = 0, sIdx = 0;
2485    Int iNuhLId = vps->getLayerIdInNuh(i);
2486    TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId);
2487    for ( Int j = 0; j < i; j++ )
2488    {
2489      if (decTop->getMotionPredEnabledFlag(j))
2490      {
2491        decTop->setMotionPredRefLayerId(mIdx++, vps->getLayerIdInNuh(j));
2492      }
2493      if (decTop->getSamplePredEnabledFlag(j))
2494      {
2495        decTop->setSamplePredRefLayerId(sIdx++, vps->getLayerIdInNuh(j));
2496      }
2497    }
2498  }
2499}
2500
2501#endif
2502
2503#if OUTPUT_LAYER_SET_INDEX
2504Void TDecTop::checkValueOfTargetOutputLayerSetIdx(TComVPS *vps)
2505{
2506  CommonDecoderParams* params = this->getCommonDecoderParams();
2507
2508  assert( params->getTargetLayerId() < vps->getMaxLayers() );
2509
2510  if( params->getValueCheckedFlag() )
2511  {
2512    return; // Already checked
2513  }
2514  if( params->getTargetOutputLayerSetIdx() == -1 )  // Output layer set index not specified
2515  {
2516    Bool layerSetMatchFound = false;
2517    // Output layer set index not assigned.
2518    // Based on the value of targetLayerId, check if any of the output layer matches
2519    // Currently, the target layer ID in the encoder assumes that all the layers are decoded   
2520    // Check if any of the output layer sets match this description
2521    for(Int i = 0; i < vps->getNumOutputLayerSets(); i++)
2522    {
2523      Bool layerSetMatchFlag = true;
2524      Int layerSetIdx = vps->getOutputLayerSetIdx( i );
2525      if( vps->getNumLayersInIdList( layerSetIdx ) == params->getTargetLayerId() + 1 )
2526      {
2527        for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
2528        {
2529          if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
2530          {
2531            layerSetMatchFlag = false;
2532            break;
2533          }
2534        }
2535      }
2536      else
2537      {
2538        layerSetMatchFlag = false;
2539      }
2540     
2541      if( layerSetMatchFlag ) // Potential output layer set candidate found
2542      {
2543        // If target dec layer ID list is also included - check if they match
2544        if( params->getTargetDecLayerIdSet() )
2545        {
2546          if( params->getTargetDecLayerIdSet()->size() ) 
2547          {
2548            for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
2549            {
2550              if( *(params->getTargetDecLayerIdSet()->begin() + j) != vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, j )))
2551              {
2552                layerSetMatchFlag = false;
2553              }
2554            }
2555          }
2556        }
2557        if( layerSetMatchFlag ) // The target dec layer ID list also matches, if present
2558        {
2559          // Match found
2560          layerSetMatchFound = true;
2561          params->setTargetOutputLayerSetIdx( i );
2562          params->setValueCheckedFlag( true );
2563          break;
2564        }
2565      }
2566    }
2567    assert( layerSetMatchFound ); // No output layer set matched the value of either targetLayerId or targetdeclayerIdlist
2568  }   
2569  else // Output layer set index is assigned - check if the values match
2570  {
2571    // Check if the target decoded layer is the highest layer in the list
2572    assert( params->getTargetOutputLayerSetIdx() < vps->getNumLayerSets() );
2573    Int layerSetIdx = vps->getOutputLayerSetIdx( params->getTargetOutputLayerSetIdx() );  // Index to the layer set
2574    assert( params->getTargetLayerId() == vps->getNumLayersInIdList( layerSetIdx ) - 1);
2575
2576    Bool layerSetMatchFlag = true;
2577    for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
2578    {
2579      if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
2580      {
2581        layerSetMatchFlag = false;
2582        break;
2583      }
2584    }
2585
2586    assert(layerSetMatchFlag);    // Signaled output layer set index does not match targetOutputLayerId.
2587   
2588    // Check if the targetdeclayerIdlist matches the output layer set
2589    if( params->getTargetDecLayerIdSet() )
2590    {
2591      if( params->getTargetDecLayerIdSet()->size() ) 
2592      {
2593        for(Int i = 0; i < vps->getNumLayersInIdList( layerSetIdx ); i++)
2594        {
2595          assert( *(params->getTargetDecLayerIdSet()->begin() + i) == vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, i )));
2596        }
2597      }
2598    }
2599    params->setValueCheckedFlag( true );
2600
2601  }
2602}
2603#endif
2604#if RESOLUTION_BASED_DPB
2605Void TDecTop::assignSubDpbs(TComVPS *vps)
2606{
2607  if( m_subDpbIdx == -1 ) // Sub-DPB index is not already assigned
2608  {
2609    Int lsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
2610
2611    Int layerIdx = vps->findLayerIdxInLayerSet( lsIdx, getLayerId() );
2612    assert( layerIdx != -1 ); // Current layer should be found in the layer set.
2613
2614    // Copy from the active VPS based on the layer ID.
2615    m_subDpbIdx = vps->getSubDpbAssigned( lsIdx, layerIdx );
2616  }
2617}
2618#endif
2619#if POC_RESET_IDC_DECODER
2620Void TDecTop::markAllPicsAsNoCurrAu()
2621{
2622  for(Int i = 0; i < MAX_LAYERS; i++)
2623  {
2624    TComList<TComPic*>* listPic = this->getLayerDec(i)->getListPic();
2625    TComList<TComPic*>::iterator  iterPic = listPic->begin();
2626    while ( iterPic != listPic->end() )
2627    {
2628      TComPic *pcPic = *(iterPic);
2629      pcPic->setCurrAuFlag( false );
2630      iterPic++;
2631    }
2632  }
2633}
2634#endif
2635#if Q0048_CGS_3D_ASYMLUT
2636Void TDecTop::initAsymLut(TComSlice *pcSlice)
2637{
2638  if(m_layerId>0)
2639  {
2640    if(!m_pColorMappedPic)
2641    {
2642      Int picWidth    = pcSlice->getPicWidthInLumaSamples();
2643      Int picHeight   = pcSlice->getPicHeightInLumaSamples();
2644      m_pColorMappedPic = new TComPicYuv;
2645      m_pColorMappedPic->create( picWidth, picHeight, pcSlice->getChromaFormatIdc()/*CHROMA_420*/, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
2646    }
2647  }
2648}
2649#endif
2650
2651#endif //SVC_EXTENSION
2652
2653#if Q0074_SEI_COLOR_MAPPING
2654TDecColorMapping::TDecColorMapping()
2655{
2656  m_pcColorMappingPic[0]   = NULL;
2657  m_pcColorMappingPic[1]   = NULL;
2658
2659  m_colorMapCancelFlag  = true;
2660
2661  for( Int i=0 ; i<3 ; i++ )
2662  {
2663    m_lut1d_computed[i]             = false;
2664    m_lut1d_input[i]                = NULL;
2665    m_coded_input_pivot_value[i]    = NULL;
2666    m_target_input_pivot_value[i]   = NULL;
2667  }
2668  for( Int i=0 ; i<3 ; i++ )
2669  {
2670    m_lut1d_output[i]               = NULL;
2671    m_coded_output_pivot_value[i]   = NULL;
2672    m_target_output_pivot_value[i]  = NULL;
2673  }
2674}
2675
2676TDecColorMapping::~TDecColorMapping()
2677{
2678  if ( m_pcColorMappingPic[0] )  delete m_pcColorMappingPic[0];
2679  if ( m_pcColorMappingPic[1] )  delete m_pcColorMappingPic[1];
2680
2681  for( Int i=0 ; i<3 ; i++ )
2682  {
2683    if ( m_lut1d_input[i] )               delete  m_lut1d_input[i];
2684    if ( m_coded_input_pivot_value[i] )   delete  m_coded_input_pivot_value[i];
2685    if ( m_target_input_pivot_value[i] )  delete  m_target_input_pivot_value[i];
2686  }
2687  for( Int i=0 ; i<3 ; i++ )
2688  {
2689    if ( m_lut1d_output[i] )               delete  m_lut1d_output[i];
2690    if ( m_coded_output_pivot_value[i] )   delete  m_coded_output_pivot_value[i];
2691    if ( m_target_output_pivot_value[i] )  delete  m_target_output_pivot_value[i];
2692  }
2693}
2694
2695Void  TDecColorMapping::setColorMapping( SEIMessages m_SEIs )
2696{
2697  SEIMessages colorMappingInfo = getSeisByType(m_SEIs, SEI::COLOR_MAPPING_INFO) ;
2698  SEIColorMappingInfo *seiColorMappingInfo = NULL;
2699  if (colorMappingInfo.size() !=0)
2700  {
2701    seiColorMappingInfo = (SEIColorMappingInfo*)(*colorMappingInfo.begin());
2702
2703    m_colorMapId                              = seiColorMappingInfo->m_colorMapId;
2704    m_colorMapCancelFlag                      = seiColorMappingInfo->m_colorMapCancelFlag;
2705    if( !m_colorMapCancelFlag )
2706    {
2707      m_colorMapPersistenceFlag                 = seiColorMappingInfo->m_colorMapPersistenceFlag;
2708      m_colorMap_video_signal_type_present_flag = seiColorMappingInfo->m_colorMap_video_signal_type_present_flag;
2709      m_colorMap_video_full_range_flag          = seiColorMappingInfo->m_colorMap_video_full_range_flag;
2710      m_colorMap_primaries                      = seiColorMappingInfo->m_colorMap_primaries;
2711      m_colorMap_transfer_characteristics       = seiColorMappingInfo->m_colorMap_transfer_characteristics;
2712      m_colorMap_matrix_coeffs                  = seiColorMappingInfo->m_colorMap_matrix_coeffs;
2713      m_colorMapModelId                         = seiColorMappingInfo->m_colorMapModelId;
2714
2715      m_colour_map_coded_data_bit_depth         = seiColorMappingInfo->m_colour_map_coded_data_bit_depth;
2716      m_colour_map_target_bit_depth             = seiColorMappingInfo->m_colour_map_target_bit_depth;
2717
2718      for( Int i=0 ; i<3 ; i++ )
2719      {
2720        m_num_input_pivots[i]                 = seiColorMappingInfo->m_num_input_pivots[i];
2721        if ( m_coded_input_pivot_value[i] )   delete  m_coded_input_pivot_value[i];
2722        if ( m_target_input_pivot_value[i] )  delete  m_target_input_pivot_value[i];
2723        m_coded_input_pivot_value[i]          = new Int[ m_num_input_pivots[i] ];
2724        m_target_input_pivot_value[i]         = new Int[ m_num_input_pivots[i] ];
2725        for( Int j=0 ; j<m_num_input_pivots[i] ; j++ )
2726        {
2727          m_coded_input_pivot_value[i][j]     = seiColorMappingInfo->m_coded_input_pivot_value[i][j];
2728          m_target_input_pivot_value[i][j]    = seiColorMappingInfo->m_target_input_pivot_value[i][j];
2729        }
2730      }
2731
2732      m_matrix_flag       = seiColorMappingInfo->m_matrix_flag;
2733      m_log2_matrix_denom = m_matrix_flag ? (seiColorMappingInfo->m_log2_matrix_denom) : (0) ;
2734      for( Int i=0 ; i<3 ; i++ )
2735      {
2736        for( Int j=0 ; j<3 ; j++ )
2737        {
2738          m_matrix_coef[i][j]  = seiColorMappingInfo->m_matrix_coef[i][j];
2739        }
2740      }
2741
2742      for( Int i=0 ; i<3 ; i++ )
2743      {
2744        m_num_output_pivots[i]                 = seiColorMappingInfo->m_num_output_pivots[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        m_coded_output_pivot_value[i]          = new Int[ m_num_output_pivots[i] ];
2748        m_target_output_pivot_value[i]         = new Int[ m_num_output_pivots[i] ];
2749        for( Int j=0 ; j<m_num_output_pivots[i] ; j++ )
2750        {
2751          m_coded_output_pivot_value[i][j]     = seiColorMappingInfo->m_coded_output_pivot_value[i][j];
2752          m_target_output_pivot_value[i][j]    = seiColorMappingInfo->m_target_output_pivot_value[i][j];
2753        }
2754      }
2755
2756      memset( m_lut1d_computed, 0, sizeof( m_lut1d_computed ) );
2757    }
2758  }
2759
2760}
2761
2762Void  TDecColorMapping::setColorMapping( Int bitDepth, Int iComp )
2763{
2764  if( !m_colorMapCancelFlag && !m_lut1d_computed[iComp] )
2765  {
2766
2767    if ( m_lut1d_input[iComp] )   delete m_lut1d_input[iComp];
2768    if ( m_lut1d_output[iComp] )  delete m_lut1d_output[iComp];
2769
2770    m_lut1d_input[iComp]  = new Int[ 1 << bitDepth ];
2771    m_lut1d_output[iComp] = new Int[ 1 << bitDepth ];
2772
2773    Int iShift      = (m_colour_map_coded_data_bit_depth >= bitDepth) ? (m_colour_map_coded_data_bit_depth - bitDepth) : (0);
2774    Int iShiftPivot = (m_colour_map_coded_data_bit_depth >= bitDepth) ? (0) : (bitDepth - m_colour_map_coded_data_bit_depth);
2775
2776    for( Int k=0 ; k<(1<<bitDepth) ; k++ )
2777    {
2778      Int iSample = k << iShift ;
2779      if( m_num_input_pivots[iComp] > 1 )
2780      {
2781        for( Int iPivot=0 ; iPivot<m_num_input_pivots[iComp] ; iPivot++ )
2782        {
2783          Int iCodedPrev  = m_coded_input_pivot_value[iComp][iPivot]     << iShiftPivot;
2784          Int iCodedNext  = m_coded_input_pivot_value[iComp][iPivot+1]   << iShiftPivot;
2785          Int iTargetPrev = m_target_input_pivot_value[iComp][iPivot]    << iShiftPivot;
2786          Int iTargetNext = m_target_input_pivot_value[iComp][iPivot+1]  << iShiftPivot;
2787          if ( iCodedPrev <= iSample && iSample < iCodedNext )
2788          {
2789            Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) / (Float)(iCodedNext - iCodedPrev) ;
2790            m_lut1d_input[iComp][k]  = (Int)( 0.5 + fInterpol );
2791            iPivot = m_num_input_pivots[iComp]; // stop
2792          }
2793        }
2794      }
2795      else
2796      {
2797        m_lut1d_input[iComp][k]  = k;
2798      }
2799    }
2800
2801    iShift      = ( (m_colour_map_coded_data_bit_depth >= bitDepth) ? (m_colour_map_coded_data_bit_depth - bitDepth) : (0) );
2802    Int iOffset = iShift ? (1 << (iShift - 1)) : (0) ;
2803    iShiftPivot = (m_colour_map_target_bit_depth >= bitDepth) ? (0) : (bitDepth - m_colour_map_target_bit_depth) ;
2804    for( Int k=0 ; k<(1<<bitDepth) ; k++ )
2805    {
2806      Int iSample = k << iShift;
2807      if ( m_num_output_pivots[iComp]>1 )
2808      {
2809        for( Int iPivot=0 ; iPivot<m_num_output_pivots[iComp] ; iPivot++ )
2810        {
2811          Int iCodedPrev  = m_coded_output_pivot_value[iComp][iPivot]     << iShiftPivot;
2812          Int iCodedNext  = m_coded_output_pivot_value[iComp][iPivot+1]   << iShiftPivot;
2813          Int iTargetPrev = m_target_output_pivot_value[iComp][iPivot]    << iShiftPivot;
2814          Int iTargetNext = m_target_output_pivot_value[iComp][iPivot+1]  << iShiftPivot;
2815          if ( iCodedPrev <= iSample && iSample < iCodedNext )
2816          {
2817            Float fInterpol =  (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) / (Float)(iCodedNext - iCodedPrev) ;
2818            m_lut1d_output[iComp][k]  = ( (Int)(0.5 + fInterpol) + iOffset ) >> iShift ;
2819            iPivot = m_num_output_pivots[iComp]; // stop
2820          }
2821        }
2822      }
2823      else
2824      {
2825        m_lut1d_output[iComp][k]  = k;
2826      }
2827    }
2828
2829    m_lut1d_computed[iComp] = true;
2830  }
2831
2832}
2833
2834TComPicYuv* TDecColorMapping::getColorMapping( TComPicYuv* pPicYuvRec, Int iTop, Int curlayerId )
2835{
2836  if( !m_colorMapCancelFlag )
2837  {
2838    if( !m_pcColorMappingPic[iTop] )
2839    {
2840      m_pcColorMappingPic[iTop] = new TComPicYuv;
2841#if SVC_EXTENSION
2842      m_pcColorMappingPic[iTop]->create( pPicYuvRec->getWidth(), pPicYuvRec->getHeight(), pPicYuvRec->getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
2843#else
2844      m_pcColorMappingPic[iTop]->create( pPicYuvRec->getWidth(), pPicYuvRec->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
2845#endif
2846    }
2847
2848    Int iHeight   = pPicYuvRec->getHeight();
2849    Int iWidth    = pPicYuvRec->getWidth();
2850    Int iStride   = pPicYuvRec->getStride();
2851    Int iCStride  = pPicYuvRec->getCStride();
2852
2853    Pel* Lum0   = pPicYuvRec->getLumaAddr();
2854    Pel* Cb0    = pPicYuvRec->getCbAddr();
2855    Pel* Cr0    = pPicYuvRec->getCrAddr();
2856    Pel* Lum1   = m_pcColorMappingPic[iTop]->getLumaAddr();
2857    Pel* Cb1    = m_pcColorMappingPic[iTop]->getCbAddr();
2858    Pel* Cr1    = m_pcColorMappingPic[iTop]->getCrAddr();
2859
2860#if SVC_EXTENSION
2861    Int bitDepthY = g_bitDepthYLayer[curlayerId];
2862    Int bitDepthC = g_bitDepthCLayer[curlayerId];
2863
2864    assert( g_bitDepthY == bitDepthY );
2865    assert( g_bitDepthC == bitDepthC );
2866#else
2867    Int bitDepthY = g_bitDepthY;
2868    Int bitDepthC = g_bitDepthC;
2869#endif
2870
2871    Int iYShift = (m_colour_map_target_bit_depth >= bitDepthY) ? (m_colour_map_target_bit_depth - bitDepthY) : (0) ;
2872    Int iCShift = (m_colour_map_target_bit_depth >= bitDepthC) ? (m_colour_map_target_bit_depth - bitDepthC) : (0) ;
2873    Int offsetY = (1 << (m_log2_matrix_denom+iYShift - 1));
2874    Int offsetC = (1 << (m_log2_matrix_denom+iCShift - 1));
2875
2876    Int   cShift  = 1 ;
2877
2878    //Pel*  LumPrev0 = Lum0;
2879    for( Int y = 0; y < iHeight ; y++ )
2880    {
2881      Bool  bDoChroma = (y % 2);
2882      for( Int x = 0; x < iWidth ; x++ )
2883      {
2884        Int s1Y = m_lut1d_input[0][ Lum0[x]   ];
2885        Int s1U = m_lut1d_input[1][ Cb0[x>>1] ];
2886        Int s1V = m_lut1d_input[2][ Cr0[x>>1] ];
2887
2888        Int s2Y, s2U, s2V;
2889        if( m_matrix_flag )
2890        {
2891          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 );
2892          //s2Y = ClipBD( s2Y , bitDepthY );
2893          s2Y = ClipY( s2Y );
2894          Lum1[x]   = m_lut1d_output[0][ s2Y ];
2895        }
2896        else
2897        {
2898          s1Y       = ( s1Y + offsetY ) >> iYShift ;
2899          //s1Y = ClipBD( s1Y , bitDepthY );
2900          s1Y = ClipY( s1Y );
2901          Lum1[x]   = m_lut1d_output[0][ s1Y ];
2902        }
2903
2904        if( bDoChroma && (x%2) )
2905        {
2906          if( m_matrix_flag )
2907          {
2908            //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 ;
2909            //s1Y = m_lut1d_input[0][ (Lum0[x] + Lum0[x+1] + LumPrev0[x] + LumPrev0[x+1] + 2)>>2 ] ;
2910            s1Y = m_lut1d_input[0][ Lum0[x] ];
2911
2912            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 ) ;
2913            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 ) ;
2914            //s2U = ClipBD( s2U , bitDepthC );
2915            //s2V = ClipBD( s2V , bitDepthC );
2916            s2U = ClipC( s2U );
2917            s2V = ClipC( s2V );
2918            Cb1[x>>cShift] = m_lut1d_output[1][ s2U ];
2919            Cr1[x>>cShift] = m_lut1d_output[2][ s2V ];
2920          }
2921          else
2922          {
2923            s1U       = ( s1U + offsetC ) >> iCShift ;
2924            s1V       = ( s1V + offsetC ) >> iCShift ;
2925            //s1U = ClipBD( s1U , bitDepthC );
2926            //s1V = ClipBD( s1V , bitDepthC );
2927            s1U = ClipC( s1U );
2928            s1V = ClipC( s1V );
2929            Cb1[x>>cShift] = m_lut1d_output[1][ s1U ];
2930            Cr1[x>>cShift] = m_lut1d_output[2][ s1V ];
2931          }
2932        }
2933
2934      }
2935
2936      //LumPrev0 = Lum0;
2937      Lum0  += iStride;
2938      Lum1  += iStride;
2939      if( bDoChroma )
2940      {
2941        Cb0 += iCStride;
2942        Cr0 += iCStride;
2943        Cb1 += iCStride;
2944        Cr1 += iCStride;
2945      }
2946    }
2947
2948    return m_pcColorMappingPic[iTop];
2949  }
2950
2951  return pPicYuvRec; 
2952}
2953#endif
2954
2955//! \}
Note: See TracBrowser for help on using the repository browser.