Index: /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 805)
+++ /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 806)
@@ -1018,8 +1018,11 @@
 #if Q0108_TSA_STSA
   for (Int i=1; i<MAX_LAYERS; i++)
-  for(Int j=1; j<MAX_GOP+1; j++){ 
-    std::ostringstream cOSS;
-    cOSS<<"Layer"<<i<<"Frame"<<j;
-    opts.addOptions()(cOSS.str(), m_EH_GOPList[i][j-1], GOPEntry());
+  {
+    for(Int j=1; j<MAX_GOP+1; j++)
+    { 
+      std::ostringstream cOSS;
+      cOSS<<"Layer"<<i<<"Frame"<<j;
+      opts.addOptions()(cOSS.str(), m_EhGOPList[i][j-1], GOPEntry());
+    }
   }
 #endif 
@@ -1035,5 +1038,5 @@
       for(Int j=1; j<MAX_GOP+1; j++)
       { 
-        m_EH_GOPList[i][j-1] = m_GOPList[j-1];
+        m_EhGOPList[i][j-1] = m_GOPList[j-1];
       }
     }
@@ -1042,5 +1045,5 @@
       for(Int j=1; j<MAX_GOP+1; j++)
       {
-        m_EH_GOPList[i][j-1] = m_EH_GOPList[m_inheritCodingStruct[i]][j-1];
+        m_EhGOPList[i][j-1] = m_EhGOPList[m_inheritCodingStruct[i]][j-1];
       }
     }
@@ -1887,5 +1890,4 @@
   }
 #endif
-  
 
   Bool verifiedGOP=false;
@@ -1920,5 +1922,4 @@
   xConfirmPara( m_numLayers > MAX_LAYERS , "Number of layers in config file is greater than MAX_LAYERS" );
   m_numLayers = m_numLayers > MAX_LAYERS ? MAX_LAYERS : m_numLayers;
-
   
   // it can be updated after AVC BL support will be added to the WD
@@ -1960,8 +1961,5 @@
    m_extraRPSs = 0;                                      
 #else
-   for (Int i = 0; i< MAX_LAYERS; i++)
-   {
-     m_extraRPSs[i] = 0;
-   }
+  memset( m_extraRPSs, 0, sizeof( m_extraRPSs ) );
 #endif
   //start looping through frames in coding order until we can verify that the GOP structure is correct.
@@ -2231,6 +2229,6 @@
   xConfirmPara(errorGOP,"Invalid GOP structure given");
 
-#if Q0108_TSA_STSA
-  for ( Int layer_index = 1; layer_index<m_numLayers; layer_index++)
+#if SVC_EXTENSION && Q0108_TSA_STSA
+  for ( Int layerId = 1; layerId < m_numLayers; layerId++ )
   {
     verifiedGOP=false;
@@ -2239,244 +2237,235 @@
     numRefs = m_isField ? 2 : 1;
     refList[0]=0;
+
     if(m_isField)
     {
       refList[1] = 1;
     }
-    for(Int i=0; i<MAX_GOP; i++) 
-    {
-      isOK[i]=false;
-    }
+
+    memset( isOK, 0, sizeof( isOK ) );
     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++)
