Index: /branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 117)
+++ /branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 118)
@@ -292,4 +292,9 @@
   Int*    cfg_IntraPeriod   [MAX_LAYERS];
   Int*    cfg_conformanceMode  [MAX_LAYERS];
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  Int*    cfg_numDirectRefLayers [MAX_LAYERS];
+  string cfg_refLayerIds   [MAX_LAYERS];
+  string* cfg_refLayerIdsPtr   [MAX_LAYERS];
+#endif
   for(UInt layer = 0; layer < MAX_LAYERS; layer++)
   {
@@ -302,4 +307,8 @@
     cfg_IntraPeriod[layer]  = &m_acLayerCfg[layer].m_iIntraPeriod; 
     cfg_conformanceMode[layer] = &m_acLayerCfg[layer].m_conformanceMode;
+#if VPS_EXTN_DIRECT_REF_LAYERS
+    cfg_numDirectRefLayers  [layer] = &m_acLayerCfg[layer].m_numDirectRefLayers;
+    cfg_refLayerIdsPtr      [layer]  = &cfg_refLayerIds[layer];
+#endif
   }
 #if AVC_SYNTAX
@@ -337,4 +346,8 @@
   ("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")
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  ("NumDirectRefLayers%d",    cfg_numDirectRefLayers, -1, MAX_LAYERS, "Number of direct reference layers")
+  ("RefLayerIds%d",           cfg_refLayerIdsPtr, string(""), MAX_LAYERS, "direct reference layer IDs")
+#endif
   ("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")
@@ -717,4 +730,37 @@
     m_pRowHeight = NULL;
   }
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  for(Int layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    Char* pRefLayerIds = cfg_refLayerIds[layer].empty() ? NULL: strdup(cfg_refLayerIds[layer].c_str());
+    if( m_acLayerCfg[layer].m_numDirectRefLayers > 0 )
+    {
+      char *refLayerId;
+      int  i=0;
+      m_acLayerCfg[layer].m_refLayerIds = new Int[m_acLayerCfg[layer].m_numDirectRefLayers];
+      refLayerId = strtok(pRefLayerIds, " ,-");
+      while(refLayerId != NULL)
+      {
+        if( i >= m_acLayerCfg[layer].m_numDirectRefLayers )
+        {
+          printf( "The number of columns whose width are defined is larger than the allowed number of columns.\n" );
+          exit( EXIT_FAILURE );
+        }
+        *( m_acLayerCfg[layer].m_refLayerIds + i ) = atoi( refLayerId );
+        refLayerId = strtok(NULL, " ,-");
+        i++;
+      }
+      if( i < m_acLayerCfg[layer].m_numDirectRefLayers )
+      {
+        printf( "The width of some columns is not defined.\n" );
+        exit( EXIT_FAILURE );
+      }
+    }
+    else
+    {
+      m_acLayerCfg[layer].m_refLayerIds = NULL;
+    }
+  }
+#endif
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
   readBoolString(cfg_bitRateInfoPresentFlag, m_bitRatePicRateMaxTLayers, m_bitRateInfoPresentFlag, "bit rate info. present flag" );
@@ -1511,5 +1557,17 @@
   }
 #endif
-
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  xConfirmPara( (m_acLayerCfg[0].m_numDirectRefLayers != 0) && (m_acLayerCfg[0].m_numDirectRefLayers != -1), "Layer 0 cannot have any reference layers" );
+  // NOTE: m_numDirectRefLayers  (for any layer) could be -1 (not signalled in cfg), in which case only the "previous layer" would be taken for reference
+  for(Int layer = 1; layer < MAX_LAYERS; layer++)
+  {
+    xConfirmPara(m_acLayerCfg[layer].m_numDirectRefLayers > layer, "Cannot reference more layers than before current layer");
+    for(Int i = 0; i < m_acLayerCfg[layer].m_numDirectRefLayers; i++)
+    {
+      xConfirmPara(m_acLayerCfg[layer].m_refLayerIds[i] > layer, "Cannot reference higher layers");
+      xConfirmPara(m_acLayerCfg[layer].m_refLayerIds[i] == layer, "Cannot reference the current layer itself");
+    }
+  }
+#endif
 #undef xConfirmPara
   if (check_failed)
