source: SHVCSoftware/trunk/source/Lib/TLibDecoder/TDecTop.cpp @ 872

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

merge with SHM-6-dev branch

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