-  {
-    if(m_EH_GOPList[layer_index][i].m_POC==m_iGOPSize)
-    {
-      xConfirmPara( m_EH_GOPList[layer_index][i].m_temporalId!=0 , "The last frame in each GOP must have temporal ID = 0 " );
-    }
-  }
-
-#if SVC_EXTENSION
-  xConfirmPara( m_numLayers > MAX_LAYERS , "Number of layers in config file is greater than MAX_LAYERS" );
-  m_numLayers = m_numLayers > MAX_LAYERS ? MAX_LAYERS : m_numLayers;
-
-  // 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) )
-  {
+
     for(Int i=0; i<m_iGOPSize; i++)
     {
-      xConfirmPara( (m_EH_GOPList[layer_index][i].m_betaOffsetDiv2 + m_loopFilterBetaOffsetDiv2) < -6 || (m_EH_GOPList[layer_index][i].m_betaOffsetDiv2 + m_loopFilterBetaOffsetDiv2) > 6, "Loop Filter Beta Offset div. 2 for one of the GOP entries exceeds supported range (-6 to 6)" );
-      xConfirmPara( (m_EH_GOPList[layer_index][i].m_tcOffsetDiv2 + m_loopFilterTcOffsetDiv2) < -6 || (m_EH_GOPList[layer_index][i].m_tcOffsetDiv2 + m_loopFilterTcOffsetDiv2) > 6, "Loop Filter Tc Offset div. 2 for one of the GOP entries exceeds supported range (-6 to 6)" );
-    }
-  }
-#if SVC_EXTENSION
-  }
-#endif
-
-  //start looping through frames in coding order until we can verify that the GOP structure is correct.
-  while(!verifiedGOP&&!errorGOP) 
-  {
-    Int curGOP = (checkGOP-1)%m_iGOPSize;
-    Int curPOC = ((checkGOP-1)/m_iGOPSize)*m_iGOPSize + m_EH_GOPList[layer_index][curGOP].m_POC;    
-    if(m_EH_GOPList[layer_index][curGOP].m_POC<0) 
-    {
-      printf("\nError: found fewer Reference Picture Sets than GOPSize\n");
-      errorGOP=true;
-    }
-    else 
-    {
-      //check that all reference pictures are available, or have a POC < 0 meaning they might be available in the next GOP.
-      Bool beforeI = false;
-      for(Int i = 0; i< m_EH_GOPList[layer_index][curGOP].m_numRefPics; i++) 
-      {
-        Int absPOC = curPOC+m_EH_GOPList[layer_index][curGOP].m_referencePics[i];
-        if(absPOC < 0)
-        {
-          beforeI=true;
-        }
-        else 
-        {
-          Bool found=false;
-          for(Int j=0; j<numRefs; j++) 
+      if(m_EhGOPList[layerId][i].m_POC==m_iGOPSize)
+      {
+        xConfirmPara( m_EhGOPList[layerId][i].m_temporalId!=0 , "The last frame in each GOP must have temporal ID = 0 " );
+      }
+    }
+
+    xConfirmPara( m_numLayers > MAX_LAYERS , "Number of layers in config file is greater than MAX_LAYERS" );
+    m_numLayers = m_numLayers > MAX_LAYERS ? MAX_LAYERS : m_numLayers;
+
+    // verify layer configuration parameters
+    for(UInt layer=0; layer<m_numLayers; layer++)
+    {
+      Int m_iIntraPeriod = m_acLayerCfg[layer].m_iIntraPeriod;
+      if ( (m_iIntraPeriod != 1) && !m_loopFilterOffsetInPPS && m_DeblockingFilterControlPresent && (!m_bLoopFilterDisable) )
+      {
+        for(Int i=0; i<m_iGOPSize; i++)
+        {
+          xConfirmPara( (m_EhGOPList[layerId][i].m_betaOffsetDiv2 + m_loopFilterBetaOffsetDiv2) < -6 || (m_EhGOPList[layerId][i].m_betaOffsetDiv2 + m_loopFilterBetaOffsetDiv2) > 6, "Loop Filter Beta Offset div. 2 for one of the GOP entries exceeds supported range (-6 to 6)" );
+          xConfirmPara( (m_EhGOPList[layerId][i].m_tcOffsetDiv2 + m_loopFilterTcOffsetDiv2) < -6 || (m_EhGOPList[layerId][i].m_tcOffsetDiv2 + m_loopFilterTcOffsetDiv2) > 6, "Loop Filter Tc Offset div. 2 for one of the GOP entries exceeds supported range (-6 to 6)" );
+        }
+      }
+    }
+
+    //start looping through frames in coding order until we can verify that the GOP structure is correct.
+    while(!verifiedGOP&&!errorGOP) 
+    {
+      Int curGOP = (checkGOP-1)%m_iGOPSize;
+      Int curPOC = ((checkGOP-1)/m_iGOPSize)*m_iGOPSize + m_EhGOPList[layerId][curGOP].m_POC;    
+      if(m_EhGOPList[layerId][curGOP].m_POC<0) 
+      {
+        printf("\nError: found fewer Reference Picture Sets than GOPSize\n");
+        errorGOP=true;
+      }
+      else 
+      {
+        //check that all reference pictures are available, or have a POC < 0 meaning they might be available in the next GOP.
+        Bool beforeI = false;
+        for(Int i = 0; i< m_EhGOPList[layerId][curGOP].m_numRefPics; i++) 
+        {
+          Int absPOC = curPOC+m_EhGOPList[layerId][curGOP].m_referencePics[i];
+          if(absPOC < 0)
           {
-            if(refList[j]==absPOC) 
+            beforeI=true;
+          }
+          else 
+          {
+            Bool found=false;
+            for(Int j=0; j<numRefs; j++) 
             {
-              found=true;
-              for(Int k=0; k<m_iGOPSize; k++)
+              if(refList[j]==absPOC) 
               {
-                if(absPOC%m_iGOPSize == m_EH_GOPList[layer_index][k].m_POC%m_iGOPSize)
+                found=true;
+                for(Int k=0; k<m_iGOPSize; k++)
                 {
-                  if(m_EH_GOPList[layer_index][k].m_temporalId==m_EH_GOPList[layer_index][curGOP].m_temporalId)
+                  if(absPOC%m_iGOPSize == m_EhGOPList[layerId][k].m_POC%m_iGOPSize)
                   {
-                    m_EH_GOPList[layer_index][k].m_refPic = true;
+                    if(m_EhGOPList[layerId][k].m_temporalId==m_EhGOPList[layerId][curGOP].m_temporalId)
+                    {
+                      m_EhGOPList[layerId][k].m_refPic = true;
+                    }
+                    m_EhGOPList[layerId][curGOP].m_usedByCurrPic[i]=m_EhGOPList[layerId][k].m_temporalId<=m_EhGOPList[layerId][curGOP].m_temporalId;
                   }
-                  m_EH_GOPList[layer_index][curGOP].m_usedByCurrPic[i]=m_EH_GOPList[layer_index][k].m_temporalId<=m_EH_GOPList[layer_index][curGOP].m_temporalId;
                 }
               }
             }
+            if(!found)
+            {
+              printf("\nError: ref pic %d is not available for GOP frame %d\n",m_EhGOPList[layerId][curGOP].m_referencePics[i],curGOP+1);
+              errorGOP=true;
+            }
           }
-          if(!found)
+        }
+        if(!beforeI&&!errorGOP)
+        {
+          //all ref frames were present
+          if(!isOK[curGOP]) 
           {
-            printf("\nError: ref pic %d is not available for GOP frame %d\n",m_EH_GOPList[layer_index][curGOP].m_referencePics[i],curGOP+1);
-            errorGOP=true;
+            numOK++;
+            isOK[curGOP]=true;
+            if(numOK==m_iGOPSize)
+            {
+              verifiedGOP=true;
+            }
           }
         }
-      }
-      if(!beforeI&&!errorGOP)
-      {
-        //all ref frames were present
-        if(!isOK[curGOP]) 
-        {
-          numOK++;
-          isOK[curGOP]=true;
-          if(numOK==m_iGOPSize)
+        else 
+        {
+          //create a new GOPEntry for this frame containing all the reference pictures that were available (POC > 0)
+
+          m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]]=m_EhGOPList[layerId][curGOP];
+          Int newRefs=0;
+          for(Int i = 0; i< m_EhGOPList[layerId][curGOP].m_numRefPics; i++) 
           {
-            verifiedGOP=true;
-          }
-        }
-      }
-      else 
-      {
-        //create a new GOPEntry for this frame containing all the reference pictures that were available (POC > 0)
- 
-        m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]]=m_EH_GOPList[layer_index][curGOP];
-        Int newRefs=0;
-        for(Int i = 0; i< m_EH_GOPList[layer_index][curGOP].m_numRefPics; i++) 
-        {
-          Int absPOC = curPOC+m_EH_GOPList[layer_index][curGOP].m_referencePics[i];
-          if(absPOC>=0)
-          {
-            m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_referencePics[newRefs]=m_EH_GOPList[layer_index][curGOP].m_referencePics[i];
-            m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_usedByCurrPic[newRefs]=m_EH_GOPList[layer_index][curGOP].m_usedByCurrPic[i];
-            newRefs++;
-          }
-        }
-        Int numPrefRefs = m_EH_GOPList[layer_index][curGOP].m_numRefPicsActive;
-        
-        for(Int offset = -1; offset>-checkGOP; offset--)
-        {
-          //step backwards in coding order and include any extra available pictures we might find useful to replace the ones with POC < 0.
-          Int offGOP = (checkGOP-1+offset)%m_iGOPSize;
-          Int offPOC = ((checkGOP-1+offset)/m_iGOPSize)*m_iGOPSize + m_EH_GOPList[layer_index][offGOP].m_POC;
-          if(offPOC>=0&&m_EH_GOPList[layer_index][offGOP].m_temporalId<=m_EH_GOPList[layer_index][curGOP].m_temporalId)
-          {
-            Bool newRef=false;
-            for(Int i=0; i<numRefs; i++)
+            Int absPOC = curPOC+m_EhGOPList[layerId][curGOP].m_referencePics[i];
+            if(absPOC>=0)
             {
-              if(refList[i]==offPOC)
-              {
-                newRef=true;
-              }
-            }
-            for(Int i=0; i<newRefs; i++) 
-            {
-              if(m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_referencePics[i]==offPOC-curPOC)
-              {
-                newRef=false;
-              }
-            }
-            if(newRef) 
-            {
-              Int insertPoint=newRefs;
-              //this picture can be added, find appropriate place in list and insert it.
-              if(m_EH_GOPList[layer_index][offGOP].m_temporalId==m_EH_GOPList[layer_index][curGOP].m_temporalId)
-              {
-                m_EH_GOPList[layer_index][offGOP].m_refPic = true;
-              }
-              for(Int j=0; j<newRefs; j++)
-              {
-                if(m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_referencePics[j]<offPOC-curPOC||m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_referencePics[j]>0)
-                {
-                  insertPoint = j;
-                  break;
-                }
-              }
-              Int prev = offPOC-curPOC;
-              Int prevUsed = m_EH_GOPList[layer_index][offGOP].m_temporalId<=m_EH_GOPList[layer_index][curGOP].m_temporalId;
-              for(Int j=insertPoint; j<newRefs+1; j++)
-              {
-                Int newPrev = m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_referencePics[j];
-                Int newUsed = m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_usedByCurrPic[j];
-                m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_referencePics[j]=prev;
-                m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_usedByCurrPic[j]=prevUsed;
-                prevUsed=newUsed;
-                prev=newPrev;
-              }
+              m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_referencePics[newRefs]=m_EhGOPList[layerId][curGOP].m_referencePics[i];
+              m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_usedByCurrPic[newRefs]=m_EhGOPList[layerId][curGOP].m_usedByCurrPic[i];
               newRefs++;
             }
           }
-          if(newRefs>=numPrefRefs)
+          Int numPrefRefs = m_EhGOPList[layerId][curGOP].m_numRefPicsActive;
+
+          for(Int offset = -1; offset>-checkGOP; offset--)
           {
-            break;
-          }
-        }
-        m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_numRefPics=newRefs;
-        m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_POC = curPOC;
-        if (m_extraRPSs[layer_index] == 0)
-        {
-          m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_interRPSPrediction = 0;
-          m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_numRefIdc = 0;
-        }
-        else
-        {
-          Int rIdx =  m_iGOPSize + m_extraRPSs[layer_index] - 1;
-          Int refPOC = m_EH_GOPList[layer_index][rIdx].m_POC;
-          Int refPics = m_EH_GOPList[layer_index][rIdx].m_numRefPics;
-          Int newIdc=0;
-          for(Int i = 0; i<= refPics; i++) 
-          {
-            Int deltaPOC = ((i != refPics)? m_EH_GOPList[layer_index][rIdx].m_referencePics[i] : 0);  // check if the reference abs POC is >= 0
-            Int absPOCref = refPOC+deltaPOC;
-            Int refIdc = 0;
-            for (Int j = 0; j < m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_numRefPics; j++)
+            //step backwards in coding order and include any extra available pictures we might find useful to replace the ones with POC < 0.
+            Int offGOP = (checkGOP-1+offset)%m_iGOPSize;
+            Int offPOC = ((checkGOP-1+offset)/m_iGOPSize)*m_iGOPSize + m_EhGOPList[layerId][offGOP].m_POC;
+            if(offPOC>=0&&m_EhGOPList[layerId][offGOP].m_temporalId<=m_EhGOPList[layerId][curGOP].m_temporalId)
             {
-              if ( (absPOCref - curPOC) == m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_referencePics[j])
+              Bool newRef=false;
+              for(Int i=0; i<numRefs; i++)
               {
-                if (m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_usedByCurrPic[j])
+                if(refList[i]==offPOC)
                 {
-                  refIdc = 1;
-                }
-                else
-                {
-                  refIdc = 2;
+                  newRef=true;
                 }
               }
+              for(Int i=0; i<newRefs; i++) 
+              {
+                if(m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_referencePics[i]==offPOC-curPOC)
+                {
+                  newRef=false;
+                }
+              }
+              if(newRef) 
+              {
+                Int insertPoint=newRefs;
+                //this picture can be added, find appropriate place in list and insert it.
+                if(m_EhGOPList[layerId][offGOP].m_temporalId==m_EhGOPList[layerId][curGOP].m_temporalId)
+                {
+                  m_EhGOPList[layerId][offGOP].m_refPic = true;
+                }
+                for(Int j=0; j<newRefs; j++)
+                {
+                  if(m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_referencePics[j]<offPOC-curPOC||m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_referencePics[j]>0)
+                  {
+                    insertPoint = j;
+                    break;
+                  }
+                }
+                Int prev = offPOC-curPOC;
+                Int prevUsed = m_EhGOPList[layerId][offGOP].m_temporalId<=m_EhGOPList[layerId][curGOP].m_temporalId;
+                for(Int j=insertPoint; j<newRefs+1; j++)
+                {
+                  Int newPrev = m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_referencePics[j];
+                  Int newUsed = m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_usedByCurrPic[j];
+                  m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_referencePics[j]=prev;
+                  m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_usedByCurrPic[j]=prevUsed;
+                  prevUsed=newUsed;
+                  prev=newPrev;
+                }
+                newRefs++;
+              }
             }
-            m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_refIdc[newIdc]=refIdc;
-            newIdc++;
+            if(newRefs>=numPrefRefs)
+            {
+              break;
+            }
           }
-          m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_interRPSPrediction = 1;  
-          m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_numRefIdc = newIdc;
-          m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_deltaRPS = refPOC - m_EH_GOPList[layer_index][m_iGOPSize+m_extraRPSs[layer_index]].m_POC; 
-        }
-        curGOP=m_iGOPSize+m_extraRPSs[layer_index];
-        m_extraRPSs[layer_index]++;
-      }
-      numRefs=0;
-      for(Int i = 0; i< m_EH_GOPList[layer_index][curGOP].m_numRefPics; i++) 
-      {
-        Int absPOC = curPOC+m_EH_GOPList[layer_index][curGOP].m_referencePics[i];
-        if(absPOC >= 0) 
-        {
-          refList[numRefs]=absPOC;
-          numRefs++;
-        }
-      }
-      refList[numRefs]=curPOC;
-      numRefs++;
-    }
-    checkGOP++;
-  }
-  xConfirmPara(errorGOP,"Invalid GOP structure given");
+          m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_numRefPics=newRefs;
+          m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_POC = curPOC;
+          if (m_extraRPSs[layerId] == 0)
+          {
+            m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_interRPSPrediction = 0;
+            m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_numRefIdc = 0;
+          }
+          else
+          {
+            Int rIdx =  m_iGOPSize + m_extraRPSs[layerId] - 1;
+            Int refPOC = m_EhGOPList[layerId][rIdx].m_POC;
+            Int refPics = m_EhGOPList[layerId][rIdx].m_numRefPics;
+            Int newIdc=0;
+            for(Int i = 0; i<= refPics; i++) 
+            {
+              Int deltaPOC = ((i != refPics)? m_EhGOPList[layerId][rIdx].m_referencePics[i] : 0);  // check if the reference abs POC is >= 0
+              Int absPOCref = refPOC+deltaPOC;
+              Int refIdc = 0;
+              for (Int j = 0; j < m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_numRefPics; j++)
+              {
+                if ( (absPOCref - curPOC) == m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_referencePics[j])
+                {
+                  if (m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_usedByCurrPic[j])
+                  {
+                    refIdc = 1;
+                  }
+                  else
+                  {
+                    refIdc = 2;
+                  }
+                }
+              }
+              m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_refIdc[newIdc]=refIdc;
+              newIdc++;
+            }
+            m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_interRPSPrediction = 1;  
+            m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_numRefIdc = newIdc;
+            m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_deltaRPS = refPOC - m_EhGOPList[layerId][m_iGOPSize+m_extraRPSs[layerId]].m_POC; 
+          }
+          curGOP=m_iGOPSize+m_extraRPSs[layerId];
+          m_extraRPSs[layerId]++;
+        }
+        numRefs=0;
+        for(Int i = 0; i< m_EhGOPList[layerId][curGOP].m_numRefPics; i++) 
+        {
+          Int absPOC = curPOC+m_EhGOPList[layerId][curGOP].m_referencePics[i];
+          if(absPOC >= 0) 
+          {
+            refList[numRefs]=absPOC;
+            numRefs++;
+          }
+        }
+        refList[numRefs]=curPOC;
+        numRefs++;
+      }
+      checkGOP++;
+    }
+    xConfirmPara(errorGOP,"Invalid GOP structure given");
   }
 #endif 