Index: /branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- /branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 117)
+++ /branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 118)
@@ -42,5 +42,8 @@
   Int       m_iIntraPeriod;                                   ///< period of I-slice (random access period)
   Double    m_fQP;                                            ///< QP value of key-picture (floating point)
-
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  Int       *m_refLayerIds;
+  Int       m_numDirectRefLayers;
+#endif
 #if SVC_EXTENSION
   Int       m_iWaveFrontSubstreams; //< If iWaveFrontSynchro, this is the number of substreams per frame (dependent tiles) or per tile (independent tiles).
@@ -80,5 +83,9 @@
   Int     getIntQP()                  {return m_iQP;              } 
   Int*    getdQPs()                   {return m_aidQP;            }
-
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  Int     getNumDirectRefLayers()     {return m_numDirectRefLayers;}
+  Int*    getRefLayerIds()            {return m_refLayerIds;      }
+  Int     getRefLayerId(Int i)        {return m_refLayerIds[i];   }
+#endif
 }; // END CLASS DEFINITION 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 117)
+++ /branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncTop.cpp	(revision 118)
@@ -140,5 +140,23 @@
     m_acTEncTop[layer].setMaxTempLayer                 ( m_maxTempLayer );
     m_acTEncTop[layer].setUseAMP( m_enableAMP );
-
+#if VPS_EXTN_DIRECT_REF_LAYERS
+    if(layer)
+    {
+      if(m_acLayerCfg[layer].getNumDirectRefLayers() == -1)
+      {
+        // Not included in the configuration file; assume that each layer depends on previous layer
+        m_acTEncTop[layer].setNumDirectRefLayers       (1);      // One ref. layer
+        m_acTEncTop[layer].setRefLayerId               (0, layer - 1);   // Previous layer
+      }
+      else
+      {
+        m_acTEncTop[layer].setNumDirectRefLayers       ( m_acLayerCfg[layer].getNumDirectRefLayers() );      
+        for(Int i = 0; i < m_acTEncTop[layer].getNumDirectRefLayers(); i++)
+        {
+          m_acTEncTop[layer].setRefLayerId             ( i, m_acLayerCfg[layer].getRefLayerId(i));
+        }        
+      }
+    }
+#endif
     //===== Slice ========
 
