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

Last change on this file since 423 was 422, checked in by qualcomm, 12 years ago

Fix for N0147.

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