-
 
   m_maxTempLayer = 1;
@@ -2491,12 +2480,12 @@
 
 #if Q0108_TSA_STSA
-  for ( Int layer_index = 1; layer_index<m_numLayers; layer_index++)
-  {
-    m_EH_maxTempLayer[layer_index] = 1;
+  for ( Int layerId = 1; layerId < m_numLayers; layerId++)
+  {
+    m_EhMaxTempLayer[layerId] = 1;
     for(Int i=0; i<m_iGOPSize; i++) 
     {
-      if(m_EH_GOPList[layer_index][i].m_temporalId >= m_EH_maxTempLayer[layer_index] )
-      {
-        m_EH_maxTempLayer[layer_index] = m_EH_GOPList[layer_index][i].m_temporalId;
+      if(m_EhGOPList[layerId][i].m_temporalId >= m_EhMaxTempLayer[layerId] )
+      {
+        m_EhMaxTempLayer[layerId] = m_EhGOPList[layerId][i].m_temporalId;
       }
       xConfirmPara(m_GOPList[i].m_sliceType!='B'&&m_GOPList[i].m_sliceType!='P'&&m_GOPList[i].m_sliceType!='I', "Slice type must be equal to B or P or I");
Index: /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 805)
+++ /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 806)
@@ -129,10 +129,10 @@
   Int       m_extraRPSs;                                      ///< extra RPSs added to handle CRA
 #else
-  Int       m_extraRPSs[MAX_LAYERS];                                      ///< extra RPSs added to handle CRA
+  Int       m_extraRPSs[MAX_LAYERS];                          ///< extra RPSs added to handle CRA
 #endif
 
   GOPEntry  m_GOPList[MAX_GOP];                               ///< the coding structure entries from the config file
 #if Q0108_TSA_STSA
-  GOPEntry  m_EH_GOPList[MAX_LAYERS][MAX_GOP];                ///< the enhancement layer coding structure entries from the config file
+  GOPEntry  m_EhGOPList[MAX_LAYERS][MAX_GOP];                 ///< the enhancement layer coding structure entries from the config file
   Int       m_inheritCodingStruct[MAX_LAYERS];
 #endif
@@ -166,5 +166,5 @@
   Int       m_maxTempLayer;                                  ///< Max temporal layer
 #if Q0108_TSA_STSA
-  Int       m_EH_maxTempLayer[MAX_LAYERS];                                  ///< Max temporal layer
+  Int       m_EhMaxTempLayer[MAX_LAYERS];                    ///< Max temporal layer
 #endif
 
Index: /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 805)
+++ /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 806)
@@ -241,8 +241,5 @@
     m_acTEncTop[layer].setGOPSize                      ( m_iGOPSize );
 #if Q0108_TSA_STSA