@@ -763,4 +781,25 @@
   }
 #endif
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  // Direct reference layers
+  for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+  {
+    vps->setNumDirectRefLayers( layerCtr, m_acTEncTop[layerCtr].getNumDirectRefLayers() );
+    for(Int i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
+    {
+      vps->setRefLayerId( layerCtr, i, m_acTEncTop[layerCtr].getRefLayerId(i) );
+    }
+    // Set direct dependency flag
+    // Initialize flag to 0
+    for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
+    {
+      vps->setDirectDependencyFlag( layerCtr, refLayerCtr, false );
+    }
+    for(Int i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
+    {
+      vps->setDirectDependencyFlag( layerCtr, vps->getLayerIdInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true);
+    }
+  }
+#endif
 #else
   m_cTEncTop.init();
Index: /branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.cpp	(revision 117)
+++ /branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.cpp	(revision 118)
@@ -1506,4 +1506,9 @@
   ::memset(m_outputLayerSetIdx, 0, sizeof(m_outputLayerSetIdx));
   ::memset(m_outputLayerFlag, 0, sizeof(m_outputLayerFlag));
+#endif
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  ::memset(m_directDependencyFlag, 0, sizeof(m_directDependencyFlag));
+  ::memset(m_numDirectRefLayers,   0, sizeof(m_numDirectRefLayers  ));
+  ::memset(m_refLayerId,           0, sizeof(m_refLayerId          ));
 #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 117)
+++ /branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.h	(revision 118)
@@ -541,5 +541,9 @@
   UInt       m_outputLayerSetIdx[MAX_VPS_LAYER_SETS_PLUS1];
   Bool       m_outputLayerFlag[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
-  // .. More declarations here
+#endif
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  Bool       m_directDependencyFlag[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  UInt       m_numDirectRefLayers[MAX_VPS_LAYER_ID_PLUS1];
+  UInt       m_refLayerId[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
 #endif
 
@@ -656,4 +660,15 @@
   Bool   getOutputLayerFlag(Int layerSet, Int layerId)          { return m_outputLayerFlag[layerSet][layerId]; }
   Void   setOutputLayerFlag(Int layerSet, Int layerId, Bool x)  { m_outputLayerFlag[layerSet][layerId] = x;    }
+#endif
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  // Direct dependency of layers
+  Bool   getDirectDependencyFlag(Int i, Int j)                  { return m_directDependencyFlag[i][j]; }
+  Void   setDirectDependencyFlag(Int i, Int j, Bool x)          { m_directDependencyFlag[i][j] = x;    }
+  
+  UInt   getNumDirectRefLayers(Int i)                                { return m_numDirectRefLayers[i];         }
+  Void   setNumDirectRefLayers(Int i, UInt x)                        { m_numDirectRefLayers[i] = x;            }
+
+  UInt   getRefLayerId(Int i, Int j)                            { return m_refLayerId[i][j];           }
+  Void   setRefLayerId(Int i, Int j, UInt x)                    { m_refLayerId[i][j] = x;              }
 #endif
 };
Index: /branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TypeDef.h	(revision 117)
+++ /branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TypeDef.h	(revision 118)
@@ -50,4 +50,5 @@
 #define VPS_EXTN_OP_LAYER_SETS           1      ///< Include output layer sets in VPS extension
 #define VPS_EXTN_PROFILE_INFO            1      ///< Include profile information for layer sets in VPS extension
+#define VPS_EXTN_DIRECT_REF_LAYERS       1      ///< Include indication of direct dependency of layers in VPS extension
 #endif
 #define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
Index: /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 117)
+++ /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 118)
@@ -934,5 +934,23 @@
   }  
 #endif
-  // ... More syntax elements to be parsed here
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  // For layer 0
+  vps->setNumDirectRefLayers(0, 0);
+  // For other layers
+  for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+  {
+    UInt numDirectRefLayers = 0;
+    for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
+    {
+      READ_FLAG(uiCode, "direct_dependency_flag[i][j]" ); vps->setDirectDependencyFlag(layerCtr, refLayerCtr, uiCode? true : false);
+      if(uiCode)
+      {
+        vps->setRefLayerId(layerCtr, numDirectRefLayers, refLayerCtr);
+        numDirectRefLayers++;
+      }
+    }
+    vps->setNumDirectRefLayers(layerCtr, numDirectRefLayers);
+  }
+#endif
 }
 #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 117)
+++ /branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 118)
@@ -731,5 +731,13 @@
   }
 #endif
-  // ... More syntax elements to be written here
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+  {
+    for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
+    {
+      WRITE_FLAG(vps->getDirectDependencyFlag(layerCtr, refLayerCtr), "direct_dependency_flag[i][j]" );
+    }
+  }
+#endif
 }
 #endif
Index: /branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCfg.h	(revision 117)
+++ /branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncCfg.h	(revision 118)
@@ -142,4 +142,8 @@
   Int       m_maxTempLayer;                      ///< Max temporal layer
   Bool m_useAMP;
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  Int       m_numDirectRefLayers;
+  Int       m_refLayerId[MAX_VPS_LAYER_ID_PLUS1];
+#endif
   //======= Transform =============
   UInt      m_uiQuadtreeTULog2MaxSize;
@@ -350,4 +354,11 @@
   Bool      getMaxTempLayer                 ()                              { return m_maxTempLayer;              } 
   Void      setMaxTempLayer                 ( Int maxTempLayer )            { m_maxTempLayer = maxTempLayer;      }
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  Int       getNumDirectRefLayers           ()                              { return m_numDirectRefLayers;      }
+  Void      setNumDirectRefLayers           (Int num)                       { m_numDirectRefLayers = num;       }
+
+  Int       getRefLayerId                   (Int i)                         { return m_refLayerId[i];           }
+  Void      setRefLayerId                   (Int i, Int refLayerId)         { m_refLayerId[i] = refLayerId;     }
+#endif
   //======== Transform =============
   Void      setQuadtreeTULog2MaxSize        ( UInt  u )      { m_uiQuadtreeTULog2MaxSize = u; }
