source: SHVCSoftware/branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecTop.cpp @ 446

Last change on this file since 446 was 446, checked in by seregin, 12 years ago

copy layerId, reference picture list modification information for the slices in the picture along with performing the upsampling once per picture

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