-    if(layer == 0)
-      m_acTEncTop[layer].setGopList                      ( m_GOPList );
-    else
-      m_acTEncTop[layer].setGopList                      ( m_EH_GOPList[layer] );
+    m_acTEncTop[layer].setGopList                      ( layer ? m_EhGOPList[layer] : m_GOPList );
 #else
     m_acTEncTop[layer].setGopList                      ( m_GOPList );
@@ -275,5 +272,5 @@
     else
     {
-      m_acTEncTop[layer].setMaxTempLayer                 ( m_EH_maxTempLayer[layer] );
+      m_acTEncTop[layer].setMaxTempLayer                 ( m_EhMaxTempLayer[layer] );
     }
 #endif
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h	(revision 805)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h	(revision 806)
@@ -41,7 +41,5 @@
 #define SVC_EXTENSION                    1
 
-#define Q0108_TSA_STSA                   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)]
+#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                       8      ///< max number of layers the codec is supposed to handle
@@ -50,4 +48,5 @@
 #define O0137_MAX_LAYERID                1      ///< JCTVC-O0137, JCTVC-O0200, JCTVC-O0223: restrict nuh_layer_id and vps_max_layers_minus1
 
+#define Q0108_TSA_STSA                   1      ///< JCTVC-Q0108, Remove cross-layer alignment constraints of TSA and STSA pictures, enable to have different prediction structures in different layers
 #define Q0177_SPS_TEMP_NESTING_FIX       1      ///< JCTVC-Q0177; Fix the inference value of sps_temporal_id_nesting_flag when it is not present
 #define Q0177_EOS_CHECKS                 1      ///< JCTVC-Q0177; Put checks on handling EOS
