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

Last change on this file since 393 was 389, checked in by qualcomm, 12 years ago

Signaling representation format in VPS (MACRO: REPN_FORMAT_IN_VPS)

Includes signaling of representation format - including picture resolution, bit depth, chroma format - in the VPS, with the option of updating them in the SPS. The configuration file has "RepFormatIdx%d" added to indicate for each layer which representation format is used. The rep_format() structures are automatically created by the encoder. If the bit depth and the chroma format are also changed across layers, some more configuration support would be needed.

From: Adarsh K. Ramasubramonian <aramasub@…>

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