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


Ignore:
Timestamp:
1 Sep 2013, 22:47:26 (11 years ago)
Author:
tech
Message:

Merged DEV-2.0-dev0@604.

File:
1 edited

Legend:

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

    r443 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3737
    3838#include "NALread.h"
    39 #include "../../App/TAppDecoder/TAppDecTop.h"
    4039#include "TDecTop.h"
    4140
     41#if H_MV
     42ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder;
     43#endif
    4244//! \ingroup TLibDecoder
    4345//! \{
    4446
    45 
     47#if H_3D
    4648CamParsCollector::CamParsCollector()
    4749: m_bInitialized( false )
    4850{
    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 #if QC_MVHEVC_B0046
    53   m_aiViewId               = new Int  [ MAX_VIEW_NUM ];
    54 #endif
    55   m_aiViewReceived         = new Int  [ MAX_VIEW_NUM ];
    56   for( UInt uiId = 0; uiId < MAX_VIEW_NUM; uiId++ )
    57   {
    58     m_aaiCodedOffset      [ uiId ] = new Int [ MAX_VIEW_NUM ];
    59     m_aaiCodedScale       [ uiId ] = new Int [ MAX_VIEW_NUM ];
    60   }
    61 
    62 #if MERL_VSP_C0152
    63   xCreateLUTs( (UInt)MAX_VIEW_NUM, (UInt)MAX_VIEW_NUM, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
     51  m_aaiCodedOffset         = new Int* [ MAX_NUM_LAYERS ];
     52  m_aaiCodedScale          = new Int* [ MAX_NUM_LAYERS ];
     53  m_aiViewId               = new Int  [ MAX_NUM_LAYERS ];
     54
     55  m_bViewReceived          = new Bool [ MAX_NUM_LAYERS ];
     56  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
     57  {
     58    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_NUM_LAYERS ];
     59    m_aaiCodedScale       [ uiId ] = new Int [ MAX_NUM_LAYERS ];
     60  }
     61
     62  xCreateLUTs( (UInt)MAX_NUM_LAYERS, (UInt)MAX_NUM_LAYERS, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
    6463  m_iLog2Precision   = LOG2_DISP_PREC_LUT;
    6564  m_uiBitDepthForLUT = 8; // fixed
    66 #endif
    6765}
    6866
    6967CamParsCollector::~CamParsCollector()
    7068{
    71   for( UInt uiId = 0; uiId < MAX_VIEW_NUM; uiId++ )
     69  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
    7270  {
    7371    delete [] m_aaiCodedOffset      [ uiId ];
     
    7674  delete [] m_aaiCodedOffset;
    7775  delete [] m_aaiCodedScale;
    78   delete [] m_aiViewOrderIndex;
    79   delete [] m_aiViewReceived;
    80 
    81 #if MERL_VSP_C0152
    82   xDeleteArray( m_adBaseViewShiftLUT, MAX_VIEW_NUM, MAX_VIEW_NUM, 2 );
    83   xDeleteArray( m_aiBaseViewShiftLUT, MAX_VIEW_NUM, MAX_VIEW_NUM, 2 );
    84 #endif
     76  delete [] m_aiViewId; 
     77  delete [] m_bViewReceived;
     78
     79  xDeleteArray( m_adBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
     80  xDeleteArray( m_aiBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
    8581}
    8682
     
    9288  m_uiCamParsCodedPrecision = 0;
    9389  m_bCamParsVaryOverTime    = false;
    94   m_iLastViewId             = -1;
     90  m_iLastViewIndex             = -1;
    9591  m_iLastPOC                = -1;
    96   m_uiMaxViewId             = 0;
    97 }
    98 
    99 #if MERL_VSP_C0152
     92  m_uiMaxViewIndex             = 0;
     93}
     94
    10095Void
    10196CamParsCollector::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT)
    10297{
    103   //AOF( m_uiBitDepthForLUT == 8 );
    104   //AOF(radLUT == NULL && raiLUT == NULL );
    105 
    106   uiNumberSourceViews = Max( 1, uiNumberSourceViews );
    107   uiNumberTargetViews = Max( 1, uiNumberTargetViews );
     98
     99  uiNumberSourceViews = std::max( (UInt) 1, uiNumberSourceViews );
     100  uiNumberTargetViews = std::max( (UInt) 1, uiNumberTargetViews );
    108101
    109102  radLUT         = new Double***[ uiNumberSourceViews ];
     
    159152    raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma;
    160153    raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma;
    161 
    162     // maximum deviation
    163     //dMaxDispDev     = Max( dMaxDispDev,    fabs( Double( (Int) iTestScale   ) - dShiftLuma * Double( 1 << iLog2DivLuma ) ) / Double( 1 << iLog2DivLuma ) );
    164     //dMaxRndDispDvL  = Max( dMaxRndDispDvL, fabs( Double( (Int) iShiftLuma   ) - dShiftLuma   ) );
    165     //dMaxRndDispDvC  = Max( dMaxRndDispDvC, fabs( Double( (Int) iShiftChroma ) - dShiftChroma ) );
    166154  }
    167155
     
    171159  raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
    172160}
    173 #endif // end MERL_VSP_C0152
    174161
    175162Void
     
    182169CamParsCollector::setSlice( TComSlice* pcSlice )
    183170{
     171
    184172  if( pcSlice == 0 )
    185173  {
     
    191179    return;
    192180  }
    193 
    194   AOF( pcSlice->getSPS()->getViewId() < MAX_VIEW_NUM );
    195 #if !FCO_FIX  // Under flexible coding order, depth may need the camera parameters
    196   if ( pcSlice->getSPS()->isDepth  () )
     181 
     182  if ( pcSlice->getIsDepth())
    197183  {
    198184    return;
    199185  }
    200 #endif
    201   Bool  bFirstAU          = ( pcSlice->getPOC()               == 0 );
    202   Bool  bFirstSliceInAU   = ( pcSlice->getPOC()               != Int ( m_iLastPOC ) );
    203   Bool  bFirstSliceInView = ( pcSlice->getSPS()->getViewId()  != UInt( m_iLastViewId ) || bFirstSliceInAU );
    204   AOT(  bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()  != 0 );
    205 #if FCO_FIX
    206 #else
    207   AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   < UInt( m_iLastViewId ) );
    208 #endif
    209   AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   > UInt( m_iLastViewId + 1 ) );
    210   AOT( !bFirstAU         &&   pcSlice->getSPS()->getViewId()   > m_uiMaxViewId );
     186
     187  Bool  bFirstAU          = ( pcSlice->getPOC()     == 0 );
     188  Bool  bFirstSliceInAU   = ( pcSlice->getPOC()     != Int ( m_iLastPOC ) );
     189  Bool  bFirstSliceInView = ( pcSlice->getViewIndex()  != UInt( m_iLastViewIndex ) || bFirstSliceInAU );
     190
     191  AOT(  bFirstSliceInAU  &&   pcSlice->getViewIndex()  != 0 );
     192  AOT( !bFirstSliceInAU  &&   pcSlice->getViewIndex()   < UInt( m_iLastViewIndex ) );
     193 
     194  AOT( !bFirstSliceInAU  &&   pcSlice->getViewIndex()   > UInt( m_iLastViewIndex + 1 ) );
     195 
     196  AOT( !bFirstAU         &&   pcSlice->getViewIndex()   > m_uiMaxViewIndex );
     197
    211198  if ( !bFirstSliceInView )
    212199  {
    213200    if( m_bCamParsVaryOverTime ) // check consistency of slice parameters here
    214201    {
    215       UInt uiViewId = pcSlice->getSPS()->getViewId();
    216       for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
    217       {
    218         AOF( m_aaiCodedScale [ uiBaseId ][ uiViewId ] == pcSlice->getCodedScale    () [ uiBaseId ] );
    219         AOF( m_aaiCodedOffset[ uiBaseId ][ uiViewId ] == pcSlice->getCodedOffset   () [ uiBaseId ] );
    220         AOF( m_aaiCodedScale [ uiViewId ][ uiBaseId ] == pcSlice->getInvCodedScale () [ uiBaseId ] );
    221         AOF( m_aaiCodedOffset[ uiViewId ][ uiBaseId ] == pcSlice->getInvCodedOffset() [ uiBaseId ] );
     202      UInt uiViewIndex = pcSlice->getViewIndex();
     203      for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ )
     204      {
     205        AOF( m_aaiCodedScale [ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedScale    () [ uiBaseViewIndex ] );
     206        AOF( m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedOffset   () [ uiBaseViewIndex ] );
     207        AOF( m_aaiCodedScale [ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedScale () [ uiBaseViewIndex ] );
     208        AOF( m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedOffset() [ uiBaseViewIndex ] );
    222209      }
    223210    }
     
    232219      xOutput( m_iLastPOC );
    233220    }
    234     ::memset( m_aiViewReceived, 0x00, MAX_VIEW_NUM * sizeof( Int ) );
    235   }
    236 
    237   UInt uiViewId                 = pcSlice->getSPS()->getViewId();
    238   m_aiViewReceived[ uiViewId ]  = 1;
     221    ::memset( m_bViewReceived, false, MAX_NUM_LAYERS * sizeof( Bool ) );
     222  }
     223
     224  UInt uiViewIndex                       = pcSlice->getViewIndex();
     225  m_bViewReceived[ uiViewIndex ]         = true;
    239226  if( bFirstAU )
    240227  {
    241     m_uiMaxViewId                     = Max( m_uiMaxViewId, uiViewId );
    242     m_aiViewOrderIndex[ uiViewId ]    = pcSlice->getSPS()->getViewOrderIdx();
    243     if( uiViewId == 1 )
     228    m_uiMaxViewIndex                     = std::max( m_uiMaxViewIndex, uiViewIndex );
     229    m_aiViewId[ uiViewIndex ]            = pcSlice->getViewId();
     230    if( uiViewIndex == 1 )
    244231    {
    245232      m_uiCamParsCodedPrecision       = pcSlice->getSPS()->getCamParPrecision     ();
    246233      m_bCamParsVaryOverTime          = pcSlice->getSPS()->hasCamParInSliceHeader ();
    247234    }
    248     else if( uiViewId > 1 )
     235    else if( uiViewIndex > 1 )
    249236    {
    250237      AOF( m_uiCamParsCodedPrecision == pcSlice->getSPS()->getCamParPrecision     () );
    251238      AOF( m_bCamParsVaryOverTime    == pcSlice->getSPS()->hasCamParInSliceHeader () );
    252239    }
    253     for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
     240    for( UInt uiBaseIndex = 0; uiBaseIndex < uiViewIndex; uiBaseIndex++ )
    254241    {
    255242      if( m_bCamParsVaryOverTime )
    256243      {
    257         m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getCodedScale    () [ uiBaseId ];
    258         m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getCodedOffset   () [ uiBaseId ];
    259         m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
    260         m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
    261 #if MERL_VSP_C0152
    262         xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
    263         xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
    264 #endif
     244        m_aaiCodedScale [ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getCodedScale    () [ uiBaseIndex ];
     245        m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getCodedOffset   () [ uiBaseIndex ];
     246        m_aaiCodedScale [ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getInvCodedScale () [ uiBaseIndex ];
     247        m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getInvCodedOffset() [ uiBaseIndex ];
     248        xInitLUTs( uiBaseIndex, uiViewIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
     249        xInitLUTs( uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
    265250      }
    266251      else
    267252      {
    268         m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getSPS()->getCodedScale    () [ uiBaseId ];
    269         m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getSPS()->getCodedOffset   () [ uiBaseId ];
    270         m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedScale () [ uiBaseId ];
    271         m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedOffset() [ uiBaseId ];
    272 #if MERL_VSP_C0152
    273         xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
    274         xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
    275 #endif
     253        m_aaiCodedScale [ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getSPS()->getCodedScale    () [ uiBaseIndex ];
     254        m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getSPS()->getCodedOffset   () [ uiBaseIndex ];
     255        m_aaiCodedScale [ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getSPS()->getInvCodedScale () [ uiBaseIndex ];
     256        m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getSPS()->getInvCodedOffset() [ uiBaseIndex ];
     257        xInitLUTs( uiBaseIndex, uiViewIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
     258        xInitLUTs( uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
    276259      }
    277260    }
     
    279262  else
    280263  {
    281     AOF( m_aiViewOrderIndex[ uiViewId ] == pcSlice->getSPS()->getViewOrderIdx() );
     264    AOF( m_aiViewId[ uiViewIndex ] == pcSlice->getViewId() );
    282265    if( m_bCamParsVaryOverTime )
    283266    {
    284       for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
    285       {
    286         m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getCodedScale    () [ uiBaseId ];
    287         m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getCodedOffset   () [ uiBaseId ];
    288         m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
    289         m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
    290 #if MERL_VSP_C0152
    291         xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
    292         xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
    293 #endif
    294       }
    295     }
    296   }
    297   m_iLastViewId = (Int)pcSlice->getSPS()->getViewId();
    298   m_iLastPOC    = (Int)pcSlice->getPOC();
     267      for( UInt uiBaseIndex = 0; uiBaseIndex < uiViewIndex; uiBaseIndex++ )
     268      {
     269        m_aaiCodedScale [ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getCodedScale    () [ uiBaseIndex ];
     270        m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getCodedOffset   () [ uiBaseIndex ];
     271        m_aaiCodedScale [ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getInvCodedScale () [ uiBaseIndex ];
     272        m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getInvCodedOffset() [ uiBaseIndex ];
     273
     274        xInitLUTs( uiBaseIndex, uiViewIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
     275        xInitLUTs( uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
     276      }
     277    }
     278  }
     279 
     280  m_iLastViewIndex = (Int)pcSlice->getViewIndex(); 
     281  m_iLastPOC       = (Int)pcSlice->getPOC();
    299282}
    300283
     
    302285CamParsCollector::xIsComplete()
    303286{
    304   for( UInt uiView = 0; uiView <= m_uiMaxViewId; uiView++ )
    305   {
    306     if( m_aiViewReceived[ uiView ] == 0 )
     287  for( UInt uiView = 0; uiView <= m_uiMaxViewIndex; uiView++ )
     288  {
     289    if( m_bViewReceived[ uiView ] == 0 )
    307290    {
    308291      return false;
     
    319302    if( iPOC == 0 )
    320303    {
    321       fprintf( m_pCodedScaleOffsetFile, "#     ViewId ViewOrderIdx\n" );
     304      fprintf( m_pCodedScaleOffsetFile, "#  ViewIndex       ViewId\n" );
    322305      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
    323       for( UInt uiViewId = 0; uiViewId <= m_uiMaxViewId; uiViewId++ )
    324       {
    325         fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewId, m_aiViewOrderIndex[ uiViewId ] );
     306      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
     307      {
     308        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewIndex, m_aiViewId[ uiViewIndex ] );
    326309      }
    327310      fprintf( m_pCodedScaleOffsetFile, "\n\n");
     
    333316      Int iS = iPOC;
    334317      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
    335       for( UInt uiViewId = 0; uiViewId <= m_uiMaxViewId; uiViewId++ )
    336       {
    337         for( UInt uiBaseId = 0; uiBaseId <= m_uiMaxViewId; uiBaseId++ )
     318      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
     319      {
     320        for( UInt uiBaseIndex = 0; uiBaseIndex <= m_uiMaxViewIndex; uiBaseIndex++ )
    338321        {
    339           if( uiViewId != uiBaseId )
     322          if( uiViewIndex != uiBaseIndex )
    340323          {
    341324            fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
    342               iS, iE, uiViewId, uiBaseId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_uiCamParsCodedPrecision );
     325              iS, iE, uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_uiCamParsCodedPrecision );
    343326          }
    344327        }
     
    347330  }
    348331}
    349 
     332#endif
    350333TDecTop::TDecTop()
    351 : m_SEIs(0)
    352 , m_tAppDecTop( NULL )
    353 , m_nalUnitTypeBaseView( NAL_UNIT_INVALID )
    354334{
    355335  m_pcPic = 0;
    356   m_iGopSize      = 0;
    357   m_bGopSizeSet   = false;
    358336  m_iMaxRefPicNum = 0;
    359   m_uiValidPS = 0;
    360337#if ENC_DEC_TRACE
    361   if(!g_hTrace) g_hTrace = fopen( "TraceDec.txt", "wb" );
     338#if H_MV
     339  if ( g_hTrace == NULL )
     340  {
     341#endif
     342  g_hTrace = fopen( "TraceDec.txt", "wb" );
    362343  g_bJustDoIt = g_bEncDecTraceDisable;
    363344  g_nSymbolCounter = 0;
    364 #endif
    365   m_bRefreshPending = 0;
     345#if H_MV
     346  }
     347#endif
     348#endif
    366349  m_pocCRA = 0;
    367   m_pocRandomAccess = MAX_INT;         
     350  m_prevRAPisBLA = false;
     351  m_pocRandomAccess = MAX_INT; 
    368352  m_prevPOC                = MAX_INT;
    369353  m_bFirstSliceInPicture    = true;
    370354  m_bFirstSliceInSequence   = true;
     355#if H_MV
     356  m_layerId = 0;
     357  m_viewId = 0;
     358#if H_3D
     359  m_viewIndex = 0;
     360  m_isDepth = false;
    371361  m_pcCamParsCollector = 0;
    372 #if QC_MVHEVC_B0046
    373   m_bFirstNal                  = false;
     362#endif
    374363#endif
    375364}
     
    378367{
    379368#if ENC_DEC_TRACE
    380   if(g_hTrace) fclose( g_hTrace );
    381   g_hTrace=NULL;
     369  fclose( g_hTrace );
    382370#endif
    383371}
     
    387375  m_cGopDecoder.create();
    388376  m_apcSlicePilot = new TComSlice;
    389   m_uiSliceIdx = m_uiLastSliceIdx = 0;
     377  m_uiSliceIdx = 0;
    390378}
    391379
     
    398386 
    399387  m_cSliceDecoder.destroy();
    400   m_tAppDecTop = NULL;
    401 
    402 #if DEPTH_MAP_GENERATION
    403   m_cDepthMapGenerator.destroy();
    404 #endif
    405 #if H3D_IVRP & !QC_ARP_D0177
    406   m_cResidualGenerator.destroy();
    407 #endif
    408 
    409 }
    410 
    411 Void TDecTop::init( TAppDecTop* pcTAppDecTop, Bool bFirstInstance )
     388}
     389
     390Void TDecTop::init()
    412391{
    413392  // initialize ROM
    414   if( bFirstInstance )
    415   {
     393#if !H_MV
    416394  initROM();
    417   }
    418   m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO
    419 #if DEPTH_MAP_GENERATION
    420                     , &m_cDepthMapGenerator
    421 #endif
    422 #if H3D_IVRP & !QC_ARP_D0177
    423                     , &m_cResidualGenerator
    424 #endif
    425     );
     395#endif
     396  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO );
    426397  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
    427398  m_cEntropyDecoder.init(&m_cPrediction);
    428   m_tAppDecTop = pcTAppDecTop;
    429 #if DEPTH_MAP_GENERATION
    430 #if VIDYO_VPS_INTEGRATION
    431   m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getVPSAccess(), m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
    432 #else
    433   m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
    434 #endif
    435 #endif
    436 #if H3D_IVRP & !QC_ARP_D0177
    437   m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator );
    438 #endif
    439399}
    440400
     
    446406  for (Int i = 0; i < iSize; i++ )
    447407  {
    448     if( *iterPic )
    449     {
    450       TComPic* pcPic = *(iterPic++);
    451       pcPic->destroy();
     408    TComPic* pcPic = *(iterPic++);
     409#if H_MV
     410    if( pcPic )
     411    {
     412#endif
     413    pcPic->destroy();
    452414   
    453       delete pcPic;
    454       pcPic = NULL;
    455     }
    456   }
    457  
    458   // destroy ALF temporary buffers
    459   m_cAdaptiveLoopFilter.destroy();
    460 
     415    delete pcPic;
     416    pcPic = NULL;
     417#if H_MV
     418    }
     419#endif
     420  }
     421 
    461422  m_cSAO.destroy();
    462423 
    463424  m_cLoopFilter.        destroy();
    464425 
     426#if !H_MV
    465427  // destroy ROM
    466   if(m_viewId == 0 && m_isDepth == false)
    467   {
    468     destroyROM();
    469   }
    470 }
    471 
    472 #if H3D_IVRP
    473 Void
    474 TDecTop::deleteExtraPicBuffers( Int iPoc )
    475 {
    476   TComPic*                      pcPic = 0;
    477   TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
    478   TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
    479   for( ; cIter != cEnd; cIter++ )
    480   {
    481     if( (*cIter)->getPOC() == iPoc )
    482     {
    483       pcPic = *cIter;
    484       break;
    485     }
    486   }
    487   //AOF( pcPic );
    488   if ( pcPic )
    489   {
    490     pcPic->removeResidualBuffer   ();
    491   }
    492 }
    493 #endif
    494 
    495 
    496 Void
    497 TDecTop::compressMotion( Int iPoc )
    498 {
    499   TComPic*                      pcPic = 0;
    500   TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
    501   TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
    502   for( ; cIter != cEnd; cIter++ )
    503   {
    504     if( (*cIter)->getPOC() == iPoc )
    505     {
    506       pcPic = *cIter;
    507       break;
    508     }
    509   }
    510 //  AOF( pcPic );
    511   if ( pcPic )
    512   {
    513     pcPic->compressMotion();
    514   }
    515 }
    516 
    517 Void TDecTop::xUpdateGopSize (TComSlice* pcSlice)
    518 {
    519   if ( !pcSlice->isIntra() && !m_bGopSizeSet)
    520   {
    521     m_iGopSize    = pcSlice->getPOC();
    522     m_bGopSizeSet = true;
    523    
    524     m_cGopDecoder.setGopSize(m_iGopSize);
    525   }
     428  destroyROM();
     429#endif
    526430}
    527431
    528432Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
    529433{
    530   xUpdateGopSize(pcSlice);
    531  
    532   m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
    533 
    534 #if DEPTH_MAP_GENERATION
    535   UInt uiPdm                  = ( pcSlice->getSPS()->getViewId() ? pcSlice->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
    536   Bool bNeedPrdDepthMapBuffer = ( !pcSlice->getSPS()->isDepth() && uiPdm > 0 );
    537 #endif
    538 
     434  Int  numReorderPics[MAX_TLAYER];
     435  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
     436  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
     437
     438  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++)
     439  {
     440    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
     441  }
     442
     443  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
    539444  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
    540445  {
    541446    rpcPic = new TComPic();
    542447   
    543     rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
    544    
    545 #if DEPTH_MAP_GENERATION
    546     if( bNeedPrdDepthMapBuffer )
    547     {
    548       rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
    549     }
    550 #endif
    551    
     448    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
     449                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
     450    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
    552451    m_cListPic.pushBack( rpcPic );
    553452   
     
    584483    m_cListPic.pushBack( rpcPic );
    585484  }
    586   rpcPic->destroy(); 
    587   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
    588 #if DEPTH_MAP_GENERATION
    589   if( bNeedPrdDepthMapBuffer && !rpcPic->getPredDepthMap() )
    590   {
    591     rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
    592   }
    593 #endif
    594 }
    595 
    596 Void TDecTop::executeDeblockAndAlf(UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame, Int& iPOCLastDisplay)
     485  rpcPic->destroy();
     486  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
     487                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
     488  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
     489}
     490
     491#if H_MV
     492Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
     493#else
     494Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
     495#endif
    597496{
    598497  if (!m_pcPic)
     
    604503  TComPic*&   pcPic         = m_pcPic;
    605504
    606   // Execute Deblock and ALF only + Cleanup
    607 
    608   m_cGopDecoder.decompressGop(NULL, pcPic, true);
     505  // Execute Deblock + Cleanup
     506
     507  m_cGopDecoder.filterPicture(pcPic);
    609508
    610509  TComSlice::sortPicList( m_cListPic ); // sorting for application output
    611   ruiPOC              = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
     510  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
    612511  rpcListPic          = &m_cListPic; 
    613512  m_cCuDecoder.destroy();       
     513#if H_MV
     514  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer ); 
     515  TComSlice::markCurrPic( pcPic );
     516  TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc );
     517#endif
    614518  m_bFirstSliceInPicture  = true;
    615519
     
    624528  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
    625529  cFillSlice.initSlice();
    626   cFillSlice.initTiles();
    627530  TComPic *cFillPic;
    628531  xGetNewPicBuffer(&cFillSlice,cFillPic);
     
    630533  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
    631534  cFillPic->getSlice(0)->initSlice();
    632   cFillPic->getSlice(0)->initTiles();
    633 
    634  
    635535 
    636536  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
     
    674574{
    675575  m_parameterSetManagerDecoder.applyPrefetchedPS();
    676 
     576 
    677577  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
    678578  assert (pps != 0);
     
    680580  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
    681581  assert (sps != 0);
    682 #if VIDYO_VPS_INTEGRATION
    683   TComVPS *vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
    684   assert (vps != 0);
    685 #if !QC_REM_IDV_B0046
    686   if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )
    687 #else
    688   if( (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA) && !sps->getViewId() )
    689 #endif
    690     // VPS can only be activated on IDR or CRA...
    691     getTAppDecTop()->getVPSAccess()->setActiveVPSId( sps->getVPSId() );
    692 #endif
     582
     583  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
     584  {
     585    printf ("Parameter set activation failed!");
     586    assert (0);
     587  }
     588
     589  if( pps->getDependentSliceSegmentsEnabledFlag() )
     590  {
     591    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
     592
     593    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
     594    {
     595      m_cSliceDecoder.initCtxMem(NumCtx);
     596      for ( UInt st = 0; st < NumCtx; st++ )
     597      {
     598        TDecSbac* ctx = NULL;
     599        ctx = new TDecSbac;
     600        ctx->init( &m_cBinCABAC );
     601        m_cSliceDecoder.setCtxMem( ctx, st );
     602      }
     603    }
     604  }
     605
    693606  m_apcSlicePilot->setPPS(pps);
    694607  m_apcSlicePilot->setSPS(sps);
    695 #if QC_MVHEVC_B0046
    696   TComVPS *vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
    697 #endif
    698 #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
    699   m_apcSlicePilot->setVPS(vps);
     608#if H_MV
     609  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getActiveVPS() );
    700610#endif
    701611  pps->setSPS(sps);
    702 
    703   if(sps->getUseSAO() || sps->getUseALF()|| sps->getScalingListFlag() || sps->getUseDF())
    704   {
    705     m_apcSlicePilot->setAPS( m_parameterSetManagerDecoder.getAPS(m_apcSlicePilot->getAPSId())  );
    706   }
     612  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
    707613  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
    708614
    709   for (Int i = 0; i < sps->getMaxCUDepth() - 1; i++)
     615  g_bitDepthY     = sps->getBitDepthY();
     616  g_bitDepthC     = sps->getBitDepthC();
     617  g_uiMaxCUWidth  = sps->getMaxCUWidth();
     618  g_uiMaxCUHeight = sps->getMaxCUHeight();
     619  g_uiMaxCUDepth  = sps->getMaxCUDepth();
     620  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
     621
     622  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
    710623  {
    711624    sps->setAMPAcc( i, sps->getUseAMP() );
    712625  }
    713626
    714   for (Int i = sps->getMaxCUDepth() - 1; i < sps->getMaxCUDepth(); i++)
     627  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
    715628  {
    716629    sps->setAMPAcc( i, 0 );
    717630  }
    718631
    719   m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    720   m_cLoopFilter.        create( g_uiMaxCUDepth );
    721 }
    722 
     632  m_cSAO.destroy();
     633  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
     634  m_cLoopFilter.create( sps->getMaxCUDepth() );
     635}
     636
     637#if H_MV
     638Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag )
     639{
     640  assert( nalu.m_layerId == m_layerId );
     641
     642#else
    723643Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
    724644{
     645#endif
    725646  TComPic*&   pcPic         = m_pcPic;
    726647  m_apcSlicePilot->initSlice();
    727648
    728   //!!!KS: DIRTY HACK
    729   m_apcSlicePilot->setPPSId(0);
    730   m_apcSlicePilot->setPPS(m_parameterSetManagerDecoder.getPrefetchedPPS(0));
    731   m_apcSlicePilot->setSPS(m_parameterSetManagerDecoder.getPrefetchedSPS(0));
    732 #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
    733 #if QC_MVHEVC_B0046
    734   m_apcSlicePilot->setIsDepth(false);
    735 #endif
    736   m_apcSlicePilot->setVPS(m_parameterSetManagerDecoder.getPrefetchedVPS(0));
    737 #endif
    738   m_apcSlicePilot->initTiles();
    739 #if QC_MVHEVC_B0046
    740   m_apcSlicePilot->setViewId( nalu.m_layerId );
    741   m_apcSlicePilot->setViewId( nalu.m_layerId );
    742   m_apcSlicePilot->setViewOrderIdx(m_apcSlicePilot->getVPS()->getViewId(nalu.m_layerId), nalu.m_layerId);
    743   Int iNumDirectRef = m_apcSlicePilot->getVPS()->getNumDirectRefLayer(nalu.m_layerId);
    744   m_apcSlicePilot->getSPS()->setNumberOfUsableInterViewRefs(iNumDirectRef);
    745   for(Int iNumIvRef = 0; iNumIvRef < iNumDirectRef; iNumIvRef ++)
    746   {
    747     Int iDeltaLayerId = m_apcSlicePilot->getVPS()->getDirectRefLayerId( nalu.m_layerId, iNumIvRef);
    748     m_apcSlicePilot->getSPS()->setUsableInterViewRef(iNumIvRef, (iDeltaLayerId-nalu.m_layerId));
    749   }
    750 #endif
    751649  if (m_bFirstSliceInPicture)
    752650  {
    753651    m_uiSliceIdx     = 0;
    754     m_uiLastSliceIdx = 0;
    755652  }
    756653  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
     
    761658
    762659  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
    763   if( m_bFirstSliceInPicture )
    764   {
    765 #if QC_MVHEVC_B0046
    766     if( nalu.m_layerId == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
    767     else                     { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, 0 )->getNalUnitTypeBaseView(); }
    768 #else
    769 #if VIDYO_VPS_INTEGRATION
    770     if( m_apcSlicePilot->getVPS()->getViewId(nalu.m_layerId) == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
    771     else { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, m_apcSlicePilot->getVPS()->getDepthFlag(nalu.m_layerId) )->getNalUnitTypeBaseView(); }
    772 #else
    773     if( nalu.m_viewId == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
    774     else                     { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, nalu.m_isDepth )->getNalUnitTypeBaseView(); }
    775 #endif
    776 #endif
    777     m_apcSlicePilot->setNalUnitTypeBaseViewMvc( m_nalUnitTypeBaseView );
    778   }
    779 
    780   m_apcSlicePilot->setReferenced(nalu.m_nalRefFlag);
     660  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
     661                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
     662                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
     663                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
     664                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
     665  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
     666 
     667  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
    781668  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
    782669
    783   // ALF CU parameters should be part of the slice header -> needs to be fixed
    784 #if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
    785   m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet(),m_apcSlicePilot->getVPS()->getDepthFlag(nalu.m_layerId));
    786 #else
    787   m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet());
    788 #endif
    789   // byte align
    790   {
    791     Int numBitsForByteAlignment = nalu.m_Bitstream->getNumBitsUntilByteAligned();
    792     if ( numBitsForByteAlignment > 0 )
    793     {
    794       UInt bitsForByteAlignment;
    795       nalu.m_Bitstream->read( numBitsForByteAlignment, bitsForByteAlignment );
    796       assert( bitsForByteAlignment == ( ( 1 << numBitsForByteAlignment ) - 1 ) );
    797     }
    798   }
    799 
     670#if H_MV
     671  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer );
     672  m_apcSlicePilot->setLayerId( nalu.m_layerId );
     673#endif
     674  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
     675
     676#if H_MV 
     677  TComVPS* vps     = m_apcSlicePilot->getVPS();
     678  Int layerIdInVps = vps->getLayerIdInVps( nalu.m_layerId ); 
     679  setViewId   ( vps->getViewId   ( layerIdInVps )      ); 
     680#if H_3D
     681  setViewIndex( vps->getViewIndex( layerIdInVps )      ); 
     682  setIsDepth  ( vps->getDepthId  ( layerIdInVps ) == 1 ); 
     683  m_ivPicLists->setVPS( vps );
     684#endif
     685#endif
     686    // Skip pictures due to random access
     687    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
     688    {
     689      return false;
     690    }
     691    // Skip TFD pictures associated with BLA/BLANT pictures
     692    if (isSkipPictureForBLA(iPOCLastDisplay))
     693    {
     694      return false;
     695    }
     696
     697  //we should only get a different poc for a new picture (with CTU address==0)
     698  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
     699  {
     700    printf ("Warning, the first slice of a picture might have been lost!\n");
     701  }
    800702  // exit when a new picture is found
    801   if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence)
     703  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
    802704  {
    803705    if (m_prevPOC >= m_pocRandomAccess)
     
    808710    m_prevPOC = m_apcSlicePilot->getPOC();
    809711  }
     712#if H_MV
     713  if ( newLayerFlag )
     714  {
     715    return false;
     716  }
     717#if ENC_DEC_TRACE
     718#if H_MV_ENC_DEC_TRAC
     719  // parse remainder of SH
     720   g_disableHLSTrace = false;
     721#endif
     722#endif
     723#endif
    810724  // actual decoding starts here
    811725  xActivateParameterSets();
    812   m_apcSlicePilot->initTiles();
    813726
    814727  if (m_apcSlicePilot->isNextSlice())
     
    817730  }
    818731  m_bFirstSliceInSequence = false;
    819   if (m_apcSlicePilot->isNextSlice())
    820   {
    821     // Skip pictures due to random access
    822     if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
    823     {
    824       return false;
    825     }
    826   }
    827732  //detect lost reference picture and insert copy of earlier frame.
    828   while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess) > 0)
    829   {
    830     xCreateLostPicture(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), false)-1);
     733  Int lostPoc;
     734  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
     735  {
     736    xCreateLostPicture(lostPoc-1);
    831737  }
    832738  if (m_bFirstSliceInPicture)
     
    835741    m_cPrediction.initTempBuff();
    836742    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
     743#if H_MV
     744    m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer );
     745#endif
    837746    //  Get a new picture buffer
    838747    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
    839748
    840 #if INTER_VIEW_VECTOR_SCALING_C0115
    841     pcPic->setViewOrderIdx( m_apcSlicePilot->getVPS()->getViewOrderIdx(nalu.m_layerId) );    // will be changed to view_id
    842 #endif
    843     /* transfer any SEI messages that have been received to the picture */
     749    // transfer any SEI messages that have been received to the picture
    844750    pcPic->setSEIs(m_SEIs);
    845     m_SEIs = NULL;
     751    m_SEIs.clear();
    846752
    847753    // Recursive structure
     
    850756    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
    851757
    852     m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    853 #if DEPTH_MAP_GENERATION
    854     UInt uiPdm = ( m_apcSlicePilot->getSPS()->getViewId() ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
    855     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) );
    856     TComDepthMapGenerator* pcDMG0 = m_tAppDecTop->getDecTop0()->getDepthMapGenerator();
    857     if( m_apcSlicePilot->getSPS()->getViewId() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
    858     {
    859       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) );
    860     }
    861 #endif
    862 #if H3D_IVRP & !QC_ARP_D0177
    863     m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
    864 #endif
    865   }
    866 
     758    m_cSliceDecoder.create();
     759  }
     760  else
     761  {
     762    // Check if any new SEI has arrived
     763    if(!m_SEIs.empty())
     764    {
     765      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
     766      SEIMessages &picSEI = pcPic->getSEIs();
     767      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
     768      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
     769      deleteSEIs(m_SEIs);
     770    }
     771  }
     772 
    867773  //  Set picture slice pointer
    868774  TComSlice*  pcSlice = m_apcSlicePilot;
     
    873779  UInt i, j, p;
    874780
    875 
    876   if( pcSlice->getPPS()->getColumnRowInfoPresent() == 1 )
    877   {
    878     //set NumColumnsMins1 and NumRowsMinus1
    879     pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
    880     pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
    881 
    882     //create the TComTileArray
    883     pcPic->getPicSym()->xCreateTComTileArray();
    884 
    885     if( pcSlice->getPPS()->getUniformSpacingIdr() == 1)
    886     {
    887       //set the width for each tile
    888       for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
    889       {
    890         for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
    891         {
    892           pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
    893             setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1)
    894             - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
    895         }
    896       }
    897 
    898       //set the height for each tile
    899       for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
    900       {
    901         for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
    902         {
    903           pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
    904             setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1)
    905             - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
    906         }
    907       }
    908     }
    909     else
    910     {
    911       //set the width for each tile
    912       for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
    913       {
    914         uiCummulativeTileWidth = 0;
    915         for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
    916         {
    917           pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
    918           uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
    919         }
    920         pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
    921       }
    922 
    923       //set the height for each tile
    924       for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
    925       {
    926         uiCummulativeTileHeight = 0;
    927         for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
    928         {
    929           pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
    930           uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
    931         }
    932         pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
     781  //set NumColumnsMins1 and NumRowsMinus1
     782  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
     783  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
     784
     785  //create the TComTileArray
     786  pcPic->getPicSym()->xCreateTComTileArray();
     787
     788  if( pcSlice->getPPS()->getUniformSpacingFlag() )
     789  {
     790    //set the width for each tile
     791    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
     792    {
     793      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
     794      {
     795        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
     796          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1)
     797          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
     798      }
     799    }
     800
     801    //set the height for each tile
     802    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
     803    {
     804      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
     805      {
     806        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
     807          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1)
     808          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
    933809      }
    934810    }
     
    936812  else
    937813  {
    938     //set NumColumnsMins1 and NumRowsMinus1
    939     pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getSPS()->getNumColumnsMinus1() );
    940     pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getSPS()->getNumRowsMinus1() );
    941 
    942     //create the TComTileArray
    943     pcPic->getPicSym()->xCreateTComTileArray();
    944 
    945     //automatically set the column and row boundary if UniformSpacingIdr = 1
    946     if( pcSlice->getSPS()->getUniformSpacingIdr() == 1 )
    947     {
    948       //set the width for each tile
    949       for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
    950       {
    951         for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
    952         {
    953           pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
    954             setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1)
    955             - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
    956         }
    957       }
    958 
    959       //set the height for each tile
    960       for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
    961       {
    962         for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
    963         {
    964           pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
    965             setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1)
    966             - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
    967         }
    968       }
    969     }
    970     else
    971     {
    972       //set the width for each tile
    973       for(j=0; j < pcSlice->getSPS()->getNumRowsMinus1()+1; j++)
    974       {
    975         uiCummulativeTileWidth = 0;
    976         for(i=0; i < pcSlice->getSPS()->getNumColumnsMinus1(); i++)
    977         {
    978           pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getSPS()->getColumnWidth(i) );
    979           uiCummulativeTileWidth += pcSlice->getSPS()->getColumnWidth(i);
    980         }
    981         pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
    982       }
    983 
    984       //set the height for each tile
    985       for(j=0; j < pcSlice->getSPS()->getNumColumnsMinus1()+1; j++)
    986       {
    987         uiCummulativeTileHeight = 0;
    988         for(i=0; i < pcSlice->getSPS()->getNumRowsMinus1(); i++)
    989         {
    990           pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getSPS()->getRowHeight(i) );
    991           uiCummulativeTileHeight += pcSlice->getSPS()->getRowHeight(i);
    992         }
    993         pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
    994       }
     814    //set the width for each tile
     815    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
     816    {
     817      uiCummulativeTileWidth = 0;
     818      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
     819      {
     820        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
     821        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
     822      }
     823      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
     824    }
     825
     826    //set the height for each tile
     827    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
     828    {
     829      uiCummulativeTileHeight = 0;
     830      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
     831      {
     832        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
     833        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
     834      }
     835      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
    995836    }
    996837  }
     
    1008849  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
    1009850
    1010   //convert the start and end CU addresses of the slice and entropy slice into encoding order
    1011   pcSlice->setEntropySliceCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurStartCUAddr()) );
    1012   pcSlice->setEntropySliceCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurEndCUAddr()) );
     851  //convert the start and end CU addresses of the slice and dependent slice into encoding order
     852  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
     853  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
    1013854  if(pcSlice->isNextSlice())
    1014855  {
     
    1034875  pcPic->setTLayer(nalu.m_temporalId);
    1035876
     877#if H_MV
     878  pcPic->setLayerId( nalu.m_layerId );
     879  pcPic->setViewId ( getViewId() );
     880#if H_3D
     881  pcPic->setViewIndex( getViewIndex() );
     882  pcPic->setIsDepth  ( getIsDepth  () );
     883#endif
     884#endif
    1036885  if (bNextSlice)
    1037886  {
    1038     pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_cListPic);
    1039 
    1040     if ( !pcSlice->getPPS()->getEnableTMVPFlag() && pcPic->getTLayer() == 0 )
    1041     {
    1042       pcSlice->decodingMarkingForNoTMVP( m_cListPic, pcSlice->getPOC() );
    1043     }
    1044 
    1045     // Set reference list
    1046 #if !QC_MVHEVC_B0046
    1047 #if VIDYO_VPS_INTEGRATION
    1048     pcSlice->setViewId( pcSlice->getVPS()->getViewId(nalu.m_layerId) );
    1049     pcSlice->setIsDepth( pcSlice->getVPS()->getDepthFlag(nalu.m_layerId) );
     887    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
     888    // Set reference list
     889#if H_MV   
     890    pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true );   
     891#if H_3D_ARP
     892    pcSlice->setARPStepNum();
     893    if( pcSlice->getARPStepNum() > 1 )
     894    {
     895      for(Int iLayerId = 0; iLayerId < nalu.m_layerId; iLayerId ++ )
     896      {
     897        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
     898        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
     899        if( iViewIdx<getViewIndex() && !bIsDepth )
     900        {
     901          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
     902        }
     903      }
     904    }
     905#endif
    1050906#else
    1051     pcSlice->setViewId(m_viewId);
    1052     pcSlice->setIsDepth(m_isDepth);
    1053 #endif
    1054 #endif
    1055 
    1056 #if INTER_VIEW_VECTOR_SCALING_C0115
    1057 #if VIDYO_VPS_INTEGRATION
    1058     pcSlice->setViewOrderIdx( pcSlice->getVPS()->getViewOrderIdx(nalu.m_layerId) );        // will be changed to view_id
     907#if FIX1071
     908    pcSlice->setRefPicList( m_cListPic, true );
    1059909#else
    1060     pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
    1061 #endif
    1062 #endif
    1063 
    1064 #if INTER_VIEW_VECTOR_SCALING_C0115
    1065     pcSlice->setIVScalingFlag( pcSlice->getVPS()->getIVScalingFlag());
    1066 #endif
    1067 
    1068     assert( m_tAppDecTop != NULL );
    1069     TComPic * const pcTexturePic = m_isDepth ? m_tAppDecTop->getPicFromView(  m_viewId, pcSlice->getPOC(), false ) : NULL;
    1070 
    1071 #if FLEX_CODING_ORDER_M23723
    1072     if (pcTexturePic != NULL)
    1073     {
    1074       assert( !m_isDepth || pcTexturePic != NULL );
    1075       pcSlice->setTexturePic( pcTexturePic );
    1076     }
    1077 #else
    1078     assert( !m_isDepth || pcTexturePic != NULL );
    1079     pcSlice->setTexturePic( pcTexturePic );
    1080 #endif
    1081 
    1082 
    1083     std::vector<TComPic*> apcInterViewRefPics = m_tAppDecTop->getInterViewRefPics( m_viewId, pcSlice->getPOC(), m_isDepth, pcSlice->getSPS() );
    1084     pcSlice->setRefPicListMvc( m_cListPic, apcInterViewRefPics );
    1085 #if QC_ARP_D0177
    1086     //pcSlice->setBaseViewRefPicList( m_tAppDecTop->getTDecTop( 0 , false )->getListPic() );
    1087     pcSlice->setARPStepNum();
    1088     if(pcSlice->getARPStepNum() > 1)
    1089     {
    1090       for(Int iViewIdx = 0; iViewIdx < pcSlice->getViewId(); iViewIdx ++ )
    1091         pcSlice->setBaseViewRefPicList( m_tAppDecTop->getTDecTop( iViewIdx, false )->getListPic(), iViewIdx );
    1092     }
     910    pcSlice->setRefPicList( m_cListPic );
     911#endif
     912
     913#endif
     914
     915#if H_3D
     916    pcSlice->setIvPicLists( m_ivPicLists );         
     917#if H_3D_IV_MERGE   
     918    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
     919#endif   
    1093920#endif
    1094921    // For generalized B
     
    1104931      }
    1105932    }
    1106     if (pcSlice->isInterB())
     933    if (!pcSlice->isIntra())
    1107934    {
    1108935      Bool bLowDelay = true;
     
    1117944        }
    1118945      }
    1119       for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
    1120       {
    1121         if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
     946      if (pcSlice->isInterB())
     947      {
     948        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
    1122949        {
    1123           bLowDelay = false;
    1124         }
     950          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
     951          {
     952            bLowDelay = false;
     953          }
     954        }       
    1125955      }
    1126956
     
    1129959
    1130960    //---------------
    1131     pcSlice->setRefPOCnViewListsMvc();
    1132 
    1133     if(!pcSlice->getRefPicListModificationFlagLC())
    1134     {
    1135       pcSlice->generateCombinedList();
    1136     }
    1137 
    1138 #if !FIX_LGE_WP_FOR_3D_C0223
    1139     if( pcSlice->getRefPicListCombinationFlag() && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE )
    1140     {
    1141       pcSlice->setWpParamforLC();
    1142     }
    1143 #endif
    1144     pcSlice->setNoBackPredFlag( false );
    1145     if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
    1146     {
    1147       if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
    1148       {
    1149         pcSlice->setNoBackPredFlag( true );
    1150         for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
    1151         {
    1152           if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) )
    1153           {
    1154             pcSlice->setNoBackPredFlag( false );
    1155             break;
    1156           }
    1157         }
    1158       }
    1159     }
     961    pcSlice->setRefPOCList();
     962#if  H_3D_TMVP
     963    if(pcSlice->getLayerId())
     964      pcSlice->generateAlterRefforTMVP();
     965#endif
    1160966  }
    1161967
     
    1163969  if(pcSlice->getSPS()->getScalingListFlag())
    1164970  {
    1165     if(pcSlice->getAPS()->getScalingListEnabled())
    1166     {
    1167       pcSlice->setScalingList ( pcSlice->getAPS()->getScalingList()  );
    1168       if(pcSlice->getScalingList()->getScalingListPresentFlag())
    1169       {
    1170         pcSlice->setDefaultScalingList();
    1171       }
    1172       m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
    1173     }
     971    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
     972    if(pcSlice->getPPS()->getScalingListPresentFlag())
     973    {
     974      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
     975    }
     976    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
     977    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
     978    {
     979      pcSlice->setDefaultScalingList();
     980    }
     981    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
    1174982    m_cTrQuant.setUseScalingList(true);
    1175983  }
     
    1180988  }
    1181989
    1182 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    1183   if( m_parameterSetManagerDecoder.getPrefetchedSPS(0)->getUseDMM() && g_aacWedgeLists.empty() )
    1184   {
    1185     initWedgeLists();
    1186   }
    1187 #endif
    1188 
    1189 #if FCO_DVP_REFINE_C0132_C0170
    1190   if(m_bFirstSliceInPicture)
    1191   {
    1192     pcPic->setDepthCoded(false);
    1193 
    1194     if(m_viewId != 0)
    1195     {
    1196       if( m_isDepth == 0)
    1197       {
    1198         TComPic * recDepthMapBuffer;
    1199         recDepthMapBuffer = m_tAppDecTop->getPicFromView( m_viewId, pcSlice->getPOC(), true );
    1200         pcPic->setRecDepthMap(recDepthMapBuffer);
    1201 
    1202         if(recDepthMapBuffer != NULL)
    1203         {
    1204           pcPic->setDepthCoded(true);
    1205         }
    1206       }
    1207     }
    1208   }
    1209 #endif
    1210 
    1211 
    1212 #if MERL_VSP_C0152 // set BW LUT
    1213   if( m_pcCamParsCollector ) // Initialize the LUT elements
     990  //  Decode a picture
     991  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
     992#if H_3D
     993  if( m_pcCamParsCollector )
    1214994  {
    1215995    m_pcCamParsCollector->setSlice( pcSlice );
    1216996  }
    1217   if( pcSlice->getViewId() !=0 )
    1218   {
    1219     TComPic* pcBaseTxtPic = m_tAppDecTop->getPicFromView(  0, pcSlice->getPOC(), false );  // get base view reconstructed texture
    1220     TComPic* pcBaseDepthPic = m_tAppDecTop->getPicFromView(  0, pcSlice->getPOC(), true ); // get base view reconstructed depth
    1221      pcSlice->setRefPicBaseTxt(pcBaseTxtPic);
    1222      pcSlice->setRefPicBaseDepth(pcBaseDepthPic);
    1223   }
    1224 #if !MERL_VSP_NBDV_RefVId_Fix_D0166
    1225   getTAppDecTop()->setBWVSPLUT( pcSlice, pcSlice->getViewId(),  pcSlice->getPOC() ); // get the LUT for backward warping
    1226 #else
    1227   if (pcSlice->getViewId() != 0)
    1228   {
    1229     Bool isDepth = true;
    1230     for(Int refviewId = 0; refviewId < (pcSlice->getViewId()); refviewId++)
    1231     {
    1232       if (m_tAppDecTop->getTDecTop( refviewId, isDepth ))
    1233       {
    1234         pcSlice->setListDepthPic(m_tAppDecTop->getTDecTop( refviewId, isDepth )->getListPic(), refviewId); // The list will store only the depth pictures
    1235       }
    1236       getTAppDecTop()->setBWVSPLUT( refviewId, pcSlice, pcSlice->getViewId(),  pcSlice->getPOC() ); // get the LUT for backward warping
    1237     }
    1238   }
    1239 #endif
    1240 #endif
    1241 
    1242   //  Decode a picture
    1243   m_cGopDecoder.decompressGop(nalu.m_Bitstream, pcPic, false);
    1244 
    1245 #if QC_IV_AS_LT_B0046
    1246   std::vector<TComPic*> apcInterViewRefPics = m_tAppDecTop->getInterViewRefPics( m_viewId, pcSlice->getPOC(), m_isDepth, pcSlice->getSPS() );
    1247   for( Int k = 0; k < apcInterViewRefPics.size(); k++ )
    1248   {
    1249     TComPic*  pcPicIv = apcInterViewRefPics[k];
    1250     pcPicIv->setIsLongTerm( 0 );
    1251   }
    1252 #endif
    1253   if( m_pcCamParsCollector )
    1254   {
    1255     m_pcCamParsCollector->setSlice( pcSlice );
    1256   }
    1257 
     997#endif
    1258998  m_bFirstSliceInPicture = false;
    1259999  m_uiSliceIdx++;
     
    12621002}
    12631003
    1264 #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
    12651004Void TDecTop::xDecodeVPS()
    12661005{
     
    12691008  m_cEntropyDecoder.decodeVPS( vps );
    12701009  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
    1271 #if !QC_MVHEVC_B0046
    1272   getTAppDecTop()->getVPSAccess()->addVPS( vps );
    1273 #endif
    1274 }
    1275 #endif
     1010}
    12761011
    12771012Void TDecTop::xDecodeSPS()
    12781013{
    12791014  TComSPS* sps = new TComSPS();
    1280   TComRPSList* rps = new TComRPSList();
    1281   sps->setRPSList(rps);
    1282 #if HHI_MPI || H3D_QTL
    1283   m_cEntropyDecoder.decodeSPS( sps, m_isDepth );
     1015#if H_MV
     1016  sps->setLayerId( getLayerId() );
     1017#endif
     1018#if H_3D
     1019  // Preliminary fix. assuming that all sps refer to the same SPS.
     1020  // Parsing dependency should be resolved!
     1021  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 );
     1022  assert( vps != 0 );
     1023  Int layerIdInVPS = vps->getLayerIdInVps( m_layerId );
     1024  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( layerIdInVPS ), ( vps->getDepthId( layerIdInVPS ) == 1 ) );
    12841025#else
    12851026  m_cEntropyDecoder.decodeSPS( sps );
    12861027#endif
    12871028  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
    1288   m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    12891029}
    12901030
     
    12921032{
    12931033  TComPPS* pps = new TComPPS();
    1294   m_cEntropyDecoder.decodePPS( pps, &m_parameterSetManagerDecoder );
     1034  m_cEntropyDecoder.decodePPS( pps );
    12951035  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
    1296 
    1297   //!!!KS: Activate parameter sets for parsing APS (unless dependency is resolved)
    1298   m_apcSlicePilot->setPPSId(pps->getPPSId());
    1299   xActivateParameterSets();
    1300   m_apcSlicePilot->initTiles();
    1301 }
    1302 
    1303 Void TDecTop::xDecodeAPS()
    1304 {
    1305   TComAPS  *aps = new TComAPS();
    1306   allocAPS (aps);
    1307   decodeAPS(aps);
    1308   m_parameterSetManagerDecoder.storePrefetchedAPS(aps);
    1309 }
    1310 
    1311 Void TDecTop::xDecodeSEI()
    1312 {
    1313   m_SEIs = new SEImessages;
    1314   m_cEntropyDecoder.decodeSEI(*m_SEIs);
    1315 }
    1316 
     1036}
     1037
     1038Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
     1039{
     1040  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
     1041  {
     1042    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
     1043  }
     1044  else
     1045  {
     1046    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
     1047    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
     1048    if (activeParamSets.size()>0)
     1049    {
     1050      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
     1051      m_parameterSetManagerDecoder.applyPrefetchedPS();
     1052      assert(seiAps->activeSeqParamSetId.size()>0);
     1053      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
     1054      {
     1055        printf ("Warning SPS activation with Active parameter set SEI failed");
     1056      }
     1057    }
     1058  }
     1059}
     1060
     1061#if H_MV
     1062Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag)
     1063#else
    13171064Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
     1065#endif
    13181066{
    13191067  // Initialize entropy decoder
     
    13231071  switch (nalu.m_nalUnitType)
    13241072  {
    1325 #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
    13261073    case NAL_UNIT_VPS:
    13271074      xDecodeVPS();
    13281075      return false;
    1329 #endif
     1076     
    13301077    case NAL_UNIT_SPS:
    13311078      xDecodeSPS();
     
    13351082      xDecodePPS();
    13361083      return false;
    1337     case NAL_UNIT_APS:
    1338       xDecodeAPS();
     1084     
     1085    case NAL_UNIT_PREFIX_SEI:
     1086    case NAL_UNIT_SUFFIX_SEI:
     1087      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
    13391088      return false;
    13401089
    1341     case NAL_UNIT_SEI:
    1342       xDecodeSEI();
    1343       return false;
    1344 
    1345     case NAL_UNIT_CODED_SLICE:
    1346     case NAL_UNIT_CODED_SLICE_IDR:
    1347 #if !QC_REM_IDV_B0046
    1348     case NAL_UNIT_CODED_SLICE_IDV:
    1349 #endif
     1090    case NAL_UNIT_CODED_SLICE_TRAIL_R:
     1091    case NAL_UNIT_CODED_SLICE_TRAIL_N:
     1092    case NAL_UNIT_CODED_SLICE_TLA_R:
     1093    case NAL_UNIT_CODED_SLICE_TSA_N:
     1094    case NAL_UNIT_CODED_SLICE_STSA_R:
     1095    case NAL_UNIT_CODED_SLICE_STSA_N:
     1096    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
     1097    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
     1098    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
     1099    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
     1100    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
    13501101    case NAL_UNIT_CODED_SLICE_CRA:
    1351     case NAL_UNIT_CODED_SLICE_TLA:
     1102    case NAL_UNIT_CODED_SLICE_RADL_N:
     1103    case NAL_UNIT_CODED_SLICE_RADL_R:
     1104    case NAL_UNIT_CODED_SLICE_RASL_N:
     1105    case NAL_UNIT_CODED_SLICE_RASL_R:
     1106#if H_MV
     1107      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag);
     1108#else
    13521109      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
     1110#endif
    13531111      break;
    13541112    default:
     
    13591117}
    13601118
    1361 #if QC_MVHEVC_B0046
    1362 Void TDecTop::xCopyVPS( TComVPS* pVPSV0 )
    1363 {
    1364   m_parameterSetManagerDecoder.storePrefetchedVPS(pVPSV0); 
    1365 }
    1366 
    1367 Void TDecTop::xCopySPS( TComSPS* pSPSV0 )
    1368 {
    1369   TComSPS* sps = new TComSPS();
    1370   sps = pSPSV0;
    1371   m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
    1372   m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    1373 }
    1374 
    1375 Void TDecTop::xCopyPPS(TComPPS* pPPSV0 )
    1376 {
    1377   m_parameterSetManagerDecoder.storePrefetchedPPS( pPPSV0 );
    1378 
    1379   //!!!KS: Activate parameter sets for parsing APS (unless dependency is resolved)
    1380   m_apcSlicePilot->setPPSId(pPPSV0->getPPSId());
    1381   xActivateParameterSets();
    1382   m_apcSlicePilot->initTiles();
    1383 }
    1384 #endif
     1119/** Function for checking if picture should be skipped because of association with a previous BLA picture
     1120 * \param iPOCLastDisplay POC of last picture displayed
     1121 * \returns true if the picture should be skipped
     1122 * This function skips all TFD pictures that follow a BLA picture
     1123 * in decoding order and precede it in output order.
     1124 */
     1125Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
     1126{
     1127  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))
     1128  {
     1129    iPOCLastDisplay++;
     1130    return true;
     1131  }
     1132  return false;
     1133}
     1134
    13851135/** Function for checking if picture should be skipped because of random access
    13861136 * \param iSkipFrame skip frame counter
     
    13901140 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
    13911141 * It also checks the type of Nal unit type at the random access point.
    1392  * If the random access point is CRA, pictures with POC equal to or greater than the CRA POC are decoded.
     1142 * 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.
    13931143 * If the random access point is IDR all pictures after the random access point are decoded.
    1394  * If the random access point is not IDR or CRA, a warning is issues, and decoding of pictures with POC
    1395  * equal to or greater than the random access point POC is attempted. For non IDR/CRA random
     1144 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
     1145 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
    13961146 * access point there is no guarantee that the decoder will not crash.
    13971147 */
     
    14051155  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
    14061156  {
    1407     if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CRA )
    1408     {
    1409       m_pocRandomAccess = m_apcSlicePilot->getPOC(); // set the POC random access since we need to skip the reordered pictures in CRA.
    1410     }
    1411     else if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_IDR )
    1412     {
    1413       m_pocRandomAccess = 0; // no need to skip the reordered pictures in IDR, they are decodable.
     1157    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
     1158        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     1159        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
     1160        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
     1161    {
     1162      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
     1163      m_pocRandomAccess = m_apcSlicePilot->getPOC();
     1164    }
     1165    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
     1166    {
     1167      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
    14141168    }
    14151169    else
    14161170    {
    1417       static bool warningMessage = false;
     1171      static Bool warningMessage = false;
    14181172      if(!warningMessage)
    14191173      {
     
    14241178    }
    14251179  }
    1426   else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess)  // skip the reordered pictures if necessary
     1180  // skip the reordered pictures, if necessary
     1181  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))
    14271182  {
    14281183    iPOCLastDisplay++;
     
    14331188}
    14341189
    1435 Void TDecTop::allocAPS (TComAPS* pAPS)
    1436 {
    1437   // we don't know the SPS before it has been activated. These fields could exist
    1438   // depending on the corresponding flags in the APS, but SAO/ALF allocation functions will
    1439   // have to be moved for that
    1440   pAPS->createScalingList();
    1441   pAPS->createSaoParam();
    1442   m_cSAO.allocSaoParam(pAPS->getSaoParam());
    1443   pAPS->createAlfParam();
    1444 }
    1445 
     1190#if H_MV
     1191TComPic* TDecTop::getPic( Int poc )
     1192{
     1193  xGetPic( m_layerId, poc );
     1194  TComList<TComPic*>* listPic = getListPic();
     1195  TComPic* pcPic = NULL;
     1196  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
     1197  {
     1198    if( (*it)->getPOC() == poc )
     1199    {
     1200      pcPic = *it ;
     1201      break ;
     1202    }
     1203  }
     1204  return pcPic;
     1205}
     1206
     1207TComPic* TDecTop::xGetPic( Int layerId, Int poc )
     1208{
     1209  return m_ivPicLists->getPic( layerId, poc ) ;
     1210}
     1211
     1212#endif
    14461213//! \}
Note: See TracChangeset for help on using the changeset viewer.