@@ -55,5 +54,5 @@
 #define Q0146_SSH_EXT_DATA_BIT           1      ///< JCTVC-Q0146; Bug-fix -- the SSH_EXT_DATA_BIT can have any value -- not required to be 1
 
-#define Q0200_CONFORMANCE_BL_SIZE        1       ///< JCTVC-Q0200; use conformance picture size in re-sampling processs
+#define Q0200_CONFORMANCE_BL_SIZE        1      ///< JCTVC-Q0200; use conformance picture size in re-sampling processs
 #define P0312_VERT_PHASE_ADJ             1      ///< JCTVC-P0312: vertical phase adjustment in re-sampling process (BoG report)
 #if P0312_VERT_PHASE_ADJ
@@ -105,6 +104,6 @@
 #define POC_RESET_IDC_ENCODER            1      ///< JCTVC-P0041: Include support of enabling POC reset at the encoder
 #define POC_RESET_IDC_DECODER            1      ///< JCTVC-P0041: Include support of enabling POC reset at the decoder
-#define ALIGN_IRAP_BUGFIX               1
-#define UNAVAILABLE_PIC_BUGFIX          1
+#define ALIGN_IRAP_BUGFIX                1
+#define UNAVAILABLE_PIC_BUGFIX           1
 #endif
 #define POC_MSB_VAL_PRESENT_FLAG_SEM     1      ///< JCTVC-Q0146: Inference of poc_msb_val_present_flag
