Index: branches/HM-10.0-dev-SHM/source/App/TAppDecoder/TAppDecCfg.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 54)
@@ -41,4 +41,7 @@
 #include "TAppDecCfg.h"
 #include "TAppCommon/program_options_lite.h"
+#if SVC_EXTENSION
+#include <cassert>
+#endif
 
 #ifdef WIN32
@@ -63,5 +66,16 @@
   Bool do_help = false;
   string cfg_BitstreamFile;
+#if SVC_EXTENSION
+  string cfg_ReconFile [MAX_LAYERS];
+  Int nLayerNum;
+#if AVC_BASE
+  string cfg_BLReconFile;
+#endif
+#else
   string cfg_ReconFile;
+#endif
+#if AVC_SYNTAX || SYNTAX_OUTPUT
+  string cfg_BLSyntaxFile;
+#endif
   string cfg_TargetDecLayerIdSetFile;
 
@@ -70,9 +84,31 @@
   ("help", do_help, false, "this help text")
   ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream input file name")
+#if SVC_EXTENSION
+  ("ReconFileL%d,-o%d",   cfg_ReconFile,   string(""), MAX_LAYERS, "Layer %d reconstructed YUV output file name\n"
+                                                     "YUV writing is skipped if omitted")
+#if AVC_BASE
+  ("BLReconFile,-ibl",    cfg_BLReconFile,  string(""), "BL reconstructed YUV input file name")
+  ("BLSourceWidth,-wdt",    m_iBLSourceWidth,        0, "BL source picture width")
+  ("BLSourceHeight,-hgt",   m_iBLSourceHeight,       0, "BL source picture height")
+#if AVC_SYNTAX
+  ("BLSyntaxFile,-ibs",    cfg_BLSyntaxFile,  string(""), "BL syntax input file name")  
+#endif
+#endif
+#else
   ("ReconFile,o",     cfg_ReconFile,     string(""), "reconstructed YUV output file name\n"
                                                      "YUV writing is skipped if omitted")
+#endif
+#if SYNTAX_OUTPUT
+  ("BLSyntaxFile,-ibs",    cfg_BLSyntaxFile,  string(""), "BL syntax input file name")
+  ("BLSourceWidth,-wdt",    m_iBLSourceWidth,        0, "BL source picture width")
+  ("BLSourceHeight,-hgt",   m_iBLSourceHeight,       0, "BL source picture height")
+  ("BLFrames,-fr",          m_iBLFrames,       0, "BL number of frames")
+#endif
   ("SkipFrames,s", m_iSkipFrame, 0, "number of frames to skip before random access")
   ("OutputBitDepth,d", m_outputBitDepthY, 0, "bit depth of YUV output luma component (default: use 0 for native depth)")
   ("OutputBitDepthC,d", m_outputBitDepthC, 0, "bit depth of YUV output chroma component (default: use 0 for native depth)")
+#if SVC_EXTENSION
+  ("LayerNum,-ls", nLayerNum, 1, "Number of layers to be decoded.")
+#endif 
   ("MaxTemporalLayer,t", m_iMaxTemporalLayer, -1, "Maximum Temporal Layer to be decoded. -1 to decode all layers")
   ("SEIDecodedPictureHash", m_decodedPictureHashSEIEnabled, 1, "Control handling of decoded picture hash SEI messages\n"
@@ -99,5 +135,20 @@
   /* convert std::string to c string for compatability */
   m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
+#if SVC_EXTENSION
+  m_tgtLayerId = nLayerNum - 1;
+  assert( m_tgtLayerId >= 0 );
+  for(UInt layer=0; layer<= m_tgtLayerId; layer++)
+  {
+    m_pchReconFile[layer] = cfg_ReconFile[layer].empty() ? NULL : strdup(cfg_ReconFile[layer].c_str());
+  }
+#if AVC_BASE
+  m_pchBLReconFile = cfg_BLReconFile.empty() ? NULL : strdup(cfg_BLReconFile.c_str());
+#endif
+#else
   m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
+#endif
+#if AVC_SYNTAX || SYNTAX_OUTPUT
+  m_pchBLSyntaxFile = cfg_BLSyntaxFile.empty() ? NULL : strdup(cfg_BLSyntaxFile.c_str());
+#endif
 
   if (!m_pchBitstreamFile)
Index: branches/HM-10.0-dev-SHM/source/App/TAppDecoder/TAppDecCfg.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppDecoder/TAppDecCfg.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/App/TAppDecoder/TAppDecCfg.h	(revision 54)
@@ -58,5 +58,23 @@
 protected:
   Char*         m_pchBitstreamFile;                   ///< input bitstream file name
+#if SVC_EXTENSION
+  Char*         m_pchReconFile [MAX_LAYERS];          ///< output reconstruction file name
+#if AVC_BASE
+  Char*         m_pchBLReconFile;                     ///< input BL reconstruction file name
+  Int           m_iBLSourceWidth;
+  Int           m_iBLSourceHeight;
+#if AVC_SYNTAX
+  Char*         m_pchBLSyntaxFile;                     ///< input BL syntax file name  
+#endif
+#endif
+#else
   Char*         m_pchReconFile;                       ///< output reconstruction file name
+#endif
+#if SYNTAX_OUTPUT
+  Char*         m_pchBLSyntaxFile;                     ///< input BL syntax file name
+  Int           m_iBLSourceWidth;
+  Int           m_iBLSourceHeight;
+  Int           m_iBLFrames;
+#endif
   Int           m_iSkipFrame;                         ///< counter for frames prior to the random access point to skip
   Int           m_outputBitDepthY;                     ///< bit depth used for writing output (luma)
@@ -66,4 +84,7 @@
   Int           m_decodedPictureHashSEIEnabled;       ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message
 
+#if SVC_EXTENSION
+  Int           m_tgtLayerId;                        ///< target layer ID
+#endif
   std::vector<Int> m_targetDecLayerIdSet;             ///< set of LayerIds to be included in the sub-bitstream extraction process.
   Int           m_respectDefDispWindow;               ///< Only output content inside the default display window 
@@ -72,5 +93,9 @@
   TAppDecCfg()
   : m_pchBitstreamFile(NULL)
+#if SVC_EXTENSION
+  , m_tgtLayerId(0)
+#else
   , m_pchReconFile(NULL) 
+#endif
   , m_iSkipFrame(0)
   , m_outputBitDepthY(0)
@@ -79,4 +104,13 @@
   , m_decodedPictureHashSEIEnabled(0)
   , m_respectDefDispWindow(0)
+#if AVC_BASE
+  , m_iBLSourceWidth(0)
+  , m_iBLSourceHeight(0)
+#endif
+#if SYNTAX_OUTPUT
+  , m_iBLSourceWidth(0)
+  , m_iBLSourceHeight(0)
+  , m_iBLFrames(0)
+#endif
   {}
   virtual ~TAppDecCfg() {}
Index: branches/HM-10.0-dev-SHM/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppDecoder/TAppDecTop.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/App/TAppDecoder/TAppDecTop.cpp	(revision 54)
@@ -53,4 +53,15 @@
 // ====================================================================================================================
 
+#if SVC_EXTENSION
+TAppDecTop::TAppDecTop()
+{
+  ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag));
+  for(UInt layer=0; layer < MAX_LAYERS; layer++)
+  {
+    m_aiPOCLastDisplay[layer]  = -MAX_INT;
+    m_apcTDecTop[layer] = &m_acTDecTop[layer];
+  }
+}
+#else
 TAppDecTop::TAppDecTop()
 : m_iPOCLastDisplay(-MAX_INT)
@@ -58,4 +69,5 @@
   ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag));
 }
+#endif
 
 Void TAppDecTop::create()
@@ -70,4 +82,21 @@
     m_pchBitstreamFile = NULL;
   }
+#if SVC_EXTENSION   
+  for( Int i = 0; i < m_tgtLayerId; i++ )
+  {
+    if( m_pchReconFile[i] )
+    {
+      free ( m_pchReconFile[i] );
+      m_pchReconFile[i] = NULL;
+    }
+  }  
+#if AVC_BASE
+  if( m_pchBLReconFile )
+  {
+    free ( m_pchBLReconFile );
+    m_pchBLReconFile = NULL;
+  }
+#endif
+#else
   if (m_pchReconFile)
   {
@@ -75,4 +104,12 @@
     m_pchReconFile = NULL;
   }
+#endif
+#if AVC_SYNTAX || SYNTAX_OUTPUT
+  if( m_pchBLSyntaxFile )
+  {
+    free ( m_pchBLSyntaxFile );
+    m_pchBLSyntaxFile = NULL;
+  }
+#endif
 }
 
@@ -89,4 +126,177 @@
  .
  */
+#if SVC_EXTENSION
+Void TAppDecTop::decode()
+{
+  Int                poc;
+  TComList<TComPic*>* pcListPic = NULL;
+
+  ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary);
+  if (!bitstreamFile)
+  {
+    fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile);
+    exit(EXIT_FAILURE);
+  }
+
+  InputByteStream bytestream(bitstreamFile);
+
+  // create & initialize internal classes
+  xCreateDecLib();
+  xInitDecLib  ();
+
+  // main decoder loop
+  Bool recon_opened[MAX_LAYERS]; // reconstruction file not yet opened. (must be performed after SPS is seen)
+  for(UInt layer=0; layer<=m_tgtLayerId; layer++)
+  {
+    recon_opened[layer] = false;
+    m_aiPOCLastDisplay[layer] += m_iSkipFrame;      // set the last displayed POC correctly for skip forward.
+  }
+
+  UInt curLayerId = 0;     // current layer to be reconstructed
+
+#if AVC_BASE
+  TComPic pcBLPic;
+  if( !m_pchBLReconFile )
+  {
+    printf( "Wrong base layer YUV input file\n" );
+    exit(EXIT_FAILURE);
+  }
+  fstream streamYUV( m_pchBLReconFile, fstream::in | fstream::binary );
+  if( !streamYUV.good() )
+  {
+    printf( "Base layer YUV input reading error\n" );
+    exit(EXIT_FAILURE);
+  }
+  TComList<TComPic*> *cListPic = m_acTDecTop[0].getListPic();
+  m_acTDecTop[0].setBLsize( m_iBLSourceWidth, m_iBLSourceHeight );
+  m_acTDecTop[0].setBLReconFile( &streamYUV );
+  pcBLPic.setLayerId( 0 );
+  cListPic->pushBack( &pcBLPic );
+#if AVC_SYNTAX
+  if( !m_pchBLSyntaxFile )
+  {
+    printf( "Wrong base layer syntax file\n" );
+    exit(EXIT_FAILURE);
+  }
+  fstream streamSyntaxFile( m_pchBLSyntaxFile, fstream::in | fstream::binary );
+  if( !streamSyntaxFile.good() )
+  {
+    printf( "Base layer syntax input reading error\n" );
+    exit(EXIT_FAILURE);
+  }
+  m_acTDecTop[0].setBLSyntaxFile( &streamSyntaxFile );
+#endif
+#endif
+
+  while (!!bitstreamFile)
+  {
+    /* location serves to work around a design fault in the decoder, whereby
+     * the process of reading a new slice that is the first slice of a new frame
+     * requires the TDecTop::decode() method to be called again with the same
+     * nal unit. */
+    streampos location = bitstreamFile.tellg();
+    AnnexBStats stats = AnnexBStats();
+
+    vector<uint8_t> nalUnit;
+    InputNALUnit nalu;
+    byteStreamNALUnit(bytestream, nalUnit, stats);
+
+    // call actual decoding function
+    Bool bNewPicture = false;
+    Bool bNewPOC = false;
+    if (nalUnit.empty())
+    {
+      /* this can happen if the following occur:
+       *  - empty input file
+       *  - two back-to-back start_code_prefixes
+       *  - start_code_prefix immediately followed by EOF
+       */
+      fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n");
+    }
+    else
+    {
+      read(nalu, nalUnit);
+      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  ||
+        (nalu.m_layerId > m_tgtLayerId) )
+      {
+        bNewPicture = false;
+      }
+      else
+      {
+        bNewPicture = m_acTDecTop[nalu.m_layerId].decode(nalu, m_iSkipFrame, m_aiPOCLastDisplay[nalu.m_layerId], curLayerId, bNewPOC);
+        if (bNewPicture)
+        {
+          bitstreamFile.clear();
+          /* location points to the current nalunit payload[1] due to the
+           * need for the annexB parser to read three extra bytes.
+           * [1] except for the first NAL unit in the file
+           *     (but bNewPicture doesn't happen then) */
+          bitstreamFile.seekg(location-streamoff(3));
+          bytestream.reset();
+        }
+      }
+    }
+    if (bNewPicture || !bitstreamFile)
+    {
+      m_acTDecTop[curLayerId].executeLoopFilters(poc, pcListPic);
+    }
+
+    if( pcListPic )
+    {
+      if ( m_pchReconFile[curLayerId] && !recon_opened[curLayerId] )
+      {
+        if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; }        
+        if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; }
+
+        m_acTVideoIOYuvReconFile[curLayerId].open( m_pchReconFile[curLayerId], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
+
+        recon_opened[curLayerId] = true;
+      }
+      if ( bNewPicture && bNewPOC && 
+           (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR
+            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
+            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP
+            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLANT
+            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA ) )
+      {
+        xFlushOutput( pcListPic, curLayerId );
+      }
+      // write reconstruction to file
+      if(bNewPicture)
+      {
+        xWriteOutput( pcListPic, curLayerId, nalu.m_temporalId );
+      }
+    }
+  }
+  for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
+  {
+    xFlushOutput( m_acTDecTop[layer].getListPic(), layer );
+  }
+  // delete buffers
+#if AVC_BASE
+  if( streamYUV.is_open() )
+  {
+    streamYUV.close();
+  }
+#if AVC_SYNTAX
+  if( streamSyntaxFile.is_open() )
+  {
+    streamSyntaxFile.close();
+  }
+#endif
+  pcBLPic.destroy();
+
+  for(UInt layer = 1; layer <= m_tgtLayerId; layer++)
+#else
+  for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
+#endif
+  {
+    m_acTDecTop[layer].deletePicBuffer();
+  }
+  
+  // destroy internal classes
+  xDestroyDecLib();
+}
+#else
 Void TAppDecTop::decode()
 {
@@ -110,4 +320,25 @@
   // main decoder loop
   Bool recon_opened = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
+
+#if SYNTAX_OUTPUT
+  if( !m_pchBLSyntaxFile )
+  {
+    printf( "Wrong base layer syntax file\n" );
+    exit(EXIT_FAILURE);
+  }
+  fstream streamSyntaxFile( m_pchBLSyntaxFile, fstream::out | fstream::binary );
+  if( !streamSyntaxFile.good() )
+  {
+    printf( "Base layer syntax input reading error\n" );
+    exit(EXIT_FAILURE);
+  }
+  m_cTDecTop.setBLSyntaxFile( &streamSyntaxFile );
+
+  for( Int i = m_iBLFrames * m_iBLSourceWidth * m_iBLSourceHeight * SYNTAX_BYTES / 16; i >= 0; i-- )
+  {
+    streamSyntaxFile.put( 0 );
+  }
+  streamSyntaxFile.seekp( 0 );
+#endif
 
   while (!!bitstreamFile)
@@ -199,4 +430,11 @@
   }
   
+#if SYNTAX_OUTPUT
+  if( streamSyntaxFile.is_open() )
+  {
+    streamSyntaxFile.close();
+  }
+#endif
+  
   xFlushOutput( pcListPic );
   // delete buffers
@@ -206,4 +444,5 @@
   xDestroyDecLib();
 }
+#endif
 
 // ====================================================================================================================
@@ -213,10 +452,41 @@
 Void TAppDecTop::xCreateDecLib()
 {
+#if SVC_EXTENSION
+  // initialize global variables
+  initROM();  
+
+  for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
+  {
+    // set layer ID
+    m_acTDecTop[layer].setLayerId                      ( layer );
+
+    // create decoder class
+    m_acTDecTop[layer].create();
+
+    m_acTDecTop[layer].setLayerDec(m_apcTDecTop);   
+  }
+#else
   // create decoder class
   m_cTDecTop.create();
+#endif
 }
 
 Void TAppDecTop::xDestroyDecLib()
 {
+#if SVC_EXTENSION
+  // destroy ROM
+  destroyROM();
+
+  for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
+  {
+    if ( m_pchReconFile[layer] )
+    {
+      m_acTVideoIOYuvReconFile[layer]. close();
+    }
+
+    // destroy decoder class
+    m_acTDecTop[layer].destroy();
+  }
+#else
   if ( m_pchReconFile )
   {
@@ -226,4 +496,5 @@
   // destroy decoder class
   m_cTDecTop.destroy();
+#endif
 }
 
@@ -231,6 +502,16 @@
 {
   // initialize decoder class
+#if SVC_EXTENSION
+  for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
+  {
+    m_acTDecTop[layer].init();
+    m_acTDecTop[layer].setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
+    m_acTDecTop[layer].setNumLayer( m_tgtLayerId + 1 );
+  }
+
+#else
   m_cTDecTop.init();
   m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
+#endif
 }
 
@@ -238,5 +519,9 @@
     \todo            DYN_REF_FREE should be revised
  */
+#if SVC_EXTENSION
+Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt layerId, UInt tId )
+#else
 Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId )
+#endif
 {
   TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
@@ -246,5 +531,9 @@
   {
     TComPic* pcPic = *(iterPic);
+#if SVC_EXTENSION
+    if(pcPic->getOutputMark() && pcPic->getPOC() > m_aiPOCLastDisplay[layerId])
+#else
     if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay)
+#endif
     {
        not_displayed++;
@@ -258,8 +547,27 @@
     TComPic* pcPic = *(iterPic);
     
+#if SVC_EXTENSION
+    if ( pcPic->getOutputMark() && (not_displayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_aiPOCLastDisplay[layerId]))
+#else
     if ( pcPic->getOutputMark() && (not_displayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
+#endif
     {
       // write to file
        not_displayed--;
+#if SVC_EXTENSION
+      if ( m_pchReconFile[layerId] )
+      {
+        const Window &conf = pcPic->getConformanceWindow();
+        const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+        m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
+                                       conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+                                       conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+                                       conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+                                       conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
+      }
+      
+      // update POC of display order
+      m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
+#else
       if ( m_pchReconFile )
       {
@@ -275,4 +583,5 @@
       // update POC of display order
       m_iPOCLastDisplay = pcPic->getPOC();
+#endif
       
       // erase non-referenced picture in the reference picture list after display
@@ -302,5 +611,9 @@
     \todo            DYN_REF_FREE should be revised
  */
+#if SVC_EXTENSION
+Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, UInt layerId )
+#else
 Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic )
+#endif
 {
   if(!pcListPic)
@@ -319,4 +632,19 @@
     {
       // write to file
+#if SVC_EXTENSION
+      if ( m_pchReconFile[layerId] )
+      {
+        const Window &conf = pcPic->getConformanceWindow();
+        const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+        m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
+                                       conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+                                       conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+                                       conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+                                       conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
+      }
+      
+      // update POC of display order
+      m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
+#else
       if ( m_pchReconFile )
       {
@@ -332,4 +660,5 @@
       // update POC of display order
       m_iPOCLastDisplay = pcPic->getPOC();
+#endif
       
       // erase non-referenced picture in the reference picture list after display
@@ -351,4 +680,5 @@
       pcPic->setOutputMark(false);
     }
+#if !SVC_EXTENSION
 #if !DYN_REF_FREE
     if(pcPic)
@@ -359,8 +689,13 @@
     }
 #endif    
+#endif
     iterPic++;
   }
+#if SVC_EXTENSION
+  m_aiPOCLastDisplay[layerId] = -MAX_INT;
+#else
   pcListPic->clear();
   m_iPOCLastDisplay = -MAX_INT;
+#endif
 }
 
Index: branches/HM-10.0-dev-SHM/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppDecoder/TAppDecTop.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/App/TAppDecoder/TAppDecTop.h	(revision 54)
@@ -61,10 +61,20 @@
 private:
   // class interface
+#if SVC_EXTENSION
+  TDecTop                         m_acTDecTop [MAX_LAYERS];                    ///< decoder class 
+  TDecTop*                        m_apcTDecTop [MAX_LAYERS];                   ///< decoder point class 
+  TVideoIOYuv                     m_acTVideoIOYuvReconFile [MAX_LAYERS];        ///< reconstruction YUV class
+#else
   TDecTop                         m_cTDecTop;                     ///< decoder class
   TVideoIOYuv                     m_cTVideoIOYuvReconFile;        ///< reconstruction YUV class
+#endif
   
   // for output control
   Bool                            m_abDecFlag[ MAX_GOP ];         ///< decoded flag in one GOP
+#if SVC_EXTENSION
+  Int                             m_aiPOCLastDisplay [MAX_LAYERS]; ///< last POC in display order
+#else
   Int                             m_iPOCLastDisplay;              ///< last POC in display order
+#endif
   
 public:
@@ -81,6 +91,11 @@
   Void  xInitDecLib       (); ///< initialize decoder class
   
+#if SVC_EXTENSION
+  Void  xWriteOutput      ( TComList<TComPic*>* pcListPic, UInt layerId, UInt tId ); ///< write YUV to file
+  Void  xFlushOutput      ( TComList<TComPic*>* pcListPic, UInt layerId ); ///< flush all remaining decoded pictures to file
+#else
   Void  xWriteOutput      ( TComList<TComPic*>* pcListPic , UInt tId); ///< write YUV to file
   Void  xFlushOutput      ( TComList<TComPic*>* pcListPic ); ///< flush all remaining decoded pictures to file
+#endif
   Bool  isNaluWithinTargetDecLayerIdSet ( InputNALUnit* nalu ); ///< check whether given Nalu is within targetDecLayerIdSet
 };
Index: branches/HM-10.0-dev-SHM/source/App/TAppDecoder/decmain.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppDecoder/decmain.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/App/TAppDecoder/decmain.cpp	(revision 54)
@@ -56,5 +56,5 @@
   // print information
   fprintf( stdout, "\n" );
-  fprintf( stdout, "HM software: Decoder Version [%s]", NV_VERSION );
+  fprintf( stdout, "SHM software: Decoder Version [%s]", NV_VERSION );
   fprintf( stdout, NVM_ONOS );
   fprintf( stdout, NVM_COMPILEDBY );
Index: branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 54)
@@ -63,4 +63,20 @@
 // ====================================================================================================================
 
+#if SVC_EXTENSION
+TAppEncCfg::TAppEncCfg()
+: m_pBitstreamFile()
+, m_pColumnWidth()
+, m_pRowHeight()
+, m_scalingListFile()
+#if REF_IDX_FRAMEWORK
+, m_elRapSliceBEnabled(0)
+#endif
+{
+  for(UInt layer=0; layer<MAX_LAYERS; layer++)
+  {
+    m_acLayerCfg[layer].setAppEncCfg(this);
+  }
+}
+#else
 TAppEncCfg::TAppEncCfg()
 : m_pchInputFile()
@@ -74,7 +90,9 @@
   m_aidQP = NULL;
 }
+#endif
 
 TAppEncCfg::~TAppEncCfg()
 {
+#if !SVC_EXTENSION
   if ( m_aidQP )
   {
@@ -82,7 +100,10 @@
   }
   free(m_pchInputFile);
-  free(m_pchBitstreamFile);
+#endif
+  free(m_pBitstreamFile);
+#if !SVC_EXTENSION  
   free(m_pchReconFile);
   free(m_pchdQPFile);
+#endif
   free(m_pColumnWidth);
   free(m_pRowHeight);
@@ -141,4 +162,30 @@
   return in;
 }
+
+#if SVC_EXTENSION
+void TAppEncCfg::getDirFilename(string& filename, string& dir, const string path)
+{
+  size_t pos = path.find_last_of("\\");
+  if(pos != std::string::npos)
+  {
+    filename.assign(path.begin() + pos + 1, path.end());
+    dir.assign(path.begin(), path.begin() + pos + 1);
+  }
+  else
+  {
+    pos = path.find_last_of("/");
+    if(pos != std::string::npos)
+    {
+      filename.assign(path.begin() + pos + 1, path.end());
+      dir.assign(path.begin(), path.begin() + pos + 1);
+    }
+    else
+    {
+      filename = path;
+      dir.assign("");
+    }
+  }
+}
+#endif
 
 static const struct MapStrToProfile {
@@ -231,8 +278,36 @@
   Bool do_help = false;
   
+#if SVC_EXTENSION
+  string  cfg_LayerCfgFile  [MAX_LAYERS];
+  string  cfg_BitstreamFile;
+  string* cfg_InputFile     [MAX_LAYERS];
+  string* cfg_ReconFile     [MAX_LAYERS];
+  Double* cfg_fQP           [MAX_LAYERS];
+
+  Int*    cfg_SourceWidth   [MAX_LAYERS]; 
+  Int*    cfg_SourceHeight  [MAX_LAYERS];
+  Int*    cfg_FrameRate     [MAX_LAYERS];
+  Int*    cfg_IntraPeriod   [MAX_LAYERS];
+  Int*    cfg_conformanceMode  [MAX_LAYERS];
+  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    cfg_InputFile[layer]    = &m_acLayerCfg[layer].m_cInputFile;
+    cfg_ReconFile[layer]    = &m_acLayerCfg[layer].m_cReconFile;
+    cfg_fQP[layer]          = &m_acLayerCfg[layer].m_fQP;
+    cfg_SourceWidth[layer]  = &m_acLayerCfg[layer].m_iSourceWidth;
+    cfg_SourceHeight[layer] = &m_acLayerCfg[layer].m_iSourceHeight;
+    cfg_FrameRate[layer]    = &m_acLayerCfg[layer].m_iFrameRate; 
+    cfg_IntraPeriod[layer]  = &m_acLayerCfg[layer].m_iIntraPeriod; 
+    cfg_conformanceMode[layer] = &m_acLayerCfg[layer].m_conformanceMode;
+  }
+#if AVC_SYNTAX
+  string  cfg_BLSyntaxFile;
+#endif
+#else
   string cfg_InputFile;
   string cfg_BitstreamFile;
   string cfg_ReconFile;
   string cfg_dQPFile;
+#endif
   string cfg_ColumnWidth;
   string cfg_RowHeight;
@@ -252,4 +327,34 @@
   
   // File, I/O and source parameters
+#if SVC_EXTENSION
+  ("InputFile%d,-i%d",        cfg_InputFile,  string(""), MAX_LAYERS, "original YUV input file name for layer %d")
+  ("ReconFile%d,-o%d",        cfg_ReconFile,  string(""), MAX_LAYERS, "reconstruction YUV input file name for layer %d")
+  ("LayerConfig%d,-lc%d",     cfg_LayerCfgFile, string(""), MAX_LAYERS, "layer %d configuration file name")
+  ("SourceWidth%d,-wdt%d",    cfg_SourceWidth, 0, MAX_LAYERS, "Source picture width for layer %d")
+  ("SourceHeight%d,-hgt%d",   cfg_SourceHeight, 0, MAX_LAYERS, "Source picture height for layer %d")
+  ("FrameRate%d,-fr%d",       cfg_FrameRate,  0, MAX_LAYERS, "Frame rate for layer %d")
+  ("LambdaModifier%d,-LM%d",  m_adLambdaModifier, ( double )1.0, MAX_TLAYER, "Lambda modifier for temporal layer %d")
+  ("NumLayers",               m_numLayers, 1, "Number of layers to code")
+  ("ConformanceMode%d",       cfg_conformanceMode,0, MAX_LAYERS, "Window conformance mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
+
+  ("BitstreamFile,b",       cfg_BitstreamFile, string(""), "Bitstream output file name")
+  ("InputBitDepth",         m_inputBitDepthY,    8, "Bit-depth of input file")
+  ("OutputBitDepth",        m_outputBitDepthY,   0, "Bit-depth of output file (default:InternalBitDepth)")
+  ("InternalBitDepth",      m_internalBitDepthY, 0, "Bit-depth the codec operates at. (default:InputBitDepth)"
+                                                       "If different to InputBitDepth, source data will be converted")
+  ("InputBitDepthC",        m_inputBitDepthC,    0, "As per InputBitDepth but for chroma component. (default:InputBitDepth)")
+  ("OutputBitDepthC",       m_outputBitDepthC,   0, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
+  ("InternalBitDepthC",     m_internalBitDepthC, 0, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth)")
+
+#if AVC_BASE
+  ("InputBLFile,-ibl",        *cfg_InputFile[0],     string(""), "Base layer rec YUV input file name")
+#if AVC_SYNTAX
+  ("InputBLSyntaxFile,-ibs",  cfg_BLSyntaxFile,     string(""), "Base layer syntax input file name")
+#endif
+#endif
+#if REF_IDX_FRAMEWORK
+  ("EnableElRapB,-use-rap-b",  m_elRapSliceBEnabled, 0, "Set ILP over base-layer I picture to B picture (default is P picture_")
+#endif  
+#else  
   ("InputFile,i",           cfg_InputFile,     string(""), "Original YUV input file name")
   ("BitstreamFile,b",       cfg_BitstreamFile, string(""), "Bitstream output file name")
@@ -272,4 +377,5 @@
   ("ConfBottom",            m_confBottom,          0, "Bottom offset for window conformance mode 3")
   ("FrameRate,-fr",         m_iFrameRate,          0, "Frame rate")
+#endif
   ("FrameSkip,-fs",         m_FrameSkip,          0u, "Number of frames to skip at start of input YUV")
   ("FramesToBeEncoded,f",   m_framesToBeEncoded,   0, "Number of frames to be encoded (default=all)")
@@ -286,5 +392,5 @@
   ("FrameOnly",         m_frameOnlyConstraintFlag, false, "Indicate that the bitstream contains only frames")
 #endif
-  
+
   // Unit definition parameters
   ("MaxCUWidth",              m_uiMaxCUWidth,             64u)
@@ -302,5 +408,9 @@
   
   // Coding structure paramters
+#if SVC_EXTENSION
+  ("IntraPeriod%d,-ip%d",  cfg_IntraPeriod, -1, MAX_LAYERS, "intra period in frames for layer %d, (-1: only first frame)")
+#else
   ("IntraPeriod,-ip",         m_iIntraPeriod,              -1, "Intra period in frames, (-1: only first frame)")
+#endif
   ("DecodingRefreshType,-dr", m_iDecodingRefreshType,       0, "Intra refresh type (0:none 1:CRA 2:IDR)")
   ("GOPSize,g",               m_iGOPSize,                   1, "GOP size of temporal structure")
@@ -313,4 +423,7 @@
   ("ASR",                     m_bUseASR,                false, "Adaptive motion search range")
 
+#if SVC_EXTENSION
+  ("LambdaModifier%d,-LM%d",  m_adLambdaModifier, ( double )1.0, MAX_TLAYER, "Lambda modifier for temporal layer %d")
+#else
   // Mode decision parameters
   ("LambdaModifier0,-LM0", m_adLambdaModifier[ 0 ], ( Double )1.0, "Lambda modifier for temporal layer 0")
@@ -322,7 +435,12 @@
   ("LambdaModifier6,-LM6", m_adLambdaModifier[ 6 ], ( Double )1.0, "Lambda modifier for temporal layer 6")
   ("LambdaModifier7,-LM7", m_adLambdaModifier[ 7 ], ( Double )1.0, "Lambda modifier for temporal layer 7")
+#endif
 
   /* Quantization parameters */
+#if SVC_EXTENSION
+  ("QP%d,-q%d",     cfg_fQP,  30.0, MAX_LAYERS, "Qp value for layer %d, if value is float, QP is switched once during encoding")
+#else
   ("QP,q",          m_fQP,             30.0, "Qp value, if value is float, QP is switched once during encoding")
+#endif
   ("DeltaQpRD,-dqr",m_uiDeltaQpRD,       0u, "max dQp offset for slice")
   ("MaxDeltaQP,d",  m_iMaxDeltaQP,        0, "max dQp offset for block")
@@ -338,5 +456,7 @@
   ("AdaptiveQP,-aq",                m_bUseAdaptiveQP,           false, "QP adaptation based on a psycho-visual model")
   ("MaxQPAdaptationRange,-aqr",     m_iQPAdaptationRange,           6, "QP adaptation range")
+#if !SVC_EXTENSION
   ("dQPFile,m",                     cfg_dQPFile,           string(""), "dQP file name")
+#endif
   ("RDOQ",                          m_useRDOQ,                  true )
   ("RDOQTS",                        m_useRDOQTS,                true )
@@ -526,9 +646,16 @@
    */
   /* convert std::string to c string for compatability */
+#if SVC_EXTENSION
+  m_pBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
+#if AVC_SYNTAX
+  m_BLSyntaxFile = cfg_BLSyntaxFile.empty() ? NULL : strdup(cfg_BLSyntaxFile.c_str());
+#endif
+#else
   m_pchInputFile = cfg_InputFile.empty() ? NULL : strdup(cfg_InputFile.c_str());
-  m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
+  m_phBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
   m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
   m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
-  
+#endif  
+
   Char* pColumnWidth = cfg_ColumnWidth.empty() ? NULL: strdup(cfg_ColumnWidth.c_str());
   Char* pRowHeight = cfg_RowHeight.empty() ? NULL : strdup(cfg_RowHeight.c_str());
@@ -605,4 +732,5 @@
   if (!m_outputBitDepthC) { m_outputBitDepthC = m_internalBitDepthC; }
 
+#if !SVC_EXTENSION
   // TODO:ChromaFmt assumes 4:2:0 below
   switch (m_conformanceMode)
@@ -702,5 +830,5 @@
   }
   m_iWaveFrontSubstreams = m_iWaveFrontSynchro ? (m_iSourceHeight + m_uiMaxCUHeight - 1) / m_uiMaxCUHeight : 1;
-
+#endif
   // check validity of input parameters
   xCheckParameter();
@@ -800,11 +928,17 @@
   xConfirmPara( m_inputBitDepthY < 8,                                                     "InputBitDepth must be at least 8" );
   xConfirmPara( m_inputBitDepthC < 8,                                                     "InputBitDepthC must be at least 8" );
+#if !SVC_EXTENSION  
   xConfirmPara( m_iFrameRate <= 0,                                                          "Frame rate must be more than 1" );
+#endif
   xConfirmPara( m_framesToBeEncoded <= 0,                                                   "Total Number Of Frames encoded must be more than 0" );
   xConfirmPara( m_iGOPSize < 1 ,                                                            "GOP Size must be greater or equal to 1" );
   xConfirmPara( m_iGOPSize > 1 &&  m_iGOPSize % 2,                                          "GOP Size must be a multiple of 2, if GOP Size is greater than 1" );
+#if !SVC_EXTENSION 
   xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < m_iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" );
+#endif
   xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 2,                   "Decoding Refresh Type must be equal to 0, 1 or 2" );
+#if !SVC_EXTENSION
   xConfirmPara( m_iQP <  -6 * (m_internalBitDepthY - 8) || m_iQP > 51,                    "QP exceeds supported range (-QpBDOffsety to 51)" );
+#endif
   xConfirmPara( m_loopFilterBetaOffsetDiv2 < -13 || m_loopFilterBetaOffsetDiv2 > 13,          "Loop Filter Beta Offset div. 2 exceeds supported range (-13 to 13)");
   xConfirmPara( m_loopFilterTcOffsetDiv2 < -13 || m_loopFilterTcOffsetDiv2 > 13,              "Loop Filter Tc Offset div. 2 exceeds supported range (-13 to 13)");
@@ -821,14 +955,18 @@
 
   xConfirmPara( m_iQPAdaptationRange <= 0,                                                  "QP Adaptation Range must be more than 0" );
+#if !SVC_EXTENSION
   if (m_iDecodingRefreshType == 2)
   {
     xConfirmPara( m_iIntraPeriod > 0 && m_iIntraPeriod <= m_iGOPSize ,                      "Intra period must be larger than GOP size for periodic IDR pictures");
   }
+#endif
   xConfirmPara( (m_uiMaxCUWidth  >> m_uiMaxCUDepth) < 4,                                    "Minimum partition width size should be larger than or equal to 8");
   xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4,                                    "Minimum partition height size should be larger than or equal to 8");
   xConfirmPara( m_uiMaxCUWidth < 16,                                                        "Maximum partition width size should be larger than or equal to 16");
   xConfirmPara( m_uiMaxCUHeight < 16,                                                       "Maximum partition height size should be larger than or equal to 16");
+#if !SVC_EXTENSION
   xConfirmPara( (m_iSourceWidth  % (m_uiMaxCUWidth  >> (m_uiMaxCUDepth-1)))!=0,             "Resulting coded frame width must be a multiple of the minimum CU size");
   xConfirmPara( (m_iSourceHeight % (m_uiMaxCUHeight >> (m_uiMaxCUDepth-1)))!=0,             "Resulting coded frame height must be a multiple of the minimum CU size");
+#endif
   
   xConfirmPara( m_uiQuadtreeTULog2MinSize < 2,                                        "QuadtreeTULog2MinSize must be 2 or greater.");
@@ -849,7 +987,9 @@
   xConfirmPara(  m_maxNumMergeCand > 5,  "MaxNumMergeCand must be 5 or smaller.");
 
+#if !SVC_EXTENSION
 #if ADAPTIVE_QP_SELECTION
   xConfirmPara( m_bUseAdaptQpSelect == true && m_iQP < 0,                                              "AdaptiveQpSelection must be disabled when QP < 0.");
   xConfirmPara( m_bUseAdaptQpSelect == true && (m_cbQpOffset !=0 || m_crQpOffset != 0 ),               "AdaptiveQpSelection must be disabled when ChromaQpOffset is not equal to 0.");
+#endif
 #endif
 
@@ -877,4 +1017,5 @@
 
   //TODO:ChromaFmt assumes 4:2:0 below
+#if !SVC_EXTENSION
   xConfirmPara( m_iSourceWidth  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Picture width must be an integer multiple of the specified chroma subsampling");
   xConfirmPara( m_iSourceHeight % TComSPS::getWinUnitY(CHROMA_420) != 0, "Picture height must be an integer multiple of the specified chroma subsampling");
@@ -887,5 +1028,9 @@
   xConfirmPara( m_confTop    % TComSPS::getWinUnitY(CHROMA_420) != 0, "Top conformance window offset must be an integer multiple of the specified chroma subsampling");
   xConfirmPara( m_confBottom % TComSPS::getWinUnitY(CHROMA_420) != 0, "Bottom conformance window offset must be an integer multiple of the specified chroma subsampling");
-
+#endif
+
+#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV
+  xConfirmPara( REF_IDX_ME_AROUND_ZEROMV && REF_IDX_ME_ZEROMV, "REF_IDX_ME_AROUND_ZEROMV and REF_IDX_ME_ZEROMV cannot be enabled simultaneously");
+#endif
   // max CU width and height should be power of 2
   UInt ui = m_uiMaxCUWidth;
@@ -904,6 +1049,12 @@
   }
 
+
   /* if this is an intra-only sequence, ie IntraPeriod=1, don't verify the GOP structure
    * This permits the ability to omit a GOP structure specification */
+#if SVC_EXTENSION
+  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    Int m_iIntraPeriod = m_acLayerCfg[layer].m_iIntraPeriod;
+#endif
   if (m_iIntraPeriod == 1 && m_GOPList[0].m_POC == -1) {
     m_GOPList[0] = GOPEntry();
@@ -914,4 +1065,7 @@
     m_GOPList[0].m_numRefPicsActive = 4;
   }
+#if SVC_EXTENSION
+  }
+#endif
   
   Bool verifiedGOP=false;
@@ -927,5 +1081,7 @@
   }
   Int numOK=0;
+#if !SVC_EXTENSION
   xConfirmPara( m_iIntraPeriod >=0&&(m_iIntraPeriod%m_iGOPSize!=0), "Intra period must be a multiple of GOPSize, or -1" );
+#endif
 
   for(Int i=0; i<m_iGOPSize; i++)
@@ -936,5 +1092,23 @@
     }
   }
-  
+
+#if SVC_EXTENSION
+  // verify layer configuration parameters
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    if(m_acLayerCfg[layer].xCheckParameter())
+    {
+      printf("\nError: invalid configuration parameter found in layer %d \n", layer);
+      check_failed = true;
+    }
+  }
+#endif  
+
+#if SVC_EXTENSION
+  // verify layer configuration parameters
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    Int m_iIntraPeriod = m_acLayerCfg[layer].m_iIntraPeriod;
+#endif
   if ( (m_iIntraPeriod != 1) && !m_loopFilterOffsetInPPS && m_DeblockingFilterControlPresent && (!m_bLoopFilterDisable) )
   {
@@ -945,4 +1119,8 @@
     }
   }
+#if SVC_EXTENSION
+  }
+#endif
+
   m_extraRPSs=0;
   //start looping through frames in coding order until we can verify that the GOP structure is correct.
@@ -1206,4 +1384,10 @@
   }
 
+#if SVC_EXTENSION // ToDo: it should be checked for the case when parameters are different for the layers
+  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    Int m_iSourceWidth = m_acLayerCfg[layer].m_iSourceWidth;
+    Int m_iSourceHeight = m_acLayerCfg[layer].m_iSourceHeight;
+#endif
   if(m_vuiParametersPresentFlag && m_bitstreamRestrictionFlag)
   { 
@@ -1279,8 +1463,14 @@
     }
   }
+#if SVC_EXTENSION
+  }
+#endif
+
   xConfirmPara( m_bUseLComb==false && m_numReorderPics[MAX_TLAYER-1]!=0, "ListCombination can only be 0 in low delay coding (more precisely when L0 and L1 are identical)" );  // Note however this is not the full necessary condition as ref_pic_list_combination_flag can only be 0 if L0 == L1.
   xConfirmPara( m_iWaveFrontSynchro < 0, "WaveFrontSynchro cannot be negative" );
+#if !SVC_EXTENSION
   xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" );
   xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_iWaveFrontSynchro, "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" );
+#endif
 
   xConfirmPara( m_decodedPictureHashSEIEnabled<0 || m_decodedPictureHashSEIEnabled>3, "this hash type is not correct!\n");
@@ -1357,4 +1547,15 @@
 {
   printf("\n");
+#if SVC_EXTENSION  
+  printf("Total number of layers        : %d\n", m_numLayers            );
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    printf("=== Layer %d settings === \n", layer);
+    m_acLayerCfg[layer].xPrintParameter();
+    printf("\n");
+  }
+  printf("=== Common configuration settings === \n");
+  printf("Bitstream      File          : %s\n", m_pBitstreamFile      );
+#else
   printf("Input          File          : %s\n", m_pchInputFile          );
   printf("Bitstream      File          : %s\n", m_pchBitstreamFile      );
@@ -1362,4 +1563,5 @@
   printf("Real     Format              : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate );
   printf("Internal Format              : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
+#endif
   printf("Frame index                  : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
   printf("CU size / depth              : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth );
@@ -1369,7 +1571,11 @@
   printf("Min PCM size                 : %d\n", 1 << m_uiPCMLog2MinSize);
   printf("Motion search range          : %d\n", m_iSearchRange );
+#if !SVC_EXTENSION
   printf("Intra period                 : %d\n", m_iIntraPeriod );
+#endif
   printf("Decoding refresh type        : %d\n", m_iDecodingRefreshType );
+#if !SVC_EXTENSION
   printf("QP                           : %5.2f\n", m_fQP );
+#endif
   printf("Max dQP signaling depth      : %d\n", m_iMaxCuDQPDepth);
 
@@ -1442,6 +1648,8 @@
   printf("WPB:%d ", (Int)m_useWeightedBiPred);
   printf("PME:%d ", m_log2ParallelMergeLevel);
+#if !SVC_EXTENSION
   printf(" WaveFrontSynchro:%d WaveFrontSubstreams:%d",
           m_iWaveFrontSynchro, m_iWaveFrontSubstreams);
+#endif
   printf(" ScalingList:%d ", m_useScalingListId );
   printf("TMVPMode:%d ", m_TMVPModeId     );
@@ -1451,5 +1659,22 @@
 
   printf(" SignBitHidingFlag:%d ", m_signHideFlag);
+#if SVC_EXTENSION
+  printf("RecalQP:%d ", m_recalculateQPAccordingToLambda ? 1 : 0 );
+  printf("AVC_BASE:%d ", AVC_BASE);
+#if REF_IDX_FRAMEWORK
+  printf("REF_IDX_FRAMEWORK:%d ", REF_IDX_FRAMEWORK);
+  printf("EL_RAP_SliceType: %d ", m_elRapSliceBEnabled);
+  printf("REF_IDX_ME_AROUND_ZEROMV:%d ", REF_IDX_ME_AROUND_ZEROMV);
+  printf("REF_IDX_ME_ZEROMV: %d", REF_IDX_ME_ZEROMV);
+#elif INTRA_BL
+  printf("INTRA_BL:%d ", INTRA_BL);
+#if !AVC_BASE
+  printf("SVC_MVP:%d ", SVC_MVP );
+  printf("SVC_BL_CAND_INTRA:%d", SVC_BL_CAND_INTRA );
+#endif
+#endif
+#else
   printf("RecalQP:%d", m_recalculateQPAccordingToLambda ? 1 : 0 );
+#endif
   printf("\n\n");
   
Index: branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncCfg.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncCfg.h	(revision 54)
@@ -42,4 +42,7 @@
 
 #include "TLibEncoder/TEncCfg.h"
+#if SVC_EXTENSION
+#include "TAppEncLayerCfg.h"
+#endif
 #include <sstream>
 //! \ingroup TAppEncoder
@@ -55,4 +58,17 @@
 protected:
   // file I/O
+#if SVC_EXTENSION
+  TAppEncLayerCfg m_acLayerCfg [MAX_LAYERS]; 
+  Int       m_numLayers;                                     ///< number of layers
+
+  Char*     m_pBitstreamFile;                                 ///< output bitstream file
+  Double    m_adLambdaModifier[ MAX_TLAYER ];                 ///< Lambda modifier array for each temporal layer
+  // source specification
+  UInt      m_FrameSkip;                                      ///< number of skipped frames from the beginning
+  Int       m_framesToBeEncoded;                              ///< number of encoded frames
+#if AVC_SYNTAX
+  char*     m_BLSyntaxFile;                                   ///< input syntax file
+#endif
+#else
   Char*     m_pchInputFile;                                   ///< source file name
   Char*     m_pchBitstreamFile;                               ///< output bitstream file
@@ -71,5 +87,6 @@
   Int       m_framesToBeEncoded;                              ///< number of encoded frames
   Int       m_aiPad[2];                                       ///< number of padded pixels for width and height
-  
+#endif  
+
   // profile/level
   Profile::Name m_profile;
@@ -84,5 +101,7 @@
   
   // coding structure
+#if !SVC_EXTENSION
   Int       m_iIntraPeriod;                                   ///< period of I-slice (random access period)
+#endif
   Int       m_iDecodingRefreshType;                           ///< random access type
   Int       m_iGOPSize;                                       ///< GOP size of hierarchical structure
@@ -96,8 +115,10 @@
   Bool      m_enableAMP;
   // coding quality
+#if !SVC_EXTENSION
   Double    m_fQP;                                            ///< QP value of key-picture (floating point)
   Int       m_iQP;                                            ///< QP value of key-picture (integer)
   Char*     m_pchdQPFile;                                     ///< QP offset for each slice (initialized from external file)
   Int*      m_aidQP;                                          ///< array of slice QP values
+#endif
   Int       m_iMaxDeltaQP;                                    ///< max. |delta QP|
   UInt      m_uiDeltaQpRD;                                    ///< dQP range for multi-pass slice QP optimization
@@ -192,5 +213,7 @@
   UInt*     m_pRowHeight;
   Int       m_iWaveFrontSynchro; //< 0: no WPP. >= 1: WPP is enabled, the "Top right" from which inheritance occurs is this LCU offset in the line above the current.
+#if !SVC_EXTENSION
   Int       m_iWaveFrontSubstreams; //< If iWaveFrontSynchro, this is the number of substreams per frame (dependent tiles) or per tile (independent tiles).
+#endif
 
   Bool      m_bUseConstrainedIntraPred;                       ///< flag for using constrained intra prediction
@@ -276,4 +299,7 @@
   Int       m_log2MaxMvLengthVertical;                        ///< Indicate the maximum absolute value of a decoded vertical MV component in quarter-pel luma units
 
+#if REF_IDX_FRAMEWORK
+  Int       m_elRapSliceBEnabled;
+#endif
   // internal member functions
   Void  xSetGlobal      ();                                   ///< set global variables
@@ -300,4 +326,20 @@
   Bool  parseCfg  ( Int argc, Char* argv[] );                 ///< parse configuration file to fill member variables
   
+#if SVC_EXTENSION
+  Int  getNumFrameToBeEncoded()    {return m_framesToBeEncoded; }
+  Int  getNumLayer()               {return m_numLayers;        }
+  Int  getGOPSize()                {return m_iGOPSize;          }
+  UInt getInternalBitDepthY()      {return m_internalBitDepthY; }
+  UInt getInternalBitDepthC()      {return m_internalBitDepthC; }
+  UInt getMaxCUWidth()             {return m_uiMaxCUWidth;      }
+  UInt getMaxCUHeight()            {return m_uiMaxCUHeight;     }
+  UInt getMaxCUDepth()             {return m_uiMaxCUDepth;      }
+  Int  getDecodingRefreshType()    {return m_iDecodingRefreshType; }
+  Int  getWaveFrontSynchro()        { return m_iWaveFrontSynchro; }
+  Void getDirFilename(string& filename, string& dir, const string path);
+#if AVC_SYNTAX
+  Char* getBLSyntaxFile()           { return m_BLSyntaxFile;      }
+#endif
+#endif
 };// END CLASS DEFINITION TAppEncCfg
 
Index: branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncLayerCfg.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 54)
+++ branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 54)
@@ -0,0 +1,247 @@
+/** \file     TAppEncLayerCfg.cpp
+\brief    Handle encoder configuration parameters
+*/
+
+#include <stdlib.h>
+#include <cassert>
+#include <cstring>
+#include <string>
+#include "TLibCommon/TComRom.h"
+#include "TAppEncCfg.h"
+#include "TAppEncLayerCfg.h"
+#include "TAppCommon/program_options_lite.h"
+
+#ifdef WIN32
+#define strdup _strdup
+#endif
+
+using namespace std;
+namespace po = df::program_options_lite;
+
+//! \ingroup TAppEncoder
+//! \{
+
+
+// ====================================================================================================================
+// Constructor / destructor / initialization / destroy
+// ====================================================================================================================
+#if SVC_EXTENSION
+TAppEncLayerCfg::TAppEncLayerCfg()
+  :m_cInputFile(string("")),
+  m_cReconFile(string("")),
+  m_conformanceMode( 0 ),
+  m_aidQP(NULL)
+{
+  m_aiPad[1] = m_aiPad[0] = 0;
+}
+
+TAppEncLayerCfg::~TAppEncLayerCfg()
+{
+  if ( m_aidQP )
+  {
+    delete[] m_aidQP;
+  }
+}
+
+Void TAppEncLayerCfg::create()
+{
+}
+
+Void TAppEncLayerCfg::destroy()
+{
+}
+
+
+// ====================================================================================================================
+// Public member functions
+// ====================================================================================================================
+
+/** \param  argc        number of arguments
+\param  argv        array of arguments
+\retval             true when success
+*/
+bool TAppEncLayerCfg::parseCfg( const string& cfgFileName  )
+{
+  string cfg_InputFile;
+  string cfg_ReconFile;
+  string cfg_dQPFile;
+  po::Options opts;
+  opts.addOptions()
+    ("InputFile,i",           cfg_InputFile,  string(""), "original YUV input file name")
+#if AVC_BASE
+    ("InputBLFile,-ibl",      cfg_InputFile,  string(""), "original YUV input file name")
+#endif
+    ("ReconFile,o",           cfg_ReconFile,  string(""), "reconstructed YUV output file name")
+    ("SourceWidth,-wdt",      m_iSourceWidth,  0, "Source picture width")
+    ("SourceHeight,-hgt",     m_iSourceHeight, 0, "Source picture height")
+    ("CroppingMode",          m_conformanceMode,  0, "Cropping mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
+    ("CropLeft",              m_confLeft,      0, "Left cropping/padding for cropping mode 3")
+    ("CropRight",             m_confRight,     0, "Right cropping/padding for cropping mode 3")
+    ("CropTop",               m_confTop,       0, "Top cropping/padding for cropping mode 3")
+    ("CropBottom",            m_confBottom,    0, "Bottom cropping/padding for cropping mode 3")
+    ("HorizontalPadding,-pdx",m_aiPad[0],      0, "horizontal source padding for cropping mode 2")
+    ("VerticalPadding,-pdy",  m_aiPad[1],      0, "vertical source padding for cropping mode 2")
+    ("IntraPeriod,-ip",       m_iIntraPeriod,  -1, "intra period in frames, (-1: only first frame)")
+    ("FrameRate,-fr",         m_iFrameRate,    0, "Frame rate")
+    ("dQPFile,m",             cfg_dQPFile, string(""), "dQP file name")
+    ("QP,q",                  m_fQP,          30.0, "Qp value, if value is float, QP is switched once during encoding")
+    ;
+
+  po::setDefaults(opts);
+  po::parseConfigFile(opts, cfgFileName);
+
+  m_cInputFile = cfg_InputFile;
+  m_cReconFile = cfg_ReconFile;
+  m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
+
+  // reading external dQP description from file
+  if ( m_pchdQPFile )
+  {
+    FILE* fpt=fopen( m_pchdQPFile, "r" );
+    if ( fpt )
+    {
+      Int iValue;
+      Int iPOC = 0;
+      while ( iPOC < m_cAppEncCfg->getNumFrameToBeEncoded() )
+      {
+        if ( fscanf(fpt, "%d", &iValue ) == EOF ) break;
+        m_aidQP[ iPOC ] = iValue;
+        iPOC++;
+      }
+      fclose(fpt);
+    }
+  }
+  return true;
+}
+
+Void TAppEncLayerCfg::xPrintParameter()
+{
+  printf("Input File                    : %s\n", m_cInputFile.c_str()  );
+  printf("Reconstruction File           : %s\n", m_cReconFile.c_str()  );
+#if AVC_SYNTAX
+  printf("Base layer input file         : %s\n", m_cAppEncCfg->getBLSyntaxFile() );
+#endif
+  printf("Real     Format               : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate );
+  printf("Internal Format               : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
+  printf("QP                            : %5.2f\n", m_fQP );
+  printf("Intra period                  : %d\n", m_iIntraPeriod );
+  printf("WaveFrontSynchro:%d WaveFrontSubstreams:%d", m_cAppEncCfg->getWaveFrontSynchro(), m_iWaveFrontSubstreams);
+}
+
+Bool confirmPara(Bool bflag, const char* message);
+
+Bool TAppEncLayerCfg::xCheckParameter()
+{
+  switch (m_conformanceMode)
+  {
+  case 0:
+    {
+      // no cropping or padding
+      m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
+      m_aiPad[1] = m_aiPad[0] = 0;
+      break;
+    }
+  case 1:
+    {
+      // automatic padding to minimum CU size
+      Int minCuSize = m_cAppEncCfg->getMaxCUHeight() >> (m_cAppEncCfg->getMaxCUDepth() - 1);
+      if (m_iSourceWidth % minCuSize)
+      {
+        m_aiPad[0] = m_confRight  = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth;
+        m_iSourceWidth  += m_confRight;
+      }
+      if (m_iSourceHeight % minCuSize)
+      {
+        m_aiPad[1] = m_confBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
+        m_iSourceHeight += m_confBottom;
+      }
+      break;
+    }
+  case 2:
+    {
+      //padding
+      m_iSourceWidth  += m_aiPad[0];
+      m_iSourceHeight += m_aiPad[1];
+      m_confRight  = m_aiPad[0];
+      m_confBottom = m_aiPad[1];
+      break;
+    }
+  case 3:
+    {
+      // conformance
+      if ((m_confLeft == 0) && (m_confRight == 0) && (m_confTop == 0) && (m_confBottom == 0))
+      {
+        fprintf(stderr, "Warning: Cropping enabled, but all cropping parameters set to zero\n");
+      }
+      if ((m_aiPad[1] != 0) || (m_aiPad[0]!=0))
+      {
+        fprintf(stderr, "Warning: Cropping enabled, padding parameters will be ignored\n");
+      }
+      m_aiPad[1] = m_aiPad[0] = 0;
+      break;
+    }
+  }
+
+  // allocate slice-based dQP values
+  Int iFrameToBeEncoded = m_cAppEncCfg->getNumFrameToBeEncoded();
+  Int iGOPSize = m_cAppEncCfg->getGOPSize();
+  if( m_aidQP == NULL )
+    m_aidQP = new Int[iFrameToBeEncoded + iGOPSize + 1 ];
+  ::memset( m_aidQP, 0, sizeof(Int)*( iFrameToBeEncoded + iGOPSize + 1 ) );
+
+  // handling of floating-point QP values
+  // if QP is not integer, sequence is split into two sections having QP and QP+1
+  m_iQP = (Int)( m_fQP );
+  if ( m_iQP < m_fQP )
+  {
+    Int iSwitchPOC = (Int)( iFrameToBeEncoded - (m_fQP - m_iQP)*iFrameToBeEncoded + 0.5 );
+
+
+    iSwitchPOC = (Int)( (Double)iSwitchPOC / iGOPSize + 0.5 )*iGOPSize;
+    for ( Int i=iSwitchPOC; i<iFrameToBeEncoded + iGOPSize + 1; i++ )
+    {
+      m_aidQP[i] = 1;
+    }
+  }
+
+  UInt maxCUWidth = m_cAppEncCfg->getMaxCUWidth();
+  UInt maxCUHeight = m_cAppEncCfg->getMaxCUHeight();
+  UInt maxCUDepth = m_cAppEncCfg->getMaxCUDepth();
+  bool check_failed = false; /* abort if there is a fatal configuration problem */
+#define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
+  // check range of parameters
+  xConfirmPara( m_iFrameRate <= 0,                                                          "Frame rate must be more than 1" );
+  xConfirmPara( (m_iSourceWidth  % (maxCUWidth  >> (maxCUDepth-1)))!=0,             "Resulting coded frame width must be a multiple of the minimum CU size");
+  xConfirmPara( (m_iSourceHeight % (maxCUHeight >> (maxCUDepth-1)))!=0,             "Resulting coded frame height must be a multiple of the minimum CU size");
+  xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" );
+  if (m_cAppEncCfg->getDecodingRefreshType() == 2)
+  {
+    xConfirmPara( m_iIntraPeriod > 0 && m_iIntraPeriod <= iGOPSize ,                      "Intra period must be larger than GOP size for periodic IDR pictures");
+  }
+
+  xConfirmPara( m_iQP <  -6 * ((Int)m_cAppEncCfg->getInternalBitDepthY() - 8) || m_iQP > 51,                "QP exceeds supported range (-QpBDOffsety to 51)" );
+
+
+  m_iWaveFrontSubstreams = m_cAppEncCfg->getWaveFrontSynchro() ? (m_iSourceHeight + m_cAppEncCfg->getMaxCUHeight() - 1) / m_cAppEncCfg->getMaxCUHeight() : 1;
+  xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" );
+  xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_cAppEncCfg->getWaveFrontSynchro(), "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" );
+
+  //chekc parameters
+  xConfirmPara( m_iSourceWidth  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Picture width must be an integer multiple of the specified chroma subsampling");
+  xConfirmPara( m_iSourceHeight % TComSPS::getWinUnitY(CHROMA_420) != 0, "Picture height must be an integer multiple of the specified chroma subsampling");
+
+  xConfirmPara( m_aiPad[0] % TComSPS::getWinUnitX(CHROMA_420) != 0, "Horizontal padding must be an integer multiple of the specified chroma subsampling");
+  xConfirmPara( m_aiPad[1] % TComSPS::getWinUnitY(CHROMA_420) != 0, "Vertical padding must be an integer multiple of the specified chroma subsampling");
+
+  xConfirmPara( m_confLeft   % TComSPS::getWinUnitX(CHROMA_420) != 0, "Left conformance window offset must be an integer multiple of the specified chroma subsampling");
+  xConfirmPara( m_confRight  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Right conformance window offset must be an integer multiple of the specified chroma subsampling");
+  xConfirmPara( m_confTop    % TComSPS::getWinUnitY(CHROMA_420) != 0, "Top conformance window offset must be an integer multiple of the specified chroma subsampling");
+  xConfirmPara( m_confBottom % TComSPS::getWinUnitY(CHROMA_420) != 0, "Bottom conformance window offset must be an integer multiple of the specified chroma subsampling");
+#undef xConfirmPara
+  return check_failed;
+}
+
+#endif
+
+
+//! \}
Index: branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 54)
+++ branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 54)
@@ -0,0 +1,87 @@
+
+/** \file     TAppEncLayerCfg.h
+    \brief    Handle encoder layer configuration parameters (header)
+*/
+#ifndef __TAPPENCLAYERCFG__
+#define __TAPPENCLAYERCFG__
+
+#include "TLibCommon/CommonDef.h"
+#include "TLibEncoder/TEncCfg.h"
+#include <sstream>
+
+using namespace std;
+#if SVC_EXTENSION
+class TAppEncCfg;
+#endif
+//! \ingroup TAppEncoder
+//! \{
+
+// ====================================================================================================================
+// Class definition
+// ====================================================================================================================
+
+/// encoder layer configuration class
+class TAppEncLayerCfg
+{
+  friend class TAppEncCfg;
+  friend class TAppEncTop;
+protected:
+  // file I/O0
+  string    m_cInputFile;                                     ///< source file name
+  string    m_cReconFile;                                     ///< output reconstruction file
+
+  Int       m_iFrameRate;                                     ///< source frame-rates (Hz)
+  Int       m_iSourceWidth;                                   ///< source width in pixel
+  Int       m_iSourceHeight;                                  ///< source height in pixel
+  Int       m_conformanceMode;
+  Int       m_confLeft;
+  Int       m_confRight;
+  Int       m_confTop;
+  Int       m_confBottom;
+  Int       m_aiPad[2];                                       ///< number of padded pixels for width and height
+  Int       m_iIntraPeriod;                                   ///< period of I-slice (random access period)
+  Double    m_fQP;                                            ///< QP value of key-picture (floating point)
+
+#if SVC_EXTENSION
+  Int       m_iWaveFrontSubstreams; //< If iWaveFrontSynchro, this is the number of substreams per frame (dependent tiles) or per tile (independent tiles).
+#endif
+
+  Int       m_iQP;                                            ///< QP value of key-picture (integer)
+  char*     m_pchdQPFile;                                     ///< QP offset for each slice (initialized from external file)
+  Int*      m_aidQP;                                          ///< array of slice QP values
+  TAppEncCfg* m_cAppEncCfg;                                   ///< pointer to app encoder config
+public:
+  TAppEncLayerCfg();
+  virtual ~TAppEncLayerCfg();
+
+public:
+  Void  create    ();                                         ///< create option handling class
+  Void  destroy   ();                                         ///< destroy option handling class
+  bool  parseCfg  ( const string& cfgFileName );              ///< parse layer configuration file to fill member variables
+
+  Void  xPrintParameter();
+  Bool  xCheckParameter();
+
+  Void    setAppEncCfg(TAppEncCfg* p) {m_cAppEncCfg = p;          }
+
+  string  getInputFile()              {return m_cInputFile;       }
+  string  getReconFile()              {return m_cReconFile;       }
+  Int     getFrameRate()              {return m_iFrameRate;       }
+  Int     getSourceWidth()            {return m_iSourceWidth;     }
+  Int     getSourceHeight()           {return m_iSourceHeight;    }
+  Int     getConformanceMode()        { return m_conformanceMode; }
+  Int*    getPad()                    {return m_aiPad;            }
+  Double  getFloatQP()                {return m_fQP;              }
+  Int     getConfLeft()               {return m_confLeft;         }
+  Int     getConfRight()              {return m_confRight;        }
+  Int     getConfTop()                {return m_confTop;          }
+  Int     getConfBottom()             {return m_confBottom;       }
+
+  Int     getIntQP()                  {return m_iQP;              } 
+  Int*    getdQPs()                   {return m_aidQP;            }
+
+}; // END CLASS DEFINITION TAppEncLayerCfg
+
+//! \}
+
+#endif // __TAPPENCLAYERCFG__
Index: branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncTop.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncTop.cpp	(revision 54)
@@ -1,37 +1,37 @@
 /* The copyright in this software is being made available under the BSD
- * License, included below. This software may be subject to other third party
- * and contributor rights, including patent rights, and no such rights are
- * granted under this license.  
- *
- * Copyright (c) 2010-2013, ITU/ISO/IEC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *  * Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
- *    be used to endorse or promote products derived from this software without
- *    specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
+* License, included below. This software may be subject to other third party
+* and contributor rights, including patent rights, and no such rights are
+* granted under this license.  
+*
+* Copyright (c) 2010-2013, ITU/ISO/IEC
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+*  * Redistributions of source code must retain the above copyright notice,
+*    this list of conditions and the following disclaimer.
+*  * Redistributions in binary form must reproduce the above copyright notice,
+*    this list of conditions and the following disclaimer in the documentation
+*    and/or other materials provided with the distribution.
+*  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
+*    be used to endorse or promote products derived from this software without
+*    specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
 
 /** \file     TAppEncTop.cpp
-    \brief    Encoder application class
+\brief    Encoder application class
 */
 
@@ -60,4 +60,10 @@
   m_totalBytes = 0;
   m_essentialBytes = 0;
+#if SVC_EXTENSION
+  for(UInt layer=0; layer < MAX_LAYERS; layer++)
+  {
+    m_apcTEncTop[layer] = &m_acTEncTop[layer];
+  }
+#endif
 }
 
@@ -66,8 +72,301 @@
 }
 
+#if SVC_EXTENSION
 Void TAppEncTop::xInitLibCfg()
 {
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    TComVPS vps;
+
+    vps.setMaxTLayers                       ( m_maxTempLayer );
+    if (m_maxTempLayer == 1)
+    {
+      vps.setTemporalNestingFlag(true);
+    }
+    vps.setMaxLayers                        ( 1 );
+    for(Int i = 0; i < MAX_TLAYER; i++)
+    {
+      vps.setNumReorderPics                 ( m_numReorderPics[i], i );
+      vps.setMaxDecPicBuffering             ( m_maxDecPicBuffering[i], i );
+    }
+    m_acTEncTop[layer].setVPS(&vps);
+    m_acTEncTop[layer].setFrameRate                    ( m_acLayerCfg[layer].getFrameRate() );
+    m_acTEncTop[layer].setFrameSkip                    ( m_FrameSkip );
+    m_acTEncTop[layer].setSourceWidth                  ( m_acLayerCfg[layer].getSourceWidth() );
+    m_acTEncTop[layer].setSourceHeight                 ( m_acLayerCfg[layer].getSourceHeight() );
+    m_acTEncTop[layer].setConformanceMode              ( m_acLayerCfg[layer].getConformanceMode() );
+    m_acTEncTop[layer].setConformanceWindow            ( m_acLayerCfg[layer].m_confLeft, m_acLayerCfg[layer].m_confRight, m_acLayerCfg[layer].m_confTop, m_acLayerCfg[layer].m_confBottom );
+    m_acTEncTop[layer].setFramesToBeEncoded            ( m_framesToBeEncoded );
+
+    m_acTEncTop[layer].setProfile(m_profile);
+    m_acTEncTop[layer].setLevel(m_levelTier, m_level);
+#if L0046_CONSTRAINT_FLAGS
+    m_acTEncTop[layer].setProgressiveSourceFlag(m_progressiveSourceFlag);
+    m_acTEncTop[layer].setInterlacedSourceFlag(m_interlacedSourceFlag);
+    m_acTEncTop[layer].setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
+    m_acTEncTop[layer].setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
+#endif
+
+#if REF_IDX_MFM
+    if(layer == 0)
+    {
+      m_acTEncTop[layer].setMFMEnabledFlag(false);
+    }
+    else
+    {
+      m_acTEncTop[layer].setMFMEnabledFlag(true);
+    }
+#endif
+    // set layer ID 
+    m_acTEncTop[layer].setLayerId ( layer ); 
+    m_acTEncTop[layer].setNumLayer ( m_numLayers );
+    m_acTEncTop[layer].setLayerEnc(m_apcTEncTop);
+
+    //====== Coding Structure ========
+    m_acTEncTop[layer].setIntraPeriod                  ( m_acLayerCfg[layer].m_iIntraPeriod );
+    m_acTEncTop[layer].setDecodingRefreshType          ( m_iDecodingRefreshType );
+    m_acTEncTop[layer].setGOPSize                      ( m_iGOPSize );
+    m_acTEncTop[layer].setGopList                      ( m_GOPList );
+    m_acTEncTop[layer].setExtraRPSs                    ( m_extraRPSs );
+    for(Int i = 0; i < MAX_TLAYER; i++)
+    {
+      m_acTEncTop[layer].setNumReorderPics             ( m_numReorderPics[i], i );
+      m_acTEncTop[layer].setMaxDecPicBuffering         ( m_maxDecPicBuffering[i], i );
+    }
+    for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
+    {
+      m_acTEncTop[layer].setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
+    }
+    m_acTEncTop[layer].setQP                           ( m_acLayerCfg[layer].getIntQP() );
+
+    m_acTEncTop[layer].setPad                          ( m_acLayerCfg[layer].getPad() );
+
+    m_acTEncTop[layer].setMaxTempLayer                 ( m_maxTempLayer );
+    m_acTEncTop[layer].setUseAMP( m_enableAMP );
+
+    //===== Slice ========
+
+    //====== Loop/Deblock Filter ========
+    m_acTEncTop[layer].setLoopFilterDisable            ( m_bLoopFilterDisable       );
+    m_acTEncTop[layer].setLoopFilterOffsetInPPS        ( m_loopFilterOffsetInPPS );
+    m_acTEncTop[layer].setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
+    m_acTEncTop[layer].setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
+    m_acTEncTop[layer].setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
+
+    //====== Motion search ========
+    m_acTEncTop[layer].setFastSearch                   ( m_iFastSearch  );
+    m_acTEncTop[layer].setSearchRange                  ( m_iSearchRange );
+    m_acTEncTop[layer].setBipredSearchRange            ( m_bipredSearchRange );
+
+    //====== Quality control ========
+    m_acTEncTop[layer].setMaxDeltaQP                   ( m_iMaxDeltaQP  );
+    m_acTEncTop[layer].setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
+
+    m_acTEncTop[layer].setChromaCbQpOffset             ( m_cbQpOffset     );
+    m_acTEncTop[layer].setChromaCrQpOffset             ( m_crQpOffset  );
+
+#if ADAPTIVE_QP_SELECTION
+    m_acTEncTop[layer].setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
+#endif
+
+    Int lowestQP;
+    lowestQP =  - 6*(g_bitDepthY - 8); // XXX: check
+
+    if ((m_iMaxDeltaQP == 0 ) && (m_acLayerCfg[layer].getIntQP() == lowestQP) && (m_useLossless == true))
+    {
+      m_bUseAdaptiveQP = false;
+    }
+    m_acTEncTop[layer].setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
+    m_acTEncTop[layer].setQPAdaptationRange            ( m_iQPAdaptationRange );
+
+    //====== Tool list ========
+    m_acTEncTop[layer].setUseSBACRD                    ( m_bUseSBACRD   );
+    m_acTEncTop[layer].setDeltaQpRD                    ( m_uiDeltaQpRD  );
+    m_acTEncTop[layer].setUseASR                       ( m_bUseASR      );
+    m_acTEncTop[layer].setUseHADME                     ( m_bUseHADME    );
+    m_acTEncTop[layer].setUseLossless                  ( m_useLossless );
+    m_acTEncTop[layer].setUseLComb                     ( m_bUseLComb    );
+    m_acTEncTop[layer].setdQPs                         ( m_acLayerCfg[layer].getdQPs() );
+    m_acTEncTop[layer].setUseRDOQ                      ( m_useRDOQ     );
+    m_acTEncTop[layer].setUseRDOQTS                    ( m_useRDOQTS   );
+#if L0232_RD_PENALTY
+    m_acTEncTop[layer].setRDpenalty                    ( m_rdPenalty );
+#endif
+    m_acTEncTop[layer].setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
+    m_acTEncTop[layer].setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
+    m_acTEncTop[layer].setQuadtreeTUMaxDepthInter      ( m_uiQuadtreeTUMaxDepthInter );
+    m_acTEncTop[layer].setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
+    m_acTEncTop[layer].setUseFastEnc                   ( m_bUseFastEnc  );
+    m_acTEncTop[layer].setUseEarlyCU                   ( m_bUseEarlyCU  ); 
+    m_acTEncTop[layer].setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
+    m_acTEncTop[layer].setUseCbfFastMode               ( m_bUseCbfFastMode  );
+    m_acTEncTop[layer].setUseEarlySkipDetection        ( m_useEarlySkipDetection );
+
+    m_acTEncTop[layer].setUseTransformSkip             ( m_useTransformSkip      );
+    m_acTEncTop[layer].setUseTransformSkipFast         ( m_useTransformSkipFast  );
+    m_acTEncTop[layer].setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
+    m_acTEncTop[layer].setPCMLog2MinSize               ( m_uiPCMLog2MinSize);
+    m_acTEncTop[layer].setUsePCM                       ( m_usePCM );
+    m_acTEncTop[layer].setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
+    m_acTEncTop[layer].setMaxNumMergeCand              ( m_maxNumMergeCand );
+
+
+    //====== Weighted Prediction ========
+    m_acTEncTop[layer].setUseWP                   ( m_useWeightedPred      );
+    m_acTEncTop[layer].setWPBiPred                ( m_useWeightedBiPred   );
+    //====== Parallel Merge Estimation ========
+    m_acTEncTop[layer].setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 );
+
+    //====== Slice ========
+    m_acTEncTop[layer].setSliceMode               ( m_sliceMode                );
+    m_acTEncTop[layer].setSliceArgument           ( m_sliceArgument            );
+
+    //====== Dependent Slice ========
+    m_acTEncTop[layer].setSliceSegmentMode        ( m_sliceSegmentMode         );
+    m_acTEncTop[layer].setSliceSegmentArgument    ( m_sliceSegmentArgument     );
+    Int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
+    if(m_sliceSegmentMode==FIXED_NUMBER_OF_LCU)
+    {
+      m_acTEncTop[layer].setSliceSegmentArgument ( m_sliceSegmentArgument * iNumPartInCU );
+    }
+    if(m_sliceMode==FIXED_NUMBER_OF_LCU)
+    {
+      m_acTEncTop[layer].setSliceArgument ( m_sliceArgument * iNumPartInCU );
+    }
+    if(m_sliceMode==FIXED_NUMBER_OF_TILES)
+    {
+      m_acTEncTop[layer].setSliceArgument ( m_sliceArgument );
+    }
+
+    if(m_sliceMode == 0 )
+    {
+      m_bLFCrossSliceBoundaryFlag = true;
+    }
+    m_acTEncTop[layer].setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
+    m_acTEncTop[layer].setUseSAO ( m_bUseSAO );
+    m_acTEncTop[layer].setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
+
+    m_acTEncTop[layer].setSaoLcuBoundary (m_saoLcuBoundary);
+    m_acTEncTop[layer].setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
+    m_acTEncTop[layer].setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
+    m_acTEncTop[layer].setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
+
+    m_acTEncTop[layer].setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
+    m_acTEncTop[layer].setRecoveryPointSEIEnabled( m_recoveryPointSEIEnabled );
+    m_acTEncTop[layer].setBufferingPeriodSEIEnabled( m_bufferingPeriodSEIEnabled );
+    m_acTEncTop[layer].setPictureTimingSEIEnabled( m_pictureTimingSEIEnabled );
+    m_acTEncTop[layer].setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled );
+    m_acTEncTop[layer].setFramePackingArrangementSEIType( m_framePackingSEIType );
+    m_acTEncTop[layer].setFramePackingArrangementSEIId( m_framePackingSEIId );
+    m_acTEncTop[layer].setFramePackingArrangementSEIQuincunx( m_framePackingSEIQuincunx );
+    m_acTEncTop[layer].setFramePackingArrangementSEIInterpretation( m_framePackingSEIInterpretation );
+    m_acTEncTop[layer].setDisplayOrientationSEIAngle( m_displayOrientationSEIAngle );
+    m_acTEncTop[layer].setTemporalLevel0IndexSEIEnabled( m_temporalLevel0IndexSEIEnabled );
+    m_acTEncTop[layer].setGradualDecodingRefreshInfoEnabled( m_gradualDecodingRefreshInfoEnabled );
+    m_acTEncTop[layer].setDecodingUnitInfoSEIEnabled( m_decodingUnitInfoSEIEnabled );
+    m_acTEncTop[layer].setUniformSpacingIdr          ( m_iUniformSpacingIdr );
+    m_acTEncTop[layer].setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
+    m_acTEncTop[layer].setNumRowsMinus1              ( m_iNumRowsMinus1 );
+    if(m_iUniformSpacingIdr==0)
+    {
+      m_acTEncTop[layer].setColumnWidth              ( m_pColumnWidth );
+      m_acTEncTop[layer].setRowHeight                ( m_pRowHeight );
+    }
+    m_acTEncTop[layer].xCheckGSParameters();
+    Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
+    if(uiTilesCount == 1)
+    {
+      m_bLFCrossTileBoundaryFlag = true; 
+    }
+    m_acTEncTop[layer].setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
+    m_acTEncTop[layer].setWaveFrontSynchro           ( m_iWaveFrontSynchro );
+    m_acTEncTop[layer].setWaveFrontSubstreams        ( m_acLayerCfg[layer].m_iWaveFrontSubstreams );
+    m_acTEncTop[layer].setTMVPModeId ( m_TMVPModeId );
+    m_acTEncTop[layer].setUseScalingListId           ( m_useScalingListId  );
+    m_acTEncTop[layer].setScalingListFile            ( m_scalingListFile   );
+    m_acTEncTop[layer].setSignHideFlag(m_signHideFlag);
+#if RATE_CONTROL_LAMBDA_DOMAIN
+    m_acTEncTop[layer].setUseRateCtrl         ( m_RCEnableRateControl );
+    m_acTEncTop[layer].setTargetBitrate       ( m_RCTargetBitrate );
+    m_acTEncTop[layer].setKeepHierBit         ( m_RCKeepHierarchicalBit );
+    m_acTEncTop[layer].setLCULevelRC          ( m_RCLCULevelRC );
+    m_acTEncTop[layer].setUseLCUSeparateModel ( m_RCUseLCUSeparateModel );
+    m_acTEncTop[layer].setInitialQP           ( m_RCInitialQP );
+    m_acTEncTop[layer].setForceIntraQP        ( m_RCForceIntraQP );
+#else
+    m_acTEncTop[layer].setUseRateCtrl     ( m_enableRateCtrl);
+    m_acTEncTop[layer].setTargetBitrate   ( m_targetBitrate);
+    m_acTEncTop[layer].setNumLCUInUnit    ( m_numLCUInUnit);
+#endif
+    m_acTEncTop[layer].setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
+    m_acTEncTop[layer].setCUTransquantBypassFlagValue(m_CUTransquantBypassFlagValue);
+    m_acTEncTop[layer].setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
+    m_acTEncTop[layer].setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
+    m_acTEncTop[layer].setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); 
+    m_acTEncTop[layer].setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
+    m_acTEncTop[layer].setAspectRatioIdc( m_aspectRatioIdc );
+    m_acTEncTop[layer].setSarWidth( m_sarWidth );
+    m_acTEncTop[layer].setSarHeight( m_sarHeight );
+    m_acTEncTop[layer].setOverscanInfoPresentFlag( m_overscanInfoPresentFlag );
+    m_acTEncTop[layer].setOverscanAppropriateFlag( m_overscanAppropriateFlag );
+    m_acTEncTop[layer].setVideoSignalTypePresentFlag( m_videoSignalTypePresentFlag );
+    m_acTEncTop[layer].setVideoFormat( m_videoFormat );
+    m_acTEncTop[layer].setVideoFullRangeFlag( m_videoFullRangeFlag );
+    m_acTEncTop[layer].setColourDescriptionPresentFlag( m_colourDescriptionPresentFlag );
+    m_acTEncTop[layer].setColourPrimaries( m_colourPrimaries );
+    m_acTEncTop[layer].setTransferCharacteristics( m_transferCharacteristics );
+    m_acTEncTop[layer].setMatrixCoefficients( m_matrixCoefficients );
+    m_acTEncTop[layer].setChromaLocInfoPresentFlag( m_chromaLocInfoPresentFlag );
+    m_acTEncTop[layer].setChromaSampleLocTypeTopField( m_chromaSampleLocTypeTopField );
+    m_acTEncTop[layer].setChromaSampleLocTypeBottomField( m_chromaSampleLocTypeBottomField );
+    m_acTEncTop[layer].setNeutralChromaIndicationFlag( m_neutralChromaIndicationFlag );
+    m_acTEncTop[layer].setDefaultDisplayWindow( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset );
+    m_acTEncTop[layer].setFrameFieldInfoPresentFlag( m_frameFieldInfoPresentFlag );
+    m_acTEncTop[layer].setPocProportionalToTimingFlag( m_pocProportionalToTimingFlag );
+    m_acTEncTop[layer].setNumTicksPocDiffOneMinus1   ( m_numTicksPocDiffOneMinus1    );
+    m_acTEncTop[layer].setBitstreamRestrictionFlag( m_bitstreamRestrictionFlag );
+    m_acTEncTop[layer].setTilesFixedStructureFlag( m_tilesFixedStructureFlag );
+    m_acTEncTop[layer].setMotionVectorsOverPicBoundariesFlag( m_motionVectorsOverPicBoundariesFlag );
+    m_acTEncTop[layer].setMinSpatialSegmentationIdc( m_minSpatialSegmentationIdc );
+    m_acTEncTop[layer].setMaxBytesPerPicDenom( m_maxBytesPerPicDenom );
+    m_acTEncTop[layer].setMaxBitsPerMinCuDenom( m_maxBitsPerMinCuDenom );
+    m_acTEncTop[layer].setLog2MaxMvLengthHorizontal( m_log2MaxMvLengthHorizontal );
+    m_acTEncTop[layer].setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
+#if SIGNAL_BITRATE_PICRATE_IN_VPS
+    TComBitRatePicRateInfo *bitRatePicRateInfo = m_cTEncTop[layer].getVPS()->getBitratePicrateInfo();
+    // The number of bit rate/pic rate have to equal to number of sub-layers.
+    if(m_bitRatePicRateMaxTLayers)
+    {
+      assert(m_bitRatePicRateMaxTLayers == m_cTEncTop[layer].getVPS()->getMaxTLayers());
+    }
+    for(Int i = 0; i < m_bitRatePicRateMaxTLayers; i++)
+    {
+      bitRatePicRateInfo->setBitRateInfoPresentFlag( i, m_bitRateInfoPresentFlag[i] );
+      if( bitRatePicRateInfo->getBitRateInfoPresentFlag(i) )
+      {
+        bitRatePicRateInfo->setAvgBitRate(i, m_avgBitRate[i]);
+        bitRatePicRateInfo->setMaxBitRate(i, m_maxBitRate[i]);
+      }
+    }
+    for(Int i = 0; i < m_bitRatePicRateMaxTLayers; i++)
+    {
+      bitRatePicRateInfo->setPicRateInfoPresentFlag( i, m_picRateInfoPresentFlag[i] );
+      if( bitRatePicRateInfo->getPicRateInfoPresentFlag(i) )
+      {
+        bitRatePicRateInfo->setAvgPicRate     (i, m_avgPicRate[i]);
+        bitRatePicRateInfo->setConstantPicRateIdc(i, m_constantPicRateIdc[i]);
+      }
+    }
+#endif
+#if REF_IDX_FRAMEWORK
+    m_acTEncTop[layer].setElRapSliceTypeB(layer == 0? 0 : m_elRapSliceBEnabled);
+#endif
+  }
+}
+#else
+Void TAppEncTop::xInitLibCfg()
+{
   TComVPS vps;
-  
+
   vps.setMaxTLayers                       ( m_maxTempLayer );
   if (m_maxTempLayer == 1)
@@ -91,5 +390,5 @@
   m_cTEncTop.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
 #endif
-  
+
   m_cTEncTop.setFrameRate                    ( m_iFrameRate );
   m_cTEncTop.setFrameSkip                    ( m_FrameSkip );
@@ -98,5 +397,5 @@
   m_cTEncTop.setConformanceWindow            ( m_confLeft, m_confRight, m_confTop, m_confBottom );
   m_cTEncTop.setFramesToBeEncoded            ( m_framesToBeEncoded );
-  
+
   //====== Coding Structure ========
   m_cTEncTop.setIntraPeriod                  ( m_iIntraPeriod );
@@ -115,12 +414,12 @@
   }
   m_cTEncTop.setQP                           ( m_iQP );
-  
+
   m_cTEncTop.setPad                          ( m_aiPad );
-    
+
   m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayer );
   m_cTEncTop.setUseAMP( m_enableAMP );
-  
+
   //===== Slice ========
-  
+
   //====== Loop/Deblock Filter ========
   m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable       );
@@ -155,5 +454,5 @@
   m_cTEncTop.setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
   m_cTEncTop.setQPAdaptationRange            ( m_iQPAdaptationRange );
-  
+
   //====== Tool list ========
   m_cTEncTop.setUseSBACRD                    ( m_bUseSBACRD   );
@@ -186,5 +485,5 @@
   m_cTEncTop.setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
   m_cTEncTop.setMaxNumMergeCand              ( m_maxNumMergeCand );
-  
+
 
   //====== Weighted Prediction ========
@@ -214,5 +513,5 @@
     m_cTEncTop.setSliceArgument ( m_sliceArgument );
   }
-  
+
   if(m_sliceMode == 0 )
   {
@@ -336,8 +635,26 @@
 #endif
 }
+#endif
 
 Void TAppEncTop::xCreateLib()
 {
   // Video I/O
+#if SVC_EXTENSION
+  // initialize global variables
+  initROM();
+
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    m_acTVideoIOYuvInputFile[layer].open( (Char *)m_acLayerCfg[layer].getInputFile().c_str(),  false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
+    m_acTVideoIOYuvInputFile[layer].skipFrames(m_FrameSkip, m_acLayerCfg[layer].getSourceWidth() - m_acLayerCfg[layer].getPad()[0], m_acLayerCfg[layer].getSourceHeight() - m_acLayerCfg[layer].getPad()[1]);
+
+    if (!m_acLayerCfg[layer].getReconFile().empty())
+    {
+      m_acTVideoIOYuvReconFile[layer].open((Char *)m_acLayerCfg[layer].getReconFile().c_str(), true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // write mode
+    }
+
+    m_acTEncTop[layer].create();
+  }
+#else
   m_cTVideoIOYuvInputFile.open( m_pchInputFile,     false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
   m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
@@ -345,7 +662,8 @@
   if (m_pchReconFile)
     m_cTVideoIOYuvReconFile.open(m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC);  // write mode
-  
+
   // Neo Decoder
   m_cTEncTop.create();
+#endif
 }
 
@@ -353,14 +671,34 @@
 {
   // Video I/O
+#if SVC_EXTENSION
+  // destroy ROM
+  destroyROM();
+
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    m_acTVideoIOYuvInputFile[layer].close();
+    m_acTVideoIOYuvReconFile[layer].close();
+
+    m_acTEncTop[layer].destroy();
+  }
+#else
   m_cTVideoIOYuvInputFile.close();
   m_cTVideoIOYuvReconFile.close();
-  
+
   // Neo Decoder
   m_cTEncTop.destroy();
+#endif
 }
 
 Void TAppEncTop::xInitLib()
 {
+#if SVC_EXTENSION
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    m_acTEncTop[layer].init();
+  }
+#else
   m_cTEncTop.init();
+#endif
 }
 
@@ -370,37 +708,235 @@
 
 /**
- - create internal class
- - initialize internal variable
- - until the end of input YUV file, call encoding function in TEncTop class
- - delete allocated buffers
- - destroy internal class
- .
- */
+- create internal class
+- initialize internal variable
+- until the end of input YUV file, call encoding function in TEncTop class
+- delete allocated buffers
+- destroy internal class
+.
+*/
+#if SVC_EXTENSION
 Void TAppEncTop::encode()
 {
-  fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out);
+  fstream bitstreamFile(m_pBitstreamFile, fstream::binary | fstream::out);
   if (!bitstreamFile)
   {
-    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile);
+    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pBitstreamFile);
     exit(EXIT_FAILURE);
   }
 
-  TComPicYuv*       pcPicYuvOrg = new TComPicYuv;
+  TComPicYuv*       pcPicYuvOrg [MAX_LAYERS];
   TComPicYuv*       pcPicYuvRec = NULL;
-  
+
   // initialize internal class & member variables
   xInitLibCfg();
   xCreateLib();
   xInitLib();
-  
+
+  // main encoder loop
+  Int   iNumEncoded = 0, iTotalNumEncoded = 0;
+  Bool  bEos = false;
+
+  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
+
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    // allocate original YUV buffer
+    pcPicYuvOrg[layer] = new TComPicYuv;
+#if SVC_UPSAMPLING
+    pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#else
+    pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
+#endif
+  }
+
+#if AVC_SYNTAX
+  if( !m_BLSyntaxFile )
+  {
+    printf( "Wrong base layer syntax input file\n" );
+    exit(EXIT_FAILURE);
+  }
+  fstream streamSyntaxFile( m_BLSyntaxFile, fstream::in | fstream::binary );
+  if( !streamSyntaxFile.good() )
+  {
+    printf( "Base layer syntax input reading error\n" );
+    exit(EXIT_FAILURE);
+  }
+  m_acTEncTop[0].setBLSyntaxFile( &streamSyntaxFile );
+#endif
+
+  Bool bFirstFrame = true;
+  while ( !bEos )
+  {
+    // Read enough frames 
+    Bool bFramesReadyToCode = false;
+    while(!bFramesReadyToCode)
+    {
+      for(UInt layer=0; layer<m_numLayers; layer++)
+      {
+        // get buffers
+        xGetBuffer(pcPicYuvRec, layer);
+
+        // read input YUV file
+        m_acTVideoIOYuvInputFile[layer].read( pcPicYuvOrg[layer], m_acLayerCfg[layer].getPad() );
+
+        if(layer == m_numLayers-1)
+        {
+          // increase number of received frames
+          m_iFrameRcvd++;
+          // check end of file
+          bEos = (m_iFrameRcvd == m_framesToBeEncoded);
+        }
+
+        m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer] );
+      }
+
+      bFramesReadyToCode = !(!bFirstFrame && ( m_acTEncTop[m_numLayers-1].getNumPicRcvd() != m_iGOPSize && m_iGOPSize ) && !bEos );
+    }
+    Bool flush = 0;
+    // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
+    if (m_acTVideoIOYuvInputFile[m_numLayers-1].isEof())
+    {
+      flush = true;
+      bEos = true;
+      m_iFrameRcvd--;
+      m_acTEncTop[m_numLayers-1].setFramesToBeEncoded(m_iFrameRcvd);
+    }
+
+    // loop through frames in one GOP 
+    for ( UInt iPicIdInGOP=0; iPicIdInGOP < (bFirstFrame? 1:m_iGOPSize); iPicIdInGOP++ )
+    {
+      // layer by layer for each frame
+      for(UInt layer=0; layer<m_numLayers; layer++)
+      {
+        // call encoding function for one frame
+        m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP );
+      }
+    }
+
+    iTotalNumEncoded = 0;
+    for(UInt layer=0; layer<m_numLayers; layer++)
+    {
+      // write bistream to file if necessary
+      iNumEncoded = m_acTEncTop[layer].getNumPicRcvd();
+      if ( iNumEncoded > 0 )
+      {
+        xWriteRecon(layer, iNumEncoded);
+        iTotalNumEncoded += iNumEncoded;
+      }
+      m_acTEncTop[layer].setNumPicRcvd( 0 );
+    }
+
+    // write bitstream out
+    if(iTotalNumEncoded)
+    {
+      xWriteStream(bitstreamFile, iTotalNumEncoded, outputAccessUnits);
+      outputAccessUnits.clear();
+    }
+
+    // print out summary
+    if (bEos)
+    {
+      printOutSummary();
+    }
+
+    bFirstFrame = false;
+  }
+  // delete original YUV buffer
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    pcPicYuvOrg[layer]->destroy();
+    delete pcPicYuvOrg[layer];
+    pcPicYuvOrg[layer] = NULL;
+
+    // delete used buffers in encoder class
+    m_acTEncTop[layer].deletePicBuffer();
+  }
+
+#if AVC_SYNTAX
+  if( streamSyntaxFile.is_open() )
+  {
+    streamSyntaxFile.close();
+  }
+#endif
+
+  // delete buffers & classes
+  xDeleteBuffer();
+  xDestroyLib();
+
+  printRateSummary();
+
+  return;
+}
+
+Void TAppEncTop::printOutSummary()
+{
+  UInt layer;
+
+  // set frame rate
+  for(layer = 0; layer < m_numLayers; layer++)
+  {
+    m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate());
+    m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
+    m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
+    m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
+  }
+
+  //-- all
+  printf( "\n\nSUMMARY --------------------------------------------------------\n" );
+  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
+  for(layer = 0; layer < m_numLayers; layer++)
+  {
+    m_gcAnalyzeAll[layer].printOut('a', layer);
+  }
+
+  printf( "\n\nI Slices--------------------------------------------------------\n" );
+  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
+  for(layer = 0; layer < m_numLayers; layer++)
+  {
+    m_gcAnalyzeI[layer].printOut('i', layer);
+  }
+
+  printf( "\n\nP Slices--------------------------------------------------------\n" );
+  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
+  for(layer = 0; layer < m_numLayers; layer++)
+  {
+    m_gcAnalyzeP[layer].printOut('p', layer);
+  }
+
+  printf( "\n\nB Slices--------------------------------------------------------\n" );
+  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
+  for(layer = 0; layer < m_numLayers; layer++)
+  {
+    m_gcAnalyzeB[layer].printOut('b', layer);
+  }
+}
+
+#else
+Void TAppEncTop::encode()
+{
+  fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out);
+  if (!bitstreamFile)
+  {
+    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile);
+    exit(EXIT_FAILURE);
+  }
+
+  TComPicYuv*       pcPicYuvOrg = new TComPicYuv;
+  TComPicYuv*       pcPicYuvRec = NULL;
+
+  // initialize internal class & member variables
+  xInitLibCfg();
+  xCreateLib();
+  xInitLib();
+
   // main encoder loop
   Int   iNumEncoded = 0;
   Bool  bEos = false;
-  
+
   list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
 
   // allocate original YUV buffer
   pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
-  
+
   while ( !bEos )
   {
@@ -410,8 +946,8 @@
     // read input YUV file
     m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, m_aiPad );
-    
+
     // increase number of received frames
     m_iFrameRcvd++;
-    
+
     bEos = (m_iFrameRcvd == m_framesToBeEncoded);
 
@@ -428,5 +964,5 @@
     // call encoding function for one frame
     m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded );
-    
+
     // write bistream to file if necessary
     if ( iNumEncoded > 0 )
@@ -443,16 +979,17 @@
   delete pcPicYuvOrg;
   pcPicYuvOrg = NULL;
-  
+
   // delete used buffers in encoder class
   m_cTEncTop.deletePicBuffer();
-  
+
   // delete buffers & classes
   xDeleteBuffer();
   xDestroyLib();
-  
+
   printRateSummary();
 
   return;
 }
+#endif
 
 // ====================================================================================================================
@@ -461,13 +998,92 @@
 
 /**
- - application has picture buffer list with size of GOP
- - picture buffer list acts as ring buffer
- - end of the list has the latest picture
- .
- */
+- application has picture buffer list with size of GOP
+- picture buffer list acts as ring buffer
+- end of the list has the latest picture
+.
+*/
+#if SVC_EXTENSION
+Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer)
+{
+  assert( m_iGOPSize > 0 );
+
+  // org. buffer
+  if ( m_acListPicYuvRec[layer].size() == (UInt)m_iGOPSize )
+  {
+    rpcPicYuvRec = m_acListPicYuvRec[layer].popFront();
+
+  }
+  else
+  {
+    rpcPicYuvRec = new TComPicYuv;
+
+#if SVC_UPSAMPLING
+    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#else
+    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
+#endif
+
+  }
+  m_acListPicYuvRec[layer].pushBack( rpcPicYuvRec );
+}
+
+Void TAppEncTop::xDeleteBuffer( )
+{
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_acListPicYuvRec[layer].begin();
+
+    Int iSize = Int( m_acListPicYuvRec[layer].size() );
+
+    for ( Int i = 0; i < iSize; i++ )
+    {
+      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
+      pcPicYuvRec->destroy();
+      delete pcPicYuvRec; pcPicYuvRec = NULL;
+    }
+  }  
+}
+
+Void TAppEncTop::xWriteRecon(UInt layer, Int iNumEncoded)
+{
+  Int i;
+
+  TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end();
+
+  for ( i = 0; i < iNumEncoded; i++ )
+  {
+    --iterPicYuvRec;
+  }
+
+  for ( i = 0; i < iNumEncoded; i++ )
+  {
+    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
+    if (!m_acLayerCfg[layer].getReconFile().empty())
+    {
+      m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(), 
+        m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom() );
+    }
+  }
+}
+
+Void TAppEncTop::xWriteStream(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
+{
+  Int i;
+
+  list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
+
+  for ( i = 0; i < iNumEncoded; i++ )
+  {
+    const AccessUnit& au = *(iterBitstream++);
+    const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
+    rateStatsAccum(au, stats);
+  }
+}
+
+#else // SVC_EXTENSION
 Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec)
 {
   assert( m_iGOPSize > 0 );
-  
+
   // org. buffer
   if ( m_cListPicYuvRec.size() == (UInt)m_iGOPSize )
@@ -479,5 +1095,5 @@
   {
     rpcPicYuvRec = new TComPicYuv;
-    
+
     rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
 
@@ -489,7 +1105,7 @@
 {
   TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvRec.begin();
-  
+
   Int iSize = Int( m_cListPicYuvRec.size() );
-  
+
   for ( Int i = 0; i < iSize; i++ )
   {
@@ -498,21 +1114,21 @@
     delete pcPicYuvRec; pcPicYuvRec = NULL;
   }
-  
+
 }
 
 /** \param iNumEncoded  number of encoded frames
- */
+*/
 Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
 {
   Int i;
-  
+
   TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
   list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
-  
+
   for ( i = 0; i < iNumEncoded; i++ )
   {
     --iterPicYuvRec;
   }
-  
+
   for ( i = 0; i < iNumEncoded; i++ )
   {
@@ -528,8 +1144,9 @@
   }
 }
+#endif
 
 /**
- *
- */
+*
+*/
 void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& annexBsizes)
 {
@@ -572,5 +1189,9 @@
 void TAppEncTop::printRateSummary()
 {
+#if SVC_EXTENSION
+  Double time = (Double) m_iFrameRcvd / m_acLayerCfg[m_numLayers-1].getFrameRate();
+#else
   Double time = (Double) m_iFrameRcvd / m_iFrameRate;
+#endif
   printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time);
 #if VERBOSE_RATE
Index: branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncTop.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncTop.h	(revision 54)
@@ -59,4 +59,12 @@
 private:
   // class interface
+#if SVC_EXTENSION
+  TEncTop                    m_acTEncTop [MAX_LAYERS];                    ///< encoder class
+  TEncTop*                   m_apcTEncTop [MAX_LAYERS];                   ///< encoder pointer class
+  TVideoIOYuv                m_acTVideoIOYuvInputFile [MAX_LAYERS];       ///< input YUV file
+  TVideoIOYuv                m_acTVideoIOYuvReconFile [MAX_LAYERS];       ///< output reconstruction file
+
+  TComList<TComPicYuv*>      m_acListPicYuvRec [MAX_LAYERS];              ///< list of reconstruction YUV files
+#else
   TEncTop                    m_cTEncTop;                    ///< encoder class
   TVideoIOYuv                m_cTVideoIOYuvInputFile;       ///< input YUV file
@@ -64,4 +72,5 @@
   
   TComList<TComPicYuv*>      m_cListPicYuvRec;              ///< list of reconstruction YUV files
+#endif
   
   Int                        m_iFrameRcvd;                  ///< number of received frames
@@ -77,5 +86,9 @@
   
   /// obtain required buffers
+#if SVC_EXTENSION
+  Void xGetBuffer(TComPicYuv*& rpcPicYuvRec, UInt layer);
+#else
   Void xGetBuffer(TComPicYuv*& rpcPicYuvRec);
+#endif
   
   /// delete allocated buffers
@@ -83,5 +96,11 @@
   
   // file I/O
+#if SVC_EXTENSION
+  Void xWriteRecon(UInt layer, Int iNumEncoded);
+  Void xWriteStream(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits);
+  Void printOutSummary();
+#else
   Void xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits); ///< write bitstream to file
+#endif
   void rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& stats);
   void printRateSummary();
@@ -92,5 +111,9 @@
   
   Void        encode      ();                               ///< main encoding function
+#if SVC_EXTENSION
+  TEncTop&    getTEncTop  (UInt layer)   { return  m_acTEncTop[layer]; }      ///< return encoder class pointer reference
+#else
   TEncTop&    getTEncTop  ()   { return  m_cTEncTop; }      ///< return encoder class pointer reference
+#endif
 };// END CLASS DEFINITION TAppEncTop
 
Index: branches/HM-10.0-dev-SHM/source/App/TAppEncoder/encmain.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppEncoder/encmain.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/App/TAppEncoder/encmain.cpp	(revision 54)
@@ -57,5 +57,5 @@
   // print information
   fprintf( stdout, "\n" );
-  fprintf( stdout, "HM software: Encoder Version [%s]", NV_VERSION );
+  fprintf( stdout, "SHM software: Encoder Version [%s]", NV_VERSION );
   fprintf( stdout, NVM_ONOS );
   fprintf( stdout, NVM_COMPILEDBY );
Index: branches/HM-10.0-dev-SHM/source/Lib/TAppCommon/program_options_lite.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TAppCommon/program_options_lite.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TAppCommon/program_options_lite.h	(revision 54)
@@ -209,5 +209,57 @@
         return *this;
       }
-      
+#if 1 //SVC_EXTENSION
+      template<typename T>
+      OptionSpecific&
+        operator()(const std::string& name, T* storage, T default_val, unsigned uiMaxNum, const std::string& desc = "" )
+      {
+        std::string cNameBuffer;
+        std::string cDescriptionBuffer;
+
+        cNameBuffer       .resize( name.size() + 10 );
+        cDescriptionBuffer.resize( desc.size() + 10 );
+
+        for ( unsigned int uiK = 0; uiK < uiMaxNum; uiK++ )
+        {
+          // isn't there are sprintf function for string??
+          sprintf((char*) cNameBuffer.c_str()       ,name.c_str(),uiK,uiK);
+          sprintf((char*) cDescriptionBuffer.c_str(),desc.c_str(),uiK,uiK);
+
+          size_t pos = cNameBuffer.find_first_of('\0');
+          if(pos != std::string::npos)
+            cNameBuffer.resize(pos);
+      
+          parent.addOption(new Option<T>( cNameBuffer, (storage[uiK]), default_val, cDescriptionBuffer ));
+        }
+
+        return *this;
+      }
+
+      template<typename T>
+      OptionSpecific&
+        operator()(const std::string& name, T** storage, T default_val, unsigned uiMaxNum, const std::string& desc = "" )
+      {
+        std::string cNameBuffer;
+        std::string cDescriptionBuffer;
+
+        cNameBuffer       .resize( name.size() + 10 );
+        cDescriptionBuffer.resize( desc.size() + 10 );
+
+        for ( unsigned int uiK = 0; uiK < uiMaxNum; uiK++ )
+        {
+          // isn't there are sprintf function for string??
+          sprintf((char*) cNameBuffer.c_str()       ,name.c_str(),uiK,uiK);
+          sprintf((char*) cDescriptionBuffer.c_str(),desc.c_str(),uiK,uiK);
+
+          size_t pos = cNameBuffer.find_first_of('\0');
+          if(pos != std::string::npos)
+            cNameBuffer.resize(pos);
+
+          parent.addOption(new Option<T>( cNameBuffer, *(storage[uiK]), default_val, cDescriptionBuffer ));
+        }
+
+        return *this;
+      }
+#endif
       /**
        * Add option described by name to the parent Options list,
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/CommonDef.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/CommonDef.h	(revision 54)
@@ -56,5 +56,5 @@
 // ====================================================================================================================
 
-#define NV_VERSION        "10.0"                 ///< Current software version
+#define NV_VERSION        "1.2"                 ///< Current software version
 
 // ====================================================================================================================
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/ContextTables.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/ContextTables.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/ContextTables.h	(revision 54)
@@ -92,4 +92,7 @@
 #define NUM_SAO_MERGE_FLAG_CTX        1       ///< number of context models for SAO merge flags
 #define NUM_SAO_TYPE_IDX_CTX          1       ///< number of context models for SAO type index
+#if INTRA_BL
+#define NUM_INTRA_BL_PRED_CTX         3
+#endif
 
 #define NUM_TRANSFORMSKIP_FLAG_CTX    1       ///< number of context models for transform skipping 
@@ -327,4 +330,13 @@
 };
 
+#if INTRA_BL
+static const UChar 
+INIT_INTRA_BL_PRED_FLAG[3][NUM_INTRA_BL_PRED_CTX] = 
+{
+  { 185,  185,  201, }, 
+  { 197,  197,  185, }, 
+  { 197,  197,  185, }, 
+};
+#endif
 static const UChar
 INIT_TRANSFORMSKIP_FLAG[3][2*NUM_TRANSFORMSKIP_FLAG_CTX] = 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/NAL.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/NAL.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/NAL.h	(revision 54)
@@ -47,4 +47,7 @@
   NalUnitType m_nalUnitType; ///< nal_unit_type
   UInt        m_temporalId;  ///< temporal_id
+#if SVC_EXTENSION
+  UInt        m_layerId;   ///< layer id
+#endif
   UInt        m_reservedZero6Bits; ///< reserved_zero_6bits
 
@@ -53,7 +56,13 @@
     NalUnitType nalUnitType,
     Int         temporalId = 0,
+#if SVC_EXTENSION
+    UInt        layerId = 0,
+#endif
     Int         reservedZero6Bits = 0)
     :m_nalUnitType (nalUnitType)
     ,m_temporalId  (temporalId)
+#if SVC_EXTENSION
+    ,m_layerId   (layerId)
+#endif
     ,m_reservedZero6Bits(reservedZero6Bits)
   {}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComDataCU.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComDataCU.cpp	(revision 54)
@@ -359,4 +359,8 @@
   m_uiTotalBins        = 0;
   m_uiNumPartition     = pcPic->getNumPartInCU();
+
+#if SVC_EXTENSION
+  m_layerId           = pcPic->getLayerId();
+#endif 
   
   for(Int i=0; i<pcPic->getNumPartInCU(); i++)
@@ -1647,10 +1651,48 @@
   pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
   
+#if INTRA_BL
+  iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) && ( !pcTempCU->isIntraBL( uiTempPartIdx ) ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
+#else
   iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
+#endif
   
   // Get intra direction of above PU
   pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, true );
   
+#if INTRA_BL
+  iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) && ( !pcTempCU->isIntraBL( uiTempPartIdx ) ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
+#else
   iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
+#endif 
+  
+#if SVC_BL_CAND_INTRA
+  if(m_layerId > 0)
+  {
+    UInt uiCUAddrBase, uiAbsPartAddrBase;
+    pcTempCU = getBaseColCU( uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase );
+
+    if(pcTempCU->getPredictionMode( uiAbsPartAddrBase ) == MODE_INTRA )
+    {
+      Int iColBaseDir = pcTempCU->getLumaIntraDir( uiAbsPartAddrBase );
+      if( iColBaseDir != iAboveIntraDir && iColBaseDir != iLeftIntraDir && iAboveIntraDir != iLeftIntraDir)
+      {
+        uiIntraDirPred[0] = iColBaseDir;
+        uiIntraDirPred[1] = iLeftIntraDir;
+        uiIntraDirPred[2] = iAboveIntraDir;
+        if( piMode )
+        {
+          *piMode = 2;
+        }
+        uiPredNum = 3;
+        return uiPredNum;
+      }
+      else 
+      {
+        iAboveIntraDir = (iColBaseDir == iLeftIntraDir) ? iAboveIntraDir : iLeftIntraDir;
+        iLeftIntraDir  = iColBaseDir;
+      }
+    }
+  }
+#endif
   
   uiPredNum = 3;
@@ -1730,5 +1772,9 @@
   UInt log2CbSize = g_aucConvertToBit[getWidth( absPartIdx )] + 2;
   PartSize  partSize  = getPartitionSize( absPartIdx );
+#if INTRA_BL
+  UInt quadtreeTUMaxDepth = isIntra( absPartIdx ) ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter(); 
+#else
   UInt quadtreeTUMaxDepth = getPredictionMode( absPartIdx ) == MODE_INTRA ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter(); 
+#endif
   Int intraSplitFlag = ( getPredictionMode( absPartIdx ) == MODE_INTRA && partSize == SIZE_NxN ) ? 1 : 0;
   Int interSplitFlag = ((quadtreeTUMaxDepth == 1) && (getPredictionMode( absPartIdx ) == MODE_INTER) && (partSize != SIZE_2Nx2N) );
@@ -1752,4 +1798,71 @@
   return log2MinTUSizeInCU;
 }
+
+#if INTRA_BL
+UInt TComDataCU::getCtxIntraBLFlag( UInt uiAbsPartIdx )
+{
+  TComDataCU* pcTempCU;
+  UInt        uiTempPartIdx;
+  UInt        uiCtx = 0;
+  
+  // Get BCBP of left PU
+#if DEPENDENT_SLICES
+  Bool bDepSliceRestriction = ( !m_pcSlice->getPPS()->getDependentSliceEnabledFlag());
+  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, bDepSliceRestriction );
+#else
+  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
+#endif  
+  uiCtx    = ( pcTempCU ) ? pcTempCU->isIntraBL( uiTempPartIdx ) : 0;
+  
+  // Get BCBP of above PU
+#if DEPENDENT_SLICES
+  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, bDepSliceRestriction );
+#else
+  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
+#endif  
+  uiCtx   += ( pcTempCU ) ? pcTempCU->isIntraBL( uiTempPartIdx ) : 0;
+  
+  return uiCtx;
+}
+#endif
+
+#if REF_IDX_ME_ZEROMV
+Bool TComDataCU::xCheckZeroMVILRMerge(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
+{
+  Bool checkZeroMVILR = true;
+
+  if(uhInterDir&0x1)  //list0
+  {
+    Int refIdxL0 = cMvFieldL0.getRefIdx();
+    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->getIsILR())
+      checkZeroMVILR &= (cMvFieldL0.getHor() == 0 && cMvFieldL0.getVer() == 0);
+  }
+  if(uhInterDir&0x2)  //list1
+  {
+    Int refIdxL1  = cMvFieldL1.getRefIdx();
+    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->getIsILR())
+      checkZeroMVILR &= (cMvFieldL1.getHor() == 0 && cMvFieldL1.getVer() == 0);
+  }
+
+  return checkZeroMVILR;
+}
+
+Bool TComDataCU::xCheckZeroMVILRMvdL1Zero(Int iRefList, Int iRefIdx, Int MvpIdx)
+{
+  RefPicList eRefPicList = iRefList > 0? REF_PIC_LIST_1: REF_PIC_LIST_0;
+  assert(eRefPicList == REF_PIC_LIST_1);
+
+  Bool checkZeroMVILR = true;
+
+  if(getSlice()->getRefPic(eRefPicList, iRefIdx)->getIsILR())
+  {
+    AMVPInfo* pcAMVPInfo = getCUMvField(eRefPicList)->getAMVPInfo();
+    TComMv    cMv        = pcAMVPInfo->m_acMvCand[MvpIdx];
+    checkZeroMVILR &= (cMv.getHor() == 0 && cMv.getVer() == 0);
+  }
+
+  return checkZeroMVILR;
+}
+#endif
 
 UInt TComDataCU::getCtxSkipFlag( UInt uiAbsPartIdx )
@@ -2406,4 +2519,60 @@
   deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
   deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
+#if SVC_MVP
+  // BL collocated
+  TComDataCU *pcColCU = 0;
+  UInt uiCUAddrBase, uiAbsPartAddrBase ;
+  TComMvField cMvFieldBaseColCU[2];
+  if(m_layerId)  
+  {
+#if MV_SCALING_POS_FIX
+    pcColCU = getBaseColCU( xP + nPSW/2, yP + nPSH/2, uiCUAddrBase, uiAbsPartAddrBase );
+#else
+    UInt uiPartIdxCenter;
+    xDeriveCenterIdx( cCurPS, uiPUIdx, uiPartIdxCenter );
+    uiPartIdxCenter -= m_uiAbsIdxInLCU;
+    pcColCU = getBaseColCU( uiPartIdxCenter, uiCUAddrBase, uiAbsPartAddrBase );
+#endif
+    
+#if INTRA_BL
+    if( pcColCU && pcColCU->isIntraBL( uiAbsPartAddrBase ) )
+    {
+      pcColCU = NULL;
+    }
+#endif
+    
+    if(pcColCU && !pcColCU->isIntra( uiAbsPartAddrBase ) )
+    {
+      abCandIsInter[iCount] = true;
+
+      // get interDir
+      puhInterDirNeighbours[iCount] = pcColCU->getInterDir( uiAbsPartAddrBase );
+
+      pcMvFieldNeighbours[(iCount << 1)].setMvField( TComMv(0,0), -1);
+      pcMvFieldNeighbours[(iCount << 1) + 1].setMvField( TComMv(0,0), -1);
+
+      if( puhInterDirNeighbours[iCount] & 1 )
+      {
+        pcColCU->getMvField( pcColCU, uiAbsPartAddrBase, REF_PIC_LIST_0, cMvFieldBaseColCU[0]);
+        scaleBaseMV( pcMvFieldNeighbours[iCount<<1], cMvFieldBaseColCU[0] );
+      }
+
+      if ( getSlice()->isInterB() && puhInterDirNeighbours[iCount] & 2 )
+      {
+        pcColCU->getMvField( pcColCU, uiAbsPartAddrBase, REF_PIC_LIST_1, cMvFieldBaseColCU[1] );
+        scaleBaseMV( pcMvFieldNeighbours[(iCount<<1)+1], cMvFieldBaseColCU[1] );
+      }
+
+      if( puhInterDirNeighbours[iCount] > 0 )
+      {
+        if ( mrgCandIdx == iCount )
+        {
+          return;
+        }
+        iCount ++;
+      }
+    }
+  }
+#endif
 
   //left
@@ -2411,6 +2580,15 @@
   TComDataCU* pcCULeft = 0;
   pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
+#if INTRA_BL
+  if( pcCULeft && pcCULeft->isIntraBL( uiLeftPartIdx ) )
+  {
+    pcCULeft = NULL;
+  }
+#endif
   Bool isAvailableA1 = pcCULeft &&
   pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
+#if SVC_MVP
+  ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCULeft->hasEqualMotion( uiLeftPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0])) &&
+#endif
   !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
   !pcCULeft->isIntra( uiLeftPartIdx ) ;
@@ -2442,5 +2620,14 @@
   TComDataCU* pcCUAbove = 0;
   pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
+#if INTRA_BL
+  if( pcCUAbove && pcCUAbove->isIntraBL( uiAbovePartIdx ) )
+  {
+    pcCUAbove = NULL;
+  }
+#endif
   Bool isAvailableB1 = pcCUAbove &&
+#if SVC_MVP
+  ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0] )) &&
+#endif
   pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
   !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
@@ -2473,5 +2660,14 @@
   TComDataCU* pcCUAboveRight = 0;
   pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
+#if INTRA_BL
+  if( pcCUAboveRight && pcCUAboveRight->isIntraBL( uiAboveRightPartIdx ) )
+  {
+    pcCUAboveRight = NULL;
+  }
+#endif
   Bool isAvailableB0 = pcCUAboveRight &&
+#if SVC_MVP
+  ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCUAboveRight->hasEqualMotion( uiAboveRightPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0] )) &&
+#endif
   pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
   !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
@@ -2500,9 +2696,22 @@
 
   //left bottom
+#if SVC_MVP
+  if( iCount < 4 )
+  {
+#endif
   UInt uiLeftBottomPartIdx = 0;
   TComDataCU* pcCULeftBottom = 0;
   pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
+#if INTRA_BL
+  if( pcCULeftBottom && pcCULeftBottom->isIntraBL( uiLeftBottomPartIdx ) )
+  {
+    pcCULeftBottom = NULL;
+  }
+#endif
   Bool isAvailableA0 = pcCULeftBottom &&
   pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
+#if SVC_MVP
+  ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCULeftBottom->hasEqualMotion( uiLeftBottomPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0]))
+#endif
   !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
   if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
@@ -2528,4 +2737,8 @@
     return;
   }
+#if SVC_MVP
+  }
+#endif
+
   // above left 
   if( iCount < 4 )
@@ -2534,6 +2747,15 @@
     TComDataCU* pcCUAboveLeft = 0;
     pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
+#if INTRA_BL
+    if( pcCUAboveLeft && pcCUAboveLeft->isIntraBL( uiAboveLeftPartIdx ) )
+    {
+      pcCUAboveLeft = NULL;
+    }
+#endif
     Bool isAvailableB2 = pcCUAboveLeft &&
     pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
+#if SVC_MVP
+    ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCUAboveLeft->hasEqualMotion( uiAboveLeftPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0] ))
+#endif
     !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
     if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
@@ -2840,10 +3062,18 @@
   UInt idx;
   tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
+#if INTRA_BL
+  bAddedSmvp = (tmpCU != NULL) && (!tmpCU->isIntra(idx));
+#else
   bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
+#endif
 
   if (!bAddedSmvp)
   {
     tmpCU = getPULeft(idx, uiPartIdxLB);
+#if INTRA_BL
+    bAddedSmvp = (tmpCU != NULL) && (!tmpCU->isIntra(idx));
+#else
     bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
+#endif
   }
 
@@ -3406,6 +3636,11 @@
   if (scaleFactor > 0)
   {
+#if SVC_MVP
+    m_acCUMvField[0].compress(m_pePredMode, m_puhInterDir, scaleFactor);
+    m_acCUMvField[1].compress(m_pePredMode, m_puhInterDir, scaleFactor);    
+#else
     m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
     m_acCUMvField[1].compress(m_pePredMode, scaleFactor);    
+#endif
   }
 }
@@ -3839,4 +4074,204 @@
 }
 
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED 
+Void TComDataCU::getBaseLumaBlk ( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride )
+{
+  TComPicYuv* pcBaseRec = getSlice()->getFullPelBaseRec();
+  UInt uiStrideBase = pcBaseRec->getStride();
+  Pel* piBase = pcBaseRec->getLumaAddr( getAddr(), getZorderIdxInCU() + uiAbsPartIdx );
+  
+  for ( UInt y = 0; y < uiHeight; y ++ )
+  {
+    memcpy( piPred + y * uiStride, piBase + y * uiStrideBase, uiWidth * sizeof( Pel ) );
+  }
+}
+
+Void TComDataCU::getBaseChromaBlk ( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, UInt uiChromaId )
+{
+  TComPicYuv* pcBaseRec = getSlice()->getFullPelBaseRec();
+
+  UInt uiStrideBase = pcBaseRec->getCStride();
+  Pel* piBase;
+  
+  if( uiChromaId == 0 )
+  {
+    piBase = pcBaseRec->getCbAddr( getAddr(), getZorderIdxInCU() + uiAbsPartIdx );
+  }
+  else
+  {
+    piBase = pcBaseRec->getCrAddr( getAddr(), getZorderIdxInCU() + uiAbsPartIdx );
+  }
+  
+  for ( UInt y = 0; y < uiHeight; y ++ )
+  {
+    memcpy( piPred + y * uiStride, piBase + y * uiStrideBase, uiWidth * sizeof( Pel ) );
+  }
+}
+
+#endif
+
+#if SVC_COL_BLK
+TComDataCU*  TComDataCU::getBaseColCU( UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
+{
+#if 1 // it should provide identical resutls
+  UInt uiPelX = getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiCuAbsPartIdx] ];
+  UInt uiPelY = getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiCuAbsPartIdx] ];
+
+  return getBaseColCU( uiPelX, uiPelY, uiCUAddrBase, uiAbsPartIdxBase );
+#else
+  TComPic* cBaseColPic = m_pcSlice->getBaseColPic();
+
+#if SVC_UPSAMPLING
+  Int iBWidth   = cBaseColPic->getPicYuvRec()->getWidth () - cBaseColPic->getPicYuvRec()->getPicCropLeftOffset() - cBaseColPic->getPicYuvRec()->getPicCropRightOffset();
+  Int iBHeight  = cBaseColPic->getPicYuvRec()->getHeight() - cBaseColPic->getPicYuvRec()->getPicCropTopOffset() - cBaseColPic->getPicYuvRec()->getPicCropBottomOffset();
+
+  Int iEWidth   = m_pcPic->getPicYuvRec()->getWidth() - m_pcPic->getPicYuvRec()->getPicCropLeftOffset() - m_pcPic->getPicYuvRec()->getPicCropRightOffset();
+  Int iEHeight  = m_pcPic->getPicYuvRec()->getHeight() - m_pcPic->getPicYuvRec()->getPicCropTopOffset() - m_pcPic->getPicYuvRec()->getPicCropBottomOffset();
+#else
+  Int iBWidth   = cBaseColPic->getPicYuvRec()->getWidth();
+  Int iBHeight  = cBaseColPic->getPicYuvRec()->getHeight();
+
+  Int iEWidth   = m_pcPic->getPicYuvRec()->getWidth();
+  Int iEHeight  = m_pcPic->getPicYuvRec()->getHeight();
+#endif
+
+  if (iBWidth == iEWidth && iEHeight == iBHeight)
+  {
+    uiAbsPartIdxBase = uiCuAbsPartIdx + m_uiAbsIdxInLCU;
+    uiCUAddrBase = m_uiCUAddr;
+  }
+  else
+  {
+    UInt uiMinUnitSize = m_pcPic->getMinCUWidth();
+    UInt uiRasterAddr  = g_auiZscanToRaster[uiCuAbsPartIdx];
+    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
+
+    Int iEX = m_uiCUPelX + uiMinUnitSize*(uiRasterAddr%uiNumPartInCUWidth);
+    Int iEY = m_uiCUPelY + uiMinUnitSize*(uiRasterAddr/uiNumPartInCUWidth);
+
+    Int iBX = (iEX*iBWidth + iEWidth/2)/iEWidth;
+    Int iBY = (iEY*iBHeight+ iEHeight/2)/iEHeight;
+
+    uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
+
+    assert(uiCUAddrBase < cBaseColPic->getNumCUsInFrame());
+    
+    UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*cBaseColPic->getNumPartInWidth()
+                          + (iBX - (iBX/g_uiMaxCUWidth)*g_uiMaxCUWidth)/uiMinUnitSize;
+
+    uiAbsPartIdxBase = g_auiRasterToZscan[uiRasterAddrBase];
+  }
+
+  return cBaseColPic->getCU(uiCUAddrBase);
+#endif
+}
+
+TComDataCU*  TComDataCU::getBaseColCU( UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
+{
+  TComPic* cBaseColPic = m_pcSlice->getBaseColPic();
+
+#if SVC_UPSAMPLING
+  const Window &confBL = cBaseColPic->getPicYuvRec()->getConformanceWindow();
+  const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
+
+  Int iBWidth   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+  Int iBHeight  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+
+  Int iEWidth   = m_pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
+  Int iEHeight  = m_pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
+#else
+  Int iBWidth   = cBaseColPic->getPicYuvRec()->getWidth();
+  Int iBHeight  = cBaseColPic->getPicYuvRec()->getHeight();
+
+  Int iEWidth   = m_pcPic->getPicYuvRec()->getWidth();
+  Int iEHeight  = m_pcPic->getPicYuvRec()->getHeight();
+#endif
+
+  uiPelX = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getWidth() - 1, uiPelX);
+  uiPelY = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getHeight() - 1, uiPelY);
+
+  UInt uiMinUnitSize = m_pcPic->getMinCUWidth();
+
+  Int iBX = (uiPelX*iBWidth + iEWidth/2)/iEWidth;
+  Int iBY = (uiPelY*iBHeight+ iEHeight/2)/iEHeight;
+
+  if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight())
+  {
+    return NULL;
+  }
+
+#if AVC_SYNTAX
+  if( iBX >= iBWidth || iBY >= iBHeight ) //outside of the reference layer cropped picture
+  {
+    return NULL;
+  }
+#endif
+
+  uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
+
+  assert(uiCUAddrBase < cBaseColPic->getNumCUsInFrame());
+
+  UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*cBaseColPic->getNumPartInWidth()
+    + (iBX - (iBX/g_uiMaxCUWidth)*g_uiMaxCUWidth)/uiMinUnitSize;
+
+  uiAbsPartIdxBase = g_auiRasterToZscan[uiRasterAddrBase];
+
+  return cBaseColPic->getCU(uiCUAddrBase);
+}
+
+Void TComDataCU::scaleBaseMV( TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase )
+{
+  TComMvField cMvFieldBase;
+  TComMv cMv;
+
+#if MV_SCALING_FIX
+  const Window &confBL = m_pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
+  const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
+
+  Int iBWidth   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+  Int iBHeight  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+
+  Int iEWidth   = m_pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
+  Int iEHeight  = m_pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
+#else
+  Int iBWidth   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth();
+  Int iBHeight  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight();
+
+  Int iEWidth   = m_pcPic->getPicYuvRec()->getWidth();
+  Int iEHeight  = m_pcPic->getPicYuvRec()->getHeight();
+#endif
+
+  Int iMvX = (rcMvFieldBase.getHor()*iEWidth + (iBWidth/2 -1) * (rcMvFieldBase.getHor() > 0 ? 1: -1) )/iBWidth;
+  Int iMvY = (rcMvFieldBase.getVer()*iEHeight + (iBHeight/2 -1) * (rcMvFieldBase.getVer() > 0 ? 1: -1) )/iBHeight;
+
+  cMv.set(iMvX, iMvY);
+
+  rcMvFieldEnhance.setMvField( cMv, rcMvFieldBase.getRefIdx() );
+}
+#endif
+
+#if SVC_MVP
+Bool TComDataCU::hasEqualMotion( UInt uiAbsPartIdx, UChar uchInterDir, TComMvField* pcMvField  )
+{
+  if ( getInterDir( uiAbsPartIdx ) != uchInterDir )
+  {
+    return false;
+  }
+
+  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
+  {
+    if ( getInterDir( uiAbsPartIdx ) & ( 1 << uiRefListIdx ) )
+    {
+      if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx )  != pcMvField[uiRefListIdx].getMv() || 
+        getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiAbsPartIdx ) != pcMvField[uiRefListIdx].getRefIdx() )
+      {
+        return false;
+      }
+    }
+  }
+
+  return true;
+}
+#endif
 
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComDataCU.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComDataCU.h	(revision 54)
@@ -125,4 +125,8 @@
   Int           m_unitSize;           ///< size of a "minimum partition"
   
+#if SVC_EXTENSION
+  UInt          m_layerId;          ///< layer id
+#endif
+
   // -------------------------------------------------------------------------------------------------------------------
   // CU data
@@ -434,4 +438,9 @@
   Void          compressMV            ();
   
+#if SVC_EXTENSION
+  Void          setLayerId (UInt layerId) { m_layerId = layerId; }
+  UInt          getLayerId ()               { return m_layerId; }
+#endif
+  
   // -------------------------------------------------------------------------------------------------------------------
   // utility functions for neighbouring information
@@ -476,4 +485,7 @@
   Void          deriveLeftBottomIdxGeneral    ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLB );
   
+#if SVC_MVP
+  Bool          hasEqualMotion              ( UInt uiAbsPartIdx, UChar uchInterDir, TComMvField* pcMvField  );
+#endif
   
   // -------------------------------------------------------------------------------------------------------------------
@@ -481,5 +493,14 @@
   // -------------------------------------------------------------------------------------------------------------------
   
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED 
+  Void          getBaseLumaBlk   ( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride );
+  Void          getBaseChromaBlk ( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, UInt uiChromaId );
+#endif
+#if INTRA_BL
+  Bool          isIntraBL ( UInt uiPartIdx )  { return m_pePredMode[ uiPartIdx ] == MODE_INTRA_BL; }
+  Bool          isIntra   ( UInt uiPartIdx )  { return m_pePredMode[ uiPartIdx ] == MODE_INTRA || m_pePredMode[ uiPartIdx ] == MODE_INTRA_BL; }
+#else
   Bool          isIntra   ( UInt uiPartIdx )  { return m_pePredMode[ uiPartIdx ] == MODE_INTRA; }
+#endif 
   Bool          isSkipped ( UInt uiPartIdx );                                                     ///< SKIP (no residual)
   Bool          isBipredRestriction( UInt puIdx );
@@ -507,4 +528,14 @@
   UInt          getSliceSegmentStartCU  ( UInt pos )                  { return m_sliceSegmentStartCU[pos-m_uiAbsIdxInLCU];                                                                                   }
   UInt&         getTotalBins            ()                            { return m_uiTotalBins;                                                                                                  }
+
+#if INTRA_BL
+  UInt          getCtxIntraBLFlag               ( UInt   uiAbsPartIdx                                 );
+#endif  
+
+#if REF_IDX_ME_ZEROMV
+  Bool xCheckZeroMVILRMerge(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1);
+  Bool xCheckZeroMVILRMvdL1Zero(Int iRefList, Int iRefIdx, Int MvpIdx);
+#endif
+
   // -------------------------------------------------------------------------------------------------------------------
   // member functions for RD cost storage
@@ -518,4 +549,9 @@
   UInt          getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra);
 
+#if SVC_COL_BLK 
+  TComDataCU*   getBaseColCU( UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase );
+  TComDataCU*   getBaseColCU( UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase );
+  Void          scaleBaseMV( TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase );
+#endif
 };
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComMotionInfo.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComMotionInfo.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComMotionInfo.cpp	(revision 54)
@@ -328,5 +328,9 @@
  * \param scale      Factor by which to subsample motion information
  */
+#if SVC_MVP
+Void TComCUMvField::compress(Char* pePredMode, UChar* peInterDir, Int scale)
+#else
 Void TComCUMvField::compress(Char* pePredMode, Int scale)
+#endif
 {
   Int N = scale * scale;
@@ -347,4 +351,7 @@
       pePredMode[ uiPartIdx + i ] = predMode;
       m_piRefIdx[ uiPartIdx + i ] = iRefIdx;
+#if SVC_MVP
+      peInterDir[ uiPartIdx + i ] = peInterDir[ uiPartIdx ];
+#endif
     }
   }
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComMotionInfo.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComMotionInfo.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComMotionInfo.h	(revision 54)
@@ -141,4 +141,9 @@
   Void    setAllMvField( TComMvField const & mvField, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 );
 
+#if AVC_SYNTAX
+  Void           setMv    (TComMv cMv,  Int iIdx )         { m_pcMv    [iIdx] = cMv; }
+  Void           setRefIdx(Int iRefIdx, Int iIdx   )       { m_piRefIdx[iIdx] =  iRefIdx; }
+#endif
+
   Void setNumPartition( Int iNumPart )
   {
@@ -153,5 +158,25 @@
   }
   
+#if SVC_MVP
+  Void compress(Char* pePredMode, UChar* peInterDir, Int scale);
+#else
   Void compress(Char* pePredMode, Int scale); 
+#endif
+
+#if REF_IDX_MFM
+  Void setMvField( TComMvField const& mvField, Int iIdx )
+  {
+    m_pcMv[iIdx]      = mvField.getMv();
+    m_piRefIdx[iIdx]  = mvField.getRefIdx();
+    return;
+  }
+
+  Void setMvField( TComMv cMv, Int iRefIdx, Int iIdx )
+  {
+    m_pcMv[iIdx]      = cMv;
+    m_piRefIdx[iIdx]  = iRefIdx;
+    return;
+  }
+#endif
 };
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPic.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPic.cpp	(revision 54)
@@ -64,4 +64,12 @@
 , m_pNDBFilterYuvTmp                      (NULL)
 , m_bCheckLTMSB                           (false)
+#if SVC_EXTENSION
+, m_layerId( 0 )
+, m_bSpatialEnhLayer( false )
+, m_pcFullPelBaseRec( NULL )
+#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
+, m_bIsILR                                (false)
+#endif
+#endif
 {
   m_apcPicYuv[0]      = NULL;
@@ -72,5 +80,65 @@
 {
 }
-
+#if SVC_UPSAMPLING
+Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
+                      Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual)
+
+{
+  m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
+  if (!bIsVirtual)
+  {
+    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+  }
+  m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+
+  if (m_bSpatialEnhLayer)
+  {
+    m_pcFullPelBaseRec = new TComPicYuv;  m_pcFullPelBaseRec->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+  }
+
+  m_layerId = pcSps->getLayerId();  
+
+  // there are no SEI messages associated with this picture initially
+  if (m_SEIs.size() > 0)
+  {
+    deleteSEIs (m_SEIs);
+  }
+  m_bUsedByCurr = false;
+
+  /* store conformance window parameters with picture */
+  m_conformanceWindow = conformanceWindow;
+  
+  /* store display window parameters with picture */
+  m_defaultDisplayWindow = defaultDisplayWindow;
+
+  /* store number of reorder pics with picture */
+  memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int));
+
+  return;
+}
+#if REF_IDX_FRAMEWORK
+Void TComPic::createWithOutYuv( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, TComSPS* pcSps,  Bool bIsVirtual)
+{
+  m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
+  if (!bIsVirtual)
+  {
+    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+  }
+  m_apcPicYuv[1]  = NULL;
+ 
+#if SVC_UPSAMPLING
+  if (m_bSpatialEnhLayer)
+  {
+    m_pcFullPelBaseRec = new TComPicYuv;  m_pcFullPelBaseRec->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+  }
+#endif
+
+  /* there are no SEI messages associated with this picture initially */
+  m_SEIs = NULL;
+  m_bUsedByCurr = false;
+  return;
+}
+#endif
+#else
 Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
                       Int *numReorderPics, Bool bIsVirtual)
@@ -102,4 +170,5 @@
   return;
 }
+#endif
 
 Void TComPic::destroy()
@@ -127,4 +196,12 @@
   
   deleteSEIs(m_SEIs);
+#if SVC_EXTENSION && SVC_UPSAMPLING
+  if (m_bSpatialEnhLayer)
+  {
+    m_pcFullPelBaseRec->destroy();
+    delete m_pcFullPelBaseRec;
+    m_pcFullPelBaseRec  = NULL;
+  }
+#endif 
 }
 
@@ -465,4 +542,354 @@
 }
 
+#if REF_IDX_FRAMEWORK
+Void copyOnetoOnePicture(    // SVC_NONCOLL
+                  Pel *in,        
+                  Pel *out,      
+                  Int nCols,
+                  Int nRows, 
+                  Int fullRowWidth)
+{
+  Int rX;
+
+  for (rX = 0; rX < nRows; rX++)       
+  {
+    memcpy( out, in, sizeof(Pel) * nCols );
+    in = in + fullRowWidth;
+    out = out + fullRowWidth;
+  }
+}
+
+Void TComPic:: copyUpsampledPictureYuv(TComPicYuv*   pcPicYuvIn, TComPicYuv*   pcPicYuvOut)
+{
+  Int upsampledRowWidthLuma = pcPicYuvOut->getStride(); // 2 * pcPicYuvOut->getLumaMargin() + pcPicYuvOut->getWidth(); 
+  Int upsampledRowWidthCroma = pcPicYuvOut->getCStride(); //2 * pcPicYuvOut->getChromaMargin() + (pcPicYuvOut->getWidth()>>1);
+
+  copyOnetoOnePicture(
+    pcPicYuvIn->getLumaAddr(),        
+    pcPicYuvOut->getLumaAddr(),      
+    pcPicYuvOut->getWidth(), 
+    pcPicYuvOut->getHeight(),
+    upsampledRowWidthLuma);
+  copyOnetoOnePicture(
+    pcPicYuvIn->getCrAddr(),        
+    pcPicYuvOut->getCrAddr(),      
+    pcPicYuvOut->getWidth()>>1, 
+    pcPicYuvOut->getHeight()>>1,
+    upsampledRowWidthCroma);
+  copyOnetoOnePicture(
+    pcPicYuvIn->getCbAddr(),        
+    pcPicYuvOut->getCbAddr(),      
+    pcPicYuvOut->getWidth()>>1, 
+    pcPicYuvOut->getHeight()>>1,
+    upsampledRowWidthCroma);
+}
+
+#if REF_IDX_MFM
+#if !REUSE_BLKMAPPING
+Void TComPic::deriveUnitIdxBase( UInt uiUpsamplePelX, UInt uiUpsamplePelY, UInt ratio, UInt& uiBaseCUAddr, UInt& uiBaseAbsPartIdx )
+{
+  //pixel in the base layer
+
+  UInt uiPelX       = (uiUpsamplePelX<<1)/ratio;
+  UInt uiPelY       = (uiUpsamplePelY<<1)/ratio;
+  UInt uiBaseWidth  = getPicYuvRec()->getWidth();
+  UInt uiBaseHeight = getPicYuvRec()->getHeight();
+  
+  UInt uiWidthInCU       = ( uiBaseWidth % g_uiMaxCUWidth  ) ? uiBaseWidth /g_uiMaxCUWidth  + 1 : uiBaseWidth /g_uiMaxCUWidth;
+
+#if MFM_CLIPPING_FIX
+  uiPelX     = (UInt)Clip3<UInt>(0, getPicYuvRec()->getWidth() - 1, uiPelX);
+  uiPelY     = (UInt)Clip3<UInt>(0, getPicYuvRec()->getHeight() - 1, uiPelY);
+#else
+  UInt uiHeightInCU      = ( uiBaseHeight% g_uiMaxCUHeight ) ? uiBaseHeight/ g_uiMaxCUHeight + 1 : uiBaseHeight/ g_uiMaxCUHeight;
+
+  uiPelX     = (UInt)Clip3<UInt>(0, uiWidthInCU * g_uiMaxCUWidth - 1, uiPelX);
+  uiPelY     = (UInt)Clip3<UInt>(0, uiHeightInCU * g_uiMaxCUHeight - 1, uiPelY);
+#endif
+  
+  uiBaseCUAddr = uiPelY / g_uiMaxCUHeight * uiWidthInCU + uiPelX / g_uiMaxCUWidth;
+
+  UInt uiWidthMinPU = g_uiMaxCUWidth / (1<<g_uiMaxCUDepth);
+  UInt uiHeightMinPU = g_uiMaxCUHeight/(1<<g_uiMaxCUDepth);
+  
+  UInt uiAbsPelX = uiPelX - (uiPelX / g_uiMaxCUWidth) * g_uiMaxCUWidth;
+  UInt uiAbsPelY = uiPelY - (uiPelY / g_uiMaxCUHeight) * g_uiMaxCUHeight;
+
+  UInt RasterIdx = uiAbsPelY / uiHeightMinPU * (g_uiMaxCUWidth/uiWidthMinPU) + uiAbsPelX / uiWidthMinPU;
+  uiBaseAbsPartIdx = g_auiRasterToZscan[RasterIdx];
+
+  return;
+}
+#endif
+
+Void TComPic::copyUpsampledMvField(TComPic* pcPicBase)
+{
+#if !REUSE_MVSCALE || !REUSE_BLKMAPPING || AVC_SYNTAX
+  Int iBWidth   = pcPicBase->getPicYuvRec()->getWidth () - pcPicBase->getPicYuvRec()->getPicCropLeftOffset() - pcPicBase->getPicYuvRec()->getPicCropRightOffset();
+  Int iBHeight  = pcPicBase->getPicYuvRec()->getHeight() - pcPicBase->getPicYuvRec()->getPicCropTopOffset() - pcPicBase->getPicYuvRec()->getPicCropBottomOffset();
+
+  Int iEWidth   = getPicYuvRec()->getWidth() -  getPicYuvRec()->getPicCropLeftOffset() - getPicYuvRec()->getPicCropRightOffset();
+  Int iEHeight  = getPicYuvRec()->getHeight() - getPicYuvRec()->getPicCropTopOffset() -  getPicYuvRec()->getPicCropBottomOffset();
+#endif
+  
+#if !REUSE_MVSCALE  || !REUSE_BLKMAPPING
+  UInt upSampleRatio = 0;
+  if(iEWidth == iBWidth && iEHeight == iBHeight)
+  {
+    upSampleRatio = 2;
+  }
+  else if(2*iEWidth == 3*iBWidth && 2*iEHeight == 3*iBHeight)
+  {
+    upSampleRatio = 3;
+  }
+  else if(iEWidth == 2*iBWidth && iEHeight == 2*iBHeight)
+  {
+    upSampleRatio = 4;
+  }
+  else
+  {
+    assert(0);
+  }
+#endif
+
+  UInt uiNumPartitions   = 1<<(g_uiMaxCUDepth<<1);
+  UInt uiWidthMinPU      = g_uiMaxCUWidth/(1<<g_uiMaxCUDepth);
+  UInt uiHeightMinPU     = g_uiMaxCUHeight/(1<<g_uiMaxCUDepth);
+  Int  unitNum           = max (1, (Int)((16/uiWidthMinPU)*(16/uiHeightMinPU)) ); 
+
+  for(UInt cuIdx = 0; cuIdx < getPicSym()->getNumberOfCUsInFrame(); cuIdx++)  //each LCU
+  {
+    TComDataCU*             pcCUDes = getCU(cuIdx);
+
+    for(UInt uiAbsPartIdx = 0; uiAbsPartIdx < uiNumPartitions; uiAbsPartIdx+=unitNum )  //each 16x16 unit
+    {
+      //pixel position of each unit in up-sampled layer
+      UInt  uiPelX = pcCUDes->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
+      UInt  uiPelY = pcCUDes->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
+      UInt uiBaseCUAddr, uiBaseAbsPartIdx;
+
+#if REUSE_BLKMAPPING
+      TComDataCU *pcColCU = 0;
+      pcColCU = pcCUDes->getBaseColCU(uiPelX + 8, uiPelY + 8, uiBaseCUAddr, uiBaseAbsPartIdx);
+#else 
+      pcPicBase->deriveUnitIdxBase(uiPelX + 8, uiPelY + 8, upSampleRatio, uiBaseCUAddr, uiBaseAbsPartIdx);
+#endif
+
+#if AVC_SYNTAX
+      Int iBX = ( (uiPelX + 8) * iBWidth + iEWidth/2 ) / iEWidth;
+      Int iBY = ( (uiPelY + 8) * iBHeight+ iEHeight/2 ) / iEHeight;
+
+#if REUSE_BLKMAPPING
+      if( ( iBX < iBWidth && iBY < iBHeight ) && pcColCU && (pcColCU->getPredictionMode(uiBaseAbsPartIdx) != MODE_NONE) && (pcColCU->getPredictionMode(uiBaseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
+#else
+      if( ( iBX < iBWidth && iBY < iBHeight ) && (pcPicBase->getCU(uiBaseCUAddr)->getPredictionMode(uiBaseAbsPartIdx) != MODE_NONE) && (pcPicBase->getCU(uiBaseCUAddr)->getPredictionMode(uiBaseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
+#endif
+#else
+#if REUSE_BLKMAPPING
+      if( pcColCU && (pcColCU->getPredictionMode(uiBaseAbsPartIdx) != MODE_NONE) && (pcColCU->getPredictionMode(uiBaseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
+#else
+      if( (pcPicBase->getCU(uiBaseCUAddr)->getPredictionMode(uiBaseAbsPartIdx) != MODE_NONE) && (pcPicBase->getCU(uiBaseCUAddr)->getPredictionMode(uiBaseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
+#endif
+#endif
+      {
+        for(UInt refPicList = 0; refPicList < 2; refPicList++)  //for each reference list
+        {
+#if REUSE_MVSCALE
+          TComMvField sMvFieldBase, sMvField;
+#if REUSE_BLKMAPPING
+          pcColCU->getMvField( pcColCU, uiBaseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase);
+#else
+          pcPicBase->getCU(uiBaseCUAddr)->getMvField( pcPicBase->getCU(uiBaseCUAddr), uiBaseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase);
+#endif
+          pcCUDes->scaleBaseMV( sMvField, sMvFieldBase );
+#else
+          TComMv cMv = pcPicBase->getCU(uiBaseCUAddr)->getCUMvField((RefPicList)refPicList)->getMv(uiBaseAbsPartIdx);
+          Int refIdx = pcPicBase->getCU(uiBaseCUAddr)->getCUMvField((RefPicList)refPicList)->getRefIdx(uiBaseAbsPartIdx);
+
+          Int Hor =  ((Int)upSampleRatio * cMv.getHor())/2 ;
+          Int Ver =  ((Int)upSampleRatio * cMv.getVer())/2 ;
+
+          TComMv cScaledMv(Hor, Ver);
+          TComMvField sMvField;
+          sMvField.setMvField(cScaledMv, refIdx);
+#endif
+
+          pcCUDes->getCUMvField((RefPicList)refPicList)->setMvField(sMvField, uiAbsPartIdx);
+          pcCUDes->setPredictionMode(uiAbsPartIdx, MODE_INTER);
+        }
+      }
+      else
+      {
+        TComMvField zeroMvField;  //zero MV and invalid reference index
+        pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, uiAbsPartIdx);
+        pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, uiAbsPartIdx);
+        pcCUDes->setPredictionMode(uiAbsPartIdx, MODE_INTRA);
+      }
+
+      for(UInt i = 1; i < unitNum; i++ )  
+      {
+        pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_0)->getMv(uiAbsPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_0)->getRefIdx(uiAbsPartIdx), uiAbsPartIdx + i);
+        pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_1)->getMv(uiAbsPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_1)->getRefIdx(uiAbsPartIdx), uiAbsPartIdx + i);
+        pcCUDes->setPredictionMode(uiAbsPartIdx+i, pcCUDes->getPredictionMode(uiAbsPartIdx))  ;
+      }
+    }
+      memset( pcCUDes->getPartitionSize(), SIZE_2Nx2N, sizeof(char)*uiNumPartitions);
+  }
+}
+#endif
+
+#endif
+
+#if AVC_SYNTAX
+Void TComPic::readBLSyntax( fstream* filestream, UInt numBytes )
+{
+  if( !filestream->good() )
+  {
+    return;
+  }
+
+  UInt   uiWidth      = this->getPicYuvRec()->getWidth() - this->getPicYuvRec()->getPicCropLeftOffset() - this->getPicYuvRec()->getPicCropRightOffset();
+  UInt   uiHeight     = this->getPicYuvRec()->getHeight() - this->getPicYuvRec()->getPicCropTopOffset() - this->getPicYuvRec()->getPicCropBottomOffset();
+  UInt64 uiPOC        = (UInt64)this->getPOC();
+  UInt   uiPartWidth  = uiWidth / 4;
+  UInt   uiPartHeight = uiHeight / 4;
+
+  UInt uiNumPartInWidth    = this->getNumPartInWidth();
+  UInt uiNumPartInHeight   = this->getNumPartInHeight();
+  UInt uiNumPartLCUInWidth = this->getFrameWidthInCU();
+
+  UInt64 uiPos = (UInt64)uiPOC * uiWidth * uiHeight * numBytes / 16;
+   
+  filestream->seekg( uiPos, ios_base::beg );
+
+  for( Int i = 0; i < uiPartHeight; i++ )
+  {
+    for( Int j = 0; j < uiPartWidth; j++ )
+    {
+      UInt uiX = ( j / uiNumPartInWidth );
+      UInt uiY = ( i / uiNumPartInHeight );
+
+      UInt uiLCUAddr = uiY * uiNumPartLCUInWidth + uiX;
+      UInt uiPartAddr = ( i - uiY * uiNumPartInHeight ) * uiNumPartInWidth + ( j - uiX * uiNumPartInWidth );
+      uiPartAddr = g_auiRasterToZscan[uiPartAddr];
+      
+      TComDataCU* pcCU = this->getCU( uiLCUAddr );
+      
+      TComMv mv;
+      Short temp;
+
+      // RefIdxL0
+      Char refIdxL0 = -1;
+      filestream->read( &refIdxL0, 1 );
+      assert( refIdxL0 >= -1 );
+      pcCU->getCUMvField( REF_PIC_LIST_0 )->setRefIdx( (Int)refIdxL0, uiPartAddr );
+
+      // RefIdxL1
+      Char refIdxL1 = -1;
+      filestream->read( &refIdxL1, 1 );
+      assert( refIdxL1 >= -1 );
+      pcCU->getCUMvField( REF_PIC_LIST_1 )->setRefIdx( (Int)refIdxL1, uiPartAddr );
+
+      // MV L0
+      temp = 0;
+      filestream->read( reinterpret_cast<char*>(&temp), 2 );
+      mv.setHor( (Short)temp );
+      temp = 0;
+      filestream->read( reinterpret_cast<char*>(&temp), 2 );
+      mv.setVer( (Short)temp );
+      pcCU->getCUMvField( REF_PIC_LIST_0 )->setMv( mv, uiPartAddr );
+
+      // MV L1
+      temp = 0;
+      filestream->read( reinterpret_cast<char*>(&temp), 2 );
+      mv.setHor( (Short)temp );
+      temp = 0;
+      filestream->read( reinterpret_cast<char*>(&temp), 2 );
+      mv.setVer( (Short)temp );
+      pcCU->getCUMvField( REF_PIC_LIST_1 )->setMv( mv, uiPartAddr );
+
+      // set dependent information
+      pcCU->setPredictionMode( uiPartAddr, ( refIdxL0 == NOT_VALID && refIdxL1 == NOT_VALID ) ? MODE_INTRA : MODE_INTER );
+      UInt uiInterDir = ( refIdxL0 != NOT_VALID ) + ( refIdxL1 != NOT_VALID && this->getSlice(0)->isInterB() ) * 2;
+      assert( uiInterDir >= 0 && uiInterDir <= 3 );
+      pcCU->setInterDir( uiPartAddr, uiInterDir );      
+    }
+  }
+}
+#endif
+
+#if SYNTAX_OUTPUT
+Void TComPic::wrireBLSyntax( fstream* filestream, UInt numBytes )
+{
+  if( !filestream->good() )
+  {
+    return;
+  }
+
+  UInt   uiWidth      = this->getPicYuvRec()->getWidth() - getSlice(0)->getSPS()->getPicCropLeftOffset() - getSlice(0)->getSPS()->getPicCropRightOffset();
+  UInt   uiHeight     = this->getPicYuvRec()->getHeight() - getSlice(0)->getSPS()->getPicCropTopOffset() - getSlice(0)->getSPS()->getPicCropBottomOffset();
+  UInt64 uiPOC        = (UInt64)this->getPOC();
+  UInt   uiPartWidth  = uiWidth / 4;
+  UInt   uiPartHeight = uiHeight / 4;
+
+  UInt uiNumPartInWidth    = this->getNumPartInWidth();
+  UInt uiNumPartInHeight   = this->getNumPartInHeight();
+  UInt uiNumPartLCUInWidth = this->getFrameWidthInCU();
+
+  filestream->seekg( uiPOC * uiWidth * uiHeight * numBytes / 16 );
+    
+  for( Int i = 0; i < uiPartHeight; i++ )
+  {
+    for( Int j = 0; j < uiPartWidth; j++ )
+    {
+      UInt uiX = ( j / uiNumPartInWidth );
+      UInt uiY = ( i / uiNumPartInHeight );
+
+      UInt uiLCUAddr = uiY * uiNumPartLCUInWidth + uiX;
+      UInt uiPartAddr = ( i - uiY * uiNumPartInHeight ) * uiNumPartInWidth + ( j - uiX * uiNumPartInWidth );
+      uiPartAddr = g_auiRasterToZscan[uiPartAddr];
+      
+      TComDataCU* pcCU = this->getCU( uiLCUAddr );
+      
+      TComMv mv;
+      Short temp;
+      Char refIdxL0 = NOT_VALID, refIdxL1 = NOT_VALID;
+
+      // RefIdx
+      if( !pcCU->isIntra( uiPartAddr ) )
+      {
+        refIdxL0 = (Char)pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr );
+        refIdxL1 = (Char)pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr );
+      }
+      assert( refIdxL0 >= - 1 && refIdxL1 >= - 1 );
+      filestream->put( refIdxL0 );
+      filestream->put( refIdxL1 );
+
+      // MV L0
+      mv.setZero();
+      if( refIdxL0 >= 0 )
+      {
+        mv = pcCU->getCUMvField( REF_PIC_LIST_0 )->getMv( uiPartAddr );
+      }
+      temp = (Short)mv.getHor();
+      filestream->write( reinterpret_cast<char*>(&temp), 2 );
+      temp = (Short)mv.getVer();
+      filestream->write( reinterpret_cast<char*>(&temp), 2 );
+
+      // MV L1
+      mv.setZero();
+      if( refIdxL1 >= 0 )
+      {
+        mv = pcCU->getCUMvField( REF_PIC_LIST_1 )->getMv( uiPartAddr );
+      }
+      temp = (Short)mv.getHor();
+      filestream->write( reinterpret_cast<char*>(&temp), 2 );
+      temp = (Short)mv.getVer();
+      filestream->write( reinterpret_cast<char*>(&temp), 2 );
+    }
+  }
+}
+#endif
+
 
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPic.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPic.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPic.h	(revision 54)
@@ -45,4 +45,7 @@
 #include "TComBitStream.h"
 #include "SEI.h"
+#if AVC_BASE || SYNTAX_OUTPUT
+#include <fstream>
+#endif
 
 //! \ingroup TLibCommon
@@ -58,4 +61,7 @@
 private:
   UInt                  m_uiTLayer;               //  Temporal layer
+#if SVC_EXTENSION
+  UInt                  m_layerId;              //  Layer ID
+#endif
   Bool                  m_bUsedByCurr;            //  Used by current picture
   Bool                  m_bIsLongTerm;            //  IS long term picture
@@ -85,4 +91,11 @@
 
   SEIMessages  m_SEIs; ///< Any SEI messages that have been received.  If !NULL we own the object.
+#if SVC_EXTENSION
+  Bool                  m_bSpatialEnhLayer;       // whether current layer is a spatial enhancement layer,
+  TComPicYuv*           m_pcFullPelBaseRec;    // upsampled base layer recontruction for difference domain inter prediction
+#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
+  Bool                  m_bIsILR;                 //  Is ILR picture
+#endif
+#endif
 
 public:
@@ -90,11 +103,38 @@
   virtual ~TComPic();
   
+#if SVC_UPSAMPLING
   Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
-                        Int *numReorderPics, Bool bIsVirtual = false );
-                        
+                        Int *numReorderPics, TComSPS* pcSps = NULL, Bool bIsVirtual = false );
+#if REF_IDX_FRAMEWORK
+  Void          createWithOutYuv( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, TComSPS* pcSps = NULL, Bool bIsVirtual = false );  
+  Void          setPicYuvRec(TComPicYuv *pPicYuv) { m_apcPicYuv[1]=pPicYuv; }
+#endif
+#else
+  Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
+                        Int *numReorderPics, Bool bIsVirtual = false );                        
+#endif
   virtual Void  destroy();
   
   UInt          getTLayer()                { return m_uiTLayer;   }
   Void          setTLayer( UInt uiTLayer ) { m_uiTLayer = uiTLayer; }
+#if SVC_EXTENSION
+  Void          setLayerId (UInt layerId) { m_layerId = layerId; }
+  UInt          getLayerId ()               { return m_layerId; }
+  Bool          isSpatialEnhLayer()             { return m_bSpatialEnhLayer; }
+  Void          setSpatialEnhLayerFlag (Bool b) { m_bSpatialEnhLayer = b; }
+  Void          setFullPelBaseRec   ( TComPicYuv* p) { m_pcFullPelBaseRec = p; }
+  TComPicYuv*   getFullPelBaseRec   ()  { return  m_pcFullPelBaseRec;  }
+#endif
+#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
+  Void          setIsILR( Bool bIsILR)      {m_bIsILR = bIsILR;}
+  Bool          getIsILR()                  {return m_bIsILR;}
+#endif
+
+#if REF_IDX_MFM
+  Void          copyUpsampledMvField  (  TComPic* pcPicBase );
+#if !REUSE_BLKMAPPING
+  Void          deriveUnitIdxBase     (  UInt uiUpsamplePelX, UInt uiUpsamplePelY, UInt ratio, UInt& uiBaseCUAddr, UInt& uiBaseAbsPartIdx );
+#endif
+#endif
 
   Bool          getUsedByCurr()             { return m_bUsedByCurr; }
@@ -177,4 +217,14 @@
   const SEIMessages& getSEIs() const { return m_SEIs; }
 
+#if REF_IDX_FRAMEWORK
+  Void  copyUpsampledPictureYuv(TComPicYuv*   pcPicYuvIn, TComPicYuv*   pcPicYuvOut); 
+#endif
+#if AVC_SYNTAX
+  Void readBLSyntax( fstream* filestream, UInt numBytes );
+#endif
+#if SYNTAX_OUTPUT
+  Void wrireBLSyntax( fstream* filestream, UInt numBytes );
+#endif
+
 };// END CLASS DEFINITION TComPic
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicSym.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicSym.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicSym.cpp	(revision 54)
@@ -147,4 +147,8 @@
   m_apcTComDataCU = NULL;
 
+#if AVC_BASE || REF_IDX_FRAMEWORK
+  if( m_apcTComTile )
+  {
+#endif
   for(Int i = 0; i < (m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1); i++ )
   {
@@ -152,4 +156,7 @@
   }
   delete [] m_apcTComTile;
+#if AVC_BASE || REF_IDX_FRAMEWORK
+  }
+#endif
 
   m_apcTComTile = NULL;
@@ -178,5 +185,9 @@
   {
     m_apcTComSlice[m_uiNumAllocatedSlice-1]->copySliceInfo( m_apcTComSlice[m_uiNumAllocatedSlice-2] );
+#if SET_SLICE_LAYER_ID
+    m_apcTComSlice[m_uiNumAllocatedSlice-1]->initSlice( m_apcTComSlice[m_uiNumAllocatedSlice-1]->getLayerId() );
+#else
     m_apcTComSlice[m_uiNumAllocatedSlice-1]->initSlice();
+#endif
   }
 }
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicSym.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicSym.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicSym.h	(revision 54)
@@ -122,4 +122,10 @@
   TComDataCU*&  getCU( UInt uiCUAddr )  { return m_apcTComDataCU[uiCUAddr];     }
   
+#if AVC_SYNTAX
+  UInt        getMaxCUWidth()           { return m_uiMaxCUWidth;                }
+  UInt        getMaxCUHeight()          { return m_uiMaxCUHeight;               }
+  UInt        getMaxDepth()             { return m_uhTotalDepth;               }
+#endif
+  
   Void        setSlice(TComSlice* p, UInt i) { m_apcTComSlice[i] = p;           }
   UInt        getNumAllocatedSlice()    { return m_uiNumAllocatedSlice;         }
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 54)
@@ -60,5 +60,4 @@
   m_piPicOrgU       = NULL;
   m_piPicOrgV       = NULL;
-  
   m_bIsBorderExtended = false;
 }
@@ -67,10 +66,20 @@
 {
 }
-
+#if SVC_UPSAMPLING
+Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps )
+#else
 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth )
+#endif
 {
   m_iPicWidth       = iPicWidth;
   m_iPicHeight      = iPicHeight;
   
+#if SVC_UPSAMPLING
+  if(pcSps != NULL)
+  {
+    m_conformanceWindow = pcSps->getConformanceWindow();
+  }
+#endif
+
   // --> After config finished!
   m_iCuWidth        = uiMaxCUWidth;
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicYuv.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicYuv.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicYuv.h	(revision 54)
@@ -42,5 +42,7 @@
 #include "CommonDef.h"
 #include "TComRom.h"
-
+#if SVC_UPSAMPLING
+#include "TComSlice.h"
+#endif
 //! \ingroup TLibCommon
 //! \{
@@ -86,4 +88,8 @@
   Int   m_iChromaMarginY;
   
+#if SVC_UPSAMPLING
+  Window  m_conformanceWindow;
+#endif
+
   Bool  m_bIsBorderExtended;
   
@@ -98,6 +104,10 @@
   //  Memory management
   // ------------------------------------------------------------------------------------------------
+#if SVC_UPSAMPLING
+  Void  create      ( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps = NULL);
+#else
+  Void  create      ( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth );
+#endif  
   
-  Void  create      ( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth );
   Void  destroy     ();
   
@@ -112,4 +122,11 @@
   Int   getHeight   ()     { return  m_iPicHeight;   }
   
+#if SVC_EXTENSION
+  Void   setHeight   ( Int iPicHeight )     { m_iPicHeight = iPicHeight; }
+#endif
+
+#if JCTVC_L0178
+  Void   setWidth   ( Int iPicWidth )     { m_iPicWidth = iPicWidth; }
+#endif
   Int   getStride   ()     { return (m_iPicWidth     ) + (m_iLumaMarginX  <<1); }
   Int   getCStride  ()     { return (m_iPicWidth >> 1) + (m_iChromaMarginX<<1); }
@@ -140,4 +157,9 @@
   Pel*  getCrAddr   ( Int iCuAddr, Int uiAbsZorderIdx ) { return m_piPicOrgV + m_cuOffsetC[iCuAddr] + m_buOffsetC[g_auiZscanToRaster[uiAbsZorderIdx]]; }
   
+#if SVC_UPSAMPLING
+  Window& getConformanceWindow()                           { return  m_conformanceWindow;             }
+  Void    setConformanceWindow(Window& conformanceWindow ) { m_conformanceWindow = conformanceWindow; }
+#endif
+
   // ------------------------------------------------------------------------------------------------
   //  Miscellaneous
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPrediction.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPrediction.cpp	(revision 54)
@@ -407,4 +407,12 @@
 }
 
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED
+Void TComPrediction::getBaseBlk( TComDataCU* pcCU, TComYuv* pcYuvPred, Int iPartAddr, Int iWidth, Int iHeight )
+{
+  pcCU->getBaseLumaBlk( iWidth, iHeight, iPartAddr, pcYuvPred->getLumaAddr( iPartAddr ), pcYuvPred->getStride() );
+  pcCU->getBaseChromaBlk( iWidth >> 1, iHeight >> 1, iPartAddr, pcYuvPred->getCbAddr( iPartAddr ), pcYuvPred->getCStride(), 0 );
+  pcCU->getBaseChromaBlk( iWidth >> 1, iHeight >> 1, iPartAddr, pcYuvPred->getCrAddr( iPartAddr ), pcYuvPred->getCStride(), 1 );
+}
+#endif
 
 Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
@@ -758,3 +766,10 @@
   return;
 }
+
+#if SVC_UPSAMPLING
+Void TComPrediction::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic)
+{
+  m_cUsf.upsampleBasePic( pcUsPic, pcBasePic, pcTempPic);
+}
+#endif
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPrediction.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPrediction.h	(revision 54)
@@ -48,4 +48,8 @@
 #include "TComWeightPrediction.h"
 
+#if SVC_UPSAMPLING
+#include "TComDataCU.h"
+#include "TComUpsampleFilter.h"
+#endif
 //! \ingroup TLibCommon
 //! \{
@@ -70,4 +74,8 @@
   TComInterpolationFilter m_if;
   
+#if SVC_UPSAMPLING
+  TComUpsampleFilter      m_cUsf;
+#endif
+
   Pel*   m_pLumaRecBuffer;       ///< array for downsampled reconstructed luma sample 
   Int    m_iLumaRecStride;       ///< stride of #m_pLumaRecBuffer array
@@ -94,4 +102,7 @@
   Void    initTempBuff();
   
+#if INTRA_BL
+  Void getBaseBlk ( TComDataCU* pcCU, TComYuv* pcYuvPred, Int iPartAddr, Int iWidth, Int iHeight );
+#endif
   // inter
   Void motionCompensation         ( TComDataCU*  pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList = REF_PIC_LIST_X, Int iPartIdx = -1 );
@@ -110,4 +121,7 @@
   Int  getPredicBufHeight()       { return m_iYuvExtHeight; }
 
+#if SVC_UPSAMPLING
+  Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
+#endif
 };
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.cpp	(revision 54)
@@ -81,4 +81,8 @@
 , m_bNoBackPredFlag               ( false )
 , m_uiTLayer                      ( 0 )
+#if SVC_EXTENSION
+, m_layerId                     ( 0 )
+, m_pcBaseColPic                  ( NULL )
+#endif
 , m_bTLayerSwitchingFlag          ( false )
 , m_sliceMode                   ( 0 )
@@ -136,6 +140,13 @@
 
 
+#if SET_SLICE_LAYER_ID
+Void TComSlice::initSlice( UInt layerId )
+#else
 Void TComSlice::initSlice()
-{
+#endif
+{
+#if SET_SLICE_LAYER_ID
+  m_layerId = layerId;
+#endif
   m_aiNumRefIdx[0]      = 0;
   m_aiNumRefIdx[1]      = 0;
@@ -344,5 +355,11 @@
 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
 {
+#if REF_IDX_FRAMEWORK
+  if( m_eSliceType == I_SLICE || ( getSPS()->getLayerId() && 
+      (getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) &&
+      (getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) ) )
+#else
   if (m_eSliceType == I_SLICE)
+#endif
   {
     ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
@@ -1261,4 +1278,7 @@
 , m_vuiParametersPresentFlag  (false)
 , m_vuiParameters             ()
+#if SVC_EXTENSION
+, m_layerId(0)
+#endif
 {
   for ( Int i = 0; i < MAX_TLAYER; i++ )
@@ -1926,5 +1946,9 @@
 //! activate a PPS and depending on isIDR parameter also SPS and VPS
 //! \returns true, if activation is successful
+#if SVC_EXTENSION
+Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIDR, UInt layerId)
+#else
 Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIDR)
+#endif
 {
   TComPPS *pps = m_ppsMap.getPS(ppsId);
@@ -1932,5 +1956,9 @@
   {
     Int spsId = pps->getSPSId();
+#if SVC_EXTENSION
+    if (!isIDR && (spsId != layerId ))
+#else
     if (!isIDR && (spsId != m_activeSPSId))
+#endif
     {
       printf("Warning: tried to activate PPS referring to a inactive SPS at non-IDR.");
@@ -2001,3 +2029,151 @@
 }
 #endif
+
+#if SVC_EXTENSION
+#if AVC_SYNTAX
+Void TComSlice::initBaseLayerRPL( TComSlice *pcSlice )
+{
+// Assumed that RPL of the base layer is same to the EL, otherwise this information should be also dumped and read from the metadata file
+  setPOC( pcSlice->getPOC() );
+  if( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )
+  {
+    setSliceType( I_SLICE );
+  }
+  else
+  {
+    setSliceType( pcSlice->getSliceType() );
+  }
+
+  if( this->isIntra() )
+  {
+    return;
+  }
+
+  //initialize reference POC of BL
+  for( Int iRefPicList = 0; iRefPicList < 2; iRefPicList++ )
+  {
+    RefPicList eRefPicList = RefPicList( iRefPicList );
+
+    assert( pcSlice->getNumRefIdx( eRefPicList) > 0 );
+    setNumRefIdx( eRefPicList, pcSlice->getNumRefIdx( eRefPicList ) - 1 );
+    assert( getNumRefIdx( eRefPicList) <= MAX_NUM_REF);
+
+    for(Int refIdx = 0; refIdx < getNumRefIdx( eRefPicList ); refIdx++) 
+    {
+      setRefPOC( pcSlice->getRefPic( eRefPicList, refIdx )->getPOC(), eRefPicList, refIdx );
+      setRefPic( pcSlice->getRefPic( eRefPicList, refIdx ), eRefPicList, refIdx );
+      /*
+      // should be set if the base layer has its own instance of the reference picture lists, currently EL RPL is reused.
+      getRefPic( eRefPicList, refIdx )->setLayerId( 0 );
+      getRefPic( eRefPicList, refIdx )->setIsLongTerm( pcSlice->getRefPic( eRefPicList, refIdx )->getIsLongTerm() );
+      getRefPic( eRefPicList, refIdx )->setIsUsedAsLongTerm( pcSlice->getRefPic( eRefPicList, refIdx )->getIsUsedAsLongTerm() );
+      */
+
+    }
+  }  
+  return;
+}
+#endif
+
+Void TComSlice::setBaseColPic(  TComList<TComPic*>& rcListPic, UInt layerID )
+{  
+  if (layerID == 0)
+  {
+    m_pcBaseColPic = NULL;
+    return;
+  }        
+  setBaseColPic(xGetRefPic(rcListPic, getPOC())); 
+}
+#endif 
+
+#if REF_IDX_FRAMEWORK
+Void TComSlice::addRefPicList( TComPic **pIlpPicList, Int iRefPicNum, Int iInsertOffset )
+{
+  if(getSPS()->getLayerId() && m_eSliceType != I_SLICE)
+  {
+#if REF_IDX_MFM
+    assert(iRefPicNum == 1);
+    if( getPOC() != 0 )
+    { 
+      pIlpPicList[0]->copyUpsampledMvField(getBaseColPic());
+    }
+#endif
+    //add to list 0;
+    Int iOffset;
+    m_aiNumRefIdx[REF_PIC_LIST_0] += iInsertOffset;
+    iOffset = m_aiNumRefIdx[REF_PIC_LIST_0];
+    for (Int i=0; i<iRefPicNum; i++)
+    {
+      pIlpPicList[i]->setIsLongTerm(1);  //mark ilp as long-term reference
+      pIlpPicList[i]->setIsUsedAsLongTerm(1);  //mark ilp as long-term reference
+      m_apcRefPicList[REF_PIC_LIST_0][iOffset + i] = pIlpPicList[i]; 
+      m_aiNumRefIdx[REF_PIC_LIST_0]++;
+      //m_aiNumRefIdx[REF_PIC_LIST_C]++;
+    }
+    if(m_eSliceType == B_SLICE)
+    {
+      m_aiNumRefIdx[REF_PIC_LIST_1] += iInsertOffset;
+      iOffset = m_aiNumRefIdx[REF_PIC_LIST_1];
+      for (Int i=0; i<iRefPicNum; i++)
+      {
+        pIlpPicList[i]->setIsLongTerm(1);  //mark ilp as long-term reference
+        pIlpPicList[i]->setIsUsedAsLongTerm(1);  //mark ilp as long-term reference
+        m_apcRefPicList[REF_PIC_LIST_1][iOffset + i] = pIlpPicList[i]; 
+        m_aiNumRefIdx[REF_PIC_LIST_1]++;
+        //m_aiNumRefIdx[REF_PIC_LIST_C]++;
+      }
+    }
+  }
+}
+
+#if REF_IDX_MFM
+Void TComSlice::setRefPOCListILP( TComPic** ilpPic, TComPic *pcRefPicBL )
+{
+  //set reference picture POC of each ILP reference 
+  Int thePoc = ilpPic[0]->getPOC(); 
+  assert(thePoc >= 0); 
+  assert(thePoc == pcRefPicBL->getPOC());
+
+#if REUSE_MVSCALE || REUSE_BLKMAPPING
+  ilpPic[0]->getSlice(0)->setBaseColPic( pcRefPicBL );
+#endif
+
+  //initialize reference POC of ILP 
+  for(Int refIdx = 0; refIdx < MAX_NUM_REF; refIdx++) 
+  { 
+    ilpPic[0]->getSlice(0)->setRefPOC(0, REF_PIC_LIST_0, refIdx); 
+    ilpPic[0]->getSlice(0)->setRefPOC(0, REF_PIC_LIST_1, refIdx); 
+
+    ilpPic[0]->getSlice(0)->setRefPic(NULL, REF_PIC_LIST_0, refIdx); 
+    ilpPic[0]->getSlice(0)->setRefPic(NULL, REF_PIC_LIST_1, refIdx); 
+  }
+
+  //set reference POC of ILP 
+  ilpPic[0]->getSlice(0)->setNumRefIdx(REF_PIC_LIST_0, pcRefPicBL->getSlice(0)->getNumRefIdx(REF_PIC_LIST_0));
+  assert(ilpPic[0]->getSlice(0)->getNumRefIdx(REF_PIC_LIST_0) <= MAX_NUM_REF); 
+  ilpPic[0]->getSlice(0)->setNumRefIdx(REF_PIC_LIST_1, pcRefPicBL->getSlice(0)->getNumRefIdx(REF_PIC_LIST_1));
+  assert(ilpPic[0]->getSlice(0)->getNumRefIdx(REF_PIC_LIST_1) <= MAX_NUM_REF);
+
+  for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(REF_PIC_LIST_0); refIdx++) 
+  {
+    ilpPic[0]->getSlice(0)->setRefPOC(pcRefPicBL->getSlice(0)->getRefPOC(REF_PIC_LIST_0, refIdx), REF_PIC_LIST_0, refIdx); 
+  }
+  for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(REF_PIC_LIST_1); refIdx++) 
+  {
+    ilpPic[0]->getSlice(0)->setRefPOC(pcRefPicBL->getSlice(0)->getRefPOC(REF_PIC_LIST_1, refIdx), REF_PIC_LIST_1, refIdx);
+  }
+  for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(REF_PIC_LIST_0); refIdx++) 
+  {
+    ilpPic[0]->getSlice(0)->setRefPic(pcRefPicBL->getSlice(0)->getRefPic(REF_PIC_LIST_0, refIdx), REF_PIC_LIST_0, refIdx); 
+  }
+  for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(REF_PIC_LIST_1); refIdx++) 
+  {
+    ilpPic[0]->getSlice(0)->setRefPic(pcRefPicBL->getSlice(0)->getRefPic(REF_PIC_LIST_1, refIdx), REF_PIC_LIST_1, refIdx); 
+  }
+  return;
+}
+#endif
+
+
+#endif
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.h	(revision 54)
@@ -51,4 +51,8 @@
 class TComPic;
 class TComTrQuant;
+
+#if SVC_EXTENSION
+class TComPicYuv;
+#endif
 // ====================================================================================================================
 // Constants
@@ -850,4 +854,11 @@
   static const Int   m_winUnitY[MAX_CHROMA_FORMAT_IDC+1];
   TComPTL     m_pcPTL;
+
+#if SVC_EXTENSION
+  UInt m_layerId;
+#endif
+#if REF_IDX_MFM
+  Bool m_bMFMEnabledFlag;
+#endif
 public:
   TComSPS();
@@ -976,4 +987,13 @@
 
   TComPTL* getPTL()     { return &m_pcPTL; }
+
+#if SVC_EXTENSION
+  Void     setLayerId(UInt layerId) { m_layerId = layerId; }
+  UInt     getLayerId() { return m_layerId; }
+#endif
+#if REF_IDX_MFM
+  Void     setMFMEnabledFlag(Bool flag) {m_bMFMEnabledFlag = flag;}
+  Bool     getMFMEnabledFlag()          {return m_bMFMEnabledFlag;}
+#endif
 };
 
@@ -1283,4 +1303,9 @@
   Bool        m_bNoBackPredFlag;
   UInt        m_uiTLayer;
+#if SVC_EXTENSION
+  UInt        m_layerId;
+  TComPic*    m_pcBaseColPic;
+  TComPicYuv* m_pcFullPelBaseRec;
+#endif 
   Bool        m_bTLayerSwitchingFlag;
 
@@ -1319,5 +1344,9 @@
   TComSlice();
   virtual ~TComSlice(); 
+#if SET_SLICE_LAYER_ID
+  Void      initSlice       ( UInt layerId );
+#else
   Void      initSlice       ();
+#endif
 
   Void      setVPS          ( TComVPS* pcVPS ) { m_pcVPS = pcVPS; }
@@ -1417,4 +1446,24 @@
   Void      setDepth            ( Int iDepth )                  { m_iDepth            = iDepth; }
   
+#if SVC_EXTENSION  
+  Void      setBaseColPic       ( TComPic* p)                   { m_pcBaseColPic = p; }
+  Void      setBaseColPic       ( TComList<TComPic*>& rcListPic , UInt layerID );
+  TComPic*  getBaseColPic       ()  { return m_pcBaseColPic; }
+
+  Void      setLayerId (UInt layerId) { m_layerId = layerId; }
+  UInt      getLayerId ()               { return m_layerId; }
+
+  Void        setFullPelBaseRec   ( TComPicYuv* p) { m_pcFullPelBaseRec = p; }
+  TComPicYuv* getFullPelBaseRec   ()  { return  m_pcFullPelBaseRec;  }
+
+#if AVC_SYNTAX
+  Void      initBaseLayerRPL( TComSlice *pcSlice );
+#endif
+#endif
+
+#if REF_IDX_MFM
+  Void      setRefPOCListILP(TComPic** ilpPic, TComPic *pcRefPicBL);
+#endif
+
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic );
   Void      setRefPOCList       ();
@@ -1536,5 +1585,7 @@
   Void      setEnableTMVPFlag     ( Bool   b )    { m_enableTMVPFlag = b; }
   Bool      getEnableTMVPFlag     ()              { return m_enableTMVPFlag;}
-
+#if REF_IDX_FRAMEWORK
+  Void      addRefPicList( TComPic **pIlpPicList, Int iRefPicNum, Int iInsertOffset=0 );
+#endif
 protected:
   TComPic*  xGetRefPic  (TComList<TComPic*>& rcListPic,
@@ -1625,5 +1676,9 @@
   //! activate a PPS and depending on isIDR parameter also SPS and VPS
   //! \returns true, if activation is successful
+#if SVC_EXTENSION
+  Bool activatePPS(Int ppsId, Bool isIDR, UInt layerId);
+#else
   Bool activatePPS(Int ppsId, Bool isIDR);
+#endif
 
   TComVPS* getActiveVPS(){ return m_vpsMap.getPS(m_activeVPSId); };
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComTrQuant.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 54)
@@ -1236,4 +1236,10 @@
     uiMode = pcCU->getLumaIntraDir( uiAbsPartIdx );
   }
+#if INTRA_BL_DST4x4
+  else if(eTType == TEXT_LUMA && pcCU->isIntraBL(uiAbsPartIdx) )
+  {
+    uiMode = DC_IDX; //Using DST
+  }
+#endif
   else
   {
@@ -1309,5 +1315,16 @@
     Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eTxt];
     assert(scalingListType < 6);
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+    if(pcCU->isIntraBL(uiAbsPartIdx) && eTxt == TEXT_LUMA)
+    {
+      invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eTxt, DC_IDX, pResi, uiStride, rpcCoeff, uiWidth, uiHeight, scalingListType, pcCU->getTransformSkip(uiAbsPartIdx, eTxt) );
+    }
+    else
+    {
+      invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eTxt, REG_DCT, pResi, uiStride, rpcCoeff, uiWidth, uiHeight, scalingListType, pcCU->getTransformSkip(uiAbsPartIdx, eTxt) );
+    }
+#else
     invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eTxt, REG_DCT, pResi, uiStride, rpcCoeff, uiWidth, uiHeight, scalingListType, pcCU->getTransformSkip(uiAbsPartIdx, eTxt) );
+#endif
   }
   else
@@ -1803,5 +1820,9 @@
   Int     ui16CtxCbf          = 0;
   Int     iBestLastIdxP1      = 0;
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+  if( (!pcCU->isIntra( uiAbsPartIdx ) || pcCU->isIntraBL( uiAbsPartIdx )) && eTType == TEXT_LUMA && pcCU->getTransformIdx( uiAbsPartIdx ) == 0 )
+#else
   if( !pcCU->isIntra( uiAbsPartIdx ) && eTType == TEXT_LUMA && pcCU->getTransformIdx( uiAbsPartIdx ) == 0 )
+#endif
   {
     ui16CtxCbf   = 0;
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 54)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 54)
@@ -0,0 +1,604 @@
+
+#include "TComUpsampleFilter.h"
+#include "TypeDef.h"
+
+#if SVC_UPSAMPLING
+// ====================================================================================================================
+// Tables:
+// 1. PHASE_DERIVATION_IN_INTEGER = 0 is the implementation using 2 multi-phase (12 phase and 8 phase) filter sets 
+//    by following K0378.
+// 2. PHASE_DERIVATION_IN_INTEGER = 1 is the implemetation using a 16-phase filter set just for speed up. Some phases 
+//    is approximated to x/16 (e.g. 1/3 -> 5/16). 
+// 3. It was confirmed that two implementations provides the identical result. 
+// 4. By default, PHASE_DERIVATION_IN_INTEGER is set to 1. 
+// ====================================================================================================================
+#define CNU -1 ///< Coefficients Not Used
+
+#if PHASE_DERIVATION_IN_INTEGER
+const Int TComUpsampleFilter::m_lumaFixedFilter[16][NTAPS_US_LUMA] =
+{
+  {  0,  0,  0, 64,  0,  0,  0,  0}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  { -1, 4, -11, 52, 26,  -8, 3, -1}, // <-> actual phase shift 1/3, used for spatial scalability x1.5      
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //       
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  { -1, 4, -11, 40, 40, -11, 4, -1}, // <-> actual phase shift 1/2, equal to HEVC MC, used for spatial scalability x2
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  { -1, 3,  -8, 26, 52, -11, 4, -1}, // <-> actual phase shift 2/3, used for spatial scalability x1.5
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}  // 
+};
+
+const Int TComUpsampleFilter::m_chromaFixedFilter[16][NTAPS_US_CHROMA] =
+{
+#if CHROMA_UPSAMPLING
+  {  0, 64,  0,  0},//
+  {CNU,CNU,CNU,CNU},//
+  {CNU,CNU,CNU,CNU},//
+  {CNU,CNU,CNU,CNU},// 
+  { -4, 54, 16, -2},// <-> actual phase shift 1/4,equal to HEVC MC, used for spatial scalability x1.5 (only for accurate Chroma alignement)
+  { -6, 52, 20, -2},// <-> actual phase shift 1/3, used for spatial scalability x1.5   
+  { -6, 46, 28, -4},// <-> actual phase shift 3/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)      
+  {CNU,CNU,CNU,CNU},// 
+  { -4, 36, 36, -4},// <-> actual phase shift 1/2,equal to HEVC MC, used for spatial scalability x2
+  { -4, 30, 42, -4},// <-> actual phase shift 7/12, used for spatial scalability x1.5 (only for accurate Chroma alignement)
+  {CNU,CNU,CNU,CNU},// 
+  { -2, 20, 52, -6},// <-> actual phase shift 2/3, used for spatial scalability x1.5
+  {CNU,CNU,CNU,CNU},// 
+  {CNU,CNU,CNU,CNU},// 
+  { -2, 10, 58, -2},// <-> actual phase shift 7/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)  
+  {  0,  4, 62, -2} // <-> actual phase shift 11/12, used for spatial scalability x1.5 (only for accurate Chroma alignement)
+#else
+  {  0, 64,  0,  0},//
+  {CNU,CNU,CNU,CNU},//
+  {CNU,CNU,CNU,CNU},//
+  {CNU,CNU,CNU,CNU},// 
+  { -4, 54, 16, -2},// <-> actual phase shift 1/4,equal to HEVC MC, used for spatial scalability x1.5 (only for accurate Chroma alignement)
+  { -5, 50, 22, -3},// <-> actual phase shift 1/3, used for spatial scalability x1.5   
+  { -6, 46, 28, -4},// <-> actual phase shift 3/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)      
+  {CNU,CNU,CNU,CNU},// 
+  { -4, 36, 36, -4},// <-> actual phase shift 1/2,equal to HEVC MC, used for spatial scalability x2
+  { -4, 30, 43, -5},// <-> actual phase shift 7/12, used for spatial scalability x1.5 (only for accurate Chroma alignement)
+  {CNU,CNU,CNU,CNU},// 
+  { -3, 22, 50, -5},// <-> actual phase shift 2/3, used for spatial scalability x1.5
+  {CNU,CNU,CNU,CNU},// 
+  {CNU,CNU,CNU,CNU},// 
+  { -2, 10, 58, -2},// <-> actual phase shift 7/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)  
+  { -1,  5, 62, -2} // <-> actual phase shift 11/12, used for spatial scalability x1.5 (only for accurate Chroma alignement)
+#endif
+};
+#else
+const Int TComUpsampleFilter::m_lumaFixedFilter[12][NTAPS_US_LUMA] =
+{
+  { 0,  0,   0, 64,  0,   0, 0,  0},
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//1/12 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//2/12 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//3/12 
+  { -1, 4, -11, 52, 26,  -8, 3, -1},//4/12 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//5/12 
+  { -1, 4, -11, 40, 40, -11, 4, -1},//6/12       
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//7/12 
+  { -1, 3,  -8, 26, 52, -11, 4, -1},//8/12 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//9/12 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//10/12
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//11/12
+};
+
+const Int TComUpsampleFilter::m_chromaFixedFilter15[12][NTAPS_US_CHROMA] =
+{
+  {  0, 64,  0,  0},
+  {CNU,CNU,CNU,CNU},//1/12 
+  {CNU,CNU,CNU,CNU},//2/12 
+  { -4, 54, 16, -2},//3/12 
+  { -5, 50, 22, -3},//4/12 
+  {CNU,CNU,CNU,CNU},//5/12 
+  {CNU,CNU,CNU,CNU},//6/12 
+  { -4, 30, 43, -5},//7/12 
+  { -3, 22, 50, -5},//8/12 
+  {CNU,CNU,CNU,CNU},//9/12 
+  {CNU,CNU,CNU,CNU},//10/12
+  { -1,  5, 62, -2} //11/12
+};
+
+const Int TComUpsampleFilter::m_chromaFixedFilter20[8][NTAPS_US_CHROMA] =
+{
+  {  0, 64,  0,  0},
+  {CNU,CNU,CNU,CNU},//1/8 
+  {CNU,CNU,CNU,CNU},//2/8 
+  { -6, 46, 28, -4},//3/8 
+  { -4, 36, 36, -4},//4/8 
+  {CNU,CNU,CNU,CNU},//5/8 
+  {CNU,CNU,CNU,CNU},//6/8 
+  { -2, 10, 58, -2},//7/8 
+};
+#endif
+
+TComUpsampleFilter::TComUpsampleFilter(void)
+{
+}
+
+TComUpsampleFilter::~TComUpsampleFilter(void)
+{
+}
+
+Void TComUpsampleFilter::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic )
+{
+  assert ( NTAPS_US_LUMA == 8 );
+  assert ( NTAPS_US_CHROMA == 4 );
+
+  Int i, j;
+
+  //========== Y component upsampling ===========
+  const Window &confBL = pcBasePic->getConformanceWindow();
+  const Window &confEL = pcUsPic->getConformanceWindow();
+
+  Int iBWidth   = pcBasePic->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+  Int iBHeight  = pcBasePic->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+  Int iBStride  = pcBasePic->getStride();
+
+  Int iEWidth   = pcUsPic->getWidth () - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
+  Int iEHeight  = pcUsPic->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
+  Int iEStride  = pcUsPic->getStride();
+  
+  Pel* piTempBufY = pcTempPic->getLumaAddr();
+  Pel* piSrcBufY  = pcBasePic->getLumaAddr();
+  Pel* piDstBufY  = pcUsPic->getLumaAddr();
+  
+  Pel* piSrcY;
+  Pel* piDstY;
+  
+  Pel* piTempBufU = pcTempPic->getCbAddr();
+  Pel* piSrcBufU  = pcBasePic->getCbAddr();
+  Pel* piDstBufU  = pcUsPic->getCbAddr();
+  
+  Pel* piTempBufV = pcTempPic->getCrAddr();
+  Pel* piSrcBufV  = pcBasePic->getCrAddr();
+  Pel* piDstBufV  = pcUsPic->getCrAddr();
+  
+  Pel* piSrcU;
+  Pel* piDstU;
+  Pel* piSrcV;
+  Pel* piDstV;
+  
+#if JCTVC_L0178
+  Pel *tempBufRight = NULL, *tempBufBottom = NULL;
+  Int tempBufSizeRight = 0, tempBufSizeBottom = 0;
+  
+  if ( pcBasePic->getPicCropRightOffset() )
+  {
+    tempBufSizeRight = pcBasePic->getPicCropRightOffset() * pcBasePic->getHeight();
+  }
+  
+  if( pcBasePic->getPicCropBottomOffset() )
+  {
+    tempBufSizeBottom = pcBasePic->getPicCropBottomOffset() * pcBasePic->getWidth ();
+  }
+  
+  if( tempBufSizeRight )
+  {
+    tempBufRight = (Pel *) xMalloc(Pel, tempBufSizeRight + (tempBufSizeRight>>1) );
+    assert( tempBufRight );
+  }
+  
+  if( tempBufSizeBottom )
+  {
+    tempBufBottom = (Pel *) xMalloc(Pel, tempBufSizeBottom + (tempBufSizeBottom>>1) );
+    assert( tempBufBottom );
+  }
+ 
+#endif
+  
+#if PHASE_DERIVATION_IN_INTEGER
+  Int iRefPos16 = 0;
+  Int phase    = 0;
+  Int refPos   = 0; 
+  Int* coeff = m_chromaFilter[phase];
+  for ( i = 0; i < 16; i++)
+  {
+    memcpy(   m_lumaFilter[i],   m_lumaFixedFilter[i], sizeof(Int) * NTAPS_US_LUMA   );
+    memcpy( m_chromaFilter[i], m_chromaFixedFilter[i], sizeof(Int) * NTAPS_US_CHROMA );
+  }
+#else
+  for ( i = 0; i < 12; i++)
+  {
+    memcpy( m_lumaFilter[i], m_lumaFixedFilter[i], sizeof(Int) * NTAPS_US_LUMA );
+  }
+
+  Int chromaPhaseDenominator;
+  if (iEWidth == 2*iBWidth) // 2x scalability
+  {
+    for ( i = 0; i < 8; i++)
+    {
+      memcpy( m_chromaFilter[i], m_chromaFixedFilter20[i], sizeof(Int) * NTAPS_US_CHROMA );
+    }
+    chromaPhaseDenominator = 8;
+  }
+  else
+  {
+    for ( i = 0; i < 12; i++) // 1.5x scalability
+    {
+      memcpy( m_chromaFilter[i], m_chromaFixedFilter15[i], sizeof(Int) * NTAPS_US_CHROMA );
+    }
+    chromaPhaseDenominator = 12;
+  }
+#endif
+
+  assert ( iEWidth == 2*iBWidth || 2*iEWidth == 3*iBWidth );
+  assert ( iEHeight == 2*iBHeight || 2*iEHeight == 3*iBHeight );
+
+#if JCTVC_L0178
+  // save the cropped region to copy back to the base picture since the base picture might be used as a reference picture
+  if( tempBufSizeRight )
+  {
+    piSrcY = piSrcBufY + iBWidth;
+    piDstY = tempBufRight;
+    for( i = 0; i < pcBasePic->getHeight(); i++ )
+    {
+      memcpy(piDstY, piSrcY, sizeof(Pel) * pcBasePic->getPicCropRightOffset());
+      piSrcY += iBStride;
+      piDstY += pcBasePic->getPicCropRightOffset();
+    }
+    
+    if(pcBasePic->getPicCropRightOffset()>>1)
+    {
+      Int iBStrideChroma = (iBStride>>1);
+      piSrcU = piSrcBufU + (iBWidth>>1);
+      piDstU = tempBufRight + pcBasePic->getPicCropRightOffset() * pcBasePic->getHeight();
+      piSrcV = piSrcBufV + (iBWidth>>1);
+      piDstV = piDstU + (pcBasePic->getPicCropRightOffset()>>1) * (pcBasePic->getHeight()>>1);
+    
+      for( i = 0; i < pcBasePic->getHeight()>>1; i++ )
+      {
+        memcpy(piDstU, piSrcU, sizeof(Pel) * (pcBasePic->getPicCropRightOffset()>>1));
+        piSrcU += iBStrideChroma;
+        piDstU += (pcBasePic->getPicCropRightOffset()>>1);
+        
+        memcpy(piDstV, piSrcV, sizeof(Pel) * (pcBasePic->getPicCropRightOffset()>>1));
+        piSrcV += iBStrideChroma;
+        piDstV += (pcBasePic->getPicCropRightOffset()>>1);
+      }
+    }
+    
+    pcBasePic->setWidth(iBWidth);
+  }
+  
+  if( tempBufSizeBottom )
+  {
+    piSrcY = piSrcBufY + iBHeight * iBStride;
+    piDstY = tempBufBottom;
+    for( i = 0; i < pcBasePic->getPicCropBottomOffset(); i++ )
+    {
+      memcpy(piDstY, piSrcY, sizeof(Pel) * pcBasePic->getWidth());
+      piSrcY += iBStride;
+      piDstY += pcBasePic->getWidth();
+    }
+    
+    if(pcBasePic->getPicCropBottomOffset()>>1)
+    {
+      Int iBStrideChroma = (iBStride>>1);
+      piSrcU = piSrcBufU + (iBHeight>>1) * iBStrideChroma;
+      piDstU = tempBufBottom + pcBasePic->getPicCropBottomOffset() * pcBasePic->getWidth();
+      piSrcV = piSrcBufV + (iBHeight>>1) * iBStrideChroma;
+      piDstV = piDstU + (pcBasePic->getPicCropBottomOffset()>>1) * (pcBasePic->getWidth()>>1);
+      
+      for( i = 0; i < pcBasePic->getPicCropBottomOffset()>>1; i++ )
+      {
+        memcpy(piDstU, piSrcU, sizeof(Pel) * (pcBasePic->getWidth()>>1));
+        piSrcU += iBStrideChroma;
+        piDstU += (pcBasePic->getWidth()>>1);
+        
+        memcpy(piDstV, piSrcV, sizeof(Pel) * (pcBasePic->getWidth()>>1));
+        piSrcV += iBStrideChroma;
+        piDstV += (pcBasePic->getWidth()>>1);
+      }
+    }
+
+    pcBasePic->setHeight(iBHeight);
+  }
+#endif
+  
+  pcBasePic->setBorderExtension(false);
+  pcBasePic->extendPicBorder   (); // extend the border.
+
+#if PHASE_DERIVATION_IN_INTEGER
+  Int   iShiftX = 16;
+  Int   iShiftY = 16;
+
+  Int   iPhaseX = 0;
+  Int   iPhaseY = 0;
+
+  Int   iAddX       = ( ( ( iBWidth * iPhaseX ) << ( iShiftX - 2 ) ) + ( iEWidth >> 1 ) ) / iEWidth + ( 1 << ( iShiftX - 5 ) );
+  Int   iAddY       = ( ( ( iBHeight * iPhaseY ) << ( iShiftY - 2 ) ) + ( iEHeight >> 1 ) ) / iEHeight+ ( 1 << ( iShiftY - 5 ) );
+
+  Int   iDeltaX     = 4 * iPhaseX;
+  Int   iDeltaY     = 4 * iPhaseY;  
+
+
+  Int iShiftXM4 = iShiftX - 4;
+  Int iShiftYM4 = iShiftY - 4;
+
+  Int   iScaleX     = ( ( iBWidth << iShiftX ) + ( iEWidth >> 1 ) ) / iEWidth;
+  Int   iScaleY     = ( ( iBHeight << iShiftY ) + ( iEHeight >> 1 ) ) / iEHeight;
+#else
+  const Double sFactor = 1.0 * iBWidth / iEWidth;
+  const Double sFactor12 = sFactor * 12;
+#endif
+
+  //========== horizontal upsampling ===========
+  for( i = 0; i < iEWidth; i++ )
+  {
+#if PHASE_DERIVATION_IN_INTEGER
+    iRefPos16 = ((i*iScaleX + iAddX) >> iShiftXM4) - iDeltaX;
+    phase    = iRefPos16 & 15;
+    refPos   = iRefPos16 >> 4;
+    coeff = m_lumaFilter[phase];
+#else
+    Int refPos12 = (Int) ( i * sFactor12 );
+    Int refPos = (Int)( i * sFactor );
+    Int phase = (refPos12 + 12) % 12; 
+    Int* coeff = m_lumaFilter[phase];
+#endif
+
+    piSrcY = piSrcBufY + refPos -((NTAPS_US_LUMA>>1) - 1);
+    piDstY = piTempBufY + i;
+
+    for( j = 0; j < iBHeight ; j++ )
+    {
+      *piDstY = sumLumaHor(piSrcY, coeff);
+      piSrcY += iBStride;
+      piDstY += iEStride;
+    }
+  }
+
+
+  //========== vertical upsampling ===========
+  pcTempPic->setBorderExtension(false);
+  pcTempPic->setHeight(iBHeight);
+  pcTempPic->extendPicBorder   (); // extend the border.
+  pcTempPic->setHeight(iEHeight);
+
+  const Int nShift = US_FILTER_PREC*2;
+  Int iOffset = 1 << (nShift - 1); 
+
+  for( j = 0; j < iEHeight; j++ )
+  {
+#if PHASE_DERIVATION_IN_INTEGER
+    iRefPos16 = ((j*iScaleY + iAddY) >> iShiftYM4) - iDeltaY;
+    phase    = iRefPos16 & 15;
+    refPos   = iRefPos16 >> 4;
+    coeff = m_lumaFilter[phase];
+#else
+    Int refPos12 = (Int) (j * sFactor12 );
+    Int refPos = (Int)( j * sFactor );
+    Int phase = (refPos12 + 12) % 12;
+    Int* coeff = m_lumaFilter[phase];
+#endif
+
+    piSrcY = piTempBufY + (refPos -((NTAPS_US_LUMA>>1) - 1))*iEStride;
+    piDstY = piDstBufY + j * iEStride;
+
+    for( i = 0; i < iEWidth; i++ )
+    {
+      *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, iEStride) + iOffset) >> (nShift));
+      piSrcY++;
+      piDstY++;
+    }
+  }
+
+  //========== UV component upsampling ===========
+
+  iEWidth  >>= 1;
+  iEHeight >>= 1;
+
+  iBWidth  >>= 1;
+  iBHeight >>= 1;
+
+  iBStride  = pcBasePic->getCStride();
+  iEStride  = pcUsPic->getCStride();
+
+#if PHASE_DERIVATION_IN_INTEGER
+  iShiftX = 16;
+  iShiftY = 16;
+
+  iPhaseX = 0;
+  iPhaseY = 1;
+
+  iAddX       = ( ( ( iBWidth * iPhaseX ) << ( iShiftX - 2 ) ) + ( iEWidth >> 1 ) ) / iEWidth + ( 1 << ( iShiftX - 5 ) );
+  iAddY       = ( ( ( iBHeight * iPhaseY ) << ( iShiftY - 2 ) ) + ( iEHeight >> 1 ) ) / iEHeight+ ( 1 << ( iShiftY - 5 ) );
+
+  iDeltaX     = 4 * iPhaseX;
+  iDeltaY     = 4 * iPhaseY;
+
+  iShiftXM4 = iShiftX - 4;
+  iShiftYM4 = iShiftY - 4;
+
+  iScaleX     = ( ( iBWidth << iShiftX ) + ( iEWidth >> 1 ) ) / iEWidth;
+  iScaleY     = ( ( iBHeight << iShiftY ) + ( iEHeight >> 1 ) ) / iEHeight;
+#endif
+
+  //========== horizontal upsampling ===========
+  for( i = 0; i < iEWidth; i++ )
+  {
+#if PHASE_DERIVATION_IN_INTEGER
+    iRefPos16 = ((i*iScaleX + iAddX) >> iShiftXM4) - iDeltaX;
+    phase    = iRefPos16 & 15;
+    refPos   = iRefPos16 >> 4;
+    coeff = m_chromaFilter[phase];
+#else
+    Int refPosM = (Int) ( i * chromaPhaseDenominator * sFactor );
+    Int refPos = (Int)( i * sFactor );
+    Int phase = (refPosM + chromaPhaseDenominator) % chromaPhaseDenominator;
+    Int* coeff = m_chromaFilter[phase];
+#endif
+
+    piSrcU = piSrcBufU + refPos -((NTAPS_US_CHROMA>>1) - 1);
+    piSrcV = piSrcBufV + refPos -((NTAPS_US_CHROMA>>1) - 1);
+    piDstU = piTempBufU + i;
+    piDstV = piTempBufV + i;
+
+    for( j = 0; j < iBHeight ; j++ )
+    {
+      *piDstU = sumChromaHor(piSrcU, coeff);
+      *piDstV = sumChromaHor(piSrcV, coeff);
+
+      piSrcU += iBStride;
+      piSrcV += iBStride;
+      piDstU += iEStride;
+      piDstV += iEStride;
+    }
+  }
+
+  //========== vertical upsampling ===========
+  pcTempPic->setBorderExtension(false);
+  pcTempPic->setHeight(iBHeight << 1);
+  pcTempPic->extendPicBorder   (); // extend the border.
+  pcTempPic->setHeight(iEHeight << 1);
+
+  for( j = 0; j < iEHeight; j++ )
+  {
+#if PHASE_DERIVATION_IN_INTEGER
+    iRefPos16 = ((j*iScaleY + iAddY) >> iShiftYM4) - iDeltaY;
+    phase    = iRefPos16 & 15;
+    refPos   = iRefPos16 >> 4; 
+    coeff = m_chromaFilter[phase];
+#else
+    Int refPosM = (Int) (j * chromaPhaseDenominator * sFactor) - 1;
+    Int refPos; 
+    if ( refPosM < 0 )
+    {
+      refPos = (Int)( j * sFactor ) - 1;
+    }
+    else
+    {
+      refPos = refPosM / chromaPhaseDenominator;
+    }
+    Int phase = (refPosM + chromaPhaseDenominator) % chromaPhaseDenominator;
+    Int* coeff = m_chromaFilter[phase];
+#endif
+
+    piSrcU = piTempBufU  + (refPos -((NTAPS_US_CHROMA>>1) - 1))*iEStride;
+    piSrcV = piTempBufV  + (refPos -((NTAPS_US_CHROMA>>1) - 1))*iEStride;
+
+    piDstU = piDstBufU + j*iEStride;
+    piDstV = piDstBufV + j*iEStride;
+
+    for( i = 0; i < iEWidth; i++ )
+    {
+      *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, iEStride) + iOffset) >> (nShift));
+      *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, iEStride) + iOffset) >> (nShift));
+
+      piSrcU++;
+      piSrcV++;
+      piDstU++;
+      piDstV++;
+    }
+  }
+
+  pcUsPic->setBorderExtension(false);
+  pcUsPic->extendPicBorder   (); // extend the border.
+
+  //Reset the Border extension flag
+  pcUsPic->setBorderExtension(false);
+  pcTempPic->setBorderExtension(false);
+  pcBasePic->setBorderExtension(false);
+  
+#if JCTVC_L0178
+  // copy back the saved cropped region
+  if( tempBufSizeRight )
+  {
+    // put the correct width back
+    pcBasePic->setWidth(pcBasePic->getWidth()+pcBasePic->getPicCropRightOffset());
+  }
+  if( tempBufSizeBottom )
+  {
+    pcBasePic->setHeight(pcBasePic->getHeight()+pcBasePic->getPicCropBottomOffset());
+  }
+  
+  iBWidth   = pcBasePic->getWidth () - pcBasePic->getPicCropLeftOffset() - pcBasePic->getPicCropRightOffset();
+  iBHeight  = pcBasePic->getHeight() - pcBasePic->getPicCropTopOffset() - pcBasePic->getPicCropBottomOffset();
+  
+  iBStride  = pcBasePic->getStride();
+  
+  if( tempBufSizeRight )
+  {
+    piSrcY = tempBufRight;
+    piDstY = piSrcBufY + iBWidth;
+    
+    for( i = 0; i < pcBasePic->getHeight(); i++ )
+    {
+      memcpy(piDstY, piSrcY, sizeof(Pel) * pcBasePic->getPicCropRightOffset());
+      piSrcY += pcBasePic->getPicCropRightOffset();
+      piDstY += iBStride;
+    }
+    
+    if(pcBasePic->getPicCropRightOffset()>>1)
+    {
+      Int iBStrideChroma = (iBStride>>1);
+      piSrcU = tempBufRight + pcBasePic->getPicCropRightOffset() * pcBasePic->getHeight();
+      piDstU = piSrcBufU + (iBWidth>>1);
+      piSrcV = piSrcU + (pcBasePic->getPicCropRightOffset()>>1) * (pcBasePic->getHeight()>>1);
+      piDstV = piSrcBufV + (iBWidth>>1);
+
+      for( i = 0; i < pcBasePic->getHeight()>>1; i++ )
+      {
+        memcpy(piDstU, piSrcU, sizeof(Pel) * (pcBasePic->getPicCropRightOffset()>>1));
+        piSrcU += (pcBasePic->getPicCropRightOffset()>>1);
+        piDstU += iBStrideChroma;
+        
+        memcpy(piDstV, piSrcV, sizeof(Pel) * (pcBasePic->getPicCropRightOffset()>>1));
+        piSrcV += (pcBasePic->getPicCropRightOffset()>>1);
+        piDstV += iBStrideChroma;
+      }
+    }
+  }
+  
+  if( tempBufSizeBottom )
+  {
+    piDstY = piSrcBufY + iBHeight * iBStride;
+    piSrcY = tempBufBottom;
+    for( i = 0; i < pcBasePic->getPicCropBottomOffset(); i++ )
+    {
+      memcpy(piDstY, piSrcY, sizeof(Pel) * pcBasePic->getWidth());
+      piDstY += iBStride;
+      piSrcY += pcBasePic->getWidth();
+    }
+    
+    if(pcBasePic->getPicCropBottomOffset()>>1)
+    {
+      Int iBStrideChroma = (iBStride>>1);
+      piSrcU = tempBufBottom + pcBasePic->getPicCropBottomOffset() * pcBasePic->getWidth();
+      piDstU = piSrcBufU + (iBHeight>>1) * iBStrideChroma;
+      piSrcV = piSrcU + (pcBasePic->getPicCropBottomOffset()>>1) * (pcBasePic->getWidth()>>1);
+      piDstV = piSrcBufV + (iBHeight>>1) * iBStrideChroma;
+            
+      for( i = 0; i < pcBasePic->getPicCropBottomOffset()>>1; i++ )
+      {
+        memcpy(piDstU, piSrcU, sizeof(Pel) * (pcBasePic->getWidth()>>1));
+        piSrcU += (pcBasePic->getWidth()>>1);
+        piDstU += iBStrideChroma;
+        
+        memcpy(piDstV, piSrcV, sizeof(Pel) * (pcBasePic->getWidth()>>1));
+        piSrcV += (pcBasePic->getWidth()>>1);
+        piDstV += iBStrideChroma;
+      }
+    }
+  
+  }
+
+  if( tempBufSizeRight )
+  {
+    xFree( tempBufRight );
+  }
+  if( tempBufSizeBottom )
+  {
+    xFree( tempBufBottom );
+  }
+#endif
+}
+#endif //SVC_EXTENSION
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComUpsampleFilter.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 54)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 54)
@@ -0,0 +1,57 @@
+#ifndef __TCOMUPSAMPLEFILTER__
+#define __TCOMUPSAMPLEFILTER__
+
+#include "TComPic.h"
+#include "TComYuv.h"
+#include "TComDataCU.h"
+
+#define NTAPS_US_LUMA        8 ///< Number of taps for luma upsampling filter
+#define NTAPS_US_CHROMA      4 ///< Number of taps for chroma upsampling filter
+#define US_FILTER_PREC       6 ///< Log2 of sum of filter taps
+
+class TComUpsampleFilter
+{
+private:
+#if PHASE_DERIVATION_IN_INTEGER
+  static const Int m_lumaFixedFilter[16][NTAPS_US_LUMA];     ///< Luma filter taps for both 1.5x and 2x scalability
+  static const Int m_chromaFixedFilter[16][NTAPS_US_CHROMA]; ///< Chroma filter taps for 1.5x scalability
+
+  Int m_lumaFilter[16][NTAPS_US_LUMA];
+  Int m_chromaFilter[16][NTAPS_US_CHROMA];
+#else
+  static const Int m_lumaFixedFilter[12][NTAPS_US_LUMA];     ///< Luma filter taps for both 1.5x and 2x scalability
+  static const Int m_chromaFixedFilter20[8][NTAPS_US_CHROMA]; ///< Chroma filter taps for 2x scalability
+  static const Int m_chromaFixedFilter15[12][NTAPS_US_CHROMA]; ///< Chroma filter taps for 1.5x scalability
+
+  Int m_lumaFilter[12][NTAPS_US_LUMA];
+  Int m_chromaFilter[12][NTAPS_US_CHROMA];
+#endif
+
+  static inline Int sumLumaHor( Pel* pel, Int* coeff )
+  {
+    return ( pel[0]*coeff[0] + pel[1]*coeff[1] + pel[2]*coeff[2] + pel[3]*coeff[3] + pel[4]*coeff[4] + pel[5]*coeff[5] + pel[6]*coeff[6] + pel[7]*coeff[7]);
+  }
+
+  static inline Int sumChromaHor( Pel* pel, Int* coeff )
+  {
+    return ( pel[0]*coeff[0] + pel[1]*coeff[1] + pel[2]*coeff[2] + pel[3]*coeff[3] );
+  }
+
+  static inline Int sumLumaVer( Pel* pel, Int* coeff, Int stride )
+  {
+    return ( pel[0]*coeff[0] + pel[stride]*coeff[1] + pel[2*stride]*coeff[2] + pel[3*stride]*coeff[3] + pel[4*stride]*coeff[4] + pel[5*stride]*coeff[5] + pel[6*stride]*coeff[6] + pel[7*stride]*coeff[7]);
+  }
+
+  static inline Int sumChromaVer( Pel* pel, Int* coeff, Int stride )
+  {
+    return ( pel[0]*coeff[0] + pel[stride]*coeff[1] + pel[2*stride]*coeff[2] + pel[3*stride]*coeff[3] );
+  }
+
+public:
+  TComUpsampleFilter(void);
+  ~TComUpsampleFilter(void);
+
+ Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
+};
+
+#endif //__TCOMUPSAMPLEFILTER__
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComYuv.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComYuv.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComYuv.cpp	(revision 54)
@@ -184,4 +184,57 @@
 }
 
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+Void TComYuv::copyFromPicLuma  ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiZorderIdxInCU, UInt uiAbsZorderIdx, UInt uiWidth, UInt uiHeight )
+{
+  Int  y;
+
+  Pel* pDst     = getLumaAddr(uiAbsZorderIdx);
+  Pel* pSrc     = pcPicYuvSrc->getLumaAddr ( iCuAddr, uiZorderIdxInCU + uiAbsZorderIdx );
+
+  UInt  iDstStride  = getStride();
+  UInt  iSrcStride  = pcPicYuvSrc->getStride();
+  for ( y = uiHeight; y != 0; y-- )
+  {
+    ::memcpy( pDst, pSrc, sizeof(Pel)*uiWidth);
+    pDst += iDstStride;
+    pSrc += iSrcStride;
+  }
+}
+
+Void TComYuv::copyFromPicChroma( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiZorderIdxInCU, UInt uiAbsZorderIdx, UInt uiCWidth, UInt uiCHeight, UInt uiChromaId  )
+{
+  Int  y;
+
+  if (!uiChromaId)
+  {
+    Pel* pDstU      = getCbAddr(uiAbsZorderIdx); 
+    Pel* pSrcU      = pcPicYuvSrc->getCbAddr( iCuAddr, uiZorderIdxInCU + uiAbsZorderIdx );
+
+    UInt  iDstStride = getCStride();
+    UInt  iSrcStride = pcPicYuvSrc->getCStride();
+    for ( y = uiCHeight; y != 0; y-- )
+    {
+      ::memcpy( pDstU, pSrcU, sizeof(Pel)*(uiCWidth) );
+      pSrcU += iSrcStride;
+      pDstU += iDstStride;
+    }
+  }
+  else
+  {
+    Pel* pDstV      = getCrAddr(uiAbsZorderIdx);
+    Pel* pSrcV      = pcPicYuvSrc->getCrAddr( iCuAddr, uiZorderIdxInCU + uiAbsZorderIdx );
+
+    UInt  iDstStride = getCStride();
+    UInt  iSrcStride = pcPicYuvSrc->getCStride();
+    for ( y = uiCHeight; y != 0; y-- )
+    {
+      ::memcpy( pDstV, pSrcV, sizeof(Pel)*(uiCWidth) );
+      pSrcV += iSrcStride;
+      pDstV += iDstStride;
+    }
+  }
+}
+#endif
+
 Void TComYuv::copyToPartYuv( TComYuv* pcYuvDst, UInt uiDstPartIdx )
 {
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComYuv.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComYuv.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComYuv.h	(revision 54)
@@ -115,4 +115,8 @@
   Void    copyFromPicLuma      ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx );
   Void    copyFromPicChroma    ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx );
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+  Void    copyFromPicLuma  ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiZorderIdxInCU, UInt uiAbsZorderIdx, UInt uiWidth, UInt uiHeight );
+  Void    copyFromPicChroma( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiZorderIdxInCU, UInt uiAbsZorderIdx, UInt uiCWidth, UInt uiCHeight, UInt uiChromaId  );
+#endif
   
   //  Copy Small YUV buffer to the part of other Big YUV buffer
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TypeDef.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TypeDef.h	(revision 54)
@@ -38,4 +38,68 @@
 #ifndef _TYPEDEF__
 #define _TYPEDEF__
+
+#define SVC_EXTENSION                    1
+
+#define SYNTAX_BYTES                     10      ///< number of bytes taken by syntaxes per 4x4 block [RefIdxL0(1byte), RefIdxL1(1byte), MVxL0(2bytes), MVyL0(2bytes), MVxL1(2bytes), MVyL1(2bytes)]
+
+#if SVC_EXTENSION
+#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
+
+#define SVC_COL_BLK                      1      ///< get co-located block
+#define SVC_UPSAMPLING                   1      ///< upsampling filters
+#define PHASE_DERIVATION_IN_INTEGER      1      ///< upsampling filters implementation using only integer arithmetic
+#define SET_SLICE_LAYER_ID               1      ///< set layerId to the slice
+#define BUGFIX_925                       1      ///< bug fix ticket #925
+#define ENCODER_BUGFIX                   1      ///< L0167: encoder bug fix for inter mode
+#define CHROMA_UPSAMPLING                1      ///< L0335: Chroma upsampling with 5 bits coefficients
+
+#define MV_SCALING_FIX                   1      ///< fixing the base layer MV scaling
+#define MV_SCALING_POS_FIX               1      ///< use center pixels to get co-located base layer block
+#define MFM_CLIPPING_FIX                 1      ///< set the right picture size for the clipping
+
+#define AVC_BASE                         0      ///< YUV BL reading for AVC base SVC
+#define REF_IDX_FRAMEWORK                0      ///< inter-layer reference framework
+
+#if AVC_BASE
+#define AVC_SYNTAX                       1      ///< Syntax reading for AVC base
+#endif
+
+#if REF_IDX_FRAMEWORK
+#define REF_IDX_ME_AROUND_ZEROMV         0      ///< added ME around zero MV for inter-layer reference picture
+#define REF_IDX_ME_ZEROMV                1      ///< L0051: use zero motion for inter-layer reference picture (without fractional ME)
+#define ENCODER_FAST_MODE                1      ///< L0174: enable encoder fast mode. TestMethod 1 is enabled by setting to 1 and TestMethod 2 is enable by setting to 2. By default it is set to 1.
+#if !AVC_BASE || AVC_SYNTAX
+#define REF_IDX_MFM                      1      ///< L0336: motion vector mapping of inter-layer reference picture
+#endif
+
+#if REF_IDX_MFM
+#define REUSE_MVSCALE                    1      ///< using the base layer MV scaling function
+#define REUSE_BLKMAPPING                 1      ///< using the base layer get co-located block function
+#endif
+
+#else
+#define INTRA_BL                         0      ///< inter-layer texture prediction
+
+#if INTRA_BL
+#define INTRA_BL_DST4x4                  1      ///< L0067/L0204: DST4x4 for Intra BL
+#define NO_RESIDUAL_FLAG_FOR_BLPRED      1      ///< L0437: Root cbf for Intra_BL
+
+// Hooks
+#if !AVC_BASE || AVC_SYNTAX
+#define SVC_MVP                          1      ///< motion hook for merge mode as an example
+#if !AVC_SYNTAX
+#define SVC_BL_CAND_INTRA                0      ///< Intra Base Mode Prediction hook as an example 
+#endif
+#endif
+
+#if SVC_UPSAMPLING
+#define JCTVC_L0178                      1      ///< implementation of JCTVC-L0178 (code only supports right and bottom croppping offsets)
+#endif
+
+#endif
+#endif
+#else
+#define SYNTAX_OUTPUT                    0
+#endif
 
 //! \ingroup TLibCommon
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/NALread.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/NALread.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/NALread.cpp	(revision 54)
@@ -100,5 +100,9 @@
   nalu.m_nalUnitType = (NalUnitType) bs.read(6);  // nal_unit_type
   nalu.m_reservedZero6Bits = bs.read(6);       // nuh_reserved_zero_6bits
+#if SVC_EXTENSION
+  nalu.m_layerId = nalu.m_reservedZero6Bits;
+#else
   assert(nalu.m_reservedZero6Bits == 0);
+#endif
   nalu.m_temporalId = bs.read(3) - 1;             // nuh_temporal_id_plus1
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 54)
@@ -697,5 +697,12 @@
   }
   READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" );            pcSPS->setTMVPFlagsPresent(uiCode);
-
+#if REF_IDX_MFM
+  if(pcSPS->getLayerId() > 0)
+  {
+    READ_FLAG( uiCode, "sps_enh_mfm_enable_flag" );
+    pcSPS->setMFMEnabledFlag( uiCode ? true : false );
+    assert(pcSPS->getMFMEnabledFlag()); 
+  }
+#endif
   READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" );  pcSPS->setUseStrongIntraSmoothing(uiCode);
 
@@ -1927,4 +1934,11 @@
 }
 
+#if INTRA_BL
+Void TDecCavlc::parseIntraBLFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
+{
+  assert(0);
+}
+#endif
+
 //! \}
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 54)
@@ -120,4 +120,8 @@
   Void updateContextTables  ( SliceType /*eSliceType*/, Int /*iQp*/ ) { return; }
 
+#if INTRA_BL
+  Void parseIntraBLFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
+#endif
+
   Void xParsePredWeightTable ( TComSlice* pcSlice );
   Void  parseScalingList               ( TComScalingList* scalingList );
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCu.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCu.cpp	(revision 54)
@@ -37,4 +37,8 @@
 
 #include "TDecCu.h"
+#if SVC_EXTENSION
+#include "TDecTop.h"
+#endif
+
 
 //! \ingroup TLibDecoder
@@ -56,4 +60,19 @@
 }
 
+#if SVC_EXTENSION
+Void TDecCu::init(TDecTop** ppcDecTop, TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction, UInt layerId)
+{
+  m_pcEntropyDecoder  = pcEntropyDecoder;
+  m_pcTrQuant         = pcTrQuant;
+  m_pcPrediction      = pcPrediction; 
+  m_ppcTDecTop = ppcDecTop;
+  m_layerId = layerId; 
+
+  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
+  {
+    m_ppcCU     [ui]->setLayerId(layerId);
+  }
+}
+#else
 Void TDecCu::init( TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction)
 {
@@ -62,4 +81,5 @@
   m_pcPrediction      = pcPrediction;
 }
+#endif
 
 /**
@@ -128,4 +148,7 @@
 
   // start from the top level CU
+#if SVC_EXTENSION
+  pcCU->setLayerId(m_layerId);
+#endif
   xDecodeCU( pcCU, 0, 0, ruiIsLast);
 }
@@ -311,4 +334,13 @@
     return;
   }
+#if INTRA_BL
+  m_pcEntropyDecoder->decodeIntraBLFlag( pcCU, uiAbsPartIdx, 0, uiDepth );
+  if ( pcCU->isIntraBL( uiAbsPartIdx ) )
+  {
+    pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); 
+  }
+  else
+  {
+#endif
 
   m_pcEntropyDecoder->decodePredMode( pcCU, uiAbsPartIdx, uiDepth );
@@ -325,10 +357,17 @@
     }
   }
+#if INTRA_BL
+  // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
+  m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
+  }
+#endif
 
   UInt uiCurrWidth      = pcCU->getWidth ( uiAbsPartIdx );
   UInt uiCurrHeight     = pcCU->getHeight( uiAbsPartIdx );
   
+#if !INTRA_BL
   // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
   m_pcEntropyDecoder->decodePredInfo( pcCU, uiAbsPartIdx, uiDepth, m_ppcCU[uiDepth]);
+#endif
   
   // Coefficient decoding
@@ -401,4 +440,13 @@
       xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
       break;
+#if INTRA_BL
+    case MODE_INTRA_BL:
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+      xReconIntraBL( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
+#else
+      xReconIntraQT( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
+#endif
+      break;
+#endif
     default:
       assert(0);
@@ -468,4 +516,11 @@
   
   //===== get prediction signal =====
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED
+  if(pcCU->isIntraBL ( uiAbsPartIdx ) )
+  {
+    pcCU->getBaseLumaBlk( uiWidth, uiHeight, uiAbsPartIdx, piPred, uiStride );
+  }
+  else
+#endif
   m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
   
@@ -552,4 +607,11 @@
   
   //===== get prediction signal =====
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED
+  if(pcCU->isIntraBL ( uiAbsPartIdx ) )
+  {
+    pcCU->getBaseChromaBlk( uiWidth, uiHeight, uiAbsPartIdx, piPred, uiStride, uiChromaId );
+  }
+  else
+#endif
   {
     if( uiChromaPredMode == DM_CHROMA_IDX )
@@ -869,3 +931,26 @@
 }
 
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+Void
+TDecCu::xReconIntraBL( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+{
+  m_ppcYuvReco[uiDepth]->copyFromPicLuma  ( pcCU->getSlice()->getFullPelBaseRec(),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, pcCU->getWidth(0), pcCU->getHeight(0));
+  m_ppcYuvReco[uiDepth]->copyFromPicChroma( pcCU->getSlice()->getFullPelBaseRec(),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, (pcCU->getWidth(0)>>1), (pcCU->getHeight(0)>>1), 0);
+  m_ppcYuvReco[uiDepth]->copyFromPicChroma( pcCU->getSlice()->getFullPelBaseRec(),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, (pcCU->getWidth(0)>>1), (pcCU->getHeight(0)>>1), 1);
+
+  // inter recon
+  xDecodeInterTexture( pcCU, 0, uiDepth );
+
+  // clip for only non-zero cbp case
+  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
+  {
+    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
+  }
+  else
+  {
+    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
+  }
+}
+#endif
+
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCu.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCu.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCu.h	(revision 54)
@@ -49,4 +49,7 @@
 //! \ingroup TLibDecoder
 //! \{
+#if SVC_EXTENSION
+class TDecTop;
+#endif
 
 // ====================================================================================================================
@@ -69,4 +72,12 @@
 
   Bool                m_bDecodeDQP;
+#if SVC_EXTENSION
+  TDecTop**           m_ppcTDecTop;
+  UInt                m_layerId;   
+#endif
+  
+#if INTRA_BL
+  TComPicYuv*         m_pcPicYuvRecBase;       ///< reconstructed base layer
+#endif 
   
 public:
@@ -75,5 +86,9 @@
   
   /// initialize access channels
+#if SVC_EXTENSION
+  Void  init                    ( TDecTop** ppcDecTop, TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction, UInt layerId );
+#else
   Void  init                    ( TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction );
+#endif 
   
   /// create internal buffers
@@ -89,4 +104,10 @@
   Void  decompressCU            ( TComDataCU* pcCU );
   
+#if SVC_EXTENSION
+  TDecTop*   getLayerDec        ( UInt LayerId )  { return m_ppcTDecTop[LayerId]; }
+#if INTRA_BL
+  Void  setBaseRecPic           ( TComPicYuv* p ) { m_pcPicYuvRecBase = p; }
+#endif 
+#endif
 protected:
   
@@ -101,4 +122,7 @@
   Void  xIntraRecLumaBlk        ( TComDataCU* pcCU, UInt uiTrDepth, UInt uiAbsPartIdx, TComYuv* pcRecoYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv );
   Void  xIntraRecChromaBlk      ( TComDataCU* pcCU, UInt uiTrDepth, UInt uiAbsPartIdx, TComYuv* pcRecoYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv, UInt uiChromaId );
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+  Void  xReconIntraBL           ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+#endif
   
   Void  xReconPCM               ( TComDataCU* pcCU, UInt uiDepth );
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 54)
@@ -58,4 +58,11 @@
 }
 
+#if INTRA_BL
+Void TDecEntropy::decodeIntraBLFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
+{
+  m_pcEntropyDecoderIf->parseIntraBLFlag( pcCU, uiAbsPartIdx, uiPartIdx, uiDepth );
+}
+#endif
+
 /** decode merge flag
  * \param pcSubCU
@@ -104,4 +111,10 @@
 Void TDecEntropy::decodePredInfo    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComDataCU* pcSubCU )
 {
+#if INTRA_BL
+  if( pcCU->isIntraBL( uiAbsPartIdx ) )                                 // Do nothing for Intra BL mode.
+  {
+    return;
+  }
+#endif
   if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
   {
@@ -175,4 +188,14 @@
       decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
       UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
+#if REF_IDX_FRAMEWORK  // HM bug fix
+      if(uiPartIdx)
+      {
+        for(UInt ui=0; ui<uiMergeIndex+1; ui++)
+        {
+          cMvFieldNeighbours[(ui<<1)].setMvField(TComMv(), NOT_VALID);
+          cMvFieldNeighbours[(ui<<1)+1].setMvField(TComMv(), NOT_VALID);
+        }
+      }
+#endif
       if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) 
       {
@@ -437,5 +460,13 @@
     
     pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth );
+#if INTRA_BL
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+    if( ( !pcCU->isIntra(uiAbsPartIdx) || pcCU->isIntraBL(uiAbsPartIdx)) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
+#else
+    if( ( !pcCU->isIntra(uiAbsPartIdx) ) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
+#endif
+#else
     if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
+#endif 
     {
       pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth );
@@ -535,5 +566,9 @@
   UInt uiChromaOffset = uiLumaOffset>>2;
   
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+  if( pcCU->isIntra(uiAbsPartIdx) && !pcCU->isIntraBL(uiAbsPartIdx) )
+#else
   if( pcCU->isIntra(uiAbsPartIdx) )
+#endif
   {
   }
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecEntropy.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecEntropy.h	(revision 54)
@@ -102,4 +102,9 @@
   virtual Void parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0;
   virtual Void parseTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType) = 0;
+
+#if INTRA_BL
+  virtual Void parseIntraBLFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth ) = 0;
+#endif
+
   virtual Void updateContextTables( SliceType eSliceType, Int iQp ) = 0;
   
@@ -157,4 +162,7 @@
   Void updateContextTables    ( SliceType eSliceType, Int iQp ) { m_pcEntropyDecoderIf->updateContextTables( eSliceType, iQp ); }
   
+#if INTRA_BL
+  Void decodeIntraBLFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
+#endif
   
 private:
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecGop.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecGop.cpp	(revision 54)
@@ -43,4 +43,7 @@
 #include "libmd5/MD5.h"
 #include "TLibCommon/SEI.h"
+#if SVC_EXTENSION
+#include "TDecTop.h"
+#endif
 
 #include <time.h>
@@ -67,15 +70,25 @@
 }
 
+#if SVC_EXTENSION
+Void TDecGop::create(UInt layerId)
+{
+  m_layerId = layerId;
+}
+#else
 Void TDecGop::create()
 {
   
 }
-
+#endif
 
 Void TDecGop::destroy()
 {
 }
-
+#if SVC_EXTENSION
+Void TDecGop::init(TDecTop**               ppcDecTop,
+                   TDecEntropy*            pcEntropyDecoder,
+#else
 Void TDecGop::init( TDecEntropy*            pcEntropyDecoder, 
+#endif
                    TDecSbac*               pcSbacDecoder, 
                    TDecBinCABAC*           pcBinCABAC,
@@ -93,4 +106,7 @@
   m_pcLoopFilter          = pcLoopFilter;
   m_pcSAO  = pcSAO;
+#if SVC_EXTENSION   
+  m_ppcTDecTop            = ppcDecTop;
+#endif
 }
 
@@ -210,9 +226,16 @@
 
   //-- For time output for each slice
+#if SVC_EXTENSION
+  printf("\nPOC %4d LId: %1d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(),
+                                                    rpcPic->getLayerId(),
+                                                    pcSlice->getTLayer(),
+                                                    c,
+                                                    pcSlice->getSliceQp() );
+#else
   printf("\nPOC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(),
                                                     pcSlice->getTLayer(),
                                                     c,
                                                     pcSlice->getSliceQp() );
-
+#endif
   m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
   printf ("[DT %6.3f] ", m_dDecTime );
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecGop.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecGop.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecGop.h	(revision 54)
@@ -87,9 +87,18 @@
   std::vector<Bool> m_LFCrossSliceBoundaryFlag;
 
+#if SVC_EXTENSION
+  UInt                  m_layerId;
+  TDecTop**             m_ppcTDecTop;
+#endif
 public:
   TDecGop();
   virtual ~TDecGop();
   
+#if SVC_EXTENSION
+Void  init      ( TDecTop**               ppcDecTop,
+                  TDecEntropy*            pcEntropyDecoder, 
+#else
   Void  init    ( TDecEntropy*            pcEntropyDecoder, 
+#endif
                  TDecSbac*               pcSbacDecoder, 
                  TDecBinCABAC*           pcBinCABAC,
@@ -99,5 +108,9 @@
                  TComSampleAdaptiveOffset* pcSAO
                  );
+#if SVC_EXTENSION
+  Void  create  (UInt layerId);
+#else
   Void  create  ();
+#endif
   Void  destroy ();
   Void  decompressSlice(TComInputBitstream* pcBitstream, TComPic*& rpcPic );
@@ -105,4 +118,7 @@
 
   void setDecodedPictureHashSEIEnabled(Int enabled) { m_decodedPictureHashSEIEnabled = enabled; }
+#if SVC_EXTENSION
+  TDecTop*   getLayerDec(UInt LayerId)  { return m_ppcTDecTop[LayerId]; }
+#endif 
 
 };
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 54)
@@ -77,4 +77,7 @@
 , m_cTransformSkipSCModel     ( 1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
 , m_CUTransquantBypassFlagSCModel( 1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+#if INTRA_BL
+, m_cIntraBLPredFlagSCModel   (1,              1,               NUM_INTRA_BL_PRED_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
+#endif
 {
   assert( m_numContextModels <= MAX_NUM_CTX_MOD );
@@ -135,4 +138,7 @@
 
   m_cCUTransSubdivFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
+#if INTRA_BL
+  m_cIntraBLPredFlagSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTRA_BL_PRED_FLAG );
+#endif
   m_cTransformSkipSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
   m_CUTransquantBypassFlagSCModel.initBuffer( sliceType, qp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
@@ -179,4 +185,7 @@
   m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
   m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
+#if INTRA_BL
+  m_cIntraBLPredFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_BL_PRED_FLAG );
+#endif
   m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
   m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
@@ -431,4 +440,32 @@
 }
 
+#if INTRA_BL
+Void TDecSbac::parseIntraBLFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
+{
+  if( pcCU->getLayerId() == 0 )
+  {
+    return;
+  }
+
+  UInt uiSymbol = 0;
+
+  UInt uiCtxIntraBL = pcCU->getCtxIntraBLFlag( uiAbsPartIdx ) ;
+  m_pcTDecBinIf->decodeBin( uiSymbol, m_cIntraBLPredFlagSCModel.get( 0, 0, uiCtxIntraBL )); 
+  DTRACE_CABAC_VL( g_nSymbolCounter++ );
+  DTRACE_CABAC_T( "\tIntrBLFlag" );
+  DTRACE_CABAC_T( "\tuiSymbol: ");
+  DTRACE_CABAC_V( uiSymbol );
+  DTRACE_CABAC_T( "\n");
+
+  if ( uiSymbol )
+  {
+    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
+    pcCU->setPredModeSubParts( MODE_INTRA_BL, uiAbsPartIdx, uiDepth );
+    pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth );
+    pcCU->setLumaIntraDirSubParts ( DC_IDX, uiAbsPartIdx, uiDepth );   
+  }
+}
+#endif
+
 /** parse merge flag
  * \param pcCU
@@ -521,4 +558,10 @@
   PartSize eMode;
   
+#if INTRA_BL
+  if ( pcCU->isIntraBL( uiAbsPartIdx ) )
+  {
+    assert( 0 );
+  }
+#endif
   if ( pcCU->isIntra( uiAbsPartIdx ) )
   {
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSbac.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSbac.h	(revision 54)
@@ -131,4 +131,7 @@
   Void  parseScalingList ( TComScalingList* /*scalingList*/ ) {}
 
+#if INTRA_BL
+  Void parseIntraBLFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
+#endif
 private:
   UInt m_uiLastDQpNonZero;
@@ -167,4 +170,7 @@
   ContextModel3DBuffer m_cTransformSkipSCModel;
   ContextModel3DBuffer m_CUTransquantBypassFlagSCModel;
+#if INTRA_BL
+  ContextModel3DBuffer m_cIntraBLPredFlagSCModel;
+#endif
 };
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSlice.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 54)
@@ -100,9 +100,18 @@
 }
 
-Void TDecSlice::init(TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder)
+#if SVC_EXTENSION
+Void TDecSlice::init(TDecTop** ppcDecTop,TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder)
 {
   m_pcEntropyDecoder  = pcEntropyDecoder;
   m_pcCuDecoder       = pcCuDecoder;
-}
+  m_ppcTDecTop        = ppcDecTop;
+}
+#else
+Void TDecSlice::init(TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder)
+{
+  m_pcEntropyDecoder  = pcEntropyDecoder;
+  m_pcCuDecoder       = pcCuDecoder;
+}
+#endif
 
 Void TDecSlice::decompressSlice(TComInputBitstream** ppcSubstreams, TComPic*& rpcPic, TDecSbac* pcSbacDecoder, TDecSbac* pcSbacDecoders)
@@ -184,4 +193,7 @@
   UInt uiTileLCUX;
   Int iNumSubstreamsPerTile = 1; // if independent.
+#if INTRA_BL
+  m_pcCuDecoder->setBaseRecPic( rpcPic->getLayerId() > 0 ? rpcPic->getFullPelBaseRec() : NULL);
+#endif
   Bool depSliceSegmentsEnabled = rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceSegmentsEnabledFlag();
   uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr))->getFirstCUAddr();
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSlice.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSlice.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSlice.h	(revision 54)
@@ -72,4 +72,7 @@
   TDecBinCABAC*   m_pcBufferLowLatBinCABACs;
   std::vector<TDecSbac*> CTXMem;
+#if SVC_EXTENSION
+  TDecTop**       m_ppcTDecTop;
+#endif 
   
 public:
@@ -77,5 +80,9 @@
   virtual ~TDecSlice();
   
+#if SVC_EXTENSION  
+  Void  init              ( TDecTop** ppcDecTop, TDecEntropy* pcEntropyDecoder, TDecCu* pcMbDecoder );
+#else
   Void  init              ( TDecEntropy* pcEntropyDecoder, TDecCu* pcMbDecoder );
+#endif
   Void  create            ();
   Void  destroy           ();
@@ -84,4 +91,7 @@
   Void      initCtxMem(  UInt i );
   Void      setCtxMem( TDecSbac* sb, Int b )   { CTXMem[b] = sb; }
+#if SVC_EXTENSION
+  TDecTop*  getLayerDec   ( UInt LayerId )  { return m_ppcTDecTop[LayerId]; }  
+#endif
 };
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecTop.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecTop.cpp	(revision 54)
@@ -39,4 +39,11 @@
 #include "TDecTop.h"
 
+#if SVC_EXTENSION
+ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder;  // storage for parameter sets 
+UInt  TDecTop::m_prevPOC = MAX_UINT;
+UInt  TDecTop::m_uiPrevLayerId = MAX_UINT;
+Bool  TDecTop::m_bFirstSliceInSequence = true;
+#endif
+
 //! \ingroup TLibDecoder
 //! \{
@@ -54,7 +61,24 @@
   m_prevRAPisBLA = false;
   m_pocRandomAccess = MAX_INT;          
+#if !SVC_EXTENSION
   m_prevPOC                = MAX_INT;
+#endif
   m_bFirstSliceInPicture    = true;
+#if !SVC_EXTENSION
   m_bFirstSliceInSequence   = true;
+#endif
+#if SVC_EXTENSION 
+  m_layerId = 0;
+#if AVC_BASE
+  m_pBLReconFile = NULL;
+#endif
+#endif
+#if REF_IDX_FRAMEWORK
+  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
+#endif
+#if AVC_SYNTAX || SYNTAX_OUTPUT
+  m_pBLSyntaxFile = NULL;
+#endif
+
 }
 
@@ -68,5 +92,9 @@
 Void TDecTop::create()
 {
+#if SVC_EXTENSION
+  m_cGopDecoder.create( m_layerId );
+#else
   m_cGopDecoder.create();
+#endif
   m_apcSlicePilot = new TComSlice;
   m_uiSliceIdx = 0;
@@ -81,14 +109,74 @@
   
   m_cSliceDecoder.destroy();
+#if REF_IDX_FRAMEWORK
+  for(Int i=0; i<MAX_NUM_REF; i++)
+  {
+    if(m_cIlpPic[i])
+    {
+      //m_cIlpPic[i]->setPicYuvRec(NULL);
+      m_cIlpPic[i]->destroy();
+      delete m_cIlpPic[i];
+      m_cIlpPic[i] = NULL;
+    }
+  }    
+#endif
 }
 
 Void TDecTop::init()
 {
+#if !SVC_EXTENSION
   // initialize ROM
   initROM();
+#endif
+#if SVC_EXTENSION
+  m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
+  m_cSliceDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cCuDecoder );
+#else
   m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
   m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
+#endif
   m_cEntropyDecoder.init(&m_cPrediction);
 }
+
+#if REF_IDX_FRAMEWORK
+Void TDecTop::xInitILRP(TComSPS *pcSPS)
+{
+  if(m_layerId>0)
+  {
+    if (m_cIlpPic[0] == NULL)
+    {
+      for (Int j=0; j<1/*MAX_NUM_REF*/; j++)
+      {
+        m_cIlpPic[j] = new  TComPic;
+        //m_cIlpPic[j]->createWithOutYuv(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, &m_cSPS, true);
+#if SVC_UPSAMPLING
+        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, pcSPS, true);
+#else
+        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
+#endif
+#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || REF_IDX_MFM
+        m_cIlpPic[j]->setIsILR(true);
+#endif
+        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
+        {
+          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
+        }
+      }
+    }
+  }
+}
+
+Void TDecTop::setILRPic(TComPic *pcPic)
+{
+  if(m_cIlpPic[0])
+  {
+    //m_cIlpPic[0]->setPicYuvRec(pcPic->getFullPelBaseRec());
+    m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec());
+    m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC());
+    m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false);
+    m_cIlpPic[0]->getPicYuvRec()->extendPicBorder();
+  }
+}
+#endif
 
 Void TDecTop::deletePicBuffer ( )
@@ -100,8 +188,18 @@
   {
     TComPic* pcPic = *(iterPic++);
+#if SVC_EXTENSION
+    if( pcPic )
+    {
+      pcPic->destroy();
+
+      delete pcPic;
+      pcPic = NULL;
+    }
+#else
     pcPic->destroy();
     
     delete pcPic;
     pcPic = NULL;
+#endif
   }
   
@@ -110,6 +208,8 @@
   m_cLoopFilter.        destroy();
   
+#if !SVC_EXTENSION
   // destroy ROM
   destroyROM();
+#endif
 }
 
@@ -129,7 +229,25 @@
   {
     rpcPic = new TComPic();
+
+#if SVC_EXTENSION //Temporal solution, should be modified
+    if(m_layerId > 0)
+    {
+      TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
+      //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin()); 
+      TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
+      if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() )
+      {
+        rpcPic->setSpatialEnhLayerFlag( true );
+      }
+    }
+#endif
     
+#if SVC_UPSAMPLING
+    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+#else
     rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                      conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
     rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
     m_cListPic.pushBack( rpcPic );
@@ -152,5 +270,7 @@
     if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
     {
+#if !SVC_EXTENSION
       rpcPic->setOutputMark(false);
+#endif
       rpcPic->setReconMark( false );
       rpcPic->getPicYuvRec()->setBorderExtension( false );
@@ -168,6 +288,13 @@
   }
   rpcPic->destroy();
+
+#if SVC_UPSAMPLING
+  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+
+#else
   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
   rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
 }
@@ -187,4 +314,7 @@
   m_cGopDecoder.filterPicture(pcPic);
 
+#if SYNTAX_OUTPUT
+  pcPic->wrireBLSyntax( getBLSyntaxFile(), SYNTAX_BYTES );
+#endif
   TComSlice::sortPicList( m_cListPic ); // sorting for application output
   poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
@@ -202,10 +332,18 @@
   cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
   cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
+#if SET_SLICE_LAYER_ID
+  cFillSlice.initSlice( m_parameterSetManagerDecoder.getFirstSPS()->getLayerId() );
+#else
   cFillSlice.initSlice();
+#endif
   TComPic *cFillPic;
   xGetNewPicBuffer(&cFillSlice,cFillPic);
   cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
   cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
+#if SET_SLICE_LAYER_ID
+  cFillPic->getSlice(0)->initSlice( cFillPic->getLayerId() );
+#else
   cFillPic->getSlice(0)->initSlice();
+#endif
   
   TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
@@ -256,5 +394,9 @@
   assert (sps != 0);
 
+#if SVC_EXTENSION
+  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(), m_apcSlicePilot->getIdrPicFlag(), m_apcSlicePilot->getLayerId() ))
+#else
   if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->getIdrPicFlag()))
+#endif
   {
     printf ("Parameter set activation failed!");
@@ -283,8 +425,16 @@
 }
 
+#if SVC_EXTENSION
+Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
+#else
 Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
+#endif
 {
   TComPic*&   pcPic         = m_pcPic;
+#if SET_SLICE_LAYER_ID
+  m_apcSlicePilot->initSlice( nalu.m_layerId );
+#else
   m_apcSlicePilot->initSlice();
+#endif
 
   if (m_bFirstSliceInPicture)
@@ -324,4 +474,14 @@
 
   // exit when a new picture is found
+#if SVC_EXTENSION
+  bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC);
+  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
+  {
+    m_prevPOC = m_apcSlicePilot->getPOC();
+    curLayerId = m_uiPrevLayerId; 
+    m_uiPrevLayerId = m_layerId;
+    return true;
+  }
+#else
   if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence)
   {
@@ -333,4 +493,5 @@
     m_prevPOC = m_apcSlicePilot->getPOC();
   }
+#endif
   // actual decoding starts here
   xActivateParameterSets();
@@ -339,4 +500,8 @@
   {
     m_prevPOC = m_apcSlicePilot->getPOC();
+#if SVC_EXTENSION
+    curLayerId = m_layerId;
+    m_uiPrevLayerId = m_layerId;
+#endif
   }
   m_bFirstSliceInSequence = false;
@@ -349,4 +514,54 @@
   if (m_bFirstSliceInPicture)
   {
+#if AVC_BASE
+  if( m_layerId == 1 )
+  {
+    TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
+    fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
+    UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth() - pBLPic->getPicYuvRec()->getPicCropLeftOffset() - pBLPic->getPicYuvRec()->getPicCropRightOffset();;
+    UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight() - pBLPic->getPicYuvRec()->getPicCropTopOffset() - pBLPic->getPicYuvRec()->getPicCropBottomOffset();
+        
+    if( pFile->good() )
+    {
+      UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
+
+      pFile->seekg((UInt)uiPos, ios::beg );
+
+      Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
+      UInt uiStride = pBLPic->getPicYuvRec()->getStride();
+      for( Int i = 0; i < uiHeight; i++ )
+      {
+        for( Int j = 0; j < uiWidth; j++ )
+        {
+          pPel[j] = pFile->get();
+        }
+        pPel += uiStride;
+      }
+
+      pPel = pBLPic->getPicYuvRec()->getCbAddr();
+      uiStride = pBLPic->getPicYuvRec()->getCStride();
+      for( Int i = 0; i < uiHeight/2; i++ )
+      {
+        for( Int j = 0; j < uiWidth/2; j++ )
+        {
+          pPel[j] = pFile->get();
+        }
+        pPel += uiStride;
+      }
+
+      pPel = pBLPic->getPicYuvRec()->getCrAddr();
+      uiStride = pBLPic->getPicYuvRec()->getCStride();
+      for( Int i = 0; i < uiHeight/2; i++ )
+      {
+        for( Int j = 0; j < uiWidth/2; j++ )
+        {
+          pPel[j] = pFile->get();
+        }
+        pPel += uiStride;
+      }
+    }
+  }
+#endif
+
     // Buffer initialize for prediction.
     m_cPrediction.initTempBuff();
@@ -361,5 +576,9 @@
     // Recursive structure
     m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
+#if SVC_EXTENSION
+    m_cCuDecoder.init   ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId );
+#else
     m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
+#endif
     m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
 
@@ -483,9 +702,72 @@
   pcPic->setTLayer(nalu.m_temporalId);
 
+#if SVC_EXTENSION
+  pcPic->setLayerId(nalu.m_layerId);
+  pcSlice->setLayerId(nalu.m_layerId);
+#endif
+
   if (bNextSlice)
   {
     pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA );
+#if !REF_IDX_FRAMEWORK || AVC_SYNTAX
     // Set reference list
     pcSlice->setRefPicList( m_cListPic );
+#endif
+
+#if SVC_EXTENSION   
+    if(m_layerId > 0)
+    {
+#if AVC_BASE
+      pcSlice->setBaseColPic ( *m_ppcTDecTop[0]->getListPic()->begin() );
+#if AVC_SYNTAX
+      TComPic* pBLPic = pcSlice->getBaseColPic();
+      if( pcSlice->getPOC() == 0 )
+      {
+        // initialize partition order.
+        UInt* piTmp = &g_auiZscanToRaster[0];
+        initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
+        initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
+      }      
+      pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
+      pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
+#endif
+
+#else
+      TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
+      TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
+      pcSlice->setBaseColPic ( *cListPic, m_layerId );
+#endif
+#if SVC_UPSAMPLING
+      if ( pcPic->isSpatialEnhLayer())
+      {    
+        m_cPrediction.upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec() );
+      }
+      else
+      {
+        pcPic->setFullPelBaseRec( pcSlice->getBaseColPic()->getPicYuvRec() );
+      }
+      pcSlice->setFullPelBaseRec ( pcPic->getFullPelBaseRec() );
+#endif
+    }
+#endif 
+
+#if REF_IDX_FRAMEWORK
+#if !AVC_SYNTAX
+    // Set reference list
+    pcSlice->setRefPicList( m_cListPic );
+#endif
+    if(m_layerId > 0)
+    {
+      setILRPic(pcPic);
+#if REF_IDX_MFM
+      pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
+#endif
+
+      pcSlice->addRefPicList ( m_cIlpPic, 
+                               1, 
+                               ((pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) && 
+                                (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)) ? 0: -1);
+    }
+#endif
 
     // For generalized B
@@ -590,6 +872,19 @@
 {
   TComSPS* sps = new TComSPS();
+#if SVC_EXTENSION
+  sps->setLayerId(m_layerId);
+#endif
   m_cEntropyDecoder.decodeSPS( sps );
   m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
+#if REF_IDX_MFM
+  m_pcSPS = sps;
+  setMFMEnabledFlag(sps->getMFMEnabledFlag());
+#endif
+#if REF_IDX_FRAMEWORK
+  if(m_numLayer>0)
+  {
+    xInitILRP(sps);
+  }
+#endif
 }
 
@@ -637,5 +932,9 @@
 }
 
+#if SVC_EXTENSION
+Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
+#else
 Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
+#endif
 {
   // Initialize entropy decoder
@@ -651,4 +950,22 @@
     case NAL_UNIT_SPS:
       xDecodeSPS();
+#if AVC_BASE
+      {
+        TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
+        if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
+        {
+#if SVC_UPSAMPLING
+#if AVC_SYNTAX
+          TComSPS* sps = new TComSPS();
+          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, sps, true);
+#else
+          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL, true);
+#endif
+#else
+          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
+#endif
+        }
+      }
+#endif
       return false;
 
@@ -678,5 +995,9 @@
     case NAL_UNIT_CODED_SLICE_RASL_N:
     case NAL_UNIT_CODED_SLICE_TFD:
+#if SVC_EXTENSION
+      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
+#else
       return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
+#endif
       break;
     default:
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecTop.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecTop.h	(revision 54)
@@ -72,5 +72,15 @@
 
   TComList<TComPic*>      m_cListPic;         //  Dynamic buffer
+#if SVC_EXTENSION
+  static ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets 
+#else
   ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets 
+#endif
+
+#if REF_IDX_MFM
+  TComSPS*               m_pcSPS;
+  Bool                   m_bMFMEnabledFlag;
+#endif
+
   TComSlice*              m_apcSlicePilot;
   
@@ -95,7 +105,31 @@
   TComPic*                m_pcPic;
   UInt                    m_uiSliceIdx;
+#if !SVC_EXTENSION
   Int                     m_prevPOC;
+#endif
   Bool                    m_bFirstSliceInPicture;
+#if !SVC_EXTENSION
   Bool                    m_bFirstSliceInSequence;
+#endif
+
+#if SVC_EXTENSION
+  static UInt             m_prevPOC;        // POC of the previous slice
+  static UInt             m_uiPrevLayerId;  // LayerId of the previous slice
+  static Bool             m_bFirstSliceInSequence;
+  UInt                    m_layerId;      
+  UInt                    m_numLayer;
+  TDecTop**               m_ppcTDecTop;
+#if AVC_BASE
+  fstream*                m_pBLReconFile;
+  Int                     m_iBLSourceWidth;
+  Int                     m_iBLSourceHeight;
+#endif
+#endif 
+#if AVC_SYNTAX || SYNTAX_OUTPUT
+  fstream*               m_pBLSyntaxFile;
+#endif
+#if REF_IDX_FRAMEWORK
+  TComPic*                m_cIlpPic[MAX_NUM_REF];                    ///<  Inter layer Prediction picture =  upsampled picture 
+#endif
 
 public:
@@ -109,9 +143,43 @@
 
   Void  init();
+#if SVC_EXTENSION
+  Bool  decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC);
+#else
   Bool  decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay);
+#endif
   
   Void  deletePicBuffer();
 
   Void executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic);
+
+#if SVC_EXTENSION
+  UInt      getLayerId            () { return m_layerId;              }
+  Void      setLayerId            (UInt layer) { m_layerId = layer; }
+  UInt      getNumLayer           () { return m_numLayer;             }
+  Void      setNumLayer           (UInt uiNum)   { m_numLayer = uiNum;  }
+  TComList<TComPic*>*      getListPic() { return &m_cListPic; }
+  Void                setLayerDec(TDecTop **p)    { m_ppcTDecTop = p; }
+  TDecTop*            getLayerDec(UInt layer)   { return m_ppcTDecTop[layer]; }
+#if AVC_BASE
+  Void      setBLReconFile( fstream* pFile ) { m_pBLReconFile = pFile; }
+  fstream*  getBLReconFile() { return m_pBLReconFile; }
+  Void      setBLsize( Int iWidth, Int iHeight ) { m_iBLSourceWidth = iWidth; m_iBLSourceHeight = iHeight; }
+  Int       getBLWidth() { return  m_iBLSourceWidth; }
+  Int       getBLHeight() { return  m_iBLSourceHeight; }
+#endif
+#endif
+#if AVC_SYNTAX || SYNTAX_OUTPUT
+  Void      setBLSyntaxFile( fstream* pFile ) { m_pBLSyntaxFile = pFile; }
+  fstream* getBLSyntaxFile() { return m_pBLSyntaxFile; }
+#endif
+#if REF_IDX_FRAMEWORK
+  Void      xInitILRP(TComSPS *pcSPS);
+  Void      setILRPic(TComPic *pcPic);
+#endif
+#if REF_IDX_MFM
+  TComSPS*  getSPS()                       {return m_pcSPS;}
+  Void      setMFMEnabledFlag(Bool flag)   {m_bMFMEnabledFlag = flag;}
+  Bool      getMFMEnabledFlag()            {return m_bMFMEnabledFlag;}
+#endif
 
 protected:
@@ -120,5 +188,9 @@
 
   Void      xActivateParameterSets();
+#if SVC_EXTENSION
+  Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC);
+#else
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay);
+#endif
   Void      xDecodeVPS();
   Void      xDecodeSPS();
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/NALwrite.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/NALwrite.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/NALwrite.cpp	(revision 54)
@@ -53,5 +53,9 @@
   bsNALUHeader.write(0,1);                    // forbidden_zero_bit
   bsNALUHeader.write(nalu.m_nalUnitType, 6);  // nal_unit_type
+#if SVC_EXTENSION
+  bsNALUHeader.write(nalu.m_layerId, 6); // reserved_one_5bits
+#else
   bsNALUHeader.write(nalu.m_reservedZero6Bits, 6);                   // nuh_reserved_zero_6bits
+#endif
   bsNALUHeader.write(nalu.m_temporalId+1, 3); // nuh_temporal_id_plus1
 
@@ -145,4 +149,7 @@
   naluDest.m_temporalId  = naluSrc.m_temporalId;
   naluDest.m_Bitstream   = naluSrc.m_Bitstream;
+#if SVC_EXTENSION
+  naluDest.m_layerId   = naluSrc.m_layerId;
+#endif
 }
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/NALwrite.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/NALwrite.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/NALwrite.h	(revision 54)
@@ -57,6 +57,13 @@
     NalUnitType nalUnitType,
     UInt temporalID = 0,
+#if SVC_EXTENSION
+    UInt     layerId = 0,
+#endif
     UInt reserved_zero_6bits = 0)
+#if SVC_EXTENSION
+  : NALUnit(nalUnitType, temporalID, layerId, reserved_zero_6bits)
+#else
   : NALUnit(nalUnitType, temporalID, reserved_zero_6bits)
+#endif
   , m_Bitstream()
   {}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncAnalyze.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncAnalyze.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncAnalyze.cpp	(revision 54)
@@ -45,8 +45,15 @@
 //////////////////////////////////////////////////////////////////////
 
+#if SVC_EXTENSION
+TEncAnalyze             m_gcAnalyzeAll [MAX_LAYERS];
+TEncAnalyze             m_gcAnalyzeI [MAX_LAYERS];
+TEncAnalyze             m_gcAnalyzeP [MAX_LAYERS];
+TEncAnalyze             m_gcAnalyzeB [MAX_LAYERS];
+#else
 TEncAnalyze             m_gcAnalyzeAll;
 TEncAnalyze             m_gcAnalyzeI;
 TEncAnalyze             m_gcAnalyzeP;
 TEncAnalyze             m_gcAnalyzeB;
+#endif
 
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncAnalyze.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncAnalyze.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncAnalyze.h	(revision 54)
@@ -88,4 +88,19 @@
   Void    setFrmRate  (Double dFrameRate) { m_dFrmRate = dFrameRate; } //--CFG_KDY
   Void    clear() { m_dPSNRSumY = m_dPSNRSumU = m_dPSNRSumV = m_dAddBits = m_uiNumPic = 0;  }
+#if SVC_EXTENSION
+  Void    printOut ( Char cDelim, UInt layer )
+  {
+    Double dFps     =   m_dFrmRate; //--CFG_KDY
+    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
+    
+    printf( "    L%d\t %8d    %c"          "%12.4lf  "    "%8.4lf  "   "%8.4lf  "    "%8.4lf\n",
+           layer,
+           getNumPic(), cDelim,
+           getBits() * dScale,
+           getPsnrY() / (Double)getNumPic(),
+           getPsnrU() / (Double)getNumPic(),
+           getPsnrV() / (Double)getNumPic() );
+  }
+#else
   Void    printOut ( Char cDelim )
   {
@@ -102,4 +117,5 @@
            getPsnrV() / (Double)getNumPic() );
   }
+#endif
   
   Void    printSummaryOut ()
@@ -150,8 +166,15 @@
 };
 
+#if SVC_EXTENSION
+extern TEncAnalyze             m_gcAnalyzeAll [MAX_LAYERS];
+extern TEncAnalyze             m_gcAnalyzeI [MAX_LAYERS];
+extern TEncAnalyze             m_gcAnalyzeP [MAX_LAYERS];
+extern TEncAnalyze             m_gcAnalyzeB [MAX_LAYERS];
+#else
 extern TEncAnalyze             m_gcAnalyzeAll;
 extern TEncAnalyze             m_gcAnalyzeI;
 extern TEncAnalyze             m_gcAnalyzeP;
 extern TEncAnalyze             m_gcAnalyzeB;
+#endif
 
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 54)
@@ -545,5 +545,11 @@
   }
   WRITE_FLAG( pcSPS->getTMVPFlagsPresent()  ? 1 : 0,           "sps_temporal_mvp_enable_flag" );
-
+#if REF_IDX_MFM
+  if( pcSPS->getLayerId() > 0 )
+  {
+    assert(pcSPS->getMFMEnabledFlag());
+    WRITE_FLAG( pcSPS->getMFMEnabledFlag() ? 1 : 0,          "sps_enh_mfm_enable_flag" );
+  }
+#endif
   WRITE_FLAG( pcSPS->getUseStrongIntraSmoothing(),             "sps_strong_intra_smoothing_enable_flag" );
 
@@ -1549,3 +1555,11 @@
   return true;
 }
+
+#if INTRA_BL
+Void TEncCavlc::codeIntraBLFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
+{
+  assert(0);
+}
+
+#endif
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCavlc.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCavlc.h	(revision 54)
@@ -114,4 +114,7 @@
   Void codeMergeFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx );
   Void codeMergeIndex    ( TComDataCU* pcCU, UInt uiAbsPartIdx );
+#if INTRA_BL
+  Void codeIntraBLFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx );
+#endif
  
   Void codeInterModeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiEncMode );
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCfg.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCfg.h	(revision 54)
@@ -298,4 +298,11 @@
 
   Bool      m_useStrongIntraSmoothing;                        ///< enable the use of strong intra smoothing (bi_linear interpolation) for 32x32 blocks when reference samples are flat.
+#if SVC_EXTENSION
+  UInt      m_layerId;   
+  UInt      m_numLayer;
+#endif 
+#if REF_IDX_FRAMEWORK
+  Int      m_elRapSliceBEnabled;
+#endif
 
 public:
@@ -692,4 +699,17 @@
   Void setFrameOnlyConstraintFlag(Bool b) { m_frameOnlyConstraintFlag = b; }
 #endif
+
+#if SVC_EXTENSION
+  UInt      getLayerId            () { return m_layerId;              }
+  Void      setLayerId            (UInt layer) { m_layerId = layer; }
+  UInt      getNumLayer           () { return m_numLayer;             }  
+  Void      setNumLayer           (UInt uiNum)   { m_numLayer = uiNum;  }
+  Void      setConformanceMode    (Int mode)     { m_conformanceMode = mode; }
+  Void      setConformanceWindow(Window& conformanceWindow ) { m_conformanceWindow = conformanceWindow; }
+#endif
+#if REF_IDX_FRAMEWORK
+  Void      setElRapSliceTypeB(Int bEnabled) {m_elRapSliceBEnabled = bEnabled;}
+  Int       getElRapSliceTypeB()              {return m_elRapSliceBEnabled;}
+#endif
 };
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCu.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCu.cpp	(revision 54)
@@ -211,4 +211,13 @@
   m_pcRdCost           = pcEncTop->getRdCost();
   
+#if SVC_EXTENSION
+  m_ppcTEncTop         = pcEncTop->getLayerEnc();
+  for(UInt i=0 ; i< m_uhTotalDepth-1 ; i++)
+  {    
+    m_ppcBestCU[i]->setLayerId(pcEncTop->getLayerId());
+    m_ppcTempCU[i]->setLayerId(pcEncTop->getLayerId());
+  }
+#endif
+  
   m_pcEntropyCoder     = pcEncTop->getEntropyCoder();
   m_pcCavlcCoder       = pcEncTop->getCavlcCoder();
@@ -445,4 +454,15 @@
   if(!bSliceEnd && !bSliceStart && bInsidePicture )
   {
+#if (ENCODER_FAST_MODE)
+    bool testInter = true;
+    if (rpcBestCU->getLayerId() > 0)
+    {
+      if (rpcBestCU->getSlice()->getBaseColPic()->getSlice(0)->getSliceType() == I_SLICE)
+      {
+        testInter = false;
+      }
+
+    }
+#endif
     for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
     {
@@ -459,5 +479,9 @@
 
       // do inter modes, SKIP and 2Nx2N
+#if (ENCODER_FAST_MODE == 1)
+      if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter )
+#else
       if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
+#endif
       {
         // 2Nx2N
@@ -480,4 +504,8 @@
           }
         }
+#if (ENCODER_FAST_MODE == 2)
+        if (testInter)
+        {
+#endif
 
         if(!m_pcEncCfg->getUseEarlySkipDetection())
@@ -493,4 +521,8 @@
           }
         }
+#if (ENCODER_FAST_MODE == 2)
+    }
+#endif
+
       }
 
@@ -531,5 +563,9 @@
 
         // do inter modes, NxN, 2NxN, and Nx2N
+#if (ENCODER_FAST_MODE)
+      if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter )
+#else
         if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
+#endif
         {
           // 2Nx2N, NxN
@@ -685,8 +721,16 @@
         {
           // speedup for inter frames
+#if (ENCODER_FAST_MODE)
+        if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || 
+          !testInter ||
+          rpcBestCU->getCbf( 0, TEXT_LUMA     ) != 0   ||
+          rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0   ||
+          rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0     ) // avoid very complex intra if it is unlikely
+#else
           if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || 
             rpcBestCU->getCbf( 0, TEXT_LUMA     ) != 0   ||
             rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0   ||
             rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0     ) // avoid very complex intra if it is unlikely
+#endif
           {
             xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
@@ -716,4 +760,20 @@
           }
         }
+#if INTRA_BL
+      if(m_pcPicYuvRecBase)
+      {
+        xCheckRDCostIntraBL( rpcBestCU, rpcTempCU );
+        rpcTempCU->initEstData( uiDepth, iQP );
+      }
+#endif
+
+#if (ENCODER_FAST_MODE)
+        if(pcPic->getLayerId() > 0)
+        { 
+          xCheckRDCostILRUni( rpcBestCU, rpcTempCU); 
+          rpcTempCU->initEstData( uiDepth, iQP );
+       }
+#endif
+
         if (isAddLowestQP && (iQP == lowestQP))
         {
@@ -1150,4 +1210,9 @@
     return;
   }
+#if INTRA_BL
+  m_pcEntropyCoder->encodeIntraBLFlag( pcCU, uiAbsPartIdx );
+  if ( !pcCU->isIntraBL( uiAbsPartIdx ) )
+  {
+#endif
   m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx );
   
@@ -1168,4 +1233,7 @@
   // prediction Info ( Intra : direction mode, Inter : Mv, reference idx )
   m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx );
+#if INTRA_BL
+  }
+#endif
   
   // Encode Coefficients
@@ -1221,5 +1289,9 @@
     for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
     {
-      {
+#if REF_IDX_ME_ZEROMV
+      Bool bZeroMVILR = rpcTempCU->xCheckZeroMVILRMerge(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]);
+      if(bZeroMVILR)
+      {
+#endif
         if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1))
         {
@@ -1271,5 +1343,7 @@
     }
     }
+#if REF_IDX_ME_ZEROMV 
    }
+#endif
   }
 
@@ -1377,4 +1451,7 @@
   
   m_pcEntropyCoder->resetBits();
+#if INTRA_BL
+  m_pcEntropyCoder->encodeIntraBLFlag ( rpcTempCU, 0,       true );
+#endif
   if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
   {
@@ -1430,4 +1507,7 @@
 
   m_pcEntropyCoder->resetBits();
+#if INTRA_BL
+  m_pcEntropyCoder->encodeIntraBLFlag ( rpcTempCU, 0,       true );
+#endif
   if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
   {
@@ -1681,3 +1761,58 @@
 }
 #endif
+
+#if INTRA_BL
+Void TEncCu::xCheckRDCostIntraBL( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU )
+{
+  UInt uiDepth = rpcTempCU->getDepth( 0 );
+  rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); 
+  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
+  rpcTempCU->setPredModeSubParts( MODE_INTRA_BL, 0, uiDepth );  
+  rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth );
+
+  m_pcPredSearch->setBaseRecPic( m_pcPicYuvRecBase ); 
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+  rpcTempCU->setDepthSubParts( uiDepth, 0 );
+  //   rpcTempCU->setLumaIntraDirSubParts( DC_IDX, 0, uiDepth );
+  //   rpcTempCU->setChromIntraDirSubParts( DC_IDX, 0, uiDepth );
+  m_ppcPredYuvTemp[uiDepth]->copyFromPicLuma  ( rpcTempCU->getSlice()->getFullPelBaseRec(),  rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU(), 0, rpcTempCU->getWidth(0), rpcTempCU->getHeight(0));
+  m_ppcPredYuvTemp[uiDepth]->copyFromPicChroma( rpcTempCU->getSlice()->getFullPelBaseRec(),  rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU(), 0, (rpcTempCU->getWidth(0)>>1), (rpcTempCU->getHeight(0)>>1), 0);
+  m_ppcPredYuvTemp[uiDepth]->copyFromPicChroma( rpcTempCU->getSlice()->getFullPelBaseRec(),  rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU(), 0, (rpcTempCU->getWidth(0)>>1), (rpcTempCU->getHeight(0)>>1), 1);
+  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcResiYuvBest[uiDepth], m_ppcRecoYuvTemp[uiDepth], false );
+  rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
+#else
+
+  m_pcPredSearch->estIntraBLPredQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth] );
+
+  m_pcEntropyCoder->resetBits();
+  m_pcEntropyCoder->encodeIntraBLFlag ( rpcTempCU, 0,       true );
+  m_pcEntropyCoder->encodeSkipFlag( rpcTempCU, 0,       true );
+  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
+  {
+    m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0,          true );
+  }
+
+  // Encode Coefficients
+  Bool bCodeDQP = getdQPFlag();
+  m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0), bCodeDQP );
+  setdQPFlag( bCodeDQP );
+  
+  if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
+  
+  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
+  if(m_pcEncCfg->getUseSBACRD())
+  {
+    rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
+  }
+  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
+#endif
+  
+  xCheckDQP( rpcTempCU );
+  xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth);
+}
+#endif
+
+
+
+
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCu.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCu.h	(revision 54)
@@ -84,8 +84,15 @@
   //  Access channel
   TEncCfg*                m_pcEncCfg;
+#if INTRA_BL
+  TComPicYuv*             m_pcPicYuvRecBase;       ///< reconstructed base layer
+#endif 
   TEncSearch*             m_pcPredSearch;
   TComTrQuant*            m_pcTrQuant;
   TComBitCounter*         m_pcBitCounter;
   TComRdCost*             m_pcRdCost;
+  
+#if SVC_EXTENSION
+  TEncTop**               m_ppcTEncTop;
+#endif
   
   TEncEntropy*            m_pcEntropyCoder;
@@ -124,4 +131,7 @@
   UInt getLCUPredictionSAD() { return m_LCUPredictionSAD; }
 #endif
+#if INTRA_BL 
+  Void  setBaseRecPic       ( TComPicYuv* p ) { m_pcPicYuvRecBase = p; }   
+#endif
 protected:
   Void  finishCU            ( TComDataCU*  pcCU, UInt uiAbsPartIdx,           UInt uiDepth        );
@@ -144,4 +154,10 @@
 #endif
   Void  xCheckRDCostIntra   ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize  );
+#if INTRA_BL
+  Void  xCheckRDCostIntraBL ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU  );
+#endif
+#if ENCODER_FAST_MODE
+  Void  xCheckRDCostILRUni  ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU );
+#endif
   Void  xCheckDQP           ( TComDataCU*  pcCU );
   
@@ -168,4 +184,8 @@
 #endif
 
+#if SVC_EXTENSION
+  TEncTop*   getLayerEnc(UInt LayerId)  {return m_ppcTEncTop[LayerId]; }
+#endif 
+
   Void  xFillPCMBuffer     ( TComDataCU*& pCU, TComYuv* pOrgYuv ); 
 };
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 54)
@@ -166,4 +166,11 @@
   }
 
+#if INTRA_BL
+  if( pcCU->isIntraBL( uiAbsPartIdx ) )
+  {
+    return;
+  }
+#endif
+
   m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx );
 }
@@ -244,6 +251,10 @@
     }
   }
+#if INTRA_BL
+    if( pcCU->isIntra(uiAbsPartIdx) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
+#else
   
   if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
+#endif
   {
     assert( uiSubdiv );
@@ -331,5 +342,13 @@
     }
     
+#if INTRA_BL
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+    if( ( !pcCU->isIntra( uiAbsPartIdx ) || pcCU->isIntraBL(uiAbsPartIdx)) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
+#else
+    if( ( !pcCU->isIntra( uiAbsPartIdx ) ) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
+#endif
+#else
     if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
+#endif
     {
       assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) );
@@ -412,4 +431,7 @@
 Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
 {
+#if INTRA_BL
+  assert ( !pcCU->isIntraBL( uiAbsPartIdx ) );
+#endif
   if( bRD )
   {
@@ -585,5 +607,9 @@
   UInt uiChromaOffset = uiLumaOffset>>2;
     
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+  if( pcCU->isIntra(uiAbsPartIdx) && !pcCU->isIntraBL(uiAbsPartIdx) )
+#else
   if( pcCU->isIntra(uiAbsPartIdx) )
+#endif
   {
     DTRACE_CABAC_VL( g_nSymbolCounter++ )
@@ -733,3 +759,18 @@
 }
 
+#if INTRA_BL
+Void TEncEntropy::encodeIntraBLFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
+{
+  if( pcCU->getLayerId() == 0 )
+  {
+    return;
+  }
+
+  if( bRD )
+  {
+    uiAbsPartIdx = 0;
+  }
+  m_pcEntropyCoderIf->codeIntraBLFlag( pcCU, uiAbsPartIdx );
+}
+#endif
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncEntropy.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncEntropy.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncEntropy.h	(revision 54)
@@ -86,4 +86,7 @@
   virtual Void codeSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
   
+#if INTRA_BL
+  virtual Void codeIntraBLFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
+#endif
   virtual Void codePartSize      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
   virtual Void codePredMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
@@ -161,4 +164,7 @@
   Void encodeMergeFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx );
   Void encodeMergeIndex   ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
+#if INTRA_BL
+  Void encodeIntraBLFlag  ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
+#endif
   Void encodePredMode          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
   Void encodePartSize          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD = false );
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 54)
@@ -97,4 +97,7 @@
   xResetNonNestedSEIPresentFlags();
 #endif
+#if SVC_UPSAMPLING
+  m_pcPredSearch        = NULL;
+#endif
   return;
 }
@@ -106,4 +109,12 @@
 /** Create list to contain pointers to LCU start addresses of slice.
  */
+#if SVC_EXTENSION
+Void  TEncGOP::create( UInt layerId )
+{
+  m_bLongtermTestPictureHasBeenCoded = 0;
+  m_bLongtermTestPictureHasBeenCoded2 = 0;
+  m_layerId = layerId;
+}
+#else
 Void  TEncGOP::create()
 {
@@ -111,4 +122,5 @@
   m_bLongtermTestPictureHasBeenCoded2 = 0;
 }
+#endif
 
 Void  TEncGOP::destroy()
@@ -121,6 +133,5 @@
   m_pcCfg                = pcTEncTop;
   m_pcSliceEncoder       = pcTEncTop->getSliceEncoder();
-  m_pcListPic            = pcTEncTop->getListPic();
-  
+  m_pcListPic            = pcTEncTop->getListPic();  
   m_pcEntropyCoder       = pcTEncTop->getEntropyCoder();
   m_pcCavlcCoder         = pcTEncTop->getCavlcCoder();
@@ -136,4 +147,10 @@
   m_totalCoded         = 0;
 
+#if SVC_EXTENSION
+  m_ppcTEncTop           = pcTEncTop->getLayerEnc();
+#endif
+#if SVC_UPSAMPLING
+  m_pcPredSearch         = pcTEncTop->getPredSearch();                       ///< encoder search class
+#endif
 }
 
@@ -239,5 +256,9 @@
 // Public member functions
 // ====================================================================================================================
+#if SVC_EXTENSION
+Void TEncGOP::compressGOP( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
+#else
 Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
+#endif
 {
   TComPic*        pcPic;
@@ -261,5 +282,9 @@
   UInt *accumNalsDU = NULL;
   SEIDecodingUnitInfo decodingUnitInfoSEI;
+#if SVC_EXTENSION
+  for ( Int iGOPid=iPicIdInGOP; iGOPid < iPicIdInGOP+1; iGOPid++ )
+#else
   for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ )
+#endif
   {
     UInt uiColDir = 1;
@@ -337,4 +362,7 @@
     m_pcSliceEncoder->setSliceIdx(0);
     pcPic->setCurrSliceIdx(0);
+#if SVC_EXTENSION
+    pcPic->setLayerId( m_layerId );
+#endif
 
     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
@@ -384,4 +412,19 @@
     // Set the nal unit type
     pcSlice->setNalUnitType(getNalUnitType(pocCurr));
+#if REF_IDX_FRAMEWORK
+    if( m_layerId > 0 && (uiPOCCurr % m_pcCfg->getIntraPeriod() == 0) )
+    {
+      pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
+    }
+    if( m_layerId > 0 && !m_pcEncTop->getElRapSliceTypeB() )
+    {
+      if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) &&
+          (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) &&
+           pcSlice->getSliceType() == B_SLICE )
+      {
+        pcSlice->setSliceType(P_SLICE);
+      }
+    }
+#endif
     if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
     {
@@ -470,6 +513,78 @@
 #endif      
 
+#if SVC_EXTENSION      
+      if(m_layerId > 0)
+      {
+        TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId-1]->getListPic();
+        pcSlice->setBaseColPic (*cListPic, m_layerId );
+#if SVC_UPSAMPLING
+        if ( pcPic->isSpatialEnhLayer())
+        {    
+          m_pcPredSearch->upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec() );
+        }
+        else
+        {
+          pcPic->setFullPelBaseRec( pcSlice->getBaseColPic()->getPicYuvRec() );
+        }
+        pcSlice->setFullPelBaseRec ( pcPic->getFullPelBaseRec() );
+#endif
+      }
+#endif 
+
+#if REF_IDX_FRAMEWORK
+    if( pcSlice->getSliceType() == B_SLICE )
+    {
+      pcSlice->setColFromL0Flag(1-uiColDir);
+    }
+#endif
+
     //  Set reference list
     pcSlice->setRefPicList ( rcListPic );
+#if REF_IDX_FRAMEWORK
+    if(m_layerId > 0)
+    {
+      m_pcEncTop->setILRPic(pcPic);
+
+#if REF_IDX_MFM
+      pcSlice->setRefPOCListILP(m_pcEncTop->getIlpList(), pcSlice->getBaseColPic());
+#endif
+      pcSlice->addRefPicList ( m_pcEncTop->getIlpList(), 1);
+
+#if REF_IDX_MFM
+      Bool found         = false;
+      UInt ColFromL0Flag = pcSlice->getColFromL0Flag();
+      UInt ColRefIdx     = pcSlice->getColRefIdx();
+      for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) 
+      { 
+        if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->getIsILR() ) 
+        { 
+          ColRefIdx = colIdx; 
+          found = true;
+          break; 
+        }
+      }
+
+      if( found == false )
+      {
+        ColFromL0Flag = 1 - ColFromL0Flag;
+        for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) 
+        { 
+          if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->getIsILR() ) 
+          { 
+            ColRefIdx = colIdx; 
+            found = true; 
+            break; 
+          } 
+        }
+      }
+
+      if(found == true)
+      {
+        pcSlice->setColFromL0Flag(ColFromL0Flag);
+        pcSlice->setColRefIdx(ColRefIdx);
+      }
+#endif
+    }
+#endif
 
     //  Slice info. refinement
@@ -493,5 +608,7 @@
     if (pcSlice->getSliceType() == B_SLICE)
     {
+#if !REF_IDX_FRAMEWORK
       pcSlice->setColFromL0Flag(1-uiColDir);
+#endif
       Bool bLowDelay = true;
       Int  iCurrPOC  = pcSlice->getPOC();
@@ -780,4 +897,14 @@
     m_storedStartCUAddrForEncodingSliceSegment.push_back(nextCUAddr);
     startCUAddrSliceSegmentIdx++;
+#if AVC_BASE
+    if( m_layerId == 0 )
+    {
+      pcPic->getPicYuvOrg()->copyToPic( pcPic->getPicYuvRec() );
+#if AVC_SYNTAX
+      pcPic->readBLSyntax( m_ppcTEncTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
+#endif
+      return;
+    }
+#endif
 
     while(nextCUAddr<uiRealEndAddress) // determine slice boundaries
@@ -878,5 +1005,9 @@
     if ( m_bSeqFirst )
     {
+#if SVC_EXTENSION
+      OutputNALUnit nalu(NAL_UNIT_VPS, 0, m_layerId);
+#else
       OutputNALUnit nalu(NAL_UNIT_VPS);
+#endif
       m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
       m_pcEntropyCoder->encodeVPS(m_pcEncTop->getVPS());
@@ -887,5 +1018,9 @@
 #endif
 
+#if SVC_EXTENSION
+      nalu = NALUnit(NAL_UNIT_SPS, 0, m_layerId);
+#else
       nalu = NALUnit(NAL_UNIT_SPS);
+#endif
       m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
       if (m_bSeqFirst)
@@ -920,5 +1055,9 @@
 #endif
 
+#if SVC_EXTENSION
+      nalu = NALUnit(NAL_UNIT_PPS, 0, m_layerId);
+#else
       nalu = NALUnit(NAL_UNIT_PPS);
+#endif
       m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
       m_pcEntropyCoder->encodePPS(pcSlice->getPPS());
@@ -1174,5 +1313,9 @@
           m_pcEntropyCoder->resetEntropy      ();
           /* start slice NALunit */
+#if SVC_EXTENSION
+          OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer(), m_layerId );
+#else
           OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer() );
+#endif
           Bool sliceSegment = (!pcSlice->isNextSlice());
           if (!sliceSegment)
@@ -1436,5 +1579,9 @@
           digestStr = digestToString(sei_recon_picture_digest.digest, 4);
         }
+#if SVC_EXTENSION
+        OutputNALUnit nalu(NAL_UNIT_SEI_SUFFIX, pcSlice->getTLayer(), m_layerId);
+#else
         OutputNALUnit nalu(NAL_UNIT_SEI_SUFFIX, pcSlice->getTLayer());
+#endif
 
         /* write the SEI messages */
@@ -1708,7 +1855,12 @@
   if( accumNalsDU != NULL) delete accumNalsDU;
 
+#if SVC_EXTENSION
+  assert ( m_iNumPicCoded <= 1 );
+#else
   assert ( m_iNumPicCoded == iNumPicRcvd );
+#endif
 }
 
+#if !SVC_EXTENSION
 Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded)
 {
@@ -1746,4 +1898,5 @@
   printf("\nRVM: %.3lf\n" , xCalculateRVM());
 }
+#endif
 
 Void TEncGOP::preLoopFilterPicAll( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits )
@@ -2020,4 +2173,20 @@
 
   //===== add PSNR =====
+#if SVC_EXTENSION
+  m_gcAnalyzeAll[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
+  TComSlice*  pcSlice = pcPic->getSlice(0);
+  if (pcSlice->isIntra())
+  {
+    m_gcAnalyzeI[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
+  }
+  if (pcSlice->isInterP())
+  {
+    m_gcAnalyzeP[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
+  }
+  if (pcSlice->isInterB())
+  {
+    m_gcAnalyzeB[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
+  }
+#else
   m_gcAnalyzeAll.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
   TComSlice*  pcSlice = pcPic->getSlice(0);
@@ -2034,8 +2203,29 @@
     m_gcAnalyzeB.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
   }
+#endif
 
   Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B');
   if (!pcSlice->isReferenced()) c += 32;
 
+#if SVC_EXTENSION
+#if ADAPTIVE_QP_SELECTION
+  printf("POC %4d LId: %1d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits",
+         pcSlice->getPOC(),
+         pcSlice->getLayerId(),
+         pcSlice->getTLayer(),
+         c,
+         pcSlice->getSliceQpBase(),
+         pcSlice->getSliceQp(),
+         uibits );
+#else
+  printf("POC %4d LId: %1d TId: %1d ( %c-SLICE, QP %d ) %10d bits",
+         pcSlice->getPOC()-pcSlice->getLastIDR(),
+         pcSlice->getLayerId(),
+         pcSlice->getTLayer(),
+         c,
+         pcSlice->getSliceQp(),
+         uibits );
+#endif
+#else
 #if ADAPTIVE_QP_SELECTION
   printf("POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits",
@@ -2054,4 +2244,5 @@
          uibits );
 #endif
+#endif
 
   printf(" [Y %6.4lf dB    U %6.4lf dB    V %6.4lf dB]", dYPSNR, dUPSNR, dVPSNR );
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncGOP.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncGOP.h	(revision 54)
@@ -83,4 +83,8 @@
   Bool                    m_bFirst;
   
+#if SVC_EXTENSION
+  UInt                    m_layerId;      
+#endif
+
   //  Access channel
   TEncTop*                m_pcEncTop;
@@ -88,4 +92,11 @@
   TEncSlice*              m_pcSliceEncoder;
   TComList<TComPic*>*     m_pcListPic;
+  
+#if SVC_EXTENSION
+  TEncTop**               m_ppcTEncTop;
+#if SVC_UPSAMPLING
+  TEncSearch*             m_pcPredSearch;                       ///< encoder search class
+#endif  
+#endif
   
   TEncEntropy*            m_pcEntropyCoder;
@@ -125,9 +136,17 @@
   virtual ~TEncGOP();
   
+#if SVC_EXTENSION
+  Void  create      ( UInt layerId );
+#else
   Void  create      ();
+#endif
   Void  destroy     ();
   
   Void  init        ( TEncTop* pcTEncTop );
+#if SVC_EXTENSION
+  Void  compressGOP ( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP );
+#else
   Void  compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP );
+#endif
   Void xWriteTileLocationToSliceHeader (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect, TComSlice*& rpcSlice);
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncPic.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncPic.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncPic.cpp	(revision 54)
@@ -126,9 +126,20 @@
  * \return Void
  */
+#if SVC_UPSAMPLING
+Void TEncPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,  
+                      Window &conformanceWindow, Window &defaultDisplayWindow, Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual )
+
+#else
 Void TEncPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,  
                       Window &conformanceWindow, Window &defaultDisplayWindow, Int *numReorderPics, Bool bIsVirtual )
+#endif
 {
+#if SVC_UPSAMPLING
+  TComPic::create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth,  
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSps, bIsVirtual );
+#else
   TComPic::create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth,  
                    conformanceWindow, defaultDisplayWindow, numReorderPics, bIsVirtual );
+#endif
   m_uiMaxAQDepth = uiMaxAQDepth;
   if ( uiMaxAQDepth > 0 )
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncPic.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncPic.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncPic.h	(revision 54)
@@ -41,5 +41,7 @@
 #include "TLibCommon/CommonDef.h"
 #include "TLibCommon/TComPic.h"
-
+#if SVC_UPSAMPLING
+#include "TLibCommon/TComSlice.h"
+#endif
 //! \ingroup TLibEncoder
 //! \{
@@ -103,6 +105,11 @@
   virtual ~TEncPic();
 
+#if SVC_UPSAMPLING
+  Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,   
+                        Window &conformanceWindow, Window &defaultDisplayWindow, Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual = false );
+#else
   Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,   
                         Window &conformanceWindow, Window &defaultDisplayWindow, Int *numReorderPics, Bool bIsVirtual = false );
+#endif
   virtual Void  destroy();
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 54)
@@ -83,4 +83,7 @@
 , m_cTransformSkipSCModel     ( 1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
 , m_CUTransquantBypassFlagSCModel( 1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+#if INTRA_BL
+, m_cIntraBLPredFlagSCModel   (1,              1,               NUM_INTRA_BL_PRED_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
+#endif
 {
   assert( m_numContextModels <= MAX_NUM_CTX_MOD );
@@ -131,4 +134,7 @@
   m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
   m_cSaoMergeSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
+#if INTRA_BL
+  m_cIntraBLPredFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_BL_PRED_FLAG );
+#endif
   m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
   m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
@@ -163,4 +169,7 @@
       curCost  = m_cCUSplitFlagSCModel.calcCost       ( curSliceType, qp, (UChar*)INIT_SPLIT_FLAG );
       curCost += m_cCUSkipFlagSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_SKIP_FLAG );
+#if INTRA_BL
+      curCost += m_cIntraBLPredFlagSCModel.calcCost   ( curSliceType, qp, (UChar*)INIT_INTRA_BL_PRED_FLAG );
+#endif
       curCost += m_cCUMergeFlagExtSCModel.calcCost    ( curSliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT);
       curCost += m_cCUMergeIdxExtSCModel.calcCost     ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT);
@@ -234,4 +243,7 @@
   m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
   m_cSaoMergeSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
+#if INTRA_BL
+  m_cIntraBLPredFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_BL_PRED_FLAG );
+#endif
   m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
   m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
@@ -416,4 +428,7 @@
 {
   PartSize eSize         = pcCU->getPartitionSize( uiAbsPartIdx );
+#if INTRA_BL
+  assert( !pcCU->isIntraBL( uiAbsPartIdx ) );
+#endif
   if ( pcCU->isIntra( uiAbsPartIdx ) )
   {
@@ -1584,3 +1599,24 @@
   this->xCopyContextsFrom(pScr);
 }
+
+#if INTRA_BL
+/** code intra_bl flag
+ * \param pcCU
+ * \param uiAbsPartIdx 
+ * \returns Void
+ */
+Void TEncSbac::codeIntraBLFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
+{
+  // get context function is here
+  UInt uiSymbol = pcCU->isIntraBL( uiAbsPartIdx ) ? 1 : 0;
+
+  UInt uiCtxIntraBL = pcCU->getCtxIntraBLFlag( uiAbsPartIdx ) ;
+  m_pcBinIf->encodeBin(uiSymbol, m_cIntraBLPredFlagSCModel.get( 0, 0, uiCtxIntraBL )); 
+
+  DTRACE_CABAC_VL( g_nSymbolCounter++ );
+  DTRACE_CABAC_T( "\tuiSymbol: ");
+  DTRACE_CABAC_V( uiSymbol );
+  DTRACE_CABAC_T( "\n");
+}
+#endif
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSbac.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSbac.h	(revision 54)
@@ -134,4 +134,7 @@
   Void codeMVPIdx        ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
   
+#if INTRA_BL
+  Void codeIntraBLFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
+#endif
   Void codePartSize      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   Void codePredMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
@@ -204,4 +207,7 @@
   ContextModel3DBuffer m_cTransformSkipSCModel;
   ContextModel3DBuffer m_CUTransquantBypassFlagSCModel;
+#if INTRA_BL
+  ContextModel3DBuffer m_cIntraBLPredFlagSCModel;
+#endif
 };
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 54)
@@ -906,5 +906,11 @@
         m_pcEntropyCoder->encodePredMode( pcCU, 0, true );
       }
-      
+#if INTRA_BL
+      m_pcEntropyCoder->encodeIntraBLFlag ( pcCU, 0, true );
+      if( pcCU->isIntraBL( 0 ) )
+      {
+        return;
+      }
+#endif      
       m_pcEntropyCoder  ->encodePartSize( pcCU, 0, pcCU->getDepth(0), true );
 
@@ -944,4 +950,10 @@
     }
   }
+#if INTRA_BL
+  if( pcCU->isIntraBL( 0 ) )
+  {
+    return;
+  }
+#endif
   if( bChroma )
   {
@@ -1043,4 +1055,11 @@
     pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail );
     //===== get prediction signal =====
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED
+    if(pcCU->isIntraBL ( uiAbsPartIdx ) )
+    {
+      pcCU->getBaseLumaBlk( uiWidth, uiHeight, uiAbsPartIdx, piPred, uiStride );
+    }
+    else
+#endif
     predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
     // save prediction 
@@ -1228,4 +1247,11 @@
 
     //===== get prediction signal =====
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED
+  if(pcCU->isIntraBL ( uiAbsPartIdx ) )
+  {
+    pcCU->getBaseChromaBlk( uiWidth, uiHeight, uiAbsPartIdx, piPred, uiStride, uiChromaId );
+  }
+  else
+#endif
     {
       predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
@@ -3039,4 +3065,12 @@
   Int iHeight = 0; 
 
+#if REF_IDX_FRAMEWORK  // HM bug fix
+  for( UInt uiMergeCand = 0; uiMergeCand < pcCU->getSlice()->getMaxNumMergeCand(); ++uiMergeCand )
+  {
+    uhInterDirNeighbours[uiMergeCand] = 0;
+    cMvFieldNeighbours[0 + 2*uiMergeCand].setMvField(TComMv(), NOT_VALID);
+    cMvFieldNeighbours[1 + 2*uiMergeCand].setMvField(TComMv(), NOT_VALID);
+  }
+#endif
   pcCU->getPartIndexAndSize( iPUIdx, uiAbsPartIdx, iWidth, iHeight );
   UInt uiDepth = pcCU->getDepth( uiAbsPartIdx );
@@ -3060,5 +3094,9 @@
   for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
   {
-    {
+#if REF_IDX_ME_ZEROMV
+    Bool bZeroMVILR = pcCU->xCheckZeroMVILRMerge(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]);
+    if(bZeroMVILR)
+    {
+#endif
       UInt uiCostCand = MAX_UINT;
       UInt uiBitsCand = 0;
@@ -3084,5 +3122,7 @@
         uiMergeIndex = uiMergeCand;
       }
-    }
+#if REF_IDX_ME_ZEROMV
+    }
+#endif
   }
 }
@@ -3209,4 +3249,8 @@
     UInt          uiBitsTempL0[MAX_NUM_REF];
 
+#if (ENCODER_FAST_MODE)
+    Bool          testILR;
+#endif
+
     xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
     
@@ -3230,6 +3274,25 @@
       RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
       
+#if (ENCODER_FAST_MODE)
+      if (pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1)
+      {
+        testILR = false;
+      }
+      else
+      {
+        testILR = true;
+      }
+#endif
+
       for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ )
       {
+#if (ENCODER_FAST_MODE)
+        TComPic* pcPic    = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp );
+        if( !testILR && pcPic->getIsILR() && (ePartSize == SIZE_2Nx2N) ) 
+        {
+          continue;
+        }
+#endif
+
         uiBitsTemp = uiMbBits[iRefList];
         if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 )
@@ -3248,7 +3311,15 @@
         if(pcCU->getSlice()->getMvdL1ZeroFlag() && iRefList==1 && biPDistTemp < bestBiPDist)
         {
+#if REF_IDX_ME_ZEROMV 
+          Bool bZeroMVILR = pcCU->xCheckZeroMVILRMvdL1Zero(iRefList, iRefIdxTemp, aaiMvpIdx[iRefList][iRefIdxTemp]);
+          if(bZeroMVILR)
+          {
+#endif
           bestBiPDist = biPDistTemp;
           bestBiPMvpL1 = aaiMvpIdx[iRefList][iRefIdxTemp];
           bestBiPRefIdxL1 = iRefIdxTemp;
+#if REF_IDX_ME_ZEROMV
+          }
+#endif
         }
 
@@ -3343,8 +3414,14 @@
         }
 
+#if ENCODER_BUGFIX
+        if ( ( iRefList == 0 && uiCostTemp < uiCost[iRefList] ) ||
+            ( iRefList == 1 &&  pcCU->getSlice()->getNoBackPredFlag() && iRefIdxTemp == iRefIdx[0] ) ||
+            ( iRefList == 1 && !pcCU->getSlice()->getNoBackPredFlag() && uiCostTemp < uiCost[iRefList] ) )
+#else
         if ( ( iRefList == 0 && uiCostTemp < uiCost[iRefList] ) ||
             ( iRefList == 1 &&  pcCU->getSlice()->getNoBackPredFlag() && iRefIdxTemp == iRefIdx[0] ) ||
             ( iRefList == 1 && (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) && (iRefIdxTemp==0 || iRefIdxTemp == iRefIdx[0]) && !pcCU->getSlice()->getNoBackPredFlag() && (iRefIdxTemp == pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)) ) ||
             ( iRefList == 1 && !pcCU->getSlice()->getNoBackPredFlag() && uiCostTemp < uiCost[iRefList] ) )
+#endif
           {
             uiCost[iRefList] = uiCostTemp;
@@ -3375,5 +3452,9 @@
     }
     //  Bi-directional prediction
+#if REF_IDX_ME_ZEROMV
+    if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) && !(pcCU->getSlice()->getMvdL1ZeroFlag() && bestBiPDist == MAX_INT) )
+#else
     if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) )
+#endif
     {
       
@@ -3449,4 +3530,12 @@
         Bool bChanged = false;
         
+#if (ENCODER_FAST_MODE)
+        Bool     testIter = true;
+        TComPic* pcPic    = pcCU->getSlice()->getRefPic( RefPicList(1 - iRefList), iRefIdxBi[1 - iRefList] );
+        if(pcPic->getIsILR() && (ePartSize == SIZE_2Nx2N))
+          testIter = false;  //the fixed part is ILR, skip this iteration       
+        if(testIter)
+        {
+#endif
         iRefStart = 0;
         iRefEnd   = pcCU->getSlice()->getNumRefIdx(eRefPicList)-1;
@@ -3454,4 +3543,12 @@
         for ( Int iRefIdxTemp = iRefStart; iRefIdxTemp <= iRefEnd; iRefIdxTemp++ )
         {
+#if (ENCODER_FAST_MODE)
+            Bool testRefIdx = true;
+            pcPic           = pcCU->getSlice()->getRefPic( RefPicList(iRefList) , iRefIdxTemp );
+            if(pcPic->getIsILR() && (ePartSize == SIZE_2Nx2N))
+              testRefIdx = false;  //the refined part is ILR, skip this reference pic           
+            if(testRefIdx)
+            {
+#endif
           uiBitsTemp = uiMbBits[2] + uiMotBits[1-iRefList];
           if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 )
@@ -3487,5 +3584,11 @@
             }
           }
+#if (ENCODER_FAST_MODE)
+            }
+#endif
+          }
+#if (ENCODER_FAST_MODE)
         } // for loop-iRefIdxTemp
+#endif
         
         if ( !bChanged )
@@ -4104,4 +4207,12 @@
   setWpScalingDistParam( pcCU, iRefIdxPred, eRefPicList );
   //  Do integer search
+#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV
+#if REF_IDX_ME_AROUND_ZEROMV
+  if( pcCU->getSlice()->getRefPic(eRefPicList, iRefIdxPred )->getIsILR())  //ILR reference pic
+  {
+    xPatternSearchILR  ( pcCU, pcPatternKey, piRefY, iRefStride, rcMv, ruiCost );
+  }
+  else  //non ILR reference pic
+  {
   if ( !m_iFastSearch || bBi )
   {
@@ -4112,5 +4223,36 @@
     rcMv = *pcMvPred;
     xPatternSearchFast  ( pcCU, pcPatternKey, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost );
-  }
+    }
+  }
+#endif
+#if REF_IDX_ME_ZEROMV
+  if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->getIsILR())  //ILR reference pic 
+  {
+    rcMv.setZero();  //use Mv(0, 0) for integer ME 
+  }
+  else  //non ILR reference pic
+  {
+    if ( !m_iFastSearch || bBi ) 
+    { 
+      xPatternSearch      ( pcPatternKey, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost ); 
+    } 
+    else 
+    { 
+      rcMv = *pcMvPred; 
+      xPatternSearchFast  ( pcCU, pcPatternKey, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost ); 
+    }
+  }
+#endif
+#else
+  if ( !m_iFastSearch || bBi )
+  {
+    xPatternSearch      ( pcPatternKey, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost );
+  }
+  else
+  {
+    rcMv = *pcMvPred;
+    xPatternSearchFast  ( pcCU, pcPatternKey, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost );
+  }
+#endif
   
   m_pcRdCost->getMotionCost( 1, 0 );
@@ -4118,7 +4260,18 @@
   
   {
+#if REF_IDX_ME_ZEROMV
+    if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->getIsILR())  //ILR reference pic
+    {
+      xPatternSearchFracDIFMv0( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi );
+    }
+    else    //non ILR reference pic
+    {
+      xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi );
+    }
+#else
     xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost
                           ,bBi
                           );
+#endif
   }
   
@@ -4457,5 +4610,9 @@
 Void TEncSearch::encodeResAndCalcRdInterCU( TComDataCU* pcCU, TComYuv* pcYuvOrg, TComYuv* pcYuvPred, TComYuv*& rpcYuvResi, TComYuv*& rpcYuvResiBest, TComYuv*& rpcYuvRec, Bool bSkipRes )
 {
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+  if ( pcCU->isIntra(0) && !pcCU->isIntraBL(0))
+#else
   if ( pcCU->isIntra(0) )
+#endif
   {
     return;
@@ -4568,4 +4725,18 @@
       pcCU->setTransformSkipSubParts ( 0, 0, 0, 0, pcCU->getDepth(0) );
     }
+#if NO_RESIDUAL_FLAG_FOR_BLPRED 
+    else if(pcCU->getLayerId() > 0 && pcCU->isIntraBL(0) && uiZeroDistortion == uiDistortion) // all zeros
+    {
+      const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (pcCU->getDepth(0) << 1);
+      ::memset( pcCU->getTransformIdx()      , 0, uiQPartNum * sizeof(UChar) );
+      ::memset( pcCU->getCbf( TEXT_LUMA )    , 0, uiQPartNum * sizeof(UChar) );
+      ::memset( pcCU->getCbf( TEXT_CHROMA_U ), 0, uiQPartNum * sizeof(UChar) );
+      ::memset( pcCU->getCbf( TEXT_CHROMA_V ), 0, uiQPartNum * sizeof(UChar) );
+      ::memset( pcCU->getCoeffY()            , 0, uiWidth * uiHeight * sizeof( TCoeff )      );
+      ::memset( pcCU->getCoeffCb()           , 0, uiWidth * uiHeight * sizeof( TCoeff ) >> 2 );
+      ::memset( pcCU->getCoeffCr()           , 0, uiWidth * uiHeight * sizeof( TCoeff ) >> 2 );
+      pcCU->setTransformSkipSubParts ( 0, 0, 0, 0, pcCU->getDepth(0) );
+    }
+#endif
     else
     {
@@ -4866,5 +5037,16 @@
       Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA];
       assert(scalingListType < 6);     
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+      if(pcCU->isIntraBL(uiAbsPartIdx) )
+      {
+        m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,DC_IDX, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),  pcCoeffCurrY, trWidth, trHeight, scalingListType );//this is for inter mode only
+      }
+      else
+      {
+        m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),  pcCoeffCurrY, trWidth, trHeight, scalingListType );//this is for inter mode only
+      }
+#else
       m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),  pcCoeffCurrY, trWidth, trHeight, scalingListType );//this is for inter mode only
+#endif
       
       const UInt uiNonzeroDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),
@@ -5136,5 +5318,16 @@
         assert(scalingListType < 6);     
 
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+        if(pcCU->isIntraBL(uiAbsPartIdx) )
+        {
+          m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,DC_IDX, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),  pcCoeffCurrY, trWidth, trHeight, scalingListType, true );
+        }
+        else
+        {
+          m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),  pcCoeffCurrY, trWidth, trHeight, scalingListType, true );
+        }
+#else
         m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),  pcCoeffCurrY, trWidth, trHeight, scalingListType, true );
+#endif
 
         uiNonzeroDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),
@@ -5467,5 +5660,13 @@
 
   {
+#if INTRA_BL
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+    assert( !pcCU->isIntra(uiAbsPartIdx) || pcCU->isIntraBL(uiAbsPartIdx));
+#else
+    assert( !pcCU->isIntra(uiAbsPartIdx) );
+#endif
+#else
     assert( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA );
+#endif
     if( bSubdivAndCbf )
     {
@@ -5701,7 +5902,23 @@
     }
     m_pcEntropyCoder->encodeSkipFlag ( pcCU, 0, true );
+#if INTRA_BL
+    if(m_pcEncCfg->getLayerId())
+    {
+      m_pcEntropyCoder->encodeIntraBLFlag(pcCU, 0, true);
+#if !NO_RESIDUAL_FLAG_FOR_BLPRED
+      assert( pcCU->isIntraBL( 0 ) == false );
+#endif
+    }
+#endif
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+    if( !pcCU->isIntraBL(0))
+    {
+#endif
     m_pcEntropyCoder->encodePredMode( pcCU, 0, true );
     m_pcEntropyCoder->encodePartSize( pcCU, 0, pcCU->getDepth(0), true );
     m_pcEntropyCoder->encodePredInfo( pcCU, 0, true );
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+    }
+#endif
     Bool bDummy = false;
     m_pcEntropyCoder->encodeCoeff   ( pcCU, 0, pcCU->getDepth(0), pcCU->getWidth(0), pcCU->getHeight(0), bDummy );
@@ -5952,3 +6169,275 @@
 }
 
+#if REF_IDX_ME_ZEROMV
+Void TEncSearch::xPatternSearchFracDIFMv0(TComDataCU* pcCU,
+                                          TComPattern* pcPatternKey,
+                                          Pel* piRefY,
+                                          Int iRefStride,
+                                          TComMv* pcMvInt,
+                                          TComMv& rcMvHalf,
+                                          TComMv& rcMvQter,
+                                          UInt& ruiCost,
+                                          Bool biPred
+                                          )
+{
+  assert(pcMvInt->getHor() == 0 && pcMvInt->getVer() == 0);
+  Int         iOffset    = pcMvInt->getHor() + pcMvInt->getVer() * iRefStride;
+  m_pcRdCost->setDistParam( pcPatternKey, piRefY + iOffset, iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME() );
+  m_pcRdCost->setCostScale ( 2 );
+  setDistParamComp(0);
+  ruiCost = m_cDistParam.DistFunc( &m_cDistParam );  //SATD
+  ruiCost += m_pcRdCost->getCost( pcMvInt->getHor(), pcMvInt->getVer() );  //SATD rdCost
+  rcMvHalf.setZero();
+  rcMvQter.setZero();
+}
+#endif
+
+#if REF_IDX_ME_AROUND_ZEROMV
+//ILR integer pixel motion estimation search
+//pcCU is CU pointer
+//pcPatterney contains target PU infor
+//piRefY is the PU at the same position as the source PU, but in the reference pic
+//iRefStride is the reference stride
+//rcMv output best integer MV
+//ruiSAD outputs the SAD of best integer MV
+Void TEncSearch::xPatternSearchILR( TComDataCU* pcCU, TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, TComMv& rcMv, UInt& ruiSAD )
+{
+  Int      candMvX[5] = {0, -1, 1,  0, 0};
+  Int      candMvY[5] = {0,  0, 0, -1, 1};
+  Int      numCand    = 1;
+  Int      iBestX = 0;
+  Int      iBestY = 0;
+  Int      uiSadBest = MAX_UINT;
+  UInt     uiSad;
+
+  Pel*  piRefSrch;
+
+  //-- jclee for using the SAD function pointer
+  m_pcRdCost->setDistParam( pcPatternKey, piRefY, iRefStride,  m_cDistParam );
+
+  // fast encoder decision: use subsampled SAD for integer ME
+  if ( m_pcEncCfg->getUseFastEnc() )
+  {
+    if ( m_cDistParam.iRows > 8 )
+    {
+      m_cDistParam.iSubShift = 1;
+    }
+  }
+
+  for(Int candId = 0; candId < numCand; candId++)
+  {
+    piRefSrch         = piRefY + (candMvY[candId] * iRefStride) + candMvX[candId];
+    m_cDistParam.pCur = piRefSrch;
+
+    setDistParamComp(0);
+    
+    uiSad = m_cDistParam.DistFunc( &m_cDistParam );  //SAD
+
+    //motion cost
+    uiSad += m_pcRdCost->getCost( candMvX[candId], candMvY[candId] );  //SAD rdCost
+
+    if(uiSad < uiSadBest)
+    {
+      uiSadBest = uiSad;
+      iBestX    = candMvX[candId];
+      iBestY    = candMvY[candId];
+    }
+  }
+
+  rcMv.set( iBestX, iBestY );
+
+  ruiSAD = uiSadBest - m_pcRdCost->getCost( iBestX, iBestY );
+  return;
+}
+#endif
+
+#if ENCODER_FAST_MODE
+Bool TEncSearch::predInterSearchILRUni( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv )
+{
+  rpcPredYuv->clear();
+  rpcRecoYuv->clear();
+
+  Int           iNumPredDir = pcCU->getSlice()->isInterP() ? 1 : 2;
+
+  TComMv        cMv[2];
+  TComMv        cMvPred[2][33];
+  TComMv        cMvTemp[2][33];
+  TComMv        TempMv;
+
+  Int           iRefIdx[2]={0,0};
+
+  Int           aaiMvpIdx[2][33];
+  Int           aaiMvpNum[2][33];
+
+  UInt          uiMbBits[3] = {1, 1, 0};
+  UInt          uiLastMode = 0;
+
+  UInt          uiCost[2]   = { MAX_UINT, MAX_UINT };     //uni, rdCost
+  UInt          uiCostTemp;
+  UInt          biPDistTemp = MAX_INT;
+  UInt          uiBitsTemp;
+
+  PartSize      ePartSize = pcCU->getPartitionSize( 0 );  //2Nx2N
+  Int           iPartIdx  = 0;                            //one PU in CU
+  UInt          uiPartAddr;
+  Int           iRoiWidth, iRoiHeight;
+
+  xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
+  pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight );
+
+  for( Int iRefList = 0; iRefList < iNumPredDir; iRefList++)  //list
+  {
+    RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
+
+    Int  iRefIdxTemp = -1;
+    Bool foundILR    = false;
+    for( Int refIdx = 0; refIdx < pcCU->getSlice()->getNumRefIdx(eRefPicList); refIdx++ )
+      if( pcCU->getSlice()->getRefPic(eRefPicList, refIdx)->getIsILR() )
+      {
+        iRefIdxTemp = refIdx;
+        foundILR    = true;
+        break;
+      }
+
+    if(!foundILR)  //no ILR in eRefPiclist
+      continue;  
+
+    uiBitsTemp = uiMbBits[iRefList];
+    if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 ) 
+    { 
+      uiBitsTemp += iRefIdxTemp+1; 
+      if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--; 
+    }
+
+    xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp);
+    aaiMvpIdx[iRefList][iRefIdxTemp] = pcCU->getMVPIdx(eRefPicList, uiPartAddr);
+    aaiMvpNum[iRefList][iRefIdxTemp] = pcCU->getMVPNum(eRefPicList, uiPartAddr);
+
+    uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
+
+    xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
+    xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
+
+    if( uiCostTemp < uiCost[iRefList] )
+    {
+      uiCost[iRefList] = uiCostTemp;
+
+      cMv[iRefList]     = cMvTemp[iRefList][iRefIdxTemp];
+      iRefIdx[iRefList] = iRefIdxTemp;
+
+      pcCU->getCUMvField(eRefPicList)->setAllMv( cMv[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
+      pcCU->getCUMvField(eRefPicList)->setAllRefIdx( iRefIdx[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
+    }
+  }
+
+  if( uiCost[0] == MAX_UINT && uiCost[1] == MAX_UINT )  //no ILR in both list0 and list1
+    return false;
+
+  //  Clear Motion Field 
+  pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx ); 
+  pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx ); 
+  pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TComMv(),      ePartSize, uiPartAddr, 0, iPartIdx ); 
+  pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TComMv(),      ePartSize, uiPartAddr, 0, iPartIdx );
+
+  pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
+  pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
+  pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
+  pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
+
+  if( uiCost[0] <= uiCost[1] )  //list0 ILR
+  {
+    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv    ( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx );
+    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx );
+
+    TempMv = cMv[0] - cMvPred[0][iRefIdx[0]]; 
+    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd( TempMv, ePartSize, uiPartAddr, 0, iPartIdx );
+
+    pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
+
+    pcCU->setMVPIdxSubParts( aaiMvpIdx[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
+    pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
+  }
+  else if( uiCost[1] < uiCost[0] )  //list1 ILR
+  {
+    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv    ( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx );
+    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx );
+
+    TempMv = cMv[1] - cMvPred[1][iRefIdx[1]]; 
+    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd( TempMv, ePartSize, uiPartAddr, 0, iPartIdx );
+
+    pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
+
+    pcCU->setMVPIdxSubParts( aaiMvpIdx[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
+    pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
+  }
+  else
+    assert(0);
+
+  pcCU->setMergeFlagSubParts( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+
+  motionCompensation ( pcCU, rpcPredYuv, REF_PIC_LIST_X, iPartIdx );
+
+  setWpScalingDistParam( pcCU, -1, REF_PIC_LIST_X );
+
+  return true;
+}
+
+
+#endif
+
+#if INTRA_BL
+Void 
+TEncSearch::estIntraBLPredQT( TComDataCU* pcCU, 
+                           TComYuv*    pcOrgYuv, 
+                           TComYuv*    pcPredYuv, 
+                           TComYuv*    pcResiYuv,
+                           TComYuv*    pcRecoYuv )
+{
+  UInt    uiDepth        = pcCU->getDepth(0);
+  UInt    uiOverallDistY = 0;
+  UInt    uiOverallDistC = 0;
+  
+  //===== set QP and clear Cbf =====
+  if ( pcCU->getSlice()->getPPS()->getUseDQP() == true)
+  {
+    pcCU->setQPSubParts( pcCU->getQP(0), 0, uiDepth );
+  }
+  else
+  {
+    pcCU->setQPSubParts( pcCU->getSlice()->getSliceQp(), 0, uiDepth );
+  }
+  
+  //===== init pattern for luma prediction =====
+  Bool bAboveAvail = false;
+  Bool bLeftAvail  = false;
+  pcCU->getPattern()->initPattern   ( pcCU, 0, 0 );
+  pcCU->getPattern()->initAdiPattern( pcCU, 0, 0, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail );
+  
+  pcCU->setLumaIntraDirSubParts ( DC_IDX, 0, uiDepth );
+  
+  // set context models
+  if( m_bUseSBACRD )
+  {
+    m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
+  }
+  
+  // determine residual for partition
+  Double dPUCost   = 0.0;
+  xRecurIntraCodingQT( pcCU, 0, 0, false, pcOrgYuv, pcPredYuv, pcResiYuv, uiOverallDistY, uiOverallDistC, false, dPUCost );
+  xSetIntraResultQT( pcCU, 0, 0, false, pcRecoYuv );
+  
+  //=== update PU data ====
+  pcCU->copyToPic( uiDepth, 0, 0 );
+   
+  //===== reset context models =====
+  if(m_bUseSBACRD)
+  {
+    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
+  }
+
+  //===== set distortion (rate and r-d costs are determined later) =====
+  pcCU->getTotalDistortion() = uiOverallDistY + uiOverallDistC;
+}
+
+#endif
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSearch.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSearch.h	(revision 54)
@@ -97,4 +97,11 @@
   TEncCfg*        m_pcEncCfg;
   
+#if SVC_EXTENSION
+  TEncTop**       m_ppcTEncTop;
+#if INTRA_BL
+  TComPicYuv*     m_pcPicYuvRecBase;       ///< reconstructed base layer
+#endif
+#endif
+  
   // interface to classes
   TComTrQuant*    m_pcTrQuant;
@@ -186,4 +193,13 @@
                                   UInt        uiPreCalcDistC );
   
+#if INTRA_BL
+  Void setBaseRecPic            ( TComPicYuv* pcPicYuvRecBase ) { m_pcPicYuvRecBase = pcPicYuvRecBase; }  
+  TComPicYuv* getBaseRecPic     ()                              { return m_pcPicYuvRecBase; }
+  Void  estIntraBLPredQT        ( TComDataCU* pcCU, 
+                                  TComYuv*    pcOrgYuv, 
+                                  TComYuv*    pcPredYuv, 
+                                  TComYuv*    pcResiYuv, 
+                                  TComYuv*    pcRecoYuv );
+#endif
   
   /// encoder estimation - inter prediction (non-skip)
@@ -198,4 +214,14 @@
 #endif
                                 );
+  
+#if (ENCODER_FAST_MODE)
+  Bool predInterSearchILRUni    ( TComDataCU* pcCU,
+                                  TComYuv*    pcOrgYuv,
+                                  TComYuv*&   rpcPredYuv,
+                                  TComYuv*&   rpcResiYuv,
+                                  TComYuv*&   rpcRecoYuv
+                                );
+
+#endif
   
   /// encode residual and compute rd-cost for inter mode
@@ -436,5 +462,24 @@
                                    ,Bool biPred
                                    );
-  
+#if REF_IDX_ME_AROUND_ZEROMV
+  Void xPatternSearchILR         ( TComDataCU*    pcCU,
+                                   TComPattern*   pcPatternKey,
+                                   Pel*           piRefY, 
+                                   Int            iRefStride, 
+                                   TComMv&        rcMv, 
+                                   UInt&          ruiSAD );
+#endif
+  
+#if REF_IDX_ME_ZEROMV
+  Void xPatternSearchFracDIFMv0  ( TComDataCU*   pcCU,
+                                   TComPattern*  pcPatternKey,
+                                   Pel*          piRefY,
+                                   Int           iRefStride,
+                                   TComMv*       pcMvInt,
+                                   TComMv&       rcMvHalf,
+                                   TComMv&       rcMvQter,
+                                   UInt&         ruiCost,
+                                   Bool          biPred );
+#endif
   Void xExtDIFUpSamplingH( TComPattern* pcPattern, Bool biPred  );
   Void xExtDIFUpSamplingQ( TComPattern* pcPatternKey, TComMv halfPelRef, Bool biPred );
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 54)
@@ -137,5 +137,7 @@
   m_pcCfg             = pcEncTop;
   m_pcListPic         = pcEncTop->getListPic();
-  
+#if SVC_EXTENSION
+  m_ppcTEncTop        = pcEncTop->getLayerEnc();
+#endif  
   m_pcGOPEncoder      = pcEncTop->getGOPEncoder();
   m_pcCuEncoder       = pcEncTop->getCuEncoder();
@@ -186,7 +188,14 @@
   rpcSlice->setSliceBits(0);
   rpcSlice->setPic( pcPic );
+#if SET_SLICE_LAYER_ID
+  rpcSlice->initSlice( pcPic->getLayerId() );
+#else
   rpcSlice->initSlice();
+#endif
   rpcSlice->setPicOutputFlag( true );
   rpcSlice->setPOC( pocCurr );
+#if SVC_EXTENSION && !SET_SLICE_LAYER_ID
+  rpcSlice->setLayerId( pcPic->getLayerId());
+#endif
   
   // depth computation based on GOP size
@@ -369,4 +378,10 @@
   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
   
+#if REF_IDX_FRAMEWORK
+  if(m_pcCfg->getLayerId() > 0)
+  {
+    eSliceType=B_SLICE;
+  }
+#endif
   rpcSlice->setSliceType        ( eSliceType );
 #endif
@@ -877,4 +892,9 @@
   UInt uiTileStartLCU = 0;
   UInt uiTileLCUX     = 0;
+
+#if INTRA_BL
+  m_pcCuEncoder->setBaseRecPic( rpcPic->getLayerId() > 0 ? rpcPic->getFullPelBaseRec() : NULL);
+#endif
+
   Bool depSliceSegmentsEnabled = pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag();
   uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
@@ -924,4 +944,7 @@
     TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
     pcCU->initCU( rpcPic, uiCUAddr );
+#if SVC_EXTENSION
+    pcCU->setLayerId(m_pcCfg->getLayerId());
+#endif
 
 #if !RATE_CONTROL_LAMBDA_DOMAIN
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSlice.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncSlice.h	(revision 54)
@@ -66,4 +66,8 @@
   TEncCfg*                m_pcCfg;                              ///< encoder configuration class
   
+#if SVC_EXTENSION
+  TEncTop**               m_ppcTEncTop;
+#endif  
+
   // pictures
   TComList<TComPic*>*     m_pcListPic;                          ///< list of pictures
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncTop.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncTop.cpp	(revision 54)
@@ -45,4 +45,8 @@
 //! \ingroup TLibEncoder
 //! \{
+#if SVC_EXTENSION  
+Int TEncTop::m_iSPSIdCnt = 0;
+Int TEncTop::m_iPPSIdCnt = 0;
+#endif
 
 // ====================================================================================================================
@@ -78,4 +82,10 @@
   m_pcBitCounters          = NULL;
   m_pcRdCosts              = NULL;
+#if REF_IDX_FRAMEWORK
+  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
+#endif
+#if REF_IDX_MFM
+  m_bMFMEnabledFlag = false;
+#endif
 }
 
@@ -89,9 +99,15 @@
 Void TEncTop::create ()
 {
+#if !SVC_EXTENSION
   // initialize global variables
   initROM();
+#endif
   
   // create processing unit classes
+#if SVC_EXTENSION
+  m_cGOPEncoder.        create( m_layerId );
+#else
   m_cGOPEncoder.        create();
+#endif
   m_cSliceEncoder.      create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
   m_cCuEncoder.         create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
@@ -268,7 +284,20 @@
   delete[] m_pcRdCosts;
   
+#if !SVC_EXTENSION
   // destroy ROM
   destroyROM();
-  
+#endif
+#if REF_IDX_FRAMEWORK
+  for(Int i=0; i<MAX_NUM_REF; i++)
+  {
+    if(m_cIlpPic[i])
+    {
+      //m_cIlpPic[i]->setPicYuvRec(NULL);
+      m_cIlpPic[i]->destroy();
+      delete m_cIlpPic[i];
+      m_cIlpPic[i] = NULL;
+    }
+  }    
+#endif
   return;
 }
@@ -313,4 +342,11 @@
 
   m_iMaxRefPicNum = 0;
+#if SVC_EXTENSION
+  m_iSPSIdCnt ++;
+  m_iPPSIdCnt ++;
+#endif
+#if REF_IDX_FRAMEWORK
+  xInitILRP();
+#endif
 }
 
@@ -345,5 +381,29 @@
  \retval  iNumEncoded         number of encoded pictures
  */
-Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
+#if SVC_EXTENSION
+Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP )
+{
+  // compress GOP
+#if RATE_CONTROL_LAMBDA_DOMAIN
+  if ( m_RCEnableRateControl )
+  {
+    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
+  }
+#endif
+
+  // compress GOP
+  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
+
+#if RATE_CONTROL_LAMBDA_DOMAIN
+  if ( m_RCEnableRateControl )
+  {
+    m_cRateCtrl.destroyRCGOP();
+  }
+#endif
+  
+  m_uiNumAllPicCoded ++;
+}
+
+Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg )
 {
   if (pcPicYuvOrg) {
@@ -359,4 +419,20 @@
     }
   }
+}
+#else
+Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
+{
+  if (pcPicYuvOrg) {
+    // get original YUV
+    TComPic* pcPicCurr = NULL;
+    xGetNewPicBuffer( pcPicCurr );
+    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
+
+    // compute image characteristics
+    if ( getUseAdaptiveQP() )
+    {
+      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
+    }
+  }
   
   if (!m_iNumPicRcvd || (!flush && m_iPOCLast != 0 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize))
@@ -387,4 +463,5 @@
   m_uiNumAllPicCoded += iNumEncoded;
 }
+#endif
 
 // ====================================================================================================================
@@ -421,6 +498,22 @@
     {
       TEncPic* pcEPic = new TEncPic;
+#if SVC_EXTENSION //Temporal solution, should be modified
+      if(m_layerId > 0)
+      {
+        TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
+        if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() )
+        {
+          pcEPic->setSpatialEnhLayerFlag( true );
+        }
+      }
+#endif
+
+#if SVC_UPSAMPLING
+      pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
+                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
+#else
       pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
                       m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
+#endif
       rpcPic = pcEPic;
     }
@@ -429,6 +522,22 @@
       rpcPic = new TComPic;
 
+#if SVC_EXTENSION //Temporal solution, should be modified
+      if(m_layerId > 0)
+      {
+        TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
+        if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() )
+        {
+          rpcPic->setSpatialEnhLayerFlag( true );
+        }
+      }
+#endif
+
+#if SVC_UPSAMPLING
+      rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
+#else
       rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                       m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
+#endif
     }
     if (getUseSAO())
@@ -450,4 +559,10 @@
 Void TEncTop::xInitSPS()
 {
+#if SVC_EXTENSION
+  m_cSPS.setLayerId(m_layerId);
+#endif
+#if REF_IDX_MFM
+  m_cSPS.setMFMEnabledFlag(m_bMFMEnabledFlag);
+#endif
   ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
   profileTierLevel.setLevelIdc(m_level);
@@ -484,4 +599,7 @@
   m_cSPS.setMinTrDepth    ( 0                   );
   m_cSPS.setMaxTrDepth    ( 1                   );
+#if SVC_EXTENSION
+  m_cSPS.setSPSId         ( m_iSPSIdCnt       );
+#endif
   
   m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
@@ -690,4 +808,8 @@
     }
   }
+#if SVC_EXTENSION
+  m_cPPS.setPPSId         ( m_iPPSIdCnt         );
+  m_cPPS.setSPSId         ( m_iSPSIdCnt         );
+#endif
 }
 
@@ -981,3 +1103,44 @@
   }
 }
+
+#if REF_IDX_FRAMEWORK
+Void TEncTop::xInitILRP()
+{
+  if(m_layerId>0)
+  {
+    if (m_cIlpPic[0] == NULL)
+    {
+      for (Int j=0; j<1/*MAX_NUM_REF*/; j++)
+      {
+        m_cIlpPic[j] = new  TComPic;
+        //m_cIlpPic[j]->createWithOutYuv(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, &m_cSPS, true);
+#if SVC_UPSAMPLING
+        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, &m_cSPS, true);
+#else
+        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
+#endif
+#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
+        m_cIlpPic[j]->setIsILR(true);
+#endif
+        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
+        {
+          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
+        }
+      }
+    }
+  }
+}
+
+Void TEncTop::setILRPic(TComPic *pcPic)
+{
+  if(m_cIlpPic[0])
+  {
+    //m_cIlpPic[0]->setPicYuvRec(pcPic->getFullPelBaseRec());
+    m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec());
+    m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC());
+    m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false);
+    m_cIlpPic[0]->getPicYuvRec()->extendPicBorder();
+  }
+}
+#endif
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncTop.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncTop.h	(revision 54)
@@ -73,4 +73,11 @@
   UInt                    m_uiNumAllPicCoded;             ///< number of coded pictures
   TComList<TComPic*>      m_cListPic;                     ///< dynamic list of pictures
+#if SVC_EXTENSION 
+  static Int              m_iSPSIdCnt;                    ///< next Id number for SPS    
+  static Int              m_iPPSIdCnt;                    ///< next Id number for PPS    
+#if AVC_SYNTAX
+  fstream*                m_pBLSyntaxFile;
+#endif
+#endif
   
   // encoder search
@@ -122,4 +129,14 @@
   TEncRateCtrl            m_cRateCtrl;                    ///< Rate control class
   
+#if SVC_EXTENSION
+  TEncTop**               m_ppcTEncTop;
+  TEncTop*                getLayerEnc(UInt layer)   { return m_ppcTEncTop[layer]; }
+#endif
+#if REF_IDX_FRAMEWORK
+  TComPic*                m_cIlpPic[MAX_NUM_REF];                    ///<  Inter layer Prediction picture =  upsampled picture 
+#endif
+#if REF_IDX_MFM
+  Bool                    m_bMFMEnabledFlag;
+#endif
 protected:
   Void  xGetNewPicBuffer  ( TComPic*& rpcPic );           ///< get picture buffer which will be processed
@@ -129,5 +146,7 @@
   Void  xInitPPSforTiles  ();
   Void  xInitRPS          ();                             ///< initialize PPS from encoder options
-
+#if REF_IDX_FRAMEWORK
+  Void xInitILRP();
+#endif
 public:
   TEncTop();
@@ -174,4 +193,12 @@
   Void selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid );
   TComScalingList*        getScalingList        () { return  &m_scalingList;         }
+#if SVC_EXTENSION
+  Void                    setLayerEnc(TEncTop** p) {m_ppcTEncTop = p;}
+  TEncTop**               getLayerEnc()            {return m_ppcTEncTop;}
+  Int                     getPOCLast            () { return m_iPOCLast;               }
+  Int                     getNumPicRcvd         () { return m_iNumPicRcvd;            }
+  Void                    setNumPicRcvd         ( Int num ) { m_iNumPicRcvd = num;      }
+#endif
+
   // -------------------------------------------------------------------------------------------------------------------
   // encoder function
@@ -179,6 +206,24 @@
 
   /// encode several number of pictures until end-of-sequence
+#if SVC_EXTENSION
+#if REF_IDX_FRAMEWORK
+  TComPic** getIlpList() { return m_cIlpPic; }
+  Void setILRPic(TComPic *pcPic);
+#endif
+#if REF_IDX_MFM
+  Void setMFMEnabledFlag       (Bool flag)   {m_bMFMEnabledFlag = flag;}
+  Bool getMFMEnabledFlag()                   {return m_bMFMEnabledFlag;}    
+#endif
+#if AVC_SYNTAX
+  Void      setBLSyntaxFile( fstream* pFile ) { m_pBLSyntaxFile = pFile; }
+  fstream*  getBLSyntaxFile() { return m_pBLSyntaxFile; }
+#endif
+  Void encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
+              std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP  );
+  Void encodePrep( TComPicYuv* pcPicYuvOrg );
+#else
   Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
               std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded );  
+#endif
 
   void printSummary() { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded); }
