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

Last change on this file since 380 was 380, checked in by nokia, 11 years ago

updated decoder random access in accordance with HM12.0 and fixed related SEI crash problem

  • Property svn:eol-style set to native
File size: 51.6 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2013, 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_pocCRA = 0;
60  m_prevRAPisBLA = false;
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#if HM12_RANDOM_ACCESS
80  m_prevSliceSkipped = false;
81  m_skippedPOC = 0;
82#endif
83}
84
85TDecTop::~TDecTop()
86{
87#if ENC_DEC_TRACE
88  fclose( g_hTrace );
89#endif
90}
91
92Void TDecTop::create()
93{
94#if SVC_EXTENSION
95  m_cGopDecoder.create( m_layerId );
96#else
97  m_cGopDecoder.create();
98#endif
99  m_apcSlicePilot = new TComSlice;
100  m_uiSliceIdx = 0;
101}
102
103Void TDecTop::destroy()
104{
105  m_cGopDecoder.destroy();
106 
107  delete m_apcSlicePilot;
108  m_apcSlicePilot = NULL;
109 
110  m_cSliceDecoder.destroy();
111#if SVC_EXTENSION
112  for(Int i=0; i<MAX_NUM_REF; i++)
113  {
114    if(m_cIlpPic[i])
115    {
116      m_cIlpPic[i]->destroy();
117      delete m_cIlpPic[i];
118      m_cIlpPic[i] = NULL;
119    }
120  }   
121#endif
122}
123
124Void TDecTop::init()
125{
126#if !SVC_EXTENSION
127  // initialize ROM
128  initROM();
129#endif
130#if SVC_EXTENSION
131  m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
132  m_cSliceDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cCuDecoder );
133#else
134  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
135  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
136#endif
137  m_cEntropyDecoder.init(&m_cPrediction);
138}
139
140#if SVC_EXTENSION
141Void TDecTop::xInitILRP(TComSPS *pcSPS)
142{
143  if(m_layerId>0)
144  {
145    g_bitDepthY     = pcSPS->getBitDepthY();
146    g_bitDepthC     = pcSPS->getBitDepthC();
147    g_uiMaxCUWidth  = pcSPS->getMaxCUWidth();
148    g_uiMaxCUHeight = pcSPS->getMaxCUHeight();
149    g_uiMaxCUDepth  = pcSPS->getMaxCUDepth();
150    g_uiAddCUDepth  = max (0, pcSPS->getLog2MinCodingBlockSize() - (Int)pcSPS->getQuadtreeTULog2MinSize() );
151
152    Int  numReorderPics[MAX_TLAYER];
153    Window &conformanceWindow = pcSPS->getConformanceWindow();
154    Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window();
155
156    for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
157    {
158      numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
159    }
160
161    if (m_cIlpPic[0] == NULL)
162    {
163      for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++)  // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
164      {
165
166        m_cIlpPic[j] = new  TComPic;
167#if SVC_UPSAMPLING
168        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
169#else
170        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
171#endif
172        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
173        {
174          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
175        }
176      }
177    }
178  }
179}
180
181Void TDecTop::setILRPic(TComPic *pcPic)
182{
183  for( Int i = 0; i < pcPic->getSlice(0)->getActiveNumILRRefIdx(); i++ )
184  {
185    Int refLayerIdc = pcPic->getSlice(0)->getInterLayerPredLayerIdc(i);
186
187    if(m_cIlpPic[refLayerIdc])
188    {
189      m_cIlpPic[refLayerIdc]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(refLayerIdc), m_cIlpPic[refLayerIdc]->getPicYuvRec());
190      m_cIlpPic[refLayerIdc]->getSlice(0)->setPOC(pcPic->getPOC());
191      m_cIlpPic[refLayerIdc]->setLayerId(pcPic->getSlice(0)->getBaseColPic(refLayerIdc)->getLayerId()); //set reference layerId
192      m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false);
193      m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
194      for (Int j=0; j<m_cIlpPic[refLayerIdc]->getPicSym()->getNumberOfCUsInFrame(); j++)  // set reference CU layerId
195      {
196        m_cIlpPic[refLayerIdc]->getPicSym()->getCU(j)->setLayerId(m_cIlpPic[refLayerIdc]->getLayerId());
197      }
198    }
199  }
200}
201#endif
202
203Void TDecTop::deletePicBuffer ( )
204{
205  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
206  Int iSize = Int( m_cListPic.size() );
207 
208  for (Int i = 0; i < iSize; i++ )
209  {
210    TComPic* pcPic = *(iterPic++);
211#if SVC_EXTENSION
212    if( pcPic )
213    {
214      pcPic->destroy();
215
216      delete pcPic;
217      pcPic = NULL;
218    }
219#else
220    pcPic->destroy();
221   
222    delete pcPic;
223    pcPic = NULL;
224#endif
225  }
226 
227  m_cSAO.destroy();
228 
229  m_cLoopFilter.        destroy();
230 
231#if !SVC_EXTENSION
232  // destroy ROM
233  destroyROM();
234#endif
235}
236
237Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
238{
239  Int  numReorderPics[MAX_TLAYER];
240  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
241  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
242
243  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
244  {
245    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
246  }
247
248  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
249
250#if SVC_EXTENSION
251  m_iMaxRefPicNum += 1; // it should be updated if more than 1 resampling picture is used
252#endif
253
254  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
255  {
256    rpcPic = new TComPic();
257
258#if SVC_EXTENSION //Temporal solution, should be modified
259    if(m_layerId > 0)
260    {
261      for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
262      {
263        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(i);
264        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
265
266#if VPS_EXTN_DIRECT_REF_LAYERS
267        TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i );
268#else
269        TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
270#endif
271        //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin());
272        TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
273        if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() || !zeroOffsets )
274        {
275          rpcPic->setSpatialEnhLayerFlag( i, true );
276
277          //only for scalable extension
278          assert( pcSlice->getVPS()->getScalabilityMask(1) == true );
279        }
280#if MAX_ONE_RESAMPLING_DIRECT_LAYERS
281        if(pcSlice->getVPS()->getScalabilityMask(1))
282        {
283          pcSlice->setPic(rpcPic);
284        }
285#endif
286      }
287    }
288#endif
289   
290#if SVC_UPSAMPLING
291    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
292                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
293#else
294    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
295                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
296#endif
297    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
298    m_cListPic.pushBack( rpcPic );
299   
300    return;
301  }
302 
303  Bool bBufferIsAvailable = false;
304  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
305  while (iterPic != m_cListPic.end())
306  {
307    rpcPic = *(iterPic++);
308    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
309    {
310      rpcPic->setOutputMark(false);
311      bBufferIsAvailable = true;
312      break;
313    }
314
315    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
316    {
317#if !SVC_EXTENSION
318      rpcPic->setOutputMark(false);
319#endif
320      rpcPic->setReconMark( false );
321      rpcPic->getPicYuvRec()->setBorderExtension( false );
322      bBufferIsAvailable = true;
323      break;
324    }
325  }
326 
327  if ( !bBufferIsAvailable )
328  {
329    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
330    m_iMaxRefPicNum++;
331    rpcPic = new TComPic();
332    m_cListPic.pushBack( rpcPic );
333  }
334  rpcPic->destroy();
335
336#if SVC_UPSAMPLING
337  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
338                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
339
340#else
341  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
342                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
343#endif
344  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
345}
346
347Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
348{
349  if (!m_pcPic)
350  {
351    /* nothing to deblock */
352    return;
353  }
354 
355  TComPic*&   pcPic         = m_pcPic;
356
357  // Execute Deblock + Cleanup
358
359  m_cGopDecoder.filterPicture(pcPic);
360
361#if SYNTAX_OUTPUT
362  pcPic->wrireBLSyntax( getBLSyntaxFile(), SYNTAX_BYTES );
363#endif
364  TComSlice::sortPicList( m_cListPic ); // sorting for application output
365  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
366  rpcListPic          = &m_cListPic; 
367  m_cCuDecoder.destroy();       
368  m_bFirstSliceInPicture  = true;
369
370  return;
371}
372
373#if EARLY_REF_PIC_MARKING
374Void TDecTop::earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdSet)
375{
376  UInt currTid = m_pcPic->getTLayer();
377  UInt highestTid = (maxTemporalLayer >= 0) ? maxTemporalLayer : (m_pcPic->getSlice(0)->getSPS()->getMaxTLayers() - 1);
378  UInt latestDecLayerId = m_layerId;
379  UInt numTargetDecLayers = 0;
380  Int targetDecLayerIdList[MAX_LAYERS];
381  UInt latestDecIdx = 0;
382  TComSlice* pcSlice = m_pcPic->getSlice(0);
383
384  if ( currTid != highestTid )  // Marking  process is only applicaple for highest decoded TLayer
385  {
386    return;
387  }
388
389  // currPic must be marked as "used for reference" and must be a sub-layer non-reference picture
390  if ( !((pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N  ||
391          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N    ||
392          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N   ||
393          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N   ||
394          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N   ||
395          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N10     ||
396          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N12     ||
397          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N14) && pcSlice->isReferenced()))
398  {
399    return;
400  }
401
402  if ( targetDecLayerIdSet.size() == 0 ) // Cannot mark if we don't know the number of scalable layers
403  {
404    return;
405  }
406
407  for (std::vector<Int>::iterator it = targetDecLayerIdSet.begin(); it != targetDecLayerIdSet.end(); it++)
408  {
409    if ( latestDecLayerId == (*it) )
410    {
411      latestDecIdx = numTargetDecLayers;
412    }
413    targetDecLayerIdList[numTargetDecLayers++] = (*it);
414  }
415
416  Int remainingInterLayerReferencesFlag = 0;
417  if ( currTid <= pcSlice->getVPS()->getMaxSublayerForIlpPlus1(latestDecLayerId) - 1 )
418  {
419    for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
420    {
421      for ( Int k = 0; k < m_ppcTDecTop[targetDecLayerIdList[j]]->getNumDirectRefLayers(); k++ )
422      {
423        if ( latestDecIdx == m_ppcTDecTop[targetDecLayerIdList[j]]->getRefLayerId(k) )
424        {
425          remainingInterLayerReferencesFlag = 1;
426        }
427      }
428    }
429  }
430
431  if ( remainingInterLayerReferencesFlag == 0 )
432  {
433    pcSlice->setReferenced(false);
434  }
435}
436#endif
437
438Void TDecTop::xCreateLostPicture(Int iLostPoc) 
439{
440  printf("\ninserting lost poc : %d\n",iLostPoc);
441  TComSlice cFillSlice;
442#if SVC_EXTENSION
443  cFillSlice.setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() );
444  cFillSlice.setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() );
445  cFillSlice.setVPS( m_parameterSetManagerDecoder[m_layerId].getFirstVPS() );
446  cFillSlice.initSlice( m_layerId );
447#else
448  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
449  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
450  cFillSlice.initSlice();
451#endif
452  TComPic *cFillPic;
453  xGetNewPicBuffer(&cFillSlice,cFillPic);
454#if SVC_EXTENSION
455  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() );
456  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() );
457  cFillPic->getSlice(0)->setVPS( m_parameterSetManagerDecoder[m_layerId].getFirstVPS() );
458  cFillPic->getSlice(0)->initSlice( m_layerId );
459#else
460  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
461  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
462  cFillPic->getSlice(0)->initSlice();
463#endif
464 
465  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
466  Int closestPoc = 1000000;
467  while ( iterPic != m_cListPic.end())
468  {
469    TComPic * rpcPic = *(iterPic++);
470    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())
471    {
472      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
473    }
474  }
475  iterPic = m_cListPic.begin();
476  while ( iterPic != m_cListPic.end())
477  {
478    TComPic *rpcPic = *(iterPic++);
479    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
480    {
481      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
482      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
483      break;
484    }
485  }
486  cFillPic->setCurrSliceIdx(0);
487  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
488  {
489    cFillPic->getCU(i)->initCU(cFillPic,i);
490  }
491  cFillPic->getSlice(0)->setReferenced(true);
492  cFillPic->getSlice(0)->setPOC(iLostPoc);
493  cFillPic->setReconMark(true);
494  cFillPic->setOutputMark(true);
495  if(m_pocRandomAccess == MAX_INT)
496  {
497    m_pocRandomAccess = iLostPoc;
498  }
499}
500
501
502Void TDecTop::xActivateParameterSets()
503{
504#if SVC_EXTENSION
505  m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
506 
507  TComPPS *pps = m_parameterSetManagerDecoder[m_layerId].getPPS(m_apcSlicePilot->getPPSId());
508  assert (pps != 0);
509
510  TComSPS *sps = m_parameterSetManagerDecoder[m_layerId].getSPS(pps->getSPSId());
511  assert (sps != 0);
512
513  if( false == m_parameterSetManagerDecoder[m_layerId].activatePPS(m_apcSlicePilot->getPPSId(), m_apcSlicePilot->isIRAP()) )
514#else
515  m_parameterSetManagerDecoder.applyPrefetchedPS();
516 
517  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
518  assert (pps != 0);
519
520  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
521  assert (sps != 0);
522
523  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
524#endif
525  {
526    printf ("Parameter set activation failed!");
527    assert (0);
528  }
529
530  if( pps->getDependentSliceSegmentsEnabledFlag() )
531  {
532    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
533
534    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
535    {
536      m_cSliceDecoder.initCtxMem(NumCtx);
537      for ( UInt st = 0; st < NumCtx; st++ )
538      {
539        TDecSbac* ctx = NULL;
540        ctx = new TDecSbac;
541        ctx->init( &m_cBinCABAC );
542        m_cSliceDecoder.setCtxMem( ctx, st );
543      }
544    }
545  }
546
547  m_apcSlicePilot->setPPS(pps);
548  m_apcSlicePilot->setSPS(sps);
549  pps->setSPS(sps);
550  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
551  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
552
553  g_bitDepthY     = sps->getBitDepthY();
554  g_bitDepthC     = sps->getBitDepthC();
555  g_uiMaxCUWidth  = sps->getMaxCUWidth();
556  g_uiMaxCUHeight = sps->getMaxCUHeight();
557  g_uiMaxCUDepth  = sps->getMaxCUDepth();
558  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
559
560  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
561  {
562    sps->setAMPAcc( i, sps->getUseAMP() );
563  }
564
565  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
566  {
567    sps->setAMPAcc( i, 0 );
568  }
569
570  m_cSAO.destroy();
571  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
572  m_cLoopFilter.create( sps->getMaxCUDepth() );
573}
574
575#if SVC_EXTENSION
576Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
577#else
578Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
579#endif
580{
581  TComPic*&   pcPic         = m_pcPic;
582#if SVC_EXTENSION
583  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder[m_layerId].getPrefetchedVPS(0) );
584  m_apcSlicePilot->initSlice( nalu.m_layerId );
585#else
586  m_apcSlicePilot->initSlice();
587#endif
588
589  if (m_bFirstSliceInPicture)
590  {
591    m_uiSliceIdx     = 0;
592  }
593  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
594  if (!m_bFirstSliceInPicture)
595  {
596    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
597  }
598
599  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
600  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
601                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
602                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
603                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
604                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
605  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
606 
607  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
608  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
609
610#if SVC_EXTENSION
611#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
612  setRefLayerParams(m_apcSlicePilot->getVPS());
613#endif
614#if M0457_COL_PICTURE_SIGNALING
615  m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers);
616#endif
617#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
618  m_apcSlicePilot->setNumSamplePredRefLayers( getNumSamplePredRefLayers() );
619#endif
620  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder[m_layerId]);
621#else
622  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
623#endif
624
625#if HM12_RANDOM_ACCESS
626  // set POC for dependent slices in skipped pictures
627  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
628  {
629    m_apcSlicePilot->setPOC(m_skippedPOC);
630  }
631#endif
632
633  // Skip pictures due to random access
634  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
635  {
636#if HM12_RANDOM_ACCESS
637    m_prevSliceSkipped = true;
638    m_skippedPOC = m_apcSlicePilot->getPOC();
639#endif
640    return false;
641  }
642  // Skip TFD pictures associated with BLA/BLANT pictures
643  if (isSkipPictureForBLA(iPOCLastDisplay))
644  {
645#if HM12_RANDOM_ACCESS
646    m_prevSliceSkipped = true;
647    m_skippedPOC = m_apcSlicePilot->getPOC();
648#endif
649    return false;
650  }
651
652#if HM12_RANDOM_ACCESS
653  // clear previous slice skipped flag
654  m_prevSliceSkipped = false;
655#endif
656
657  // exit when a new picture is found
658#if SVC_EXTENSION
659  bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC);
660  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
661  {
662    m_prevPOC = m_apcSlicePilot->getPOC();
663    curLayerId = m_uiPrevLayerId; 
664    m_uiPrevLayerId = m_layerId;
665    return true;
666  }
667#else
668  //we should only get a different poc for a new picture (with CTU address==0)
669  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
670  {
671    printf ("Warning, the first slice of a picture might have been lost!\n");
672  }
673  // exit when a new picture is found
674  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
675  {
676    if (m_prevPOC >= m_pocRandomAccess)
677    {
678      m_prevPOC = m_apcSlicePilot->getPOC();
679      return true;
680    }
681    m_prevPOC = m_apcSlicePilot->getPOC();
682  }
683#endif
684  // actual decoding starts here
685  xActivateParameterSets();
686
687  if (m_apcSlicePilot->isNextSlice()) 
688  {
689    m_prevPOC = m_apcSlicePilot->getPOC();
690#if SVC_EXTENSION
691    curLayerId = m_layerId;
692    m_uiPrevLayerId = m_layerId;
693#endif
694  }
695  m_bFirstSliceInSequence = false;
696  //detect lost reference picture and insert copy of earlier frame.
697  Int lostPoc;
698  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
699  {
700    xCreateLostPicture(lostPoc-1);
701  }
702  if (m_bFirstSliceInPicture)
703  {
704#if AVC_BASE
705    if( m_layerId == 1 && m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
706    {
707      TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
708      fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
709      UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth();
710      UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight();
711
712      if( pFile->good() )
713      {
714        UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
715
716        pFile->seekg((UInt)uiPos, ios::beg );
717
718        Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
719        UInt uiStride = pBLPic->getPicYuvRec()->getStride();
720        for( Int i = 0; i < uiHeight; i++ )
721        {
722          for( Int j = 0; j < uiWidth; j++ )
723          {
724            pPel[j] = pFile->get();
725          }
726          pPel += uiStride;
727        }
728
729        pPel = pBLPic->getPicYuvRec()->getCbAddr();
730        uiStride = pBLPic->getPicYuvRec()->getCStride();
731        for( Int i = 0; i < uiHeight/2; i++ )
732        {
733          for( Int j = 0; j < uiWidth/2; j++ )
734          {
735            pPel[j] = pFile->get();
736          }
737          pPel += uiStride;
738        }
739
740        pPel = pBLPic->getPicYuvRec()->getCrAddr();
741        uiStride = pBLPic->getPicYuvRec()->getCStride();
742        for( Int i = 0; i < uiHeight/2; i++ )
743        {
744          for( Int j = 0; j < uiWidth/2; j++ )
745          {
746            pPel[j] = pFile->get();
747          }
748          pPel += uiStride;
749        }
750      }
751    }
752#endif
753
754    // Buffer initialize for prediction.
755    m_cPrediction.initTempBuff();
756    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
757    //  Get a new picture buffer
758    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
759
760    // transfer any SEI messages that have been received to the picture
761    pcPic->setSEIs(m_SEIs);
762    m_SEIs.clear();
763
764    // Recursive structure
765    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
766#if SVC_EXTENSION
767    m_cCuDecoder.init   ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId );
768#else
769    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
770#endif
771    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
772
773    m_cSliceDecoder.create();
774  }
775  else
776  {
777    // Check if any new SEI has arrived
778    if(!m_SEIs.empty())
779    {
780      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
781      SEIMessages &picSEI = pcPic->getSEIs();
782      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
783      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
784      deleteSEIs(m_SEIs);
785    }
786  }
787 
788  //  Set picture slice pointer
789  TComSlice*  pcSlice = m_apcSlicePilot;
790  Bool bNextSlice     = pcSlice->isNextSlice();
791
792  UInt uiCummulativeTileWidth;
793  UInt uiCummulativeTileHeight;
794  UInt i, j, p;
795
796  //set NumColumnsMins1 and NumRowsMinus1
797  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
798  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
799
800  //create the TComTileArray
801  pcPic->getPicSym()->xCreateTComTileArray();
802
803  if( pcSlice->getPPS()->getUniformSpacingFlag() )
804  {
805    //set the width for each tile
806    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
807    {
808      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
809      {
810        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
811          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
812          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
813      }
814    }
815
816    //set the height for each tile
817    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
818    {
819      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
820      {
821        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
822          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
823          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
824      }
825    }
826  }
827  else
828  {
829    //set the width for each tile
830    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
831    {
832      uiCummulativeTileWidth = 0;
833      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
834      {
835        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
836        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
837      }
838      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
839    }
840
841    //set the height for each tile
842    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
843    {
844      uiCummulativeTileHeight = 0;
845      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
846      { 
847        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
848        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
849      }
850      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
851    }
852  }
853
854  pcPic->getPicSym()->xInitTiles();
855
856  //generate the Coding Order Map and Inverse Coding Order Map
857  UInt uiEncCUAddr;
858  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
859  {
860    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
861    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
862  }
863  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
864  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
865
866  //convert the start and end CU addresses of the slice and dependent slice into encoding order
867  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
868  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
869  if(pcSlice->isNextSlice())
870  {
871    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
872    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
873  }
874
875  if (m_bFirstSliceInPicture) 
876  {
877    if(pcPic->getNumAllocatedSlice() != 1)
878    {
879      pcPic->clearSliceBuffer();
880    }
881  }
882  else
883  {
884    pcPic->allocateNewSlice();
885  }
886  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
887  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
888  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
889
890  pcPic->setTLayer(nalu.m_temporalId);
891
892#if SVC_EXTENSION
893  pcPic->setLayerId(nalu.m_layerId);
894  pcSlice->setLayerId(nalu.m_layerId);
895#endif
896
897  if (bNextSlice)
898  {
899    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
900    // Set reference list
901#if SVC_EXTENSION
902    if (m_layerId == 0)
903#endif
904#if FIX1071
905    pcSlice->setRefPicList( m_cListPic, true );
906#else
907    pcSlice->setRefPicList( m_cListPic );
908#endif
909
910#if SVC_EXTENSION   
911    if(m_layerId > 0)
912    {
913      for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
914      {
915        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
916#if AVC_BASE
917        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder[0].getActiveVPS()->getAvcBaseLayerFlag() )
918        {
919          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
920#if AVC_SYNTAX
921          TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
922          if( pcSlice->getPOC() == 0 )
923          {
924            // initialize partition order.
925            UInt* piTmp = &g_auiZscanToRaster[0];
926            initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
927            initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
928          }     
929          pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
930          pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
931#endif
932        }
933        else
934        {
935#if VPS_EXTN_DIRECT_REF_LAYERS
936          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
937#else
938          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
939#endif
940          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
941          pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
942        }
943#else
944#if VPS_EXTN_DIRECT_REF_LAYERS
945        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
946#else
947        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
948#endif
949        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
950        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
951#endif
952
953#if SCALED_REF_LAYER_OFFSETS
954        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
955
956        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
957        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
958
959        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
960        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
961#else
962        const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
963        const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
964
965        Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
966        Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
967
968        Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
969        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
970#endif
971        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
972        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
973
974        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
975        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
976
977#if SVC_UPSAMPLING
978        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
979        {   
980#if SCALED_REF_LAYER_OFFSETS
981          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
982#else
983          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec() );
984#endif
985        }
986        else
987        {
988          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
989        }
990        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
991#endif
992      }
993    }
994
995    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
996    {
997      setILRPic(pcPic);
998#if REF_IDX_MFM
999#if M0457_COL_PICTURE_SIGNALING
1000      if( pcSlice->getMFMEnabledFlag() )
1001#else
1002      if( pcSlice->getSPS()->getMFMEnabledFlag() )
1003#endif
1004      {
1005        pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
1006#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
1007        pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice));
1008#endif
1009      }
1010      pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
1011    }
1012#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1013    else if ( m_layerId > 0 )
1014    {
1015      pcSlice->setRefPicList( m_cListPic, false, NULL);
1016    }
1017#endif
1018#endif
1019
1020#endif //SVC_EXTENSION
1021
1022    // For generalized B
1023    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1024    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1025    {
1026      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1027      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1028
1029      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1030      {
1031        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1032      }
1033    }
1034    if (!pcSlice->isIntra())
1035    {
1036      Bool bLowDelay = true;
1037      Int  iCurrPOC  = pcSlice->getPOC();
1038      Int iRefIdx = 0;
1039
1040      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1041      {
1042        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1043        {
1044          bLowDelay = false;
1045        }
1046      }
1047      if (pcSlice->isInterB())
1048      {
1049        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1050        {
1051          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1052          {
1053            bLowDelay = false;
1054          }
1055        }       
1056      }
1057
1058      pcSlice->setCheckLDC(bLowDelay);           
1059    }
1060
1061    //---------------
1062    pcSlice->setRefPOCList();
1063  }
1064
1065  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1066  if(pcSlice->getSPS()->getScalingListFlag())
1067  {
1068    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
1069    if(pcSlice->getPPS()->getScalingListPresentFlag())
1070    {
1071      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
1072    }
1073    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
1074    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1075    {
1076      pcSlice->setDefaultScalingList();
1077    }
1078    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1079    m_cTrQuant.setUseScalingList(true);
1080  }
1081  else
1082  {
1083    m_cTrQuant.setFlatScalingList();
1084    m_cTrQuant.setUseScalingList(false);
1085  }
1086
1087  //  Decode a picture
1088  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1089
1090  m_bFirstSliceInPicture = false;
1091  m_uiSliceIdx++;
1092
1093  return false;
1094}
1095
1096Void TDecTop::xDecodeVPS()
1097{
1098  TComVPS* vps = new TComVPS();
1099 
1100  m_cEntropyDecoder.decodeVPS( vps );
1101#if SVC_EXTENSION
1102  m_parameterSetManagerDecoder[0].storePrefetchedVPS(vps);
1103#else
1104  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1105#endif
1106}
1107
1108Void TDecTop::xDecodeSPS()
1109{
1110  TComSPS* sps = new TComSPS();
1111#if SVC_EXTENSION
1112  sps->setLayerId(m_layerId);
1113#endif
1114#if SPS_SUB_LAYER_INFO
1115  m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder[0] );
1116#else
1117  m_cEntropyDecoder.decodeSPS( sps );
1118#endif
1119#if SVC_EXTENSION
1120  m_parameterSetManagerDecoder[m_layerId].storePrefetchedSPS(sps);
1121#else
1122  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1123#endif
1124#if SVC_EXTENSION
1125  if(m_numLayer>0)
1126  {
1127    xInitILRP(sps);
1128  }
1129#endif
1130}
1131
1132Void TDecTop::xDecodePPS()
1133{
1134  TComPPS* pps = new TComPPS();
1135  m_cEntropyDecoder.decodePPS( pps );
1136#if SVC_EXTENSION
1137  m_parameterSetManagerDecoder[m_layerId].storePrefetchedPPS( pps );
1138#else
1139  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1140#endif
1141
1142  if( pps->getDependentSliceSegmentsEnabledFlag() )
1143  {
1144    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
1145    m_cSliceDecoder.initCtxMem(NumCtx);
1146    for ( UInt st = 0; st < NumCtx; st++ )
1147    {
1148      TDecSbac* ctx = NULL;
1149      ctx = new TDecSbac;
1150      ctx->init( &m_cBinCABAC );
1151      m_cSliceDecoder.setCtxMem( ctx, st );
1152    }
1153  }
1154}
1155
1156Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1157{
1158#if SVC_EXTENSION
1159  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1160  {
1161#if RANDOM_ACCESS_SEI_FIX
1162    if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
1163    {
1164      return;
1165    }
1166#endif
1167#if M0043_LAYERS_PRESENT_SEI
1168    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveVPS(), m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1169#else
1170    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1171#endif
1172  }
1173  else
1174  {
1175#if M0043_LAYERS_PRESENT_SEI
1176    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveVPS(), m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1177#else
1178    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1179#endif
1180    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1181    if (activeParamSets.size()>0)
1182    {
1183      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1184      m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
1185      assert(seiAps->activeSeqParamSetId.size()>0);
1186      if (! m_parameterSetManagerDecoder[m_layerId].activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1187      {
1188        printf ("Warning SPS activation with Active parameter set SEI failed");
1189      }
1190    }
1191  }
1192#else
1193  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1194  {
1195#if M0043_LAYERS_PRESENT_SEI
1196    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1197#else
1198    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1199#endif
1200  }
1201  else
1202  {
1203#if M0043_LAYERS_PRESENT_SEI
1204    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1205#else
1206    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1207#endif
1208    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1209    if (activeParamSets.size()>0)
1210    {
1211      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1212      m_parameterSetManagerDecoder.applyPrefetchedPS();
1213      assert(seiAps->activeSeqParamSetId.size()>0);
1214      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1215      {
1216        printf ("Warning SPS activation with Active parameter set SEI failed");
1217      }
1218    }
1219  }
1220#endif
1221}
1222
1223#if SVC_EXTENSION
1224Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
1225#else
1226Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1227#endif
1228{
1229  // Initialize entropy decoder
1230  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1231  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1232
1233  switch (nalu.m_nalUnitType)
1234  {
1235    case NAL_UNIT_VPS:
1236      xDecodeVPS();
1237#if AVC_BASE
1238      if( m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1239      {
1240        if( !m_ppcTDecTop[0]->getBLReconFile()->good() )
1241        {
1242          printf( "Base layer YUV input reading error\n" );
1243          exit(EXIT_FAILURE);
1244        }       
1245#if AVC_SYNTAX
1246        if( !m_ppcTDecTop[0]->getBLSyntaxFile()->good() )
1247        {
1248          printf( "Base layer syntax input reading error\n" );
1249          exit(EXIT_FAILURE);
1250        }
1251#endif
1252      }
1253      else
1254      {
1255        TComList<TComPic*> *cListPic = m_ppcTDecTop[0]->getListPic();
1256        cListPic->clear();
1257      }
1258#endif
1259      return false;
1260     
1261    case NAL_UNIT_SPS:
1262      xDecodeSPS();
1263#if AVC_BASE
1264      if( m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1265      {
1266        TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
1267        if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
1268        {
1269          // using EL SPS with spsId = 1
1270          TComSPS* sps = m_parameterSetManagerDecoder[nalu.m_layerId].getPrefetchedSPS(1);
1271          Int  numReorderPics[MAX_TLAYER];
1272          Window &conformanceWindow = sps->getConformanceWindow();
1273          Window defaultDisplayWindow = sps->getVuiParametersPresentFlag() ? sps->getVuiParameters()->getDefaultDisplayWindow() : Window();
1274#if SVC_UPSAMPLING
1275#if AVC_SYNTAX
1276
1277          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
1278#else
1279          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
1280#endif
1281#else
1282          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
1283#endif
1284        }
1285      }
1286#endif
1287      return false;
1288
1289    case NAL_UNIT_PPS:
1290      xDecodePPS();
1291      return false;
1292     
1293    case NAL_UNIT_PREFIX_SEI:
1294    case NAL_UNIT_SUFFIX_SEI:
1295      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1296      return false;
1297
1298    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1299    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1300    case NAL_UNIT_CODED_SLICE_TLA_R:
1301    case NAL_UNIT_CODED_SLICE_TSA_N:
1302    case NAL_UNIT_CODED_SLICE_STSA_R:
1303    case NAL_UNIT_CODED_SLICE_STSA_N:
1304    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1305    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1306    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1307    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1308    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1309    case NAL_UNIT_CODED_SLICE_CRA:
1310    case NAL_UNIT_CODED_SLICE_RADL_N:
1311    case NAL_UNIT_CODED_SLICE_RADL_R:
1312    case NAL_UNIT_CODED_SLICE_RASL_N:
1313    case NAL_UNIT_CODED_SLICE_RASL_R:
1314#if SVC_EXTENSION
1315      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
1316#else
1317      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1318#endif
1319      break;
1320    default:
1321      assert (1);
1322  }
1323
1324  return false;
1325}
1326
1327/** Function for checking if picture should be skipped because of association with a previous BLA picture
1328 * \param iPOCLastDisplay POC of last picture displayed
1329 * \returns true if the picture should be skipped
1330 * This function skips all TFD pictures that follow a BLA picture
1331 * in decoding order and precede it in output order.
1332 */
1333Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1334{
1335  if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1336  {
1337    iPOCLastDisplay++;
1338    return true;
1339  }
1340  return false;
1341}
1342
1343/** Function for checking if picture should be skipped because of random access
1344 * \param iSkipFrame skip frame counter
1345 * \param iPOCLastDisplay POC of last picture displayed
1346 * \returns true if the picture shold be skipped in the random access.
1347 * This function checks the skipping of pictures in the case of -s option random access.
1348 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1349 * It also checks the type of Nal unit type at the random access point.
1350 * 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.
1351 * If the random access point is IDR all pictures after the random access point are decoded.
1352 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1353 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1354 * access point there is no guarantee that the decoder will not crash.
1355 */
1356Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1357{
1358  if (iSkipFrame) 
1359  {
1360    iSkipFrame--;   // decrement the counter
1361    return true;
1362  }
1363  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1364  {
1365    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1366        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1367        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1368        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1369    {
1370      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1371      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1372    }
1373    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1374    {
1375      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1376    }
1377    else 
1378    {
1379      static Bool warningMessage = false;
1380      if(!warningMessage)
1381      {
1382        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1383        warningMessage = true;
1384      }
1385      return true;
1386    }
1387  }
1388  // skip the reordered pictures, if necessary
1389  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))
1390  {
1391    iPOCLastDisplay++;
1392    return true;
1393  }
1394  // if we reach here, then the picture is not skipped.
1395  return false; 
1396}
1397
1398#if VPS_EXTN_DIRECT_REF_LAYERS
1399TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc )
1400{
1401  TComVPS* vps = m_parameterSetManagerDecoder[0].getActiveVPS();
1402  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
1403  {
1404    return (TDecTop *)getLayerDec( 0 );
1405  }
1406 
1407  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdc ) );
1408}
1409#endif
1410
1411#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
1412
1413Void TDecTop::setRefLayerParams( TComVPS* vps )
1414{
1415  for(UInt layer = 0; layer < m_numLayer; layer++)
1416  {
1417    TDecTop *decTop = (TDecTop *)getLayerDec(layer);
1418    decTop->setNumSamplePredRefLayers(0);
1419    decTop->setNumMotionPredRefLayers(0);
1420    decTop->setNumDirectRefLayers(0);
1421    for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++)
1422    {
1423      decTop->setSamplePredEnabledFlag(i, false);
1424      decTop->setMotionPredEnabledFlag(i, false);
1425      decTop->setSamplePredRefLayerId(i, 0);
1426      decTop->setMotionPredRefLayerId(i, 0);
1427    }
1428    for(Int j = 0; j < layer; j++)
1429    {
1430      if (vps->getDirectDependencyFlag(layer, j))
1431      {
1432        decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layer));
1433        decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1);
1434
1435        Int samplePredEnabledFlag = (vps->getDirectDependencyType(layer, j) + 1) & 1;
1436        decTop->setSamplePredEnabledFlag(j, samplePredEnabledFlag == 1 ? true : false);
1437        decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag);
1438
1439        Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layer, j) + 1) & 2) >> 1;
1440        decTop->setMotionPredEnabledFlag(j, motionPredEnabledFlag == 1 ? true : false);
1441        decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag);
1442      }
1443    }
1444  }
1445  for ( Int i = 1, mIdx = 0, sIdx = 0; i < m_numLayer; i++ )
1446  {
1447    Int iNuhLId = vps->getLayerIdInNuh(i);
1448    TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId);
1449    for ( Int j = 0; j < i; j++ )
1450    {
1451      if (decTop->getMotionPredEnabledFlag(j))
1452      {
1453        decTop->setMotionPredRefLayerId(mIdx++, vps->getLayerIdInNuh(j));
1454      }
1455      if (decTop->getSamplePredEnabledFlag(j))
1456      {
1457        decTop->setSamplePredRefLayerId(sIdx++, vps->getLayerIdInNuh(j));
1458      }
1459    }
1460  }
1461}
1462
1463#endif
1464
1465#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
1466TComPic* TDecTop::getMotionPredIlp(TComSlice* pcSlice)
1467{
1468  TComPic* ilpPic = NULL;
1469  Int activeMotionPredReflayerIdx = 0;
1470
1471  for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
1472  {
1473    UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
1474    if( getMotionPredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) ) )
1475    {
1476      if (activeMotionPredReflayerIdx == pcSlice->getColRefLayerIdx())
1477      {
1478        ilpPic = m_cIlpPic[refLayerIdc];
1479        break;
1480      }
1481      else
1482      {
1483        activeMotionPredReflayerIdx++;
1484      }
1485    }
1486  }
1487
1488  assert(ilpPic != NULL);
1489
1490  return ilpPic;
1491}
1492#endif
1493
1494//! \}
Note: See TracBrowser for help on using the repository browser.