source: SHVCSoftware/branches/SHM-2.1-dev/source/Lib/TLibDecoder/TDecTop.cpp @ 299

Last change on this file since 299 was 297, checked in by vidyo, 12 years ago

Implementation of inter_layer_sample_pred_only_flag part of M0457. The code is disabled by default. Enable by setting M0457_IL_SAMPLE_PRED_ONLY_FLAG to 1.

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