@@ -169,9 +168,9 @@
 #define Q0060_MAX_TID_REF_EQUAL_TO_ZERO  1      ///< JCTVC-Q0060 handling the case max_tid_il_ref_pics_plus1 is equal to 0.
 
-#define O0223_PICTURE_TYPES_ALIGN_FLAG   1  ///< a flag to indicatate whether picture types are aligned across layers.
+#define O0223_PICTURE_TYPES_ALIGN_FLAG   1      ///< a flag to indicatate whether picture types are aligned across layers.
 
 #define P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG   1  ///< a flag to indicatate whether picture types for IRAP are IDR across layers.
 
-#define IRAP_ALIGN_FLAG_IN_VPS_VUI       1       ///< Move IRAP align flag to VPS VUI 
+#define IRAP_ALIGN_FLAG_IN_VPS_VUI       1      ///< Move IRAP align flag to VPS VUI 
 
 #define VIEW_ID_RELATED_SIGNALING        1      ///< Introduce syntax elements view_id and view_id_val
Index: /branches/SHM-6-dev/source/Lib/TLibDecoder/NALread.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibDecoder/NALread.cpp	(revision 805)
+++ /branches/SHM-6-dev/source/Lib/TLibDecoder/NALread.cpp	(revision 806)
@@ -114,5 +114,5 @@
   if ( nalu.m_temporalId )
   {
-#if    !Q0108_TSA_STSA
+#if !Q0108_TSA_STSA
     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_LP
          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_RADL
@@ -139,5 +139,5 @@
   else
   {
-#if    !Q0108_TSA_STSA
+#if !Q0108_TSA_STSA
     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R
          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 805)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 806)
