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

Last change on this file since 429 was 424, checked in by qualcomm, 12 years ago

Integrate POC_reset_flag restriction 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_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  if( m_apcSlicePilot->getVPS()->getCrossLayerIrapAlignFlag() )
771  {
772    assert( m_apcSlicePilot->getPocResetFlag() == 0);
773  }
774#endif
775
776#if REPN_FORMAT_IN_VPS
777  // Initialize ILRP if needed, only for the current layer 
778  // ILRP intialization should go along with activation of parameters sets,
779  // although activation of parameter sets itself need not be done for each and every slice!!!
780  xInitILRP(m_apcSlicePilot);
781#endif
782  if (m_apcSlicePilot->isNextSlice()) 
783  {
784    m_prevPOC = m_apcSlicePilot->getPOC();
785#if SVC_EXTENSION
786    curLayerId = m_layerId;
787    m_uiPrevLayerId = m_layerId;
788#endif
789  }
790  m_bFirstSliceInSequence = false;
791#if POC_RESET_FLAG
792  // This operation would do the following:
793  // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
794  // 2. Update the value of m_pocCRA.
795  // 3. Reset the POC values at the decoder for the current picture to be zero.
796  // 4. update value of POCLastDisplay
797  if( m_apcSlicePilot->getPocResetFlag() )
798  {
799    if( m_apcSlicePilot->getSliceIdx() == 0 )
800    {
801      Int pocAdjustValue = m_apcSlicePilot->getPOC();
802
803      // If poc reset flag is set to 1, reset all POC for DPB -> basically do it for each slice in the picutre
804      TComList<TComPic*>::iterator  iterPic = m_cListPic.begin(); 
805
806      // Iterate through all picture in DPB
807      while( iterPic != m_cListPic.end() )
808      {
809        TComPic *dpbPic = *iterPic;
810        // Check if the picture pointed to by iterPic is either used for reference or
811        // needed for output, are in the same layer, and not the current picture.
812        if( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
813            &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
814              && ( dpbPic->getReconMark() ) 
815          )
816        {
817          for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
818          {
819
820            TComSlice *slice = dpbPic->getSlice(i);
821            TComReferencePictureSet *rps = slice->getRPS();
822            slice->setPOC( slice->getPOC() - pocAdjustValue );
823
824            // Also adjust the POC value stored in the RPS of each such slice
825            for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
826            {
827              rps->setPOC( j, rps->getPOC(j) - pocAdjustValue );
828            }
829            // Also adjust the value of refPOC
830            for(Int k = 0; k < 2; k++)  // For List 0 and List 1
831            {
832              RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
833              for(Int j = 0; j < slice->getNumRefIdx(list); j++)
834              {
835                slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j);
836              }
837            }
838          }
839        }
840        iterPic++;
841      }
842      // Update the value of pocCRA
843      m_pocCRA -= pocAdjustValue;
844      // Update value of POCLastDisplay
845      iPOCLastDisplay -= pocAdjustValue;
846    }
847    // Reset current poc for current slice and RPS
848    m_apcSlicePilot->setPOC( 0 );
849  }
850#endif
851  //detect lost reference picture and insert copy of earlier frame.
852  Int lostPoc;
853  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
854  {
855    xCreateLostPicture(lostPoc-1);
856  }
857  if (m_bFirstSliceInPicture)
858  {
859#if AVC_BASE
860    if( m_layerId == 1 && m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
861    {
862      TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
863      fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
864      UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth();
865      UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight();
866
867      if( pFile->good() )
868      {
869        UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
870
871        pFile->seekg((UInt)uiPos, ios::beg );
872
873        Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
874        UInt uiStride = pBLPic->getPicYuvRec()->getStride();
875        for( Int i = 0; i < uiHeight; i++ )
876        {
877          for( Int j = 0; j < uiWidth; j++ )
878          {
879            pPel[j] = pFile->get();
880          }
881          pPel += uiStride;
882        }
883
884        pPel = pBLPic->getPicYuvRec()->getCbAddr();
885        uiStride = pBLPic->getPicYuvRec()->getCStride();
886        for( Int i = 0; i < uiHeight/2; i++ )
887        {
888          for( Int j = 0; j < uiWidth/2; j++ )
889          {
890            pPel[j] = pFile->get();
891          }
892          pPel += uiStride;
893        }
894
895        pPel = pBLPic->getPicYuvRec()->getCrAddr();
896        uiStride = pBLPic->getPicYuvRec()->getCStride();
897        for( Int i = 0; i < uiHeight/2; i++ )
898        {
899          for( Int j = 0; j < uiWidth/2; j++ )
900          {
901            pPel[j] = pFile->get();
902          }
903          pPel += uiStride;
904        }
905      }
906    }
907#endif
908
909    // Buffer initialize for prediction.
910    m_cPrediction.initTempBuff();
911    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
912    //  Get a new picture buffer
913    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
914
915    // transfer any SEI messages that have been received to the picture
916    pcPic->setSEIs(m_SEIs);
917    m_SEIs.clear();
918
919    // Recursive structure
920    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
921#if SVC_EXTENSION
922    m_cCuDecoder.init   ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId );
923#else
924    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
925#endif
926    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
927
928    m_cSliceDecoder.create();
929  }
930  else
931  {
932    // Check if any new SEI has arrived
933    if(!m_SEIs.empty())
934    {
935      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
936      SEIMessages &picSEI = pcPic->getSEIs();
937      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
938      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
939      deleteSEIs(m_SEIs);
940    }
941  }
942 
943  //  Set picture slice pointer
944  TComSlice*  pcSlice = m_apcSlicePilot;
945  Bool bNextSlice     = pcSlice->isNextSlice();
946
947  UInt uiCummulativeTileWidth;
948  UInt uiCummulativeTileHeight;
949  UInt i, j, p;
950
951  //set NumColumnsMins1 and NumRowsMinus1
952  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
953  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
954
955  //create the TComTileArray
956  pcPic->getPicSym()->xCreateTComTileArray();
957
958  if( pcSlice->getPPS()->getUniformSpacingFlag() )
959  {
960    //set the width for each tile
961    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
962    {
963      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
964      {
965        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
966          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
967          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
968      }
969    }
970
971    //set the height for each tile
972    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
973    {
974      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
975      {
976        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
977          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
978          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
979      }
980    }
981  }
982  else
983  {
984    //set the width for each tile
985    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
986    {
987      uiCummulativeTileWidth = 0;
988      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
989      {
990        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
991        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
992      }
993      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
994    }
995
996    //set the height for each tile
997    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
998    {
999      uiCummulativeTileHeight = 0;
1000      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
1001      { 
1002        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
1003        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
1004      }
1005      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
1006    }
1007  }
1008
1009  pcPic->getPicSym()->xInitTiles();
1010
1011  //generate the Coding Order Map and Inverse Coding Order Map
1012  UInt uiEncCUAddr;
1013  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
1014  {
1015    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
1016    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
1017  }
1018  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1019  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1020
1021  //convert the start and end CU addresses of the slice and dependent slice into encoding order
1022  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
1023  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
1024  if(pcSlice->isNextSlice())
1025  {
1026    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
1027    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
1028  }
1029
1030  if (m_bFirstSliceInPicture) 
1031  {
1032    if(pcPic->getNumAllocatedSlice() != 1)
1033    {
1034      pcPic->clearSliceBuffer();
1035    }
1036  }
1037  else
1038  {
1039    pcPic->allocateNewSlice();
1040  }
1041  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
1042  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
1043  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
1044
1045  pcPic->setTLayer(nalu.m_temporalId);
1046
1047#if SVC_EXTENSION
1048  pcPic->setLayerId(nalu.m_layerId);
1049  pcSlice->setLayerId(nalu.m_layerId);
1050#endif
1051
1052  if (bNextSlice)
1053  {
1054    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
1055    // Set reference list
1056#if SVC_EXTENSION
1057    if (m_layerId == 0)
1058#endif
1059#if FIX1071
1060    pcSlice->setRefPicList( m_cListPic, true );
1061#else
1062    pcSlice->setRefPicList( m_cListPic );
1063#endif
1064
1065#if SVC_EXTENSION   
1066    if(m_layerId > 0)
1067    {
1068      for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
1069      {
1070        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
1071#if AVC_BASE
1072        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder[0].getActiveVPS()->getAvcBaseLayerFlag() )
1073        {
1074          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
1075#if AVC_SYNTAX
1076          TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
1077          if( pcSlice->getPOC() == 0 )
1078          {
1079            // initialize partition order.
1080            UInt* piTmp = &g_auiZscanToRaster[0];
1081            initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
1082            initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
1083          }     
1084          pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
1085          pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
1086#endif
1087        }
1088        else
1089        {
1090#if VPS_EXTN_DIRECT_REF_LAYERS
1091          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1092#else
1093          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1094#endif
1095          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1096          pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1097        }
1098#else
1099#if VPS_EXTN_DIRECT_REF_LAYERS
1100        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1101#else
1102        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1103#endif
1104        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1105        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1106#endif
1107
1108#if SCALED_REF_LAYER_OFFSETS
1109        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
1110
1111
1112        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
1113        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
1114
1115        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
1116        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
1117#else
1118        const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
1119        const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
1120
1121        Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
1122        Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
1123
1124        Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
1125        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
1126#endif
1127        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
1128        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
1129
1130        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
1131        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
1132
1133#if SVC_UPSAMPLING
1134        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
1135        {   
1136#if SCALED_REF_LAYER_OFFSETS
1137          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
1138#else
1139          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec() );
1140#endif
1141        }
1142        else
1143        {
1144          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
1145        }
1146        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
1147#endif
1148      }
1149    }
1150
1151    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
1152    {
1153      setILRPic(pcPic);
1154#if REF_IDX_MFM
1155#if M0457_COL_PICTURE_SIGNALING
1156      if( pcSlice->getMFMEnabledFlag() )
1157#else
1158      if( pcSlice->getSPS()->getMFMEnabledFlag() )
1159#endif
1160      {
1161        pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
1162#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
1163        pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice));
1164#endif
1165      }
1166      pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
1167    }
1168#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1169    else if ( m_layerId > 0 )
1170    {
1171      pcSlice->setRefPicList( m_cListPic, false, NULL);
1172    }
1173#endif
1174#endif
1175
1176#endif //SVC_EXTENSION
1177
1178#if N0147_IRAP_ALIGN_FLAG
1179    if(  m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag())
1180    {
1181      for(Int dependentLayerIdx = 0; dependentLayerIdx < pcSlice->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1182      {
1183        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1184        TComPic* refpicLayer = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
1185        if(refpicLayer && pcSlice->isIRAP())
1186        {                 
1187          assert(pcSlice->getNalUnitType() == refpicLayer->getSlice(0)->getNalUnitType());
1188        }
1189      }
1190    }
1191#endif
1192   
1193    // For generalized B
1194    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1195    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1196    {
1197      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1198      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1199
1200      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1201      {
1202        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1203      }
1204    }
1205    if (!pcSlice->isIntra())
1206    {
1207      Bool bLowDelay = true;
1208      Int  iCurrPOC  = pcSlice->getPOC();
1209      Int iRefIdx = 0;
1210
1211      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1212      {
1213        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1214        {
1215          bLowDelay = false;
1216        }
1217      }
1218      if (pcSlice->isInterB())
1219      {
1220        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1221        {
1222          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1223          {
1224            bLowDelay = false;
1225          }
1226        }       
1227      }
1228
1229      pcSlice->setCheckLDC(bLowDelay);           
1230    }
1231
1232    //---------------
1233    pcSlice->setRefPOCList();
1234  }
1235
1236  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1237  if(pcSlice->getSPS()->getScalingListFlag())
1238  {
1239#if IL_SL_SIGNALLING_N0371
1240    pcSlice->getSPS()->getScalingList()->setLayerId( m_layerId );
1241#endif
1242
1243    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
1244
1245    if(pcSlice->getPPS()->getScalingListPresentFlag())
1246    {
1247#if IL_SL_SIGNALLING_N0371
1248      pcSlice->getPPS()->getScalingList()->setLayerId( m_layerId );
1249#endif
1250
1251      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
1252    }
1253    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
1254    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1255    {
1256#if IL_SL_SIGNALLING_N0371
1257      pcSlice->setDefaultScalingList( m_layerId );
1258#else
1259      pcSlice->setDefaultScalingList();
1260#endif
1261    }
1262    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1263    m_cTrQuant.setUseScalingList(true);
1264  }
1265  else
1266  {
1267#if IL_SL_SIGNALLING_N0371
1268    m_cTrQuant.setFlatScalingList( m_layerId );
1269#else
1270    m_cTrQuant.setFlatScalingList();
1271#endif
1272    m_cTrQuant.setUseScalingList(false);
1273  }
1274
1275  //  Decode a picture
1276  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1277
1278  m_bFirstSliceInPicture = false;
1279  m_uiSliceIdx++;
1280
1281  return false;
1282}
1283
1284Void TDecTop::xDecodeVPS()
1285{
1286  TComVPS* vps = new TComVPS();
1287 
1288  m_cEntropyDecoder.decodeVPS( vps );
1289#if SVC_EXTENSION
1290  m_parameterSetManagerDecoder[0].storePrefetchedVPS(vps);
1291#else
1292  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1293#endif
1294}
1295
1296Void TDecTop::xDecodeSPS()
1297{
1298  TComSPS* sps = new TComSPS();
1299#if SVC_EXTENSION
1300  sps->setLayerId(m_layerId);
1301#endif
1302
1303#if SPS_SUB_LAYER_INFO
1304  m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder[0] );
1305#else
1306  m_cEntropyDecoder.decodeSPS( sps );
1307#endif
1308#if SVC_EXTENSION
1309  m_parameterSetManagerDecoder[m_layerId].storePrefetchedSPS(sps);
1310#else
1311  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1312#endif
1313#if SVC_EXTENSION
1314#if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation 
1315  if(m_numLayer>0)
1316  {
1317    xInitILRP(sps);
1318  }
1319#endif
1320#endif
1321}
1322
1323Void TDecTop::xDecodePPS()
1324{
1325  TComPPS* pps = new TComPPS();
1326
1327#if IL_SL_SIGNALLING_N0371
1328  pps->setLayerId(m_layerId);
1329#endif
1330
1331  m_cEntropyDecoder.decodePPS( pps );
1332#if SVC_EXTENSION
1333  m_parameterSetManagerDecoder[m_layerId].storePrefetchedPPS( pps );
1334#else
1335  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1336#endif
1337
1338  if( pps->getDependentSliceSegmentsEnabledFlag() )
1339  {
1340    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
1341    m_cSliceDecoder.initCtxMem(NumCtx);
1342    for ( UInt st = 0; st < NumCtx; st++ )
1343    {
1344      TDecSbac* ctx = NULL;
1345      ctx = new TDecSbac;
1346      ctx->init( &m_cBinCABAC );
1347      m_cSliceDecoder.setCtxMem( ctx, st );
1348    }
1349  }
1350}
1351
1352Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1353{
1354#if SVC_EXTENSION
1355  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1356  {
1357#if RANDOM_ACCESS_SEI_FIX
1358    if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
1359    {
1360      return;
1361    }
1362#endif
1363#if M0043_LAYERS_PRESENT_SEI
1364    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveVPS(), m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1365#else
1366    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1367#endif
1368  }
1369  else
1370  {
1371#if M0043_LAYERS_PRESENT_SEI
1372    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveVPS(), m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1373#else
1374    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1375#endif
1376    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1377    if (activeParamSets.size()>0)
1378    {
1379      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1380      m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
1381      assert(seiAps->activeSeqParamSetId.size()>0);
1382      if (! m_parameterSetManagerDecoder[m_layerId].activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1383      {
1384        printf ("Warning SPS activation with Active parameter set SEI failed");
1385      }
1386    }
1387  }
1388#else
1389  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1390  {
1391#if M0043_LAYERS_PRESENT_SEI
1392    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1393#else
1394    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1395#endif
1396  }
1397  else
1398  {
1399#if M0043_LAYERS_PRESENT_SEI
1400    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1401#else
1402    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1403#endif
1404    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1405    if (activeParamSets.size()>0)
1406    {
1407      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1408      m_parameterSetManagerDecoder.applyPrefetchedPS();
1409      assert(seiAps->activeSeqParamSetId.size()>0);
1410      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1411      {
1412        printf ("Warning SPS activation with Active parameter set SEI failed");
1413      }
1414    }
1415  }
1416#endif
1417}
1418
1419#if SVC_EXTENSION
1420Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
1421#else
1422Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1423#endif
1424{
1425  // Initialize entropy decoder
1426  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1427  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1428
1429  switch (nalu.m_nalUnitType)
1430  {
1431    case NAL_UNIT_VPS:
1432#if VPS_NUH_LAYER_ID
1433      assert( nalu.m_layerId == 0 ); // Non-conforming bitstream. The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
1434#endif
1435      xDecodeVPS();
1436#if AVC_BASE
1437      if( m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1438      {
1439        if( !m_ppcTDecTop[0]->getBLReconFile()->good() )
1440        {
1441          printf( "Base layer YUV input reading error\n" );
1442          exit(EXIT_FAILURE);
1443        }       
1444#if AVC_SYNTAX
1445        if( !m_ppcTDecTop[0]->getBLSyntaxFile()->good() )
1446        {
1447          printf( "Base layer syntax input reading error\n" );
1448          exit(EXIT_FAILURE);
1449        }
1450#endif
1451      }
1452      else
1453      {
1454        TComList<TComPic*> *cListPic = m_ppcTDecTop[0]->getListPic();
1455        cListPic->clear();
1456      }
1457#endif
1458      return false;
1459     
1460    case NAL_UNIT_SPS:
1461      xDecodeSPS();
1462#if AVC_BASE
1463      if( m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1464      {
1465        TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
1466        if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
1467        {
1468          // using EL SPS with spsId = 1
1469          TComSPS* sps = m_parameterSetManagerDecoder[nalu.m_layerId].getPrefetchedSPS(1);
1470          Int  numReorderPics[MAX_TLAYER];
1471          Window &conformanceWindow = sps->getConformanceWindow();
1472          Window defaultDisplayWindow = sps->getVuiParametersPresentFlag() ? sps->getVuiParameters()->getDefaultDisplayWindow() : Window();
1473#if SVC_UPSAMPLING
1474#if AVC_SYNTAX
1475
1476          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
1477#else
1478          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
1479#endif
1480#else
1481          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
1482#endif
1483        }
1484      }
1485#endif
1486      return false;
1487
1488    case NAL_UNIT_PPS:
1489      xDecodePPS();
1490      return false;
1491     
1492    case NAL_UNIT_PREFIX_SEI:
1493    case NAL_UNIT_SUFFIX_SEI:
1494      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1495      return false;
1496
1497    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1498    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1499    case NAL_UNIT_CODED_SLICE_TSA_R:
1500    case NAL_UNIT_CODED_SLICE_TSA_N:
1501    case NAL_UNIT_CODED_SLICE_STSA_R:
1502    case NAL_UNIT_CODED_SLICE_STSA_N:
1503    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1504    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1505    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1506    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1507    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1508    case NAL_UNIT_CODED_SLICE_CRA:
1509    case NAL_UNIT_CODED_SLICE_RADL_N:
1510    case NAL_UNIT_CODED_SLICE_RADL_R:
1511    case NAL_UNIT_CODED_SLICE_RASL_N:
1512    case NAL_UNIT_CODED_SLICE_RASL_R:
1513#if SVC_EXTENSION
1514      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
1515#else
1516      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1517#endif
1518      break;
1519    default:
1520      assert (1);
1521  }
1522
1523  return false;
1524}
1525
1526/** Function for checking if picture should be skipped because of association with a previous BLA picture
1527 * \param iPOCLastDisplay POC of last picture displayed
1528 * \returns true if the picture should be skipped
1529 * This function skips all TFD pictures that follow a BLA picture
1530 * in decoding order and precede it in output order.
1531 */
1532Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1533{
1534  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))
1535  {
1536    iPOCLastDisplay++;
1537    return true;
1538  }
1539  return false;
1540}
1541
1542/** Function for checking if picture should be skipped because of random access
1543 * \param iSkipFrame skip frame counter
1544 * \param iPOCLastDisplay POC of last picture displayed
1545 * \returns true if the picture shold be skipped in the random access.
1546 * This function checks the skipping of pictures in the case of -s option random access.
1547 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1548 * It also checks the type of Nal unit type at the random access point.
1549 * 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.
1550 * If the random access point is IDR all pictures after the random access point are decoded.
1551 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1552 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1553 * access point there is no guarantee that the decoder will not crash.
1554 */
1555Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1556{
1557  if (iSkipFrame) 
1558  {
1559    iSkipFrame--;   // decrement the counter
1560    return true;
1561  }
1562  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1563  {
1564    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1565        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1566        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1567        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1568    {
1569      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1570      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1571    }
1572    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1573    {
1574      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1575    }
1576    else 
1577    {
1578      static Bool warningMessage = false;
1579      if(!warningMessage)
1580      {
1581        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1582        warningMessage = true;
1583      }
1584      return true;
1585    }
1586  }
1587  // skip the reordered pictures, if necessary
1588  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))
1589  {
1590    iPOCLastDisplay++;
1591    return true;
1592  }
1593  // if we reach here, then the picture is not skipped.
1594  return false; 
1595}
1596
1597#if VPS_EXTN_DIRECT_REF_LAYERS
1598TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc )
1599{
1600  TComVPS* vps = m_parameterSetManagerDecoder[0].getActiveVPS();
1601  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
1602  {
1603    return (TDecTop *)getLayerDec( 0 );
1604  }
1605 
1606  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdc ) );
1607}
1608#endif
1609
1610#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
1611
1612Void TDecTop::setRefLayerParams( TComVPS* vps )
1613{
1614  for(UInt layer = 0; layer < m_numLayer; layer++)
1615  {
1616    TDecTop *decTop = (TDecTop *)getLayerDec(layer);
1617    decTop->setNumSamplePredRefLayers(0);
1618    decTop->setNumMotionPredRefLayers(0);
1619    decTop->setNumDirectRefLayers(0);
1620    for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++)
1621    {
1622      decTop->setSamplePredEnabledFlag(i, false);
1623      decTop->setMotionPredEnabledFlag(i, false);
1624      decTop->setSamplePredRefLayerId(i, 0);
1625      decTop->setMotionPredRefLayerId(i, 0);
1626    }
1627    for(Int j = 0; j < layer; j++)
1628    {
1629      if (vps->getDirectDependencyFlag(layer, j))
1630      {
1631        decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layer));
1632        decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1);
1633
1634        Int samplePredEnabledFlag = (vps->getDirectDependencyType(layer, j) + 1) & 1;
1635        decTop->setSamplePredEnabledFlag(j, samplePredEnabledFlag == 1 ? true : false);
1636        decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag);
1637
1638        Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layer, j) + 1) & 2) >> 1;
1639        decTop->setMotionPredEnabledFlag(j, motionPredEnabledFlag == 1 ? true : false);
1640        decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag);
1641      }
1642    }
1643  }
1644  for ( Int i = 1, mIdx = 0, sIdx = 0; i < m_numLayer; i++ )
1645  {
1646    Int iNuhLId = vps->getLayerIdInNuh(i);
1647    TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId);
1648    for ( Int j = 0; j < i; j++ )
1649    {
1650      if (decTop->getMotionPredEnabledFlag(j))
1651      {
1652        decTop->setMotionPredRefLayerId(mIdx++, vps->getLayerIdInNuh(j));
1653      }
1654      if (decTop->getSamplePredEnabledFlag(j))
1655      {
1656        decTop->setSamplePredRefLayerId(sIdx++, vps->getLayerIdInNuh(j));
1657      }
1658    }
1659  }
1660}
1661
1662#endif
1663
1664#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
1665TComPic* TDecTop::getMotionPredIlp(TComSlice* pcSlice)
1666{
1667  TComPic* ilpPic = NULL;
1668  Int activeMotionPredReflayerIdx = 0;
1669
1670  for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
1671  {
1672    UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
1673    if( getMotionPredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) ) )
1674    {
1675      if (activeMotionPredReflayerIdx == pcSlice->getColRefLayerIdx())
1676      {
1677        ilpPic = m_cIlpPic[refLayerIdc];
1678        break;
1679      }
1680      else
1681      {
1682        activeMotionPredReflayerIdx++;
1683      }
1684    }
1685  }
1686
1687  assert(ilpPic != NULL);
1688
1689  return ilpPic;
1690}
1691#endif
1692
1693//! \}
Note: See TracBrowser for help on using the repository browser.