Changeset 56 in 3DVCSoftware for trunk/source/Lib/TLibDecoder/TDecTop.cpp


Ignore:
Timestamp:
11 May 2012, 21:20:17 (12 years ago)
Author:
hschwarz
Message:

updated trunk (move to HM6.1)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibDecoder/TDecTop.cpp

    r42 r56  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license.
     4 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2011, ISO/IEC
     6 * Copyright (c) 2010-2012, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    1515 *    this list of conditions and the following disclaimer in the documentation
    1616 *    and/or other materials provided with the distribution.
    17  *  * Neither the name of the ISO/IEC nor the names of its contributors may
     17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
    1818 *    be used to endorse or promote products derived from this software without
    1919 *    specific prior written permission.
     
    3636*/
    3737
     38#include "NALread.h"
    3839#include "../../App/TAppDecoder/TAppDecTop.h"
    3940#include "TDecTop.h"
    4041
     42//! \ingroup TLibDecoder
     43//! \{
    4144
    4245
     
    4447: m_bInitialized( false )
    4548{
    46   m_aaiCodedOffset         = new Int* [ MAX_NUMBER_VIEWS ];
    47   m_aaiCodedScale          = new Int* [ MAX_NUMBER_VIEWS ];
    48   m_aiViewOrderIndex       = new Int  [ MAX_NUMBER_VIEWS ];
    49   m_aiViewReceived         = new Int  [ MAX_NUMBER_VIEWS ];
    50   for( UInt uiId = 0; uiId < MAX_NUMBER_VIEWS; uiId++ )
    51   {
    52     m_aaiCodedOffset      [ uiId ] = new Int [ MAX_NUMBER_VIEWS ];
    53     m_aaiCodedScale       [ uiId ] = new Int [ MAX_NUMBER_VIEWS ];
     49  m_aaiCodedOffset         = new Int* [ MAX_VIEW_NUM ];
     50  m_aaiCodedScale          = new Int* [ MAX_VIEW_NUM ];
     51  m_aiViewOrderIndex       = new Int  [ MAX_VIEW_NUM ];
     52  m_aiViewReceived         = new Int  [ MAX_VIEW_NUM ];
     53  for( UInt uiId = 0; uiId < MAX_VIEW_NUM; uiId++ )
     54  {
     55    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_VIEW_NUM ];
     56    m_aaiCodedScale       [ uiId ] = new Int [ MAX_VIEW_NUM ];
    5457  }
    5558}
     
    5760CamParsCollector::~CamParsCollector()
    5861{
    59   for( UInt uiId = 0; uiId < MAX_NUMBER_VIEWS; uiId++ )
     62  for( UInt uiId = 0; uiId < MAX_VIEW_NUM; uiId++ )
    6063  {
    6164    delete [] m_aaiCodedOffset      [ uiId ];
     
    99102  }
    100103
    101   AOF( pcSlice->getSPS()->getViewId() < MAX_NUMBER_VIEWS );
     104  AOF( pcSlice->getSPS()->getViewId() < MAX_VIEW_NUM );
    102105  if ( pcSlice->getSPS()->isDepth  () )
    103106  {
     
    134137      xOutput( m_iLastPOC );
    135138    }
    136     ::memset( m_aiViewReceived, 0x00, MAX_NUMBER_VIEWS * sizeof( Int ) );
     139    ::memset( m_aiViewReceived, 0x00, MAX_VIEW_NUM * sizeof( Int ) );
    137140  }
    138141
     
    230233          {
    231234            fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
    232                      iS, iE, uiViewId, uiBaseId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_uiCamParsCodedPrecision );
     235              iS, iE, uiViewId, uiBaseId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_uiCamParsCodedPrecision );
    233236          }
    234237        }
     
    238241}
    239242
    240 
    241 
    242 
    243243TDecTop::TDecTop()
    244244: m_SEIs(0)
    245 {
     245, m_tAppDecTop( NULL )
     246, m_nalUnitTypeBaseView( NAL_UNIT_INVALID )
     247{
     248  m_pcPic = 0;
    246249  m_iGopSize      = 0;
    247250  m_bGopSizeSet   = false;
    248251  m_iMaxRefPicNum = 0;
    249252  m_uiValidPS = 0;
    250   m_bIsDepth = false ;
    251   m_iViewIdx = 0 ;
    252253#if SONY_COLPIC_AVAILABILITY
    253254  m_iViewOrderIdx = 0;
     
    258259  g_nSymbolCounter = 0;
    259260#endif
    260 #if DCM_DECODING_REFRESH
    261261  m_bRefreshPending = 0;
    262   m_uiPOCCDR = 0;
    263 #if DCM_SKIP_DECODING_FRAMES
    264   m_uiPOCRA = MAX_UINT;
    265 #endif
    266 #endif
    267   m_uiPrevPOC               = UInt(-1);
     262  m_pocCRA = 0;
     263  m_pocRandomAccess = MAX_INT;         
     264  m_prevPOC                = MAX_INT;
    268265  m_bFirstSliceInPicture    = true;
    269266  m_bFirstSliceInSequence   = true;
    270   m_pcCamParsCollector = 0;
    271267}
    272268
     
    288284{
    289285  m_cGopDecoder.destroy();
    290 
     286 
    291287  delete m_apcSlicePilot;
    292288  m_apcSlicePilot = NULL;
    293 
     289 
    294290  m_cSliceDecoder.destroy();
     291  m_tAppDecTop = NULL;
    295292
    296293#if DEPTH_MAP_GENERATION
     
    306303  // initialize ROM
    307304  if( bFirstInstance )
    308     initROM();
    309 #if MTK_SAO
    310   m_cGopDecoder.  init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO
     305  {
     306  initROM();
     307  }
     308  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO
    311309#if DEPTH_MAP_GENERATION
    312                       , &m_cDepthMapGenerator
     310                    , &m_cDepthMapGenerator
    313311#endif
    314312#if HHI_INTER_VIEW_RESIDUAL_PRED
    315                       , &m_cResidualGenerator
    316 #endif
    317                       );
    318 #else
    319   m_cGopDecoder.  init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter
    320 #if DEPTH_MAP_GENERATION
    321                       , &m_cDepthMapGenerator
    322 #endif
    323 #if HHI_INTER_VIEW_RESIDUAL_PRED
    324                       , &m_cResidualGenerator
    325 #endif
    326                       );
    327 #endif
     313                    , &m_cResidualGenerator
     314#endif
     315    );
    328316  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
    329317  m_cEntropyDecoder.init(&m_cPrediction);
    330 
    331   m_pcTAppDecTop = pcTAppDecTop;
     318  m_tAppDecTop = pcTAppDecTop;
    332319#if DEPTH_MAP_GENERATION
    333   m_cDepthMapGenerator.init( &m_cPrediction, m_pcTAppDecTop->getSPSAccess(), m_pcTAppDecTop->getAUPicAccess() );
     320  m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
    334321#endif
    335322#if HHI_INTER_VIEW_RESIDUAL_PRED
     
    338325}
    339326
    340 Void TDecTop::setSPS(TComSPS cSPS)
    341 {
    342   m_cSPS = cSPS ;
    343       if ( !m_cAdaptiveLoopFilter.isCreated())
    344       {
    345   m_cAdaptiveLoopFilter.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    346 #if MTK_SAO
    347   m_cSAO.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    348 #endif
    349   m_cLoopFilter.        create( g_uiMaxCUDepth );
    350       }
    351   m_uiValidPS |= 1;
    352 }
    353 
    354327Void TDecTop::deletePicBuffer ( )
    355328{
    356329  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
    357330  Int iSize = Int( m_cListPic.size() );
    358 
     331 
    359332  for (Int i = 0; i < iSize; i++ )
    360333  {
    361     TComPic* pcPic = *(iterPic++);
    362     pcPic->destroy();
    363 
    364     delete pcPic;
    365     pcPic = NULL;
    366   }
    367 
     334    if( *iterPic )
     335    {
     336      TComPic* pcPic = *(iterPic++);
     337      pcPic->destroy();
     338   
     339      delete pcPic;
     340      pcPic = NULL;
     341    }
     342  }
     343 
    368344  // destroy ALF temporary buffers
    369345  m_cAdaptiveLoopFilter.destroy();
    370346
    371 #if MTK_SAO
    372347  m_cSAO.destroy();
    373 #endif
    374 
     348 
    375349  m_cLoopFilter.        destroy();
    376 
     350 
    377351  // destroy ROM
    378   if( m_iViewIdx <= 0 && !m_bIsDepth)
     352  if(m_viewId == 0 && m_isDepth == false)
     353  {
    379354    destroyROM();
    380 }
    381 
    382 Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
    383 {
    384   m_iMaxRefPicNum = getCodedPictureBufferSize( );
    385 
    386 #if DEPTH_MAP_GENERATION
    387   UInt uiPdm                  = ( pcSlice->getSPS()->getViewId() ? pcSlice->getSPS()->getPredDepthMapGeneration() : m_pcTAppDecTop->getSPSAccess()->getPdm() );
    388   Bool bNeedPrdDepthMapBuffer = ( !pcSlice->getSPS()->isDepth() && uiPdm > 0 );
    389 #endif
    390 
    391   if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
    392   {
    393     rpcPic = new TComPic;
    394     rpcPic->create ( pcSlice->getSPS()->getWidth(), pcSlice->getSPS()->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    395 #if DEPTH_MAP_GENERATION
    396     if( bNeedPrdDepthMapBuffer )
    397     {
    398       rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
    399     }
    400 #endif
    401     m_cListPic.pushBack( rpcPic );
    402 
    403     return;
    404   }
    405 
    406   Bool bBufferIsAvailable = false;
    407   TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
    408   while (iterPic != m_cListPic.end())
    409   {
    410     rpcPic = *(iterPic++);
    411     if ( rpcPic->getReconMark() == false )
    412     {
    413       bBufferIsAvailable = true;
    414       break;
    415     }
    416   }
    417 
    418   if ( !bBufferIsAvailable )
    419   {
    420     pcSlice->sortPicList(m_cListPic);
    421     iterPic = m_cListPic.begin();
    422     rpcPic = *(iterPic);
    423     rpcPic->setReconMark(false);
    424 
    425     // mark it should be extended
    426   }
    427   rpcPic->getPicYuvRec()->setBorderExtension(false);
    428 
    429 #if DEPTH_MAP_GENERATION
    430   if( bNeedPrdDepthMapBuffer && !rpcPic->getPredDepthMap() )
    431   {
    432     rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
    433   }
    434 #endif
    435 }
    436 
    437 
     355  }
     356}
     357
     358#if HHI_INTER_VIEW_RESIDUAL_PRED
    438359Void
    439360TDecTop::deleteExtraPicBuffers( Int iPoc )
     
    450371    }
    451372  }
    452   AOF( pcPic );
     373  //AOF( pcPic );
    453374  if ( pcPic )
    454375  {
    455     pcPic->removeOriginalBuffer   ();
    456 #if HHI_INTER_VIEW_MOTION_PRED
    457     pcPic->removeOrgDepthMapBuffer();
    458 #endif
    459 #if HHI_INTER_VIEW_RESIDUAL_PRED
    460376    pcPic->removeResidualBuffer   ();
    461 #endif
    462 #if HHI_INTERVIEW_SKIP
    463     pcPic->removeUsedPelsMapBuffer();
    464 #endif
    465   }
    466 }
    467 
    468 #if AMVP_BUFFERCOMPRESS
     377  }
     378}
     379#endif
     380
     381
    469382Void
    470383TDecTop::compressMotion( Int iPoc )
     
    481394    }
    482395  }
    483   AOF( pcPic );
     396//  AOF( pcPic );
    484397  if ( pcPic )
    485398  {
     
    487400  }
    488401}
    489 #endif
    490 
    491 
    492 Void TDecTop::executeDeblockAndAlf(Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame,  Int& iPOCLastDisplay)
    493 {
     402
     403Void TDecTop::xUpdateGopSize (TComSlice* pcSlice)
     404{
     405  if ( !pcSlice->isIntra() && !m_bGopSizeSet)
     406  {
     407    m_iGopSize    = pcSlice->getPOC();
     408    m_bGopSizeSet = true;
     409   
     410    m_cGopDecoder.setGopSize(m_iGopSize);
     411  }
     412}
     413
     414Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
     415{
     416  xUpdateGopSize(pcSlice);
     417 
     418#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
     419  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
     420#else
     421  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxNumberOfReferencePictures()+pcSlice->getSPS()->getNumReorderFrames() + 1; // +1 to have space for the picture currently being decoded
     422#endif
     423
     424#if DEPTH_MAP_GENERATION
     425  UInt uiPdm                  = ( pcSlice->getSPS()->getViewId() ? pcSlice->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
     426  Bool bNeedPrdDepthMapBuffer = ( !pcSlice->getSPS()->isDepth() && uiPdm > 0 );
     427#endif
     428
     429  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
     430  {
     431    rpcPic = new TComPic();
     432   
     433    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
     434   
     435#if DEPTH_MAP_GENERATION
     436    if( bNeedPrdDepthMapBuffer )
     437    {
     438      rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
     439    }
     440#endif
     441   
     442    m_cListPic.pushBack( rpcPic );
     443   
     444    return;
     445  }
     446 
     447  Bool bBufferIsAvailable = false;
     448  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
     449  while (iterPic != m_cListPic.end())
     450  {
     451    rpcPic = *(iterPic++);
     452    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
     453    {
     454      rpcPic->setOutputMark(false);
     455      bBufferIsAvailable = true;
     456      break;
     457    }
     458
     459    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
     460    {
     461      rpcPic->setOutputMark(false);
     462      rpcPic->setReconMark( false );
     463      rpcPic->getPicYuvRec()->setBorderExtension( false );
     464      bBufferIsAvailable = true;
     465      break;
     466    }
     467  }
     468 
     469  if ( !bBufferIsAvailable )
     470  {
     471    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
     472    m_iMaxRefPicNum++;
     473    rpcPic = new TComPic();
     474    m_cListPic.pushBack( rpcPic );
     475  }
     476  rpcPic->destroy(); 
     477  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
     478#if DEPTH_MAP_GENERATION
     479  if( bNeedPrdDepthMapBuffer && !rpcPic->getPredDepthMap() )
     480  {
     481    rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
     482  }
     483#endif
     484}
     485
     486Void TDecTop::executeDeblockAndAlf(UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame, Int& iPOCLastDisplay)
     487{
     488  if (!m_pcPic)
     489  {
     490    /* nothing to deblock */
     491    return;
     492  }
     493 
    494494  TComPic*&   pcPic         = m_pcPic;
    495495
    496496  // Execute Deblock and ALF only + Cleanup
    497   TComSlice* pcSlice  = pcPic->getPicSym()->getSlice( m_uiSliceIdx                  );
    498   m_cGopDecoder.decompressGop ( bEos, pcBitstream, pcPic, true);
    499 
    500   if( m_pcCamParsCollector && bEos )
    501   {
    502     m_pcCamParsCollector->setSlice( 0 );
    503   }
    504 
    505   pcSlice->sortPicList        ( m_cListPic );       //  sorting for application output
     497
     498  m_cGopDecoder.decompressGop(NULL, pcPic, true);
     499
     500  TComSlice::sortPicList( m_cListPic ); // sorting for application output
    506501  ruiPOC              = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
    507   rpcListPic          = &m_cListPic;
    508   m_cCuDecoder.destroy();
     502  rpcListPic          = &m_cListPic; 
     503  m_cCuDecoder.destroy();       
    509504  m_bFirstSliceInPicture  = true;
    510505
     
    512507}
    513508
    514 #if DCM_SKIP_DECODING_FRAMES
    515 #if FLEX_CODING_ORDER
    516 Bool TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame,  Int& iPOCLastDisplay, Bool& bNewPictureType)
     509Void TDecTop::xCreateLostPicture(Int iLostPoc)
     510{
     511  printf("\ninserting lost poc : %d\n",iLostPoc);
     512  TComSlice cFillSlice;
     513  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
     514  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
     515  cFillSlice.initSlice();
     516  cFillSlice.initTiles();
     517  TComPic *cFillPic;
     518  xGetNewPicBuffer(&cFillSlice,cFillPic);
     519  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
     520  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
     521  cFillPic->getSlice(0)->initSlice();
     522  cFillPic->getSlice(0)->initTiles();
     523
     524 
     525 
     526  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
     527  Int closestPoc = 1000000;
     528  while ( iterPic != m_cListPic.end())
     529  {
     530    TComPic * rpcPic = *(iterPic++);
     531    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())
     532    {
     533      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
     534    }
     535  }
     536  iterPic = m_cListPic.begin();
     537  while ( iterPic != m_cListPic.end())
     538  {
     539    TComPic *rpcPic = *(iterPic++);
     540    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
     541    {
     542      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
     543      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
     544      break;
     545    }
     546  }
     547  cFillPic->setCurrSliceIdx(0);
     548  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++)
     549  {
     550    cFillPic->getCU(i)->initCU(cFillPic,i);
     551  }
     552  cFillPic->getSlice(0)->setReferenced(true);
     553  cFillPic->getSlice(0)->setPOC(iLostPoc);
     554  cFillPic->setReconMark(true);
     555  cFillPic->setOutputMark(true);
     556  if(m_pocRandomAccess == MAX_INT)
     557  {
     558    m_pocRandomAccess = iLostPoc;
     559  }
     560}
     561
     562
     563Void TDecTop::xActivateParameterSets()
     564{
     565  m_parameterSetManagerDecoder.applyPrefetchedPS();
     566
     567  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
     568  assert (pps != 0);
     569
     570  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
     571  assert (sps != 0);
     572
     573  m_apcSlicePilot->setPPS(pps);
     574  m_apcSlicePilot->setSPS(sps);
     575  pps->setSPS(sps);
     576
     577  if(sps->getUseSAO() || sps->getUseALF()|| sps->getScalingListFlag() || sps->getUseDF())
     578  {
     579    m_apcSlicePilot->setAPS( m_parameterSetManagerDecoder.getAPS(m_apcSlicePilot->getAPSId())  );
     580  }
     581  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
     582
     583  for (Int i = 0; i < sps->getMaxCUDepth() - 1; i++)
     584  {
     585    sps->setAMPAcc( i, sps->getUseAMP() );
     586  }
     587
     588  for (Int i = sps->getMaxCUDepth() - 1; i < sps->getMaxCUDepth(); i++)
     589  {
     590    sps->setAMPAcc( i, 0 );
     591  }
     592
     593#if !LCU_SYNTAX_ALF
     594  // create ALF temporary buffer
     595  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     596#endif
     597  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     598  m_cLoopFilter.        create( g_uiMaxCUDepth );
     599}
     600
     601#if SKIPFRAME_BUGFIX
     602Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
    517603#else
    518 Bool TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame,  Int& iPOCLastDisplay)
    519 
    520 #endif
     604Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int iSkipFrame, Int iPOCLastDisplay )
     605#endif
     606{
     607  TComPic*&   pcPic         = m_pcPic;
     608  m_apcSlicePilot->initSlice();
     609
     610  //!!!KS: DIRTY HACK
     611  m_apcSlicePilot->setPPSId(0);
     612  m_apcSlicePilot->setPPS(m_parameterSetManagerDecoder.getPrefetchedPPS(0));
     613  m_apcSlicePilot->setSPS(m_parameterSetManagerDecoder.getPrefetchedSPS(0));
     614  m_apcSlicePilot->initTiles();
     615
     616  if (m_bFirstSliceInPicture)
     617  {
     618    m_uiSliceIdx     = 0;
     619    m_uiLastSliceIdx = 0;
     620  }
     621  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
     622  if (!m_bFirstSliceInPicture)
     623  {
     624    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
     625  }
     626
     627  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
     628  if( m_bFirstSliceInPicture )
     629  {
     630    if( nalu.m_viewId == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
     631    else                     { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, nalu.m_isDepth )->getNalUnitTypeBaseView(); }
     632    m_apcSlicePilot->setNalUnitTypeBaseViewMvc( m_nalUnitTypeBaseView );
     633  }
     634
     635#if SONY_COLPIC_AVAILABILITY
     636  m_apcSlicePilot->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx());
     637#endif
     638
     639#if NAL_REF_FLAG
     640  m_apcSlicePilot->setReferenced(nalu.m_nalRefFlag);
    521641#else
    522 Void TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS )
    523 #endif
    524 {
     642  m_apcSlicePilot->setReferenced(nalu.m_nalRefIDC != NAL_REF_IDC_PRIORITY_LOWEST);
     643#endif
     644  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
     645
     646  // ALF CU parameters should be part of the slice header -> needs to be fixed
     647#if LCU_SYNTAX_ALF
     648  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet());
     649#else
     650  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam() );
     651#endif
     652  // byte align
     653  {
     654    Int numBitsForByteAlignment = nalu.m_Bitstream->getNumBitsUntilByteAligned();
     655    if ( numBitsForByteAlignment > 0 )
     656    {
     657      UInt bitsForByteAlignment;
     658      nalu.m_Bitstream->read( numBitsForByteAlignment, bitsForByteAlignment );
     659      assert( bitsForByteAlignment == ( ( 1 << numBitsForByteAlignment ) - 1 ) );
     660    }
     661  }
     662
     663  // exit when a new picture is found
     664  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence)
     665  {
     666#if START_DECODING_AT_CRA
     667    if (m_prevPOC >= m_pocRandomAccess)
     668    {
     669      m_prevPOC = m_apcSlicePilot->getPOC();
     670      return true;
     671    }
     672    m_prevPOC = m_apcSlicePilot->getPOC();
     673#else
     674    m_prevPOC = m_apcSlicePilot->getPOC();
     675    return true;
     676#endif
     677  }
     678  // actual decoding starts here
     679  xActivateParameterSets();
     680  m_apcSlicePilot->initTiles();
     681
     682  if (m_apcSlicePilot->isNextSlice())
     683  {
     684    m_prevPOC = m_apcSlicePilot->getPOC();
     685  }
     686  m_bFirstSliceInSequence = false;
     687  if (m_apcSlicePilot->isNextSlice())
     688  {
     689    // Skip pictures due to random access
     690    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
     691    {
     692      return false;
     693    }
     694  }
     695  //detect lost reference picture and insert copy of earlier frame.
     696#if START_DECODING_AT_CRA
     697  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess) > 0)
     698#else
     699  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true) > 0)
     700#endif
     701  {
     702    xCreateLostPicture(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), false)-1);
     703  }
    525704  if (m_bFirstSliceInPicture)
    526705  {
    527     rpcListPic = NULL;
    528   }
    529   TComPic*&   pcPic         = m_pcPic;
    530 
     706    // Buffer initialize for prediction.
     707    m_cPrediction.initTempBuff();
     708    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
     709    //  Get a new picture buffer
     710    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
     711
     712#if SONY_COLPIC_AVAILABILITY
     713    pcPic->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx() );
     714#endif
     715
     716    /* transfer any SEI messages that have been received to the picture */
     717    pcPic->setSEIs(m_SEIs);
     718    m_SEIs = NULL;
     719
     720    // Recursive structure
     721    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
     722    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
     723    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
     724
     725    m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     726#if DEPTH_MAP_GENERATION
     727    UInt uiPdm = ( m_apcSlicePilot->getSPS()->getViewId() ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
     728    m_cDepthMapGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
     729    TComDepthMapGenerator* pcDMG0 = m_tAppDecTop->getDecTop0()->getDepthMapGenerator();
     730    if( m_apcSlicePilot->getSPS()->getViewId() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
     731    {
     732      pcDMG0->create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
     733    }
     734#endif
     735#if HHI_INTER_VIEW_RESIDUAL_PRED
     736    m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
     737#endif
     738  }
     739
     740  //  Set picture slice pointer
     741  TComSlice*  pcSlice = m_apcSlicePilot;
     742  Bool bNextSlice     = pcSlice->isNextSlice();
     743
     744  UInt uiCummulativeTileWidth;
     745  UInt uiCummulativeTileHeight;
     746  UInt i, j, p;
     747
     748#if !REMOVE_TILE_DEPENDENCE
     749  //set the TileBoundaryIndependenceIdr
     750  if(pcSlice->getPPS()->getTileBehaviorControlPresentFlag() == 1)
     751  {
     752    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getTileBoundaryIndependenceIdr() );
     753  }
     754  else
     755  {
     756    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getSPS()->getTileBoundaryIndependenceIdr() );
     757  }
     758#endif
     759
     760  if( pcSlice->getPPS()->getColumnRowInfoPresent() == 1 )
     761  {
     762    //set NumColumnsMins1 and NumRowsMinus1
     763    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
     764    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
     765
     766    //create the TComTileArray
     767    pcPic->getPicSym()->xCreateTComTileArray();
     768
     769    if( pcSlice->getPPS()->getUniformSpacingIdr() == 1)
     770    {
     771      //set the width for each tile
     772      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
     773      {
     774        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
     775        {
     776          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
     777            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1)
     778            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
     779        }
     780      }
     781
     782      //set the height for each tile
     783      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
     784      {
     785        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
     786        {
     787          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
     788            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1)
     789            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
     790        }
     791      }
     792    }
     793    else
     794    {
     795      //set the width for each tile
     796      for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
     797      {
     798        uiCummulativeTileWidth = 0;
     799        for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
     800        {
     801          pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
     802          uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
     803        }
     804        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
     805      }
     806
     807      //set the height for each tile
     808      for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
     809      {
     810        uiCummulativeTileHeight = 0;
     811        for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
     812        {
     813          pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
     814          uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
     815        }
     816        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
     817      }
     818    }
     819  }
     820  else
     821  {
     822    //set NumColumnsMins1 and NumRowsMinus1
     823    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getSPS()->getNumColumnsMinus1() );
     824    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getSPS()->getNumRowsMinus1() );
     825
     826    //create the TComTileArray
     827    pcPic->getPicSym()->xCreateTComTileArray();
     828
     829    //automatically set the column and row boundary if UniformSpacingIdr = 1
     830    if( pcSlice->getSPS()->getUniformSpacingIdr() == 1 )
     831    {
     832      //set the width for each tile
     833      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
     834      {
     835        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
     836        {
     837          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
     838            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1)
     839            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
     840        }
     841      }
     842
     843      //set the height for each tile
     844      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
     845      {
     846        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
     847        {
     848          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
     849            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1)
     850            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
     851        }
     852      }
     853    }
     854    else
     855    {
     856      //set the width for each tile
     857      for(j=0; j < pcSlice->getSPS()->getNumRowsMinus1()+1; j++)
     858      {
     859        uiCummulativeTileWidth = 0;
     860        for(i=0; i < pcSlice->getSPS()->getNumColumnsMinus1(); i++)
     861        {
     862          pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getSPS()->getColumnWidth(i) );
     863          uiCummulativeTileWidth += pcSlice->getSPS()->getColumnWidth(i);
     864        }
     865        pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
     866      }
     867
     868      //set the height for each tile
     869      for(j=0; j < pcSlice->getSPS()->getNumColumnsMinus1()+1; j++)
     870      {
     871        uiCummulativeTileHeight = 0;
     872        for(i=0; i < pcSlice->getSPS()->getNumRowsMinus1(); i++)
     873        {
     874          pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getSPS()->getRowHeight(i) );
     875          uiCummulativeTileHeight += pcSlice->getSPS()->getRowHeight(i);
     876        }
     877        pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
     878      }
     879    }
     880  }
     881
     882  pcPic->getPicSym()->xInitTiles();
     883
     884  //generate the Coding Order Map and Inverse Coding Order Map
     885  UInt uiEncCUAddr;
     886  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
     887  {
     888    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
     889    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
     890  }
     891  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
     892  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
     893
     894  //convert the start and end CU addresses of the slice and entropy slice into encoding order
     895  pcSlice->setEntropySliceCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurStartCUAddr()) );
     896  pcSlice->setEntropySliceCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurEndCUAddr()) );
     897  if(pcSlice->isNextSlice())
     898  {
     899    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
     900    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
     901  }
     902
     903  if (m_bFirstSliceInPicture)
     904  {
     905    if(pcPic->getNumAllocatedSlice() != 1)
     906    {
     907      pcPic->clearSliceBuffer();
     908    }
     909  }
     910  else
     911  {
     912    pcPic->allocateNewSlice();
     913  }
     914  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
     915  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx);
     916  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
     917
     918  pcPic->setTLayer(nalu.m_temporalId);
     919
     920  if (bNextSlice)
     921  {
     922    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_cListPic);
     923
     924    if ( !pcSlice->getPPS()->getEnableTMVPFlag() && pcPic->getTLayer() == 0 )
     925    {
     926      pcSlice->decodingMarkingForNoTMVP( m_cListPic, pcSlice->getPOC() );
     927    }
     928
     929    // Set reference list
     930    pcSlice->setViewId(m_viewId);
     931    pcSlice->setIsDepth(m_isDepth);
     932
     933#if SONY_COLPIC_AVAILABILITY
     934    pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
     935#endif
     936
     937    assert( m_tAppDecTop != NULL );
     938    TComPic * const pcTexturePic = m_isDepth ? m_tAppDecTop->getPicFromView(  m_viewId, pcSlice->getPOC(), false ) : NULL;
     939    assert( !m_isDepth || pcTexturePic != NULL );
     940    pcSlice->setTexturePic( pcTexturePic );
     941
     942    std::vector<TComPic*> apcInterViewRefPics = m_tAppDecTop->getInterViewRefPics( m_viewId, pcSlice->getPOC(), m_isDepth, pcSlice->getSPS() );
     943    pcSlice->setRefPicListMvc( m_cListPic, apcInterViewRefPics );
     944
     945    // For generalized B
     946    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
     947    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
     948    {
     949      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
     950      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
     951
     952      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
     953      {
     954        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
     955      }
     956    }
     957    if (pcSlice->isInterB())
     958    {
     959      Bool bLowDelay = true;
     960      Int  iCurrPOC  = pcSlice->getPOC();
     961      Int iRefIdx = 0;
     962
     963      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
     964      {
     965        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
     966        {
     967          bLowDelay = false;
     968        }
     969      }
     970      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
     971      {
     972        if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
     973        {
     974          bLowDelay = false;
     975        }
     976      }
     977
     978      pcSlice->setCheckLDC(bLowDelay);           
     979    }
     980
     981    //---------------
     982    pcSlice->setRefPOCnViewListsMvc();
     983
     984    if(!pcSlice->getRefPicListModificationFlagLC())
     985    {
     986      pcSlice->generateCombinedList();
     987    }
     988
     989    if( pcSlice->getRefPicListCombinationFlag() && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE )
     990    {
     991      pcSlice->setWpParamforLC();
     992    }
     993    pcSlice->setNoBackPredFlag( false );
     994    if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
     995    {
     996      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
     997      {
     998        pcSlice->setNoBackPredFlag( true );
     999        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
     1000        {
     1001          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) )
     1002          {
     1003            pcSlice->setNoBackPredFlag( false );
     1004            break;
     1005          }
     1006        }
     1007      }
     1008    }
     1009  }
     1010
     1011  pcPic->setCurrSliceIdx(m_uiSliceIdx);
     1012  if(pcSlice->getSPS()->getScalingListFlag())
     1013  {
     1014    if(pcSlice->getAPS()->getScalingListEnabled())
     1015    {
     1016      pcSlice->setScalingList ( pcSlice->getAPS()->getScalingList()  );
     1017      if(pcSlice->getScalingList()->getScalingListPresentFlag())
     1018      {
     1019        pcSlice->setDefaultScalingList();
     1020      }
     1021      m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
     1022    }
     1023    m_cTrQuant.setUseScalingList(true);
     1024  }
     1025  else
     1026  {
     1027    m_cTrQuant.setFlatScalingList();
     1028    m_cTrQuant.setUseScalingList(false);
     1029  }
     1030
     1031#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     1032  if( m_parameterSetManagerDecoder.getPrefetchedSPS(0)->getUseDMM() && g_aacWedgeLists.empty() )
     1033  {
     1034    initWedgeLists();
     1035  }
     1036#endif
     1037
     1038  //  Decode a picture
     1039  m_cGopDecoder.decompressGop(nalu.m_Bitstream, pcPic, false);
     1040
     1041  m_bFirstSliceInPicture = false;
     1042  m_uiSliceIdx++;
     1043
     1044  return false;
     1045}
     1046
     1047
     1048Void TDecTop::xDecodeSPS()
     1049{
     1050  TComSPS* sps = new TComSPS();
     1051#if RPS_IN_SPS
     1052  TComRPSList* rps = new TComRPSList();
     1053  sps->setRPSList(rps);
     1054#endif
     1055#if HHI_MPI
     1056  m_cEntropyDecoder.decodeSPS( sps, m_isDepth );
     1057#else
     1058  m_cEntropyDecoder.decodeSPS( sps );
     1059#endif
     1060  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
     1061#if LCU_SYNTAX_ALF
     1062  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     1063#endif
     1064}
     1065
     1066Void TDecTop::xDecodePPS()
     1067{
     1068#if !RPS_IN_SPS
     1069  TComRPSList* rps = new TComRPSList();
     1070#endif
     1071  TComPPS* pps = new TComPPS();
     1072#if !RPS_IN_SPS
     1073  pps->setRPSList(rps);
     1074#endif
     1075#if TILES_OR_ENTROPY_SYNC_IDC
     1076  m_cEntropyDecoder.decodePPS( pps, &m_parameterSetManagerDecoder );
     1077#else
     1078  m_cEntropyDecoder.decodePPS( pps );
     1079#endif
     1080  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
     1081
     1082  //!!!KS: Activate parameter sets for parsing APS (unless dependency is resolved)
     1083  m_apcSlicePilot->setPPSId(pps->getPPSId());
     1084  xActivateParameterSets();
     1085  m_apcSlicePilot->initTiles();
     1086}
     1087
     1088Void TDecTop::xDecodeAPS()
     1089{
     1090  TComAPS  *aps = new TComAPS();
     1091  allocAPS (aps);
     1092  decodeAPS(aps);
     1093  m_parameterSetManagerDecoder.storePrefetchedAPS(aps);
     1094}
     1095
     1096Void TDecTop::xDecodeSEI()
     1097{
     1098  m_SEIs = new SEImessages;
     1099  m_cEntropyDecoder.decodeSEI(*m_SEIs);
     1100}
     1101
     1102Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
     1103{
    5311104  // Initialize entropy decoder
    5321105  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
    533   m_cEntropyDecoder.setBitstream      (pcBitstream);
    534 
    535   NalUnitType eNalUnitType;
    536   UInt        TemporalId;
    537 
    538 #if BITSTREAM_EXTRACTION
    539   UInt        uiLayerId;
    540 
    541   m_cEntropyDecoder.decodeNalUnitHeader(eNalUnitType, TemporalId, uiLayerId);
    542 #else
    543   Bool        OutputFlag;
    544 
    545   m_cEntropyDecoder.decodeNalUnitHeader(eNalUnitType, TemporalId, OutputFlag);
    546 #endif
    547 
    548   reNalUnitType = eNalUnitType;
    549 
    550   switch (eNalUnitType)
     1106  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
     1107
     1108  switch (nalu.m_nalUnitType)
    5511109  {
    5521110    case NAL_UNIT_SPS:
    553     {
    554       TComSPS cTempSPS;
    555       m_cEntropyDecoder.decodeSPS( &cTempSPS );
    556 #if FLEX_CODING_ORDER
    557       m_cNewSPS = cTempSPS;
    558 #endif
    559 
    560       if( (m_iViewIdx == cTempSPS.getViewId()) && ( m_bIsDepth == cTempSPS.isDepth() ) )
    561       {
    562         m_cSPS = cTempSPS;
    563         cComSPS = m_cSPS;
    564       }
    565       else
    566       {
    567         cComSPS = cTempSPS;
    568         return false;
    569       }
    570 
    571       // create ALF temporary buffer
    572       if ( !m_cAdaptiveLoopFilter.isCreated())
    573       {
    574       m_cAdaptiveLoopFilter.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    575 #if MTK_SAO
    576       m_cSAO.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    577 #endif
    578       m_cLoopFilter.        create( g_uiMaxCUDepth );
    579       }
    580       m_uiValidPS |= 1;
    581 
     1111      xDecodeSPS();
    5821112      return false;
    583     }
    5841113
    5851114    case NAL_UNIT_PPS:
    586       m_cEntropyDecoder.decodePPS( &m_cPPS );
    587       assert( m_cPPS.getSPSId() == m_cSPS.getSPSId() );
    588       m_uiValidPS |= 2;
     1115      xDecodePPS();
    5891116      return false;
     1117    case NAL_UNIT_APS:
     1118      xDecodeAPS();
     1119      return false;
    5901120
    5911121    case NAL_UNIT_SEI:
    592       m_SEIs = new SEImessages;
    593       m_cEntropyDecoder.decodeSEI(*m_SEIs);
     1122      xDecodeSEI();
    5941123      return false;
    5951124
    5961125    case NAL_UNIT_CODED_SLICE:
    5971126    case NAL_UNIT_CODED_SLICE_IDR:
     1127#if H0566_TLA
     1128    case NAL_UNIT_CODED_SLICE_IDV:
     1129    case NAL_UNIT_CODED_SLICE_CRA:
     1130    case NAL_UNIT_CODED_SLICE_TLA:
     1131#else
    5981132    case NAL_UNIT_CODED_SLICE_CDR:
    599     {
    600       // make sure we already received both parameter sets
    601       assert( 3 == m_uiValidPS );
    602       if (m_bFirstSliceInPicture)
    603       {
    604         m_apcSlicePilot->initSlice();
    605         m_uiSliceIdx     = 0;
    606         m_uiLastSliceIdx = 0;
    607       }
    608       m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
    609 
    610       //  Read slice header
    611       m_apcSlicePilot->setSPS( &m_cSPS );
    612       m_apcSlicePilot->setPPS( &m_cPPS );
    613       m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
    614       m_apcSlicePilot->setViewIdx( m_cSPS.getViewId() );
    615 #if SONY_COLPIC_AVAILABILITY
    616       m_apcSlicePilot->setViewOrderIdx( m_cSPS.getViewOrderIdx());
    617 #endif
    618       if (!m_bFirstSliceInPicture)
    619       {
    620         memcpy(m_apcSlicePilot, pcPic->getPicSym()->getSlice(m_uiSliceIdx-1), sizeof(TComSlice));
    621       }
    622 
    623 #if DCM_DECODING_REFRESH
    624       m_apcSlicePilot->setNalUnitType        (eNalUnitType);
    625 #endif
    626       m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot);
    627 
    628 //      if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_uiPrevPOC && !m_bFirstSliceInSequence)
    629 //      if (m_apcSlicePilot->isNextSlice() && ( m_apcSlicePilot->getPOC()!=m_uiPrevPOC || m_apcSlicePilot->getPPSId() != m_cPPS.getPPSId() ) && !m_bFirstSliceInSequence)
    630       if (m_apcSlicePilot->isNextSlice() && ( m_apcSlicePilot->getPOC()!=m_uiPrevPOC || m_apcSlicePilot->getPPSId() != m_cPPS.getPPSId() ) && !m_bFirstSliceInPicture)
    631       {
    632         m_uiPrevPOC = m_apcSlicePilot->getPOC();
    633 #if FLEX_CODING_ORDER
    634         bNewPictureType = m_cNewSPS.isDepth();
    635 #endif
    636         return true;
    637       }
    638       if (m_apcSlicePilot->isNextSlice())
    639         m_uiPrevPOC = m_apcSlicePilot->getPOC();
    640       m_bFirstSliceInSequence = false;
    641       if (m_apcSlicePilot->isNextSlice())
    642       {
    643 #if DCM_SKIP_DECODING_FRAMES
    644         // Skip pictures due to random access
    645         if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
    646         {
    647           return false;
    648         }
    649 #endif
    650       }
    651 
    652       if (m_bFirstSliceInPicture)
    653       {
    654         // Buffer initialize for prediction.
    655         m_cPrediction.initTempBuff();
    656         //  Get a new picture buffer
    657         xGetNewPicBuffer (m_apcSlicePilot, pcPic);
    658 
    659         pcPic->setViewIdx( m_cSPS.getViewId() );
    660 
    661 #if SONY_COLPIC_AVAILABILITY
    662         pcPic->setViewOrderIdx( m_cSPS.getViewOrderIdx() );
    663 #endif
    664 
    665         /* transfer any SEI messages that have been received to the picture */
    666         pcPic->setSEIs(m_SEIs);
    667         m_SEIs = NULL;
    668 
    669         // Recursive structure
    670         m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
    671         m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
    672         m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
    673 
    674         m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    675 
    676 #if DEPTH_MAP_GENERATION
    677         UInt uiPdm = ( m_cSPS.getViewId() ? m_cSPS.getPredDepthMapGeneration() : getDecTop()->getSPSAccess()->getPdm() );
    678         m_cDepthMapGenerator.create( true, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
    679         TComDepthMapGenerator* pcDMG0 = getDecTop()->getDecTop0()->getDepthMapGenerator();
    680         if( m_cSPS.getViewId() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
    681         {
    682           pcDMG0->create( true, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
    683         }
    684 #endif
    685 #if HHI_INTER_VIEW_RESIDUAL_PRED
    686         m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
    687 #endif
    688       }
    689 
    690       //  Set picture slice pointer
    691       TComSlice*  pcSlice = m_apcSlicePilot;
    692       Bool bNextSlice     = pcSlice->isNextSlice();
    693       if (m_bFirstSliceInPicture)
    694       {
    695         if(pcPic->getNumAllocatedSlice() != 1)
    696         {
    697           pcPic->clearSliceBuffer();
    698         }
    699       }
    700       else
    701       {
    702         pcPic->allocateNewSlice();
    703       }
    704       assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
    705       m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx);
    706       pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
    707 
    708       if (bNextSlice)
    709       {
    710 #if DCM_DECODING_REFRESH
    711         // Do decoding refresh marking if any
    712         pcSlice->decodingRefreshMarking(m_uiPOCCDR, m_bRefreshPending, m_cListPic);
    713 #endif
    714 
    715         // Set reference list
    716         std::vector<TComPic*> apcSpatRefPics = getDecTop()->getSpatialRefPics( pcPic->getViewIdx(), pcSlice->getPOC(), m_cSPS.isDepth() );
    717         TComPic * const pcTexturePic = m_cSPS.isDepth() ? getDecTop()->getPicFromView( pcPic->getViewIdx(), pcSlice->getPOC(), false ) : NULL;
    718 
    719 #if FLEX_CODING_ORDER
    720         if (pcTexturePic != NULL)
    721         {
    722           assert( ! m_cSPS.isDepth() || pcTexturePic != NULL );
    723           pcSlice->setTexturePic( pcTexturePic );
    724         }
    725 #else
    726         assert( ! m_cSPS.isDepth() || pcTexturePic != NULL );
    727         pcSlice->setTexturePic( pcTexturePic );
    728         pcSlice->setViewIdx( pcPic->getViewIdx() );
    729 #endif
    730 #if SONY_COLPIC_AVAILABILITY
    731         pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
    732 #endif
    733         pcSlice->setRefPicListExplicitlyDecoderSided(m_cListPic, apcSpatRefPics) ;// temporary solution
    734 
    735 #if DCM_COMB_LIST
    736         if(!pcSlice->getRefPicListModificationFlagLC())
    737         {
    738           pcSlice->generateCombinedList();
    739         }
    740 #endif
    741 
    742         pcSlice->setNoBackPredFlag( false );
    743 #if DCM_COMB_LIST
    744         if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
    745 #else
    746           if ( pcSlice->getSliceType() == B_SLICE )
    747 #endif
    748           {
    749             if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
    750             {
    751               pcSlice->setNoBackPredFlag( true );
    752               int i;
    753               for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
    754               {
    755                 if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) )
    756                 {
    757                   pcSlice->setNoBackPredFlag( false );
    758                   break;
    759                 }
    760               }
    761             }
    762           }
    763       }
    764 
    765       pcPic->setCurrSliceIdx(m_uiSliceIdx);
    766 
    767 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    768     if ( m_cSPS.getUseDMM() && g_aacWedgeLists.empty() && m_bIsDepth )
    769       {
    770         initWedgeLists();
    771       }
    772 #endif
    773 
    774       //  Decode a picture
    775       m_cGopDecoder.decompressGop ( bEos, pcBitstream, pcPic, false );
    776 
    777       if( m_pcCamParsCollector )
    778       {
    779         m_pcCamParsCollector->setSlice( pcSlice );
    780       }
    781 
    782       m_bFirstSliceInPicture = false;
    783       m_uiSliceIdx++;
    784     }
     1133#endif
     1134      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
    7851135      break;
    7861136    default:
     
    7911141}
    7921142
    793 #if DCM_SKIP_DECODING_FRAMES
    7941143/** Function for checking if picture should be skipped because of random access
    7951144 * \param iSkipFrame skip frame counter
     
    7991148 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
    8001149 * It also checks the type of Nal unit type at the random access point.
    801  * If the random access point is CDR, pictures with POC equal to or greater than the CDR POC are decoded.
     1150 * If the random access point is CRA, pictures with POC equal to or greater than the CRA POC are decoded.
    8021151 * If the random access point is IDR all pictures after the random access point are decoded.
    803  * If the random access point is not IDR or CDR, a warning is issues, and decoding of pictures with POC
    804  * equal to or greater than the random access point POC is attempted. For non IDR/CDR random
     1152 * If the random access point is not IDR or CRA, a warning is issues, and decoding of pictures with POC
     1153 * equal to or greater than the random access point POC is attempted. For non IDR/CRA random
    8051154 * access point there is no guarantee that the decoder will not crash.
    8061155 */
    8071156Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
    8081157{
    809   if (iSkipFrame)
     1158  if (iSkipFrame) 
    8101159  {
    8111160    iSkipFrame--;   // decrement the counter
    8121161    return true;
    8131162  }
    814   else if (m_uiPOCRA == MAX_UINT) // start of random access point, m_uiPOCRA has not been set yet.
    815   {
    816     if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CDR)
    817     {
    818       m_uiPOCRA = m_apcSlicePilot->getPOC(); // set the POC random access since we need to skip the reordered pictures in CDR.
    819     }
    820     else if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR)
    821     {
    822       m_uiPOCRA = 0; // no need to skip the reordered pictures in IDR, they are decodable.
    823     }
    824     else
    825     {
     1163  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
     1164  {
     1165#if H0566_TLA
     1166    if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CRA )
     1167#else
     1168    if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CDR )
     1169#endif
     1170    {
     1171      m_pocRandomAccess = m_apcSlicePilot->getPOC(); // set the POC random access since we need to skip the reordered pictures in CRA.
     1172    }
     1173    else if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_IDR )
     1174    {
     1175      m_pocRandomAccess = 0; // no need to skip the reordered pictures in IDR, they are decodable.
     1176    }
     1177    else
     1178    {
     1179#if START_DECODING_AT_CRA
     1180      static bool warningMessage = false;
     1181      if(!warningMessage)
     1182      {
     1183        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
     1184        warningMessage = true;
     1185      }
     1186      return true;
     1187#else
    8261188      printf("\nUnsafe random access point. Decoder may crash.");
    827       m_uiPOCRA = m_apcSlicePilot->getPOC(); // set the POC random access skip the reordered pictures and try to decode if possible.  This increases the chances of avoiding a decoder crash.
    828       //m_uiPOCRA = 0;
    829     }
    830   }
    831   else if (m_apcSlicePilot->getPOC() < m_uiPOCRA)  // skip the reordered pictures if necessary
     1189      m_pocRandomAccess = 0;
     1190#endif
     1191    }
     1192  }
     1193  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess)  // skip the reordered pictures if necessary
    8321194  {
    8331195    iPOCLastDisplay++;
     
    8351197  }
    8361198  // if we reach here, then the picture is not skipped.
    837   return false;
    838 }
    839 #endif
    840 
     1199  return false;
     1200}
     1201
     1202Void TDecTop::allocAPS (TComAPS* pAPS)
     1203{
     1204  // we don't know the SPS before it has been activated. These fields could exist
     1205  // depending on the corresponding flags in the APS, but SAO/ALF allocation functions will
     1206  // have to be moved for that
     1207  pAPS->createScalingList();
     1208  pAPS->createSaoParam();
     1209  m_cSAO.allocSaoParam(pAPS->getSaoParam());
     1210  pAPS->createAlfParam();
     1211#if !LCU_SYNTAX_ALF
     1212  m_cAdaptiveLoopFilter.allocALFParam(pAPS->getAlfParam());
     1213#endif
     1214}
     1215
     1216//! \}
Note: See TracChangeset for help on using the changeset viewer.