@@ -610,5 +610,5 @@
   TComOutputBitstream* pcSubstreamsOut = NULL;
 #if Q0108_TSA_STSA
-  Int b_TSTA_flag = 0;
+  Int flagTSTA = 0;
 #endif
 
@@ -1559,5 +1559,5 @@
       }
     }
-#if    Q0108_TSA_STSA
+#if Q0108_TSA_STSA
     else if( ( pcSlice->getTLayer() == 0 && pcSlice->getLayerId() > 0)    // only for enhancement layer and with temporal layer 0
        && !( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N     
@@ -1572,5 +1572,5 @@
     {
         Bool isSTSA=true;
-        for(Int ii=iGOPid+1;(ii<m_pcCfg->getGOPSize() && isSTSA==true);ii++)
+        for(Int ii=iGOPid+1; ii < m_pcCfg->getGOPSize() && isSTSA; ii++)
         {
           Int lTid= m_pcCfg->getGOPEntry(ii).m_temporalId;
@@ -1578,5 +1578,5 @@
           {
             TComReferencePictureSet* nRPS = pcSlice->getSPS()->getRPSList()->getReferencePictureSet(ii);
-            for(Int jj=0;jj<nRPS->getNumberOfPictures();jj++)
+            for(Int jj=0; jj<nRPS->getNumberOfPictures(); jj++)
             {
               if(nRPS->getUsed(jj)) 
@@ -1584,13 +1584,15 @@
                 Int tPoc=m_pcCfg->getGOPEntry(ii).m_POC+nRPS->getDeltaPOC(jj);
                 Int kk=0;
-                for(kk=0;kk<m_pcCfg->getGOPSize();kk++)
+                for(kk=0; kk<m_pcCfg->getGOPSize(); kk++)
                 {
                   if(m_pcCfg->getGOPEntry(kk).m_POC==tPoc)
+                  {
                     break;
+                  }
                 }
                 Int tTid=m_pcCfg->getGOPEntry(kk).m_temporalId;
                 if(tTid >= pcSlice->getTLayer())
                 {
-                  isSTSA=false;
+                  isSTSA = false;
                   break;
                 }
@@ -1661,10 +1663,10 @@
           {
             pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N);
-            b_TSTA_flag = 1;
+            flagTSTA = 1;
           }
           else
           {
             pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R);
-            b_TSTA_flag = 1;
+            flagTSTA = 1;
           }
 #endif
@@ -1684,5 +1686,5 @@
     {
 #if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
-      if ( pocCurr > 0          && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
+      if ( pocCurr > 0 && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
 #else
       if (pcSlice->getPOC()>0  && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
@@ -1692,6 +1694,6 @@
         pcSlice->setInterLayerPredEnabledFlag(0);
       }
-#if   Q0108_TSA_STSA
-     if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) || b_TSTA_flag == 1)
+#if Q0108_TSA_STSA
+     if( ( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) || flagTSTA == 1 )
 #else
      if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
