Index: trunk/SHM.xcodeproj/project.pbxproj
===================================================================
--- trunk/SHM.xcodeproj/project.pbxproj	(revision 752)
+++ trunk/SHM.xcodeproj/project.pbxproj	(revision 815)
@@ -131,4 +131,8 @@
 		71AD603A11EBC28D00F5F1FE /* libTLibEncoder.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6767961911AD626F00421804 /* libTLibEncoder.a */; };
 		71AD603B11EBC29600F5F1FE /* libTLibVideoIO.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6767964B11AD629200421804 /* libTLibVideoIO.a */; };
+		C3D5A69A190AD6DA005E0EBE /* TCom3DAsymLUT.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C3D5A698190AD6DA005E0EBE /* TCom3DAsymLUT.cpp */; };
+		C3D5A69B190AD6DA005E0EBE /* TCom3DAsymLUT.h in Headers */ = {isa = PBXBuildFile; fileRef = C3D5A699190AD6DA005E0EBE /* TCom3DAsymLUT.h */; };
+		C3D5A69E190AD6F8005E0EBE /* TEnc3DAsymLUT.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C3D5A69C190AD6F8005E0EBE /* TEnc3DAsymLUT.cpp */; };
+		C3D5A69F190AD6F8005E0EBE /* TEnc3DAsymLUT.h in Headers */ = {isa = PBXBuildFile; fileRef = C3D5A69D190AD6F8005E0EBE /* TEnc3DAsymLUT.h */; };
 		DB7795C213F1226500C92469 /* TEncPic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DB7795BE13F1226500C92469 /* TEncPic.cpp */; };
 		DB7795C313F1226500C92469 /* TEncPic.h in Headers */ = {isa = PBXBuildFile; fileRef = DB7795BF13F1226500C92469 /* TEncPic.h */; };
@@ -340,4 +344,8 @@
 		7184647513FAE75800747BF9 /* program_options_lite.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = program_options_lite.cpp; path = source/Lib/TAppCommon/program_options_lite.cpp; sourceTree = "<group>"; };
 		7184647613FAE75800747BF9 /* program_options_lite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = program_options_lite.h; path = source/Lib/TAppCommon/program_options_lite.h; sourceTree = "<group>"; };
+		C3D5A698190AD6DA005E0EBE /* TCom3DAsymLUT.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TCom3DAsymLUT.cpp; path = source/Lib/TLibCommon/TCom3DAsymLUT.cpp; sourceTree = "<group>"; };
+		C3D5A699190AD6DA005E0EBE /* TCom3DAsymLUT.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TCom3DAsymLUT.h; path = source/Lib/TLibCommon/TCom3DAsymLUT.h; sourceTree = "<group>"; };
+		C3D5A69C190AD6F8005E0EBE /* TEnc3DAsymLUT.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TEnc3DAsymLUT.cpp; path = source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp; sourceTree = "<group>"; };
+		C3D5A69D190AD6F8005E0EBE /* TEnc3DAsymLUT.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TEnc3DAsymLUT.h; path = source/Lib/TLibEncoder/TEnc3DAsymLUT.h; sourceTree = "<group>"; };
 		DB7795BE13F1226500C92469 /* TEncPic.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TEncPic.cpp; path = source/Lib/TLibEncoder/TEncPic.cpp; sourceTree = "<group>"; };
 		DB7795BF13F1226500C92469 /* TEncPic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TEncPic.h; path = source/Lib/TLibEncoder/TEncPic.h; sourceTree = "<group>"; };
@@ -464,4 +472,6 @@
 			isa = PBXGroup;
 			children = (
+				C3D5A698190AD6DA005E0EBE /* TCom3DAsymLUT.cpp */,
+				C3D5A699190AD6DA005E0EBE /* TCom3DAsymLUT.h */,
 				6B635E7516E5EAB60057B313 /* TComUpsampleFilter.h */,
 				6B635E7616E5EAB60057B313 /* TComUpsampleFilter.cpp */,
@@ -563,4 +573,6 @@
 			isa = PBXGroup;
 			children = (
+				C3D5A69C190AD6F8005E0EBE /* TEnc3DAsymLUT.cpp */,
+				C3D5A69D190AD6F8005E0EBE /* TEnc3DAsymLUT.h */,
 				71206CD916066EDD00A354E7 /* SyntaxElementWriter.cpp */,
 				71206CDA16066EDD00A354E7 /* SyntaxElementWriter.h */,
@@ -670,4 +682,5 @@
 				676795D211AD61FC00421804 /* TComList.h in Headers */,
 				676795D411AD61FC00421804 /* TComLoopFilter.h in Headers */,
+				C3D5A69B190AD6DA005E0EBE /* TCom3DAsymLUT.h in Headers */,
 				676795D611AD61FC00421804 /* TComMotionInfo.h in Headers */,
 				676795D911AD61FC00421804 /* TComPattern.h in Headers */,
@@ -685,4 +698,5 @@
 				671E0D4C11B6AD8C00F3747B /* ContextModel3DBuffer.h in Headers */,
 				671E0D4F11B6AD8C00F3747B /* TComBitCounter.h in Headers */,
+				C3D5A69F190AD6F8005E0EBE /* TEnc3DAsymLUT.h in Headers */,
 				671E0D5111B6AD8C00F3747B /* TComCABACTables.h in Headers */,
 				671E0D5211B6AD8C00F3747B /* TComMv.h in Headers */,
@@ -932,4 +946,5 @@
 			buildActionMask = 2147483647;
 			files = (
+				C3D5A69E190AD6F8005E0EBE /* TEnc3DAsymLUT.cpp in Sources */,
 				676795CE11AD61FC00421804 /* TComBitStream.cpp in Sources */,
 				676795D011AD61FC00421804 /* TComDataCU.cpp in Sources */,
@@ -939,4 +954,5 @@
 				676795DA11AD61FC00421804 /* TComPic.cpp in Sources */,
 				676795DC11AD61FC00421804 /* TComPicSym.cpp in Sources */,
+				C3D5A69A190AD6DA005E0EBE /* TCom3DAsymLUT.cpp in Sources */,
 				676795DE11AD61FC00421804 /* TComPicYuv.cpp in Sources */,
 				676795E211AD61FC00421804 /* TComPrediction.cpp in Sources */,
@@ -1098,5 +1114,5 @@
 				HEADER_SEARCH_PATHS = source/Lib;
 				ONLY_ACTIVE_ARCH = YES;
-				SDKROOT = macosx;
+				SDKROOT = macosx10.8;
 			};
 			name = Debug;
@@ -1112,5 +1128,5 @@
 				GCC_WARN_UNUSED_VARIABLE = YES;
 				HEADER_SEARCH_PATHS = source/Lib;
-				SDKROOT = macosx;
+				SDKROOT = macosx10.8;
 			};
 			name = Release;
Index: trunk/cfg/cfg_extension/Q0108_Extension.cfg
===================================================================
--- trunk/cfg/cfg_extension/Q0108_Extension.cfg	(revision 815)
+++ trunk/cfg/cfg_extension/Q0108_Extension.cfg	(revision 815)
@@ -0,0 +1,26 @@
+InheritCodingStruct1              : -1
+MaxTidIlRefPicsPlus10         : 4           # max_tid_il_ref_pics_plus1 for layer0
+
+#Layer0 prediction structure
+
+Frame1:  B    8   1        0.442    0            0              0           4                2         -8 -9                  0
+Frame2:  B    4   2        0.3536   0            0              1           4                3         -4 -5  4               0
+Frame3:  B    2   3        0.3536   0            0              2           4                4         -2 -3  2 6             0
+Frame4:  B    1   4        0.68     0            0              3           4                5         -1 -2  1 3 7           0
+Frame5:  B    3   4        0.68     0            0              3           4                4         -1 -2  1 5             0
+Frame6:  B    6   3        0.3536   0            0              2           4                4         -2 -3 -4 2             0
+Frame7:  B    5   4        0.68     0            0              3           4                4         -1 -2  1 3             0
+Frame8:  B    7   4        0.68     0            0              3           4                3         -1 -2  1               0
+
+
+#Layer1 prediction structure
+
+Layer1Frame1:  B    8   1        0.442    0            0              0           4                1         -8                     0
+Layer1Frame2:  B    4   2        0.3536   0            0              1           4                2         -4  4                  0
+Layer1Frame3:  B    2   3        0.3536   0            0              2           4                3         -2  2  6               0  
+Layer1Frame4:  B    1   4        0.68     0            0              3           4                4         -1  1  3 7             0 
+Layer1Frame5:  B    3   4        0.68     0            0              3           4                3         -1  1  5               0
+Layer1Frame6:  B    6   3        0.3536   0            0              2           4                3         -2 -4  2               0
+Layer1Frame7:  B    5   4        0.68     0            0              3           4                3         -1  1  3               0
+Layer1Frame8:  B    7   4        0.68     0            0              3           4                2         -1  1                  0
+
Index: trunk/cfg/layers.cfg
===================================================================
--- trunk/cfg/layers.cfg	(revision 752)
+++ trunk/cfg/layers.cfg	(revision 815)
@@ -41,2 +41,9 @@
 InitialQP1                    : 0           # Rate control: initial QP for layer 1
 RCForceIntraQP1               : 0           # Rate control: force intra QP to be equal to initial QP for layer 1
+
+
+NumLayerSets                  : 1
+NumLayerInIdList0             : 2
+LayerSetLayerIdList0          : 0 1
+
+NumAddLayerSets               : 0
Index: trunk/source/App/TAppDecoder/TAppDecCfg.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 752)
+++ trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 815)
@@ -146,4 +146,5 @@
   m_tgtLayerId = nLayerNum - 1;
   assert( m_tgtLayerId >= 0 );
+  assert( m_tgtLayerId < MAX_LAYERS );
 #if O0137_MAX_LAYERID
   assert( m_tgtLayerId < MAX_NUM_LAYER_IDS );
Index: trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 752)
+++ trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 815)
@@ -191,5 +191,4 @@
     InputNALUnit nalu;
     byteStreamNALUnit(bytestream, nalUnit, stats);
-
     // call actual decoding function
     Bool bNewPicture = false;
@@ -215,5 +214,9 @@
       {
         bNewPicture = m_acTDecTop[nalu.m_layerId].decode(nalu, m_iSkipFrame, m_aiPOCLastDisplay[nalu.m_layerId], curLayerId, bNewPOC);
+#if POC_RESET_IDC_DECODER
+        if ( (bNewPicture && m_acTDecTop[nalu.m_layerId].getParseIdc() == 3) || (m_acTDecTop[nalu.m_layerId].getParseIdc() == 0) )
+#else
         if (bNewPicture)
+#endif
         {
           bitstreamFile.clear();
@@ -225,8 +228,22 @@
           bytestream.reset();
         }
-      }
-    }
-
+#if POC_RESET_IDC_DECODER
+        else if(m_acTDecTop[nalu.m_layerId].getParseIdc() == 1) 
+        {
+          bitstreamFile.clear();
+          // This is before third parse of the NAL unit, and 
+          // location points to correct beginning of the NALU
+          bitstreamFile.seekg(location);
+          bytestream.reset();
+        }
+#endif
+      }
+    }
+
+#if POC_RESET_IDC_DECODER
+    if ((bNewPicture && m_acTDecTop[nalu.m_layerId].getParseIdc() == 3) || (m_acTDecTop[nalu.m_layerId].getParseIdc() == 0) || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS)
+#else
     if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS)
+#endif
     {
 #if O0194_DIFFERENT_BITDEPTH_EL_BL
@@ -245,4 +262,11 @@
     }
 
+#if POC_RESET_IDC_DECODER
+    if( bNewPicture && m_acTDecTop[nalu.m_layerId].getParseIdc() == 0 )
+    {
+      outputAllPictures( nalu.m_layerId, true );
+    }
+#endif
+
     if( pcListPic )
     {
@@ -269,5 +293,11 @@
         flushAllPictures( nalu.m_layerId, outputPicturesFlag );       
       }
+
+#if POC_RESET_IDC_DECODER
+      if( bNewPicture && m_acTDecTop[nalu.m_layerId].getParseIdc() != 0 )
+      // New picture, slice header parsed but picture not decoded
+#else
       if( bNewPicture ) // New picture, slice header parsed but picture not decoded
+#endif
       {
 #if NO_OUTPUT_OF_PRIOR_PICS
@@ -1235,5 +1265,9 @@
 
     // Find the status of the DPB
+#if POC_RESET_IDC_DECODER
+    xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus, false);
+#else
     xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus);
+#endif
 
     while( dpbStatus.m_numAUsNotDisplayed )
@@ -1282,6 +1316,8 @@
   // Find DPB-information from the VPS
   DpbStatus maxDpbLimit;
+#if RESOLUTION_BASED_DPB
   Int targetLsIdx, subDpbIdx;
   TComVPS *vps = findDpbParametersFromVps(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, maxDpbLimit);
+
   if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
   {
@@ -1294,4 +1330,8 @@
     subDpbIdx   = vps->getSubDpbAssigned( targetLsIdx, layerIdx );
   }
+#else
+  Int subDpbIdx = getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 ? 0 : layerIdx;
+  findDpbParametersFromVps(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, maxDpbLimit);
+#endif
   // Assume that listOfPocs is sorted in increasing order - if not have to sort it.
   while( ifInvokeBumpingBeforeDecoding(dpbStatus, maxDpbLimit, layerIdx, subDpbIdx) )
@@ -1437,6 +1477,10 @@
     for(Int i = 0; i < vps->getNumLayersInIdList( targetLsIdx ); i++)
     {
+#if RESOUTION_BASED_DPB
       maxDpbLimit.m_numPicsInLayer[i] = vps->getMaxVpsLayerDecPicBuffMinus1( targetOutputLsIdx, i, highestTId ) + 1;
       maxDpbLimit.m_numPicsInSubDpb[vps->getSubDpbAssigned( targetLsIdx, i )] = vps->getMaxVpsDecPicBufferingMinus1( targetOutputLsIdx, vps->getSubDpbAssigned( targetLsIdx, i ), highestTId) + 1;
+#else
+      maxDpbLimit.m_numPicsInSubDpb[i] = vps->getMaxVpsDecPicBufferingMinus1( targetOutputLsIdx, i, highestTId) + 1;
+#endif
     }
     // -------------------------------------
@@ -1472,6 +1516,8 @@
   retVal |= ( dpbStatus.m_numPicsInSubDpb[subDpbIdx] >= dpbLimit.m_numPicsInSubDpb[subDpbIdx] );
   
+#if RESOLUTION_BASED_DPB
   // Number of pictures in each layer
   retVal |= ( dpbStatus.m_numPicsInLayer[layerIdx] >= dpbLimit.m_numPicsInLayer[layerIdx]);
+#endif
 
   return retVal;
@@ -1492,4 +1538,7 @@
                             , std::vector<Int> *listOfPocsPositionInEachLayer
                             , DpbStatus &dpbStatus
+#if POC_RESET_IDC_DECODER
+                            , Bool notOutputCurrAu
+#endif
                             )
 {
@@ -1516,20 +1565,26 @@
           vps = pic->getSlice(0)->getVPS();
         }
-
-        std::vector<Int>::iterator it;
-        if( pic->getOutputMark() ) // && pic->getPOC() > m_aiPOCLastDisplay[i])
-        {
-          it = find( listOfPocs.begin(), listOfPocs.end(), pic->getPOC() ); // Check if already included
-          if( it == listOfPocs.end() )  // New POC value - i.e. new AU - add to the list
+#if POC_RESET_IDC_DECODER
+        if( !(pic->isCurrAu() && notOutputCurrAu ) )
+        {
+#endif
+          std::vector<Int>::iterator it;
+          if( pic->getOutputMark() ) // && pic->getPOC() > m_aiPOCLastDisplay[i])
           {
-            listOfPocs.push_back( pic->getPOC() );
+            it = find( listOfPocs.begin(), listOfPocs.end(), pic->getPOC() ); // Check if already included
+            if( it == listOfPocs.end() )  // New POC value - i.e. new AU - add to the list
+            {
+              listOfPocs.push_back( pic->getPOC() );
+            }
+            listOfPocsInEachLayer         [i].push_back( pic->getPOC()    );    // POC to be output in each layer
+            listOfPocsPositionInEachLayer [i].push_back( picPositionInList  );  // For ease of access
           }
-          listOfPocsInEachLayer         [i].push_back( pic->getPOC()    );    // POC to be output in each layer
-          listOfPocsPositionInEachLayer [i].push_back( picPositionInList  );  // For ease of access
-        }
-        if( pic->getSlice(0)->isReferenced() || pic->getOutputMark() )
-        {
-          dpbStatus.m_numPicsInLayer[i]++;  // Count pictures that are "used for reference" or "needed for output"
-        }
+          if( pic->getSlice(0)->isReferenced() || pic->getOutputMark() )
+          {
+            dpbStatus.m_numPicsInLayer[i]++;  // Count pictures that are "used for reference" or "needed for output"
+          }
+#if POC_RESET_IDC_DECODER
+        }
+#endif
       }
       iterPic++;
@@ -1550,10 +1605,35 @@
   {
     dpbStatus.m_numPicsNotDisplayedInLayer[i] = listOfPocsInEachLayer[i].size();
+#if RESOLUTION_BASED_DPB
     dpbStatus.m_numPicsInSubDpb[vps->getSubDpbAssigned(targetLsIdx,i)] += dpbStatus.m_numPicsInLayer[i];
+#else
+    dpbStatus.m_numPicsInSubDpb[i] += dpbStatus.m_numPicsInLayer[i];
+#endif
   }
   assert( dpbStatus.m_numAUsNotDisplayed != -1 );
-
-
 }  
+
+#if POC_RESET_IDC_DECODER
+Void TAppDecTop::outputAllPictures(Int layerId, Bool notOutputCurrPic)
+{
+  { // All pictures in the DPB in that layer are to be output; this means other pictures would also be output
+    std::vector<Int>  listOfPocs;
+    std::vector<Int>  listOfPocsInEachLayer[MAX_LAYERS];
+    std::vector<Int>  listOfPocsPositionInEachLayer[MAX_LAYERS];
+    DpbStatus dpbStatus;
+
+    // Find the status of the DPB
+    xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus, notOutputCurrPic);
+
+    if( listOfPocs.size() )
+    {
+      while( listOfPocsInEachLayer[layerId].size() )    // As long as there picture in the layer to be output
+      {
+        bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus );
+      }
+    }
+  }
+}
+#endif
 #endif
 //! \}
Index: trunk/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 752)
+++ trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 815)
@@ -107,8 +107,14 @@
 
   Void xOutputAndMarkPic( TComPic *pic, const Char *reconFile, const Int layerID, Int &pocLastDisplay, DpbStatus &dpbStatus);
+#if POC_RESET_IDC_DECODER
+  Void outputAllPictures(Int layerId, Bool notOutputCurrAu);
+#endif
   Void xFindDPBStatus( std::vector<Int> &listOfPocs
                             , std::vector<Int> *listOfPocsInEachLayer
                             , std::vector<Int> *listOfPocsPositionInEachLayer
                             , DpbStatus &dpbStatus
+#if POC_RESET_IDC_DECODER
+                            , Bool notOutputCurrAu = true
+#endif
                             );
 
Index: trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 752)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 815)
@@ -69,7 +69,5 @@
 , m_avcBaseLayerFlag(0)
 #endif
-#if N0120_MAX_TID_REF_CFG
 , m_maxTidRefPresentFlag(1)
-#endif 
 , m_pColumnWidth()
 , m_pRowHeight()
@@ -420,7 +418,5 @@
   Int*    cfg_OutputBitDepthC   [MAX_LAYERS];
 #endif
-#if N0120_MAX_TID_REF_CFG
   Int*    cfg_maxTidIlRefPicsPlus1[MAX_LAYERS]; 
-#endif 
   for(UInt layer = 0; layer < MAX_LAYERS; layer++)
   {
@@ -491,11 +487,24 @@
   cfg_OutputBitDepthC  [layer] = &m_acLayerCfg[layer].m_outputBitDepthC;
 #endif
-#if N0120_MAX_TID_REF_CFG
-    cfg_maxTidIlRefPicsPlus1[layer] = &m_acLayerCfg[layer].m_maxTidIlRefPicsPlus1; 
-#endif 
+  cfg_maxTidIlRefPicsPlus1[layer] = &m_acLayerCfg[layer].m_maxTidIlRefPicsPlus1; 
 #if AUXILIARY_PICTURES
     cfg_auxId[layer]                = &m_acLayerCfg[layer].m_auxId; 
 #endif
   }
+#if Q0078_ADD_LAYER_SETS
+  Int* cfg_numLayerInIdList[MAX_VPS_LAYER_SETS_PLUS1];
+  string cfg_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1];
+  string* cfg_layerSetLayerIdListPtr[MAX_VPS_LAYER_SETS_PLUS1];
+  Int* cfg_numHighestLayerIdx[MAX_VPS_LAYER_SETS_PLUS1];
+  string cfg_highestLayerIdx[MAX_VPS_LAYER_SETS_PLUS1];
+  string* cfg_highestLayerIdxPtr[MAX_VPS_LAYER_SETS_PLUS1];
+  for (UInt i = 0; i < MAX_VPS_LAYER_SETS_PLUS1; i++)
+  {
+    cfg_numLayerInIdList[i] = &m_numLayerInIdList[i];
+    cfg_layerSetLayerIdListPtr[i] = &cfg_layerSetLayerIdList[i];
+    cfg_highestLayerIdxPtr[i] = &cfg_highestLayerIdx[i];
+    cfg_numHighestLayerIdx[i] = &m_numHighestLayerIdx[i];
+  }
+#endif
 #if AVC_BASE
   string  cfg_BLInputFile;
@@ -519,4 +528,8 @@
   string cfg_codedPivotValue;
   string cfg_targetPivotValue;
+#if P0050_KNEE_FUNCTION_SEI
+  string cfg_kneeSEIInputKneePointValue;
+  string cfg_kneeSEIOutputKneePointValue;
+#endif
   po::Options opts;
   opts.addOptions()
@@ -548,4 +561,12 @@
 #endif
   ("NumLayers",               m_numLayers, 1, "Number of layers to code")
+#if Q0078_ADD_LAYER_SETS
+  ("NumLayerSets",            m_numLayerSets, 0, "Number of layer sets")
+  ("NumLayerInIdList%d",      cfg_numLayerInIdList, 0, MAX_VPS_LAYER_ID_PLUS1, "Number of layers in the set")
+  ("LayerSetLayerIdList%d",   cfg_layerSetLayerIdListPtr, string(""), MAX_VPS_LAYER_ID_PLUS1, "Layer IDs for the set")
+  ("NumAddLayerSets",         m_numAddLayerSets, 0, "Number of additional layer sets")
+  ("NumHighestLayerIdx%d",    cfg_numHighestLayerIdx, 0, MAX_VPS_LAYER_ID_PLUS1, "Number of highest layer idx")
+  ("HighestLayerIdx%d",       cfg_highestLayerIdxPtr, string(""), MAX_VPS_LAYER_ID_PLUS1, "Highest layer idx for an additional layer set")
+#endif
 #if AUXILIARY_PICTURES
   ("InputChromaFormat%d",     cfg_tmpInputChromaFormat,  420, MAX_LAYERS, "InputChromaFormatIDC for layer %d")
@@ -554,13 +575,8 @@
 #endif
   ("ConformanceMode%d",       cfg_conformanceMode,0, MAX_LAYERS, "Window conformance mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
-#if SCALABILITY_MASK_E0104
   ("ScalabilityMask1",        m_scalabilityMask[1], 0, "scalability_mask[1] (multiview)")
   ("ScalabilityMask2",        m_scalabilityMask[2], 1, "scalability_mask[2] (scalable)" )
 #if AUXILIARY_PICTURES
   ("ScalabilityMask3",        m_scalabilityMask[3], 0, "scalability_mask[3] (auxiliary pictures)" )
-#endif
-#else
-  ("ScalabilityMask0",        m_scalabilityMask[0], 0, "scalability_mask[0] (multiview)")
-  ("ScalabilityMask1",        m_scalabilityMask[1], 1, "scalability_mask[1] (scalable)" )
 #endif
   ("BitstreamFile,b",         cfg_BitstreamFile, string(""), "Bitstream output file name")
@@ -598,14 +614,10 @@
   ("OutputBitDepthC%d",     cfg_OutputBitDepthC,   0, MAX_LAYERS, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
 #endif
-#if N0120_MAX_TID_REF_CFG
   ("MaxTidRefPresentFlag", m_maxTidRefPresentFlag, true, "max_tid_ref_present_flag (0: not present, 1: present(default)) " )
   ("MaxTidIlRefPicsPlus1%d", cfg_maxTidIlRefPicsPlus1, 1, MAX_LAYERS, "allowed maximum temporal_id for inter-layer prediction")
-#endif
 #if O0223_PICTURE_TYPES_ALIGN_FLAG
   ("CrossLayerPictureTypeAlignFlag", m_crossLayerPictureTypeAlignFlag, true, "align picture type across layers" )  
 #endif
-#if N0147_IRAP_ALIGN_FLAG
   ("CrossLayerIrapAlignFlag", m_crossLayerIrapAlignFlag, true, "align IRAP across layers" )  
-#endif
 #if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
   ("CrossLayerAlignedIdrOnlyFlag", m_crossLayerAlignedIdrOnlyFlag, true, "only idr for IRAP across layers" )  
@@ -953,4 +965,21 @@
   ("SEISOPDescription",              m_SOPDescriptionSEIEnabled,              0, "Control generation of SOP description SEI messages")
   ("SEIScalableNesting",             m_scalableNestingSEIEnabled,              0, "Control generation of scalable nesting SEI messages")
+#if P0050_KNEE_FUNCTION_SEI
+  ("SEIKneeFunctionInfo",                 m_kneeSEIEnabled,               false, "Control generation of Knee function SEI messages")
+  ("SEIKneeFunctionId",                   m_kneeSEIId,                        0, "Specifies Id of Knee function SEI message for a given session")
+  ("SEIKneeFunctionCancelFlag",           m_kneeSEICancelFlag,            false, "Indicates that Knee function SEI message cancels the persistance or follows")
+  ("SEIKneeFunctionPersistenceFlag",      m_kneeSEIPersistenceFlag,        true, "Specifies the persistence of the Knee function SEI message")
+  ("SEIKneeFunctionMappingFlag",          m_kneeSEIMappingFlag,           false, "Specifies the mapping mode of the Knee function SEI message")
+  ("SEIKneeFunctionInputDrange",          m_kneeSEIInputDrange,            1000, "Specifies the peak luminance level for the input picture of Knee function SEI messages")
+  ("SEIKneeFunctionInputDispLuminance",   m_kneeSEIInputDispLuminance,      100, "Specifies the expected display brightness for the input picture of Knee function SEI messages")
+  ("SEIKneeFunctionOutputDrange",         m_kneeSEIOutputDrange,           4000, "Specifies the peak luminance level for the output picture of Knee function SEI messages")
+  ("SEIKneeFunctionOutputDispLuminance",  m_kneeSEIOutputDispLuminance,     800, "Specifies the expected display brightness for the output picture of Knee function SEI messages")
+  ("SEIKneeFunctionNumKneePointsMinus1",  m_kneeSEINumKneePointsMinus1,       2, "Specifies the number of knee points - 1")
+  ("SEIKneeFunctionInputKneePointValue",  cfg_kneeSEIInputKneePointValue,     string("600 800 900"), "Array of input knee point")
+  ("SEIKneeFunctionOutputKneePointValue", cfg_kneeSEIOutputKneePointValue,    string("100 250 450"), "Array of output knee point")
+#endif
+#if Q0189_TMVP_CONSTRAINTS
+  ("SEITemporalMotionVectorPredictionConstraints",             m_TMVPConstraintsSEIEnabled,              0, "Control generation of TMVP constrants SEI message")
+#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   ("AdaptiveResolutionChange",     m_adaptiveResolutionChange, 0, "Adaptive resolution change frame number. Should coincide with EL RAP picture. (0: disable)")
@@ -976,4 +1005,7 @@
   ("CGSLUTBit",     m_nCGSLUTBit , 12, "bit depth of CGS LUT")
 #endif
+#if Q0108_TSA_STSA
+  ("InheritCodingStruct%d",m_inheritCodingStruct, 0, MAX_LAYERS, "Predicts the GOP structure of one layer for another layer")
+#endif
   ;
   
@@ -983,6 +1015,39 @@
     opts.addOptions()(cOSS.str(), m_GOPList[i-1], GOPEntry());
   }
+
+#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_EhGOPList[i][j-1], GOPEntry());
+    }
+  }
+#endif 
+
   po::setDefaults(opts);
   const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
+
+#if Q0108_TSA_STSA
+  for (Int i=1; i<MAX_LAYERS; i++)
+  {
+    if(m_inheritCodingStruct[i] == 0)
+    {
+      for(Int j=1; j<MAX_GOP+1; j++)
+      { 
+        m_EhGOPList[i][j-1] = m_GOPList[j-1];
+      }
+    }
+    else if( m_inheritCodingStruct[i] > 0)
+    {
+      for(Int j=1; j<MAX_GOP+1; j++)
+      {
+        m_EhGOPList[i][j-1] = m_EhGOPList[m_inheritCodingStruct[i]][j-1];
+      }
+    }
+  }
+#endif 
 
   if(m_isField)
@@ -1309,4 +1374,46 @@
     {
       m_acLayerCfg[layer].m_predLayerIds = NULL;
+    }
+  }
+#endif
+#if Q0078_ADD_LAYER_SETS
+  for (Int layerSet = 0; layerSet < m_numLayerSets; layerSet++)
+  {
+    if (m_numLayerInIdList[layerSet] > 0)
+    {
+      Char* layerSetLayerIdListDup = cfg_layerSetLayerIdList[layerSet].empty() ? NULL : strdup(cfg_layerSetLayerIdList[layerSet].c_str());
+      Int  i = 0;
+      char *layerId = strtok(layerSetLayerIdListDup, " ,-");
+      while (layerId != NULL)
+      {
+        if (i >= m_numLayerInIdList[layerSet])
+        {
+          printf("NumLayerInIdList%d: The number of layers in the set is larger than the allowed number of layers.\n", layerSet);
+          exit(EXIT_FAILURE);
+        }
+        m_layerSetLayerIdList[layerSet][i] = atoi(layerId);
+        layerId = strtok(NULL, " ,-");
+        i++;
+      }
+    }
+  }
+  for (Int addLayerSet = 0; addLayerSet < m_numAddLayerSets; addLayerSet++)
+  {
+    if (m_numHighestLayerIdx[addLayerSet] > 0)
+    {
+      Char* highestLayrIdxListDup = cfg_highestLayerIdx[addLayerSet].empty() ? NULL : strdup(cfg_highestLayerIdx[addLayerSet].c_str());
+      Int  i = 0;
+      char *layerIdx = strtok(highestLayrIdxListDup, " ,-");
+      while (layerIdx != NULL)
+      {
+        if (i >= m_numLayerInIdList[addLayerSet])
+        {
+          printf("NumLayerInIdList%d: The number of layer idx's in the highest layer idx list is larger than the allowed number of idx's.\n", addLayerSet);
+          exit(EXIT_FAILURE);
+        }
+        m_highestLayerIdx[addLayerSet][i] = atoi(layerIdx);
+        layerIdx = strtok(NULL, " ,-");
+        i++;
+      }
     }
   }
@@ -1495,4 +1602,30 @@
     }
   }
+#if P0050_KNEE_FUNCTION_SEI
+  if( m_kneeSEIEnabled && !m_kneeSEICancelFlag )
+  {
+    Char* pcInputKneePointValue  = cfg_kneeSEIInputKneePointValue.empty()  ? NULL : strdup(cfg_kneeSEIInputKneePointValue.c_str());
+    Char* pcOutputKneePointValue = cfg_kneeSEIOutputKneePointValue.empty() ? NULL : strdup(cfg_kneeSEIOutputKneePointValue.c_str());
+    assert ( m_kneeSEINumKneePointsMinus1 >= 0 && m_kneeSEINumKneePointsMinus1 < 999 );
+    m_kneeSEIInputKneePoint = new Int[m_kneeSEINumKneePointsMinus1+1];
+    m_kneeSEIOutputKneePoint = new Int[m_kneeSEINumKneePointsMinus1+1];
+    char *InputVal = strtok(pcInputKneePointValue, " .,");
+    Int i=0;
+    while( InputVal && i<(m_kneeSEINumKneePointsMinus1+1) )
+    {
+      m_kneeSEIInputKneePoint[i] = (UInt) atoi( InputVal );
+      InputVal = strtok(NULL, " .,");
+      i++;
+    }
+    char *OutputVal = strtok(pcOutputKneePointValue, " .,");
+    i=0;
+    while( OutputVal && i<(m_kneeSEINumKneePointsMinus1+1) )
+    {
+      m_kneeSEIOutputKneePoint[i] = (UInt) atoi( OutputVal );
+      OutputVal = strtok(NULL, " .,");
+      i++;
+    }
+  }
+#endif
 
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
@@ -1742,8 +1875,41 @@
    * This permits the ability to omit a GOP structure specification */
 #if SVC_EXTENSION
+#if Q0108_TSA_STSA
+  if( m_acLayerCfg[0].m_iIntraPeriod == 1 && m_GOPList[0].m_POC == -1 )
+  {
+    m_GOPList[0] = GOPEntry();
+    m_GOPList[0].m_QPFactor = 1;
+    m_GOPList[0].m_betaOffsetDiv2 = 0;
+    m_GOPList[0].m_tcOffsetDiv2 = 0;
+    m_GOPList[0].m_POC = 1;
+    m_GOPList[0].m_numRefPicsActive = 4;
+  }
+
   for(UInt layer = 0; layer < MAX_LAYERS; layer++)
   {
+    if (m_acLayerCfg[layer].m_iIntraPeriod == 1 && m_EhGOPList[layer][0].m_POC == -1) {
+      m_EhGOPList[layer][0] = GOPEntry();
+      m_EhGOPList[layer][0].m_QPFactor = 1;
+      m_EhGOPList[layer][0].m_betaOffsetDiv2 = 0;
+      m_EhGOPList[layer][0].m_tcOffsetDiv2 = 0;
+      m_EhGOPList[layer][0].m_POC = 1;
+      m_EhGOPList[layer][0].m_numRefPicsActive = 4;
+    }
+  }
+#else
+  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();
+      m_GOPList[0].m_QPFactor = 1;
+      m_GOPList[0].m_betaOffsetDiv2 = 0;
+      m_GOPList[0].m_tcOffsetDiv2 = 0;
+      m_GOPList[0].m_POC = 1;
+      m_GOPList[0].m_numRefPicsActive = 4;
+    }
+  }
+#endif
+#else
   if (m_iIntraPeriod == 1 && m_GOPList[0].m_POC == -1) {
     m_GOPList[0] = GOPEntry();
@@ -1754,8 +1920,5 @@
     m_GOPList[0].m_numRefPicsActive = 4;
   }
-#if SVC_EXTENSION
-  }
-#endif
-  
+#endif
 
   Bool verifiedGOP=false;
@@ -1790,5 +1953,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
@@ -1827,5 +1989,9 @@
 #endif
 
-  m_extraRPSs=0;
+#if !Q0108_TSA_STSA
+   m_extraRPSs = 0;                                      
+#else
+  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.
   while(!verifiedGOP&&!errorGOP) 
@@ -1893,5 +2059,9 @@
       {
         //create a new GOPEntry for this frame containing all the reference pictures that were available (POC > 0)
+#if !Q0108_TSA_STSA
         m_GOPList[m_iGOPSize+m_extraRPSs]=m_GOPList[curGOP];
+#else
+        m_GOPList[m_iGOPSize+m_extraRPSs[0]]=m_GOPList[curGOP];
+#endif
         Int newRefs=0;
         for(Int i = 0; i< m_GOPList[curGOP].m_numRefPics; i++) 
@@ -1900,6 +2070,11 @@
           if(absPOC>=0)
           {
+#if !Q0108_TSA_STSA
             m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[newRefs]=m_GOPList[curGOP].m_referencePics[i];
             m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[newRefs]=m_GOPList[curGOP].m_usedByCurrPic[i];
+#else
+            m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_referencePics[newRefs]=m_GOPList[curGOP].m_referencePics[i];
+            m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_usedByCurrPic[newRefs]=m_GOPList[curGOP].m_usedByCurrPic[i];
+#endif
             newRefs++;
           }
@@ -1924,5 +2099,9 @@
             for(Int i=0; i<newRefs; i++) 
             {
+#if !Q0108_TSA_STSA
               if(m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[i]==offPOC-curPOC)
+#else
+              if(m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_referencePics[i]==offPOC-curPOC)
+#endif
               {
                 newRef=false;
@@ -1939,5 +2118,9 @@
               for(Int j=0; j<newRefs; j++)
               {
+#if !Q0108_TSA_STSA
                 if(m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]<offPOC-curPOC||m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]>0)
+#else
+                if(m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_referencePics[j]<offPOC-curPOC||m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_referencePics[j]>0)
+#endif
                 {
                   insertPoint = j;
@@ -1949,8 +2132,16 @@
               for(Int j=insertPoint; j<newRefs+1; j++)
               {
+#if !Q0108_TSA_STSA
                 Int newPrev = m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j];
                 Int newUsed = m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j];
                 m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]=prev;
                 m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j]=prevUsed;
+#else
+                Int newPrev = m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_referencePics[j];
+                Int newUsed = m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_usedByCurrPic[j];
+                m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_referencePics[j]=prev;
+                m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_usedByCurrPic[j]=prevUsed;
+#endif
+
                 prevUsed=newUsed;
                 prev=newPrev;
@@ -1964,14 +2155,32 @@
           }
         }
+#if !Q0108_TSA_STSA
         m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefPics=newRefs;
         m_GOPList[m_iGOPSize+m_extraRPSs].m_POC = curPOC;
+#else
+        m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_numRefPics=newRefs;
+        m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_POC = curPOC;
+#endif
+#if !Q0108_TSA_STSA
         if (m_extraRPSs == 0)
-        {
+#else
+        if (m_extraRPSs[0] == 0)
+#endif
+        {
+#if !Q0108_TSA_STSA
           m_GOPList[m_iGOPSize+m_extraRPSs].m_interRPSPrediction = 0;
           m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefIdc = 0;
+#else
+          m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_interRPSPrediction = 0;
+          m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_numRefIdc = 0;
+#endif
         }
         else
         {
+#if !Q0108_TSA_STSA
           Int rIdx =  m_iGOPSize + m_extraRPSs - 1;
+#else
+          Int rIdx =  m_iGOPSize + m_extraRPSs[0] - 1;
+#endif
           Int refPOC = m_GOPList[rIdx].m_POC;
           Int refPics = m_GOPList[rIdx].m_numRefPics;
@@ -1982,4 +2191,5 @@
             Int absPOCref = refPOC+deltaPOC;
             Int refIdc = 0;
+#if !Q0108_TSA_STSA
             for (Int j = 0; j < m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefPics; j++)
             {
@@ -2006,4 +2216,31 @@
         m_extraRPSs++;
       }
+#else
+            for (Int j = 0; j < m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_numRefPics; j++)
+            {
+              if ( (absPOCref - curPOC) == m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_referencePics[j])
+              {
+                if (m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_usedByCurrPic[j])
+                {
+                  refIdc = 1;
+                }
+                else
+                {
+                  refIdc = 2;
+                }
+              }
+            }
+            m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_refIdc[newIdc]=refIdc;
+            newIdc++;
+          }
+          m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_interRPSPrediction = 1;  
+          m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_numRefIdc = newIdc;
+          m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_deltaRPS = refPOC - m_GOPList[m_iGOPSize+m_extraRPSs[0]].m_POC; 
+        }
+        curGOP=m_iGOPSize+m_extraRPSs[0];
+        m_extraRPSs[0]++;
+      }
+#endif
+
       numRefs=0;
       for(Int i = 0; i< m_GOPList[curGOP].m_numRefPics; i++) 
@@ -2022,4 +2259,245 @@
   }
   xConfirmPara(errorGOP,"Invalid GOP structure given");
+
+#if SVC_EXTENSION && Q0108_TSA_STSA
+  for ( Int layerId = 1; layerId < m_numLayers; layerId++ )
+  {
+    verifiedGOP=false;
+    errorGOP=false;
+    checkGOP=1;
+    numRefs = m_isField ? 2 : 1;
+    refList[0]=0;
+
+    if(m_isField)
+    {
+      refList[1] = 1;
+    }
+
+    memset( isOK, 0, sizeof( isOK ) );
+    numOK=0;
+
+    for(Int i=0; i<m_iGOPSize; i++)
+    {
+      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)
+          {
+            beforeI=true;
+          }
+          else 
+          {
+            Bool found=false;
+            for(Int j=0; j<numRefs; j++) 
+            {
+              if(refList[j]==absPOC) 
+              {
+                found=true;
+                for(Int k=0; k<m_iGOPSize; k++)
+                {
+                  if(absPOC%m_iGOPSize == m_EhGOPList[layerId][k].m_POC%m_iGOPSize)
+                  {
+                    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;
+                  }
+                }
+              }
+            }
+            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(!beforeI&&!errorGOP)
+        {
+          //all ref frames were present
+          if(!isOK[curGOP]) 
+          {
+            numOK++;
+            isOK[curGOP]=true;
+            if(numOK==m_iGOPSize)
+            {
+              verifiedGOP=true;
+            }
+          }
+        }
+        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++) 
+          {
+            Int absPOC = curPOC+m_EhGOPList[layerId][curGOP].m_referencePics[i];
+            if(absPOC>=0)
+            {
+              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++;
+            }
+          }
+          Int numPrefRefs = m_EhGOPList[layerId][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_EhGOPList[layerId][offGOP].m_POC;
+            if(offPOC>=0&&m_EhGOPList[layerId][offGOP].m_temporalId<=m_EhGOPList[layerId][curGOP].m_temporalId)
+            {
+              Bool newRef=false;
+              for(Int i=0; i<numRefs; i++)
+              {
+                if(refList[i]==offPOC)
+                {
+                  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++;
+              }
+            }
+            if(newRefs>=numPrefRefs)
+            {
+              break;
+            }
+          }
+          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;
   for(Int i=0; i<m_iGOPSize; i++) 
@@ -2031,4 +2509,20 @@
     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");
   }
+
+#if Q0108_TSA_STSA
+  for ( Int layerId = 1; layerId < m_numLayers; layerId++)
+  {
+    m_EhMaxTempLayer[layerId] = 1;
+    for(Int i=0; i<m_iGOPSize; i++) 
+    {
+      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");
+    }
+  }
+#endif
+
   for(Int i=0; i<MAX_TLAYER; i++)
   {
@@ -2195,4 +2689,18 @@
     xConfirmPara( m_extendedWhiteLevelLumaCodeValue < m_nominalWhiteLevelLumaCodeValue, "SEIToneMapExtendedWhiteLevelLumaCodeValue shall be greater than or equal to SEIToneMapNominalWhiteLevelLumaCodeValue");
   }
+#if P0050_KNEE_FUNCTION_SEI
+  if (m_kneeSEIEnabled && !m_kneeSEICancelFlag)
+  {
+    xConfirmPara( m_kneeSEINumKneePointsMinus1 < 0 || m_kneeSEINumKneePointsMinus1 > 998, "SEIKneeFunctionNumKneePointsMinus1 must be in the range of 0 to 998");
+    for ( UInt i=0; i<=m_kneeSEINumKneePointsMinus1; i++ ){
+      xConfirmPara( m_kneeSEIInputKneePoint[i] < 1 || m_kneeSEIInputKneePoint[i] > 999, "SEIKneeFunctionInputKneePointValue must be in the range of 1 to 999");
+      xConfirmPara( m_kneeSEIOutputKneePoint[i] < 0 || m_kneeSEIOutputKneePoint[i] > 1000, "SEIKneeFunctionInputKneePointValue must be in the range of 0 to 1000");
+      if ( i > 0 )
+      {
+        xConfirmPara( m_kneeSEIInputKneePoint[i-1] >= m_kneeSEIInputKneePoint[i],  "The i-th SEIKneeFunctionInputKneePointValue must be greather than the (i-1)-th value");
+      }
+    }
+  }
+#endif
 
 #if RC_SHVC_HARMONIZATION
@@ -2234,4 +2742,6 @@
     xConfirmPara(m_framePackingSEIType < 3 || m_framePackingSEIType > 5 , "SEIFramePackingType must be in rage 3 to 5");
   }
+
+#if SVC_EXTENSION
 #if VPS_EXTN_DIRECT_REF_LAYERS
   xConfirmPara( (m_acLayerCfg[0].m_numSamplePredRefLayers != 0) && (m_acLayerCfg[0].m_numSamplePredRefLayers != -1), "Layer 0 cannot have any reference layers" );
@@ -2304,10 +2814,8 @@
   }
 #endif
-#if N0120_MAX_TID_REF_CFG
   for (UInt layer=0; layer < MAX_LAYERS-1; layer++)
   {
     xConfirmPara(m_acLayerCfg[layer].m_maxTidIlRefPicsPlus1 < 0 || m_acLayerCfg[layer].m_maxTidIlRefPicsPlus1 > 7, "MaxTidIlRefPicsPlus1 must be in range 0 to 7");
   }
-#endif 
 #if AUXILIARY_PICTURES
   for (UInt layer=0; layer < MAX_LAYERS-1; layer++)
@@ -2320,4 +2828,5 @@
   xConfirmPara( m_nCGSFlag < 0 || m_nCGSFlag > 1 , "0<=CGS<=1" );
 #endif
+#endif //SVC_EXTENSION
 #undef xConfirmPara
   if (check_failed)
@@ -2397,16 +2906,11 @@
 #if SVC_EXTENSION  
   printf("Total number of layers        : %d\n", m_numLayers       );
-#if SCALABILITY_MASK_E0104
-  printf("Multiview                     : %d\n", m_scalabilityMask[1] );
-  printf("Scalable                      : %d\n", m_scalabilityMask[2] );
+  printf("Multiview                     : %d\n", m_scalabilityMask[VIEW_ORDER_INDEX] );
+  printf("Scalable                      : %d\n", m_scalabilityMask[SCALABILITY_ID] );
 #if AVC_BASE
   printf("Base layer                    : %s\n", m_avcBaseLayerFlag ? "AVC" : "HEVC");
 #endif
 #if AUXILIARY_PICTURES
-  printf("Auxiliary pictures            : %d\n", m_scalabilityMask[3] );
-#endif
-#else
-  printf("Multiview                     : %d\n", m_scalabilityMask[0] );
-  printf("Scalable                      : %d\n", m_scalabilityMask[1] );
+  printf("Auxiliary pictures            : %d\n", m_scalabilityMask[AUX_ID] );
 #endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
@@ -2419,7 +2923,5 @@
   printf("Align picture type            : %d\n", m_crossLayerPictureTypeAlignFlag );
 #endif
-#if N0147_IRAP_ALIGN_FLAG
   printf("Cross layer IRAP alignment    : %d\n", m_crossLayerIrapAlignFlag );
-#endif
 #if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
   printf("IDR only for IRAP             : %d\n", m_crossLayerAlignedIdrOnlyFlag );
Index: trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 752)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 815)
@@ -73,7 +73,13 @@
   Char*     m_BLSyntaxFile;                                   ///< input syntax file
 #endif
-#if N0120_MAX_TID_REF_CFG
   Bool      m_maxTidRefPresentFlag; 
-#endif 
+#if Q0078_ADD_LAYER_SETS
+  Int       m_numLayerSets;
+  Int       m_numLayerInIdList[MAX_VPS_LAYER_SETS_PLUS1];
+  Int       m_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  Int       m_numAddLayerSets;
+  Int       m_numHighestLayerIdx[MAX_VPS_LAYER_SETS_PLUS1];
+  Int       m_highestLayerIdx[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+#endif
 #else
   Char*     m_pchInputFile;                                   ///< source file name
@@ -119,6 +125,17 @@
   Int       m_iDecodingRefreshType;                           ///< random access type
   Int       m_iGOPSize;                                       ///< GOP size of hierarchical structure
+
+#if !Q0108_TSA_STSA
   Int       m_extraRPSs;                                      ///< extra RPSs added to handle CRA
+#else
+  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_EhGOPList[MAX_LAYERS][MAX_GOP];                 ///< the enhancement layer coding structure entries from the config file
+  Int       m_inheritCodingStruct[MAX_LAYERS];
+#endif
+
   Int       m_numReorderPics[MAX_TLAYER];                     ///< total number of reorder pictures
   Int       m_maxDecPicBuffering[MAX_TLAYER];                 ///< total number of pictures in the decoded picture buffer
@@ -148,4 +165,7 @@
   
   Int       m_maxTempLayer;                                  ///< Max temporal layer
+#if Q0108_TSA_STSA
+  Int       m_EhMaxTempLayer[MAX_LAYERS];                    ///< Max temporal layer
+#endif
 
 #if !LAYER_CTB
@@ -285,4 +305,7 @@
   Int       m_SOPDescriptionSEIEnabled;
   Int       m_scalableNestingSEIEnabled;
+#if Q0189_TMVP_CONSTRAINTS
+  Int       m_TMVPConstraintsSEIEnabled;
+#endif
   // weighted prediction
   Bool      m_useWeightedPred;                    ///< Use of weighted prediction in P slices
@@ -363,4 +386,5 @@
   Void  xPrintParameter ();                                   ///< print configuration values
   Void  xPrintUsage     ();                                   ///< print usage
+#if SVC_EXTENSION
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   Int       m_adaptiveResolutionChange;                       ///< Indicate adaptive resolution change frame
@@ -386,6 +410,18 @@
   Bool      m_crossLayerPictureTypeAlignFlag;
 #endif
-#if N0147_IRAP_ALIGN_FLAG
   Bool      m_crossLayerIrapAlignFlag;
+#if P0050_KNEE_FUNCTION_SEI
+  Bool      m_kneeSEIEnabled;
+  Int       m_kneeSEIId;
+  Bool      m_kneeSEICancelFlag;
+  Bool      m_kneeSEIPersistenceFlag;
+  Bool      m_kneeSEIMappingFlag;
+  Int       m_kneeSEIInputDrange;
+  Int       m_kneeSEIInputDispLuminance;
+  Int       m_kneeSEIOutputDrange;
+  Int       m_kneeSEIOutputDispLuminance;
+  Int       m_kneeSEINumKneePointsMinus1;
+  Int*      m_kneeSEIInputKneePoint;
+  Int*      m_kneeSEIOutputKneePoint;
 #endif
 #if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
@@ -404,4 +440,5 @@
   Int  m_nCGSLUTBit;
 #endif
+#endif //SVC_EXTENSION
 public:
   TAppEncCfg();
Index: trunk/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 752)
+++ trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 815)
@@ -83,7 +83,5 @@
 #endif
 
-#if N0120_MAX_TID_REF_CFG
   Int       m_maxTidIlRefPicsPlus1;
-#endif 
   Int       m_iWaveFrontSubstreams; //< If iWaveFrontSynchro, this is the number of substreams per frame (dependent tiles) or per tile (independent tiles).
 
@@ -181,7 +179,5 @@
   Void    setSourceHeight(Int x)      { m_iSourceHeight = x;    }
 #endif
-#if N0120_MAX_TID_REF_CFG
   Int     getMaxTidIlRefPicsPlus1()   { return m_maxTidIlRefPicsPlus1; }
-#endif 
 #if LAYER_CTB
   UInt    getMaxCUWidth()             {return m_uiMaxCUWidth;      }
Index: trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 752)
+++ trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 815)
@@ -82,7 +82,4 @@
     vps->setTemporalNestingFlag(true);
   }
-#if !VPS_RENAME
-  vps.setMaxLayers                        ( 1 );
-#endif
   for(Int i = 0; i < MAX_TLAYER; i++)
   {
@@ -190,4 +187,6 @@
   delete [] mapIdxToLayer;
 #endif
+
+  assert( m_numLayers <= MAX_LAYERS );
 
   for(UInt layer=0; layer<m_numLayers; layer++)
@@ -241,7 +240,15 @@
     m_acTEncTop[layer].setDecodingRefreshType          ( m_iDecodingRefreshType );
     m_acTEncTop[layer].setGOPSize                      ( m_iGOPSize );
+#if Q0108_TSA_STSA
+    m_acTEncTop[layer].setGopList                      ( layer ? m_EhGOPList[layer] : m_GOPList );
+#else
     m_acTEncTop[layer].setGopList                      ( m_GOPList );
-
+#endif
+
+#if !Q0108_TSA_STSA
     m_acTEncTop[layer].setExtraRPSs                    ( m_extraRPSs );
+#else
+    m_acTEncTop[layer].setExtraRPSs                    ( m_extraRPSs[layer] );
+#endif
     for(Int i = 0; i < MAX_TLAYER; i++)
     {
@@ -256,13 +263,23 @@
 
     m_acTEncTop[layer].setPad                          ( m_acLayerCfg[layer].getPad() );
-
+#if !Q0108_TSA_STSA
     m_acTEncTop[layer].setMaxTempLayer                 ( m_maxTempLayer );
+#else
+    if (layer== 0)
+    {
+      m_acTEncTop[layer].setMaxTempLayer                 ( m_maxTempLayer );
+    }
+    else
+    {
+      m_acTEncTop[layer].setMaxTempLayer                 ( m_EhMaxTempLayer[layer] );
+    }
+#endif
     m_acTEncTop[layer].setUseAMP( m_enableAMP );
-#if N0120_MAX_TID_REF_CFG
-    if (layer<m_numLayers-1)
+
+    if( layer < m_numLayers - 1 )
     {
        m_acTEncTop[layer].setMaxTidIlRefPicsPlus1 ( m_acLayerCfg[layer].getMaxTidIlRefPicsPlus1());
     }
-#endif
+
 #if VPS_EXTN_DIRECT_REF_LAYERS
     if(layer)
@@ -306,4 +323,7 @@
       }
       Int numDirectRefLayers = 0;
+
+      assert( layer < MAX_LAYERS );
+
       for (Int i = 0; i < layer; i++)
       {
@@ -480,4 +500,18 @@
     m_acTEncTop[layer].setTMISEINominalWhiteLevelLumaCodeValue      ( m_nominalWhiteLevelLumaCodeValue );
     m_acTEncTop[layer].setTMISEIExtendedWhiteLevelLumaCodeValue     ( m_extendedWhiteLevelLumaCodeValue );
+#if P0050_KNEE_FUNCTION_SEI
+    m_acTEncTop[layer].setKneeSEIEnabled                            ( m_kneeSEIEnabled );
+    m_acTEncTop[layer].setKneeSEIId                                 ( m_kneeSEIId );
+    m_acTEncTop[layer].setKneeSEICancelFlag                         ( m_kneeSEICancelFlag );
+    m_acTEncTop[layer].setKneeSEIPersistenceFlag                    ( m_kneeSEIPersistenceFlag );
+    m_acTEncTop[layer].setKneeSEIMappingFlag                        ( m_kneeSEIMappingFlag );
+    m_acTEncTop[layer].setKneeSEIInputDrange                        ( m_kneeSEIInputDrange );
+    m_acTEncTop[layer].setKneeSEIInputDispLuminance                 ( m_kneeSEIInputDispLuminance );
+    m_acTEncTop[layer].setKneeSEIOutputDrange                       ( m_kneeSEIOutputDrange );
+    m_acTEncTop[layer].setKneeSEIOutputDispLuminance                ( m_kneeSEIOutputDispLuminance );
+    m_acTEncTop[layer].setKneeSEINumKneePointsMinus1                ( m_kneeSEINumKneePointsMinus1 );
+    m_acTEncTop[layer].setKneeSEIInputKneePoint                     ( m_kneeSEIInputKneePoint );
+    m_acTEncTop[layer].setKneeSEIOutputKneePoint                    ( m_kneeSEIOutputKneePoint );
+#endif
 #if Q0074_SEI_COLOR_MAPPING
     m_acTEncTop[layer].setColorMappingInfoSEIFile                   ( m_acLayerCfg[layer].m_cSeiColorMappingFile.empty() ? NULL : const_cast<Char *>(m_acLayerCfg[layer].m_cSeiColorMappingFile.c_str()) );
@@ -497,4 +531,7 @@
     m_acTEncTop[layer].setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled );
     m_acTEncTop[layer].setScalableNestingSEIEnabled( m_scalableNestingSEIEnabled );
+#if Q0189_TMVP_CONSTRAINTS
+    m_acTEncTop[layer].setTMVPConstraintsSEIEnabled( m_TMVPConstraintsSEIEnabled);           
+#endif
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     m_acTEncTop[layer].setInterLayerConstrainedTileSetsSEIEnabled( m_interLayerConstrainedTileSetsSEIEnabled );
@@ -614,4 +651,7 @@
     m_acTEncTop[layer].setCGSLUTBit( m_nCGSLUTBit );
 #endif
+#if Q0078_ADD_LAYER_SETS
+    m_acTEncTop[layer].setNumAddLayerSets( m_numAddLayerSets );
+#endif
   }
 }
@@ -799,4 +839,18 @@
   m_cTEncTop.setTMISEINominalWhiteLevelLumaCodeValue      ( m_nominalWhiteLevelLumaCodeValue );
   m_cTEncTop.setTMISEIExtendedWhiteLevelLumaCodeValue     ( m_extendedWhiteLevelLumaCodeValue );
+#if P0050_KNEE_FUNCTION_SEI
+  m_cTEncTop.setKneeSEIEnabled              ( m_kneeSEIEnabled );
+  m_cTEncTop.setKneeSEIId                   ( m_kneeSEIId );
+  m_cTEncTop.setKneeSEICancelFlag           ( m_kneeSEICancelFlag );
+  m_cTEncTop.setKneeSEIPersistenceFlag      ( m_kneeSEIPersistenceFlag );
+  m_cTEncTop.setKneeSEIMappingFlag          ( m_kneeSEIMappingFlag );
+  m_cTEncTop.setKneeSEIInputDrange          ( m_kneeSEIInputDrange );
+  m_cTEncTop.setKneeSEIInputDispLuminance   ( m_kneeSEIInputDispLuminance );
+  m_cTEncTop.setKneeSEIOutputDrange         ( m_kneeSEIOutputDrange );
+  m_cTEncTop.setKneeSEIOutputDispLuminance  ( m_kneeSEIOutputDispLuminance );
+  m_cTEncTop.setKneeSEINumKneePointsMinus1  ( m_kneeSEINumKneePointsMinus1 );
+  m_cTEncTop.setKneeSEIInputKneePoint       ( m_kneeSEIInputKneePoint );
+  m_cTEncTop.setKneeSEIOutputKneePoint      ( m_kneeSEIOutputKneePoint );
+#endif
 #if Q0074_SEI_COLOR_MAPPING
   m_cTEncTop.setColorMappingInfoSEIFile                   ( m_pchSEIColorMappingFile );
@@ -994,7 +1048,5 @@
 #endif
   }
-#if VPS_RENAME
   m_acTEncTop[0].getVPS()->setMaxLayers( m_numLayers );
-#endif
 #if VPS_EXTN_OP_LAYER_SETS
   TComVPS* vps = m_acTEncTop[0].getVPS();
@@ -1003,27 +1055,79 @@
   vps->setVpsExtensionFlag( m_numLayers > 1 ? true : false );
 
-  vps->setNumLayerSets(m_numLayers);
-  for(Int setId = 1; setId < vps->getNumLayerSets(); setId++)
-  {
-    for(Int layerId = 0; layerId <= vps->getMaxLayerId(); layerId++)
-    {
+#if Q0078_ADD_LAYER_SETS
+  if (m_numLayerSets > 0)
+  {
+    vps->setNumLayerSets(m_numLayerSets+1);
+    for (Int setId = 1; setId < vps->getNumLayerSets(); setId++)
+    {
+      for (Int layerId = 0; layerId <= vps->getMaxLayerId(); layerId++)
+      {
+        vps->setLayerIdIncludedFlag(false, setId, layerId);
+      }
+    }
+    for (Int setId = 1; setId < vps->getNumLayerSets(); setId++)
+    {
+      for (Int i = 0; i < m_numLayerInIdList[setId-1]; i++)
+      {
+        Int layerId = m_layerSetLayerIdList[setId-1][i];
+
 #if O0194_DIFFERENT_BITDEPTH_EL_BL
-      //4
-      g_bitDepthY = m_acLayerCfg[layerId].m_internalBitDepthY;
-      g_bitDepthC = m_acLayerCfg[layerId].m_internalBitDepthC;
-
-      g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthY : m_acLayerCfg[layerId].m_internalBitDepthY;
-      g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthC : m_acLayerCfg[layerId].m_internalBitDepthC;
-#endif
-      if( layerId <= setId )
-      {
+        //4
+        g_bitDepthY = m_acLayerCfg[layerId].m_internalBitDepthY;
+        g_bitDepthC = m_acLayerCfg[layerId].m_internalBitDepthC;
+
+        g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthY : m_acLayerCfg[layerId].m_internalBitDepthY;
+        g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthC : m_acLayerCfg[layerId].m_internalBitDepthC;
+#endif
+
         vps->setLayerIdIncludedFlag(true, setId, layerId);
       }
-      else
-      {
-        vps->setLayerIdIncludedFlag(false, setId, layerId);
-      }
-    }
-  }
+    }
+  }
+  else
+  {
+    // Default layer sets
+#endif
+    vps->setNumLayerSets(m_numLayers);
+    for (Int setId = 1; setId < vps->getNumLayerSets(); setId++)
+    {
+      for (Int layerId = 0; layerId <= vps->getMaxLayerId(); layerId++)
+      {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+        //4
+        g_bitDepthY = m_acLayerCfg[layerId].m_internalBitDepthY;
+        g_bitDepthC = m_acLayerCfg[layerId].m_internalBitDepthC;
+
+        g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthY : m_acLayerCfg[layerId].m_internalBitDepthY;
+        g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthC : m_acLayerCfg[layerId].m_internalBitDepthC;
+#endif
+        if (layerId <= setId)
+        {
+          vps->setLayerIdIncludedFlag(true, setId, layerId);
+        }
+        else
+        {
+          vps->setLayerIdIncludedFlag(false, setId, layerId);
+        }
+      }
+    }
+#if Q0078_ADD_LAYER_SETS
+  }
+#endif
+#if Q0078_ADD_LAYER_SETS
+  vps->setVpsNumLayerSetsMinus1(vps->getNumLayerSets() - 1);
+  vps->setNumAddLayerSets(m_numAddLayerSets);
+  vps->setNumLayerSets(vps->getNumLayerSets() + vps->getNumAddLayerSets());
+  if (m_numAddLayerSets > 0)
+  {
+    for (Int setId = 0; setId < m_numAddLayerSets; setId++)
+    {
+      for (Int j = 0; j < m_numHighestLayerIdx[setId]; j++)
+      {
+        vps->setHighestLayerIdxPlus1(setId, j + 1, m_highestLayerIdx[setId][j] + 1);
+      }
+    }
+  }
+#endif
 #if VPS_EXTN_MASK_AND_DIM_INFO
   UInt i = 0, dimIdLen = 0;
@@ -1097,4 +1201,5 @@
 #if VPS_TSLAYERS
     vps->setMaxTSLayersPresentFlag(true);
+
     for( i = 0; i < vps->getMaxLayers(); i++ )
     {
@@ -1102,15 +1207,9 @@
     }
 #endif
-#if N0120_MAX_TID_REF_PRESENT_FLAG
-#if N0120_MAX_TID_REF_CFG
   vps->setMaxTidRefPresentFlag(m_maxTidRefPresentFlag);
-#else
-  vps->setMaxTidRefPresentFlag(true);
-#endif
   if (vps->getMaxTidRefPresentFlag())
   {
     for( i = 0; i < vps->getMaxLayers() - 1; i++ )
     {
-#if N0120_MAX_TID_REF_CFG
 #if O0225_MAX_TID_FOR_REF_LAYERS
       for( Int j = i+1; j < vps->getMaxLayers(); j++)
@@ -1121,23 +1220,13 @@
       vps->setMaxTidIlRefPicsPlus1(i, m_acTEncTop[i].getMaxTidIlRefPicsPlus1());
 #endif 
-#else
+    }
+  }
+  else
+  {
+    for( i = 0; i < vps->getMaxLayers() - 1; i++ )
+    {
 #if O0225_MAX_TID_FOR_REF_LAYERS
       for( Int j = i+1; j < vps->getMaxLayers(); j++)
       {
-        vps->setMaxTidIlRefPicsPlus1(i, j, vps->getMaxTLayers()+1);
-      }
-#else
-      vps->setMaxTidIlRefPicsPlus1(i, vps->getMaxTLayers()+1);
-#endif
-#endif
-    }
-  }
-  else
-  {
-    for( i = 0; i < vps->getMaxLayers() - 1; i++ )
-    {
-#if O0225_MAX_TID_FOR_REF_LAYERS
-      for( Int j = i+1; j < vps->getMaxLayers(); j++)
-      {
         vps->setMaxTidIlRefPicsPlus1(i, j, 7);
       }
@@ -1147,12 +1236,5 @@
     }
   }
-#endif
-#if ILP_SSH_SIG
-#if ILP_SSH_SIG_FIX
     vps->setIlpSshSignalingEnabledFlag(false);
-#else
-    vps->setIlpSshSignalingEnabledFlag(true);
-#endif
-#endif
 #if VPS_EXTN_PROFILE_INFO
   vps->getPTLForExtnPtr()->resize(vps->getNumLayerSets());
@@ -1162,105 +1244,4 @@
     // Note - may need to be changed for other layer structures.
     *(vps->getPTLForExtn(setId)) = *(m_acTEncTop[setId].getSPS()->getPTL());
-  }
-#endif
-  // Target output layer
-  vps->setNumOutputLayerSets(vps->getNumLayerSets());
-  vps->setNumProfileTierLevel(vps->getNumLayerSets());
-#if P0295_DEFAULT_OUT_LAYER_IDC
-  vps->setDefaultTargetOutputLayerIdc(1);
-#else
-#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
-  vps->setDefaultOneTargetOutputLayerIdc(1);
-#else
-  vps->setDefaultOneTargetOutputLayerFlag(true);
-#endif
-#endif
-  for(i = 1; i < vps->getNumLayerSets(); i++)
-  {
-    vps->setProfileLevelTierIdx(i, i);
-    vps->setOutputLayerSetIdx(i, i);
-  }  
-#endif
- #if VPS_DPB_SIZE_TABLE
-  // The Layer ID List variables can be derived here.  
-#if DERIVE_LAYER_ID_LIST_VARIABLES
-  vps->deriveLayerIdListVariables();
-#endif
-#if RESOLUTION_BASED_DPB
-  vps->assignSubDpbIndices();
-#else
-  vps->deriveNumberOfSubDpbs();
-#endif
-
-  // derive OutputLayerFlag[i][j] 
-  if( vps->getDefaultTargetOutputLayerIdc() == 1 )
-  {
-    // default_target_output_layer_idc equal to 1 specifies that only the layer with the highest value of nuh_layer_id such that nuh_layer_id equal to nuhLayerIdA and 
-    // AuxId[ nuhLayerIdA ] equal to 0 in each of the output layer sets with index in the range of 1 to vps_num_layer_sets_minus1, inclusive, is an output layer of its output layer set.
-
-    // Include the highest layer as output layer for each layer set
-    for(Int lsIdx = 1; lsIdx < vps->getNumLayerSets(); lsIdx++)
-    {
-      for( UInt layer = 0; layer < vps->getNumLayersInIdList(lsIdx); layer++ )
-      {
-        if( vps->getLayerIdIncludedFlag(lsIdx, layer) )      
-        {        
-          vps->setOutputLayerFlag( lsIdx, layer, layer == vps->getNumLayersInIdList(lsIdx) - 1 );
-        }
-      }
-    }
-  }
-  else
-  {
-    // cases when default_target_output_layer_idc is not equal to 1
-    assert(!"default_target_output_layer_idc not equal to 1 is not yet supported");
-  }
-
-  // Initialize dpb_size_table() for all ouput layer sets in the VPS extension
-  for(i = 1; i < vps->getNumOutputLayerSets(); i++)
-  {
-#if CHANGE_NUMSUBDPB_IDX
-    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
-#endif
-    Int layerSetId = vps->getOutputLayerSetIdx(i);
-
-    for(Int j = 0; j < vps->getMaxTLayers(); j++)
-    {
-
-      Int maxNumReorderPics = -1;
-#if CHANGE_NUMSUBDPB_IDX
-#if RESOLUTION_BASED_DPB
-      for(Int k = 0; k < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); k++)
-#else
-      for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
-#endif
-#else
-      for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
-#endif
-      {
-        Int layerId = vps->getLayerSetLayerIdList(layerSetId, k); // k-th layer in the output layer set
-#if RESOLUTION_BASED_DPB
-        vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, m_acTEncTop[layerId].getMaxDecPicBuffering(j) - 1 );
-        // Add sub-DPB sizes of layers belonging to a sub-DPB. If a different sub-DPB size is calculated
-        // at the encoder, modify below
-        Int oldValue = vps->getMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j );
-        oldValue += vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j ) + 1;
-        vps->setMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j, oldValue );
-#else
-        vps->setMaxVpsDecPicBufferingMinus1( i, k, j,  m_acTEncTop[layerId].getMaxDecPicBuffering(j) - 1 );
-#endif
-        maxNumReorderPics       = std::max( maxNumReorderPics, m_acTEncTop[layerId].getNumReorderPics(j));
-      }
-#if RESOLUTION_BASED_DPB
-      for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
-      {
-        // Decrement m_maxVpsDecPicBufferingMinus1
-        Int oldValue = vps->getMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j );
-        vps->setMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j, oldValue - 1 );
-      }
-#endif
-      vps->setMaxVpsNumReorderPics(i, j, maxNumReorderPics);
-      vps->determineSubDpbInfoFlags();
-    }
   }
 #endif
@@ -1271,32 +1252,32 @@
   Bool isDefaultDirectDependencyTypeSet = false;
 #endif
-  for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
-  {
-    vps->setNumDirectRefLayers( layerCtr, m_acTEncTop[layerCtr].getNumDirectRefLayers() );
-    maxDirectRefLayers = max<UInt>( maxDirectRefLayers, vps->getNumDirectRefLayers( layerCtr ) );
-
-    for(i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
-    {
-      vps->setRefLayerId( layerCtr, i, m_acTEncTop[layerCtr].getRefLayerId(i) );
+  for (UInt layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+  {
+    vps->setNumDirectRefLayers(layerCtr, m_acTEncTop[layerCtr].getNumDirectRefLayers());
+    maxDirectRefLayers = max<UInt>(maxDirectRefLayers, vps->getNumDirectRefLayers(layerCtr));
+
+    for (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(i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
-    {
-      vps->setDirectDependencyFlag( layerCtr, vps->getLayerIdInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true);
+    for (Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
+    {
+      vps->setDirectDependencyFlag(layerCtr, refLayerCtr, false);
+    }
+    for (i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
+    {
+      vps->setDirectDependencyFlag(layerCtr, vps->getLayerIdInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true);
     }
     // prediction indications
     vps->setDirectDepTypeLen(2); // sample and motion types are encoded
-    for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
-    {
-      if (vps->getDirectDependencyFlag( layerCtr, refLayerCtr))
+    for (Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
+    {
+      if (vps->getDirectDependencyFlag(layerCtr, refLayerCtr))
       {
         assert(m_acTEncTop[layerCtr].getSamplePredEnabledFlag(refLayerCtr) || m_acTEncTop[layerCtr].getMotionPredEnabledFlag(refLayerCtr));
-        vps->setDirectDependencyType( layerCtr, refLayerCtr, ((m_acTEncTop[layerCtr].getSamplePredEnabledFlag(refLayerCtr) ? 1 : 0) |
-                                                              (m_acTEncTop[layerCtr].getMotionPredEnabledFlag(refLayerCtr) ? 2 : 0)) - 1);
+        vps->setDirectDependencyType(layerCtr, refLayerCtr, ((m_acTEncTop[layerCtr].getSamplePredEnabledFlag(refLayerCtr) ? 1 : 0) |
+          (m_acTEncTop[layerCtr].getMotionPredEnabledFlag(refLayerCtr) ? 2 : 0)) - 1);
 #if O0096_DEFAULT_DEPENDENCY_TYPE
         if (!isDefaultDirectDependencyTypeSet)
@@ -1314,5 +1295,5 @@
       else
       {
-        vps->setDirectDependencyType( layerCtr, refLayerCtr, 0 );
+        vps->setDirectDependencyType(layerCtr, refLayerCtr, 0);
       }
     }
@@ -1320,16 +1301,122 @@
 
 #if O0092_0094_DEPENDENCY_CONSTRAINT
-  for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
-  {
-    vps->setNumRefLayers(vps->getLayerIdInNuh(layerCtr));   // identify the number of direct and indirect reference layers of current layer and set recursiveRefLayersFlags
-  }
-  if(vps->getMaxLayers() > MAX_REF_LAYERS)
-  {
-    for(UInt layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
-    {
-      assert( vps->getNumRefLayers(vps->getLayerIdInNuh(layerCtr)) <= MAX_REF_LAYERS);
-    }
-  }
-#endif
+  vps->setNumRefLayers();
+
+  if (vps->getMaxLayers() > MAX_REF_LAYERS)
+  {
+    for (UInt layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+    {
+      assert(vps->getNumRefLayers(vps->getLayerIdInNuh(layerCtr)) <= MAX_REF_LAYERS);
+    }
+  }
+#endif
+#if Q0078_ADD_LAYER_SETS
+  vps->setPredictedLayerIds();
+  vps->setTreePartitionLayerIdList();
+  vps->setLayerIdIncludedFlagsForAddLayerSets();
+#endif
+#endif
+  // Target output layer
+  vps->setNumOutputLayerSets(vps->getNumLayerSets());
+  vps->setNumProfileTierLevel(vps->getNumLayerSets());
+#if P0295_DEFAULT_OUT_LAYER_IDC
+  vps->setDefaultTargetOutputLayerIdc(1);
+#else
+#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
+  vps->setDefaultOneTargetOutputLayerIdc(1);
+#else
+  vps->setDefaultOneTargetOutputLayerFlag(true);
+#endif
+#endif
+  for(i = 1; i < vps->getNumLayerSets(); i++)
+  {
+    vps->setProfileLevelTierIdx(i, i);
+    vps->setOutputLayerSetIdx(i, i);
+  }  
+#endif
+ #if VPS_DPB_SIZE_TABLE
+  // The Layer ID List variables can be derived here.  
+#if DERIVE_LAYER_ID_LIST_VARIABLES
+  vps->deriveLayerIdListVariables();
+#endif
+#if RESOLUTION_BASED_DPB
+  vps->assignSubDpbIndices();
+#else
+  vps->deriveNumberOfSubDpbs();
+#endif
+
+  // derive OutputLayerFlag[i][j] 
+  if( vps->getDefaultTargetOutputLayerIdc() == 1 )
+  {
+    // default_output_layer_idc equal to 1 specifies that only the layer with the highest value of nuh_layer_id such that nuh_layer_id equal to nuhLayerIdA and 
+    // AuxId[ nuhLayerIdA ] equal to 0 in each of the output layer sets with index in the range of 1 to vps_num_layer_sets_minus1, inclusive, is an output layer of its output layer set.
+
+    // Include the highest layer as output layer for each layer set
+    for(Int lsIdx = 1; lsIdx < vps->getNumLayerSets(); lsIdx++)
+    {
+      for( UInt layer = 0; layer < vps->getNumLayersInIdList(lsIdx); layer++ )
+      {
+#if !Q0078_ADD_LAYER_SETS  // the following condition is incorrect and is not needed anyway
+        if( vps->getLayerIdIncludedFlag(lsIdx, layer) )      
+#endif
+        {        
+          vps->setOutputLayerFlag( lsIdx, layer, layer == vps->getNumLayersInIdList(lsIdx) - 1 );
+        }
+      }
+    }
+  }
+  else
+  {
+    // cases when default_output_layer_idc is not equal to 1
+    assert(!"default_output_layer_idc not equal to 1 is not yet supported");
+  }
+
+  // Initialize dpb_size_table() for all ouput layer sets in the VPS extension
+  for(i = 1; i < vps->getNumOutputLayerSets(); i++)
+  {
+#if CHANGE_NUMSUBDPB_IDX
+    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
+#endif
+    Int layerSetId = vps->getOutputLayerSetIdx(i);
+
+    for(Int j = 0; j < vps->getMaxTLayers(); j++)
+    {
+
+      Int maxNumReorderPics = -1;
+#if CHANGE_NUMSUBDPB_IDX
+#if RESOLUTION_BASED_DPB
+      for(Int k = 0; k < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); k++)
+#else
+      for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
+#endif
+#else
+      for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
+#endif
+      {
+        Int layerId = vps->getLayerSetLayerIdList(layerSetId, k); // k-th layer in the output layer set
+#if RESOLUTION_BASED_DPB
+        vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, m_acTEncTop[layerId].getMaxDecPicBuffering(j) - 1 );
+        // Add sub-DPB sizes of layers belonging to a sub-DPB. If a different sub-DPB size is calculated
+        // at the encoder, modify below
+        Int oldValue = vps->getMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j );
+        oldValue += vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j ) + 1;
+        vps->setMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j, oldValue );
+#else
+        vps->setMaxVpsDecPicBufferingMinus1( i, k, j,  m_acTEncTop[layerId].getMaxDecPicBuffering(j) - 1 );
+#endif
+        maxNumReorderPics       = std::max( maxNumReorderPics, m_acTEncTop[layerId].getNumReorderPics(j));
+      }
+#if RESOLUTION_BASED_DPB
+      for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
+      {
+        // Decrement m_maxVpsDecPicBufferingMinus1
+        Int oldValue = vps->getMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j );
+        vps->setMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j, oldValue - 1 );
+      }
+#endif
+      vps->setMaxVpsNumReorderPics(i, j, maxNumReorderPics);
+      vps->determineSubDpbInfoFlags();
+    }
+  }
 #endif
     vps->setMaxOneActiveRefLayerFlag(maxDirectRefLayers > 1 ? false : true);
@@ -1339,5 +1426,9 @@
       if( vps->getNumDirectRefLayers( vps->getLayerIdInNuh(i) ) == 0  )
       {
+#if Q0078_ADD_LAYER_SETS
+        vps->setPocLsbNotPresentFlag(i, true); // make independedent layers base-layer compliant
+#else
         vps->setPocLsbNotPresentFlag(i, false);
+#endif
       }
     }
@@ -1349,5 +1440,4 @@
     vps->setCrossLayerAlignedIdrOnlyFlag( m_crossLayerAlignedIdrOnlyFlag );
 #endif
-#if N0147_IRAP_ALIGN_FLAG
     vps->setCrossLayerIrapAlignFlag( m_crossLayerIrapAlignFlag );
     for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
@@ -1365,5 +1455,4 @@
       }
     }
-#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   vps->setSingleLayerForNonIrapFlag(m_adaptiveResolutionChange > 0 ? true : false);
@@ -1418,5 +1507,9 @@
   {
     vps->setVpsVuiBspHrdPresentFlag(true);
+#if Q0078_ADD_LAYER_SETS
+    vps->setVpsNumBspHrdParametersMinus1(vps->getVpsNumLayerSetsMinus1() - 1); 
+#else
     vps->setVpsNumBspHrdParametersMinus1(vps->getNumLayerSets() - 2); 
+#endif
     vps->createBspHrdParamBuffer(vps->getVpsNumBspHrdParametersMinus1() + 1);
     for ( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
@@ -1451,5 +1544,9 @@
       vps->setBspHrdParameters( i, pcCfgLayer->getFrameRate(), numDU, pcCfgLayer->getTargetBitrate(), ( pcCfgLayer->getIntraPeriod() > 0 ) );
     }
+#if Q0078_ADD_LAYER_SETS
+    for (UInt h = 1; h <= vps->getVpsNumLayerSetsMinus1(); h++)
+#else
     for(UInt h = 1; h <= (vps->getNumLayerSets()-1); h++)
+#endif
     {
       vps->setNumBitstreamPartitions(h, 1);
@@ -1532,5 +1629,5 @@
     if( m_isField )
     {
-#if SVC_UPSAMPLING
+#if SVC_EXTENSION
 #if LAYER_CTB
 #if AUXILIARY_PICTURES
@@ -1552,5 +1649,5 @@
     else
     {
-#if SVC_UPSAMPLING
+#if SVC_EXTENSION
 #if LAYER_CTB
 #if AUXILIARY_PICTURES
@@ -1991,5 +2088,4 @@
     rpcPicYuvRec = new TComPicYuv;
 
-#if SVC_UPSAMPLING
 #if LAYER_CTB
 #if AUXILIARY_PICTURES
@@ -2005,7 +2101,4 @@
 #endif
 #endif
-#else
-    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
-#endif
 
   }
@@ -2032,4 +2125,10 @@
 Void TAppEncTop::xWriteRecon(UInt layer, Int iNumEncoded)
 {
+#if REPN_FORMAT_IN_VPS
+  ChromaFormat chromaFormatIdc = m_acLayerCfg[layer].getChromaFormatIDC();
+  Int xScal = TComSPS::getWinUnitX( chromaFormatIdc );
+  Int yScal = TComSPS::getWinUnitY( chromaFormatIdc );
+#endif
+
   if (m_isField)
   {
@@ -2054,5 +2153,10 @@
 #endif
       {
+#if REPN_FORMAT_IN_VPS
+        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRecTop, pcPicYuvRecBottom, m_acLayerCfg[layer].getConfLeft() * xScal, m_acLayerCfg[layer].getConfRight() * xScal, 
+          m_acLayerCfg[layer].getConfTop() * yScal, m_acLayerCfg[layer].getConfBottom() * yScal, m_isTopFieldFirst );
+#else
         m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRecTop, pcPicYuvRecBottom, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(), m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom(), m_isTopFieldFirst );
+#endif
       }
     }
@@ -2078,6 +2182,11 @@
 #endif
       {
+#if REPN_FORMAT_IN_VPS
+        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft() * xScal, m_acLayerCfg[layer].getConfRight() * xScal,
+          m_acLayerCfg[layer].getConfTop() * yScal, m_acLayerCfg[layer].getConfBottom() * yScal );
+#else
         m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(),
           m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom() );
+#endif
       }
     }
Index: trunk/source/App/utils/BLRewrite/BLRewrite.c
===================================================================
--- trunk/source/App/utils/BLRewrite/BLRewrite.c	(revision 815)
+++ trunk/source/App/utils/BLRewrite/BLRewrite.c	(revision 815)
@@ -0,0 +1,274 @@
+/* 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-2014, 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.
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+
+
+enum NalUnitType
+{
+  NAL_UNIT_CODED_SLICE_TRAIL_N = 0,   // 0
+  NAL_UNIT_CODED_SLICE_TRAIL_R,   // 1
+
+  NAL_UNIT_CODED_SLICE_TSA_N,     // 2
+  NAL_UNIT_CODED_SLICE_TSA_R,       // 3
+
+  NAL_UNIT_CODED_SLICE_STSA_N,    // 4
+  NAL_UNIT_CODED_SLICE_STSA_R,    // 5
+
+  NAL_UNIT_CODED_SLICE_RADL_N,    // 6
+  NAL_UNIT_CODED_SLICE_RADL_R,      // 7
+
+  NAL_UNIT_CODED_SLICE_RASL_N,    // 8
+  NAL_UNIT_CODED_SLICE_RASL_R,      // 9
+
+  NAL_UNIT_RESERVED_VCL_N10,
+  NAL_UNIT_RESERVED_VCL_R11,
+  NAL_UNIT_RESERVED_VCL_N12,
+  NAL_UNIT_RESERVED_VCL_R13,
+  NAL_UNIT_RESERVED_VCL_N14,
+  NAL_UNIT_RESERVED_VCL_R15,
+
+  NAL_UNIT_CODED_SLICE_BLA_W_LP,    // 16
+  NAL_UNIT_CODED_SLICE_BLA_W_RADL,  // 17
+  NAL_UNIT_CODED_SLICE_BLA_N_LP,  // 18
+  NAL_UNIT_CODED_SLICE_IDR_W_RADL,  // 19
+  NAL_UNIT_CODED_SLICE_IDR_N_LP,  // 20
+  NAL_UNIT_CODED_SLICE_CRA,       // 21
+  NAL_UNIT_RESERVED_IRAP_VCL22,
+  NAL_UNIT_RESERVED_IRAP_VCL23,
+
+  NAL_UNIT_RESERVED_VCL24,
+  NAL_UNIT_RESERVED_VCL25,
+  NAL_UNIT_RESERVED_VCL26,
+  NAL_UNIT_RESERVED_VCL27,
+  NAL_UNIT_RESERVED_VCL28,
+  NAL_UNIT_RESERVED_VCL29,
+  NAL_UNIT_RESERVED_VCL30,
+  NAL_UNIT_RESERVED_VCL31,
+
+  NAL_UNIT_VPS,                   // 32
+  NAL_UNIT_SPS,                   // 33
+  NAL_UNIT_PPS,                   // 34
+  NAL_UNIT_ACCESS_UNIT_DELIMITER, // 35
+  NAL_UNIT_EOS,                   // 36
+  NAL_UNIT_EOB,                   // 37
+  NAL_UNIT_FILLER_DATA,           // 38
+  NAL_UNIT_PREFIX_SEI,              // 39
+  NAL_UNIT_SUFFIX_SEI,              // 40
+  NAL_UNIT_RESERVED_NVCL41,
+  NAL_UNIT_RESERVED_NVCL42,
+  NAL_UNIT_RESERVED_NVCL43,
+  NAL_UNIT_RESERVED_NVCL44,
+  NAL_UNIT_RESERVED_NVCL45,
+  NAL_UNIT_RESERVED_NVCL46,
+  NAL_UNIT_RESERVED_NVCL47,
+  NAL_UNIT_UNSPECIFIED_48,
+  NAL_UNIT_UNSPECIFIED_49,
+  NAL_UNIT_UNSPECIFIED_50,
+  NAL_UNIT_UNSPECIFIED_51,
+  NAL_UNIT_UNSPECIFIED_52,
+  NAL_UNIT_UNSPECIFIED_53,
+  NAL_UNIT_UNSPECIFIED_54,
+  NAL_UNIT_UNSPECIFIED_55,
+  NAL_UNIT_UNSPECIFIED_56,
+  NAL_UNIT_UNSPECIFIED_57,
+  NAL_UNIT_UNSPECIFIED_58,
+  NAL_UNIT_UNSPECIFIED_59,
+  NAL_UNIT_UNSPECIFIED_60,
+  NAL_UNIT_UNSPECIFIED_61,
+  NAL_UNIT_UNSPECIFIED_62,
+  NAL_UNIT_UNSPECIFIED_63,
+  NAL_UNIT_INVALID,
+};
+
+typedef struct NalUnitHeader_s
+{
+  int nalUnitType;
+  int nuhLayerId;
+  int nuhTemporalIdPlus1;
+} NalUnitHeader;
+
+
+int findStartCodePrefix(FILE *inFile, int *numStartCodeZeros)
+{
+  int numZeros = 0;
+  int currByte;
+  
+  while (1)
+  {
+    currByte = fgetc(inFile);
+    if (currByte == EOF)
+    {
+      return 0;
+    }
+
+    if (currByte == 0x01 && numZeros > 1)
+    {
+      *numStartCodeZeros = numZeros;
+      return 1;
+    }
+    else if (currByte == 0)
+    {
+      numZeros++;
+    }
+    else
+    {
+      numZeros = 0;
+    }
+  }
+}
+
+int parseNalUnitHeader(FILE *inFile, NalUnitHeader *nalu)
+{
+  int byte0, byte1;
+
+  byte0 = fgetc(inFile);
+  byte1 = fgetc(inFile);
+
+  if (byte0 == EOF || byte1 == EOF)
+  {
+    return 0;
+  }
+
+  nalu->nalUnitType = (byte0 >> 1) & 0x3f;
+  nalu->nuhLayerId  = (((byte0 << 8) | byte1) >> 3) & 0x3f;
+  nalu->nuhTemporalIdPlus1 = byte1 & 0x07;
+
+  return 1;
+}
+
+void writeStartCodePrefixAndNUH(FILE *outFile, int numStartCodeZeros, NalUnitHeader *nalu)
+{
+  int byte0, byte1;
+  int i;
+
+  /* Start code prefix */
+  if (numStartCodeZeros > 3)
+  {
+    numStartCodeZeros = 3;
+  }
+  for (i = 0; i < numStartCodeZeros; i++)
+  {
+    fputc(0, outFile);
+  }
+  fputc(0x01, outFile);
+
+  /* NAL unit header */
+  byte0 = ((nalu->nalUnitType << 6) | nalu->nuhLayerId) >> 5;
+  byte1 = ((nalu->nuhLayerId << 3) | nalu->nuhTemporalIdPlus1) & 0xff;
+  fputc(byte0, outFile);
+  fputc(byte1, outFile);
+}
+
+int main(int argc, char **argv)
+{
+  FILE *inFile;
+  FILE *outFile;
+  int assignedBaseLayerId;
+  NalUnitHeader nalu;
+  int numStartCodeZeros;
+  int isSpsPpsEosEob;
+
+  if (argc < 3)
+  {
+    printf("Usage: Splicer <infile> <outfile> <assigned base layer ID>\n", argv[0]);
+  }
+
+  inFile = fopen(argv[1], "rb");
+  if (inFile == NULL)
+  {
+    fprintf(stderr, "Cannot open input file %s\n", argv[1]);
+    exit(1);
+  }
+
+  outFile = fopen(argv[2], "wb");
+  if (outFile == NULL)
+  {
+    fprintf(stderr, "Cannot open output file %s\n", argv[2]);
+    exit(1);
+  }
+
+  assignedBaseLayerId = atoi(argv[3]);
+
+  while (1)
+  {
+    if (!findStartCodePrefix(inFile, &numStartCodeZeros))
+    {
+      break;
+    }
+    if (!parseNalUnitHeader(inFile, &nalu))
+    {
+      break;
+    }
+
+    printf("NAL unit type: %i,  NUH layer ID: %i,  NUH Temporal ID: %i\n", nalu.nalUnitType, nalu.nuhLayerId, nalu.nuhTemporalIdPlus1 - 1);
+
+    isSpsPpsEosEob = (nalu.nalUnitType == NAL_UNIT_SPS || nalu.nalUnitType == NAL_UNIT_PPS || nalu.nalUnitType == NAL_UNIT_EOS || nalu.nalUnitType == NAL_UNIT_EOB);
+
+    if ((isSpsPpsEosEob && nalu.nuhLayerId == 0) || (!isSpsPpsEosEob && nalu.nuhLayerId == assignedBaseLayerId))
+    {
+      /* Write current NAL unit to output bitstream */
+
+      long naluBytesStartPos;
+      long numNaluBytes;
+      long i;
+
+      nalu.nuhLayerId = 0;
+      writeStartCodePrefixAndNUH(outFile, numStartCodeZeros, &nalu);
+
+      naluBytesStartPos = ftell(inFile);
+      /* Find beginning of the next NAL unit to calculate length of the current unit */
+      if (findStartCodePrefix(inFile, &numStartCodeZeros))
+      {
+        numNaluBytes = ftell(inFile) - naluBytesStartPos - numStartCodeZeros - 1;
+      }
+      else
+      {
+        numNaluBytes = ftell(inFile) - naluBytesStartPos;
+      }
+      fseek(inFile, naluBytesStartPos, SEEK_SET);
+
+      for (i = 0; i < numNaluBytes; i++)
+      {
+        fputc(fgetc(inFile), outFile);
+      }
+    }
+  }
+
+  fclose(inFile);
+  fclose(outFile);
+
+
+  return 0;
+}
Index: trunk/source/App/utils/BLRewrite/ReadMe.txt
===================================================================
--- trunk/source/App/utils/BLRewrite/ReadMe.txt	(revision 815)
+++ trunk/source/App/utils/BLRewrite/ReadMe.txt	(revision 815)
@@ -0,0 +1,17 @@
+
+This is a simple tool that extracts an independent non-base layer from a multi-layer bitstream, converts it to a base-layer bistream and writes it to a file. The tool is invoked as follows. 
+
+  BLRewrite <infile> <outfile> <layer ID of the extracted layer>
+
+The tool is based on the contribution JCTVC-Q0078 / JCTVC-R0042. Sub-bitstream extraction process done by the tool can be summarized as follows.
+
+- NAL units with nal_unit_type not equal to SPS_NUT, PPS_NUT, EOS_NUT and EOB_NUT and with nuh_layer_id not equal to the assignedBaseLayerId are removed from outBitstream.
+- NAL units with nal_unit_type equal to SPS_NUT, PPS_NUT, EOS_NUT or EOB_NUT with nuh_layer_id not equal to 0 are removed from outBitstream.
+- For each NAL unit, the following applies:
+   When nuh_layer_id is equal to assignedBaseLayerId, nuh_layer_id is set equal to 0.
+
+The resulting bitstream can be decoded with an HEVC/H.265 v1 compliant decoder as long as the extracted independent layer conform with v1 specification text. The tool removes VPS from the output bitstream so an HEVC/H.265 decoder should not expect it to be present.
+
+
+
+
Index: trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/CommonDef.h	(revision 752)
+++ trunk/source/Lib/TLibCommon/CommonDef.h	(revision 815)
@@ -58,5 +58,5 @@
 #if SVC_EXTENSION
 #include <vector>
-#define NV_VERSION        "6.0 (HM-14.0)"                 ///< Current software version
+#define NV_VERSION        "6.1 (HM-14.0)"                 ///< Current software version
 #else
 #define NV_VERSION        "14.0"                ///< Current software version
Index: trunk/source/Lib/TLibCommon/SEI.h
===================================================================
--- trunk/source/Lib/TLibCommon/SEI.h	(revision 752)
+++ trunk/source/Lib/TLibCommon/SEI.h	(revision 815)
@@ -37,4 +37,8 @@
 #include <cstring>
 
+#if Q0078_ADD_LAYER_SETS
+#include "TLibCommon/NAL.h"
+#endif
+
 //! \ingroup TLibCommon
 //! \{
@@ -66,4 +70,7 @@
     POST_FILTER_HINT                     = 22,
     TONE_MAPPING_INFO                    = 23,
+#if P0050_KNEE_FUNCTION_SEI
+    KNEE_FUNCTION_INFO                   = 24,
+#endif
     FRAME_PACKING                        = 45,
     DISPLAY_ORIENTATION                  = 47,
@@ -91,4 +98,14 @@
 #if Q0074_SEI_COLOR_MAPPING
     COLOR_MAPPING_INFO                   = 143,
+#endif
+#if Q0078_ADD_LAYER_SETS
+    OUTPUT_LAYER_SET_NESTING             = 144,
+    VPS_REWRITING                        = 145,
+#endif
+#if Q0189_TMVP_CONSTRAINTS
+    TMVP_CONSTRAINTS                     = 146,
+#endif
+#if Q0247_FRAME_FIELD_INFO
+    FRAME_FIELD_INFO                     = 147,
 #endif
   };
@@ -407,5 +424,25 @@
   Int    m_extendedWhiteLevelLumaCodeValue;
 };
-
+#if P0050_KNEE_FUNCTION_SEI
+class SEIKneeFunctionInfo : public SEI
+{
+public:
+  PayloadType payloadType() const { return KNEE_FUNCTION_INFO; }
+  SEIKneeFunctionInfo() {}
+  virtual ~SEIKneeFunctionInfo() {}
+
+  Int   m_kneeId;
+  Bool  m_kneeCancelFlag;
+  Bool  m_kneePersistenceFlag;
+  Bool  m_kneeMappingFlag;
+  Int   m_kneeInputDrange;
+  Int   m_kneeInputDispLuminance;
+  Int   m_kneeOutputDrange;
+  Int   m_kneeOutputDispLuminance;
+  Int   m_kneeNumKneePointsMinus1;
+  std::vector<Int> m_kneeInputKneePoint;
+  std::vector<Int> m_kneeOutputKneePoint;
+};
+#endif
 #if Q0074_SEI_COLOR_MAPPING
 class SEIColorMappingInfo : public SEI
@@ -486,4 +523,44 @@
 #endif
 
+#if Q0189_TMVP_CONSTRAINTS
+class SEITMVPConstrains : public SEI
+{
+public:
+  PayloadType payloadType() const { return TMVP_CONSTRAINTS; }
+
+  SEITMVPConstrains()
+    : prev_pics_not_used_flag(0),no_intra_layer_col_pic_flag(0)
+    {}
+
+  virtual ~SEITMVPConstrains()
+  {
+  }
+
+  UInt prev_pics_not_used_flag;
+  UInt no_intra_layer_col_pic_flag;
+};
+#endif
+
+#if Q0247_FRAME_FIELD_INFO 
+class SEIFrameFieldInfo: public SEI
+{
+public:
+  PayloadType payloadType() const { return FRAME_FIELD_INFO; }
+
+  SEIFrameFieldInfo()
+    : m_ffinfo_picStruct(0),m_ffinfo_sourceScanType(0), m_ffinfo_duplicateFlag(false)
+    {}
+
+  virtual ~SEIFrameFieldInfo()
+  {
+  }
+
+  UInt  m_ffinfo_picStruct;
+  UInt  m_ffinfo_sourceScanType;
+  Bool  m_ffinfo_duplicateFlag;
+};
+
+#endif
+
 typedef std::list<SEI*> SEIMessages;
 
@@ -583,3 +660,37 @@
 };
 
+#if Q0078_ADD_LAYER_SETS
+class SEIOutputLayerSetNesting : public SEI
+{
+public:
+  PayloadType payloadType() const { return OUTPUT_LAYER_SET_NESTING; }
+
+  SEIOutputLayerSetNesting() {}
+  virtual ~SEIOutputLayerSetNesting()
+  {
+    if (!m_callerOwnsSEIs)
+    {
+      deleteSEIs(m_nestedSEIs);
+    }
+  }
+
+  Bool m_olsFlag;
+  UInt m_numOlsIndicesMinus1;
+  UInt m_olsIdx[1024];
+  Bool  m_callerOwnsSEIs;
+  SEIMessages m_nestedSEIs;
+};
+
+class SEIVPSRewriting : public SEI
+{
+public:
+  PayloadType payloadType() const { return VPS_REWRITING; }
+
+  SEIVPSRewriting() {}
+  virtual ~SEIVPSRewriting() {}
+
+  NALUnit* nalu;
+};
+#endif
+
 //! \}
Index: trunk/source/Lib/TLibCommon/TCom3DAsymLUT.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TCom3DAsymLUT.cpp	(revision 752)
+++ trunk/source/Lib/TLibCommon/TCom3DAsymLUT.cpp	(revision 815)
@@ -44,5 +44,7 @@
 
   if( m_pCuboid != NULL )
+  {
     destroy();
+  }
   xAllocate3DArray( m_pCuboid , m_nYSize , m_nUSize , m_nVSize );
 }
@@ -88,17 +90,6 @@
 
   // alignment padding
-  pU += (nWidth>>1);
-  pV += (nWidth>>1);
-  for( Int y = 0 ; y < (nHeight>>1) ; y ++ )
-  {
-    *pU = pU[-1];
-    *pV = pV[-1];
-    pU += nStrideC;
-    pV += nStrideC;
-  }
-  memcpy(pU-(nWidth>>1), pU-(nWidth>>1)-nStrideC, ((nWidth>>1)+1)*sizeof(Pel));
-  memcpy(pV-(nWidth>>1), pV-(nWidth>>1)-nStrideC, ((nWidth>>1)+1)*sizeof(Pel));
-  pU = pcPic->getCbAddr();
-  pV = pcPic->getCrAddr();
+  pcPic->setBorderExtension( false );
+  pcPic->extendPicBorder();
 
   Pel iMaxValY = (1<<getOutputBitDepthY())-1;
Index: trunk/source/Lib/TLibCommon/TCom3DAsymLUT.h
===================================================================
--- trunk/source/Lib/TLibCommon/TCom3DAsymLUT.h	(revision 752)
+++ trunk/source/Lib/TLibCommon/TCom3DAsymLUT.h	(revision 815)
@@ -100,10 +100,14 @@
   p[0] = new T*[xSize*ySize];
   for( Int x = 1 ; x < xSize ; x++ )
+  {
     p[x] = p[x-1] + ySize;
+  }
   p[0][0] = new T[xSize*ySize*zSize];
   for( Int x = 0 ; x < xSize ; x++ )
   {
     for( Int y = 0 ; y < ySize ; y++ )
+    {
       p[x][y] = p[0][0] + x * ySize * zSize + y * zSize;
+    }
   }
 }
@@ -117,5 +121,7 @@
     {
       if( p[0][0] != NULL )
+      {
         delete [] p[0][0];
+      }
       delete [] p[0];
     }
Index: trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 752)
+++ trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 815)
@@ -3517,10 +3517,21 @@
 #endif
 
-#if N0139_POSITION_ROUNDING_OFFSET
+#if REF_IDX_MFM
+  // offset for collocated block in the motion mapping
   if( iMotionMapping == 1 )
   {
+    Bool unequalPictureSizeFlag = g_posScalingFactor[refLayerIdc][0] != 65536 || g_posScalingFactor[refLayerIdc][1] != 65536; //the condition should be updated according to the WD.
+
     // actually, motion field compression is performed in the Void TComPic::compressMotion() function, but with (+4) the rounding may have effect on the picture boundary check.
-    iBX = ( ( iBX + 4 ) >> 4 ) << 4;
-    iBY = ( ( iBY + 4 ) >> 4 ) << 4;
+    if( unequalPictureSizeFlag )
+    {
+      iBX = ( ( iBX + 4 ) >> 4 ) << 4;
+      iBY = ( ( iBY + 4 ) >> 4 ) << 4;
+    }
+    else
+    {
+      iBX += 4;
+      iBY += 4;
+    }
   }
 #endif
@@ -3637,7 +3648,13 @@
   {
     Int refIdxL0 = cMvFieldL0.getRefIdx();
-    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId))
+    TComPic* refPic = m_pcSlice->getRefPic(REF_PIC_LIST_0, refIdxL0);
+
+    if(refPic->isILR(m_layerId))
     {
       checkZeroMVILR &= (cMvFieldL0.getHor() == 0 && cMvFieldL0.getVer() == 0);
+
+      // It is a requirement of bitstream conformance that when the reference picture represented by the variable refIdxLX is an inter-layer reference picture, 
+      // VpsInterLayerSamplePredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture
+      checkZeroMVILR &= m_pcSlice->getVPS()->isSamplePredictionType( m_layerId, refPic->getLayerId() );
     }
   }
@@ -3645,7 +3662,13 @@
   {
     Int refIdxL1  = cMvFieldL1.getRefIdx();
-    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId))
+    TComPic* refPic = m_pcSlice->getRefPic(REF_PIC_LIST_1, refIdxL1);
+
+    if(refPic->isILR(m_layerId))
     {
       checkZeroMVILR &= (cMvFieldL1.getHor() == 0 && cMvFieldL1.getVer() == 0);
+
+      // It is a requirement of bitstream conformance that when the reference picture represented by the variable refIdxLX is an inter-layer reference picture, 
+      // VpsInterLayerSamplePredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture
+      checkZeroMVILR &= m_pcSlice->getVPS()->isSamplePredictionType( m_layerId, refPic->getLayerId() );
     }
   }
Index: trunk/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 752)
+++ trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 815)
@@ -72,5 +72,5 @@
 {
 }
-#if SVC_UPSAMPLING
+#if SVC_EXTENSION
 #if AUXILIARY_PICTURES
 Void TComPic::create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
@@ -184,5 +184,5 @@
   
   deleteSEIs(m_SEIs);
-#if SVC_EXTENSION && SVC_UPSAMPLING
+#if SVC_EXTENSION
   for( Int i = 0; i < MAX_LAYERS; i++ )
   {
Index: trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.h	(revision 752)
+++ trunk/source/Lib/TLibCommon/TComPic.h	(revision 815)
@@ -92,26 +92,24 @@
   Int                   m_nFrameBit;
 #endif
-
+#if POC_RESET_IDC_DECODER
+  Bool                  m_currAuFlag;
+#endif
 public:
   TComPic();
   virtual ~TComPic();
   
+#if SVC_EXTENSION
 #if AUXILIARY_PICTURES
-#if SVC_UPSAMPLING
   Void          create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
                         Int *numReorderPics, TComSPS* pcSps = NULL, Bool bIsVirtual = false );
 #else
-  Void          create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
-                        Int *numReorderPics, Bool bIsVirtual = false );                        
-#endif
-#else
-#if SVC_UPSAMPLING
   Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
                         Int *numReorderPics, TComSPS* pcSps = NULL, Bool bIsVirtual = false );
+#endif
 #else
   Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
-                        Int *numReorderPics, Bool bIsVirtual = false );                        
-#endif
-#endif
+                        Int *numReorderPics, Bool bIsVirtual = false ); 
+#endif //SVC_EXTENSION 
+
   virtual Void  destroy();
   
@@ -202,5 +200,5 @@
   TComPicYuv*   getFullPelBaseRec   (UInt refLayerIdc)  { return  m_pcFullPelBaseRec[refLayerIdc];  }
 #if REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
-  Bool          isILR( UInt currLayerId )   { return ( getIsLongTerm() && m_layerId < currLayerId ); }
+  Bool          isILR( UInt currLayerId )   { return ( m_bIsLongTerm && m_layerId < currLayerId ); }
 #endif
 #if REF_IDX_MFM
@@ -227,4 +225,8 @@
   Int   getFrameBit()         { return m_nFrameBit; }
 #endif
+#if POC_RESET_IDC_DECODER
+  Bool isCurrAu() { return m_currAuFlag; }
+  Void setCurrAuFlag(Bool x) {m_currAuFlag = x; }
+#endif
 };// END CLASS DEFINITION TComPic
 
Index: trunk/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 752)
+++ trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 815)
@@ -67,22 +67,19 @@
 {
 }
+
+#if SVC_EXTENSION
 #if AUXILIARY_PICTURES
-#if SVC_UPSAMPLING
 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps )
 #else
-Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth )
-#endif
-#else
-#if SVC_UPSAMPLING
 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps )
+#endif
 #else
 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth )
 #endif
-#endif
 {
   m_iPicWidth       = iPicWidth;
   m_iPicHeight      = iPicHeight;
   
-#if SVC_UPSAMPLING
+#if SVC_EXTENSION
   if(pcSps != NULL)
   {
@@ -369,4 +366,70 @@
 }
 
+#if SVC_EXTENSION
+Void TComPicYuv::dump( Char* pFileName, Bool bAdd, Int bitDepth )
+{
+  FILE* pFile;
+  if (!bAdd)
+  {
+    pFile = fopen (pFileName, "wb");
+  }
+  else
+  {
+    pFile = fopen (pFileName, "ab");
+  }
+
+  if( bitDepth == 8 )
+  {
+    dump( pFileName, bAdd );
+    return;
+  }
+  
+  Int   x, y;
+  UChar uc;
+  
+  Pel*  piY   = getLumaAddr();
+  Pel*  piCb  = getCbAddr();
+  Pel*  piCr  = getCrAddr();
+  
+  for ( y = 0; y < m_iPicHeight; y++ )
+  {
+    for ( x = 0; x < m_iPicWidth; x++ )
+    {
+      uc = piY[x] & 0xff;      
+      fwrite( &uc, sizeof(UChar), 1, pFile );
+      uc = (piY[x] >> 8) & 0xff;      
+      fwrite( &uc, sizeof(UChar), 1, pFile );
+    }
+    piY += getStride();
+  }
+  
+  for ( y = 0; y < m_iPicHeight >> 1; y++ )
+  {
+    for ( x = 0; x < m_iPicWidth >> 1; x++ )
+    {
+      uc = piCb[x] & 0xff;
+      fwrite( &uc, sizeof(UChar), 1, pFile );
+      uc = (piCb[x] >> 8) & 0xff;
+      fwrite( &uc, sizeof(UChar), 1, pFile );
+    }
+    piCb += getCStride();
+  }
+  
+  for ( y = 0; y < m_iPicHeight >> 1; y++ )
+  {
+    for ( x = 0; x < m_iPicWidth >> 1; x++ )
+    {
+      uc = piCr[x] & 0xff;
+      fwrite( &uc, sizeof(UChar), 1, pFile );
+      uc = (piCr[x] >> 8) & 0xff;
+      fwrite( &uc, sizeof(UChar), 1, pFile );
+    }
+    piCr += getCStride();
+  }
+  
+  fclose(pFile);
+}
+
+#endif
 
 //! \}
Index: trunk/source/Lib/TLibCommon/TComPicYuv.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicYuv.h	(revision 752)
+++ trunk/source/Lib/TLibCommon/TComPicYuv.h	(revision 815)
@@ -42,5 +42,5 @@
 #include "CommonDef.h"
 #include "TComRom.h"
-#if SVC_UPSAMPLING
+#if SVC_EXTENSION
 #include "TComSlice.h"
 #endif
@@ -94,7 +94,5 @@
   ChromaFormat m_chromaFormatIDC; ////< Chroma Format
 #endif
-#if SVC_UPSAMPLING
   Window  m_conformanceWindow;
-#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   Bool    m_isReconstructed;
@@ -112,17 +110,13 @@
   //  Memory management
   // ------------------------------------------------------------------------------------------------
+#if SVC_EXTENSION
 #if AUXILIARY_PICTURES
-#if SVC_UPSAMPLING
   Void  create      ( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps = NULL);
 #else
-  Void  create      ( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth );
-#endif  
-#else
-#if SVC_UPSAMPLING
   Void  create      ( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps = NULL);
+#endif
 #else
   Void  create      ( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth );
-#endif  
-#endif
+#endif //SVC_EXTENSION
   
   Void  destroy     ();
@@ -187,8 +181,6 @@
 #if SVC_EXTENSION
   Void   setHeight   ( Int iPicHeight )     { m_iPicHeight = iPicHeight; }
-#if SVC_UPSAMPLING
   Window& getConformanceWindow()                           { return  m_conformanceWindow;             }
   Void    setConformanceWindow(Window& conformanceWindow ) { m_conformanceWindow = conformanceWindow; }
-#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   Void  setReconstructed(Bool x) { m_isReconstructed = x;    }
@@ -199,4 +191,5 @@
   Void convertToMonochrome();
 #endif
+  Void dump( Char* pFileName, Bool bAdd, Int bitDepth );
 #endif //SVC_EXTENSION
 
Index: trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 752)
+++ trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 815)
@@ -487,6 +487,22 @@
   pcCU->clipMv(cMv);
 
+#if SVC_EXTENSION
+  if( pcCU->getLayerId() > 0 )
+  {
+    TComPic* refPic = pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx);
+
+    if( refPic->isILR(pcCU->getLayerId()) )
+    {
+      // It is a requirement of bitstream conformance that when the reference picture represented by the variable refIdxLX is an inter-layer reference picture, 
+      // VpsInterLayerSamplePredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture
+      assert( pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerId(), refPic->getLayerId() ) );
+
 #if REF_IDX_ME_ZEROMV
-  assert( ( pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(pcCU->getLayerId()) && cMv.getHor() == 0 && cMv.getVer() == 0 ) || pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(pcCU->getLayerId()) == false );
+      // It is a requirement of bitstream conformance that the variables mvLX[ 0 ] and mvLX[ 1 ] shall be equal to 0 if the value of refIdxLX corresponds to an inter-layer reference picture. 
+      assert( cMv.getHor() == 0 && cMv.getVer() == 0 );
+#endif
+    }
+
+  }
 #endif
 
@@ -765,5 +781,5 @@
 }
 
-#if SVC_UPSAMPLING
+#if SVC_EXTENSION
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
@@ -791,4 +807,4 @@
 #endif
 #endif
-#endif
+#endif //SVC_EXTENSION
 //! \}
Index: trunk/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 752)
+++ trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 815)
@@ -48,5 +48,5 @@
 #include "TComWeightPrediction.h"
 
-#if SVC_UPSAMPLING
+#if SVC_EXTENSION
 #include "TComUpsampleFilter.h"
 #endif
@@ -72,8 +72,4 @@
   
   TComInterpolationFilter m_if;
-  
-#if SVC_UPSAMPLING
-  TComUpsampleFilter      m_cUsf;
-#endif
 
   Pel*   m_pLumaRecBuffer;       ///< array for downsampled reconstructed luma sample 
@@ -94,4 +90,8 @@
   Void xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight );
   Bool xCheckIdenticalMotion    ( TComDataCU* pcCU, UInt PartAddr);
+  
+#if SVC_EXTENSION
+  TComUpsampleFilter      m_cUsf;
+#endif
 
 public:
@@ -118,5 +118,4 @@
 
 #if SVC_EXTENSION
-#if SVC_UPSAMPLING
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
@@ -132,5 +131,4 @@
 #endif
 #endif
-#endif
 #endif //SVC_EXTENSION
 };
Index: trunk/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 752)
+++ trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 815)
@@ -527,37 +527,42 @@
   {
   case NAL_UNIT_CODED_SLICE_TRAIL_N:
+    return "TRAIL_N";
   case NAL_UNIT_CODED_SLICE_TRAIL_R:
-    return "TRAIL";
+    return "TRAIL_R";
   
   case NAL_UNIT_CODED_SLICE_TSA_N:
+    return "  TSA_N";
   case NAL_UNIT_CODED_SLICE_TSA_R:
-    return "  TSA";
+    return "  TSA_R";
   
   case NAL_UNIT_CODED_SLICE_STSA_N:
+    return " STSA_N";
   case NAL_UNIT_CODED_SLICE_STSA_R:
-    return " STSA";
+    return " STSA_R";
 
   case NAL_UNIT_CODED_SLICE_RADL_N:
+    return " RADL_N";
   case NAL_UNIT_CODED_SLICE_RADL_R:
-    return " RADL";
+    return " RADL_R";
   
   case NAL_UNIT_CODED_SLICE_RASL_N:
+    return " RASL_N";
   case NAL_UNIT_CODED_SLICE_RASL_R:
-    return " RASL";
+    return " RASL_R";
 
   case NAL_UNIT_CODED_SLICE_BLA_W_LP:
   case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
   case NAL_UNIT_CODED_SLICE_BLA_N_LP:
-    return "  BLA";
+    return "    BLA";
 
   case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
   case NAL_UNIT_CODED_SLICE_IDR_N_LP:
-    return "  IDR";
+    return "    IDR";
   
   case NAL_UNIT_CODED_SLICE_CRA:
-    return "  CRA";
+    return "    CRA";
 
   default:
-    return "     ";
+    return "       ";
   };
 }
Index: trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 752)
+++ trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 815)
@@ -125,4 +125,7 @@
 , m_pocMsbValPresentFlag          ( false )
 #endif
+#if POC_RESET_IDC_DECODER || POC_RESET_IDC_ENCODER
+, m_picOrderCntLsb (0)
+#endif
 #endif //SVC_EXTENSION
 {
@@ -200,4 +203,16 @@
   m_numEntryPointOffsets = 0;
   m_enableTMVPFlag = true;
+#if POC_RESET_IDC_SIGNALLING
+  m_pocResetIdc                   = 0;
+  m_pocResetPeriodId              = 0;
+  m_fullPocResetFlag              = false;
+  m_pocLsbVal                     = 0;
+  m_pocMsbVal                     = 0;
+  m_pocMsbValRequiredFlag         = false;
+  m_pocMsbValPresentFlag          = false;
+#endif
+#if POC_RESET_IDC_DECODER || POC_RESET_IDC_ENCODER
+  m_picOrderCntLsb = 0;
+#endif
 }
 
@@ -223,5 +238,47 @@
 }
 #endif
-
+#if POC_RESET_IDC_DECODER
+Bool TComSlice::getRaslPicFlag      ()
+{
+  return  getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R
+  || getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N;
+}
+Bool TComSlice::getRadlPicFlag      ()
+{
+  return  getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R
+  || getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N;
+}
+#endif
+#if POC_RESET_IDC_ENCODER
+Void TComSlice::decrementRefPocValues(Int const decrementValue)
+{
+  for(Int listNum = 0; listNum < 2; listNum++)
+  {
+    RefPicList dpbPicSliceList = (listNum == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
+    for(Int listIdx = 0; listIdx < getNumRefIdx( dpbPicSliceList ); listIdx++)
+    {
+      setRefPOC( getRefPOC(dpbPicSliceList, listIdx) - decrementValue, 
+                  dpbPicSliceList,
+                  listIdx
+                  );
+    }
+  }
+}
+Int TComSlice::getCurrMsb( Int currLsb, Int prevLsb, Int prevMsb, Int maxLsbVal )
+{
+  if( prevLsb - currLsb >= (maxLsbVal >> 1) )
+  {
+    return prevMsb + maxLsbVal;
+  }
+  else if( currLsb - prevLsb > (maxLsbVal >> 1) )
+  {
+    return prevMsb - maxLsbVal;
+  }
+  else
+  {
+    return prevMsb;
+  }
+}
+#endif
 /**
  - allocate table to contain substream sizes to be written to the slice header.
@@ -279,5 +336,9 @@
   while ( iterPic != rcListPic.end() )
   {
+#if POC_RESET_IDC_ENCODER
+    if( (pcPic->getPOC() == poc) && (pcPic->getSlice(0)->isReferenced()) )
+#else
     if(pcPic->getPOC() == poc)
+#endif
     {
       break;
@@ -293,5 +354,5 @@
     pcPic = *(iterPic);
   }
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_DECODER
   assert( pcPic->getSlice(0)->isReferenced() );
 #endif
@@ -512,9 +573,5 @@
     }
 #if MAX_ONE_RESAMPLING_DIRECT_LAYERS
-#if SCALABILITY_MASK_E0104
-    if( m_pcVPS->getScalabilityMask(2) )
-#else
-    if( m_pcVPS->getScalabilityMask(1) )
-#endif
+    if( m_pcVPS->getScalabilityMask( SCALABILITY_ID ) )
     {
       Int numResampler = 0;
@@ -550,7 +607,7 @@
 #endif
 #if O0194_DIFFERENT_BITDEPTH_EL_BL
-        Int sameBitDepth = g_bitDepthYLayer[m_layerId] - g_bitDepthYLayer[refLayerId] + g_bitDepthCLayer[m_layerId] - g_bitDepthCLayer[refLayerId];
-
-        if( !( g_posScalingFactor[refLayerIdc][0] == 65536 && g_posScalingFactor[refLayerIdc][1] == 65536 ) || !scalingOffset || !sameBitDepth 
+        Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
+
+        if( !( g_posScalingFactor[refLayerIdc][0] == 65536 && g_posScalingFactor[refLayerIdc][1] == 65536 ) || !scalingOffset || !sameBitDepths 
 #if Q0048_CGS_3D_ASYMLUT
           || getPPS()->getCGSFlag()
@@ -775,21 +832,19 @@
 #endif
 
-#if N0147_IRAP_ALIGN_FLAG
   assert(m_aiNumRefIdx[REF_PIC_LIST_0] > 0);
   assert(m_aiNumRefIdx[REF_PIC_LIST_1] > 0);
-#else
-  assert(m_aiNumRefIdx[REF_PIC_LIST_0] > 1);
-  assert(m_aiNumRefIdx[REF_PIC_LIST_1] > 1);
-#endif
 
   //set L0 inter-layer reference picture modification
 #if RPL_INIT_N0316_N0082
   Bool hasModification = (m_aiNumRefIdx[REF_PIC_LIST_0] == (numberOfPocBeforeCurr + m_activeNumILRRefIdx)) ? false : true;
+
+  if( m_activeNumILRRefIdx > 1 )
+  {
+    hasModification = (m_aiNumRefIdx[REF_PIC_LIST_0] >= (numberOfPocBeforeCurr + m_activeNumILRRefIdx)) ? false : true;
+  }
 #else
   Bool hasModification = (m_aiNumRefIdx[REF_PIC_LIST_0] == numberOfRpsCurrTempList) ? false : true;
 #endif
-#if N0147_IRAP_ALIGN_FLAG
   hasModification = hasModification && ( m_aiNumRefIdx[REF_PIC_LIST_0] > 1 );
-#endif
   refPicListModification->setRefPicListModificationFlagL0(hasModification);
   if(hasModification)
@@ -799,7 +854,8 @@
       refPicListModification->setRefPicSetIdxL0(i, i);
     }
+
     if(m_aiNumRefIdx[REF_PIC_LIST_0] > numberOfRpsCurrTempList)
     {
-        // repeat last ref pic when the number of active ref idx are more than RPS entries
+      // repeat last ref pic when the number of active ref idx are more than RPS entries
       for (Int i = numberOfRpsCurrTempList; i < m_aiNumRefIdx[REF_PIC_LIST_0]; i ++)
       {
@@ -809,17 +865,21 @@
     else
     {
-      for(Int i = m_activeNumILRRefIdx; i > 0; i-- )
+      // number of ILRPs included into the reference picture list with the list modification
+      Int includeNumILRP = min( max(1, m_aiNumRefIdx[REF_PIC_LIST_0]-numberOfPocBeforeCurr), m_activeNumILRRefIdx);
+
+      for(Int i = includeNumILRP; i > 0; i-- )
       {
 #if RPL_INIT_N0316_N0082
         if((numberOfPocBeforeCurr) >= m_aiNumRefIdx[REF_PIC_LIST_0])
         {
-          refPicListModification->setRefPicSetIdxL0(m_aiNumRefIdx[REF_PIC_LIST_0] - i, numberOfPocBeforeCurr);
+          refPicListModification->setRefPicSetIdxL0(m_aiNumRefIdx[REF_PIC_LIST_0] - i, numberOfPocBeforeCurr + includeNumILRP - i);
         }
         else
         {
-          refPicListModification->setRefPicSetIdxL0(m_aiNumRefIdx[REF_PIC_LIST_0] - i, numberOfPocBeforeCurr);
+          refPicListModification->setRefPicSetIdxL0(m_aiNumRefIdx[REF_PIC_LIST_0] - i, numberOfPocBeforeCurr + includeNumILRP - i);
           for (Int j = numberOfPocBeforeCurr; j < (m_aiNumRefIdx[REF_PIC_LIST_0] - i); j++)
           {
-            refPicListModification->setRefPicSetIdxL0(j, j + m_activeNumILRRefIdx);
+            assert( j + includeNumILRP < numberOfRpsCurrTempList );
+            refPicListModification->setRefPicSetIdxL0(j, j + includeNumILRP);
           }
         }
@@ -832,8 +892,6 @@
 
   //set L1 inter-layer reference picture modification
-  hasModification = (m_aiNumRefIdx[REF_PIC_LIST_1] == numberOfRpsCurrTempList) ? false : true;
-#if N0147_IRAP_ALIGN_FLAG
+  hasModification = (m_aiNumRefIdx[REF_PIC_LIST_1] >= numberOfRpsCurrTempList) ? false : true;
   hasModification = hasModification && ( m_aiNumRefIdx[REF_PIC_LIST_1] > 1 );
-#endif
 
   refPicListModification->setRefPicListModificationFlagL1(hasModification);
@@ -854,5 +912,7 @@
     else
     {
-      for(Int i = m_activeNumILRRefIdx; i > 0; i-- )
+      Int includeNumILRP = min(m_aiNumRefIdx[REF_PIC_LIST_1], m_activeNumILRRefIdx);
+
+      for(Int i = includeNumILRP; i > 0; i-- )
       {
         refPicListModification->setRefPicSetIdxL1(m_aiNumRefIdx[REF_PIC_LIST_1] - i, numberOfRpsCurrTempList - i);
@@ -1088,6 +1148,16 @@
       rpcPic->setCurrSliceIdx(0);
 #if NO_CLRAS_OUTPUT_FLAG
+#if POC_RESET_IDC_ENCODER
       if (noClrasOutputFlag)
       {
+        rpcPic->getSlice(0)->setReferenced(false);  // all layers // TODO. This does not mark all layers
+      }
+      else
+      {
+        if (rpcPic->getLayerId() == m_layerId) rpcPic->getSlice(0)->setReferenced(false);  // only current layer
+      }
+#else
+      if (noClrasOutputFlag)
+      {
         if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false);  // all layers
       }
@@ -1096,4 +1166,5 @@
         if (rpcPic->getPOC() != pocCurr && rpcPic->getLayerId() == m_layerId) rpcPic->getSlice(0)->setReferenced(false);  // only current layer
       }
+#endif
 #else
       if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false);
@@ -1101,4 +1172,7 @@
       iterPic++;
     }
+#if POC_RESET_IDC_ENCODER
+    this->getPic()->getSlice(0)->setReferenced(true);   // Mark the current picture back as refererced.
+#endif
     if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
       || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
@@ -1329,6 +1403,9 @@
 }
 
-
+#if POC_RESET_IDC_ENCODER
+Void TComSlice::checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic, Bool usePocBeforeReset)
+#else
 Void TComSlice::checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic)
+#endif
 {
   TComPic* rpcPic;
@@ -1419,5 +1496,16 @@
          nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
       {
+#if POC_RESET_IDC_ENCODER
+        if( usePocBeforeReset )
+        {
+          assert(rpcPic->getSlice(0)->getPocValueBeforeReset() < this->getPocValueBeforeReset());
+        }
+        else
+        {
+          assert(rpcPic->getPOC() < this->getPOC());
+        }
+#else
         assert(rpcPic->getPOC() < this->getPOC());
+#endif
       }
     }
@@ -1437,5 +1525,16 @@
           if(this->getAssociatedIRAPPOC() != rpcPic->getPOC())
           {
+#if POC_RESET_IDC_ENCODER
+            if( usePocBeforeReset )
+            {
+              assert(rpcPic->getSlice(0)->getPocValueBeforeReset() < this->getPocValueBeforeReset());
+            }
+            else
+            {
+              assert(rpcPic->getPOC() < this->getPOC());
+            }
+#else
             assert(rpcPic->getPOC() < this->getPOC());
+#endif
           }
         }
@@ -1454,5 +1553,16 @@
         // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB
         // rpcPic would violate the constraint if it was a trailing picture
+#if POC_RESET_IDC_ENCODER
+        if( usePocBeforeReset )
+        {
+          assert(rpcPic->getPOC() <= this->getAssociatedIrapPocBeforeReset());
+        }
+        else
+        {
+          assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC());
+        }
+#else
         assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC());
+#endif
       }
     }
@@ -1760,5 +1870,7 @@
     if(isAvailable == 0)    
     {            
+#if !UNAVAILABLE_PIC_BUGFIX
       if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
+#endif
       {
         if(!pReferencePictureSet->getUsed(i) )
@@ -1781,5 +1893,9 @@
       }
 #if ALLOW_RECOVERY_POINT_AS_RAP
+#if UNAVAILABLE_PIC_BUGFIX
+      if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
+#else
       else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
+#endif
       {
         atLeastOneUnabledByRecoveryPoint = 1;
@@ -2025,5 +2141,12 @@
   if ( layerId == 0 )
   {
-    retVal = sps->getPicWidthInLumaSamples();
+    if( vps->getAvcBaseLayerFlag() )
+    {
+      retVal = vps->getVpsRepFormat(layerId)->getPicWidthVpsInLumaSamples();
+    }
+    else
+    {
+      retVal = sps->getPicWidthInLumaSamples();
+    }
   }
   else
@@ -2051,5 +2174,12 @@
   if( layerId == 0 )
   {
-    retVal = sps->getPicHeightInLumaSamples();
+    if( vps->getAvcBaseLayerFlag() )
+    {
+      retVal = vps->getVpsRepFormat(layerId)->getPicHeightVpsInLumaSamples();
+    }
+    else
+    {
+      retVal = sps->getPicHeightInLumaSamples();
+    }
   }
   else
@@ -2207,14 +2337,9 @@
 , m_bTemporalIdNestingFlag    (false)
 , m_numHrdParameters          (  0)
-#if !VPS_RENAME
-, m_maxNuhReservedZeroLayerId (  0)
-#endif
 , m_hrdParameters             (NULL)
 , m_hrdOpSetIdx               (NULL)
 , m_cprmsPresentFlag          (NULL)
-#if VPS_RENAME
 , m_maxLayerId                (0)
 , m_numLayerSets              (0)
-#endif
 #if VPS_EXTN_OP_LAYER_SETS
 , m_numOutputLayerSets        (0)  
@@ -2234,8 +2359,6 @@
 #endif
 #endif
-#if VPS_VUI_BITRATE_PICRATE
 , m_bitRatePresentVpsFlag     (false)
 , m_picRatePresentVpsFlag     (false)
-#endif
 #if REPN_FORMAT_IN_VPS
 #if Q0195_REP_FORMAT_CLEANUP
@@ -2311,13 +2434,9 @@
   m_crossLayerPictureTypeAlignFlag = true;
 #endif 
-#if N0147_IRAP_ALIGN_FLAG
   m_crossLayerIrapAlignFlag = true;
-#endif 
 #if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
   m_crossLayerAlignedIdrOnlyFlag = false;
 #endif
-#if N0120_MAX_TID_REF_PRESENT_FLAG
   m_maxTidRefPresentFlag = true;
-#endif 
   for( Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++)
   {
@@ -2336,7 +2455,5 @@
   ::memset(m_loopFilterNotAcrossTilesFlag,  0, sizeof(m_loopFilterNotAcrossTilesFlag));
 #endif
-#if TILE_BOUNDARY_ALIGNED_FLAG
   ::memset(m_tileBoundariesAlignedFlag,  0, sizeof(m_tileBoundariesAlignedFlag));
-#endif 
 #if VPS_VUI_WPP_NOT_IN_USE__FLAG
   m_wppNotInUseFlag = true;
@@ -2363,5 +2480,4 @@
   }
 #endif
-#if VPS_VUI_BITRATE_PICRATE  
   ::memset(m_bitRatePresentFlag, 0, sizeof(m_bitRatePresentFlag));
   ::memset(m_picRatePresentFlag, 0, sizeof(m_picRatePresentFlag));
@@ -2370,5 +2486,4 @@
   ::memset(m_constPicRateIdc   , 0, sizeof(m_constPicRateIdc)   );
   ::memset(m_avgPicRate        , 0, sizeof(m_avgPicRate)        );
-#endif
 #if REPN_FORMAT_IN_VPS
   ::memset( m_vpsRepFormatIdx, 0, sizeof(m_vpsRepFormatIdx) );
@@ -2485,5 +2600,5 @@
     }
   }
-#if TILE_BOUNDARY_ALIGNED_FLAG  
+
   if (m_tilesNotInUseFlag)
   {
@@ -2496,7 +2611,7 @@
     }
   }
-#endif
-}
-#endif
+}
+#endif
+
 #if VPS_VUI_WPP_NOT_IN_USE__FLAG
 Void TComVPS::setWppNotInUseFlag(Bool x)
@@ -2526,6 +2641,8 @@
 }
 
-Void TComVPS::setNumRefLayers(Int currLayerId)
-{
+Void TComVPS::setNumRefLayers()
+{
+  memset( m_numberRefLayers, 0, sizeof( m_numberRefLayers ) );
+
   for (Int i = 0; i < m_uiMaxLayers; i++)
   {
@@ -2538,4 +2655,85 @@
   }
 }
+#endif
+
+#if Q0078_ADD_LAYER_SETS
+Void TComVPS::setPredictedLayerIds()
+{
+  for (UInt i = 0; i < getMaxLayers() - 1; i++)
+  {
+    UInt iNuhLId = getLayerIdInNuh(i);
+    UInt predIdx = 0;
+    for (UInt j = iNuhLId + 1; j < MAX_NUM_LAYER_IDS; j++)
+    {
+      if (getRecursiveRefLayerFlag(j, iNuhLId))
+      {
+        setPredictedLayerId(i, predIdx, j);
+        predIdx++;
+      }
+    }
+    setNumPredictedLayers(iNuhLId, predIdx);
+  }
+}
+
+Void TComVPS::setTreePartitionLayerIdList()
+{
+  Bool countedLayerIdxFlag[MAX_NUM_LAYER_IDS];
+
+  for (UInt i = 0; i <= getMaxLayers() - 1; i++)
+  {
+    countedLayerIdxFlag[i] = false;
+  }
+
+  Int numIndependentLayers = 0;
+
+  for (UInt i = 0; i <= getMaxLayers() - 1; i++)
+  {
+    UInt iNuhLId = getLayerIdInNuh(i);
+    if (getNumDirectRefLayers(iNuhLId) == 0)
+    {
+      setTreePartitionLayerId(numIndependentLayers, 0, iNuhLId);
+      setNumLayersInTreePartition(numIndependentLayers, 1);
+      for (UInt j = 0; j < getNumPredictedLayers(iNuhLId); j++)
+      {
+        if (!countedLayerIdxFlag[getLayerIdInVps(iNuhLId)])
+        {
+          setTreePartitionLayerId(numIndependentLayers, getNumLayersInTreePartition(numIndependentLayers), getPredictedLayerId(iNuhLId, j));
+          setNumLayersInTreePartition(numIndependentLayers, getNumLayersInTreePartition(numIndependentLayers) + 1);
+          countedLayerIdxFlag[getLayerIdInVps(getPredictedLayerId(iNuhLId, j))] = true;
+        }
+      }
+      numIndependentLayers++;
+    }
+  }
+
+  setNumIndependentLayers(numIndependentLayers);
+}
+
+void TComVPS::setLayerIdIncludedFlagsForAddLayerSets()
+{
+  for (UInt i = 0; i < getNumAddLayerSets(); i++)
+  {
+    for (UInt j = 1; j < getNumIndependentLayers(); j++)
+    {
+      Int layerNum = 0;
+      Int lsIdx = getVpsNumLayerSetsMinus1() + 1 + i;
+      for (Int layerId = 0; layerId < MAX_VPS_LAYER_ID_PLUS1; layerId++)
+      {
+        setLayerIdIncludedFlag(false, lsIdx, layerId);
+      }
+      for (Int treeIdx = 1; treeIdx < getNumIndependentLayers(); treeIdx++)
+      {
+        for (Int layerCnt = 0; layerCnt < getHighestLayerIdxPlus1(i, j); layerCnt++)
+        {
+          setLayerSetLayerIdList(lsIdx, layerNum, getTreePartitionLayerId(treeIdx, layerCnt));
+          setLayerIdIncludedFlag(true, lsIdx, getTreePartitionLayerId(treeIdx, layerCnt));
+          layerNum++;
+        }
+      }
+      setNumLayersInIdList(lsIdx, layerNum);
+    }
+  }
+}
+
 #endif
 
@@ -2701,4 +2899,5 @@
   return -1;  // Layer not found
 }
+#endif
 #if O0164_MULTI_LAYER_HRD
 Void TComVPS::setBspHrdParameters( UInt hrdIdx, UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess )
@@ -2780,4 +2979,5 @@
 }
 #endif
+#if RESOLUTION_BASED_DPB
 // RepFormat Assignment operator
 RepFormat& RepFormat::operator= (const RepFormat &other)
@@ -2851,4 +3051,5 @@
 #if SVC_EXTENSION
 , m_layerId                   ( 0 )
+, m_extensionFlag             ( false )
 , m_numScaledRefLayerOffsets  ( 0 )
 #if REPN_FORMAT_IN_VPS
@@ -2905,105 +3106,102 @@
 
   TimingInfo *timingInfo = vui->getTimingInfo();
-#if TIMING_INFO_NONZERO_LAYERID_SPS
-  if( getLayerId() > 0 )
+#if SVC_EXTENSION
+  if( m_layerId > 0 )
   {
     timingInfo->setTimingInfoPresentFlag( false );
+    return;
+  }
+#endif
+
+  timingInfo->setTimingInfoPresentFlag( true );
+  switch( frameRate )
+  {
+  case 24:
+    timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
+    break;
+  case 25:
+    timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
+    break;
+  case 30:
+    timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
+    break;
+  case 50:
+    timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
+    break;
+  case 60:
+    timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
+    break;
+  default:
+    timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
+    break;
+  }
+
+  Bool rateCnt = ( bitRate > 0 );
+  hrd->setNalHrdParametersPresentFlag( rateCnt );
+  hrd->setVclHrdParametersPresentFlag( rateCnt );
+
+  hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
+
+  if( hrd->getSubPicCpbParamsPresentFlag() )
+  {
+    hrd->setTickDivisorMinus2( 100 - 2 );                          // 
+    hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
+    hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
+    hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
   }
   else
   {
-#endif
-    timingInfo->setTimingInfoPresentFlag( true );
-    switch( frameRate )
-    {
-    case 24:
-      timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
-      break;
-    case 25:
-      timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
-      break;
-    case 30:
-      timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
-      break;
-    case 50:
-      timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
-      break;
-    case 60:
-      timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
-      break;
-    default:
-      timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
-      break;
-    }
-
-    Bool rateCnt = ( bitRate > 0 );
-    hrd->setNalHrdParametersPresentFlag( rateCnt );
-    hrd->setVclHrdParametersPresentFlag( rateCnt );
-
-    hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
-
-    if( hrd->getSubPicCpbParamsPresentFlag() )
-    {
-      hrd->setTickDivisorMinus2( 100 - 2 );                          // 
-      hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
-      hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
-      hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
-    }
-    else
-    {
-      hrd->setSubPicCpbParamsInPicTimingSEIFlag( false );  
-    }
-
-    hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
-    hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
-    hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
-  
-    hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
-    if( randomAccess )
-    {
-      hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
-      hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
-    }
-    else
-    {
-      hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
-      hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
-    }
-
-/*
-     Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
-*/
-    Int i, j;
-    UInt birateValue, cpbSizeValue;
-    UInt ducpbSizeValue;
-    UInt duBitRateValue = 0;
-
-    for( i = 0; i < MAX_TLAYER; i ++ )
-    {
-      hrd->setFixedPicRateFlag( i, 1 );
-      hrd->setPicDurationInTcMinus1( i, 0 );
-      hrd->setLowDelayHrdFlag( i, 0 );
-      hrd->setCpbCntMinus1( i, 0 );
-
-      birateValue  = bitRate;
-      cpbSizeValue = bitRate;                                     // 1 second
-      ducpbSizeValue = bitRate/numDU;
-      duBitRateValue = bitRate;
-      for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
-      {
-        hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
-        hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
-        hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
-        hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
-
-        hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
-        hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
-        hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
-        hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
-        hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
-      }
-    }
-#if TIMING_INFO_NONZERO_LAYERID_SPS
-  }
-#endif
+    hrd->setSubPicCpbParamsInPicTimingSEIFlag( false );  
+  }
+
+  hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
+  hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
+  hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
+
+  hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
+  if( randomAccess )
+  {
+    hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
+    hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
+  }
+  else
+  {
+    hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
+    hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
+  }
+
+  /*
+  Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
+  */
+  Int i, j;
+  UInt birateValue, cpbSizeValue;
+  UInt ducpbSizeValue;
+  UInt duBitRateValue = 0;
+
+  for( i = 0; i < MAX_TLAYER; i ++ )
+  {
+    hrd->setFixedPicRateFlag( i, 1 );
+    hrd->setPicDurationInTcMinus1( i, 0 );
+    hrd->setLowDelayHrdFlag( i, 0 );
+    hrd->setCpbCntMinus1( i, 0 );
+
+    birateValue  = bitRate;
+    cpbSizeValue = bitRate;                                     // 1 second
+    ducpbSizeValue = bitRate/numDU;
+    duBitRateValue = bitRate;
+    for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
+    {
+      hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
+      hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
+      hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
+      hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
+
+      hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
+      hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
+      hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
+      hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
+      hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
+    }
+  }
 }
 const Int TComSPS::m_winUnitX[]={1,2,2,1};
@@ -3061,5 +3259,8 @@
 , m_listsModificationPresentFlag(  0)
 , m_numExtraSliceHeaderBits(0)
+#if SVC_EXTENSION
+, m_extensionFlag(false)
 #if SCALINGLIST_INFERRING
+, m_layerId(0)
 , m_inferScalingListFlag ( false )
 , m_scalingListRefLayerId ( 0 )
@@ -3068,4 +3269,10 @@
 , m_pocResetInfoPresentFlag   (false)
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+, m_nCGSFlag(0)
+, m_nCGSOutputBitDepthY(0)
+, m_nCGSOutputBitDepthC(0)
+#endif
+#endif //SVC_EXTENSION
 {
   m_scalingList = new TComScalingList;
@@ -3698,6 +3905,10 @@
     return false;
   }        
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_DECODER
+#if POC_RESET_IDC_DECODER
+  TComPic* pic = xGetRefPic( rcListPic, getPOC() );
+#else
   TComPic* pic = xGetRefPic( rcListPic, m_bPocResetFlag ? 0 : m_iPOC );
+#endif
 
   if( pic )
@@ -3712,5 +3923,6 @@
   return true;
 #else
-  setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC())); 
+  setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC()));
+  return true;
 #endif
 }
Index: trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.h	(revision 752)
+++ trunk/source/Lib/TLibCommon/TComSlice.h	(revision 815)
@@ -140,5 +140,5 @@
   
   Void  create  (Int numberOfEntries);
-  Void  destroy ();
+  Void  destroy();
 
 
@@ -469,5 +469,5 @@
 
   UInt        m_numHrdParameters;
-#if !VPS_RENAME
+#if !SVC_EXTENSION
   UInt        m_maxNuhReservedZeroLayerId;
 #endif
@@ -484,6 +484,11 @@
 #if SVC_EXTENSION
 #if DERIVE_LAYER_ID_LIST_VARIABLES
+#if Q0078_ADD_LAYER_SETS
+  Int         m_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1 + MAX_NUM_ADD_LAYER_SETS][MAX_VPS_LAYER_ID_PLUS1];
+  Int         m_numLayerInIdList[MAX_VPS_LAYER_SETS_PLUS1 + MAX_NUM_ADD_LAYER_SETS];
+#else
   Int         m_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
   Int         m_numLayerInIdList[MAX_VPS_LAYER_SETS_PLUS1];
+#endif
 #endif
 #if !P0125_REVERT_VPS_EXTN_OFFSET_TO_RESERVED
@@ -492,7 +497,10 @@
 #endif
 #endif
-#if VPS_RENAME
   UInt        m_maxLayerId;
   UInt        m_numLayerSets;
+#if Q0078_ADD_LAYER_SETS
+  UInt        m_vpsNumLayerSetsMinus1;
+  Bool        m_layerIdIncludedFlag[MAX_VPS_LAYER_SETS_PLUS1 + MAX_NUM_ADD_LAYER_SETS][MAX_VPS_LAYER_ID_PLUS1];
+#else
   Bool        m_layerIdIncludedFlag[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
 #endif
@@ -514,7 +522,13 @@
   UInt       m_layerIdInVps[MAX_VPS_LAYER_ID_PLUS1];            // Maps layer_id_in_nuh with the layer ID in the VPS
 #endif
-#if ILP_SSH_SIG
+#if BITRATE_PICRATE_SIGNALLING
+#if Q0078_ADD_LAYER_SETS
+  UInt       m_maxSLInLayerSetMinus1[MAX_VPS_LAYER_SETS_PLUS1 + MAX_NUM_ADD_LAYER_SETS];
+#else
+  UInt       m_maxSLInLayerSetMinus1[MAX_VPS_LAYER_SETS_PLUS1];
+#endif
+#endif
+    
   Bool       m_ilpSshSignalingEnabledFlag;
-#endif
 #if VPS_EXTN_PROFILE_INFO
   // Profile-tier-level signalling related
@@ -529,6 +543,11 @@
   // Target output layer signalling related
   UInt       m_numOutputLayerSets;
+#if Q0078_ADD_LAYER_SETS
+  UInt       m_outputLayerSetIdx[MAX_VPS_LAYER_SETS_PLUS1 + 2*MAX_NUM_ADD_LAYER_SETS];
+  Bool       m_outputLayerFlag[MAX_VPS_LAYER_SETS_PLUS1 + 2*MAX_NUM_ADD_LAYER_SETS][MAX_VPS_LAYER_ID_PLUS1];
+#else
   UInt       m_outputLayerSetIdx[MAX_VPS_LAYER_SETS_PLUS1];
   Bool       m_outputLayerFlag[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+#endif
 #endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
@@ -565,7 +584,5 @@
   Bool       m_crossLayerPictureTypeAlignFlag;
 #endif
-#if N0147_IRAP_ALIGN_FLAG
   Bool       m_crossLayerIrapAlignFlag;
-#endif
 #if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
   Bool       m_crossLayerAlignedIdrOnlyFlag;
@@ -576,7 +593,5 @@
   UInt       m_maxTidIlRefPicsPlus1[MAX_VPS_LAYER_ID_PLUS1 - 1];
 #endif
-#if N0120_MAX_TID_REF_PRESENT_FLAG
   Bool       m_maxTidRefPresentFlag;
-#endif 
 #if VPS_TSLAYERS
   Bool       m_maxTSLayersPresentFlag;
@@ -594,7 +609,5 @@
   Bool       m_loopFilterNotAcrossTilesFlag[MAX_VPS_LAYER_ID_PLUS1];
 #endif 
-#if TILE_BOUNDARY_ALIGNED_FLAG
   Bool       m_tileBoundariesAlignedFlag[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
-#endif 
 #if VPS_VUI_WPP_NOT_IN_USE__FLAG
   Bool       m_wppNotInUseFlag;
@@ -616,6 +629,6 @@
   Int        m_vpsTransChar[16];
   Int        m_vpsMatCoeff[16];
-#endif 
-#if VPS_VUI_BITRATE_PICRATE
+#endif
+
   Bool       m_bitRatePresentVpsFlag;
   Bool       m_picRatePresentVpsFlag;
@@ -626,5 +639,4 @@
   Int        m_constPicRateIdc     [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
   Int        m_avgPicRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
-#endif
   
 #if P0312_VERT_PHASE_ADJ
@@ -633,5 +645,9 @@
 
 #if P0300_ALT_OUTPUT_LAYER_FLAG
+#if Q0078_ADD_LAYER_SETS
+  Bool       m_altOutputLayerFlag[MAX_VPS_LAYER_SETS_PLUS1 + 2*MAX_NUM_ADD_LAYER_SETS];
+#else
   Bool       m_altOutputLayerFlag[MAX_VPS_LAYER_SETS_PLUS1];
+#endif
 #else
 #if O0153_ALT_OUTPUT_LAYER_FLAG
@@ -661,4 +677,13 @@
   Int        m_numberRefLayers[MAX_NUM_LAYER_IDS];  // number of direct and indirect reference layers of a coding layer
   Bool       m_recursiveRefLayerFlag[MAX_NUM_LAYER_IDS][MAX_NUM_LAYER_IDS];  // flag to indicate if j-th layer is a direct or indirect reference layer of i-th layer
+#endif
+#if Q0078_ADD_LAYER_SETS
+  Int        m_numAddLayerSets;
+  UInt       m_highestLayerIdxPlus1[MAX_NUM_ADD_LAYER_SETS][MAX_NUM_LAYER_IDS];
+  UInt       m_predictedLayerId[MAX_NUM_LAYER_IDS][MAX_NUM_LAYER_IDS];
+  UInt       m_numPredictedLayers[MAX_NUM_LAYER_IDS];
+  Int        m_numIndependentLayers;
+  Int        m_numLayersInTreePartition[MAX_NUM_LAYER_IDS];
+  UInt       m_treePartitionLayerIdList[MAX_NUM_LAYER_IDS][MAX_NUM_LAYER_IDS];
 #endif
 #if SPS_DPB_PARAMS
@@ -675,5 +700,9 @@
   Int        m_maxVpsLatencyIncreasePlus1  [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
 #if CHANGE_NUMSUBDPB_IDX
+#if Q0078_ADD_LAYER_SETS
+  Int        m_numSubDpbs                  [MAX_VPS_LAYER_SETS_PLUS1 + 2*MAX_NUM_ADD_LAYER_SETS];
+#else
   Int        m_numSubDpbs                  [MAX_VPS_LAYER_SETS_PLUS1];
+#endif
 #else
   Int        m_numSubDpbs                  [MAX_VPS_OP_LAYER_SETS_PLUS1];
@@ -735,4 +764,10 @@
   }
 #endif
+#if HRD_BPB
+  Int getBspHrdParamBufferCpbCntMinus1(UInt i, UInt sl)
+  {
+    return m_bspHrd->getCpbCntMinus1(sl);
+  }
+#endif
 
   TComHRD* getHrdParameters   ( UInt i )             { return &m_hrdParameters[ i ]; }
@@ -798,13 +833,31 @@
   Void    setRecursiveRefLayerFlag(Int currLayerId, Int refLayerId, Bool x)      { m_recursiveRefLayerFlag[currLayerId][refLayerId] = x;   }
   Int     getNumRefLayers(Int currLayerId)                                       { return m_numberRefLayers[currLayerId];                  }
-  Void    setNumRefLayers(Int currLayerId);
-#endif
-#if VPS_RENAME
-  UInt    getMaxLayerId()                                       { return m_maxLayerId; }
-  Void    setMaxLayerId(UInt v)                                 { m_maxLayerId = v;    }
-
+  Void    setNumRefLayers();
+#endif
+#if Q0078_ADD_LAYER_SETS
+  void    setLayerIdIncludedFlagsForAddLayerSets();
+  UInt    getVpsNumLayerSetsMinus1()                                             { return m_vpsNumLayerSetsMinus1; }
+  Void    setVpsNumLayerSetsMinus1(UInt x)                                       { m_vpsNumLayerSetsMinus1 = x; }
+  UInt    getNumAddLayerSets()                                                   { return m_numAddLayerSets; }
+  Void    setNumAddLayerSets(UInt x)                                             { m_numAddLayerSets = x; }
+  UInt    getHighestLayerIdxPlus1(UInt set, UInt idx)                            { return m_highestLayerIdxPlus1[set][idx]; }
+  Void    setHighestLayerIdxPlus1(UInt set, UInt idx, UInt layerIdx)             { m_highestLayerIdxPlus1[set][idx] = layerIdx; }
+  Void    setPredictedLayerIds();
+  UInt    getPredictedLayerId(UInt layerIdx, UInt predIdx)                       { return m_predictedLayerId[layerIdx][predIdx]; }
+  Void    setPredictedLayerId(UInt layerIdx, UInt predIdx, UInt x)               { m_predictedLayerId[layerIdx][predIdx] = x; }
+  UInt    getNumPredictedLayers(UInt layerId)                                    { return m_numPredictedLayers[layerId]; }
+  Void    setNumPredictedLayers(UInt layerId, UInt x)                            { m_numPredictedLayers[layerId] = x; }
+  Void    setTreePartitionLayerIdList();
+  Int     getNumIndependentLayers()                                              { return m_numIndependentLayers; }
+  Void    setNumIndependentLayers(Int x)                                         { m_numIndependentLayers = x; }
+  Int     getNumLayersInTreePartition(Int idx)                                   { return m_numLayersInTreePartition[idx]; }
+  Void    setNumLayersInTreePartition(Int idx, Int x)                            { m_numLayersInTreePartition[idx] = x; }
+  UInt    getTreePartitionLayerId(Int idx, Int layerIdx)                         { return m_treePartitionLayerIdList[idx][layerIdx]; }
+  Void    setTreePartitionLayerId(Int idx, Int layerIdx, UInt layerId)           { m_treePartitionLayerIdList[idx][layerIdx] = layerId; }
+#endif
+  UInt    getMaxLayerId()                                       { return m_maxLayerId;   }
+  Void    setMaxLayerId(UInt v)                                 { m_maxLayerId = v;      }
   UInt    getNumLayerSets()                                     { return m_numLayerSets; }
   Void    setNumLayerSets(UInt v)                               { m_numLayerSets = v;    }
-#endif
 #if VPS_EXTN_MASK_AND_DIM_INFO
   Bool   getAvcBaseLayerFlag()                                  { return m_avcBaseLayerFlag;       }
@@ -835,8 +888,10 @@
   Void   setLayerIdInVps(Int id, UInt x)                        { m_layerIdInVps[id] = x;          }
 #endif
-#if ILP_SSH_SIG
-    Bool   getIlpSshSignalingEnabledFlag()                      { return m_ilpSshSignalingEnabledFlag;}
-    Void   setIlpSshSignalingEnabledFlag(Bool x)                { m_ilpSshSignalingEnabledFlag = x;}
-#endif
+#if BITRATE_PICRATE_SIGNALLING
+  UInt   getMaxSLayersInLayerSetMinus1(Int ls)                  { return m_maxSLInLayerSetMinus1[ls]; }
+  Void   setMaxSLayersInLayerSetMinus1(Int ls, Int x)           { m_maxSLInLayerSetMinus1[ls] = x;    }
+#endif
+  Bool   getIlpSshSignalingEnabledFlag()                        { return m_ilpSshSignalingEnabledFlag;}
+  Void   setIlpSshSignalingEnabledFlag(Bool x)                  { m_ilpSshSignalingEnabledFlag = x;}
 #if VPS_EXTN_PROFILE_INFO
   Bool   getProfilePresentFlag(Int id)                          { return m_profilePresentFlag[id]; }
@@ -883,4 +938,6 @@
   UInt   getDirectDependencyType(Int currLayerId, Int refLayerId)               { return m_directDependencyType[currLayerId][refLayerId]; }
   Void   setDirectDependencyType(Int currLayerId, Int refLayerId, UInt x)       { m_directDependencyType[currLayerId][refLayerId] = x;    }
+  Bool   isSamplePredictionType(Int currLayerId, Int refLayerId)                { assert(currLayerId != refLayerId); return ( ( m_directDependencyType[currLayerId][refLayerId] + 1 ) & 1 ) ? true : false; }
+  Bool   isMotionPredictionType(Int currLayerId, Int refLayerId)                { assert(currLayerId != refLayerId); return ( ( ( m_directDependencyType[currLayerId][refLayerId] + 1 ) & 2 ) >> 1 ) ? true : false; }
 #endif
   UInt   getNumProfileTierLevel()                                { return m_numProfileTierLevel; }
@@ -923,8 +980,6 @@
   Void   setCrossLayerAlignedIdrOnlyFlag(Bool x)                              { m_crossLayerAlignedIdrOnlyFlag = x;                         }
 #endif 
-#if N0147_IRAP_ALIGN_FLAG
   Bool   getCrossLayerIrapAlignFlag()                                           { return m_crossLayerIrapAlignFlag;                      }
   Void   setCrossLayerIrapAlignFlag(Bool x)                                     { m_crossLayerIrapAlignFlag = x;                         }
-#endif 
 #if O0225_MAX_TID_FOR_REF_LAYERS
   UInt   getMaxTidIlRefPicsPlus1(Int layerId, Int refLayerId)                     { return m_maxTidIlRefPicsPlus1[layerId][refLayerId];           }
@@ -934,8 +989,6 @@
   Void   setMaxTidIlRefPicsPlus1(Int layerId, UInt maxSublayer)   { m_maxTidIlRefPicsPlus1[layerId] = maxSublayer;            }
 #endif
-#if N0120_MAX_TID_REF_PRESENT_FLAG
   Bool   getMaxTidRefPresentFlag()                                  { return m_maxTidRefPresentFlag ;}
   Void   setMaxTidRefPresentFlag(Bool x)                            { m_maxTidRefPresentFlag = x;}
-#endif 
 #if VPS_TSLAYERS
   Bool   getMaxTSLayersPresentFlag()                                  { return m_maxTSLayersPresentFlag ;}
@@ -960,8 +1013,6 @@
   Void   setLoopFilterNotAcrossTilesFlag(Int currLayerId, Bool x)    { m_loopFilterNotAcrossTilesFlag[currLayerId] = x; } 
 #endif 
-#if TILE_BOUNDARY_ALIGNED_FLAG  
   Bool   getTileBoundariesAlignedFlag(Int currLayerId, Int refLayerId)           { return m_tileBoundariesAlignedFlag[currLayerId][refLayerId]; }
   Void   setTileBoundariesAlignedFlag(Int currLayerId, Int refLayerId, Bool x)   { m_tileBoundariesAlignedFlag[currLayerId][refLayerId] = x; } 
-#endif 
 #if VPS_VUI_WPP_NOT_IN_USE__FLAG  
   Bool   getWppNotInUseFlag()         { return m_wppNotInUseFlag; }
@@ -1001,5 +1052,4 @@
   Void   setMaxtrixCoeff(Int idx, Int x)       { m_vpsMatCoeff[idx] = x;        }
 #endif
-#if VPS_VUI_BITRATE_PICRATE
   Bool   getBitRatePresentVpsFlag()       { return m_bitRatePresentVpsFlag; }
   Void   setBitRatePresentVpsFlag(Bool x) { m_bitRatePresentVpsFlag = x;    }
@@ -1021,5 +1071,4 @@
   Int    getAvgPicRate(Int i, Int j)          { return m_avgPicRate[i][j]; }
   Void   setAvgPicRate(Int i, Int j, Int x)   { m_avgPicRate[i][j] = x;    }
-#endif
 #if O0164_MULTI_LAYER_HRD
   Bool     getVpsVuiBspHrdPresentFlag()                         { return m_vpsVuiBspHrdPresentFlag;      }
@@ -1463,4 +1512,5 @@
 #if SVC_EXTENSION
   UInt        m_layerId;
+  Bool        m_extensionFlag;
   UInt        m_numScaledRefLayerOffsets;
 #if P0312_VERT_PHASE_ADJ
@@ -1621,4 +1671,6 @@
   Void     setLayerId(UInt layerId)            { m_layerId = layerId; }
   UInt     getLayerId()                        { return m_layerId;    }
+  Int      getExtensionFlag()                  { return m_extensionFlag;  }
+  Void     setExtensionFlag(Int n)             { m_extensionFlag = n;     }
   UInt     getNumScaledRefLayerOffsets()       { return m_numScaledRefLayerOffsets; }
   Void     setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x;    }
@@ -1736,4 +1788,5 @@
 
 #if SVC_EXTENSION
+  Bool     m_extensionFlag;
 #if SCALINGLIST_INFERRING
   UInt     m_layerId;
@@ -1862,13 +1915,4 @@
 
 #if SCALINGLIST_INFERRING
-  UInt     getLayerId() { return m_layerId; }
-  Void     setLayerId( UInt layerId ) { m_layerId = layerId;            }
-  Bool     getInferScalingListFlag()  { return m_inferScalingListFlag;  }
-  UInt     getScalingListRefLayerId() { return m_scalingListRefLayerId; }
-  Void     setInferScalingListFlag( Bool flag )     { m_inferScalingListFlag = flag;     }
-  Void     setScalingListRefLayerId( UInt layerId ) { m_scalingListRefLayerId = layerId; }
-#endif
-
-#if SCALINGLIST_INFERRING
   Void     setScalingList( TComScalingList *scalingList ) { m_scalingList = scalingList; }
 #else
@@ -1886,4 +1930,15 @@
   Bool getSliceHeaderExtensionPresentFlag   ()                    { return m_sliceHeaderExtensionPresentFlag; }
   Void setSliceHeaderExtensionPresentFlag   (Bool val)            { m_sliceHeaderExtensionPresentFlag = val; }
+#if SVC_EXTENSION
+  Int     getExtensionFlag()                { return m_extensionFlag;  }
+  Void    setExtensionFlag(Int n)           { m_extensionFlag = n;     }
+#if SCALINGLIST_INFERRING
+  UInt     getLayerId() { return m_layerId; }
+  Void     setLayerId( UInt layerId ) { m_layerId = layerId;            }
+  Bool     getInferScalingListFlag()  { return m_inferScalingListFlag;  }
+  UInt     getScalingListRefLayerId() { return m_scalingListRefLayerId; }
+  Void     setInferScalingListFlag( Bool flag )     { m_inferScalingListFlag = flag;     }
+  Void     setScalingListRefLayerId( UInt layerId ) { m_scalingListRefLayerId = layerId; }
+#endif
 #if POC_RESET_IDC
   Bool getPocResetInfoPresentFlag   ()                    { return m_pocResetInfoPresentFlag; }
@@ -1898,4 +1953,5 @@
   Void    setCGSOutputBitDepthC(Int n){ m_nCGSOutputBitDepthC = n;     }
 #endif
+#endif //SVC_EXTENSION
 };
 
@@ -1935,4 +1991,8 @@
   Int         m_iLastIDR;
   Int         m_iAssociatedIRAP;
+#if POC_RESET_IDC_ENCODER
+  Int         m_associatedIrapPocBeforeReset;
+#endif
+
   NalUnitType m_iAssociatedIRAPType;
   static Int  m_prevTid0POC;
@@ -2061,4 +2121,10 @@
   Bool        m_pocMsbValPresentFlag;
 #endif
+#if POC_RESET_IDC_ENCODER
+  Int         m_pocValueBeforeReset;
+#endif
+#if POC_RESET_IDC_DECODER || POC_RESET_IDC_ENCODER
+  Int         m_picOrderCntLsb;
+#endif
 #if Q0048_CGS_3D_ASYMLUT
   Int        m_nCGSOverWritePPS;  // for optimization, not output to bitstream
@@ -2106,4 +2172,8 @@
     Void     adjustPrevTid0POC      (Int adj)             { m_prevTid0POC=m_prevTid0POC-adj; }
 #endif
+#if POC_RESET_IDC_DECODER
+  Void      setPrevTid0POC( Int x ) { m_prevTid0POC = x; }
+#endif
+
   TComRefPicListModification* getRefPicListModification() { return &m_RefPicListModification; }
   Void      setLastIDR(Int iIDRPOC)                       { m_iLastIDR = iIDRPOC; }
@@ -2111,4 +2181,9 @@
   Void      setAssociatedIRAPPOC(Int iAssociatedIRAPPOC)             { m_iAssociatedIRAP = iAssociatedIRAPPOC; }
   Int       getAssociatedIRAPPOC()                        { return m_iAssociatedIRAP; }
+#if POC_RESET_IDC_ENCODER
+  Void setAssociatedIrapPocBeforeReset(Int x) { m_associatedIrapPocBeforeReset = x; }
+  Int  getAssociatedIrapPocBeforeReset(     ) { return m_associatedIrapPocBeforeReset; }
+#endif
+
   Void      setAssociatedIRAPType(NalUnitType associatedIRAPType)    { m_iAssociatedIRAPType = associatedIRAPType; }
   NalUnitType getAssociatedIRAPType()                        { return m_iAssociatedIRAPType; }
@@ -2220,5 +2295,9 @@
   Void setTLayerInfo( UInt uiTLayer );
   Void decodingMarking( TComList<TComPic*>& rcListPic, Int iGOPSIze, Int& iMaxRefPicNum ); 
+#if POC_RESET_IDC_ENCODER
+  Void checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic, Bool usePocBeforeReset = false);
+#else
   Void checkLeadingPictureRestrictions( TComList<TComPic*>& rcListPic );
+#endif
   Void applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *RPSList);
   Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
@@ -2418,4 +2497,20 @@
   Bool      getCraPicFlag       ();
 #endif
+#if POC_RESET_IDC_DECODER
+  Bool      getRaslPicFlag      ();
+  Bool      getRadlPicFlag      ();
+#endif
+#if POC_RESET_IDC_DECODER || POC_RESET_IDC_ENCODER
+  Int       getPicOrderCntLsb() { return m_picOrderCntLsb; }
+  Void      setPicOrderCntLsb(Int x) { m_picOrderCntLsb = x; }
+#endif
+
+#if POC_RESET_IDC_ENCODER
+  Int       getPocValueBeforeReset ()                        { return m_pocValueBeforeReset; }
+  Void      setPocValueBeforeReset (Int x)                   { m_pocValueBeforeReset = x ;   }
+  Void      decrementRefPocValues(Int const decrementValue);
+  Int       getCurrMsb( Int currLsb, Int prevLsb, Int prevMsb, Int maxLsbVal );
+#endif
+
 
 #endif //SVC_EXTENSION
@@ -2472,4 +2567,16 @@
   }
 
+#if Q0078_ADD_LAYER_SETS
+  Void removePS(Int psId)
+  {
+    assert(psId < m_maxId);
+    if (m_paramsetMap.find(psId) != m_paramsetMap.end())
+    {
+      m_paramsetMap.erase(psId);
+    }
+  }
+#endif
+
+
 private:
   std::map<Int,T *> m_paramsetMap;
@@ -2494,4 +2601,7 @@
   TComSPS* getSPS(Int spsId)  { return m_spsMap.getPS(spsId); };
   TComSPS* getFirstSPS()      { return m_spsMap.getFirstPS(); };
+#if Q0078_ADD_LAYER_SETS
+  Void     removeSPS(Int spsId) { m_spsMap.removePS(spsId); };
+#endif
 
   //! store picture parameter set and take ownership of it 
@@ -2500,4 +2610,7 @@
   TComPPS* getPPS(Int ppsId)  { return m_ppsMap.getPS(ppsId); };
   TComPPS* getFirstPPS()      { return m_ppsMap.getFirstPS(); };
+#if Q0078_ADD_LAYER_SETS
+  Void     removePPS(Int ppsId) { m_ppsMap.removePS(ppsId); };
+#endif
 
   //! activate a SPS from a active parameter sets SEI message
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 752)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 815)
@@ -1,90 +1,44 @@
-
+#include "TypeDef.h"
+#if SVC_EXTENSION
 #include "TComUpsampleFilter.h"
-#include "TypeDef.h"
-
-#if SVC_UPSAMPLING
-#define CNU -1 ///< Coefficients Not Used
 
 const Int TComUpsampleFilter::m_lumaFixedFilter[16][NTAPS_US_LUMA] =
 {
-  {  0,  0,  0, 64,  0,  0,  0,  0}, //
-#if ARBITRARY_SPATIAL_RATIO
-  {  0,  1, -3, 63,  4, -2,  1,  0},
-  { -1,  2, -5, 62,  8, -3,  1,  0},
-  { -1,  3, -8, 60, 13, -4,  1,  0},
-  { -1,  4,-10, 58, 17, -5,  1,  0},
-#else
-  {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}, //
-#endif
-  { -1, 4, -11, 52, 26,  -8,  3, -1}, // <-> actual phase shift 1/3, used for spatial scalability x1.5
-#if ARBITRARY_SPATIAL_RATIO
-  { -1, 3,  -9, 47, 31, -10,  4, -1},
-  { -1, 4, -11, 45, 34, -10,  4, -1},
-#else
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
-#endif
-  { -1, 4, -11, 40, 40, -11,  4, -1}, // <-> actual phase shift 1/2, equal to HEVC MC, used for spatial scalability x2
-#if ARBITRARY_SPATIAL_RATIO
-  { -1,  4, -10, 34, 45, -11,  4, -1},
-  { -1,  4, -10, 31, 47,  -9,  3, -1},
-#else
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
-#endif
-  { -1, 3,  -8, 26, 52, -11, 4, -1}, // <-> actual phase shift 2/3, used for spatial scalability x1.5
-#if ARBITRARY_SPATIAL_RATIO
-  { 0,  1,  -5, 17, 58, -10,  4, -1},
-  { 0,  1,  -4, 13, 60,  -8,  3, -1},
-  { 0,  1,  -3,  8, 62,  -5,  2, -1},
-  { 0,  1,  -2,  4, 63,  -3,  1,  0}
-#else
-  {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}  //
-#endif
+  {  0, 0,   0, 64,  0,   0,  0,  0 },
+  {  0, 1,  -3, 63,  4,  -2,  1,  0 },
+  { -1, 2,  -5, 62,  8,  -3,  1,  0 },
+  { -1, 3,  -8, 60, 13,  -4,  1,  0 },
+  { -1, 4, -10, 58, 17,  -5,  1,  0 },
+  { -1, 4, -11, 52, 26,  -8,  3, -1 }, // <-> actual phase shift 1/3, used for spatial scalability x1.5
+  { -1, 3,  -9, 47, 31, -10,  4, -1 },
+  { -1, 4, -11, 45, 34, -10,  4, -1 },
+  { -1, 4, -11, 40, 40, -11,  4, -1 }, // <-> actual phase shift 1/2, equal to HEVC MC, used for spatial scalability x2
+  { -1, 4, -10, 34, 45, -11,  4, -1 },
+  { -1, 4, -10, 31, 47,  -9,  3, -1 },
+  { -1, 3,  -8, 26, 52, -11,  4, -1 }, // <-> actual phase shift 2/3, used for spatial scalability x1.5
+  {  0, 1,  -5, 17, 58, -10,  4, -1 },
+  {  0, 1,  -4, 13, 60,  -8,  3, -1 },
+  {  0, 1,  -3,  8, 62,  -5,  2, -1 },
+  {  0, 1,  -2,  4, 63,  -3,  1,  0 }
 };
 
 const Int TComUpsampleFilter::m_chromaFixedFilter[16][NTAPS_US_CHROMA] =
 {
-  {  0, 64,  0,  0},//
-#if ARBITRARY_SPATIAL_RATIO
-  { -2, 62,  4,  0},
-  { -2, 58, 10, -2},
-  { -4, 56, 14, -2},
-#else
-  {CNU,CNU,CNU,CNU},//
-  {CNU,CNU,CNU,CNU},//
-  {CNU,CNU,CNU,CNU},//
-#endif
-  { -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)
-#if ARBITRARY_SPATIAL_RATIO
-  { -4, 42, 30, -4},
-#else
-  {CNU,CNU,CNU,CNU},//
-#endif
-  { -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)
-#if ARBITRARY_SPATIAL_RATIO
-  { -4, 28, 46, -6},
-#else
-  {CNU,CNU,CNU,CNU},//
-#endif
-  { -2, 20, 52, -6},// <-> actual phase shift 2/3, used for spatial scalability x1.5
-#if ARBITRARY_SPATIAL_RATIO
-  {-2, 16, 54, -4},
-  {-2, 14, 56, -4},
-#else
-  {CNU,CNU,CNU,CNU},//
-  {CNU,CNU,CNU,CNU},//
-#endif
-  { -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)
+  {  0, 64,  0,  0 },
+  { -2, 62,  4,  0 },
+  { -2, 58, 10, -2 },
+  { -4, 56, 14, -2 },
+  { -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)
+  { -4, 42, 30, -4 },
+  { -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)
+  { -4, 28, 46, -6 },
+  { -2, 20, 52, -6 }, // <-> actual phase shift 2/3, used for spatial scalability x1.5
+  { -2, 16, 54, -4 },
+  { -2, 14, 56, -4 },
+  { -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)
 };
 
@@ -260,11 +214,6 @@
     }
 
-#if ARBITRARY_SPATIAL_RATIO
     assert ( widthEL >= widthBL );
     assert ( heightEL >= heightBL );
-#else
-    assert ( widthEL == widthBL || widthEL == 2*widthBL || 2*widthEL == 3*widthBL );
-    assert ( heightEL == heightBL || heightEL == 2*heightBL || 2*heightEL == 3*heightBL );
-#endif
 
     pcBasePic->setBorderExtension(false);
@@ -298,11 +247,6 @@
 #endif
  
-#if ROUNDING_OFFSET
     Int   addX = ( ( phaseX * scaleX + 2 ) >> 2 ) + ( 1 << ( shiftX - 5 ) );
     Int   addY = ( ( phaseY * scaleY + 2 ) >> 2 ) + ( 1 << ( shiftY - 5 ) );
-#else
-    Int   addX = ( ( ( widthBL * phaseX ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
-    Int   addY = ( ( ( heightBL * phaseY ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
-#endif
 
 #if Q0120_PHASE_CALCULATION
@@ -333,5 +277,4 @@
     Int bottomEndL = pcUsPic->getHeight() - scalEL.getWindowBottomOffset();
     Int leftOffset = leftStartL > 0 ? leftStartL : 0;
-#if N0214_INTERMEDIATE_BUFFER_16BITS
 #if O0194_JOINT_US_BITSHIFT
     // g_bitDepthY was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
@@ -345,5 +288,4 @@
 #else
     Int shift1 = g_bitDepthY - 8;
-#endif
 #endif
 
@@ -362,9 +304,5 @@
       for( j = 0; j < heightBL ; j++ )
       {
-#if N0214_INTERMEDIATE_BUFFER_16BITS
         *piDstY = sumLumaHor(piSrcY, coeff) >> shift1;
-#else
-        *piDstY = sumLumaHor(piSrcY, coeff);
-#endif
         piSrcY += strideBL;
         piDstY += strideEL;
@@ -378,12 +316,8 @@
     pcTempPic->setHeight(heightEL);
 
-#if N0214_INTERMEDIATE_BUFFER_16BITS
 #if O0194_JOINT_US_BITSHIFT
     Int nShift = 20 - g_bitDepthYLayer[currLayerId];
 #else
     Int nShift = US_FILTER_PREC*2 - shift1;
-#endif
-#else
-    const Int nShift = US_FILTER_PREC*2;
 #endif
     Int iOffset = 1 << (nShift - 1);
@@ -472,11 +406,6 @@
 #endif
     
-#if ROUNDING_OFFSET
     addX       = ( ( phaseXC * scaleX + 2 ) >> 2 ) + ( 1 << ( shiftX - 5 ) );
     addY       = ( ( phaseYC * scaleY + 2 ) >> 2 ) + ( 1 << ( shiftY - 5 ) );
-#else
-    addX       = ( ( ( widthBL * (phaseXC) ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
-    addY       = ( ( ( heightBL * (phaseYC) ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
-#endif
 
 #if Q0120_PHASE_CALCULATION
@@ -502,5 +431,4 @@
     heightBL  = min<Int>( pcBasePic->getHeight() >> 1, heightEL );
 
-#if N0214_INTERMEDIATE_BUFFER_16BITS
 #if O0194_JOINT_US_BITSHIFT
     // g_bitDepthC was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
@@ -514,5 +442,4 @@
 #else
     shift1 = g_bitDepthC - 8;
-#endif
 #endif
 
@@ -533,11 +460,6 @@
       for( j = 0; j < heightBL ; j++ )
       {
-#if N0214_INTERMEDIATE_BUFFER_16BITS
         *piDstU = sumChromaHor(piSrcU, coeff) >> shift1;
         *piDstV = sumChromaHor(piSrcV, coeff) >> shift1;
-#else
-        *piDstU = sumChromaHor(piSrcU, coeff);
-        *piDstV = sumChromaHor(piSrcV, coeff);
-#endif
 
         piSrcU += strideBL;
@@ -554,5 +476,4 @@
     pcTempPic->setHeight(heightEL << 1);
 
-#if N0214_INTERMEDIATE_BUFFER_16BITS
 #if O0194_JOINT_US_BITSHIFT
     nShift = 20 - g_bitDepthCLayer[currLayerId];
@@ -561,5 +482,4 @@
 #endif
     iOffset = 1 << (nShift - 1);
-#endif
 
     for( j = 0; j < pcTempPic->getHeight() >> 1; j++ )
Index: trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/TypeDef.h	(revision 752)
+++ trunk/source/Lib/TLibCommon/TypeDef.h	(revision 815)
@@ -41,13 +41,18 @@
 #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)]
+#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
 
 #define VPS_VUI_OFFSET                   1      ///< N0085: Signal VPS VUI offset in the VPS extension 
-#define RANDOM_ACCESS_SEI_FIX            1
 #define O0137_MAX_LAYERID                1      ///< JCTVC-O0137, JCTVC-O0200, JCTVC-O0223: restrict nuh_layer_id and vps_max_layers_minus1
 
-#define Q0200_CONFORMANCE_BL_SIZE        1       ///< JCTVC-Q0200; use conformance picture size in re-sampling processs
+#define Q0108_TSA_STSA                   0      ///< 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
+#define Q0142_POC_LSB_NOT_PRESENT        1      ///< JCTVC-Q0142; Add constraint checking on the value of poc_reset_idc and poc_lsb_val
+#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 P0312_VERT_PHASE_ADJ             1      ///< JCTVC-P0312: vertical phase adjustment in re-sampling process (BoG report)
 #if P0312_VERT_PHASE_ADJ
@@ -62,11 +67,7 @@
 #define VPS_EXTN_UEV_CODING              1      ///< JCTVC-P0306: Code some syntax elements as ue(v), and remove some syntax elements that duplicate behaviour
 #define CHANGE_NUMSUBDPB_IDX             1      ///< Change index of NumSubDpb from output layer set to layer set, to be more aligned with the Spec
-#define RESOLUTION_BASED_DPB             1      ///< JCTVC-P0192: Assign layers to sub-DPBs based on the rep_format() signaled in the VPS
+#define RESOLUTION_BASED_DPB             0      ///< JCTVC-Q0154 - remove sharing of sub-DPB across layers
+                                                ///< JCTVC-P0192: Assign layers to sub-DPBs based on the rep_format() signaled in the VPS
 #define ALIGNED_BUMPING                  1      ///< JCTVC-P0192: Align bumping of pictures in an AU
-#define MAX_SUBDPBS                      MAX_LAYERS
-#define SUB_BITSTREAM_PROPERTY_SEI       1      ///< JCTVC-P0204: Sub-bitstream property SEI message
-#if SUB_BITSTREAM_PROPERTY_SEI
-#define MAX_SUB_STREAMS                  1024
-#endif
 #define O0109_O0199_FLAGS_TO_VUI         1      ///< JCTVC-O0109, O0199: move single_layer_for_non_irap_flag and higher_layer_flag to vps_vui
 #define O0109_VIEW_ID_LEN                1      ///< JCTVC-O0109: view_id_len_minus1 to view_id_len, and add constraint (1<<view_id_len) is greater than or equal to NumViews
@@ -77,5 +78,5 @@
 #endif
 
-#define P0295_DEFAULT_OUT_LAYER_IDC      1      ///< JCTVC-P0295: modifify default_one_target_output_layer_idc to default_target_output_layer_idc
+#define P0295_DEFAULT_OUT_LAYER_IDC      1      ///< JCTVC-P0295: modifify default_one_target_output_layer_idc to default_output_layer_idc
 #define O0109_DEFAULT_ONE_OUT_LAYER_IDC  1      ///< JCTVC-O0109: default_one_target_output_layer_flag to default_one_target_output_layer_idc
 #define O0109_MOVE_VPS_VUI_FLAG          1      ///< JCTVC-O0109: move vps_vui_present_flag before vps_vui_offset
@@ -84,5 +85,5 @@
 
 #define O0164_MULTI_LAYER_HRD            1      ///< JCTVC-O0164: Multi-layer HRD operation
-#define Q0074_SEI_COLOR_MAPPING          1      ///< JCTVC-Q0074, SEI Color Mapping
+#define Q0182_MULTI_LAYER_HRD_UPDATE     1      ///< JCTVC-Q0182: On bitstream partition buffering
 
 #define O0194_DIFFERENT_BITDEPTH_EL_BL   1      ///< JCTVC-O0194: Support for different bitdepth values for BL and EL, add required configuration parameters (and Some bugfixes when REPN_FORMAT_IN_VPS (JCTVC-N0092) is enabled)
@@ -92,31 +93,29 @@
 #define Q0048_CGS_3D_ASYMLUT             1      ///< JCTVC-Q0048: Colour gamut scalability with look-up table
 #if Q0048_CGS_3D_ASYMLUT
+#define CGS_GCC_NO_VECTORIZATION         1
 #define O0194_WEIGHTED_PREDICTION_CGS    0
 #else
 #define O0194_WEIGHTED_PREDICTION_CGS    1      ///< JCTVC-O0194: Weighted prediciton for color gamut scalability
 #endif
-#define MFM_ENCCONSTRAINT                1      ///< JCTVC-O0216: Encoder constraint for motion field mapping
-#define VPS_NUH_LAYER_ID                 1      ///< JCTVC-N0085: Assert that the nuh_layer_id of VPS NAL unit should be 0
-#define POC_RESET_FLAG                   1      ///< JCTVC-N0244: POC reset flag for  layer pictures.
+#define POC_RESET_FLAG                   0      ///< JCTVC-N0244: POC reset flag for  layer pictures.
 #define POC_RESET_IDC                    1      ///< JCTVC-P0041: Include poc_reset_idc and related derivation - eventually will replace POC_RESET_FLAG
 #if POC_RESET_IDC
 #define POC_RESET_IDC_SIGNALLING         1      ///< JCTVC-P0041: Include signalling for poc_reset related syntax elements
-#endif
+#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
+#endif
+#define POC_MSB_VAL_PRESENT_FLAG_SEM     1      ///< JCTVC-Q0146: Inference of poc_msb_val_present_flag
+#define POC_RESET_INFO_INFERENCE         1      ///< JCTVC-Q0146: Infer the value of poc_reset_info_present_flag when not present
 #define NO_OUTPUT_OF_PRIOR_PICS          1      ///< Use no_output_of_prior_pics_flag
-#define ALIGN_TSA_STSA_PICS              1      ///< JCTVC-N0084: Alignment of TSA and STSA pictures across AU.
 #define REPN_FORMAT_IN_VPS               1      ///< JCTVC-N0092: Signal represenation format (spatial resolution, bit depth, colour format) in the VPS
 #if REPN_FORMAT_IN_VPS
 #define REPN_FORMAT_CONTROL_FLAG         1      ///< JCTVC-O0179: Add control flag in representation format to control sending of chroma and bitdepth parameters
 #endif 
-#define TIMING_INFO_NONZERO_LAYERID_SPS  1      ///< JCTVC-N0085: Semantics of vui_timing_info_present_flag to always set that flag to zero for non-zero layer ID SPS 
 #define RPL_INIT_N0316_N0082             1      ///< JCTVC-N0316, JCTVC-N0082: initial reference picture list construction 
 
 #define SCALINGLIST_INFERRING            1      ///< JCTVC-N0371: inter-layer scaling list
-#define SPS_EXTENSION                    1      ///< Define sps_extension() syntax structure
-#if SPS_EXTENSION
 #define O0142_CONDITIONAL_SPS_EXTENSION  1      ///< JCTVC-O0142: Conditional SPS extension
-#endif
-#define SCALABILITY_MASK_E0104           1      ///< JCT3V-E0104: scalability mask for depth
-#define LAYER_CTB                        0      ///< enable layer-specific CTB structure
 #if POC_RESET_FLAG
 #define PREVTID0_POC_RESET               1      ///< JCTVC-O0117 Modification of the PicOrderCntVal of prevTid0Pic
@@ -124,14 +123,4 @@
 #endif
 
-#define ILP_SSH_SIG                      1      ///< JCTVC-N0195 proposal 2, JCTVC-N0118: add presence flag in VPS ext to condition inter-layer prediction signaling in slice segment header
-#if ILP_SSH_SIG
-#define ILP_SSH_SIG_FIX                  1      ///< fix for SHM ticket #5
-#endif 
-#define SPL_FLG_CHK                      1      ///< JCTVC-N0195 proposal 5, JCTVC-N0085: constrain sum of lengths to be less than or equal to 6
-#define ILP_NUM_REF_CHK                  1      ///< JCTVC-N0195 proposal 1, JCTVC-N0081, JCTVC-N0154, JCTVC-N0217: a condition on signaling inter_layer_pred_layer_idc[ i ], to avoid sending when NumDirectRefLayers equals NumActiveRefLayerPics, and instead infer values
-
-#define VPS_RENAME                       1      ///< Rename variables max_layer_id and num_layer_sets_minus1 in VPS
-#define VPS_EXTNS                        1      ///< Include function structure for VPS extensions
-#if VPS_EXTNS
 #define VPS_EXTN_MASK_AND_DIM_INFO       1      ///< Include avc_base_layer_flag, splitting_flag, scalability mask and dimension related info
 #if VPS_EXTN_MASK_AND_DIM_INFO
@@ -142,12 +131,8 @@
 #define VPS_EXTN_DIRECT_REF_LAYERS       1      ///< Include indication of direct dependency of layers in VPS extension
 #define M0040_ADAPTIVE_RESOLUTION_CHANGE 1
-#define VPS_VUI                          1      ///< Include function structure for VPS VUI
-
-#if VPS_VUI
+
 #define VPS_VUI_TILES_NOT_IN_USE__FLAG   1      ///< JCTVC-O0226: VPS VUI flag to indicate tile not in use
 #define VPS_VUI_WPP_NOT_IN_USE__FLAG     1      ///< JCTVC-O0226: VPS VUI flag to indicate tile not in use
-#define TILE_BOUNDARY_ALIGNED_FLAG       1      ///< JCTVC-N0160/JCTVC-N0199 proposal 2 variant 2: VPS VUI flag to indicate tile boundary alignment
 #define N0160_VUI_EXT_ILP_REF            1      ///< VUI extension inter-layer dependency offset signalling
-#define VPS_VUI_BITRATE_PICRATE          1      ///< JCTVC-N0085: Signal bit rate and picture in VPS VUI
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
 #define HIGHER_LAYER_IRAP_SKIP_FLAG      1      ///< JCTVC-O0199: Indication that higher layer IRAP picture uses skip blocks only
@@ -158,7 +143,4 @@
 #endif 
 #define P0182_VPS_VUI_PS_FLAG            1      ///< JCTVC-P0182, add base_layer_parameter_set_compatibility_flag
-#endif //VPS_VUI
-
-#endif
 
 #define P0125_REVERT_VPS_EXTN_OFFSET_TO_RESERVED        1   ///< JCTVC-P0125 -- Keep it as a reserved FFFF value --- The following two macros (VPS_EXTN_OFFSET & VPS_EXTN_OFFSET_CALC) will have no effect when this macro is set to 1.
@@ -169,11 +151,4 @@
 #define DERIVE_LAYER_ID_LIST_VARIABLES   1      ///< Derived variables based on the variables in VPS - for use in syntax table parsing
 
-#define SVC_UPSAMPLING                   1      ///< upsampling filters
-#define ROUNDING_OFFSET                  1      ///< JCTVC-N0111: upsampling rounding offset using scalling factors
-#define N0214_INTERMEDIATE_BUFFER_16BITS 1      ///< JCTVC-N0214: support base layer input more than 8 bits
-#define ARBITRARY_SPATIAL_RATIO          1      ///< JCTVC-N0219, JCTVC-N0273: Support arbitrary spatial ratio
-
-#define JCTVC_M0259_LAMBDAREFINEMENT     1      ///< JCTVC-M0259: lambda refinement (encoder only optimization)
-
 #define AVC_BASE                         1      ///< YUV BL reading for AVC base SVC
 #if AVC_BASE
@@ -181,12 +156,9 @@
 #endif
 
-#define REF_IDX_ME_ZEROMV                1      ///< JCTVC-L0051: use zero motion for inter-layer reference picture (without fractional ME)
-#define ENCODER_FAST_MODE                1      ///< JCTVC-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.
 #define REF_IDX_MFM                      1      ///< JCTVC-L0336: motion vector mapping of inter-layer reference picture
 #define MAX_ONE_RESAMPLING_DIRECT_LAYERS 1      ///< Allow maximum of one resampling process for direct reference layers
 #define MOTION_RESAMPLING_CONSTRAINT     1      ///< JCTVC-N0108: Allow maximum of one motion resampling process for direct reference layers, and use motion inter-layer prediction from the same layer as texture inter-layer prediction.
-#define EARLY_REF_PIC_MARKING            1      ///< Decoded picture marking of sub-layer non-reference pictures
-#define N0120_MAX_TID_REF_PRESENT_FLAG   1      ///< JCTVC-N0120: max_tid_ref_pics_plus1_present_flag
-#define N0120_MAX_TID_REF_CFG            1      ///< set max_tid_il_ref_pics_plus1 and max_tid_ref_present_flag in the config. file (configuration setting)
+#define EARLY_REF_PIC_MARKING            0      ///< Valencia meeting - remove early marking of inter-layer reference pictures
+                                                ///< Decoded picture marking of sub-layer non-reference pictures
 #define O0225_MAX_TID_FOR_REF_LAYERS     1
 #define O0225_TID_BASED_IL_RPS_DERIV     1
@@ -195,30 +167,12 @@
 #define P0079_DERIVE_NUMACTIVE_REF_PICS  1      ///< JCTVC-P0079 Modification of derivation of variable NumActiveRefLayerPics
 #define Q0060_MAX_TID_REF_EQUAL_TO_ZERO  1      ///< JCTVC-Q0060 handling the case max_tid_il_ref_pics_plus1 is equal to 0.
-#if REF_IDX_MFM
-#define N0139_POSITION_ROUNDING_OFFSET   1      ///< JCTVC-N0139: offset for collocated block in motion mapping
-#endif
-
-#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 N0147_IRAP_ALIGN_FLAG            1      ///< a flag to indicatate whether IRAPs are aligned across layers
-#if N0147_IRAP_ALIGN_FLAG
-#define O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS  1  ///< Remove IRAP align depedency constraints on poc_Reset_flag.
-#define IRAP_ALIGN_FLAG_IN_VPS_VUI       1       ///< Move IRAP align flag to VPS VUI 
-#endif 
-#if !N0147_IRAP_ALIGN_FLAG
-#define IDR_ALIGNMENT                    1      ///< align IDR picures across layers : As per JCTVC-N0373, IDR are not required to be aligned.
-#endif
-#define FAST_INTRA_SHVC                  1      ///< JCTVC-M0115: reduction number of intra modes in the EL (encoder only)
-#if FAST_INTRA_SHVC
-#define NB_REMAIN_MODES                  2      ///< JCTVC-M0115: nb of remaining modes
-#endif
-
-#define RC_SHVC_HARMONIZATION            1      ///< JCTVC-M0037: rate control for SHVC
+#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
-#define LAYERS_NOT_PRESENT_SEI           1      ///< JCTVC-M0043: add layers not present SEI.
-#define N0383_IL_CONSTRAINED_TILE_SETS_SEI  1
 #define N0065_LAYER_POC_ALIGNMENT        1
 
@@ -246,5 +200,10 @@
 
 #define Q0165_OUTPUT_LAYER_SET           1      ///< JCTVC-Q0165: add a constraint to disallow an empty output layer set
-#define Q0165_NUM_ADD_OUTPUT_LAYER_SETS  1      ///< JCTVC-Q0165: signal num_add_output_layer_set and default_target_output_layer_idc when vps_num_layer_sets_minus1 is greater than 0
+#define Q0165_NUM_ADD_OUTPUT_LAYER_SETS  1      ///< JCTVC-Q0165: signal num_add_olss and default_target_output_layer_idc when vps_num_layer_sets_minus1 is greater than 0
+
+#define Q0078_ADD_LAYER_SETS             1      ///< JCTVC-Q0078: additional layer sets and layer set config
+#if Q0078_ADD_LAYER_SETS
+#define MAX_NUM_ADD_LAYER_SETS           1023
+#endif
 
 #define VPS_DPB_SIZE_TABLE               1      ///< JCTVC-O0217: DPB operations: signaling DPB-related parameters
@@ -263,13 +222,43 @@
 #define P0138_USE_ALT_CPB_PARAMS_FLAG    1      ///< JCTVC-P0138: use_alt_cpb_params_flag syntax in buffering period SEI message extension
 #define P0166_MODIFIED_PPS_EXTENSION     1      ///< JCTVC-P0166: add pps_extension_type_flag
-
-#if VIEW_ID_RELATED_SIGNALING
+#define BITRATE_PICRATE_SIGNALLING       1      ///< JCTVC-Q0102 Proposal 3 signal bitrate, picrate only up to the maximum temporal sub-layers in the corresponding layer set
+#define LAYER_DECPICBUFF_PARAM           1      ///< JCTVC-Q0102 Proposal 2 infer value from layer DPB param
+#define HRD_BPB                          1      ///< JCTVC-Q0101 Bitstream Partition Buffering Proposals
+#define DPB_CONSTRAINTS                  1      ///< JCTVC-Q0100 RPS DPB constraints
+
 /// scalability types
 enum ScalabilityType
 {
   VIEW_ORDER_INDEX  = 1,
-  SCALABILITY_ID = 2,
-};
-#endif
+  SCALABILITY_ID    = 2,
+  AUX_ID            = 3,
+};
+
+/// normative encoder constraints --------
+#define MFM_ENCCONSTRAINT                1      ///< JCTVC-O0216: Encoder constraint for motion field mapping
+#define REF_IDX_ME_ZEROMV                1      ///< JCTVC-L0051: use zero motion for inter-layer reference picture (without fractional ME)
+
+/// encoder settings ---------------------
+#define FAST_INTRA_SHVC                  1      ///< JCTVC-M0115: reduction number of intra modes in the EL (encoder only)
+#if FAST_INTRA_SHVC
+#define NB_REMAIN_MODES                  2      ///< JCTVC-M0115: nb of remaining modes
+#endif
+#define RC_SHVC_HARMONIZATION            1      ///< JCTVC-M0037: rate control for SHVC
+#define JCTVC_M0259_LAMBDAREFINEMENT     1      ///< JCTVC-M0259: lambda refinement (encoder only optimization)
+#define ENCODER_FAST_MODE                1      ///< JCTVC-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.
+#define LAYER_CTB                        0      ///< enable layer-specific CTB structure
+
+/// SEI messages -------------------------
+#define P0050_KNEE_FUNCTION_SEI          1      ///< JCTVC-P0050: Knee function SEI
+#define SUB_BITSTREAM_PROPERTY_SEI       1      ///< JCTVC-P0204: Sub-bitstream property SEI message
+#if SUB_BITSTREAM_PROPERTY_SEI
+#define MAX_SUB_STREAMS                  1024
+#endif
+#define Q0074_SEI_COLOR_MAPPING          1      ///< JCTVC-Q0074, SEI Color Mapping
+#define LAYERS_NOT_PRESENT_SEI           1      ///< JCTVC-M0043: add layers not present SEI.
+#define N0383_IL_CONSTRAINED_TILE_SETS_SEI  1
+#define Q0189_TMVP_CONSTRAINTS           1      ///< JCTVC-Q0189: indicate constraints on TMVP
+#define Q0247_FRAME_FIELD_INFO           1      ///< JCTVC-Q0247: field_frame_info SEI message
+
 
 #else
@@ -304,6 +293,6 @@
 #define MAX_NESTING_NUM_LAYER       64
 
-#if VPS_RENAME
-#define MAX_VPS_OP_LAYER_SETS_PLUS1               3
+#if SVC_EXTENSION
+#define MAX_VPS_OP_LAYER_SETS_PLUS1               (MAX_LAYERS+1)
 #define MAX_VPS_LAYER_SETS_PLUS1                  1024
 #define MAX_VPS_LAYER_ID_PLUS1                    MAX_LAYERS
Index: trunk/source/Lib/TLibDecoder/NALread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/NALread.cpp	(revision 752)
+++ trunk/source/Lib/TLibDecoder/NALread.cpp	(revision 815)
@@ -114,4 +114,5 @@
   if ( nalu.m_temporalId )
   {
+#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
@@ -124,11 +125,29 @@
          && nalu.m_nalUnitType != NAL_UNIT_EOS
          && nalu.m_nalUnitType != NAL_UNIT_EOB );
+#else
+    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_LP
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_RADL
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_N_LP
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_W_RADL
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_N_LP
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA
+         && nalu.m_nalUnitType != NAL_UNIT_VPS
+         && nalu.m_nalUnitType != NAL_UNIT_SPS
+         && nalu.m_nalUnitType != NAL_UNIT_EOS); 
+#endif
   }
   else
   {
+#if !Q0108_TSA_STSA
     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R
          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N );
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N 
+         );
+#else
+    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
+         );
+#endif
   }
 }
Index: trunk/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 752)
+++ trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 815)
@@ -93,4 +93,9 @@
     fprintf( g_hTrace, "===========Tone Mapping Info SEI message ===========\n");
     break;
+#if P0050_KNEE_FUNCTION_SEI
+  case SEI::KNEE_FUNCTION_INFO:
+    fprintf( g_hTrace, "=========== Knee Function Information SEI message ===========\n");
+    break;
+#endif
 #if Q0074_SEI_COLOR_MAPPING
   case SEI::COLOR_MAPPING_INFO:
@@ -129,4 +134,12 @@
   case SEI::BSP_HRD:
     fprintf( g_hTrace, "=========== Bitstream parition HRD parameters SEI message ===========\n");
+    break;
+#endif
+#if Q0078_ADD_LAYER_SETS
+  case SEI::OUTPUT_LAYER_SET_NESTING:
+    fprintf(g_hTrace, "=========== Output layer set nesting SEI message ===========\n");
+    break;
+  case SEI::VPS_REWRITING:
+    fprintf(g_hTrace, "=========== VPS rewriting SEI message ===========\n");
     break;
 #endif
@@ -285,4 +298,10 @@
       xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize);
       break;
+#if P0050_KNEE_FUNCTION_SEI
+    case SEI::KNEE_FUNCTION_INFO:
+      sei = new SEIKneeFunctionInfo;
+      xParseSEIKneeFunctionInfo((SEIKneeFunctionInfo&) *sei, payloadSize);
+      break;
+#endif
 #if Q0074_SEI_COLOR_MAPPING
     case SEI::COLOR_MAPPING_INFO:
@@ -345,4 +364,30 @@
      sei = new SEIBspHrd;
      xParseSEIBspHrd((SEIBspHrd&) *sei, sps, *nestingSei);
+     break;
+#endif
+#if Q0078_ADD_LAYER_SETS
+   case SEI::OUTPUT_LAYER_SET_NESTING:
+     sei = new SEIOutputLayerSetNesting;
+#if LAYERS_NOT_PRESENT_SEI
+     xParseSEIOutputLayerSetNesting((SEIOutputLayerSetNesting&)*sei, nalUnitType, vps, sps);
+#else
+     xParseSEIOutputLayerSetNesting((SEIOutputLayerSetNesting&)*sei, nalUnitType, sps);
+#endif
+     break;
+   case SEI::VPS_REWRITING:
+     sei = new SEIVPSRewriting;
+     xParseSEIVPSRewriting((SEIVPSRewriting&)*sei);
+     break;
+#endif
+#if Q0189_TMVP_CONSTRAINTS
+   case SEI::TMVP_CONSTRAINTS:
+     sei =  new SEITMVPConstrains;
+     xParseSEITMVPConstraints((SEITMVPConstrains&) *sei, payloadSize);
+     break;
+#endif
+#if Q0247_FRAME_FIELD_INFO
+   case SEI::FRAME_FIELD_INFO:
+     sei =  new SEIFrameFieldInfo;
+     xParseSEIFrameFieldInfo    ((SEIFrameFieldInfo&) *sei, payloadSize); 
      break;
 #endif
@@ -849,4 +894,31 @@
 }
 
+#if P0050_KNEE_FUNCTION_SEI
+Void SEIReader::xParseSEIKneeFunctionInfo(SEIKneeFunctionInfo& sei, UInt /*payloadSize*/){
+  Int i;
+  UInt val;
+  READ_UVLC( val, "knee_function_id" );                   sei.m_kneeId = val;
+  READ_FLAG( val, "knee_function_cancel_flag" );          sei.m_kneeCancelFlag = val;
+  if ( !sei.m_kneeCancelFlag )
+  {
+    READ_FLAG( val, "knee_function_persistence_flag" );   sei.m_kneePersistenceFlag = val;
+    READ_FLAG( val, "mapping_flag" );                     sei.m_kneeMappingFlag = val;
+    READ_CODE( 32, val, "input_d_range" );                sei.m_kneeInputDrange = val;
+    READ_CODE( 32, val, "input_disp_luminance" );         sei.m_kneeInputDispLuminance = val;
+    READ_CODE( 32, val, "output_d_range" );               sei.m_kneeOutputDrange = val;
+    READ_CODE( 32, val, "output_disp_luminance" );        sei.m_kneeOutputDispLuminance = val;
+    READ_UVLC( val, "num_knee_points_minus1" );           sei.m_kneeNumKneePointsMinus1 = val;
+    assert( sei.m_kneeNumKneePointsMinus1 > 0 );
+    sei.m_kneeInputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
+    sei.m_kneeOutputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
+    for(i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ )
+    {
+      READ_CODE( 10, val, "input_knee_point" );           sei.m_kneeInputKneePoint[i] = val;
+      READ_CODE( 10, val, "output_knee_point" );          sei.m_kneeOutputKneePoint[i] = val;
+    }
+  }
+}
+#endif
+
 #if Q0074_SEI_COLOR_MAPPING
 Void SEIReader::xParseSEIColorMappingInfo(SEIColorMappingInfo& sei, UInt /*payloadSize*/)
@@ -960,4 +1032,25 @@
 }
 
+#if Q0189_TMVP_CONSTRAINTS 
+Void SEIReader::xParseSEITMVPConstraints   (SEITMVPConstrains& sei, UInt payloadSize)
+{
+  UInt uiCode;
+  READ_UVLC( uiCode,           "prev_pics_not_used_flag"              ); sei.prev_pics_not_used_flag = uiCode;
+  READ_UVLC( uiCode,           "no_intra_layer_col_pic_flag"            ); sei.no_intra_layer_col_pic_flag = uiCode;
+  xParseByteAlign();
+}
+#endif
+
+#if Q0247_FRAME_FIELD_INFO
+Void SEIReader::xParseSEIFrameFieldInfo    (SEIFrameFieldInfo& sei, UInt payloadSize)
+{
+  UInt code;
+  READ_CODE( 4, code, "ffinfo_pic_struct" );             sei.m_ffinfo_picStruct            = code;
+  READ_CODE( 2, code, "ffinfo_source_scan_type" );       sei.m_ffinfo_sourceScanType = code;
+  READ_FLAG(    code, "ffinfo_duplicate_flag" );         sei.m_ffinfo_duplicateFlag    = ( code == 1 ? true : false );
+  xParseByteAlign();
+}
+#endif
+
 #if LAYERS_NOT_PRESENT_SEI
 Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComVPS *vps, TComSPS *sps)
@@ -1209,21 +1302,69 @@
     UInt lsIdx = nestingSei.m_nestingOpIdx[h];
     READ_UVLC( uiCode, "num_sei_bitstream_partitions_minus1[i]"); sei.m_seiNumBitstreamPartitionsMinus1[lsIdx] = uiCode;
-    for (UInt i = 0; i <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; i++)
-    {
-      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
+#if HRD_BPB
+    Int chkPart=0;
+#endif
+    UInt i;
+    for(i = 0; i <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; i++)
+    {
+#if HRD_BPB
+      UInt nl=0; UInt j;
+      for(j = 0; j < sei.m_vpsMaxLayers; j++)
       {
         if (sei.m_layerIdIncludedFlag[lsIdx][j])
         {
+          nl++;
+        }
+      }
+      for (j = 0; j < nl; j++)
+      {
+#else
+      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
+      {
+        if (sei.m_layerIdIncludedFlag[lsIdx][j])
+        {
+#endif
           READ_FLAG( uiCode, "sei_layer_in_bsp_flag[lsIdx][i][j]" ); sei.m_seiLayerInBspFlag[lsIdx][i][j] = uiCode;
         }
-      }
-    }
+#if !HRD_BPB
+      }
+#endif
+#if HRD_BPB
+      chkPart+=sei.m_seiLayerInBspFlag[lsIdx][i][j];
+#endif
+    }
+#if HRD_BPB
+    assert(chkPart<=1);
+#endif
+#if HRD_BPB
+    if(sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]==0)
+    {
+      Int chkPartition1=0; Int chkPartition2=0;
+      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
+      {
+        if( sei.m_layerIdIncludedFlag[lsIdx][j] )
+        {
+          chkPartition1+=sei.m_seiLayerInBspFlag[lsIdx][0][j];
+          chkPartition2++;
+        }
+      }
+      assert(chkPartition1!=chkPartition2);
+    }
+#endif
+      
     READ_UVLC( uiCode, "sei_num_bsp_sched_combinations_minus1[i]"); sei.m_seiNumBspSchedCombinationsMinus1[lsIdx] = uiCode;
-    for (UInt i = 0; i <= sei.m_seiNumBspSchedCombinationsMinus1[lsIdx]; i++)
+    for (i = 0; i <= sei.m_seiNumBspSchedCombinationsMinus1[lsIdx]; i++)
     {
       for (UInt j = 0; j <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; j++)
       {
         READ_UVLC( uiCode, "sei_bsp_comb_hrd_idx[lsIdx][i][j]"); sei.m_seiBspCombHrdIdx[lsIdx][i][j] = uiCode;
+#if HRD_BPB
+        assert(uiCode <= sei.m_seiNumBspHrdParametersMinus1);
+#endif
         READ_UVLC( uiCode, "sei_bsp_comb_sched_idx[lsIdx][i][j]"); sei.m_seiBspCombScheddx[lsIdx][i][j] = uiCode;
+#if HRD_BPB
+        assert(uiCode <= sei.hrd->getCpbCntMinus1( sps->getMaxTLayers()-1 ));
+#endif
+
       }
     }
@@ -1307,4 +1448,57 @@
 #endif
 
+#if Q0078_ADD_LAYER_SETS
+
+#if LAYERS_NOT_PRESENT_SEI
+Void SEIReader::xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps)
+#else
+Void SEIReader::xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComSPS *sps)
+#endif
+{
+  UInt uiCode;
+  SEIMessages seis;
+
+  READ_FLAG(uiCode, "ols_flag"); sei.m_olsFlag = uiCode;
+  READ_UVLC(uiCode, "num_ols_indices_minus1"); sei.m_numOlsIndicesMinus1 = uiCode;
+
+  for (Int i = 0; i <= sei.m_numOlsIndicesMinus1; i++)
+  {
+    READ_UVLC(uiCode, "ols_idx[i]"); sei.m_olsIdx[i] = uiCode;
+  }
+
+  // byte alignment
+  while (m_pcBitstream->getNumBitsRead() % 8 != 0)
+  {
+    UInt code;
+    READ_FLAG(code, "ols_nesting_zero_bit");
+  }
+
+  sei.m_callerOwnsSEIs = false;
+
+  // read nested SEI messages
+  do {
+#if O0164_MULTI_LAYER_HRD
+#if LAYERS_NOT_PRESENT_SEI
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps);
+#else
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
+#endif
+#else
+#if LAYERS_NOT_PRESENT_SEI
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps);
+#else
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
+#endif
+#endif
+  } while (m_pcBitstream->getNumBitsLeft() > 8);
+
+}
+
+Void SEIReader::xParseSEIVPSRewriting(SEIVPSRewriting &sei)
+{
+}
+
+#endif
+
 #endif //SVC_EXTENSION
 
Index: trunk/source/Lib/TLibDecoder/SEIread.h
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.h	(revision 752)
+++ trunk/source/Lib/TLibDecoder/SEIread.h	(revision 815)
@@ -90,4 +90,7 @@
   Void xParseSEIGradualDecodingRefreshInfo (SEIGradualDecodingRefreshInfo &sei, UInt payloadSize);
   Void xParseSEIToneMappingInfo       (SEIToneMappingInfo& sei, UInt payloadSize);
+#if P0050_KNEE_FUNCTION_SEI
+  Void xParseSEIKneeFunctionInfo      (SEIKneeFunctionInfo& sei, UInt payloadSize);
+#endif
 #if Q0074_SEI_COLOR_MAPPING
   Void xParseSEIColorMappingInfo      (SEIColorMappingInfo& sei, UInt payloadSize);
@@ -116,4 +119,19 @@
   Void xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1);
 #endif
+#if Q0078_ADD_LAYER_SETS
+#if LAYERS_NOT_PRESENT_SEI
+  Void xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps);
+#else
+  Void xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComSPS *sps);
+#endif
+  Void xParseSEIVPSRewriting(SEIVPSRewriting &sei);
+#endif
+
+#if Q0189_TMVP_CONSTRAINTS 
+  Void xParseSEITMVPConstraints    (SEITMVPConstrains& sei, UInt payloadSize);
+#endif
+#if Q0247_FRAME_FIELD_INFO
+  Void xParseSEIFrameFieldInfo    (SEIFrameFieldInfo& sei, UInt payloadSize);
+#endif
   Void xParseByteAlign();
 };
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 752)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 815)
@@ -339,5 +339,11 @@
 
   READ_FLAG( uiCode, "pps_extension_flag");
+#if POC_RESET_INFO_INFERENCE
+  pcPPS->setExtensionFlag( uiCode ? true : false );
+
+  if( pcPPS->getExtensionFlag() )
+#else
   if (uiCode)
+#endif  
   {
 #if P0166_MODIFIED_PPS_EXTENSION
@@ -367,4 +373,10 @@
 #endif
     }
+#if POC_RESET_INFO_INFERENCE
+    else  // Extension type 0 absent
+    {
+      pcPPS->setPocResetInfoPresentFlag( false );
+    }
+#endif
     if (ppsExtensionTypeFlag[7])
     {
@@ -379,4 +391,10 @@
 #endif
   }
+#if POC_RESET_INFO_INFERENCE
+  if( !pcPPS->getExtensionFlag() )
+  {
+    pcPPS->setPocResetInfoPresentFlag( false );
+  }
+#endif
 }
 
@@ -443,5 +461,5 @@
   TimingInfo *timingInfo = pcVUI->getTimingInfo();
   READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
-#if TIMING_INFO_NONZERO_LAYERID_SPS
+#if SVC_EXTENSION
   if( pcSPS->getLayerId() > 0 )
   {
@@ -585,4 +603,5 @@
 #endif
 
+#if !Q0177_SPS_TEMP_NESTING_FIX   //This part is not needed anymore as it is already covered by implementation in TDecTop::xActivateParameterSets()
   if ( pcSPS->getMaxTLayers() == 1 )
   {
@@ -596,4 +615,6 @@
 #endif
   }
+#endif
+
 #ifdef SPS_PTL_FIX
   if ( pcSPS->getLayerId() == 0)
@@ -827,8 +848,10 @@
 
   READ_FLAG( uiCode, "sps_extension_flag");
-  if (uiCode)
-  {
-#if SPS_EXTENSION
-
+
+#if SVC_EXTENSION
+  pcSPS->setExtensionFlag( uiCode ? true : false );
+
+  if( pcSPS->getExtensionFlag() )
+  {
 #if O0142_CONDITIONAL_SPS_EXTENSION
     UInt spsExtensionTypeFlag[8];
@@ -849,17 +872,22 @@
     {
 #endif
-
-#endif
       while ( xMoreRbspData() )
       {
         READ_FLAG( uiCode, "sps_extension_data_flag");
       }
-#if SPS_EXTENSION
-    }
-#endif
-  }
-}
-
-#if SPS_EXTENSION
+    }
+  }
+#else
+  if (uiCode)
+  {
+    while ( xMoreRbspData() )
+    {
+      READ_FLAG( uiCode, "sps_extension_data_flag");
+    }
+  }
+#endif
+}
+
+#if SVC_EXTENSION
 Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
 {
@@ -899,5 +927,5 @@
   READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
   READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
-#if VPS_RENAME
+#if SVC_EXTENSION
 #if O0137_MAX_LAYERID
   READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( min( 62u, uiCode) + 1 );
@@ -941,10 +969,16 @@
   }
 
-#if VPS_RENAME
+#if SVC_EXTENSION
   assert( pcVPS->getNumHrdParameters() < MAX_VPS_LAYER_SETS_PLUS1 );
   assert( pcVPS->getMaxLayerId()       < MAX_VPS_LAYER_ID_PLUS1 );
   READ_CODE( 6, uiCode, "vps_max_layer_id" );           pcVPS->setMaxLayerId( uiCode );
+#if Q0078_ADD_LAYER_SETS
+  READ_UVLC(uiCode, "vps_num_layer_sets_minus1");  pcVPS->setVpsNumLayerSetsMinus1(uiCode);
+  pcVPS->setNumLayerSets(pcVPS->getVpsNumLayerSetsMinus1() + 1);
+  for (UInt opsIdx = 1; opsIdx <= pcVPS->getVpsNumLayerSetsMinus1(); opsIdx++)
+#else
   READ_UVLC(    uiCode, "vps_num_layer_sets_minus1" );  pcVPS->setNumLayerSets( uiCode + 1 );
   for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getNumLayerSets() - 1 ); opsIdx ++ )
+#endif
   {
     // Operation point set
@@ -995,5 +1029,5 @@
   }
 
-#if VPS_EXTNS
+#if SVC_EXTENSION
   READ_FLAG( uiCode,  "vps_extension_flag" );      pcVPS->setVpsExtensionFlag( uiCode ? true : false );
 
@@ -1040,5 +1074,4 @@
 
 #if SVC_EXTENSION
-#if VPS_EXTNS
 Void TDecCavlc::parseVPSExtension(TComVPS *vps)
 {
@@ -1081,4 +1114,5 @@
   }
 
+  // The value of dimBitOffset[ NumScalabilityTypes ] is set equal to 6.
   if(vps->getSplittingFlag())
   {
@@ -1166,4 +1200,19 @@
   }
 #endif
+#if Q0078_ADD_LAYER_SETS
+#if O0092_0094_DEPENDENCY_CONSTRAINT // Moved here
+  vps->setNumRefLayers();
+
+  if (vps->getMaxLayers() > MAX_REF_LAYERS)
+  {
+    for (i = 1; i < vps->getMaxLayers(); i++)
+    {
+      assert(vps->getNumRefLayers(vps->getLayerIdInNuh(i)) <= MAX_REF_LAYERS);
+    }
+  }
+#endif
+  vps->setPredictedLayerIds();
+  vps->setTreePartitionLayerIdList();
+#endif
 #if VPS_TSLAYERS
   READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag"); vps->setMaxTSLayersPresentFlag(uiCode ? true : false);
@@ -1184,5 +1233,4 @@
   }
 #endif
-#if N0120_MAX_TID_REF_PRESENT_FLAG
   READ_FLAG( uiCode, "max_tid_ref_present_flag"); vps->setMaxTidRefPresentFlag(uiCode ? true : false);
   if (vps->getMaxTidRefPresentFlag())
@@ -1201,9 +1249,5 @@
 #else
       READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); vps->setMaxTidIlRefPicsPlus1(i, uiCode);
-#if N0120_MAX_TID_REF_CFG
       assert( uiCode <= vps->getMaxTLayers());
-#else
-      assert( uiCode <= vps->getMaxTLayers()+ 1 );
-#endif
 #endif 
     }
@@ -1223,25 +1267,5 @@
     }
   }
-#else
-  for(i = 0; i < vps->getMaxLayers() - 1; i++)
-  {
-#if O0225_MAX_TID_FOR_REF_LAYERS
-       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
-       {
-         if(vps->getDirectDependencyFlag(j, i))
-         {
-           READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i][j]" ); vps->setMaxTidIlRefPicsPlus1(i, j, uiCode);
-           assert( uiCode <= vps->getMaxTLayers() );
-         }
-       }
-#else
-    READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); vps->setMaxTidIlRefPicsPlus1(i, uiCode);
-    assert( uiCode <= vps->getMaxTLayers() );
-#endif   
-  }
-#endif
-#if ILP_SSH_SIG
-    READ_FLAG( uiCode, "all_ref_layers_active_flag" ); vps->setIlpSshSignalingEnabledFlag(uiCode ? true : false);
-#endif
+  READ_FLAG( uiCode, "all_ref_layers_active_flag" ); vps->setIlpSshSignalingEnabledFlag(uiCode ? true : false);
 #if VPS_EXTN_PROFILE_INFO
   // Profile-tier-level signalling
@@ -1276,4 +1300,25 @@
 #endif
 
+#if Q0078_ADD_LAYER_SETS
+  if (vps->getNumIndependentLayers() > 1)
+  {
+    READ_UVLC(uiCode, "num_add_layer_sets"); vps->setNumAddLayerSets(uiCode);
+    for (i = 0; i < vps->getNumAddLayerSets(); i++)
+    {
+      for (j = 1; j < vps->getNumIndependentLayers(); j++)
+      {
+        int len = 1;
+        while ((1 << len) < (vps->getNumLayersInTreePartition(j) + 1))
+        {
+          len++;
+        }
+        READ_CODE(len, uiCode, "highest_layer_idx_plus1[i][j]"); vps->setHighestLayerIdxPlus1(i, j, uiCode);
+      }
+    }
+    vps->setNumLayerSets(vps->getNumLayerSets() + vps->getNumAddLayerSets());
+    vps->setLayerIdIncludedFlagsForAddLayerSets();
+  }
+#endif
+
 #if !VPS_EXTN_UEV_CODING
   READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); vps->setMoreOutputLayerSetsThanDefaultFlag( uiCode ? true : false );
@@ -1293,6 +1338,6 @@
   if( vps->getNumLayerSets() > 1 )
   {
-    READ_UVLC( uiCode, "num_add_output_layer_sets" );            vps->setNumAddOutputLayerSets( uiCode );
-    READ_CODE( 2, uiCode, "default_target_output_layer_idc" );   vps->setDefaultTargetOutputLayerIdc( uiCode );
+    READ_UVLC( uiCode, "num_add_olss" );            vps->setNumAddOutputLayerSets( uiCode );
+    READ_CODE( 2, uiCode, "default_output_layer_idc" );   vps->setDefaultTargetOutputLayerIdc( uiCode );
   }
   else
@@ -1304,5 +1349,5 @@
 #endif
 
-  // The value of num_add_output_layer_sets shall be in the range of 0 to 1023, inclusive.
+  // The value of num_add_olss shall be in the range of 0 to 1023, inclusive.
   assert( vps->getNumAddOutputLayerSets() >= 0 && vps->getNumAddOutputLayerSets() < 1024 );
 
@@ -1328,5 +1373,5 @@
         numBits++;
       }
-      READ_CODE( numBits, uiCode, "output_layer_set_idx_minus1");   vps->setOutputLayerSetIdx( i, uiCode + 1);
+      READ_CODE( numBits, uiCode, "layer_set_idx_for_ols_minus1");   vps->setOutputLayerSetIdx( i, uiCode + 1);
     }
     else
@@ -1334,5 +1379,9 @@
       vps->setOutputLayerSetIdx( i, i );
     }
+#if Q0078_ADD_LAYER_SETS
+    if ( i > vps->getVpsNumLayerSetsMinus1() || vps->getDefaultTargetOutputLayerIdc() >= 2 )
+#else
     if ( i > (vps->getNumLayerSets() - 1) || vps->getDefaultTargetOutputLayerIdc() >= 2 )
+#endif
     {
       Int lsIdx = vps->getOutputLayerSetIdx(i);
@@ -1634,5 +1683,5 @@
 #endif
 
-#if N0147_IRAP_ALIGN_FLAG && !IRAP_ALIGN_FLAG_IN_VPS_VUI
+#if !IRAP_ALIGN_FLAG_IN_VPS_VUI
   READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
   vps->setCrossLayerIrapAlignFlag(uiCode);
@@ -1678,9 +1727,8 @@
   }
 #endif
-#if O0092_0094_DEPENDENCY_CONSTRAINT
-  for(i = 1; i < vps->getMaxLayers(); i++)
-  {
-    vps->setNumRefLayers(vps->getLayerIdInNuh(i));   // identify the number of direct and indirect reference layers of current layer and set recursiveRefLayersFlags
-  }
+#if !Q0078_ADD_LAYER_SETS
+#if O0092_0094_DEPENDENCY_CONSTRAINT // Moved up
+  vps->setNumRefLayers();
+
   if(vps->getMaxLayers() > MAX_REF_LAYERS)
   {
@@ -1690,4 +1738,5 @@
     }
   }
+#endif
 #endif
 
@@ -1732,5 +1781,4 @@
 #endif
   {
-#if VPS_VUI
     while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
     {
@@ -1738,5 +1786,4 @@
     }
     parseVPSVUI(vps);
-#endif
   }
   else
@@ -1778,10 +1825,10 @@
   }
   
-  // When not present, the value of num_add_output_layer_sets is inferred to be equal to 0.
-  // NumOutputLayerSets = num_add_output_layer_sets + vps_num_layer_sets_minus1 + 1
+  // When not present, the value of num_add_olss is inferred to be equal to 0.
+  // NumOutputLayerSets = num_add_olss + NumLayerSets
   vps->setNumOutputLayerSets( vps->getNumLayerSets() );
 
   // For i in the range of 0 to NumOutputLayerSets-1, inclusive, the variable LayerSetIdxForOutputLayerSet[ i ] is derived as specified in the following: 
-  // LayerSetIdxForOutputLayerSet[ i ] = ( i <= vps_number_layer_sets_minus1 ) ? i : output_layer_set_idx_minus1[ i ] + 1
+  // LayerSetIdxForOutputLayerSet[ i ] = ( i <= vps_number_layer_sets_minus1 ) ? i : layer_set_idx_for_ols_minus1[ i ] + 1
   for( i = 1; i < vps->getNumOutputLayerSets(); i++ )
   {
@@ -1834,8 +1881,6 @@
 Void TDecCavlc::defaultVPSVUI( TComVPS* vps )
 {
-#if N0147_IRAP_ALIGN_FLAG
   // When not present, the value of all_layers_idr_aligned_flag is inferred to be equal to 0.
   vps->setCrossLayerIrapAlignFlag( false );
-#endif
 
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
@@ -1849,5 +1894,4 @@
 #endif
 }
-#endif
 
 #if REPN_FORMAT_IN_VPS
@@ -1918,6 +1962,11 @@
   UInt uiCode;
 #if DPB_PARAMS_MAXTLAYERS
+#if BITRATE_PICRATE_SIGNALLING
+    Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumLayerSets()];
+    for(Int i = 0; i < vps->getNumLayerSets(); i++)
+#else
     Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumOutputLayerSets()];
     for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
+#endif
     {
         UInt maxSLMinus1 = 0;
@@ -1927,4 +1976,7 @@
         Int optLsIdx = i;
 #endif
+#if BITRATE_PICRATE_SIGNALLING
+        optLsIdx = i;
+#endif
         for(Int k = 0; k < vps->getNumLayersInIdList(optLsIdx); k++ ) {
             Int  lId = vps->getLayerSetLayerIdList(optLsIdx, k);
@@ -1932,4 +1984,7 @@
         }
         MaxSubLayersInLayerSetMinus1[ i ] = maxSLMinus1;
+#if BITRATE_PICRATE_SIGNALLING
+        vps->setMaxSLayersInLayerSetMinus1(i,MaxSubLayersInLayerSetMinus1[ i ]);
+#endif
     }
 #endif
@@ -1945,5 +2000,9 @@
     READ_FLAG( uiCode, "sub_layer_flag_info_present_flag[i]");  vps->setSubLayerFlagInfoPresentFlag( i, uiCode ? true : false );
 #if DPB_PARAMS_MAXTLAYERS
+#if BITRATE_PICRATE_SIGNALLING
+    for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ vps->getOutputLayerSetIdx( i ) ]; j++)
+#else
     for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ i ]; j++)
+#endif
 #else
     for(Int j = 0; j <= vps->getMaxTLayers(); j++)
@@ -2009,13 +2068,19 @@
       if( !vps->getSubLayerDpbInfoPresentFlag(i, j) )  // If sub-layer DPB information is NOT present
       {
+#if RESOLUTION_BASED_DPB
         for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
+#else
+        for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
+#endif
         {
           vps->setMaxVpsDecPicBufferingMinus1( i, k, j, vps->getMaxVpsDecPicBufferingMinus1( i, k, j - 1 ) );
         }
         vps->setMaxVpsNumReorderPics( i, j, vps->getMaxVpsNumReorderPics( i, j - 1) );
+#if RESOLUTION_BASED_DPB
         for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
         {
           vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j - 1));
         }
+#endif
         vps->setMaxVpsLatencyIncreasePlus1( i, j, vps->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
       }
@@ -2024,5 +2089,5 @@
 }
 #endif
-#if VPS_VUI
+
 Void TDecCavlc::parseVPSVUI(TComVPS *vps)
 {
@@ -2039,8 +2104,8 @@
     vps->setCrossLayerIrapAlignFlag(uiCode);
 #if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
-    if (uiCode)
-    {
-      READ_FLAG(uiCode, "all_layers_idr_aligned_flag" );
-      vps->setCrossLayerIrapAlignFlag(uiCode);
+    if( uiCode )
+    {
+      READ_FLAG( uiCode, "all_layers_idr_aligned_flag" );
+      vps->setCrossLayerAlignedIdrOnlyFlag(uiCode);
     }
 #endif
@@ -2053,54 +2118,60 @@
   }
 #endif
-#if VPS_VUI_BITRATE_PICRATE
+
   READ_FLAG( uiCode,        "bit_rate_present_vps_flag" );  vps->setBitRatePresentVpsFlag( uiCode ? true : false );
   READ_FLAG( uiCode,        "pic_rate_present_vps_flag" );  vps->setPicRatePresentVpsFlag( uiCode ? true : false );
 
   Bool parseFlag = vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag();
-  {
-    for( i = 0; i < vps->getNumLayerSets(); i++ )
-    {
-      for( j = 0; j < vps->getMaxTLayers(); j++ )
-      {
-        if( parseFlag && vps->getBitRatePresentVpsFlag() )
-        {
-          READ_FLAG( uiCode,        "bit_rate_present_flag[i][j]" );  vps->setBitRatePresentFlag( i, j, uiCode ? true : false );
-        }
-        else
-        {
-          vps->setBitRatePresentFlag( i, j, false );
-        }
-        if( parseFlag && vps->getPicRatePresentVpsFlag() )
-        {
-          READ_FLAG( uiCode,        "pic_rate_present_flag[i][j]" );  vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
-        }
-        else
-        {
-          vps->setPicRatePresentFlag( i, j, false );
-        }
-        if( parseFlag && vps->getBitRatePresentFlag(i, j) )
-        {
-          READ_CODE( 16, uiCode,    "avg_bit_rate[i][j]" ); vps->setAvgBitRate( i, j, uiCode );
-          READ_CODE( 16, uiCode,    "max_bit_rate[i][j]" ); vps->setMaxBitRate( i, j, uiCode );
-        }
-        else
-        {
-          vps->setAvgBitRate( i, j, 0 );
-          vps->setMaxBitRate( i, j, 0 );
-        }
-        if( parseFlag && vps->getPicRatePresentFlag(i, j) )
-        {
-          READ_CODE( 2 , uiCode,    "constant_pic_rate_idc[i][j]" ); vps->setConstPicRateIdc( i, j, uiCode );
-          READ_CODE( 16, uiCode,    "avg_pic_rate[i][j]"          ); vps->setAvgPicRate( i, j, uiCode );
-        }
-        else
-        {
-          vps->setConstPicRateIdc( i, j, 0 );
-          vps->setAvgPicRate     ( i, j, 0 );
-        }
-      }
-    }
-  }
-#endif
+
+#if Q0078_ADD_LAYER_SETS
+  for( i = 0; i <= vps->getVpsNumLayerSetsMinus1(); i++ )
+#else
+  for( i = 0; i < vps->getNumLayerSets(); i++ )
+#endif
+  {
+#if BITRATE_PICRATE_SIGNALLING
+    for( j = 0; j <= vps->getMaxSLayersInLayerSetMinus1(i); j++ )
+#else
+    for( j = 0; j < vps->getMaxTLayers(); j++ )
+#endif
+    {
+      if( parseFlag && vps->getBitRatePresentVpsFlag() )
+      {
+        READ_FLAG( uiCode,        "bit_rate_present_flag[i][j]" );  vps->setBitRatePresentFlag( i, j, uiCode ? true : false );
+      }
+      else
+      {
+        vps->setBitRatePresentFlag( i, j, false );
+      }
+      if( parseFlag && vps->getPicRatePresentVpsFlag() )
+      {
+        READ_FLAG( uiCode,        "pic_rate_present_flag[i][j]" );  vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
+      }
+      else
+      {
+        vps->setPicRatePresentFlag( i, j, false );
+      }
+      if( parseFlag && vps->getBitRatePresentFlag(i, j) )
+      {
+        READ_CODE( 16, uiCode,    "avg_bit_rate[i][j]" ); vps->setAvgBitRate( i, j, uiCode );
+        READ_CODE( 16, uiCode,    "max_bit_rate[i][j]" ); vps->setMaxBitRate( i, j, uiCode );
+      }
+      else
+      {
+        vps->setAvgBitRate( i, j, 0 );
+        vps->setMaxBitRate( i, j, 0 );
+      }
+      if( parseFlag && vps->getPicRatePresentFlag(i, j) )
+      {
+        READ_CODE( 2 , uiCode,    "constant_pic_rate_idc[i][j]" ); vps->setConstPicRateIdc( i, j, uiCode );
+        READ_CODE( 16, uiCode,    "avg_pic_rate[i][j]"          ); vps->setAvgPicRate( i, j, uiCode );
+      }
+      else
+      {
+        vps->setConstPicRateIdc( i, j, 0 );
+        vps->setAvgPicRate     ( i, j, 0 );
+      }
+    }
+  }
 #if VPS_VUI_VIDEO_SIGNAL_MOVE
   READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
@@ -2162,5 +2233,5 @@
     }
 #endif
-#if TILE_BOUNDARY_ALIGNED_FLAG
+
     for(i = 1; i < vps->getMaxLayers(); i++)
     {
@@ -2177,5 +2248,4 @@
       }
     }
-#endif
 #if VPS_VUI_TILES_NOT_IN_USE__FLAG
   }
@@ -2290,7 +2360,14 @@
         parseHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
       }
+#if Q0078_ADD_LAYER_SETS
+      for (UInt h = 1; h <= vps->getVpsNumLayerSetsMinus1(); h++)
+#else
       for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
+#endif
       {
         READ_UVLC( uiCode, "num_bitstream_partitions[i]"); vps->setNumBitstreamPartitions(h, uiCode);
+#if HRD_BPB
+        Int chkPart=0;
+#endif
         for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
         {
@@ -2302,8 +2379,33 @@
             }
           }
-        }
+#if HRD_BPB
+          chkPart+=vps->getLayerInBspFlag(h, i, j);
+#endif
+        }
+#if HRD_BPB
+        assert(chkPart<=1);
+#endif
+#if HRD_BPB
+        if(vps->getNumBitstreamPartitions(h)==1)
+        {
+          Int chkPartition1=0; Int chkPartition2=0;
+          for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
+          {
+            if( vps->getLayerIdIncludedFlag(h, j) )
+            {
+              chkPartition1+=vps->getLayerInBspFlag(h, 0, j);
+              chkPartition2++;
+            }
+          }
+          assert(chkPartition1!=chkPartition2);
+        }
+#endif
         if (vps->getNumBitstreamPartitions(h))
         {
+#if Q0182_MULTI_LAYER_HRD_UPDATE
+          READ_UVLC( uiCode, "num_bsp_sched_combinations_minus1[h]"); vps->setNumBspSchedCombinations(h, uiCode + 1);
+#else
           READ_UVLC( uiCode, "num_bsp_sched_combinations[h]"); vps->setNumBspSchedCombinations(h, uiCode);
+#endif
           for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
           {
@@ -2311,5 +2413,12 @@
             {
               READ_UVLC( uiCode, "bsp_comb_hrd_idx[h][i][j]"); vps->setBspCombHrdIdx(h, i, j, uiCode);
+#if HRD_BPB
+              assert(uiCode <= vps->getVpsNumBspHrdParametersMinus1());
+#endif
+                
               READ_UVLC( uiCode, "bsp_comb_sched_idx[h][i][j]"); vps->setBspCombSchedIdx(h, i, j, uiCode);
+#if HRD_BPB
+              assert(uiCode <= vps->getBspHrdParamBufferCpbCntMinus1(uiCode,vps->getMaxTLayers()-1));
+#endif
             }
           }
@@ -2334,5 +2443,4 @@
 #endif
 }
-#endif
 #endif //SVC_EXTENSION
 
@@ -2412,4 +2520,10 @@
   }
 
+#if Q0142_POC_LSB_NOT_PRESENT
+#if SHM_FIX7
+    Int iPOClsb = 0;
+#endif
+#endif
+
   if(!rpcSlice->getDependentSliceSegmentFlag())
   {
@@ -2484,7 +2598,9 @@
     }
 #if N0065_LAYER_POC_ALIGNMENT
+#if !Q0142_POC_LSB_NOT_PRESENT
 #if SHM_FIX7
     Int iPOClsb = 0;
 #endif
+#endif
 #if O0062_POC_LSB_NOT_PRESENT_FLAG
     if( ( rpcSlice->getLayerId() > 0 && !rpcSlice->getVPS()->getPocLsbNotPresentFlag( rpcSlice->getVPS()->getLayerIdInVps(rpcSlice->getLayerId())) ) || !rpcSlice->getIdrPicFlag())
@@ -2497,4 +2613,7 @@
     {
       READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");
+#if POC_RESET_IDC_DECODER
+      rpcSlice->setPicOrderCntLsb( uiCode );
+#endif
 #if SHM_FIX7
       iPOClsb = uiCode;
@@ -2531,4 +2650,10 @@
 #if SHM_FIX7
       }
+#endif
+#if POC_RESET_IDC_DECODER
+    else
+    {
+      rpcSlice->setPicOrderCntLsb( 0 );
+    }
 #endif
       if( !rpcSlice->getIdrPicFlag() )
@@ -2645,4 +2770,40 @@
         rps->setNumberOfPictures(offset);
       }
+#if DPB_CONSTRAINTS
+          if(rpcSlice->getVPS()->getVpsExtensionFlag()==1)
+          {
+#if Q0078_ADD_LAYER_SETS
+              for (Int ii = 1; ii < (rpcSlice->getVPS()->getVpsNumLayerSetsMinus1() + 1); ii++)  // prevent assert error when num_add_layer_sets > 0
+#else
+              for (Int ii=1; ii< rpcSlice->getVPS()->getNumOutputLayerSets(); ii++ )
+#endif
+              {
+                  Int layerSetIdxForOutputLayerSet = rpcSlice->getVPS()->getOutputLayerSetIdx( ii );
+                  Int chkAssert=0;
+                  for(Int kk = 0; kk < rpcSlice->getVPS()->getNumLayersInIdList(layerSetIdxForOutputLayerSet); kk++)
+                  {
+                      if(rpcSlice->getLayerId()==rpcSlice->getVPS()->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, kk))
+                      {
+                          chkAssert=1;
+                      }
+                  }
+                  if(chkAssert)
+                  {
+                      // There may be something wrong here (layer id assumed to be layer idx?)
+                      assert(rps->getNumberOfNegativePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
+                      assert(rps->getNumberOfPositivePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
+                      assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
+                  }
+              }
+              
+              
+          }
+          if(rpcSlice->getLayerId() == 0)
+          {
+              assert(rps->getNumberOfNegativePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) );
+              assert(rps->getNumberOfPositivePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) -rps->getNumberOfNegativePictures());
+              assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1));
+          }
+#endif
       if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
@@ -2673,13 +2834,5 @@
 #if SVC_EXTENSION
     rpcSlice->setActiveNumILRRefIdx(0);
-#if ILP_SSH_SIG
-#if ILP_SSH_SIG_FIX
     if((rpcSlice->getLayerId() > 0) && !(rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (rpcSlice->getNumILRRefIdx() > 0) )
-#else
-    if((rpcSlice->getLayerId() > 0) && rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() && (rpcSlice->getNumILRRefIdx() > 0) )
-#endif
-#else
-    if((rpcSlice->getLayerId() > 0)  &&  (rpcSlice->getNumILRRefIdx() > 0) )
-#endif
     {
       READ_FLAG(uiCode,"inter_layer_pred_enabled_flag");
@@ -2720,5 +2873,5 @@
 #endif 
           }
-#if ILP_NUM_REF_CHK
+
           if( rpcSlice->getActiveNumILRRefIdx() == rpcSlice->getNumILRRefIdx() )
           {
@@ -2730,13 +2883,10 @@
           else
           {
-#endif
-          for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
-          {
-            READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
-            rpcSlice->setInterLayerPredLayerIdc(uiCode,i);
+            for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
+            {
+              READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
+              rpcSlice->setInterLayerPredLayerIdc(uiCode,i);
+            }
           }
-#if ILP_NUM_REF_CHK
-          }
-#endif
         }
         else
@@ -2760,10 +2910,5 @@
       }
     }
-#if ILP_SSH_SIG
-#if ILP_SSH_SIG_FIX
     else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true &&  (rpcSlice->getLayerId() > 0 ))
-#else
-    else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == false )
-#endif
     {
       rpcSlice->setInterLayerPredEnabledFlag(true);
@@ -2799,6 +2944,4 @@
 #endif 
     }
-#endif
-#endif
 #if P0312_VERT_PHASE_ADJ
     for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ ) 
@@ -2811,4 +2954,5 @@
     }
 #endif
+#endif //SVC_EXTENSION
 
     if(sps->getUseSAO())
@@ -2992,5 +3136,5 @@
 #if SVC_EXTENSION && REF_IDX_MFM
       // set motion mapping flag
-      rpcSlice->setMFMEnabledFlag( ( rpcSlice->getNumMotionPredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() ) ? true : false );
+      rpcSlice->setMFMEnabledFlag( ( rpcSlice->getNumMotionPredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() && !rpcSlice->isIntra() ) ? true : false );
 #endif
       if ( rpcSlice->getSliceType() == B_SLICE )
@@ -3132,15 +3276,15 @@
 
 #if POC_RESET_IDC_SIGNALLING
-  Int sliceHederExtensionLength = 0;
+  Int sliceHeaderExtensionLength = 0;
   if(pps->getSliceHeaderExtensionPresentFlag())
   {
-    READ_UVLC( uiCode, "slice_header_extension_length"); sliceHederExtensionLength = uiCode;
+    READ_UVLC( uiCode, "slice_header_extension_length"); sliceHeaderExtensionLength = uiCode;
   }
   else
   {
-    sliceHederExtensionLength = 0;
+    sliceHeaderExtensionLength = 0;
   }
   UInt startBits = m_pcBitstream->getNumBitsRead();     // Start counter of # SH Extn bits
-  if( sliceHederExtensionLength > 0 )
+  if( sliceHeaderExtensionLength > 0 )
   {
     if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
@@ -3152,4 +3296,10 @@
       rpcSlice->setPocResetIdc( 0 );
     }
+#if Q0142_POC_LSB_NOT_PRESENT
+    if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && iPOClsb > 0 )
+    {
+      assert( rpcSlice->getPocResetIdc() != 2 );
+    }
+#endif
     if( rpcSlice->getPocResetIdc() > 0 )
     {
@@ -3166,4 +3316,10 @@
       READ_FLAG( uiCode,        "full_poc_reset_flag"); rpcSlice->setFullPocResetFlag((uiCode == 1) ? true : false);
       READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode,"poc_lsb_val"); rpcSlice->setPocLsbVal(uiCode);
+#if Q0142_POC_LSB_NOT_PRESENT
+      if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && rpcSlice->getFullPocResetFlag() )
+      {
+        assert( rpcSlice->getPocLsbVal() == 0 );
+      }
+#endif
     }
 
@@ -3179,5 +3335,13 @@
     else
     {
+#if POC_MSB_VAL_PRESENT_FLAG_SEM
+      if( sliceHeaderExtensionLength == 0 )
+      {
+        rpcSlice->setPocMsbValPresentFlag( false );
+      }
+      else if( rpcSlice->getPocMsbValRequiredFlag() )
+#else
       if( rpcSlice->getPocMsbValRequiredFlag() )
+#endif
       {
         rpcSlice->setPocMsbValPresentFlag( true );
@@ -3189,8 +3353,12 @@
     }
 
+#if !POC_RESET_IDC_DECODER
     Int maxPocLsb  = 1 << rpcSlice->getSPS()->getBitsForPOC();
+#endif
     if( rpcSlice->getPocMsbValPresentFlag() )
     {
       READ_UVLC( uiCode,    "poc_msb_val");             rpcSlice->setPocMsbVal( uiCode );
+
+#if !POC_RESET_IDC_DECODER
       // Update POC of the slice based on this MSB val
       Int pocLsb     = rpcSlice->getPOC() % maxPocLsb;
@@ -3200,4 +3368,5 @@
     {
       rpcSlice->setPocMsbVal( rpcSlice->getPOC() / maxPocLsb );
+#endif
     }
 
@@ -3212,5 +3381,9 @@
     while( counter )
     {
+#if Q0146_SSH_EXT_DATA_BIT 
+      READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
+#else
       READ_FLAG( uiCode, "slice_segment_header_extension_reserved_bit" ); assert( uiCode == 1 );
+#endif
       counter--;
     }
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 752)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 815)
@@ -75,14 +75,9 @@
   Void  parseQtRootCbf      ( UInt uiAbsPartIdx, UInt& uiQtRootCbf );
   Void  parseVPS            ( TComVPS* pcVPS );
-#if SPS_EXTENSION
-#if VPS_EXTNS
+#if SVC_EXTENSION
   Void  parseVPSExtension   ( TComVPS* pcVPS );
   Void  defaultVPSExtension ( TComVPS* pcVPS );
-#endif
-
-#if VPS_VUI
-  Void  parseVPSVUI   ( TComVPS* pcVPS );
-  Void  defaultVPSVUI ( TComVPS* pcVPS );
-#endif 
+  Void  parseVPSVUI         ( TComVPS* pcVPS );
+  Void  defaultVPSVUI       ( TComVPS* pcVPS );
 #if REPN_FORMAT_IN_VPS
   Void  parseRepFormat      ( RepFormat *repFormat, RepFormat *repFormatPrev );
Index: trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 752)
+++ trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 815)
@@ -85,4 +85,7 @@
   m_isNoOutputPriorPics = false;
 #endif
+#if Q0177_EOS_CHECKS
+  m_isLastNALWasEos = false;
+#endif
 #if NO_CLRAS_OUTPUT_FLAG
   m_noClrasOutputFlag          = false;
@@ -93,4 +96,9 @@
   m_subDpbIdx = -1;
 #endif
+#if POC_RESET_IDC_DECODER
+  m_parseIdc = -1;
+  m_lastPocPeriodId = -1;
+  m_prevPicOrderCnt = 0;
+#endif
 #if Q0048_CGS_3D_ASYMLUT
   m_pColorMappedPic = NULL;
@@ -104,4 +112,36 @@
 TDecTop::~TDecTop()
 {
+#if Q0078_ADD_LAYER_SETS
+  for (Int psId = 0; psId < MAX_NUM_SPS; psId++)
+  {
+    TComSPS* sps = m_parameterSetManagerDecoder.getSPS(psId);
+    if (sps != NULL)
+    {
+      // Remove parameter set from other layers to prevent multiple deletes of the same object
+      for (Int lId = 0; lId < m_numLayer; lId++)
+      {
+        if (m_ppcTDecTop[lId] != this)
+        {
+          m_parameterSetManagerDecoder.removeSPS(psId);
+        }
+      }
+    }
+  }
+  for (Int psId = 0; psId < MAX_NUM_PPS; psId++)
+  {
+    TComPPS* pps = m_parameterSetManagerDecoder.getPPS(psId);
+    if (pps != NULL)
+    {
+      // Remove parameter set from other layers to prevent multiple deletes of the same object
+      for (Int lId = 0; lId < m_numLayer; lId++)
+      {
+        if (m_ppcTDecTop[lId] != this)
+        {
+          m_parameterSetManagerDecoder.removePPS(psId);
+        }
+      }
+    }
+  }
+#endif
 #if ENC_DEC_TRACE
   fclose( g_hTrace );
@@ -225,31 +265,16 @@
 
         m_cIlpPic[j] = new  TComPic;
+
 #if AUXILIARY_PICTURES
 #if REPN_FORMAT_IN_VPS
-#if SVC_UPSAMPLING
         m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
 #else
-        m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
         m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
-#else
-        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
 #endif
 #else
 #if REPN_FORMAT_IN_VPS
-#if SVC_UPSAMPLING
         m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
 #else
-        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
         m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
-#else
-        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
 #endif
 #endif
@@ -393,51 +418,32 @@
 
           //only for scalable extension
-#if SCALABILITY_MASK_E0104
-          assert( pcSlice->getVPS()->getScalabilityMask(2) == true );
-#else
-          assert( pcSlice->getVPS()->getScalabilityMask(1) == true );
-#endif
-        }
-      }
-    }
-#endif
-    
+          assert( pcSlice->getVPS()->getScalabilityMask( SCALABILITY_ID ) == true );
+        }
+      }
+    }
+
 #if AUXILIARY_PICTURES
 #if REPN_FORMAT_IN_VPS
-#if SVC_UPSAMPLING
     rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                      conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
 #else
-    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
-                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
     rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                      conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
-#else
-    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
-                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
 #endif
 #else
 #if REPN_FORMAT_IN_VPS
-#if SVC_UPSAMPLING
     rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                      conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
 #else
-    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
-                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
     rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                      conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
-#else
+#endif
+#endif
+
+#else //SVC_EXTENSION
     rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                      conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#endif
-#endif
+#endif //SVC_EXTENSION
+    
     m_cListPic.pushBack( rpcPic );
     
@@ -478,45 +484,27 @@
   rpcPic->destroy();
 
+#if SVC_EXTENSION
 #if AUXILIARY_PICTURES
 #if REPN_FORMAT_IN_VPS
-#if SVC_UPSAMPLING
   rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
-
-#else
-  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
-                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
+#else
   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
-
-#else
-  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
-                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
 #endif
 #else
 #if REPN_FORMAT_IN_VPS
-#if SVC_UPSAMPLING
   rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
 
 #else
-  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
-                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
-
-#else
+#endif
+#endif
+#else  //SVC_EXTENSION
   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#endif
-#endif
+#endif //SVC_EXTENSION
 }
 
@@ -793,5 +781,4 @@
 
 #if AUXILIARY_PICTURES
-#if SVC_UPSAMPLING
 #if AVC_SYNTAX
       pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, activeSPS, true);
@@ -800,15 +787,8 @@
 #endif
 #else
-      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
 #if AVC_SYNTAX
       pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, activeSPS, true);
 #else
       pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
-#endif
-#else
-      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
 #endif
 #endif
@@ -846,5 +826,9 @@
 
     // When not present sps_temporal_id_nesting_flag is inferred to be equal to vps_temporal_id_nesting_flag
+#if Q0177_SPS_TEMP_NESTING_FIX
+    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? activeVPS->getTemporalNestingFlag() : true );
+#else
     sps->setTemporalIdNestingFlag( activeVPS->getTemporalNestingFlag() );
+#endif
 
     // When sps_max_dec_pic_buffering_minus1[ i ] is not present for i in the range of 0 to sps_max_sub_layers_minus1, inclusive, due to nuh_layer_id being greater than 0, 
@@ -854,6 +838,9 @@
       // to avoid compiler warning "array subscript is above array bounds"
       assert( i < MAX_TLAYER );
-
+#if LAYER_DECPICBUFF_PARAM && RESOLUTION_BASED_DPB
+      sps->setMaxDecPicBuffering( activeVPS->getMaxVpsLayerDecPicBuffMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), sps->getLayerId(), i) + 1, i);
+#else
       sps->setMaxDecPicBuffering( activeVPS->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), sps->getLayerId(), i) + 1, i);
+#endif
     }
   }
@@ -1122,12 +1109,210 @@
   }
 #endif
+#if POC_RESET_IDC_DECODER
+  if( m_parseIdc != -1 ) // Second pass for a POC resetting picture
+  {
+    m_parseIdc++; // Proceed to POC decoding and RPS derivation
+  }
+  
+  if( m_parseIdc == 2 )
+  {
+    bNewPOC = false;
+  }
+
+  if( (bNewPOC || m_layerId!=m_uiPrevLayerId) && (m_parseIdc == -1) ) // Will be true at the first pass
+  {
+  //if (bNewPOC || m_layerId!=m_uiPrevLayerId)
+  // Check if new reset period has started - this is needed just so that the SHM decoder which calls slice header decoding twice 
+  // does not invoke the output twice
+  //if( m_lastPocPeriodId[m_apcSlicePilot->getLayerId()] == m_apcSlicePilot->getPocResetPeriodId() )
+    // Update CurrAU marking
+    if(( m_layerId < m_uiPrevLayerId) ||( ( m_layerId == m_uiPrevLayerId) && bNewPOC)) // Decoding a lower layer than or same layer as previous - mark all earlier pictures as not in current AU
+    {
+      markAllPicsAsNoCurrAu();
+    }
+
+    if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getSliceIdx() == 0 )
+    {
+      Int pocResetPeriodId = m_apcSlicePilot->getPocResetPeriodId();
+      if ( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 ||
+        ( m_apcSlicePilot->getPocResetIdc() == 3 && pocResetPeriodId != getLastPocPeriodId() ) )
+      {
+        setLastPocPeriodId(pocResetPeriodId);
+        m_parseIdc = 0;
+      }
+    }
+    else
+    {
+      m_parseIdc = 3; // Proceed to decoding POC and RPS
+    }  
+  }
+#endif
 
 #if ALIGNED_BUMPING
+#if POC_RESET_IDC_DECODER
+  //if(  (bNewPOC || m_layerId != m_uiPrevLayerId) && ( m_parseIdc != 1) )
+  if( m_parseIdc == 1 )
+  {
+    // Invoke output of pictures if the current picture is a POC reset picture
+    bNewPOC = true;
+    /* Include reset of all POCs in the layer */
+
+  // This operation would do the following:
+  // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
+  // 2. Update the value of m_pocCRA.
+  // 3. Reset the POC values at the decoder for the current picture to be zero - will be done later
+  // 4. update value of POCLastDisplay
+      
+  //Do the reset stuff here
+    Int maxPocLsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
+    Int pocLsbVal;
+    if( m_apcSlicePilot->getPocResetIdc() == 3 )
+    {
+      pocLsbVal = m_apcSlicePilot->getPocLsbVal() ;
+    }
+    else
+    {
+      pocLsbVal = (m_apcSlicePilot->getPOC() % maxPocLsb);
+    }
+
+    Int pocMsbDelta = 0;
+    if ( m_apcSlicePilot->getPocMsbValPresentFlag() ) 
+    {
+      pocMsbDelta = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
+    }
+    else
+    {
+      //This MSB derivation can be made into one function. Item to do next.
+      Int prevPoc     = this->getPrevPicOrderCnt();
+      Int prevPocLsb  = prevPoc & (maxPocLsb - 1);
+      Int prevPocMsb  = prevPoc - prevPocLsb;
+
+      pocMsbDelta = m_apcSlicePilot->getCurrMsb( pocLsbVal, prevPocLsb, prevPocMsb, maxPocLsb );
+    }
+
+    Int pocLsbDelta;
+    if( m_apcSlicePilot->getPocResetIdc() == 2 ||  ( m_apcSlicePilot->getPocResetIdc() == 3 && m_apcSlicePilot->getFullPocResetFlag() ))
+    {
+      pocLsbDelta = pocLsbVal;
+    }
+    else
+    {
+      pocLsbDelta = 0; 
+    }
+
+    Int deltaPocVal  =  pocMsbDelta + pocLsbDelta;
+
+    //Reset all POC for DPB -> basically do it for each slice in the picutre
+    TComList<TComPic*>::iterator  iterPic = m_cListPic.begin();  
+
+    // Iterate through all picture in DPB
+    while( iterPic != m_cListPic.end() )
+    {
+      TComPic *dpbPic = *iterPic;
+      // Check if the picture pointed to by iterPic is either used for reference or
+      // needed for output, are in the same layer, and not the current picture.
+      if( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
+          &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
+            && ( dpbPic->getReconMark() ) && ( dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag() ))
+      {
+        for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
+        {
+
+          TComSlice *slice = dpbPic->getSlice(i);
+          TComReferencePictureSet *rps = slice->getRPS();
+          slice->setPOC( slice->getPOC() - deltaPocVal );
+
+          // Also adjust the POC value stored in the RPS of each such slice
+          for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
+          {
+            rps->setPOC( j, rps->getPOC(j) - deltaPocVal );
+          }
+          // Also adjust the value of refPOC
+          for(Int k = 0; k < 2; k++)  // For List 0 and List 1
+          {
+            RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
+            for(Int j = 0; j < slice->getNumRefIdx(list); j++)
+            {
+              slice->setRefPOC( slice->getRefPOC(list, j) - deltaPocVal, list, j);
+            }
+          }
+        }
+      }
+      iterPic++;
+    }
+    // Update the value of pocCRA
+    m_pocCRA -= deltaPocVal;
+
+    // Update value of POCLastDisplay
+    iPOCLastDisplay -= deltaPocVal;
+  }
+  Int maxPocLsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
+  Int slicePicOrderCntLsb = m_apcSlicePilot->getPicOrderCntLsb();
+
+  if( m_parseIdc == 1 || m_parseIdc == 2 ) // TODO This should be replaced by pocResettingFlag.
+  {
+    // Set poc for current slice
+    if( m_apcSlicePilot->getPocResetIdc() == 1 )
+    {        
+      m_apcSlicePilot->setPOC( slicePicOrderCntLsb );
+    }
+    else if( m_apcSlicePilot->getPocResetIdc() == 2 )
+    {
+      m_apcSlicePilot->setPOC( 0 );
+    }
+    else 
+    {
+      Int picOrderCntMsb = m_apcSlicePilot->getCurrMsb( slicePicOrderCntLsb, m_apcSlicePilot->getFullPocResetFlag() ? 0 : m_apcSlicePilot->getPocLsbVal(), 0 , maxPocLsb );
+      m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
+    }
+  }
+  else if (m_parseIdc == 3)
+  {
+    Int picOrderCntMsb = 0;
+    if( m_apcSlicePilot->getPocMsbValPresentFlag() )
+    {
+      picOrderCntMsb = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
+    }
+    else if( m_apcSlicePilot->getIdrPicFlag() )
+    {
+      picOrderCntMsb = 0;
+    }
+    else
+    {
+      Int prevPicOrderCntLsb = this->getPrevPicOrderCnt() & ( maxPocLsb - 1);
+      Int prevPicOrderCntMsb  = this->getPrevPicOrderCnt() - prevPicOrderCntLsb;
+      picOrderCntMsb = m_apcSlicePilot->getCurrMsb(slicePicOrderCntLsb, prevPicOrderCntLsb, prevPicOrderCntMsb, maxPocLsb );
+    }
+    m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
+  }
+
+  if( m_parseIdc == 1 || m_parseIdc == 3)
+  {
+    // Adjust prevPicOrderCnt
+    if(    !m_apcSlicePilot->getRaslPicFlag() 
+        && !m_apcSlicePilot->getRadlPicFlag()
+        && (m_apcSlicePilot->getNalUnitType() % 2 == 1)
+        && ( nalu.m_temporalId == 0 )
+        && !m_apcSlicePilot->getDiscardableFlag() )
+    {
+      this->setPrevPicOrderCnt( m_apcSlicePilot->getPOC() );
+    }
+    else if ( m_apcSlicePilot->getPocResetIdc() == 3 )
+    {
+      this->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag() 
+                                            ? 0 : m_apcSlicePilot->getPocLsbVal() );
+    }
+#else
   if (bNewPOC || m_layerId!=m_uiPrevLayerId)
   {
+#endif
     m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
   }
 #endif
+#if POC_RESET_IDC_DECODER
+  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId || m_parseIdc == 1) && !m_bFirstSliceInSequence )
+#else
   if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
+#endif
   {
     m_prevPOC = m_apcSlicePilot->getPOC();
@@ -1136,36 +1321,12 @@
     return true;
   }
-#else
-  //we should only get a different poc for a new picture (with CTU address==0)
-  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
-  {
-    printf ("Warning, the first slice of a picture might have been lost!\n");
-  }
-  // exit when a new picture is found
-  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
-  {
-    if (m_prevPOC >= m_pocRandomAccess)
-    {
-      m_prevPOC = m_apcSlicePilot->getPOC();
-      return true;
-    }
-    m_prevPOC = m_apcSlicePilot->getPOC();
-  }
-#endif
+
+#if POC_RESET_IDC_DECODER
+  m_parseIdc = -1;
+#endif
+
   // actual decoding starts here
-  xActivateParameterSets();
-#if !O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS && N0147_IRAP_ALIGN_FLAG
-  //Note setting O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS to 0 may cause decoder to crash.
-  //When cross_layer_irap_aligned_flag is equal to 0, num_extra_slice_header_bits >=1 
-  if(!m_apcSlicePilot->getVPS()->getCrossLayerIrapAlignFlag() )
-  {
-    assert( m_apcSlicePilot->getPPS()->getNumExtraSliceHeaderBits() > 0);
-  }
-  //When cross_layer_irap_aligned_flag is equal to 1, the value of poc_reset_flag shall be equal to 0  
-  if( m_apcSlicePilot->getVPS()->getCrossLayerIrapAlignFlag() )
-  {
-    assert( m_apcSlicePilot->getPocResetFlag() == 0);
-  }
-#endif 
+    xActivateParameterSets();
+
 #if REPN_FORMAT_IN_VPS
   // Initialize ILRP if needed, only for the current layer  
@@ -1177,8 +1338,6 @@
   {
     m_prevPOC = m_apcSlicePilot->getPOC();
-#if SVC_EXTENSION
     curLayerId = m_layerId;
     m_uiPrevLayerId = m_layerId;
-#endif
   }
   m_bFirstSliceInSequence = false;
@@ -1249,5 +1408,6 @@
   }
 #endif
-#if ALIGN_TSA_STSA_PICS
+  // Alignment of TSA and STSA pictures across AU
+#if !Q0108_TSA_STSA
   if( m_apcSlicePilot->getLayerId() > 0 )
   {
@@ -1287,4 +1447,31 @@
   }
 #endif
+
+#else //SVC_EXTENSION
+  //we should only get a different poc for a new picture (with CTU address==0)
+  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
+  {
+    printf ("Warning, the first slice of a picture might have been lost!\n");
+  }
+  // exit when a new picture is found
+  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
+  {
+    if (m_prevPOC >= m_pocRandomAccess)
+    {
+      m_prevPOC = m_apcSlicePilot->getPOC();
+      return true;
+    }
+    m_prevPOC = m_apcSlicePilot->getPOC();
+  }
+
+  // actual decoding starts here
+  xActivateParameterSets();
+
+  if (m_apcSlicePilot->isNextSlice()) 
+  {
+    m_prevPOC = m_apcSlicePilot->getPOC();
+  }
+  m_bFirstSliceInSequence = false;
+#endif //SVC_EXTENSION
   //detect lost reference picture and insert copy of earlier frame.
   Int lostPoc;
@@ -1301,45 +1488,102 @@
       pBLPic->getSlice(0)->setReferenced(true);
       fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
-      UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth();
-      UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight();
 
       if( pFile->good() )
       {
+        Bool is16bit  = g_bitDepthYLayer[0] > 8 || g_bitDepthCLayer[0] > 8;
+        UInt uiWidth  = pBLPic->getPicYuvRec()->getWidth();
+        UInt uiHeight = pBLPic->getPicYuvRec()->getHeight();
+
+        Int len = uiWidth * (is16bit ? 2 : 1);
+        UChar *buf = new UChar[len];
+
         UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
+        if( is16bit )
+        {
+            uiPos <<= 1;
+        }
 
         pFile->seekg((UInt)uiPos, ios::beg );
 
+        // read Y component
         Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
         UInt uiStride = pBLPic->getPicYuvRec()->getStride();
         for( Int i = 0; i < uiHeight; i++ )
         {
-          for( Int j = 0; j < uiWidth; j++ )
+          pFile->read(reinterpret_cast<Char*>(buf), len);
+
+          if( !is16bit )
           {
-            pPel[j] = pFile->get();
+            for (Int x = 0; x < uiWidth; x++)
+            {
+              pPel[x] = buf[x];
+            }
           }
+          else
+          {
+            for (Int x = 0; x < uiWidth; x++)
+            {
+              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
+            }
+          }
+     
           pPel += uiStride;
         }
 
+        len >>= 1;
+        uiWidth >>= 1;
+        uiHeight >>= 1;
+
+        // read Cb component
         pPel = pBLPic->getPicYuvRec()->getCbAddr();
         uiStride = pBLPic->getPicYuvRec()->getCStride();
-        for( Int i = 0; i < uiHeight/2; i++ )
-        {
-          for( Int j = 0; j < uiWidth/2; j++ )
+        for( Int i = 0; i < uiHeight; i++ )
+        {
+          pFile->read(reinterpret_cast<Char*>(buf), len);
+
+          if( !is16bit )
           {
-            pPel[j] = pFile->get();
+            for( Int x = 0; x < uiWidth; x++ )
+            {
+              pPel[x] = buf[x];
+            }
           }
+          else
+          {
+            for( Int x = 0; x < uiWidth; x++ )
+            {
+              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
+            }
+          }
+     
           pPel += uiStride;
         }
 
+        // read Cr component
         pPel = pBLPic->getPicYuvRec()->getCrAddr();
         uiStride = pBLPic->getPicYuvRec()->getCStride();
-        for( Int i = 0; i < uiHeight/2; i++ )
-        {
-          for( Int j = 0; j < uiWidth/2; j++ )
+        for( Int i = 0; i < uiHeight; i++ )
+        {
+          pFile->read(reinterpret_cast<Char*>(buf), len);
+
+          if( !is16bit )
           {
-            pPel[j] = pFile->get();
+            for( Int x = 0; x < uiWidth; x++ )
+            {
+              pPel[x] = buf[x];
+            }
           }
+          else
+          {
+            for( Int x = 0; x < uiWidth; x++ )
+            {
+              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
+            }
+          }
+     
           pPel += uiStride;
         }
+
+        delete[] buf;
       }
     }
@@ -1365,4 +1609,8 @@
     //  Get a new picture buffer
     xGetNewPicBuffer (m_apcSlicePilot, pcPic);
+
+#if POC_RESET_IDC_DECODER
+  pcPic->setCurrAuFlag( true );
+#endif
 
     Bool isField = false;
@@ -1543,6 +1791,7 @@
       {
         UInt refLayerIdc = i;
+        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc);
 #if AVC_BASE
-        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
+        if( refLayerId == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
         {          
           TComPic* pic = *m_ppcTDecTop[0]->getListPic()->begin();
@@ -1593,5 +1842,5 @@
 
 #if O0098_SCALED_REF_LAYER_ID
-        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
+        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
 #else
         const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
@@ -1627,19 +1876,22 @@
         }
 #endif
-#if SVC_UPSAMPLING
+#if SVC_EXTENSION
         if( pcPic->isSpatialEnhLayer(refLayerIdc) )
-        {    
+        {
+          // check for the sample prediction picture type
+          if( m_ppcTDecTop[m_layerId]->getSamplePredEnabledFlag(refLayerId) )
+          {
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
 #if Q0048_CGS_3D_ASYMLUT 
-          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
-#else
-          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
+            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
+#else
+            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
 #endif
 #else
 #if Q0048_CGS_3D_ASYMLUT 
-          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
-#else
-          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
+            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
+#else
+            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
 #endif
 #endif
@@ -1647,16 +1899,17 @@
 #if O0194_JOINT_US_BITSHIFT
 #if Q0048_CGS_3D_ASYMLUT 
-          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
-#else
-          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
+            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
+#else
+            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
 #endif
 #else
 #if Q0048_CGS_3D_ASYMLUT 
-          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
-#else
-          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
-#endif
-#endif
-#endif
+            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
+#else
+            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
+#endif
+#endif
+#endif
+          }
         }
         else
@@ -1665,5 +1918,5 @@
         }
         pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
-#endif
+#endif //SVC_EXTENSION
       }
     }
@@ -1732,5 +1985,10 @@
     if( pcSlice->getMFMEnabledFlag() )
     {
-      Int refLayerId = pcSlice->getRefPic( pcSlice->getSliceType() == B_SLICE ? ( RefPicList )( 1 - pcSlice->getColFromL0Flag() ) : REF_PIC_LIST_0 , pcSlice->getColRefIdx() )->getLayerId();
+      TComPic* refPic = pcSlice->getRefPic( pcSlice->getSliceType() == B_SLICE ? ( RefPicList )( 1 - pcSlice->getColFromL0Flag() ) : REF_PIC_LIST_0 , pcSlice->getColRefIdx() );
+
+      assert( refPic );
+
+      Int refLayerId = refPic->getLayerId();
+
       if( refLayerId != pcSlice->getLayerId() )
       {
@@ -1742,5 +2000,4 @@
 #endif
     
-#if N0147_IRAP_ALIGN_FLAG
     if( m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag() )
     {
@@ -1758,5 +2015,18 @@
       }
     }
-#endif 
+
+    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
+    {
+      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
+
+      assert( refPic );
+
+      // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture, 
+      // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture.
+      if( refPic->isILR(pcSlice->getLayerId()) )
+      {
+        assert( m_ppcTDecTop[m_layerId]->getMotionPredEnabledFlag(refPic->getLayerId()) );
+      }
+    }
 #endif //SVC_EXTENSION
     
@@ -1856,4 +2126,14 @@
 #endif
   m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
+#if Q0078_ADD_LAYER_SETS
+  // Store SPS for all layers
+  for (Int lId = 0; lId < m_numLayer; lId++)
+  {
+    if (m_ppcTDecTop[lId] != this)
+    {
+      m_ppcTDecTop[lId]->getParameterSetManager()->storePrefetchedSPS(sps);
+    }
+  }
+#endif
 #if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation  
   if(m_numLayer>0)
@@ -1886,4 +2166,14 @@
     );
   m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
+#if Q0078_ADD_LAYER_SETS
+  // Store PPS for all layers
+  for (Int lId = 0; lId < m_numLayer; lId++)
+  {
+    if (m_ppcTDecTop[lId] != this)
+    {
+      m_ppcTDecTop[lId]->getParameterSetManager()->storePrefetchedPPS(pps);
+    }
+  }
+#endif
 
   if( pps->getDependentSliceSegmentsEnabledFlag() )
@@ -1906,10 +2196,8 @@
   if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
   {
-#if RANDOM_ACCESS_SEI_FIX
     if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
     {
       return;
     }
-#endif
 #if LAYERS_NOT_PRESENT_SEI
     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
@@ -1991,8 +2279,11 @@
   {
     case NAL_UNIT_VPS:
-#if VPS_NUH_LAYER_ID
+#if SVC_EXTENSION
       assert( nalu.m_layerId == 0 ); // Non-conforming bitstream. The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
 #endif
       xDecodeVPS();
+#if Q0177_EOS_CHECKS
+      m_isLastNALWasEos = false;
+#endif
 #if AVC_BASE
       if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
@@ -2033,4 +2324,10 @@
     case NAL_UNIT_PREFIX_SEI:
     case NAL_UNIT_SUFFIX_SEI:
+#if Q0177_EOS_CHECKS
+      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
+      {
+        assert( m_isLastNALWasEos == false );
+      }
+#endif
       xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
       return false;
@@ -2052,4 +2349,18 @@
     case NAL_UNIT_CODED_SLICE_RASL_N:
     case NAL_UNIT_CODED_SLICE_RASL_R:
+#if Q0177_EOS_CHECKS
+      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
+          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
+          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
+          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
+          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
+      {
+        assert( m_isLastNALWasEos == false );
+      }
+      else
+      {
+        m_isLastNALWasEos = false;
+      }
+#endif
 #if SVC_EXTENSION
       return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
@@ -2060,4 +2371,14 @@
       
     case NAL_UNIT_EOS:
+#if Q0177_EOS_CHECKS
+      assert( m_isLastNALWasEos == false );
+      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
+      if (nalu.m_layerId > 0)
+      {
+        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
+        return false;
+      }
+      m_isLastNALWasEos = true;
+#endif
       m_associatedIRAPType = NAL_UNIT_INVALID;
       m_pocCRA = 0;
@@ -2085,4 +2406,7 @@
       
     case NAL_UNIT_FILLER_DATA:
+#if Q0177_EOS_CHECKS
+      assert( m_isLastNALWasEos == false );
+#endif
       return false;
       
@@ -2256,6 +2580,7 @@
     }
   }
-  for ( Int i = 1, mIdx = 0, sIdx = 0; i < m_numLayer; i++ )
-  {
+  for( Int i = 1; i < m_numLayer; i++ )
+  {
+    Int mIdx = 0, sIdx = 0;
     Int iNuhLId = vps->getLayerIdInNuh(i);
     TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId);
@@ -2392,5 +2717,20 @@
 }
 #endif
-
+#if POC_RESET_IDC_DECODER
+Void TDecTop::markAllPicsAsNoCurrAu()
+{
+  for(Int i = 0; i < MAX_LAYERS; i++)
+  {
+    TComList<TComPic*>* listPic = this->getLayerDec(i)->getListPic();
+    TComList<TComPic*>::iterator  iterPic = listPic->begin();
+    while ( iterPic != listPic->end() )
+    {
+      TComPic *pcPic = *(iterPic);
+      pcPic->setCurrAuFlag( false );
+      iterPic++;
+    }
+  }
+}
+#endif
 #if Q0048_CGS_3D_ASYMLUT
 Void TDecTop::initAsymLut(TComSlice *pcSlice)
Index: trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 752)
+++ trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 815)
@@ -162,4 +162,7 @@
   Bool                    m_craNoRaslOutputFlag;    //value of variable NoRaslOutputFlag of the last CRA pic
 #endif
+#if Q0177_EOS_CHECKS
+  Bool                    m_isLastNALWasEos;
+#endif
 
 #if SVC_EXTENSION
@@ -201,4 +204,9 @@
   Bool                    m_firstPicInLayerDecodedFlag;
 #endif
+#if POC_RESET_IDC_DECODER
+  Int                     m_parseIdc;
+  Int                     m_lastPocPeriodId;
+  Int                     m_prevPicOrderCnt;
+#endif
 #if RESOLUTION_BASED_DPB
   Int                     m_subDpbIdx;     // Index to the sub-DPB that the layer belongs to.
@@ -241,4 +249,15 @@
 #if EARLY_REF_PIC_MARKING
   Void earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdList);
+#endif
+#if POC_RESET_IDC_DECODER
+  Int getParseIdc() { return m_parseIdc;}
+  Void        setParseIdc(Int x) { m_parseIdc = x;}
+  Void        markAllPicsAsNoCurrAu();
+
+  Int   getLastPocPeriodId() { return m_lastPocPeriodId; }
+  Void  setLastPocPeriodId(Int x)    { m_lastPocPeriodId = x; }
+
+  Int   getPrevPicOrderCnt() { return m_prevPicOrderCnt; }
+  Void  setPrevPicOrderCnt(Int const x) { m_prevPicOrderCnt = x; }
 #endif
   UInt      getLayerId            () { return m_layerId;              }
Index: trunk/source/Lib/TLibEncoder/SEIwrite.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 752)
+++ trunk/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 815)
@@ -87,4 +87,9 @@
     fprintf( g_hTrace, "=========== Tone Mapping Info SEI message ===========\n");
     break;
+#if P0050_KNEE_FUNCTION_SEI
+  case SEI::KNEE_FUNCTION_INFO:
+    fprintf( g_hTrace, "=========== Knee Function Information SEI message ===========\n");
+    break;
+#endif
 #if Q0074_SEI_COLOR_MAPPING
   case SEI::COLOR_MAPPING_INFO:
@@ -123,4 +128,12 @@
   case SEI::BSP_HRD:
     fprintf( g_hTrace, "=========== Bitstream parition HRD parameters SEI message ===========\n");
+    break;
+#endif
+#if Q0078_ADD_LAYER_SETS
+  case SEI::OUTPUT_LAYER_SET_NESTING:
+    fprintf(g_hTrace, "=========== Output layer set nesting SEI message ===========\n");
+    break;
+  case SEI::VPS_REWRITING:
+    fprintf(g_hTrace, "=========== VPS rewriting SEI message ===========\n");
     break;
 #endif
@@ -177,4 +190,9 @@
     xWriteSEIToneMappingInfo(*static_cast<const SEIToneMappingInfo*>(&sei));
     break;
+#if P0050_KNEE_FUNCTION_SEI
+  case SEI::KNEE_FUNCTION_INFO:
+    xWriteSEIKneeFunctionInfo(*static_cast<const SEIKneeFunctionInfo*>(&sei));
+    break;
+#endif
 #if Q0074_SEI_COLOR_MAPPING
   case SEI::COLOR_MAPPING_INFO:
@@ -217,4 +235,22 @@
    case SEI::BSP_HRD:
      xWriteSEIBspHrd(*static_cast<const SEIBspHrd*>(&sei), sps, nestingSei);
+     break;
+#endif
+#if Q0078_ADD_LAYER_SETS
+   case SEI::OUTPUT_LAYER_SET_NESTING:
+     xWriteSEIOutputLayerSetNesting(bs, *static_cast<const SEIOutputLayerSetNesting*>(&sei), vps, sps);
+     break;
+   case SEI::VPS_REWRITING:
+     xWriteSEIVPSRewriting(*static_cast<const SEIVPSRewriting*>(&sei));
+     break;
+#endif
+#if Q0189_TMVP_CONSTRAINTS
+   case SEI::TMVP_CONSTRAINTS:
+     xWriteSEITMVPConstraints(*static_cast<const SEITMVPConstrains*>(&sei));
+     break;
+#endif
+#if Q0247_FRAME_FIELD_INFO
+   case SEI::FRAME_FIELD_INFO:
+     xWriteSEIFrameFieldInfo(*static_cast<const SEIFrameFieldInfo*>(&sei));
      break;
 #endif
@@ -575,5 +611,27 @@
   xWriteByteAlign();
 }
-
+#if P0050_KNEE_FUNCTION_SEI
+Void SEIWriter::xWriteSEIKneeFunctionInfo(const SEIKneeFunctionInfo &sei)
+{
+  WRITE_UVLC( sei.m_kneeId, "knee_function_id" );
+  WRITE_FLAG( sei.m_kneeCancelFlag, "knee_function_cancel_flag" ); 
+  if ( !sei.m_kneeCancelFlag )
+  {
+    WRITE_FLAG( sei.m_kneePersistenceFlag, "knee_function_persistence_flag" );
+    WRITE_FLAG( sei.m_kneeMappingFlag, "mapping_flag" );
+    WRITE_CODE( (UInt)sei.m_kneeInputDrange , 32,  "input_d_range" );
+    WRITE_CODE( (UInt)sei.m_kneeInputDispLuminance, 32,  "input_disp_luminance" );
+    WRITE_CODE( (UInt)sei.m_kneeOutputDrange, 32,  "output_d_range" );
+    WRITE_CODE( (UInt)sei.m_kneeOutputDispLuminance, 32,  "output_disp_luminance" );
+    WRITE_UVLC( sei.m_kneeNumKneePointsMinus1, "num_knee_points_minus1" );
+    for(Int i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ )
+    {
+      WRITE_CODE( (UInt)sei.m_kneeInputKneePoint[i], 10,"input_knee_point" );
+      WRITE_CODE( (UInt)sei.m_kneeOutputKneePoint[i], 10, "output_knee_point" );
+    }
+  }
+  xWriteByteAlign();
+}
+#endif
 #if Q0074_SEI_COLOR_MAPPING
 Void SEIWriter::xWriteSEIColorMappingInfo(const SEIColorMappingInfo& sei)
@@ -815,4 +873,23 @@
 #endif
 
+#if Q0189_TMVP_CONSTRAINTS 
+Void SEIWriter::xWriteSEITMVPConstraints (const SEITMVPConstrains &sei)
+{
+  WRITE_UVLC( sei.prev_pics_not_used_flag ,    "prev_pics_not_used_flag"  );
+  WRITE_UVLC( sei.no_intra_layer_col_pic_flag ,    "no_intra_layer_col_pic_flag"  ); 
+  xWriteByteAlign();
+}
+#endif
+
+#if Q0247_FRAME_FIELD_INFO
+Void SEIWriter::xWriteSEIFrameFieldInfo  (const SEIFrameFieldInfo &sei)
+{
+  WRITE_CODE( sei.m_ffinfo_picStruct , 4,             "ffinfo_pic_struct" );
+  WRITE_CODE( sei.m_ffinfo_sourceScanType, 2,         "ffinfo_source_scan_type" );
+  WRITE_FLAG( sei.m_ffinfo_duplicateFlag ? 1 : 0,     "ffinfo_duplicate_flag" );
+  xWriteByteAlign();
+}
+#endif
+
 #if O0164_MULTI_LAYER_HRD
 Void SEIWriter::xWriteSEIBspNesting(TComBitIf& bs, const SEIBspNesting &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei)
@@ -893,11 +970,26 @@
     for (UInt i = 0; i <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; i++)
     {
+#if HRD_BPB
+      UInt nl=0;
       for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
       {
         if (sei.m_layerIdIncludedFlag[lsIdx][j])
         {
+          nl++;
+        }
+      }
+      for (UInt j = 0; j < nl; j++)
+      {
+#else
+      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
+      {
+        if (sei.m_layerIdIncludedFlag[lsIdx][j])
+        {
+#endif
           WRITE_FLAG( sei.m_seiLayerInBspFlag[lsIdx][i][j], "sei_layer_in_bsp_flag[lsIdx][i][j]" );
         }
-      }
+#if !HRD_BPB
+      }
+#endif
     }
     WRITE_UVLC( sei.m_seiNumBspSchedCombinationsMinus1[lsIdx], "sei_num_bsp_sched_combinations_minus1[i]");
@@ -988,4 +1080,35 @@
 #endif
 
+#if Q0078_ADD_LAYER_SETS
+
+Void SEIWriter::xWriteSEIOutputLayerSetNesting(TComBitIf& bs, const SEIOutputLayerSetNesting &sei, TComVPS *vps, TComSPS *sps)
+{
+  WRITE_FLAG(sei.m_olsFlag, "ols_flag");
+  WRITE_UVLC(sei.m_numOlsIndicesMinus1, "num_ols_indices_minus1");
+
+  for (Int i = 0; i <= sei.m_numOlsIndicesMinus1; i++)
+  {
+    WRITE_UVLC(sei.m_olsIdx[i], "ols_idx[i]");
+  }
+
+  while (m_pcBitIf->getNumberOfWrittenBits() % 8 != 0)
+  {
+    WRITE_FLAG(0, "ols_nesting_zero_bit");
+  }
+
+  // write nested SEI messages
+  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
+  {
+    writeSEImessage(bs, *(*it), vps, sps);
+  }
+}
+
+Void SEIWriter::xWriteSEIVPSRewriting(const SEIVPSRewriting &sei)
+{
+  //sei.nalu->
+}
+
+#endif
+
 #endif //SVC_EXTENSION
 
Index: trunk/source/Lib/TLibEncoder/SEIwrite.h
===================================================================
--- trunk/source/Lib/TLibEncoder/SEIwrite.h	(revision 752)
+++ trunk/source/Lib/TLibEncoder/SEIwrite.h	(revision 815)
@@ -72,4 +72,7 @@
   Void xWriteSEIGradualDecodingRefreshInfo(const SEIGradualDecodingRefreshInfo &sei);
   Void xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei);
+#if P0050_KNEE_FUNCTION_SEI
+  Void xWriteSEIKneeFunctionInfo(const SEIKneeFunctionInfo &sei);
+#endif
 #if Q0074_SEI_COLOR_MAPPING
   Void xWriteSEIColorMappingInfo(const SEIColorMappingInfo& sei);
@@ -92,4 +95,10 @@
   Void xWriteSEISubBitstreamProperty(const SEISubBitstreamProperty &sei);
 #endif
+#if Q0189_TMVP_CONSTRAINTS 
+Void xWriteSEITMVPConstraints (const SEITMVPConstrains &sei);
+#endif
+#if Q0247_FRAME_FIELD_INFO
+  Void xWriteSEIFrameFieldInfo  (const SEIFrameFieldInfo &sei);
+#endif
 #if O0164_MULTI_LAYER_HRD
   Void xWriteSEIBspNesting(TComBitIf& bs, const SEIBspNesting &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei);
@@ -98,4 +107,8 @@
   Void xCodeHrdParameters( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 );
 #endif
+#if Q0078_ADD_LAYER_SETS
+  Void xWriteSEIOutputLayerSetNesting(TComBitIf& bs, const SEIOutputLayerSetNesting &sei, TComVPS *vps, TComSPS *sps);
+  Void xWriteSEIVPSRewriting(const SEIVPSRewriting &sei);
+#endif
 #endif //SVC_EXTENSION
 };
Index: trunk/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp	(revision 752)
+++ trunk/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp	(revision 815)
@@ -276,36 +276,36 @@
   Int nStrideILRY = pRecPic->getStride();
   Int nStrideILRC = pRecPic->getCStride();
-  Int nWidth = m_pDsOrigPic->getWidth();   //should exclude the padding;
-  Int nHeight= m_pDsOrigPic->getHeight();
   xReset3DArray( m_pColorInfo , xGetYSize() , xGetUSize() , xGetVSize() );
   xReset3DArray( m_pColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() );
 
   //alignment padding
-  Pel *pU = pRecPic->getCbAddr();
-  Pel *pV = pRecPic->getCrAddr();
-  pU[(nWidth>>1)] = pU[(nWidth>>1)-1];
-  pV[(nWidth>>1)] = pV[(nWidth>>1)-1];
-  memcpy(pU-nStrideILRC, pU, ((nWidth>>1)+1)*sizeof(Pel));
-  memcpy(pV-nStrideILRC, pV, ((nWidth>>1)+1)*sizeof(Pel));
-  pU += nStrideILRC+ (nWidth>>1);
-  pV += nStrideILRC+ (nWidth>>1);
-
-  for( Int y = 1 ; y < (nHeight>>1) ; y ++ )
-  {
-    *pU = pU[-1];
-    *pV = pV[-1];
-    pU += nStrideILRC;
-    pV += nStrideILRC;
-  }
-  memcpy(pU-(nWidth>>1), pU-(nWidth>>1)-nStrideILRC, ((nWidth>>1)+1)*sizeof(Pel));
-  memcpy(pV-(nWidth>>1), pV-(nWidth>>1)-nStrideILRC, ((nWidth>>1)+1)*sizeof(Pel));
-
-  for( Int i = 0 ; i < nHeight ; i++ )
-  {
-    Int posSrcY = i * nStrideSrcY;
-    Int posIRLY = i * nStrideILRY;
-    Int posSrcUV = ( i >> 1 ) * nStrideSrcC;
-    Int posIRLUV = ( i >> 1 ) * nStrideILRC;
-    for( Int j = 0 ; j < nWidth ; j++ , posSrcY++ , posIRLY++ , posSrcUV += !( j & 0x01 ) , posIRLUV += !( j & 0x01 ) )
+  pRecPic->setBorderExtension( false );
+  pRecPic->extendPicBorder();
+
+  TComSlice * pSlice = pCurPic->getSlice(pCurPic->getCurrSliceIdx());
+  UInt refLayerId = pSlice->getVPS()->getRefLayerId(pSlice->getLayerId(), refLayerIdc);
+  const Window &scalEL = pSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId); 
+  TComPicYuv *pcRecPicBL = pSlice->getBaseColPic(refLayerIdc)->getPicYuvRec();
+  // borders of down-sampled picture
+  Int leftDS =  (scalEL.getWindowLeftOffset()*g_posScalingFactor[refLayerIdc][0]+(1<<15))>>16;
+  Int rightDS = pcRecPicBL->getWidth() - 1 + (((scalEL.getWindowRightOffset())*g_posScalingFactor[refLayerIdc][0]+(1<<15))>>16);
+  Int topDS = (((scalEL.getWindowTopOffset())*g_posScalingFactor[refLayerIdc][1]+(1<<15))>>16);
+  Int bottomDS = pcRecPicBL->getHeight() - 1 + (((scalEL.getWindowBottomOffset())*g_posScalingFactor[refLayerIdc][1]+(1<<15))>>16);
+  // overlapped region
+  Int left = max( 0 , leftDS );
+  Int right = min( pcRecPicBL->getWidth() - 1 , rightDS );
+  Int top = max( 0 , topDS );
+  Int bottom = min( pcRecPicBL->getHeight() - 1 , bottomDS );
+  // since we do data collection only for overlapped region, the border extension is good enough
+
+  for( Int i = top ; i <= bottom ; i++ )
+  {
+    Int iDS = i-topDS;
+    Int jDS = left-leftDS;
+    Int posSrcY = iDS * nStrideSrcY + jDS;
+    Int posIRLY = i * nStrideILRY + left;
+    Int posSrcUV = ( iDS >> 1 ) * nStrideSrcC + (jDS>>1);
+    Int posIRLUV = ( i >> 1 ) * nStrideILRC + (left>>1);
+    for( Int j = left ; j <= right ; j++ , posSrcY++ , posIRLY++ , posSrcUV += !( j & 0x01 ) , posIRLUV += !( j & 0x01 ) )
     {
       Int Y = pSrcY[posSrcY];
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 752)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 815)
@@ -256,6 +256,7 @@
   WRITE_FLAG( pcPPS->getSliceHeaderExtensionPresentFlag() ? 1 : 0, "slice_segment_header_extension_present_flag");
 #if P0166_MODIFIED_PPS_EXTENSION
-  WRITE_FLAG( 1, "pps_extension_flag" );
-  if( 1 ) //pps_extension_flag
+  WRITE_FLAG( pcPPS->getExtensionFlag() ? 1 : 0, "pps_extension_flag" );
+
+  if( pcPPS->getExtensionFlag() )
   {
 #if !POC_RESET_IDC
@@ -638,7 +639,8 @@
   }
 
-#if SPS_EXTENSION
-  WRITE_FLAG( 1, "sps_extension_flag" );
-  if( 1 )   // if( sps_extension_flag )
+#if SVC_EXTENSION
+  WRITE_FLAG( pcSPS->getExtensionFlag() ? 1 : 0, "sps_extension_flag" );
+
+  if( pcSPS->getExtensionFlag() )
   {
 #if O0142_CONDITIONAL_SPS_EXTENSION
@@ -661,5 +663,6 @@
 #endif
 }
-#if SPS_EXTENSION
+
+#if SVC_EXTENSION
 Void TEncCavlc::codeSPSExtension( TComSPS* pcSPS )
 {
@@ -688,5 +691,6 @@
   }
 }
-#endif
+#endif //SVC_EXTENSION
+
 Void TEncCavlc::codeVPS( TComVPS* pcVPS )
 {
@@ -703,5 +707,5 @@
   WRITE_CODE( pcVPS->getVPSId(),                    4,        "vps_video_parameter_set_id" );
   WRITE_CODE( 3,                                    2,        "vps_reserved_three_2bits" );
-#if VPS_RENAME
+#if SVC_EXTENSION
   WRITE_CODE( pcVPS->getMaxLayers() - 1,            6,        "vps_max_layers_minus1" );            
 #else
@@ -734,5 +738,5 @@
   }
 
-#if VPS_RENAME
+#if SVC_EXTENSION
   assert( pcVPS->getNumHrdParameters() <= MAX_VPS_LAYER_SETS_PLUS1 );
   assert( pcVPS->getMaxLayerId() < MAX_VPS_LAYER_ID_PLUS1 );
@@ -741,6 +745,11 @@
 #endif
   WRITE_CODE( pcVPS->getMaxLayerId(), 6,                       "vps_max_layer_id" );
+#if Q0078_ADD_LAYER_SETS
+  WRITE_UVLC(pcVPS->getVpsNumLayerSetsMinus1(),                "vps_num_layer_sets_minus1");
+  for (UInt opsIdx = 1; opsIdx <= pcVPS->getVpsNumLayerSetsMinus1(); opsIdx++)
+#else
   WRITE_UVLC( pcVPS->getNumLayerSets() - 1,                 "vps_num_layer_sets_minus1" );
-  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getNumLayerSets() - 1 ); opsIdx ++ )
+  for (UInt opsIdx = 1; opsIdx <= (pcVPS->getNumLayerSets() - 1); opsIdx++)
+#endif
   {
     // Operation point set
@@ -798,5 +807,5 @@
     }
   }
-#if VPS_EXTNS
+#if SVC_EXTENSION
   // When MaxLayersMinus1 is greater than 0, vps_extension_flag shall be equal to 1.
   if( pcVPS->getMaxLayers() > 1 )
@@ -832,5 +841,4 @@
 
 #if SVC_EXTENSION
-#if VPS_EXTNS
 Void TEncCavlc::codeVPSExtension (TComVPS *vps)
 {
@@ -846,11 +854,6 @@
 #if !P0307_REMOVE_VPS_VUI_OFFSET
 #if O0109_MOVE_VPS_VUI_FLAG
-#if !VPS_VUI
-  WRITE_FLAG( 0,                     "vps_vui_present_flag" );
-  vps->setVpsVuiPresentFlag(false);
-#else
   WRITE_FLAG( 1,                     "vps_vui_present_flag" );
   vps->setVpsVuiPresentFlag(true);
-#endif
   if ( vps->getVpsVuiPresentFlag() ) 
   {
@@ -879,5 +882,5 @@
   }
 
-#if SPL_FLG_CHK
+  // The value of dimBitOffset[ NumScalabilityTypes ] is set equal to 6.
   if(vps->getSplittingFlag())
   {
@@ -889,5 +892,4 @@
     assert(splDimSum<=6);
   }
-#endif
 
   WRITE_FLAG( vps->getNuhLayerIdPresentFlag(),         "vps_nuh_layer_id_present_flag" );
@@ -957,5 +959,4 @@
     }
 #endif
-#if N0120_MAX_TID_REF_PRESENT_FLAG
    WRITE_FLAG( vps->getMaxTidRefPresentFlag(), "max_tid_ref_present_flag");
    if (vps->getMaxTidRefPresentFlag())
@@ -976,23 +977,5 @@
      }
    }
-#else
-  for( i = 0; i < vps->getMaxLayers() - 1; i++)
-  {
-#if O0225_MAX_TID_FOR_REF_LAYERS
-       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
-       {
-         if(vps->getDirectDependencyFlag(j, i))
-         {
-           WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i,j), 3, "max_tid_il_ref_pics_plus1[i][j]" );
-         }
-       }
-#else
-    WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i), 3, "max_tid_il_ref_pics_plus1[i]" );
-#endif 
-  }
-#endif
-#if ILP_SSH_SIG
-    WRITE_FLAG( vps->getIlpSshSignalingEnabledFlag(), "all_ref_layers_active_flag" );
-#endif
+   WRITE_FLAG( vps->getIlpSshSignalingEnabledFlag(), "all_ref_layers_active_flag" );
 #if VPS_EXTN_PROFILE_INFO
   // Profile-tier-level signalling
@@ -1016,4 +999,23 @@
 #endif
 
+#if Q0078_ADD_LAYER_SETS
+  if (vps->getNumIndependentLayers() > 1)
+  {
+    WRITE_UVLC( vps->getNumAddLayerSets(), "num_add_layer_sets" );
+    for (i = 0; i < vps->getNumAddLayerSets(); i++)
+    {
+      for (j = 1; j < vps->getNumIndependentLayers(); j++)
+      {
+        int len = 1;
+        while ((1 << len) < (vps->getNumLayersInTreePartition(j) + 1))
+        {
+          len++;
+        }
+        WRITE_CODE(vps->getHighestLayerIdxPlus1(i, j), len, "highest_layer_idx_plus1[i][j]");
+      }
+    }
+  }
+#endif
+
 #if !VPS_EXTN_UEV_CODING
   Int numOutputLayerSets = vps->getNumOutputLayerSets() ;
@@ -1027,5 +1029,5 @@
   Int numAddOutputLayerSets = numOutputLayerSets - (Int)vps->getNumLayerSets();
 
-  // The value of num_add_output_layer_sets shall be in the range of 0 to 1023, inclusive.
+  // The value of num_add_olss shall be in the range of 0 to 1023, inclusive.
   assert( numAddOutputLayerSets >= 0 && numAddOutputLayerSets < 1024 );
 
@@ -1033,6 +1035,6 @@
   if( vps->getNumLayerSets() > 1 )
   {
-    WRITE_UVLC( numAddOutputLayerSets, "num_add_output_layer_sets" );
-    WRITE_CODE( vps->getDefaultTargetOutputLayerIdc(), 2, "default_target_output_layer_idc" );
+    WRITE_UVLC( numAddOutputLayerSets, "num_add_olss" );
+    WRITE_CODE( vps->getDefaultTargetOutputLayerIdc(), 2, "default_output_layer_idc" );
   }
 #else
@@ -1065,8 +1067,12 @@
         numBits++;
       }
-      WRITE_CODE( vps->getOutputLayerSetIdx(i) - 1, numBits, "output_layer_set_idx_minus1"); 
+      WRITE_CODE( vps->getOutputLayerSetIdx(i) - 1, numBits, "layer_set_idx_for_ols_minus1"); 
 #if P0295_DEFAULT_OUT_LAYER_IDC
     }
+#if Q0078_ADD_LAYER_SETS
+    if ( i > vps->getVpsNumLayerSetsMinus1() || vps->getDefaultTargetOutputLayerIdc() >= 2 ) //Instead of == 2, >= 2 is used to follow the agreement that value 3 should be interpreted as 2
+#else
     if ( i > (vps->getNumLayerSets() - 1) || vps->getDefaultTargetOutputLayerIdc() >= 2 ) //Instead of == 2, >= 2 is used to follow the agreement that value 3 should be interpreted as 2
+#endif
     {
 #endif
@@ -1217,5 +1223,5 @@
   WRITE_FLAG(vps->getPhaseAlignFlag(), "cross_layer_phase_alignment_flag" );
 #endif
-#if N0147_IRAP_ALIGN_FLAG && !IRAP_ALIGN_FLAG_IN_VPS_VUI
+#if !IRAP_ALIGN_FLAG_IN_VPS_VUI
   WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
 #endif 
@@ -1286,7 +1292,4 @@
 
 #if !O0109_MOVE_VPS_VUI_FLAG
-#if !VPS_VUI
-  WRITE_FLAG( 0,                     "vps_vui_present_flag" );
-#else
   WRITE_FLAG( 1,                     "vps_vui_present_flag" );
   if(1)   // Should be conditioned on the value of vps_vui_present_flag
@@ -1303,5 +1306,4 @@
     codeVPSVUI(vps);  
   }
-#endif 
 #else
 #if P0307_REMOVE_VPS_VUI_OFFSET
@@ -1326,5 +1328,5 @@
 #endif // 0109_MOVE_VPS_FLAG
 }
-#endif
+
 #if REPN_FORMAT_IN_VPS
 Void  TEncCavlc::codeRepFormat( RepFormat *repFormat )
@@ -1371,6 +1373,11 @@
 {
 #if DPB_PARAMS_MAXTLAYERS
+#if BITRATE_PICRATE_SIGNALLING
+    Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumLayerSets()];
+    for(Int i = 0; i < vps->getNumLayerSets(); i++)
+#else
     Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumOutputLayerSets()];
     for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
+#endif
     {
         UInt maxSLMinus1 = 0;
@@ -1380,4 +1387,7 @@
         Int optLsIdx = i;
 #endif
+#if BITRATE_PICRATE_SIGNALLING
+        optLsIdx = i;
+#endif
         for(Int k = 0; k < vps->getNumLayersInIdList(optLsIdx); k++ ) {
             Int  lId = vps->getLayerSetLayerIdList(optLsIdx, k);
@@ -1385,6 +1395,10 @@
         }
         MaxSubLayersInLayerSetMinus1[ i ] = maxSLMinus1;
-    }
-#endif
+#if BITRATE_PICRATE_SIGNALLING
+        vps->setMaxSLayersInLayerSetMinus1(i,MaxSubLayersInLayerSetMinus1[ i ]);
+#endif
+    }
+#endif
+    
     
   for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
@@ -1395,5 +1409,9 @@
     WRITE_FLAG( vps->getSubLayerFlagInfoPresentFlag( i ), "sub_layer_flag_info_present_flag[i]");
 #if DPB_PARAMS_MAXTLAYERS
+#if BITRATE_PICRATE_SIGNALLING
+    for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ vps->getOutputLayerSetIdx( i ) ]; j++)
+#else
     for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ i ]; j++)
+#endif
 #else
     for(Int j = 0; j < vps->getMaxTLayers(); j++)
@@ -1407,5 +1425,9 @@
       {
 #if CHANGE_NUMSUBDPB_IDX
+#if RESOLUTION_BASED_DPB
         for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
+#else
+        for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
+#endif
 #else
         for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
@@ -1430,5 +1452,5 @@
 }
 #endif
-#if VPS_VUI
+
 Void TEncCavlc::codeVPSVUI (TComVPS *vps)
 {
@@ -1451,5 +1473,4 @@
   }
 #endif
-#if VPS_VUI_BITRATE_PICRATE
   WRITE_FLAG( vps->getBitRatePresentVpsFlag(),        "bit_rate_present_vps_flag" );
   WRITE_FLAG( vps->getPicRatePresentVpsFlag(),        "pic_rate_present_vps_flag" );
@@ -1457,7 +1478,15 @@
   if( vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag() )
   {
+#if Q0078_ADD_LAYER_SETS
+    for( i = 0; i <= vps->getVpsNumLayerSetsMinus1(); i++ )
+#else
     for( i = 0; i < vps->getNumLayerSets(); i++ )
-    {
+#endif
+    {
+#if BITRATE_PICRATE_SIGNALLING
+      for( j = 0; j <= vps->getMaxSLayersInLayerSetMinus1(i); j++ )
+#else
       for( j = 0; j < vps->getMaxTLayers(); j++ )
+#endif
       {
         if( vps->getBitRatePresentVpsFlag() )
@@ -1482,5 +1511,4 @@
     }
   }
-#endif
 #if VPS_VUI_VIDEO_SIGNAL_MOVE
   WRITE_FLAG( vps->getVideoSigPresentVpsFlag(), "video_signal_info_idx_present_flag" );
@@ -1519,5 +1547,5 @@
     }
 #endif
-#if TILE_BOUNDARY_ALIGNED_FLAG
+
     for(i = 1; i < vps->getMaxLayers(); i++)
     {
@@ -1534,5 +1562,4 @@
       }
     }  
-#endif
 #if VPS_VUI_TILES_NOT_IN_USE__FLAG
   }
@@ -1627,5 +1654,9 @@
         codeHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
       }
+#if Q0078_ADD_LAYER_SETS
+      for( UInt h = 1; h <= vps->getVpsNumLayerSetsMinus1(); h++ )
+#else
       for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
+#endif
       {
         WRITE_UVLC( vps->getNumBitstreamPartitions(h), "num_bitstream_partitions[i]");
@@ -1642,5 +1673,9 @@
         if (vps->getNumBitstreamPartitions(h))
         {
+#if Q0182_MULTI_LAYER_HRD_UPDATE
+          WRITE_UVLC(vps->getNumBspSchedCombinations(h) - 1, "num_bsp_sched_combinations_minus1[h]");
+#else
           WRITE_UVLC( vps->getNumBspSchedCombinations(h), "num_bsp_sched_combinations[h]");
+#endif
           for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
           {
@@ -1673,5 +1708,4 @@
 #endif
 }
-#endif
 #endif //SVC_EXTENSION
 
@@ -1811,5 +1845,17 @@
       }
 #else
+#if POC_RESET_IDC_ENCODER
+      Int picOrderCntLSB;
+      if( pcSlice->getPocResetIdc() == 2 )  // i.e. the LSB is reset
+      {
+        picOrderCntLSB = pcSlice->getPicOrderCntLsb();  // This will be the LSB value w.r.t to the previous POC reset period.
+      }
+      else
+      {
+        picOrderCntLSB = (pcSlice->getPOC() + (1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
+      }
+#else
       Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
+#endif
 #endif
       WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
@@ -1940,13 +1986,5 @@
 
 #if SVC_EXTENSION
-#if ILP_SSH_SIG
-#if ILP_SSH_SIG_FIX
     if((pcSlice->getLayerId() > 0) && !(pcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (pcSlice->getNumILRRefIdx() > 0) )
-#else
-    if((pcSlice->getLayerId() > 0) && pcSlice->getVPS()->getIlpSshSignalingEnabledFlag() && (pcSlice->getNumILRRefIdx() > 0) )
-#endif
-#else
-    if((pcSlice->getLayerId() > 0)  &&  (pcSlice->getNumILRRefIdx() > 0) )
-#endif
     {
       WRITE_FLAG(pcSlice->getInterLayerPredEnabledFlag(),"inter_layer_pred_enabled_flag");
@@ -1964,15 +2002,12 @@
             WRITE_CODE(pcSlice->getActiveNumILRRefIdx() - 1, numBits,"num_inter_layer_ref_pics_minus1");
           }       
-#if ILP_NUM_REF_CHK
+
           if( pcSlice->getNumILRRefIdx() != pcSlice->getActiveNumILRRefIdx() )
           {
-#endif
-          for(Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
-          {
-            WRITE_CODE(pcSlice->getInterLayerPredLayerIdc(i),numBits,"inter_layer_pred_layer_idc[i]");   
+            for(Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
+            {
+              WRITE_CODE(pcSlice->getInterLayerPredLayerIdc(i),numBits,"inter_layer_pred_layer_idc[i]");   
+            }
           }
-#if ILP_NUM_REF_CHK
-          }
-#endif
         }
       }
@@ -2294,4 +2329,5 @@
 {
   Int tmpBitsBeforeWriting = getNumberOfWrittenBits();
+  Int maxPocLsb = 1 << slice->getSPS()->getBitsForPOC();
   if(slice->getPPS()->getSliceHeaderExtensionPresentFlag())
   {
@@ -2336,5 +2372,5 @@
     {
       UInt lengthVal = 1;
-      UInt tempVal = slice->getPocMsbVal() + 1;
+      UInt tempVal = (slice->getPocMsbVal() / maxPocLsb) + 1;
       assert ( tempVal );
       while( 1 != tempVal )
@@ -2373,9 +2409,14 @@
     if( slice->getPocMsbValPresentFlag() )
     {
-      WRITE_UVLC( slice->getPocMsbVal(),                                      "poc_msb_val" );
+      assert( slice->getPocMsbVal() % maxPocLsb == 0 );
+      WRITE_UVLC( slice->getPocMsbVal() / maxPocLsb,                                      "poc_msb_val" );
     }
     for (Int i = 0; i < shExtnAdditionalBits; i++)
     {
+#if Q0146_SSH_EXT_DATA_BIT 
+      WRITE_FLAG( 1, "slice_segment_header_extension_data_bit");
+#else
       WRITE_FLAG( 1, "slice_segment_header_extension_reserved_bit");
+#endif
     }
   }
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 752)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 815)
@@ -159,17 +159,13 @@
   Void codeDFSvlc       ( Int   iCode, const Char *pSymbolName );
 
-#if SPS_EXTENSION
-  Void codeSPSExtension         ( TComSPS* pcSPS );
-#if VPS_EXTNS
-  Void  codeVPSExtension        ( TComVPS* pcVPS );
-#endif
-#if VPS_VUI
-  Void codeVPSVUI               (TComVPS *vps);
-#endif
+#if SVC_EXTENSION
+  Void codeSPSExtension        ( TComSPS* pcSPS );
+  Void codeVPSExtension        ( TComVPS* pcVPS );
+  Void codeVPSVUI              ( TComVPS *vps   );
 #if REPN_FORMAT_IN_VPS
-  Void  codeRepFormat           ( RepFormat *repFormat );
+  Void  codeRepFormat          ( RepFormat *repFormat );
 #endif
 #if VPS_DPB_SIZE_TABLE
-  Void  codeVpsDpbSizeTable      (TComVPS *vps);
+  Void  codeVpsDpbSizeTable    (TComVPS *vps);
 #endif
 #if Q0048_CGS_3D_ASYMLUT
Index: trunk/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 752)
+++ trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 815)
@@ -248,4 +248,18 @@
   Int*      m_codedPivotValue;
   Int*      m_targetPivotValue;
+#if P0050_KNEE_FUNCTION_SEI
+  Bool      m_kneeSEIEnabled;
+  Int       m_kneeSEIId;
+  Bool      m_kneeSEICancelFlag;
+  Bool      m_kneeSEIPersistenceFlag;
+  Bool      m_kneeSEIMappingFlag;
+  Int       m_kneeSEIInputDrange;
+  Int       m_kneeSEIInputDispLuminance;
+  Int       m_kneeSEIOutputDrange;
+  Int       m_kneeSEIOutputDispLuminance;
+  Int       m_kneeSEINumKneePointsMinus1;
+  Int*      m_kneeSEIInputKneePoint;
+  Int*      m_kneeSEIOutputKneePoint;
+#endif
 #if Q0074_SEI_COLOR_MAPPING
   Char*     m_seiColorMappingFile;
@@ -262,4 +276,7 @@
   Int       m_SOPDescriptionSEIEnabled;
   Int       m_scalableNestingSEIEnabled;
+#if Q0189_TMVP_CONSTRAINTS
+  Int       m_TMVPConstraintsSEIEnabled;
+#endif
   //====== Weighted Prediction ========
   Bool      m_useWeightedPred;       //< Use of Weighting Prediction (P_SLICE)
@@ -348,7 +365,5 @@
   Bool      m_motionPredEnabledFlag[MAX_VPS_LAYER_ID_PLUS1];
 #endif
-#if N0120_MAX_TID_REF_CFG
   Int       m_maxTidIlRefPicsPlus1;
-#endif 
 #if AUXILIARY_PICTURES
   ChromaFormat m_chromaFormatIDC;
@@ -670,4 +685,30 @@
   Void  setTMISEIExtendedWhiteLevelLumaCodeValue(Int b)      {  m_extendedWhiteLevelLumaCodeValue =b;  }
   Int   getTMISEIExtendedWhiteLevelLumaCodeValue()           {  return m_extendedWhiteLevelLumaCodeValue;  }
+#if P0050_KNEE_FUNCTION_SEI
+  Void  setKneeSEIEnabled(Int b)                             { m_kneeSEIEnabled = b; }
+  Bool  getKneeSEIEnabled()                                  { return m_kneeSEIEnabled; }
+  Void  setKneeSEIId(Int b)                                  { m_kneeSEIId = b; }
+  Int   getKneeSEIId()                                       { return m_kneeSEIId; }
+  Void  setKneeSEICancelFlag(Bool b)                         { m_kneeSEICancelFlag=b; }
+  Bool  getKneeSEICancelFlag()                               { return m_kneeSEICancelFlag; }
+  Void  setKneeSEIPersistenceFlag(Bool b)                    { m_kneeSEIPersistenceFlag = b; }
+  Bool  getKneeSEIPersistenceFlag()                          { return m_kneeSEIPersistenceFlag; }
+  Void  setKneeSEIMappingFlag(Bool b)                        { m_kneeSEIMappingFlag = b; }
+  Bool  getKneeSEIMappingFlag()                              { return m_kneeSEIMappingFlag; }
+  Void  setKneeSEIInputDrange(Int b)                         { m_kneeSEIInputDrange = b; }
+  Int   getKneeSEIInputDrange()                              { return m_kneeSEIInputDrange; }
+  Void  setKneeSEIInputDispLuminance(Int b)                  { m_kneeSEIInputDispLuminance = b; }
+  Int   getKneeSEIInputDispLuminance()                       { return m_kneeSEIInputDispLuminance; }
+  Void  setKneeSEIOutputDrange(Int b)                        { m_kneeSEIOutputDrange = b; }
+  Int   getKneeSEIOutputDrange()                             { return m_kneeSEIOutputDrange; }
+  Void  setKneeSEIOutputDispLuminance(Int b)                 { m_kneeSEIOutputDispLuminance = b; }
+  Int   getKneeSEIOutputDispLuminance()                      { return m_kneeSEIOutputDispLuminance; }
+  Void  setKneeSEINumKneePointsMinus1(Int b)                 { m_kneeSEINumKneePointsMinus1 = b; }
+  Int   getKneeSEINumKneePointsMinus1()                      { return m_kneeSEINumKneePointsMinus1; }
+  Void  setKneeSEIInputKneePoint(Int *p)                     { m_kneeSEIInputKneePoint = p; }
+  Int*  getKneeSEIInputKneePoint()                           { return m_kneeSEIInputKneePoint; }
+  Void  setKneeSEIOutputKneePoint(Int *p)                    { m_kneeSEIOutputKneePoint = p; }
+  Int*  getKneeSEIOutputKneePoint()                          { return m_kneeSEIOutputKneePoint; }
+#endif
 #if Q0074_SEI_COLOR_MAPPING
   Void  setColorMappingInfoSEIFile( Char* nameFile )         {  m_seiColorMappingFile = nameFile; }
@@ -695,5 +736,11 @@
   Int   getSOPDescriptionSEIEnabled()                     { return m_SOPDescriptionSEIEnabled; }
   Void  setScalableNestingSEIEnabled(Int b)                { m_scalableNestingSEIEnabled = b; }
+#if Q0189_TMVP_CONSTRAINTS
+  void setTMVPConstraintsSEIEnabled(Int b)                { m_TMVPConstraintsSEIEnabled = b; }
+#endif
   Int   getScalableNestingSEIEnabled()                     { return m_scalableNestingSEIEnabled; }
+#if Q0189_TMVP_CONSTRAINTS
+  Int   getTMVPConstraintsSEIEnabled()                {  return m_TMVPConstraintsSEIEnabled; }
+#endif
   Void      setUseWP               ( Bool b )    { m_useWeightedPred   = b;    }
   Void      setWPBiPred            ( Bool b )    { m_useWeightedBiPred = b;    }
@@ -877,8 +924,6 @@
   Void      setMotionPredEnabledFlag        (Int i,Bool flag)               { m_motionPredEnabledFlag[i] = flag;  }
 #endif
-#if N0120_MAX_TID_REF_CFG
   Int       getMaxTidIlRefPicsPlus1         ()                              { return m_maxTidIlRefPicsPlus1; }
   Void      setMaxTidIlRefPicsPlus1         (Int num)                       { m_maxTidIlRefPicsPlus1 = num;  }
-#endif 
 #if LAYERS_NOT_PRESENT_SEI
   Void  setLayersNotPresentSEIEnabled(Int b)             { m_layersNotPresentSEIEnabled = b; }
Index: trunk/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 752)
+++ trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 815)
@@ -696,4 +696,5 @@
 #if (ENCODER_FAST_MODE)
         if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || 
+          rpcBestCU->getPredictionMode(0) == MODE_NONE ||  // if there is no valid inter prediction
           !testInter ||
           rpcBestCU->getCbf( 0, TEXT_LUMA     ) != 0   ||
@@ -701,21 +702,21 @@
           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
+        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 );
+          rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
+          if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
           {
-            xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
-          rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
-            if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
+            if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) )
             {
-              if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) )
-              {
-                xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN   );
+              xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN   );
               rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
-              }
             }
           }
+        }
 
         // test PCM
@@ -734,15 +735,15 @@
 #if (ENCODER_FAST_MODE)
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-      if(pcPic->getLayerId() > 0 && !m_disableILP)
-#else
-      if(pcPic->getLayerId() > 0)
-#endif
-      {
-        for(Int refLayer = 0; refLayer < pcSlice->getActiveNumILRRefIdx(); refLayer++)
-        {  
-           xCheckRDCostILRUni( rpcBestCU, rpcTempCU, pcSlice->getInterLayerPredLayerIdc(refLayer));
-           rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
+        if(pcPic->getLayerId() > 0 && !m_disableILP)
+#else
+        if(pcPic->getLayerId() > 0)
+#endif
+        {
+          for(Int refLayer = 0; refLayer < pcSlice->getActiveNumILRRefIdx(); refLayer++)
+          {  
+            xCheckRDCostILRUni( rpcBestCU, rpcTempCU, pcSlice->getVPS()->getRefLayerId( pcSlice->getLayerId(), pcSlice->getInterLayerPredLayerIdc(refLayer) ) );
+            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
+          }
         }
-      }
 #endif
 
@@ -821,7 +822,7 @@
 
   if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
-    {
+  {
     iMaxQP = iMinQP; // If all blocks are forced into using transquant bypass, do not loop here.
-    }
+  }
 
   for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
@@ -1476,4 +1477,17 @@
   rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
   
+#if SVC_EXTENSION
+#if AMP_MRG
+  rpcTempCU->setMergeAMP (true);
+  Bool ret = m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], false, bUseMRG );
+#else  
+  Bool ret = m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] );
+#endif
+
+  if( !ret )
+  {
+    return;
+  }
+#else
 #if AMP_MRG
   rpcTempCU->setMergeAMP (true);
@@ -1481,4 +1495,5 @@
 #else  
   m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] );
+#endif
 #endif
 
Index: trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 752)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 815)
@@ -92,4 +92,8 @@
   m_bRefreshPending     = 0;
   m_pocCRA            = 0;
+#if POC_RESET_IDC_ENCODER
+  m_pocCraWithoutReset = 0;
+  m_associatedIrapPocBeforeReset = 0;
+#endif
   m_numLongTermRefPicSPS = 0;
   ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
@@ -103,11 +107,14 @@
   m_associatedIRAPPOC  = 0;
 #endif
-#if SVC_UPSAMPLING
+#if SVC_EXTENSION
   m_pcPredSearch        = NULL;
-#endif
 #if Q0048_CGS_3D_ASYMLUT
   m_temp = NULL;
   m_pColorMappedPic = NULL;
 #endif
+#if POC_RESET_IDC_ENCODER
+  m_lastPocPeriodId = -1;
+#endif
+#endif //SVC_EXTENSION
   return;
 }
@@ -173,8 +180,5 @@
 #if SVC_EXTENSION
   m_ppcTEncTop           = pcTEncTop->getLayerEnc();
-#endif
-#if SVC_UPSAMPLING
   m_pcPredSearch         = pcTEncTop->getPredSearch();                       ///< encoder search class
-#endif
 #if Q0048_CGS_3D_ASYMLUT
   if( pcTEncTop->getLayerId() )
@@ -185,8 +189,9 @@
     {
       m_pColorMappedPic = new TComPicYuv;
-      m_pColorMappedPic->create( m_ppcTEncTop[0]->getSourceWidth(), m_ppcTEncTop[0]->getSourceHeight(), CHROMA_420, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
-    }
-  }
-#endif
+      m_pColorMappedPic->create( m_ppcTEncTop[0]->getSourceWidth(), m_ppcTEncTop[0]->getSourceHeight(), m_ppcTEncTop[0]->getChromaFormatIDC(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
+    }
+  }
+#endif
+#endif //SVC_EXTENSION
 }
 
@@ -327,4 +332,37 @@
 }
 
+#if P0050_KNEE_FUNCTION_SEI
+SEIKneeFunctionInfo* TEncGOP::xCreateSEIKneeFunctionInfo()
+{
+  SEIKneeFunctionInfo *seiKneeFunctionInfo = new SEIKneeFunctionInfo();
+  seiKneeFunctionInfo->m_kneeId = m_pcCfg->getKneeSEIId();
+  seiKneeFunctionInfo->m_kneeCancelFlag = m_pcCfg->getKneeSEICancelFlag();
+  if ( !seiKneeFunctionInfo->m_kneeCancelFlag )
+  {
+    seiKneeFunctionInfo->m_kneePersistenceFlag = m_pcCfg->getKneeSEIPersistenceFlag();
+    seiKneeFunctionInfo->m_kneeMappingFlag = m_pcCfg->getKneeSEIMappingFlag();
+    seiKneeFunctionInfo->m_kneeInputDrange = m_pcCfg->getKneeSEIInputDrange();
+    seiKneeFunctionInfo->m_kneeInputDispLuminance = m_pcCfg->getKneeSEIInputDispLuminance();
+    seiKneeFunctionInfo->m_kneeOutputDrange = m_pcCfg->getKneeSEIOutputDrange();
+    seiKneeFunctionInfo->m_kneeOutputDispLuminance = m_pcCfg->getKneeSEIOutputDispLuminance();
+
+    seiKneeFunctionInfo->m_kneeNumKneePointsMinus1 = m_pcCfg->getKneeSEINumKneePointsMinus1();
+    Int* piInputKneePoint  = m_pcCfg->getKneeSEIInputKneePoint();
+    Int* piOutputKneePoint = m_pcCfg->getKneeSEIOutputKneePoint();
+    if(piInputKneePoint&&piOutputKneePoint)
+    {
+      seiKneeFunctionInfo->m_kneeInputKneePoint.resize(seiKneeFunctionInfo->m_kneeNumKneePointsMinus1+1);
+      seiKneeFunctionInfo->m_kneeOutputKneePoint.resize(seiKneeFunctionInfo->m_kneeNumKneePointsMinus1+1);
+      for(Int i=0; i<=seiKneeFunctionInfo->m_kneeNumKneePointsMinus1; i++)
+      {
+        seiKneeFunctionInfo->m_kneeInputKneePoint[i] = piInputKneePoint[i];
+        seiKneeFunctionInfo->m_kneeOutputKneePoint[i] = piOutputKneePoint[i];
+       }
+    }
+  }
+  return seiKneeFunctionInfo;
+}
+#endif
+
 #if Q0074_SEI_COLOR_MAPPING
 SEIColorMappingInfo*  TEncGOP::xCreateSEIColorMappingInfo( Char* file )
@@ -477,4 +515,21 @@
     delete sei;
   }
+#if P0050_KNEE_FUNCTION_SEI
+  if(m_pcCfg->getKneeSEIEnabled())
+  {
+    SEIKneeFunctionInfo *sei = xCreateSEIKneeFunctionInfo();
+
+    nalu = NALUnit(NAL_UNIT_PREFIX_SEI);
+    m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+#if O0164_MULTI_LAYER_HRD
+    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, m_pcEncTop->getVPS(), sps);
+#else
+    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps);
+#endif
+    writeRBSPTrailingBits(nalu.m_Bitstream);
+    accessUnit.push_back(new NALUnitEBSP(nalu));
+    delete sei;
+  }
+#endif
 #if Q0074_SEI_COLOR_MAPPING
   if(m_pcCfg->getColorMappingInfoSEIFile())
@@ -554,4 +609,7 @@
   TEncSbac* pcSbacCoders = NULL;
   TComOutputBitstream* pcSubstreamsOut = NULL;
+#if Q0108_TSA_STSA
+  Int flagTSTA = 0;
+#endif
 
   xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut, isField );
@@ -855,4 +913,34 @@
     }
 #endif
+#if POC_RESET_IDC_ENCODER
+    pcSlice->setPocValueBeforeReset( pocCurr );
+    // Check if the current picture is to be assigned as a reset picture
+    determinePocResetIdc(pocCurr, pcSlice);
+
+    // If reset, do the following steps:
+    if( pcSlice->getPocResetIdc() )
+    {
+      updatePocValuesOfPics(pocCurr, pcSlice);
+    }
+    else
+    {
+      // Check the base layer picture is IDR. If so, just set current POC equal to 0 (alignment of POC)
+      if( ( m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() == 2) && ( pocCurr % m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshInterval() == 0 ) )        
+      {
+        m_pcEncTop->setPocAdjustmentValue( pocCurr );
+      }
+      // else
+      {
+        // Just subtract POC by the current cumulative POC delta
+        pcSlice->setPOC( pocCurr - m_pcEncTop->getPocAdjustmentValue() );
+      }
+
+      Int maxPocLsb = 1 << pcSlice->getSPS()->getBitsForPOC();
+      pcSlice->setPocMsbVal( pcSlice->getPOC() - ( pcSlice->getPOC() & (maxPocLsb-1) ) );
+    }
+    // Update the POC of current picture, pictures in the DPB, including references inside the reference pictures
+
+#endif
+
 #if O0149_CROSS_LAYER_BLA_FLAG
     if( m_layerId == 0 && (getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_N_LP) )
@@ -1012,10 +1100,11 @@
     if (m_layerId > 0)
     {
-    Int interLayerPredLayerIdcTmp[MAX_VPS_LAYER_ID_PLUS1];
-    Int activeNumILRRefIdxTmp = 0;
+      Int interLayerPredLayerIdcTmp[MAX_VPS_LAYER_ID_PLUS1];
+      Int activeNumILRRefIdxTmp = 0;
 
       for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
       {
         UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
+        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc);
 #if VPS_EXTN_DIRECT_REF_LAYERS
         TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(refLayerIdc)->getListPic();
@@ -1041,5 +1130,5 @@
 
 #if O0098_SCALED_REF_LAYER_ID
-        const Window &scalEL = m_pcEncTop->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
+        const Window &scalEL = m_pcEncTop->getScaledRefLayerWindowForLayer(refLayerId);
 #else
         const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow(refLayerIdc);
@@ -1088,26 +1177,29 @@
         }
 #endif
-#if SVC_UPSAMPLING
-        if( pcPic->isSpatialEnhLayer(refLayerIdc))
-        {
+#if SVC_EXTENSION
+        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
+        {
+          // check for the sample prediction picture type
+          if( m_ppcTEncTop[m_layerId]->getSamplePredEnabledFlag(refLayerId) )
+          {
 #if P0312_VERT_PHASE_ADJ
-          //when PhasePositionEnableFlag is equal to 1, set vertPhasePositionFlag to 0 if BL is top field and 1 if bottom
-          if( scalEL.getVertPhasePositionEnableFlag() )
-          {
-            pcSlice->setVertPhasePositionFlag( pcSlice->getPOC()%2, refLayerIdc );
-          }
+            //when PhasePositionEnableFlag is equal to 1, set vertPhasePositionFlag to 0 if BL is top field and 1 if bottom
+            if( scalEL.getVertPhasePositionEnableFlag() )
+            {
+              pcSlice->setVertPhasePositionFlag( pcSlice->getPOC()%2, refLayerIdc );
+            }
 #endif
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
 #if Q0048_CGS_3D_ASYMLUT 
-          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
-#else
-          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
+            m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
+#else
+            m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
 #endif
 #else
 #if Q0048_CGS_3D_ASYMLUT
-          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
-#else
-          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
+            m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
+#else
+            m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
 #endif
 #endif
@@ -1115,16 +1207,17 @@
 #if O0194_JOINT_US_BITSHIFT
 #if Q0048_CGS_3D_ASYMLUT 
-          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
-#else
-          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
+            m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
+#else
+            m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
 #endif
 #else
 #if Q0048_CGS_3D_ASYMLUT 
-          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
-#else
-          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
-#endif
-#endif
-#endif
+            m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
+#else
+            m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
+#endif
+#endif
+#endif
+          }
         }
         else
@@ -1137,5 +1230,5 @@
         }
         pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
-#endif
+#endif //SVC_EXTENSION
       }
 
@@ -1154,8 +1247,7 @@
         pcSlice->setInterLayerPredEnabledFlag(false);
       }
-      
+
       if( pocCurr % m_pcCfg->getIntraPeriod() == 0 )
       {
-#if N0147_IRAP_ALIGN_FLAG
         if(pcSlice->getVPS()->getCrossLayerIrapAlignFlag())
         {
@@ -1172,21 +1264,11 @@
         }
         else
-#endif 
-        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
-
-#if IDR_ALIGNMENT
-        TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic();
-        TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
-        if( picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
-        {
-          pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType());
-        }
-        else
-        {
+        {
+#if !ALIGN_IRAP_BUGFIX
           pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
-        }
-#endif 
-      }
-      
+#endif
+        }
+      }
+
       if( pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
       {
@@ -1196,10 +1278,10 @@
       {
         if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
-           (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) &&
-           pcSlice->getSliceType() == B_SLICE )
+          (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) &&
+          pcSlice->getSliceType() == B_SLICE )
         {
           pcSlice->setSliceType(P_SLICE);
         }
-      }
+      }      
     }
 #endif //#if SVC_EXTENSION
@@ -1207,5 +1289,9 @@
     {
       if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_R &&
+#if SVC_EXTENSION
+        ( m_iGopSize != 1 || m_ppcTEncTop[m_layerId]->getIntraPeriod() > 1 ) )
+#else
           !(m_iGopSize == 1 && pcSlice->getSliceType() == I_SLICE))
+#endif
         // Add this condition to avoid POC issues with encoder_intra_main.cfg configuration (see #1127 in bug tracker)
       {
@@ -1232,8 +1318,16 @@
     {
       m_associatedIRAPType = pcSlice->getNalUnitType();
+#if POC_RESET_IDC_ENCODER
+      m_associatedIRAPPOC = pcSlice->getPOC();
+      m_associatedIrapPocBeforeReset = pocCurr;
+#else
       m_associatedIRAPPOC = pocCurr;
+#endif
     }
     pcSlice->setAssociatedIRAPType(m_associatedIRAPType);
     pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC);
+#if POC_RESET_IDC_ENCODER
+    pcSlice->setAssociatedIrapPocBeforeReset(m_associatedIrapPocBeforeReset);
+#endif
 #endif
 #endif
@@ -1243,4 +1337,8 @@
 #else
     pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic);
+#endif
+#if POC_RESET_IDC_ENCODER
+    // m_pocCRA may have been update here; update m_pocCraWithoutReset
+    m_pocCraWithoutReset = m_pocCRA + m_pcEncTop->getPocAdjustmentValue();
 #endif
     m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid);
@@ -1280,5 +1378,9 @@
 #endif
 #if ALIGNED_BUMPING
+#if POC_RESET_IDC_ENCODER
+    pcSlice->checkLeadingPictureRestrictions(rcListPic, true);
+#else
     pcSlice->checkLeadingPictureRestrictions(rcListPic);
+#endif
 #endif
     pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS());
@@ -1293,5 +1395,5 @@
       if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic) || pcSlice->getSPS()->getTemporalIdNestingFlag())
       {
-#if ALIGN_TSA_STSA_PICS
+#if !Q0108_TSA_STSA
         if( pcSlice->getLayerId() > 0 )
         {
@@ -1392,5 +1494,5 @@
         if(isSTSA==true)
         {    
-#if ALIGN_TSA_STSA_PICS
+#if !Q0108_TSA_STSA
           if( pcSlice->getLayerId() > 0 )
           {
@@ -1461,4 +1563,120 @@
       }
     }
+#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     
+          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R
+          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N
+          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R 
+          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
+          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
+          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
+          )
+        )
+    {
+        Bool isSTSA=true;
+        for(Int ii=iGOPid+1; ii < m_pcCfg->getGOPSize() && isSTSA; ii++)
+        {
+          Int lTid= m_pcCfg->getGOPEntry(ii).m_temporalId;
+          if(lTid==pcSlice->getTLayer()) 
+          {
+            TComReferencePictureSet* nRPS = pcSlice->getSPS()->getRPSList()->getReferencePictureSet(ii);
+            for(Int jj=0; jj<nRPS->getNumberOfPictures(); jj++)
+            {
+              if(nRPS->getUsed(jj)) 
+              {
+                Int tPoc=m_pcCfg->getGOPEntry(ii).m_POC+nRPS->getDeltaPOC(jj);
+                Int kk=0;
+                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;
+                  break;
+                }
+              }
+            }
+          }
+        }
+        if(isSTSA==true)
+        {    
+#if !Q0108_TSA_STSA
+          if( pcSlice->getLayerId() > 0 )
+          {
+            Bool oneRefLayerSTSA = false, oneRefLayerNotSTSA = false;
+            for( Int i = 0; i < pcSlice->getLayerId(); i++)
+            {
+              TComList<TComPic *> *cListPic = m_ppcTEncTop[i]->getListPic();
+              TComPic *lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC());
+              if( lowerLayerPic && pcSlice->getVPS()->getDirectDependencyFlag(pcSlice->getLayerId(), i) )
+              {
+                if( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ) ||
+                    ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R ) 
+                  )
+                {
+                  if(pcSlice->getTemporalLayerNonReferenceFlag() )
+                  {
+                    pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N);
+                  }
+                  else
+                  {
+                    pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R );
+                  }
+                  oneRefLayerSTSA = true;
+                }
+                else
+                {
+                  oneRefLayerNotSTSA = true;
+                }
+              }
+            }
+            assert( !( oneRefLayerNotSTSA && oneRefLayerSTSA ) ); // Only one variable should be true - failure of this assert means
+                                                                  // that two independent reference layers that are not dependent on
+                                                                  // each other, but are reference for current layer have inconsistency
+            if( oneRefLayerNotSTSA /*&& !oneRefLayerSTSA*/ )          // No reference layer is STSA - set current as TRAIL
+            {
+              if(pcSlice->getTemporalLayerNonReferenceFlag() )
+              {
+                pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_N );
+              }
+              else
+              {
+                pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_R );
+              }
+            }
+            else  // This means there is no reference layer picture for current picture in this AU
+            {
+              if(pcSlice->getTemporalLayerNonReferenceFlag() )
+              {
+                pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N);
+              }
+              else
+              {
+                pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R );
+              }
+            }
+          }
+#else
+          if(pcSlice->getTemporalLayerNonReferenceFlag())
+          {
+            pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N);
+            flagTSTA = 1;
+          }
+          else
+          {
+            pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R);
+            flagTSTA = 1;
+          }
+#endif
+        }
+    }
+#endif
+
     arrangeLongtermPicturesInRPS(pcSlice, rcListPic);
     TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
@@ -1471,6 +1689,6 @@
     if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
     {
-#if POC_RESET_FLAG
-      if ( pocCurr > 0          && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
+#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())
 #else
       if (pcSlice->getPOC()>0  && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
@@ -1480,5 +1698,9 @@
         pcSlice->setInterLayerPredEnabledFlag(0);
       }
-      if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
+#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 )
+#endif
       {
         pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getActiveNumILRRefIdx());
@@ -1489,4 +1711,26 @@
         pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumRefIdx(REF_PIC_LIST_0)+pcSlice->getActiveNumILRRefIdx());
         pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumRefIdx(REF_PIC_LIST_1)+pcSlice->getActiveNumILRRefIdx());
+      }
+
+      // check for the reference pictures whether there is at least one either temporal picture or ILRP with sample prediction type
+      if( pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) - pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNumRefIdx( REF_PIC_LIST_1 ) - pcSlice->getActiveNumILRRefIdx() == 0 )
+      {
+        Bool foundSamplePredPicture = false;                
+
+        for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
+        {
+          if( m_ppcTEncTop[m_layerId]->getSamplePredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, pcSlice->getInterLayerPredLayerIdc(i) ) ) )
+          {
+            foundSamplePredPicture = true;
+            break;
+          }
+        }
+
+        if( !foundSamplePredPicture )
+        {
+          pcSlice->setSliceType(I_SLICE);
+          pcSlice->setInterLayerPredEnabledFlag(0);
+          pcSlice->setActiveNumILRRefIdx(0);
+        }
       }
     }
@@ -1520,5 +1764,5 @@
       //  Set reference list
       pcSlice->setRefPicList ( rcListPic );
-#endif //SVC_EXTENSION
+#endif
       pcSlice->setRefPicListModificationSvc();
       pcSlice->setRefPicList( rcListPic, false, m_pcEncTop->getIlpList());
@@ -1532,8 +1776,13 @@
 
         for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) 
-        { 
-          if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) 
+        {
+          RefPicList refList = RefPicList(1 - ColFromL0Flag);
+          TComPic* refPic = pcSlice->getRefPic(refList, colIdx);
+
+          // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture, 
+          // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture.
+          if( refPic->isILR(m_layerId) && m_ppcTEncTop[m_layerId]->getMotionPredEnabledFlag( refPic->getLayerId() )
 #if MFM_ENCCONSTRAINT
-            && pcSlice->getBaseColPic( *m_ppcTEncTop[pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->getLayerId()]->getListPic() )->checkSameRefInfo() == true 
+            && pcSlice->getBaseColPic( *m_ppcTEncTop[refPic->getLayerId()]->getListPic() )->checkSameRefInfo() == true 
 #endif
             ) 
@@ -1549,8 +1798,13 @@
           ColFromL0Flag = 1 - ColFromL0Flag;
           for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) 
-          { 
-            if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) 
+          {
+            RefPicList refList = RefPicList(1 - ColFromL0Flag);
+            TComPic* refPic = pcSlice->getRefPic(refList, colIdx);
+
+            // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture, 
+            // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture.
+            if( refPic->isILR(m_layerId) && m_ppcTEncTop[m_layerId]->getMotionPredEnabledFlag( refPic->getLayerId() )
 #if MFM_ENCCONSTRAINT
-              && pcSlice->getBaseColPic( *m_ppcTEncTop[pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->getLayerId()]->getListPic() )->checkSameRefInfo() == true 
+              && pcSlice->getBaseColPic( *m_ppcTEncTop[refPic->getLayerId()]->getListPic() )->checkSameRefInfo() == true 
 #endif
               ) 
@@ -1650,4 +1904,83 @@
       pcSlice->setEnableTMVPFlag(0);
     }
+
+#if SVC_EXTENSION
+    if( m_layerId > 0 && !pcSlice->isIntra() )
+    {
+      Int colFromL0Flag = 1;
+      Int colRefIdx = 0;
+
+      // check whether collocated picture is valid
+      if( pcSlice->getEnableTMVPFlag() )
+      {
+        colFromL0Flag = pcSlice->getColFromL0Flag();
+        colRefIdx = pcSlice->getColRefIdx();
+
+        TComPic* refPic = pcSlice->getRefPic(RefPicList(1-colFromL0Flag), colRefIdx);
+
+        assert( refPic );
+
+        // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture, 
+        // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture.
+        if( refPic->isILR(m_layerId) && !m_ppcTEncTop[m_layerId]->getMotionPredEnabledFlag(refPic->getLayerId()) )
+        {
+          pcSlice->setEnableTMVPFlag(false);
+          pcSlice->setMFMEnabledFlag(false);
+          colRefIdx = 0;
+        }
+      }
+
+      // remove motion only ILRP from the end of the colFromL0Flag reference picture list
+      RefPicList refList = RefPicList(colFromL0Flag);
+      Int numRefIdx = pcSlice->getNumRefIdx(refList);
+
+      if( numRefIdx > 0 )
+      {
+        for( Int refIdx = pcSlice->getNumRefIdx(refList) - 1; refIdx > 0; refIdx-- )
+        {
+          TComPic* refPic = pcSlice->getRefPic(refList, refIdx);
+
+          if( !refPic->isILR(m_layerId) || ( refPic->isILR(m_layerId) && m_ppcTEncTop[m_layerId]->getSamplePredEnabledFlag( refPic->getLayerId() ) ) )
+          {
+            break;
+          }
+          else
+          {
+            assert( numRefIdx > 1 );
+            numRefIdx--;              
+          }
+        }
+
+        pcSlice->setNumRefIdx( refList, numRefIdx );
+      }
+
+      // remove motion only ILRP from the end of the (1-colFromL0Flag) reference picture list up to colRefIdx
+      refList = RefPicList(1 - colFromL0Flag);
+      numRefIdx = pcSlice->getNumRefIdx(refList);
+
+      if( numRefIdx > 0 )
+      {
+        for( Int refIdx = pcSlice->getNumRefIdx(refList) - 1; refIdx > colRefIdx; refIdx-- )
+        {
+          TComPic* refPic = pcSlice->getRefPic(refList, refIdx);
+
+          if( !refPic->isILR(m_layerId) || ( refPic->isILR(m_layerId) && m_ppcTEncTop[m_layerId]->getSamplePredEnabledFlag( refPic->getLayerId() ) ) )
+          {
+            break;
+          }
+          else
+          {
+            assert( numRefIdx > 1 );
+            numRefIdx--;              
+          }
+        }
+
+        pcSlice->setNumRefIdx( refList, numRefIdx );
+      }
+
+      assert( pcSlice->getNumRefIdx(REF_PIC_LIST_0) > 0 && ( pcSlice->isInterP() || (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) > 0) ) );
+    }
+#endif
+
     /////////////////////////////////////////////////////////////////////////////////////////////////// Compress a slice
     //  Slice compression
@@ -1700,5 +2033,5 @@
 
       Int sliceQP = m_pcCfg->getInitialQP();
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
       if ( ( pocCurr == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified
 #else
@@ -1983,9 +2316,5 @@
     {
 #if SVC_EXTENSION
-#if VPS_NUH_LAYER_ID
-      OutputNALUnit nalu(NAL_UNIT_VPS, 0, 0        ); // The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
-#else
-      OutputNALUnit nalu(NAL_UNIT_VPS, 0, m_layerId);
-#endif
+      OutputNALUnit nalu( NAL_UNIT_VPS, 0, 0 ); // The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
 #if AVC_BASE
       if( ( m_layerId == 1 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) || ( m_layerId == 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) )
@@ -2021,4 +2350,10 @@
       nalu = NALUnit(NAL_UNIT_SPS);
 #endif
+#if Q0078_ADD_LAYER_SETS
+      if (m_pcEncTop->getVPS()->getNumDirectRefLayers(m_layerId) == 0 && m_pcEncTop->getVPS()->getNumAddLayerSets() > 0)
+      {
+        nalu.m_layerId = 0; // For independent base layer rewriting
+      }
+#endif
       m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
       if (m_bSeqFirst)
@@ -2058,4 +2393,10 @@
 #else
       nalu = NALUnit(NAL_UNIT_PPS);
+#endif
+#if Q0078_ADD_LAYER_SETS
+      if (m_pcEncTop->getVPS()->getNumDirectRefLayers(m_layerId) == 0 && m_pcEncTop->getVPS()->getNumAddLayerSets() > 0)
+      {
+        nalu.m_layerId = 0; // For independent base layer rewriting
+      }
 #endif
       m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
@@ -2155,4 +2496,43 @@
       writeSOP = false;
     }
+#if Q0189_TMVP_CONSTRAINTS
+   if( m_pcEncTop->getTMVPConstraintsSEIEnabled() == 1 &&
+      (m_pcEncTop->getTMVPModeId() == 1 || m_pcEncTop->getTMVPModeId() == 2) &&
+      pcSlice->getLayerId() >0 && 
+      (pcSlice->getNalUnitType() ==  NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcSlice->getNalUnitType() ==  NAL_UNIT_CODED_SLICE_IDR_N_LP))
+   {
+      OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
+      SEITMVPConstrains seiTMVPConstrains;
+      m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
+      m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+      seiTMVPConstrains.no_intra_layer_col_pic_flag = 1;
+      seiTMVPConstrains.prev_pics_not_used_flag = 1;
+#if   O0164_MULTI_LAYER_HRD
+      m_seiWriter.writeSEImessage( nalu.m_Bitstream, seiTMVPConstrains, m_pcEncTop->getVPS(), pcSlice->getSPS() );
+#else
+      m_seiWriter.writeSEImessage( nalu.m_Bitstream, seiTMVPConstrains, pcSlice->getSPS() );
+#endif
+      writeRBSPTrailingBits(nalu.m_Bitstream);
+      accessUnit.push_back(new NALUnitEBSP(nalu));
+   }
+#endif
+#if Q0247_FRAME_FIELD_INFO
+    if(  pcSlice->getLayerId()> 0 &&
+     ( (m_pcCfg->getProgressiveSourceFlag() && m_pcCfg->getInterlacedSourceFlag()) || m_pcCfg->getFrameFieldInfoPresentFlag()))
+    {
+      OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
+      SEIFrameFieldInfo seiFFInfo;
+      m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
+      m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+      seiFFInfo.m_ffinfo_picStruct = (isField && pcSlice->getPic()->isTopField())? 1 : isField? 2 : 0;
+#if   O0164_MULTI_LAYER_HRD
+      m_seiWriter.writeSEImessage( nalu.m_Bitstream, seiFFInfo, m_pcEncTop->getVPS(), pcSlice->getSPS() );
+#else
+      m_seiWriter.writeSEImessage( nalu.m_Bitstream, seiFFInfo, pcSlice->getSPS() );
+#endif
+      writeRBSPTrailingBits(nalu.m_Bitstream);
+      accessUnit.push_back(new NALUnitEBSP(nalu));
+    }
+#endif
 
     if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) &&
@@ -2185,5 +2565,5 @@
       }
       pictureTimingSEI.m_auCpbRemovalDelay = std::min<Int>(std::max<Int>(1, m_totalCoded - m_lastBPSEI), static_cast<Int>(pow(2, static_cast<double>(pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getCpbRemovalDelayLengthMinus1()+1)))); // Syntax element signalled as minus, hence the .
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
       pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(pcSlice->getSPS()->getMaxTLayers()-1) + pocCurr - m_totalCoded;
 #else
@@ -2313,5 +2693,5 @@
       SEIRecoveryPoint sei_recovery_point;
       sei_recovery_point.m_recoveryPocCnt    = 0;
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
       sei_recovery_point.m_exactMatchingFlag = ( pocCurr == 0 ) ? (true) : (false);
 #else
@@ -3068,4 +3448,197 @@
 #endif
 }
+
+#if POC_RESET_IDC_ENCODER
+Void TEncGOP::determinePocResetIdc(Int const pocCurr, TComSlice *const slice)
+{
+  // If one picture in the AU is IDR, and another picture is not IDR, set the poc_reset_idc to 1 or 2
+  // If BL picture in the AU is IDR, and another picture is not IDR, set the poc_reset_idc to 2
+  // If BL picture is IRAP, and another picture is non-IRAP, then the poc_reset_idc is equal to 1 or 2.
+  if( slice->getSliceIdx() == 0 ) // First slice - compute, copy for other slices
+  {
+    Int needReset = false;
+    Int resetDueToBL = false;
+    if( slice->getVPS()->getMaxLayers() > 1 )
+    {
+      // If IRAP is refreshed in this access unit for base layer
+      if( (m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() == 1 || m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() == 2)
+        && ( pocCurr % m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshInterval() == 0 )
+        )
+      {
+        // Check if the IRAP refresh interval of any layer does not match that of the base layer
+        for(Int i = 1; i < slice->getVPS()->getMaxLayers(); i++)
+        {
+          Bool refreshIntervalFlag = ( pocCurr % m_ppcTEncTop[i]->getGOPEncoder()->getIntraRefreshInterval() == 0 );
+          Bool refreshTypeFlag     = ( m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() == m_ppcTEncTop[i]->getGOPEncoder()->getIntraRefreshType() );
+          if( !(refreshIntervalFlag && refreshTypeFlag) )
+          {
+            needReset = true;
+            resetDueToBL = true;
+            break;
+          }
+        }
+      }
+    }
+    
+    if( !needReset )// No need reset due to base layer IRAP
+    {
+      // Check if EL IDRs results in POC Reset
+      for(Int i = 1; i < slice->getVPS()->getMaxLayers() && !needReset; i++)
+      {
+        Bool idrFlag = ( (m_ppcTEncTop[i]->getGOPEncoder()->getIntraRefreshType() == 2) 
+                        && ( pocCurr % m_ppcTEncTop[i]->getGOPEncoder()->getIntraRefreshInterval() == 0 )
+                        );
+        for(Int j = 0; j < slice->getVPS()->getMaxLayers(); j++)
+        {
+          if( j == i )
+          {
+            continue;
+          }
+          Bool idrOtherPicFlag = ( (m_ppcTEncTop[j]->getGOPEncoder()->getIntraRefreshType() == 2) 
+                                  && ( pocCurr % m_ppcTEncTop[j]->getGOPEncoder()->getIntraRefreshInterval() == 0 )
+                                  );
+
+          if( idrFlag != idrOtherPicFlag )
+          {
+            needReset = true;
+            break;
+          }
+        }
+      }
+    }
+    if( needReset )
+    {
+      if( m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() == 2 )  // BL IDR refresh, assuming BL picture present
+      {
+        if( resetDueToBL )
+        {
+          slice->setPocResetIdc( 2 ); // Full reset needed
+        }
+        else
+        {
+          slice->setPocResetIdc( 1 ); // Due to IDR in EL
+        }
+      }
+      else
+      {
+        slice->setPocResetIdc( 1 ); // Only MSB reset
+      }
+
+      // Start a new POC reset period
+      if (m_layerId == 0)   // Assuming BL picture is always present at encoder; for other AU structures, need to change this
+      {
+        Int periodId = rand() % 64;
+        m_lastPocPeriodId = (periodId == m_lastPocPeriodId) ? (periodId + 1) % 64 : periodId ;
+      }
+      else
+      {
+        m_lastPocPeriodId = m_ppcTEncTop[0]->getGOPEncoder()->getLastPocPeriodId();
+      }
+      slice->setPocResetPeriodId(m_lastPocPeriodId);
+    }
+    else
+    {
+      slice->setPocResetIdc( 0 );
+    }
+  }
+}
+
+Void TEncGOP::updatePocValuesOfPics(Int const pocCurr, TComSlice *const slice)
+{
+
+  Int pocAdjustValue = pocCurr - m_pcEncTop->getPocAdjustmentValue();
+
+  // New POC reset period
+  Int maxPocLsb, pocLsbVal, pocMsbDelta, pocLsbDelta, deltaPocVal;
+
+  maxPocLsb   = 1 << slice->getSPS()->getBitsForPOC();
+  pocLsbVal   = (slice->getPocResetIdc() == 3)
+                ? slice->getPocLsbVal()
+                : pocAdjustValue % maxPocLsb; 
+  pocMsbDelta = pocAdjustValue - pocLsbVal;
+  pocLsbDelta = (slice->getPocResetIdc() == 2 || ( slice->getPocResetIdc() == 3 && slice->getFullPocResetFlag() )) 
+                ? pocLsbVal 
+                : 0; 
+  deltaPocVal = pocMsbDelta  + pocLsbDelta;
+  
+  // Decrement value of associatedIrapPoc of the TEncGop object
+  this->m_associatedIRAPPOC -= deltaPocVal;
+
+  // Decrememnt the value of m_pocCRA
+  this->m_pocCRA -= deltaPocVal;
+
+  // Iterate through all pictures in the DPB
+  TComList<TComPic*>::iterator  iterPic = getListPic()->begin();  
+  while( iterPic != getListPic()->end() )
+  {
+    TComPic *dpbPic = *iterPic;
+    
+    if( dpbPic->getReconMark() )
+    {
+      for(Int i = dpbPic->getNumAllocatedSlice() - 1; i >= 0; i--)
+      {
+        TComSlice *dpbPicSlice = dpbPic->getSlice( i );
+        TComReferencePictureSet *dpbPicRps = dpbPicSlice->getRPS();
+
+        // Decrement POC of slice
+        dpbPicSlice->setPOC( dpbPicSlice->getPOC() - deltaPocVal );
+
+        // Decrement POC value stored in the RPS of each such slice
+        for( Int j = dpbPicRps->getNumberOfPictures() - 1; j >= 0; j-- )
+        {
+          dpbPicRps->setPOC( j, dpbPicRps->getPOC(j) - deltaPocVal );
+        }
+
+        // Decrement value of refPOC
+        dpbPicSlice->decrementRefPocValues( deltaPocVal );
+
+        // Update value of associatedIrapPoc of each slice
+        dpbPicSlice->setAssociatedIRAPPOC( dpbPicSlice->getAssociatedIRAPPOC() - deltaPocVal );
+      }
+    }
+    iterPic++;
+  }
+  
+  // Actual POC value before reset
+  Int adjustedPocValue = pocCurr - m_pcEncTop->getPocAdjustmentValue();
+
+  // Set MSB value before reset
+  Int tempLsbVal = adjustedPocValue & (maxPocLsb - 1);
+  slice->setPocMsbVal( adjustedPocValue - tempLsbVal);
+
+  // Set LSB value before reset - this is needed in the case of resetIdc = 2
+  slice->setPicOrderCntLsb( tempLsbVal );
+
+  // Cumulative delta
+  m_pcEncTop->setPocAdjustmentValue( m_pcEncTop->getPocAdjustmentValue() + deltaPocVal );
+
+  // New LSB value, after reset
+  adjustedPocValue = pocCurr - m_pcEncTop->getPocAdjustmentValue();
+  Int newLsbVal = adjustedPocValue & (maxPocLsb - 1);
+
+  // Set value of POC current picture after RESET
+  if( slice->getPocResetIdc() == 1 )
+  {
+    slice->setPOC( newLsbVal );
+  }
+  else if( slice->getPocResetIdc() == 2 )
+  {
+    slice->setPOC( 0 );
+  }
+  else if( slice->getPocResetIdc() == 3 )
+  {
+    Int picOrderCntMsb = slice->getCurrMsb( newLsbVal, 
+                                        slice->getFullPocResetFlag() ? 0 : slice->getPocLsbVal(), 
+                                        0,
+                                        maxPocLsb );
+    slice->setPOC( picOrderCntMsb + newLsbVal );
+  }
+  else
+  {
+    assert(0);
+  }
+}
+#endif
+
 
 #if !SVC_EXTENSION
@@ -3516,9 +4089,17 @@
       if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR(m_layerId) )
       {
+#if POC_RESET_IDC_ENCODER
+        printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
+#else
         printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR(), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
+#endif
       }
       else
       {
+#if POC_RESET_IDC_ENCODER
+        printf ("%d", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
+#else
         printf ("%d", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR());
+#endif
       }
 #endif
@@ -3747,7 +4328,14 @@
     }
   }
+
+#if POC_RESET_IDC_ENCODER
+  if(m_pocCraWithoutReset > 0 && this->m_associatedIRAPType == NAL_UNIT_CODED_SLICE_CRA)
+  {
+    if(pocCurr < m_pocCraWithoutReset)
+#else
   if(m_pocCRA>0)
   {
     if(pocCurr<m_pocCRA)
+#endif
     {
       // All leading pictures are being marked as TFD pictures here since current encoder uses all 
@@ -4287,5 +4875,7 @@
 
     if(!m_temp)
+    {
       initDs(iWidth, iHeight, m_pcCfg->getIntraPeriod()>1);
+    }
 
     filterImg(pcYuvSrc->getLumaAddr(), pcYuvSrc->getStride(), pcYuvDest->getLumaAddr(), pcYuvDest->getStride(), iHeight, iWidth,  inputBitDepth-outputBitDepth, 0);
@@ -4294,5 +4884,5 @@
   }
 }
-const int TEncGOP::m_phase_filter_0_t0[4][13]={
+const Int TEncGOP::m_phase_filter_0_t0[4][13]={
   {0,  2,  -3,  -9,   6,  39,  58,  39,   6,  -9,  -3,  2,  0},  
   {0, 0,  0,  -2,  8,-20, 116, 34, -10,  2,  0, 0,  0},                      //{0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0},  //
@@ -4301,5 +4891,5 @@
 };
 
-const int TEncGOP::m_phase_filter_0_t1[4][13]={
+const Int TEncGOP::m_phase_filter_0_t1[4][13]={
   {0,  4,  0,  -12, 0,  40,  64,  40, 0, -12,  0,  4,  0},
   {0, 0,  0,  -2,  8,-20, 116,34,-10,  2,  0, 0,  0},                      //{0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0},  //
@@ -4307,5 +4897,5 @@
   {0,  0,   1,  -5,  -7,  13,  47,  57,  31,  -1,  -8,-1,  1}  
 };
-const int TEncGOP::m_phase_filter_0_t1_chroma[4][13]={
+const Int TEncGOP::m_phase_filter_0_t1_chroma[4][13]={
   {0,  0,  0,   0,  0,   0,  128, 0,  0,  0,  0,  0,  0},
   {0, 0,  0,  -2,  8,-20, 116,34,-10,  2,  0, 0,  0},                      //{0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0},  //
@@ -4314,5 +4904,5 @@
 };
 
-const int TEncGOP::m_phase_filter_1[8][13]={
+const Int TEncGOP::m_phase_filter_1[8][13]={
   {0,   0,  5,  -6,  -10,37,  76,  37,-10,   -6, 5,  0,   0},    
   {0,  -1,  5,  -3,  -12,29,  75,  45,  -7,   -8, 5,  0,   0},    
@@ -4325,4 +4915,12 @@
 };
 
+#if CGS_GCC_NO_VECTORIZATION  
+#ifdef __GNUC__
+#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+#if GCC_VERSION > 40600
+__attribute__((optimize("no-tree-vectorize")))
+#endif
+#endif
+#endif
 Void TEncGOP::filterImg(
     Pel           *src,
@@ -4377,7 +4975,11 @@
   // pad temp (vertical)
   for (k=-(length>>1); k<0; k++)
-    memcpy(m_temp[k], m_temp[0], width2*sizeof(int));
+  {
+    memcpy(m_temp[k], m_temp[0], width2*sizeof(Int));
+  }
   for (k=height1; k<(height1+(length>>1)); k++)
-    memcpy(m_temp[k], m_temp[k-1], (width2)* sizeof(int));
+  {
+    memcpy(m_temp[k], m_temp[k-1], (width2)* sizeof(Int));
+  }
 
   // vertical filtering
@@ -4400,5 +5002,5 @@
       }
       iSum=((iSum + shift_round) >> shift2);
-      *p_dst++ = (short)(iSum > iMax ? iMax : (iSum < 0 ? 0 : iSum));
+      *p_dst++ = (Short)(iSum > iMax ? iMax : (iSum < 0 ? 0 : iSum));
     }
     p_dst_line += iDstStride;
@@ -4455,7 +5057,11 @@
   {
     if (*array2D)
+    {
       xFree(array2D[-iPadY]-iPadX);
+    }
     else 
+    {
       printf("free_mem2DintWithPad: trying to free unused memory\r\nPress Any Key\r\n");
+    }
 
     free (&array2D[-iPadY]);
Index: trunk/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 752)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 815)
@@ -113,4 +113,8 @@
   Bool                    m_bRefreshPending;
   Int                     m_pocCRA;
+#if POC_RESET_IDC_ENCODER
+  Int                     m_pocCraWithoutReset;
+  Int                     m_associatedIrapPocBeforeReset;
+#endif
   std::vector<Int>        m_storedStartCUAddrForEncodingSlice;
   std::vector<Int>        m_storedStartCUAddrForEncodingSliceSegment;
@@ -135,7 +139,5 @@
   UInt                    m_layerId;      
   TEncTop**               m_ppcTEncTop;
-#if SVC_UPSAMPLING
   TEncSearch*             m_pcPredSearch;                       ///< encoder search class
-#endif  
 #if Q0048_CGS_3D_ASYMLUT
   TEnc3DAsymLUT           m_Enc3DAsymLUTPicUpdate;
@@ -154,4 +156,7 @@
   Int   **m_temp;
 #endif
+#if POC_RESET_IDC_ENCODER
+  Int   m_lastPocPeriodId;
+#endif
 #endif
   
@@ -172,4 +177,13 @@
 #else
   Void  compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff );
+#endif
+#if POC_RESET_IDC_ENCODER
+  Void  determinePocResetIdc( Int const pocCurr, TComSlice *const slice);
+  Int   getIntraRefreshInterval()  { return m_pcCfg->getIntraPeriod(); }
+  Int   getIntraRefreshType()      { return m_pcCfg->getDecodingRefreshType(); }
+  // Int   getIntraRefreshInterval ()  { return (m_pcCfg) ? m_pcCfg->getIntraPeriod() : 0;  }
+  Int   getLastPocPeriodId()      { return m_lastPocPeriodId; }
+  Void  setLastPocPeriodId(Int x) { m_lastPocPeriodId = x;    }
+  Void  updatePocValuesOfPics( Int const pocCurr, TComSlice *const slice);
 #endif
   Void  xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect);
@@ -209,4 +223,7 @@
 
   SEIToneMappingInfo*     xCreateSEIToneMappingInfo();
+#if P0050_KNEE_FUNCTION_SEI
+  SEIKneeFunctionInfo*    xCreateSEIKneeFunctionInfo();
+#endif
 #if Q0074_SEI_COLOR_MAPPING
   SEIColorMappingInfo*    xCreateSEIColorMappingInfo( Char* file );
Index: trunk/source/Lib/TLibEncoder/TEncPic.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncPic.cpp	(revision 752)
+++ trunk/source/Lib/TLibEncoder/TEncPic.cpp	(revision 815)
@@ -126,20 +126,17 @@
  * \return Void
  */
+#if SVC_EXTENSION
 #if AUXILIARY_PICTURES
-#if SVC_UPSAMPLING
 Void TEncPic::create( Int iWidth, Int iHeight, ChromaFormat chromaFormat, 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, ChromaFormat chromaFormat, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,
-                      Window &conformanceWindow, Window &defaultDisplayWindow, Int *numReorderPics, Bool bIsVirtual )
-#endif
 {
-#if SVC_UPSAMPLING
   TComPic::create( iWidth, iHeight, chromaFormat, uiMaxWidth, uiMaxHeight, uiMaxDepth,  
                    conformanceWindow, defaultDisplayWindow, numReorderPics, pcSps, bIsVirtual );
 #else
-  TComPic::create( iWidth, iHeight, chromaFormat, uiMaxWidth, uiMaxHeight, uiMaxDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, bIsVirtual );
+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 )
+{
+  TComPic::create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth,  
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSps, bIsVirtual );
 #endif
   m_uiMaxAQDepth = uiMaxAQDepth;
@@ -153,21 +150,10 @@
   }
 }
-#else
-#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
+#else  //SVC_EXTENSION
 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 )
@@ -180,5 +166,5 @@
   }
 }
-#endif
+#endif //SVC_EXTENSION
 
 /** Clean up
Index: trunk/source/Lib/TLibEncoder/TEncPic.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncPic.h	(revision 752)
+++ trunk/source/Lib/TLibEncoder/TEncPic.h	(revision 815)
@@ -41,5 +41,5 @@
 #include "TLibCommon/CommonDef.h"
 #include "TLibCommon/TComPic.h"
-#if SVC_UPSAMPLING
+#if SVC_EXTENSION
 #include "TLibCommon/TComSlice.h"
 #endif
@@ -105,22 +105,17 @@
   virtual ~TEncPic();
 
+#if SVC_EXTENSION
 #if AUXILIARY_PICTURES
-#if SVC_UPSAMPLING
   Void          create( Int iWidth, Int iHeight, ChromaFormat chromaFormat, 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, ChromaFormat chromaFormat, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,
-                          Window &conformanceWindow, Window &defaultDisplayWindow, Int *numReorderPics, Bool bIsVirtual = false );
-
-#endif
-#else
-#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
+#endif
+#else  //SVC_EXTENSION
   Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,   
                         Window &conformanceWindow, Window &defaultDisplayWindow, Int *numReorderPics, Bool bIsVirtual = false );
-#endif
-#endif
+#endif //SVC_EXTENSION
+
   virtual Void  destroy();
 
Index: trunk/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 752)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 815)
@@ -3102,8 +3102,16 @@
  * \returns Void
  */
+#if SVC_EXTENSION
+#if AMP_MRG
+Bool TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bUseRes, Bool bUseMRG )
+#else
+Bool TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bUseRes )
+#endif
+#else
 #if AMP_MRG
 Void TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bUseRes, Bool bUseMRG )
 #else
 Void TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bUseRes )
+#endif
 #endif
 {
@@ -3215,4 +3223,8 @@
 #endif
 
+#if SVC_EXTENSION
+      Bool doneUniPred = false;
+#endif
+
     //  Uni-directional prediction
     for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ )
@@ -3222,16 +3234,26 @@
       for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ )
       {
+#if SVC_EXTENSION
+        TComPic* pcPic = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp );
+        
+        // motion search only for the ILRP with sample prediction type
+        if( pcPic->isILR( pcCU->getLayerId() ) && !pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerId(), pcPic->getLayerId() ) )
+        {
+          continue;
+        }
+
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-        if (pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp )->isILR(pcCU->getLayerId()) && m_disableILP)
+        if( pcPic->isILR(pcCU->getLayerId()) && m_disableILP )
         {
           continue;
         }
 #endif
-#if (ENCODER_FAST_MODE)
-        TComPic* pcPic    = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp );
+#if (ENCODER_FAST_MODE)        
         if( pcPic->isILR(pcCU->getLayerId()) && (ePartSize == SIZE_2Nx2N) ) 
         {
           continue;
         }
+#endif
+        doneUniPred = true;
 #endif
 
@@ -3342,4 +3364,13 @@
       }
     }
+
+#if SVC_EXTENSION
+    if( pcCU->getLayerId() && !doneUniPred )
+    {
+      // there is no valid reference pictures for inter prediction
+      return false;
+    }
+#endif
+
     //  Bi-directional prediction
 #if REF_IDX_ME_ZEROMV
@@ -3462,5 +3493,12 @@
 #if (ENCODER_FAST_MODE)
           Bool testRefIdx = true;
-          pcPic           = pcCU->getSlice()->getRefPic( RefPicList(iRefList) , iRefIdxTemp );
+          pcPic = pcCU->getSlice()->getRefPic( RefPicList(iRefList) , iRefIdxTemp );
+
+          // motion search only for the ILRP with sample prediction type
+          if( pcPic->isILR( pcCU->getLayerId() ) && !pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerId(), pcPic->getLayerId() ) )
+          {
+            continue;
+          }
+
           if(pcPic->isILR(pcCU->getLayerId()) && (ePartSize == SIZE_2Nx2N))
           {
@@ -3781,5 +3819,9 @@
   setWpScalingDistParam( pcCU, -1, REF_PIC_LIST_X );
 
+#if SVC_EXTENSION
+  return true;
+#else
   return;
+#endif
 }
 
@@ -5967,143 +6009,148 @@
 Bool TEncSearch::predInterSearchILRUni( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, UInt refLayerId )
 {
-    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;
-    Bool          bILRSearched = false;
-
-    xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
-    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight );
-
-    for( Int iRefList = 0; iRefList < iNumPredDir; iRefList++)  //list
-    {
-        if(bILRSearched)
-           continue;
-
-        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)->isILR(pcCU->getLayerId()) && pcCU->getSlice()->getRefPic(eRefPicList, refIdx)->getLayerId() == refLayerId )
-            {
-                iRefIdxTemp = refIdx;
-                foundILR    = true;
-                bILRSearched = 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;
+  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;
+  Bool          bILRSearched = false;
+
+  xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
+  pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight );
+
+  for( Int iRefList = 0; iRefList < iNumPredDir; iRefList++)  //list
+  {
+    if(bILRSearched)
+    {
+      continue;
+    }
+
+    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++ )
+    {
+      TComPic* refPic = pcCU->getSlice()->getRefPic(eRefPicList, refIdx);
+
+      // ILRP has to be for the sample prediction type
+      if( refPic->isILR(pcCU->getLayerId()) && refPic->getLayerId() == refLayerId && pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerId(), refLayerId ) )
+      {
+        iRefIdxTemp = refIdx;
+        foundILR    = true;
+        bILRSearched = 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
Index: trunk/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 752)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 815)
@@ -126,9 +126,8 @@
 
 #if SVC_EXTENSION
-  TEncTop**       m_ppcTEncTop;
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
   Bool            m_disableILP;
 #endif
-#endif //SVC_EXTENAION
+#endif //SVC_EXTENSION
 
 public:
@@ -194,5 +193,9 @@
   
   /// encoder estimation - inter prediction (non-skip)
+#if SVC_EXTENSION
+  Bool predInterSearch          ( TComDataCU* pcCU,
+#else
   Void predInterSearch          ( TComDataCU* pcCU,
+#endif
                                   TComYuv*    pcOrgYuv,
                                   TComYuv*&   rpcPredYuv,
Index: trunk/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 752)
+++ trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 815)
@@ -89,5 +89,5 @@
 #endif
   m_numScaledRefLayerOffsets = 0;
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
   m_pocAdjustmentValue     = 0;
 #endif
@@ -810,9 +810,5 @@
 
             //only for scalable extension
-#if SCALABILITY_MASK_E0104
-            assert( m_cVPS.getScalabilityMask(2) == true );
-#else
-            assert( m_cVPS.getScalabilityMask(1) == true );
-#endif
+            assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true );
           }
         }
@@ -820,21 +816,16 @@
 #endif
 
+#if SVC_EXTENSION
 #if AUXILIARY_PICTURES
-#if SVC_UPSAMPLING
       pcEPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, 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, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
-                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
-#endif
-#else
-#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
+#endif
+#else  //SVC_EXTENSION
       pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
                       m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
-#endif
-#endif
+#endif //SVC_EXTENSION
       rpcPic = pcEPic;
     }
@@ -879,9 +870,5 @@
 
             //only for scalable extension
-#if SCALABILITY_MASK_E0104
-            assert( m_cVPS.getScalabilityMask(2) == true );
-#else
-            assert( m_cVPS.getScalabilityMask(1) == true );
-#endif
+            assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true );
           }
         }
@@ -889,21 +876,16 @@
 #endif
 
+#if SVC_EXTENSION
 #if AUXILIARY_PICTURES
-#if SVC_UPSAMPLING
       rpcPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                       m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
 #else
-      rpcPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
-                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
-#endif
-#else
-#if SVC_UPSAMPLING
       rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                       m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
-#else
+#endif
+#else  //SVC_EXTENSION
       rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                       m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
-#endif
-#endif
+#endif //SVC_EXTENSION
     }
     m_cListPic.pushBack( rpcPic );
@@ -922,5 +904,18 @@
 {
 #if SVC_EXTENSION
+  m_cSPS.setExtensionFlag( m_layerId > 0 ? true : false );
+
+#if Q0078_ADD_LAYER_SETS
+  if (getNumDirectRefLayers() == 0 && getNumAddLayerSets() > 0)
+  {
+    m_cSPS.setLayerId(0); // layer ID 0 for independent layers
+  }
+  else
+  {
+    m_cSPS.setLayerId(m_layerId);
+  }
+#else
   m_cSPS.setLayerId(m_layerId);
+#endif
   m_cSPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets);
   for(Int i = 0; i < m_cSPS.getNumScaledRefLayerOffsets(); i++)
@@ -1082,8 +1077,4 @@
 Void TEncTop::xInitPPS()
 {
-#if SCALINGLIST_INFERRING
-  m_cPPS.setLayerId( m_layerId );
-#endif
-
   m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
   Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
@@ -1181,16 +1172,28 @@
   }
 #if SVC_EXTENSION
-  if (!m_layerId)
+#if SCALINGLIST_INFERRING
+  m_cPPS.setLayerId( m_layerId );
+#endif
+
+#if Q0078_ADD_LAYER_SETS
+  if (getNumDirectRefLayers() == 0 && getNumAddLayerSets() > 0)
+  {
+    m_cPPS.setLayerId(0); // layer ID 0 for independent layers
+  }
+#endif
+
+  if( m_layerId > 0 )
+  {
+    m_cPPS.setListsModificationPresentFlag(true);
+    m_cPPS.setExtensionFlag(true);
+  }
+  else
   {
     m_cPPS.setListsModificationPresentFlag(false);
-  }
-  else
-  {
-    m_cPPS.setListsModificationPresentFlag(true);
-  }
-
-  m_cPPS.setPPSId         ( m_iPPSIdCnt         );
-  m_cPPS.setSPSId         ( m_iSPSIdCnt         );
-#endif
+    m_cPPS.setExtensionFlag(false);
+  }
+
+  m_cPPS.setPPSId( m_iPPSIdCnt );
+  m_cPPS.setSPSId( m_iSPSIdCnt );
 #if POC_RESET_FLAG
   m_cPPS.setNumExtraSliceHeaderBits( 2 );
@@ -1205,4 +1208,10 @@
   m_cPPS.setCGSFlag( m_nCGSFlag );
 #endif
+#if POC_RESET_IDC_ENCODER
+  m_cPPS.setPocResetInfoPresentFlag( true );
+  m_cPPS.setExtensionFlag( true );
+  m_cPPS.setSliceHeaderExtensionPresentFlag( true );
+#endif
+#endif //SVC_EXTENSION
 }
 
@@ -1582,12 +1591,8 @@
       {
         m_cIlpPic[j] = new  TComPic;
-#if SVC_UPSAMPLING
 #if AUXILIARY_PICTURES
         m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
 #else
         m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
-#endif
-#else
-        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
 #endif
         for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
@@ -1649,12 +1654,8 @@
       {
         m_cIlpPic[j] = new  TComPic;
-#if SVC_UPSAMPLING
 #if AUXILIARY_PICTURES
         m_cIlpPic[j]->create(picWidth, picHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
 #else
         m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
-#endif
-#else
-        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
 #endif
         for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
Index: trunk/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 752)
+++ trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 815)
@@ -142,5 +142,5 @@
   Bool                    m_vertPhasePositionEnableFlag[MAX_LAYERS];
 #endif
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
   Int                     m_pocAdjustmentValue;
 #endif
@@ -153,4 +153,7 @@
 #if O0194_WEIGHTED_PREDICTION_CGS
   Bool                    m_interLayerWeightedPredFlag;
+#endif
+#if Q0078_ADD_LAYER_SETS
+  int                     m_numAddLayerSets;
 #endif
 #endif //SVC_EXTENSION
@@ -254,5 +257,5 @@
   TEncTop*  getRefLayerEnc(UInt refLayerIdc);
 #endif
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
   Int       getPocAdjustmentValue()      { return m_pocAdjustmentValue;}
   Void      setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x;   }
@@ -268,4 +271,8 @@
   Void setNoOutputOfPriorPicsFlags(Bool x)   { m_noOutputOfPriorPicsFlags = x;   }
 #endif
+#if Q0078_ADD_LAYER_SETS
+  Void setNumAddLayerSets(Int x)             { m_numAddLayerSets = x; }
+  Int  getNumAddLayerSets()                  { return m_numAddLayerSets; }
+#endif
 #else //SVC_EXTENSION
   Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
