Index: trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/CommonDef.h	(revision 951)
+++ trunk/source/Lib/TLibCommon/CommonDef.h	(revision 964)
@@ -60,8 +60,8 @@
 
 #if H_MV
-#define NV_VERSION        "11.0"                ///< Current software version
-#define HM_VERSION        "13.0"                ///< 
+#define NV_VERSION        "11.1"                ///< Current software version
+#define HM_VERSION        "14.0"                ///< 
 #else
-#define NV_VERSION        "13.0"                 ///< Current software version
+#define NV_VERSION        "14.0"                 ///< Current software version
 #endif
 
@@ -215,5 +215,5 @@
 
 // Explicit temporal layer QP offset
-#define MAX_TLAYER                  8           ///< max number of temporal layer
+#define MAX_TLAYER                  7           ///< max number of temporal layer
 #define HB_LAMBDA_FOR_LDC           1           ///< use of B-style lambda for non-key pictures in low-delay mode
 
Index: trunk/source/Lib/TLibCommon/SEI.h
===================================================================
--- trunk/source/Lib/TLibCommon/SEI.h	(revision 951)
+++ trunk/source/Lib/TLibCommon/SEI.h	(revision 964)
@@ -128,6 +128,6 @@
   SEIActiveParameterSets() 
     : activeVPSId            (0)
-    , m_fullRandomAccessFlag (false)
-    , m_noParamSetUpdateFlag (false)
+    , m_selfContainedCvsFlag (false)
+    , m_noParameterSetUpdateFlag (false)
     , numSpsIdsMinus1        (0)
   {}
@@ -135,8 +135,8 @@
 
   Int activeVPSId; 
-  Bool m_fullRandomAccessFlag;
-  Bool m_noParamSetUpdateFlag;
+  Bool m_selfContainedCvsFlag;
+  Bool m_noParameterSetUpdateFlag;
   Int numSpsIdsMinus1;
-  std::vector<Int> activeSeqParamSetId; 
+  std::vector<Int> activeSeqParameterSetId; 
 };
 
@@ -356,4 +356,6 @@
   Int    m_cameraIsoSpeedIdc;
   Int    m_cameraIsoSpeedValue;
+  Int    m_exposureIndexIdc;
+  Int    m_exposureIndexValue;
   Int    m_exposureCompensationValueSignFlag;
   Int    m_exposureCompensationValueNumerator;
Index: trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 951)
+++ trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 964)
@@ -2883,5 +2883,5 @@
 }
 
-UChar TComDataCU::getNumPartInter()
+UChar TComDataCU::getNumPartitions()
 {
   UChar iNumPart = 0;
@@ -6830,5 +6830,7 @@
 #else
         picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
+#if !BUG_FIX_TK65
         assert(picDepth != NULL);
+#endif
 #endif
         if (picDepth && bDepthRefine)
@@ -6901,5 +6903,7 @@
 #else
           TComPic* picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
+#if !BUG_FIX_TK65
           assert(picDepth!=NULL);
+#endif
 #endif
 
@@ -6960,5 +6964,7 @@
 #else
     picDepth = getSlice()->getIvPic( true, viewIndex );
+#if !BUG_FIX_TK65
     assert(picDepth!=NULL);
+#endif
 #endif
     if (picDepth && bDepthRefine)
@@ -7060,5 +7066,7 @@
 #else
           picDepth   = getSlice()->getIvPic (true, refViewIdx );
+#if !BUG_FIX_TK65
           assert(picDepth != NULL);
+#endif
 #endif
           UInt uiPartIdx = 0;   //Notes from MTK: Please confirm that using 0 as partition index and partition address is correct for CU-level DoNBDV
Index: trunk/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 951)
+++ trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 964)
@@ -559,5 +559,5 @@
   Void          getPartIndexAndSize   ( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight );
 #endif
-  UChar         getNumPartInter       ();
+UChar         getNumPartitions       ();
   Bool          isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth);
 
Index: trunk/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 951)
+++ trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 964)
@@ -55,4 +55,7 @@
 , m_bReconstructed                        (false)
 , m_bNeededForOutput                      (false)
+#if H_MV_HLS_7_VPS_P0300_27
+, m_bPicOutputFlag                        (false)
+#endif
 , m_uiCurrSliceIdx                        (0)
 , m_bCheckLTMSB                           (false)
Index: trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.h	(revision 951)
+++ trunk/source/Lib/TLibCommon/TComPic.h	(revision 964)
@@ -69,4 +69,7 @@
   Bool                  m_bReconstructed;
   Bool                  m_bNeededForOutput;
+#if H_MV_HLS_7_VPS_P0300_27
+  Bool                  m_bPicOutputFlag;         // Semantics variable 
+#endif
   UInt                  m_uiCurrSliceIdx;         // Index of current slice
   Bool                  m_bCheckLTMSB;
@@ -175,5 +178,9 @@
   Void          setOutputMark (Bool b) { m_bNeededForOutput = b;     }
   Bool          getOutputMark ()       { return m_bNeededForOutput;  }
- 
+ #if H_MV_HLS_7_VPS_P0300_27
+  Void          setPicOutputFlag(Bool b) { m_bPicOutputFlag = b;      }
+  Bool          getPicOutputFlag()       { return m_bPicOutputFlag ;  }
+#endif
+
   Void          setNumReorderPics(Int i, UInt tlayer) { m_numReorderPics[tlayer] = i;    }
   Int           getNumReorderPics(UInt tlayer)        { return m_numReorderPics[tlayer]; }
Index: trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 951)
+++ trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 964)
@@ -1130,5 +1130,5 @@
   }
 
-  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
+  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ )
   {
     pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
Index: trunk/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 951)
+++ trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 964)
@@ -381,4 +381,5 @@
 Bool g_decTraceDispDer       = false; 
 Bool g_decTraceMvFromMerge   = false; 
+Bool g_decTracePicOutput     = false; 
 Bool g_stopAtPos             = false; 
 Bool g_outputPos             = false; 
Index: trunk/source/Lib/TLibCommon/TComRom.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.h	(revision 951)
+++ trunk/source/Lib/TLibCommon/TComRom.h	(revision 964)
@@ -225,6 +225,7 @@
  extern UInt64 g_stopAtCounter;         // Counter to set breakpoint. 
  extern Bool   g_traceCopyBack;         // Output samples on copy back  
- extern Bool   g_decTraceDispDer; // Trace derived disparity vectors (decoder only) 
+ extern Bool   g_decTraceDispDer;       // Trace derived disparity vectors (decoder only) 
  extern Bool   g_decTraceMvFromMerge;   // Trace motion vectors obtained from merge (decoder only) 
+ extern Bool   g_decTracePicOutput;     // Trace output of pictures
  extern Bool   g_stopAtPos;             // Stop at position
  extern Bool   g_outputPos;             // Output position
@@ -236,5 +237,4 @@
 #define DTRACE_PU_S(x)             writeToTraceFile( x,   g_tracePU );
 #define DTRACE_TU_S(x)             writeToTraceFile( x,   g_traceTU );
-
 
  Void           writeToTraceFile( const Char* symbolName, Int val, Bool doIt );
Index: trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 951)
+++ trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 964)
@@ -110,6 +110,7 @@
     m_offsetClipTable[compIdx] = NULL;
   }
+#if !SAO_SGN_FUNC
   m_signTable = NULL; 
-
+#endif
   
   m_lineBufWidth = 0;
@@ -155,5 +156,8 @@
   }
 
+#if !SAO_SGN_FUNC
   //look-up table for clipping
+  Int overallMaxSampleValue=0;
+#endif
   for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
   {
@@ -161,4 +165,7 @@
     Int maxSampleValue = (1<< bitDepthSample); //exclusive
     Int maxOffsetValue = (g_saoMaxOffsetQVal[compIdx] << m_offsetStepLog2[compIdx]); 
+#if !SAO_SGN_FUNC
+    if (maxSampleValue>overallMaxSampleValue) overallMaxSampleValue=maxSampleValue;
+#endif
 
     m_offsetClipTable[compIdx] = new Int[(maxSampleValue + maxOffsetValue -1)+ (maxOffsetValue)+1 ]; //positive & negative range plus 0
@@ -176,18 +183,17 @@
       *(offsetClipPtr -k -1 )              = 0;
     }
-    if(compIdx == SAO_Y) //g_bitDepthY is always larger than or equal to g_bitDepthC
-    {
-      m_signTable = new Short[ 2*(maxSampleValue-1) + 1 ];
-      m_sign = &(m_signTable[maxSampleValue-1]);
+  }
+
+#if !SAO_SGN_FUNC
+  m_signTable = new Short[ 2*(overallMaxSampleValue-1) + 1 ];
+  m_sign = &(m_signTable[overallMaxSampleValue-1]);
 
       m_sign[0] = 0;
-      for(Int k=1; k< maxSampleValue; k++)
+  for(Int k=1; k< overallMaxSampleValue; k++)
       {
         m_sign[k] = 1;
         m_sign[-k]= -1;
       }
-    }
-  }  
-
+#endif
 }
 
@@ -208,8 +214,10 @@
     }
   }
+#if !SAO_SGN_FUNC
   if( m_signTable )
   {
     delete[] m_signTable; m_signTable = NULL;
   }
+#endif
 }
 
@@ -388,8 +396,16 @@
       for (y=0; y< height; y++)
       {
+#if SAO_SGN_FUNC
+        signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]);
+#else
         signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
+#endif
         for (x=startX; x< endX; x++)
         {
+#if SAO_SGN_FUNC
+          signRight = (Char)sgn(srcLine[x] - srcLine[x+1]); 
+#else
           signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]]; 
+#endif
           edgeType =  signRight + signLeft;
           signLeft  = -signRight;
@@ -419,5 +435,9 @@
       for (x=0; x< width; x++)
       {
+#if SAO_SGN_FUNC
+        signUpLine[x] = (Char)sgn(srcLine[x] - srcLineAbove[x]);
+#else
         signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
+#endif
       }
 
@@ -429,5 +449,9 @@
         for (x=0; x< width; x++)
         {
+#if SAO_SGN_FUNC
+          signDown  = (Char)sgn(srcLine[x] - srcLineBelow[x]);
+#else
           signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]]; 
+#endif
           edgeType = signDown + signUpLine[x];
           signUpLine[x]= -signDown;
@@ -456,5 +480,9 @@
       for (x=startX; x< endX+1; x++)
       {
+#if SAO_SGN_FUNC
+        signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x- 1]);
+#else
         signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x- 1]];
+#endif
       }
 
@@ -465,5 +493,9 @@
       for(x= firstLineStartX; x< firstLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType  =  sgn(srcLine[x] - srcLineAbove[x- 1]) - signUpLine[x+1];
+#else
         edgeType  =  m_sign[srcLine[x] - srcLineAbove[x- 1]] - signUpLine[x+1];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
       }
@@ -479,5 +511,9 @@
         for (x=startX; x<endX; x++)
         {
+#if SAO_SGN_FUNC
+          signDown =  (Char)sgn(srcLine[x] - srcLineBelow[x+ 1]);
+#else
           signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x+ 1]] ;
+#endif
           edgeType =  signDown + signUpLine[x];
           resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
@@ -485,5 +521,9 @@
           signDownLine[x+1] = -signDown; 
         }
+#if SAO_SGN_FUNC
+        signDownLine[startX] = (Char)sgn(srcLineBelow[startX] - srcLine[startX-1]);
+#else
         signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
+#endif
 
         signTmpLine  = signUpLine;
@@ -501,5 +541,9 @@
       for(x= lastLineStartX; x< lastLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType =  sgn(srcLine[x] - srcLineBelow[x+ 1]) + signUpLine[x];
+#else
         edgeType =  m_sign[srcLine[x] - srcLineBelow[x+ 1]] + signUpLine[x];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
 
@@ -519,5 +563,9 @@
       for (x=startX-1; x< endX; x++)
       {
+#if SAO_SGN_FUNC
+        signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x+1]);
+#else
         signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
+#endif
       }
 
@@ -529,5 +577,9 @@
       for(x= firstLineStartX; x< firstLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType = sgn(srcLine[x] - srcLineAbove[x+1]) -signUpLine[x-1];
+#else
         edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] -signUpLine[x-1];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
       }
@@ -542,10 +594,18 @@
         for(x= startX; x< endX; x++)
         {
+#if SAO_SGN_FUNC
+          signDown =  (Char)sgn(srcLine[x] - srcLineBelow[x-1]);
+#else
           signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
+#endif
           edgeType =  signDown + signUpLine[x];
           resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
           signUpLine[x-1] = -signDown; 
         }
+#if SAO_SGN_FUNC
+        signUpLine[endX-1] = (Char)sgn(srcLineBelow[endX-1] - srcLine[endX]);
+#else
         signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
+#endif
         srcLine  += srcStride;
         resLine += resStride;
@@ -558,5 +618,9 @@
       for(x= lastLineStartX; x< lastLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType = sgn(srcLine[x] - srcLineBelow[x-1]) + signUpLine[x];
+#else
         edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + signUpLine[x];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
 
Index: trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h	(revision 951)
+++ trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h	(revision 964)
@@ -55,4 +55,11 @@
 extern UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 
 
+#if SAO_SGN_FUNC
+template <typename T> int sgn(T val) 
+{
+  return (T(0) < val) - (val < T(0));
+}
+#endif
+
 class TComSampleAdaptiveOffset
 {
@@ -79,5 +86,7 @@
   UInt m_offsetStepLog2[NUM_SAO_COMPONENTS]; //offset step  
   Int* m_offsetClip[NUM_SAO_COMPONENTS]; //clip table for fast operation
+#if !SAO_SGN_FUNC
   Short* m_sign; //sign table for fast operation
+#endif
   TComPicYuv*   m_tempPicYuv; //temporary buffer
   Int m_picWidth;
@@ -96,6 +105,7 @@
   Bool m_picSAOEnabled[NUM_SAO_COMPONENTS];
   Int*   m_offsetClipTable[NUM_SAO_COMPONENTS];
+#if !SAO_SGN_FUNC
   Short* m_signTable;
-
+#endif
 };
 
Index: trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 951)
+++ trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 964)
@@ -1,3 +1,3 @@
-/* The copyright in this software is being made available under the BSD
+﻿/* 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
@@ -45,6 +45,10 @@
 //! \{
 
+
 TComSlice::TComSlice()
 : m_iPPSId                        ( -1 )
+#if H_MV_HLS_8_POC_Q0142_32
+, m_slicePicOrderCntLsb           ( 0 )
+#endif
 , m_iPOC                          ( 0 )
 , m_iLastIDR                      ( 0 )
@@ -70,4 +74,9 @@
 , m_pcPic                         ( NULL )
 , m_colFromL0Flag                 ( 1 )
+#if SETTING_NO_OUT_PIC_PRIOR
+, m_noOutputPriorPicsFlag         ( false )
+, m_noRaslOutputFlag              ( false )
+, m_handleCraAsBlaFlag              ( false )
+#endif
 , m_colRefIdx                     ( 0 )
 , m_uiTLayer                      ( 0 )
@@ -459,6 +468,6 @@
   {
     // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
-    // ?If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-    // ?Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    // - If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
+    // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     if (getRapPicFlag())
     {
@@ -903,7 +912,31 @@
       pocCRA = pocCurr;
     }
+#if EFFICIENT_FIELD_IRAP
+    bRefreshPending = true;
+#endif
   }
   else // CRA or No DR
   {
+#if EFFICIENT_FIELD_IRAP
+    if(getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
+    {
+      if (bRefreshPending==true && pocCurr > m_iLastIDR) // IDR reference marking pending 
+      {
+        TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
+        while (iterPic != rcListPic.end())
+        {
+          rpcPic = *(iterPic);
+          if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != m_iLastIDR)
+          {
+            rpcPic->getSlice(0)->setReferenced(false);
+          }
+          iterPic++;
+        }
+        bRefreshPending = false; 
+      }
+    }
+    else
+    {
+#endif
     if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending 
     {
@@ -920,4 +953,7 @@
       bRefreshPending = false; 
     }
+#if EFFICIENT_FIELD_IRAP
+    }
+#endif
     if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
     {
@@ -1194,5 +1230,9 @@
     // in decoding order shall precede the IRAP picture in output order.
     // (Note that any picture following in output order would be present in the DPB)
+#if !SETTING_NO_OUT_PIC_PRIOR
     if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
+#else
+    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1 && !this->getNoOutputPriorPicsFlag())
+#endif
     {
       if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP    ||
@@ -1370,6 +1410,14 @@
 /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
 */
+#if ALLOW_RECOVERY_POINT_AS_RAP
+Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess, Bool bUseRecoveryPoint)
+#else
 Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess)
-{
+#endif
+{
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  Int atLeastOneUnabledByRecoveryPoint = 0;
+  Int atLeastOneFlushedByPreviousIDR = 0;
+#endif
   TComPic* rpcPic;
   Int i, isAvailable;
@@ -1392,5 +1440,16 @@
         if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced())
         {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+          {
+            isAvailable = 0;
+          }
+          else
+          {
           isAvailable = 1;
+        }
+#else
+          isAvailable = 1;
+#endif
         }
       }
@@ -1402,5 +1461,16 @@
         if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced())
         {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+          {
+            isAvailable = 0;
+          }
+          else
+          {
           isAvailable = 1;
+        }
+#else
+          isAvailable = 1;
+#endif
         }
       }
@@ -1425,7 +1495,20 @@
         if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc)
         {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+          {
+            isAvailable = 0;
+          }
+          else
+          {
           isAvailable = 1;
           rpcPic->setIsLongTerm(1);
           break;
+        }
+#else
+          isAvailable = 1;
+          rpcPic->setIsLongTerm(1);
+          break;
+#endif
         }
       }
@@ -1455,4 +1538,14 @@
         }
       }
+#if ALLOW_RECOVERY_POINT_AS_RAP
+      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
+      {
+        atLeastOneUnabledByRecoveryPoint = 1;
+      }
+      else if(bUseRecoveryPoint && (this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_N_LP || this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_W_RADL))
+      {
+        atLeastOneFlushedByPreviousIDR = 1;
+      }
+#endif
     }
   }  
@@ -1470,5 +1563,16 @@
       if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
       {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+        if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+        {
+          isAvailable = 0;
+        }
+        else
+        {
         isAvailable = 1;
+      }
+#else
+        isAvailable = 1;
+#endif
       }
     }
@@ -1497,6 +1601,22 @@
         }
       }
-    }
+#if ALLOW_RECOVERY_POINT_AS_RAP
+      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
+      {
+        atLeastOneUnabledByRecoveryPoint = 1;
+    }
+      else if(bUseRecoveryPoint && (this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_N_LP || this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_W_RADL))
+      {
+        atLeastOneFlushedByPreviousIDR = 1;
   }    
+#endif
+    }
+    }
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  if(atLeastOneUnabledByRecoveryPoint || atLeastOneFlushedByPreviousIDR)
+  {
+    return -1;
+  }    
+#endif
   if(atLeastOneLost)
   {
@@ -1515,5 +1635,9 @@
 /** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
 */
+#if ALLOW_RECOVERY_POINT_AS_RAP
+Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP, Int pocRandomAccess, Bool bUseRecoveryPoint)
+#else
 Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP)
+#endif
 {
   TComPic* rpcPic;
@@ -1541,4 +1665,7 @@
         pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
         pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
+#if ALLOW_RECOVERY_POINT_AS_RAP
+        pcRPS->setUsed(k, pcRPS->getUsed(k) && !(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess) ); 
+#endif
         if(pcRPS->getDeltaPOC(k) < 0)
         {
@@ -1553,4 +1680,24 @@
     }
   }
+#if EFFICIENT_FIELD_IRAP
+  Bool useNewRPS = false;
+  // if current picture is complimentary field associated to IRAP, add the IRAP to its RPS. 
+  if(m_pcPic->isField())
+  {
+    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
+    while ( iterPic != rcListPic.end())
+    {
+      rpcPic = *(iterPic++);
+      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getAssociatedIRAPPOC() && this->getAssociatedIRAPPOC() == this->getPOC()+1)
+      {
+        pcRPS->setDeltaPOC(k, 1);
+        pcRPS->setUsed(k, true);
+        nrOfPositivePictures++;
+        k ++;
+        useNewRPS = true;
+      }
+    }
+  }
+#endif
   pcRPS->setNumberOfNegativePictures(nrOfNegativePictures);
   pcRPS->setNumberOfPositivePictures(nrOfPositivePictures);
@@ -1559,5 +1706,9 @@
   // inter RPS prediction with.  Here we just use the reference used by pReferencePictureSet.
   // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled.
-  if (!pReferencePictureSet->getInterRPSPrediction())
+  if (!pReferencePictureSet->getInterRPSPrediction()
+#if EFFICIENT_FIELD_IRAP
+    || useNewRPS
+#endif
+    )
   {
     pcRPS->setInterRPSPrediction(false);
@@ -1712,4 +1863,8 @@
 #endif
 {
+#if H_MV_HLS_8_SYN_Q0041_03
+  m_vpsBaseLayerInternalFlag = true; 
+#endif
+
   for( Int i = 0; i < MAX_TLAYER; i++)
   {
@@ -1728,10 +1883,15 @@
   m_vpsNumProfileTierLevelMinus1 = -1; 
     
-  m_numAddOutputLayerSets              = -1;   
-  m_defaultTargetOutputLayerIdc     = 0; 
+#if H_MV_HLS_8_SYN_39_19
+  m_numAddLayerSets              = 0;   
+  m_numAddOlss                   = 0; 
+#else
+  m_numAddLayerSets              = -1;   
+#endif
+  m_defaultOutputLayerIdc     = 0; 
   
   for ( Int i = 0; i < MAX_VPS_OUTPUTLAYER_SETS; i++)
   {
-    m_outputLayerSetIdxMinus1[i]  = -1; 
+    m_layerSetIdxForOlsMinus1[i]  = -1; 
     m_profileLevelTierIdx[i]      = 0; 
     for ( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++)
@@ -1741,8 +1901,15 @@
     m_altOutputLayerFlag[ i ]       = false; 
   }
+
+#if H_MV_HLS_8_PMS_Q0195_20
+  m_repFormatIdxPresentFlag = false; 
+#endif
   m_maxOneActiveRefLayerFlag = false; 
   m_directDepTypeLenMinus2   = 0;         
   
 
+#if H_MV_HLS_8_RPS_Q0100_36
+  m_vpsExtensionFlag = true; 
+#endif
   m_avcBaseLayerFlag = false;
   m_vpsNonVuiExtensionLength = 0;
@@ -1760,5 +1927,5 @@
   {
     m_vpsProfilePresentFlag   [i] = false;
-    m_outputLayerSetIdxMinus1       [i] = 0;
+    m_layerSetIdxForOlsMinus1       [i] = 0;
     for( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++ )
     {
@@ -1864,4 +2031,12 @@
     assert( getLayerIdInNuh( layer ) > getLayerIdInNuh( layer -1 ) );
   }
+
+
+#if H_MV_HLS_8_PMS_Q0195_20
+  //The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
+  assert( getVpsNumRepFormatsMinus1() >= 0 ); 
+  assert( getVpsNumRepFormatsMinus1() <= 255 ); 
+#endif
+
   return true; 
 }
@@ -1907,4 +2082,72 @@
     }
   }
+
+#if H_MV_HLS_8
+  for (Int i = 0 ; i < MAX_NUM_LAYER_IDS; i++ )
+  {
+    m_numRefLayers[i] = 0; 
+  }
+
+  for (Int currLayerId = 0; currLayerId <= 62; currLayerId++ ) 
+  {
+    for (Int i = 0 ; i < MAX_NUM_LAYER_IDS; i++ )
+    {
+      m_recursiveRefLayerFlag[currLayerId][i] = 0; 
+    }
+  }
+
+
+  for( Int i = 0; i  <=  getMaxLayersMinus1(); i++ )
+  {
+    Int iNuhLId = getLayerIdInNuh( i );
+    xSetRefLayerFlags( iNuhLId );
+    for( Int j = 0; j < 63; j++ )
+    {
+      m_numRefLayers[ iNuhLId ]  +=  m_recursiveRefLayerFlag[ iNuhLId ][ j ];
+    }
+  }
+
+
+  for( Int i = 0; i <= getMaxLayersMinus1(); i++ )  // Bug in spec "<" instead of "<=" 
+  {
+    Int iNuhLId = getLayerIdInNuh( i );
+    Int predIdx = 0;
+    for( Int j = iNuhLId + 1; j < 63; j++ )
+    {
+      if( m_recursiveRefLayerFlag[ j ][ iNuhLId ] )
+      {
+        m_predictedLayerId[ iNuhLId ][ predIdx++ ] = j;
+      }
+    }
+    m_numPredictedLayers[ iNuhLId ] = predIdx;
+  }
+  
+  Bool countedLayerIdxFlag[ MAX_NUM_LAYERS ]; 
+  for( Int i = 0; i  <=  getMaxLayersMinus1(); i++ )
+  {
+    countedLayerIdxFlag[ i ] = 0;
+  }
+ 
+  for( Int i = 0, k = 0; i  <=  getMaxLayersMinus1(); i++ )
+  {
+    Int iNuhLId = getLayerIdInNuh( i );
+    if( m_numDirectRefLayers[ iNuhLId ]  ==  0 )
+    {
+      m_treePartitionLayerIdList[ k ][ 0 ] = iNuhLId;
+      m_numLayersInTreePartition[ k ]      = 1;
+      for( Int j = 0; j < m_numPredictedLayers[ iNuhLId ]; j++ )  
+      {
+        if( !countedLayerIdxFlag[ getLayerIdInVps( m_predictedLayerId[ iNuhLId ][ j ] ) ] )    
+        {
+          m_treePartitionLayerIdList[ k ][ m_numLayersInTreePartition[ k ] ] = m_predictedLayerId[ iNuhLId ][ j ];
+          m_numLayersInTreePartition[ k ]++;
+          countedLayerIdxFlag[ getLayerIdInVps( m_predictedLayerId[ iNuhLId ][ j ] ) ] = 1;
+        }
+      }
+      k++;
+    }
+    m_numIndependentLayers = k;
+  }
+#endif
 }
 
@@ -1936,6 +2179,7 @@
     }
   }
+#if !BUG_FIX_TK65
   assert( foundLayerIdinNuh != -1 ); 
-
+#endif
   return foundLayerIdinNuh;
 }
@@ -2070,5 +2314,9 @@
 Int    TComVPS::getNumOutputLayerSets() 
 {
-  return getNumAddOutputLayerSets() + getVpsNumLayerSetsMinus1() + 1; 
+#if H_MV_HLS_8_SYN_39_19
+  return getNumAddOlss() + getNumLayerSets(); 
+#else
+  return getNumAddLayerSets() + getVpsNumLayerSetsMinus1() + 1; 
+#endif
 }
 
@@ -2126,5 +2374,5 @@
 Void TComVPS::deriveTargetLayerIdList( Int i )
 {  
-  Int lsIdx = getLayerSetIdxForOutputLayerSet( i );     
+  Int lsIdx = olsIdxToLsIdx( i );     
   
   for( Int j = 0; j < getNumLayersInIdList( lsIdx ); j++ )
@@ -2136,4 +2384,7 @@
     }
   }  
+#if H_MV_HLS_8_PMS_Q0165_18
+  assert( getNumOutputLayersInOutputLayerSet( i ) > 0 ); 
+#endif
 }
 
@@ -2141,5 +2392,5 @@
 {
   Bool outputLayerFlag; 
-  switch ( getDefaultTargetOutputLayerIdc( ) )
+  switch ( getDefaultOutputLayerIdc( ) )
   {
   case 0:
@@ -2147,5 +2398,5 @@
     break; 
   case 1:
-    outputLayerFlag = ( j == m_layerSetLayerIdList[ getLayerSetIdxForOutputLayerSet( i ) ].size() - 1 );  
+    outputLayerFlag = ( j == m_layerSetLayerIdList[ olsIdxToLsIdx( i ) ].size() - 1 );  
     break;
   case 2:
@@ -2169,13 +2420,43 @@
 {
   Int maxSLMinus1 = 0; 
-  Int optLsIdx    = getLayerSetIdxForOutputLayerSet( i );
+#if H_MV_HLS_8_MIS_Q0102_30
+  for( Int k = 0; k < getNumLayersInIdList( i ); k++ )
+  {
+    Int lId = m_layerSetLayerIdList[i][k];
+#else  
+  Int optLsIdx    = olsIdxToLsIdx( i );
+
   for( Int k = 0; k < getNumLayersInIdList( optLsIdx ); k++ )
   {
     Int lId = m_layerSetLayerIdList[optLsIdx][k];
+#endif
     maxSLMinus1 = std::max( maxSLMinus1, getSubLayersVpsMaxMinus1( getLayerIdInVps( lId ) ));
   }
   return maxSLMinus1;
 }
-
+#if H_MV_HLS_8_RPS_Q0100_36
+Void TComVPS::inferDbpSizeLayerSetZero( TComSPS* sps, Bool encoder )
+{
+  for( Int j = 0; j <= getMaxSubLayersInLayerSetMinus1( 0 ); j++ )
+  {
+    Int maxDecPicBufferingMinus1 = sps->getMaxDecPicBuffering( j ) - 1; 
+    Int numReorderPics           = sps->getNumReorderPics    ( j ); 
+    Int maxLatencyIncreasePlus1  = sps->getMaxLatencyIncrease( j ); 
+
+    if ( encoder )
+    {
+      assert( getDpbSize()->getMaxVpsDecPicBufferingMinus1(0, 0, j ) == maxDecPicBufferingMinus1 );
+      assert( getDpbSize()->getMaxVpsNumReorderPics       (0,    j ) == numReorderPics           );
+      assert( getDpbSize()->getMaxVpsLatencyIncreasePlus1 (0,    j ) == maxLatencyIncreasePlus1  );
+    }
+    else
+    {
+      getDpbSize()->setMaxVpsDecPicBufferingMinus1(0, 0, j, maxDecPicBufferingMinus1 );
+      getDpbSize()->setMaxVpsNumReorderPics       (0,    j, numReorderPics           );
+      getDpbSize()->setMaxVpsLatencyIncreasePlus1 (0,    j, maxLatencyIncreasePlus1  );        
+    }     
+  }
+}
+#endif
 #endif // H_MV
 
@@ -2249,9 +2530,21 @@
   ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
 #if H_MV
-  m_spsExtensionFlag = false; 
+#if !H_MV_HLS_8_SPS_NODOC_48
+  m_spsExtensionPresentFlag = false; 
   for( Int i = 0; i < PS_EX_T_MAX_NUM; i++ ) 
   {
     m_spsExtensionTypeFlag[ i ] = false;
   }
+#else 
+  m_spsRangeExtensionsFlag     = false;
+  m_spsMultilayerExtensionFlag = false;
+#if H_3D
+  m_spsExtension5bits          = 0;
+  m_sps3dExtensionFlag         = false; 
+#else
+  m_spsExtension6bits          = 0;
+#endif
+#endif
+
   m_numScaledRefLayerOffsets = 0; 
 
@@ -2433,8 +2726,19 @@
 
 #if H_MV
+#if H_MV_HLS_8_SPS_NODOC_48
+  m_ppsRangeExtensionsFlag     = false;
+  m_ppsMultilayerExtensionFlag = false;
+#if !H_3D
+  m_ppsExtension6bits          = 0;
+#else
+  m_pps3dExtensionFlag         = false;
+  m_ppsExtension5bits          = 0;
+#endif
+#else
   for( Int i = 0; i < PS_EX_T_MAX_NUM; i++ ) 
   {
     m_ppsExtensionTypeFlag[ i ] = false;
   }
+#endif
 #endif
 }
@@ -2962,5 +3266,5 @@
 Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 )
 {
-  // Mark as shortterm 
+  // Mark as short-term 
   for ( Int i = 0; i < refPicSetInterLayer0.size(); i++ ) 
   {
@@ -2974,4 +3278,6 @@
 
 }
+
+#if !H_MV_HLS_8_DBP_NODOC_42
 Void TComSlice::markIvRefPicsAsUnused( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc )
 {
@@ -3028,5 +3334,5 @@
   }
 }
-
+#endif
 Void TComSlice::printRefPicList()
 {  
@@ -3045,8 +3351,12 @@
 Void TComSlice::markCurrPic( TComPic* currPic )
 {
+
+#if !H_MV_HLS_8_DBP_NODOC_42
   if ( !currPic->getSlice(0)->getDiscardableFlag() )
   {
+#endif
     currPic->getSlice(0)->setReferenced( true ) ; 
     currPic->setIsLongTerm( false ); 
+#if !H_MV_HLS_8_DBP_NODOC_42
   }
   else
@@ -3054,4 +3364,10 @@
     currPic->getSlice(0)->setReferenced( false ) ; 
   }
+#endif
+
+#if H_MV_HLS_7_VPS_P0300_27
+  currPic->setReconMark( true );
+  currPic->setPicOutputFlag( currPic->getSlice(0)->getPicOutputFlag() );
+#endif
 }
 
@@ -3087,6 +3403,11 @@
   Int refLayerIdx = vps->getLayerIdInVps( vps->getRefLayerId( getLayerId(), i ) ); 
 
+#if H_MV_HLS_8_RPS_Q0060_17
+  Bool refLayerPicFlag = ( vps->getSubLayersVpsMaxMinus1( refLayerIdx ) >=  getTLayer() )  && ( getTLayer() == 0  ) &&
+    ( vps->getMaxTidIlRefPicsPlus1( refLayerIdx, vps->getLayerIdInVps( getLayerId() )) > getTLayer() ); 
+#else
   Bool refLayerPicFlag = ( vps->getSubLayersVpsMaxMinus1( refLayerIdx ) >=  getTLayer() )  && 
     ( vps->getMaxTidIlRefPicsPlus1( refLayerIdx, vps->getLayerIdInVps( getLayerId() )) > getTLayer() ); 
+#endif
 
   return refLayerPicFlag;       
@@ -3969,4 +4290,43 @@
     }
   }
+
+  // ---------------
+  // To be added: 
+  // When vps_base_layer_internal_flag is equal to 0 and layer_in_bsp_flag[ h ][ i ][ 0 ] is equal to 1 for any value of h in the 
+  // range of 1 to vps_num_layer_sets_minus1, inclusive, and any value of i in the range of 0 to num_bitstream_partitions[ h ] - 1, 
+  // inclusive, the value of layer_in_bsp_flag[ h ][ i ][ j ] for at least one value of j in the range of 1 to 
+  // NumLayersInIdList[ h ] - 1, inclusive, shall be equal to 1.
+  // ---------------
+
+
+  // When num_bitstream_partitions[ h ] is equal to 1 for any value of h in the range 1 to vps_num_layer_set_minus1, inclusive, 
+  // the value of layer_in_bsp_flag[ h ][ 0 ][ j ] should be equal to 0 for at least one value of j in the range 0 to 
+  // NumLayersInIdList[ h ] − 1, inclusive. 
+
+
+  if ( getNumBitstreamPartitions( h ) == 1 )
+  {
+    Bool atLeastOneZero = false; 
+    for ( Int j = 0; j <= vps->getNumLayersInIdList( h ) - 1; j++ )
+    {
+      atLeastOneZero = atLeastOneZero || !getLayerInBspFlag( h, 0, j ); 
+    }    
+    assert( atLeastOneZero ); 
+  }
+
+  
+  // For any value of h in the range 1 to vps_num_layer_set_minus1, inclusive, the value of layer_in_bsp_flag[ h ][ i ][ j ] 
+  // shall be equal to 1 for at most one value of i in the range of 0 to num_bitstream_partitions[ h ] − 1, inclusive. 
+
+  for ( Int j = 0; j <= vps->getNumLayersInIdList( h ) - 1; j++ )
+  {
+    Int numLayerInBsp = 0; 
+    for ( Int i = 0; i <= getNumBitstreamPartitions( h ) - 1; i++ )
+    {
+      numLayerInBsp += ( getLayerInBspFlag( h, i, j ) ? 1 : 0 );  
+    }    
+    assert( numLayerInBsp <= 1 ); 
+  }
+
 }
 
Index: trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.h	(revision 951)
+++ trunk/source/Lib/TLibCommon/TComSlice.h	(revision 964)
@@ -54,4 +54,7 @@
 class TComPicLists; 
 class TComVPS; 
+#if H_MV_HLS_8_RPS_Q0100_36
+class TComSPS; 
+#endif
 #endif
 // ====================================================================================================================
@@ -126,4 +129,20 @@
   Void sortDeltaPOC();
   Void printDeltaPOC();
+
+#if H_MV_HLS_8_RPS_Q0100_36
+  Void checkMaxNumPics( Bool vpsExtensionFlag, Int maxNumPics, Int nuhLayerId, Int spsMaxDecPicBufferingMinus1 )
+  {
+    assert( getNumberOfPictures() >= 0 ); 
+    if ( nuhLayerId == 0 )
+    {
+      assert( getNumberOfPictures() <= spsMaxDecPicBufferingMinus1 ); 
+    }
+
+    if ( vpsExtensionFlag )
+    {
+      assert( getNumberOfPictures() <= maxNumPics );
+    }
+  }
+#endif
 };
 
@@ -231,7 +250,7 @@
 {
   ProfileTierLevel m_generalPTL;
-  ProfileTierLevel m_subLayerPTL[6];      // max. value of max_sub_layers_minus1 is 6
-  Bool m_subLayerProfilePresentFlag[6];
-  Bool m_subLayerLevelPresentFlag[6];
+  ProfileTierLevel m_subLayerPTL    [MAX_TLAYER-1];      // max. value of max_sub_layers_minus1 is MAX_TLAYER-1 (= 6)
+  Bool m_subLayerProfilePresentFlag [MAX_TLAYER-1];
+  Bool m_subLayerLevelPresentFlag   [MAX_TLAYER-1];
 
 public:
@@ -436,5 +455,5 @@
   Int  m_numBitstreamPartitions[MAX_VPS_OP_SETS_PLUS1];
   Bool m_layerInBspFlag[MAX_VPS_OP_SETS_PLUS1][MAX_NUM_BSP_HRD_PARAMETERS][MAX_NUM_LAYERS];
-  Int  m_numBspSchedCombinations[MAX_VPS_OP_SETS_PLUS1];
+  Int  m_numBspSchedCombinationsMinus1[MAX_VPS_OP_SETS_PLUS1];
   Int  m_bspCombHrdIdx[MAX_VPS_OP_SETS_PLUS1][MAX_NUM_BSP_HRD_PARAMETERS][MAX_NUM_BSP_SCHED_COMBINATION];
   Int  m_bspCombSchedIdx[MAX_VPS_OP_SETS_PLUS1][MAX_NUM_BSP_HRD_PARAMETERS][MAX_NUM_BSP_SCHED_COMBINATION];
@@ -455,9 +474,24 @@
   Void checkLayerInBspFlag ( TComVPS* vps, Int h );  
 
-  Void setNumBspSchedCombinations( Int h, Int  val ) { m_numBspSchedCombinations[h] = val; } 
-  Int  getNumBspSchedCombinations( Int h ) { return m_numBspSchedCombinations[h]; } 
+  Void setNumBspSchedCombinationsMinus1( Int h, Int  val ) { m_numBspSchedCombinationsMinus1[h] = val; } 
+  Int  getNumBspSchedCombinationsMinus1( Int h ) { return m_numBspSchedCombinationsMinus1[h]; } 
 
   Void setBspCombHrdIdx( Int h, Int i, Int j, Int  val ) { m_bspCombHrdIdx[h][i][j] = val; } 
   Int  getBspCombHrdIdx( Int h, Int i, Int j ) { return m_bspCombHrdIdx[h][i][j]; } 
+#if H_MV_HLS_8_HRD_Q0101_04
+  Int  getBspCombHrdIdxLen() { return gCeilLog2( getVpsNumBspHrdParametersMinus1() + 1);  }; 
+  Void checkBspCombHrdAndShedIdx( TComVPS* vps, Int h, Int i, Int j )  
+  {
+    // bsp_comb_hrd_idx
+    assert( getBspCombSchedIdx(h, i, j ) >= 0 );
+    assert( getBspCombSchedIdx(h, i, j ) <= getVpsNumBspHrdParametersMinus1() );
+
+    // bsp_comb_sched_idx
+    assert( getBspCombSchedIdx(h, i, j ) >= 0 );
+
+    //* This check needs to activated,  when HighestTid is available here    
+    //  assert(  getBspCombSchedIdx(h, i, j ) <= vps->getHrdParameters( getBspCombHrdIdx( h, i, j ) )->getCpbCntMinus1( highestTid ) );
+  }
+#endif
 
   Void setBspCombSchedIdx( Int h, Int i, Int j, Int  val ) { m_bspCombSchedIdx[h][i][j] = val; } 
@@ -636,7 +670,4 @@
   Int   m_maxVpsDecPicBufferingMinus1[MAX_VPS_OUTPUTLAYER_SETS][MAX_NUM_LAYER_IDS][MAX_TLAYER];; 
   Int   m_maxVpsNumReorderPics       [MAX_VPS_OUTPUTLAYER_SETS][MAX_TLAYER];
-#if H_MV_HLS7_GEN
-  Int  m_maxVpsLayerDecPicBuffMinus1[TO_BE_SPECIFIED][TO_BE_SPECIFIED][TO_BE_SPECIFIED];
-#endif
   Int   m_maxVpsLatencyIncreasePlus1 [MAX_VPS_OUTPUTLAYER_SETS][MAX_TLAYER];
 
@@ -655,8 +686,5 @@
   Void setMaxVpsNumReorderPics( Int i, Int j, Int  val ) { m_maxVpsNumReorderPics[i][j] = val; } 
   Int  getMaxVpsNumReorderPics( Int i, Int j ) { return m_maxVpsNumReorderPics[i][j]; } 
-#if H_MV_HLS7_GEN
-  Void setMaxVpsLayerDecPicBuffMinus1( Int i, Int k, Int j, Int  val ) { m_maxVpsLayerDecPicBuffMinus1[i][k][j] = val; } 
-  Int  getMaxVpsLayerDecPicBuffMinus1( Int i, Int k, Int j ) { return m_maxVpsLayerDecPicBuffMinus1[i][k][j]; } 
-#endif
+
   Void setMaxVpsLatencyIncreasePlus1( Int i, Int j, Int  val ) { m_maxVpsLatencyIncreasePlus1[i][j] = val; } 
   Int  getMaxVpsLatencyIncreasePlus1( Int i, Int j ) { return m_maxVpsLatencyIncreasePlus1[i][j]; } 
@@ -667,4 +695,8 @@
 private:
   Int         m_VPSId;
+#if H_MV_HLS_8_SYN_Q0041_03
+  Bool        m_vpsBaseLayerInternalFlag;
+#endif
+
   UInt        m_uiMaxTLayers;
 
@@ -704,4 +736,7 @@
   TimingInfo  m_timingInfo;
 #if H_MV
+  #if H_MV_HLS_8_RPS_Q0100_36
+  Bool        m_vpsExtensionFlag;
+#endif
   /// VPS EXTENSION SYNTAX ELEMENTS
   Bool        m_avcBaseLayerFlag;
@@ -725,12 +760,17 @@
   Bool        m_vpsProfilePresentFlag    [MAX_VPS_OP_SETS_PLUS1];
 
-  Int         m_numAddOutputLayerSets;    
-  Int         m_defaultTargetOutputLayerIdc;
-
-  Int         m_outputLayerSetIdxMinus1  [MAX_VPS_OUTPUTLAYER_SETS];  
+  Int         m_numAddLayerSets;    
+#if H_MV_HLS_8_SYN_39_19
+  Int         m_highestLayerIdxPlus1     [MAX_VPS_ADD_OUTPUT_LAYER_SETS][MAX_NUM_LAYERS];
+  Int         m_numAddOlss;
+#endif
+  Int         m_defaultOutputLayerIdc;
+
+  Int         m_layerSetIdxForOlsMinus1  [MAX_VPS_OUTPUTLAYER_SETS];  
   Bool        m_outputLayerFlag          [MAX_VPS_OUTPUTLAYER_SETS][MAX_VPS_NUH_LAYER_ID_PLUS1];
   Int         m_profileLevelTierIdx      [MAX_VPS_OUTPUTLAYER_SETS ];
   Bool        m_altOutputLayerFlag       [MAX_VPS_OUTPUTLAYER_SETS];
   Bool        m_repFormatIdxPresentFlag;
+
   Int         m_vpsNumRepFormatsMinus1;
   Int         m_vpsRepFormatIdx          [MAX_NUM_LAYERS];
@@ -762,4 +802,14 @@
   Int         m_refLayerId               [MAX_NUM_LAYERS][MAX_NUM_LAYERS];  
 
+#if H_MV_HLS_8
+  Int         m_numRefLayers             [MAX_NUM_LAYER_IDS]; 
+  Int         m_numPredictedLayers       [MAX_NUM_LAYERS]; 
+  Int         m_predictedLayerId         [MAX_NUM_LAYERS][MAX_NUM_LAYER_IDS];
+  Int         m_numIndependentLayers; 
+  Int         m_numLayersInTreePartition [MAX_NUM_LAYER_IDS];
+  Int         m_treePartitionLayerIdList [MAX_NUM_LAYERS][MAX_NUM_LAYER_IDS];
+  Bool        m_recursiveRefLayerFlag    [MAX_NUM_LAYER_IDS][MAX_NUM_LAYER_IDS]; 
+#else
+
   Int         m_numSamplePredRefLayers   [MAX_NUM_LAYERS];
   Bool        m_samplePredEnabledFlag    [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
@@ -769,4 +819,5 @@
   Bool        m_motionPredEnabledFlag    [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
   Int         m_motionPredRefLayerId     [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+#endif
   Int         m_viewIndex                [MAX_NUM_LAYERS   ];
   
@@ -777,5 +828,19 @@
 
   Int         xGetDimBitOffset( Int j );
-  
+
+#if H_MV_HLS_8
+  Void xSetRefLayerFlags( Int currLayerId )
+  { 
+    for( Int j = 0; j < getNumDirectRefLayers( currLayerId ); j++ )
+    {
+      Int refLayerId = m_refLayerId[ currLayerId ][ j ];
+      m_recursiveRefLayerFlag[ currLayerId ][ refLayerId ] = 1;
+      for( Int k = 0; k < MAX_NUM_LAYER_IDS; k++ )
+      {
+        m_recursiveRefLayerFlag[ currLayerId ][ k ] = m_recursiveRefLayerFlag[ currLayerId ][ k ]  ||  m_recursiveRefLayerFlag[ refLayerId ][ k ];
+      }
+    }
+  }
+#endif
   // VPS EXTENSION 2 SYNTAX ELEMENTS
 #if H_3D_ARP
@@ -837,4 +902,9 @@
   Void    setVPSId       (Int i)              { m_VPSId = i;             }
 
+#if H_MV_HLS_8_SYN_Q0041_03
+  Void    setVpsBaseLayerInternalFlag( Bool flag ) { m_vpsBaseLayerInternalFlag = flag; } 
+  Bool    getVpsBaseLayerInternalFlag(  )          { return m_vpsBaseLayerInternalFlag; } 
+#endif
+
   UInt    getMaxTLayers  ()                   { return m_uiMaxTLayers;   }
   Void    setMaxTLayers  (UInt t)             { m_uiMaxTLayers = t; }
@@ -887,7 +957,13 @@
   TimingInfo* getTimingInfo() { return &m_timingInfo; }
 #if H_MV
+
+#if H_MV_HLS_8_RPS_Q0100_36
+  Void    setVpsExtensionFlag( Bool flag )                                 { m_vpsExtensionFlag = flag; } 
+  Bool    getVpsExtensionFlag(  )                                          { return m_vpsExtensionFlag; } 
+#endif
+#if !H_MV_HLS_8_SYN_Q0041_03
   Void    setAvcBaseLayerFlag( Bool val )                                  { m_avcBaseLayerFlag = val;  }
   Bool    getAvcBaseLayerFlag()                                            { return m_avcBaseLayerFlag; } 
-
+#endif 
   Void    setVpsNonVuiExtensionLength( Int  val )                          { m_vpsNonVuiExtensionLength = val; } 
   Int     getVpsNonVuiExtensionLength(  )                                  { return m_vpsNonVuiExtensionLength; } 
@@ -947,12 +1023,20 @@
   Bool    getVpsProfilePresentFlag( Int idx )                              { return m_vpsProfilePresentFlag[idx]; }
 
-  Void    setNumAddOutputLayerSets( Int val )                              { m_numAddOutputLayerSets = val; } 
-  Int     getNumAddOutputLayerSets( )                                      { return m_numAddOutputLayerSets; } 
-  
-  Void    setDefaultTargetOutputLayerIdc( Int  val )                       { m_defaultTargetOutputLayerIdc = val; } 
-  Int     getDefaultTargetOutputLayerIdc(  )                               { return m_defaultTargetOutputLayerIdc; }   
-  
-  Void    setOutputLayerSetIdxMinus1( Int outLayerSetIdx, Int val )        { m_outputLayerSetIdxMinus1[ outLayerSetIdx ]  = val; } 
-  Int     getOutputLayerSetIdxMinus1( Int outLayerSetIdx )                 { return m_outputLayerSetIdxMinus1[ outLayerSetIdx ]; } 
+  Void    setNumAddLayerSets( Int val )                                    { m_numAddLayerSets = val; } 
+  Int     getNumAddLayerSets( )                                            { return m_numAddLayerSets; } 
+  
+#if H_MV_HLS_8_SYN_39_19
+  Void    setHighestLayerIdxPlus1( Int i, Int j, Int  val )                { m_highestLayerIdxPlus1[i][j] = val; } 
+  Int     getHighestLayerIdxPlus1( Int i, Int j )                          { return m_highestLayerIdxPlus1[i][j]; } 
+
+  Void    setNumAddOlss( Int  val )                                        { m_numAddOlss = val; } 
+  Int     getNumAddOlss(  )                                                { return m_numAddOlss; } 
+#endif
+
+  Void    setDefaultOutputLayerIdc( Int  val )                             { m_defaultOutputLayerIdc = val; } 
+  Int     getDefaultOutputLayerIdc(  )                                     { return m_defaultOutputLayerIdc; }   
+  
+  Void    setLayerSetIdxForOlsMinus1( Int outLayerSetIdx, Int val )        { m_layerSetIdxForOlsMinus1[ outLayerSetIdx ]  = val; } 
+  Int     getLayerSetIdxForOlsMinus1( Int outLayerSetIdx )                 { return m_layerSetIdxForOlsMinus1[ outLayerSetIdx ]; } 
 
   Void    setOutputLayerFlag( Int outLayerSetIdx, Int i, Bool flag )       { m_outputLayerFlag[ outLayerSetIdx ][ i ] = flag; } 
@@ -975,4 +1059,8 @@
   Void    setVpsRepFormatIdx( Int i, Int  val )                            { m_vpsRepFormatIdx[i] = val; } 
   Int     getVpsRepFormatIdx( Int i )                                      { return m_vpsRepFormatIdx[i]; } 
+
+#if H_MV_HLS_8_PMS_Q0195_20
+  Int     inferVpsRepFormatIdx( Int i )                                    { return std::min( i, getVpsNumRepFormatsMinus1()  );  }
+#endif
 
   Void    setRepFormat( Int i, TComRepFormat* val )                        { m_repFormat[i] = val;  }
@@ -989,4 +1077,8 @@
   Void    setDpbSize( TComDpbSize* val )                                   { assert( m_dpbSize != 0 ); m_dpbSize = val; } 
   TComDpbSize* getDpbSize( )                                               { return m_dpbSize;} 
+#if H_MV_HLS_8_RPS_Q0100_36
+  Void    inferDbpSizeLayerSetZero( TComSPS* sps, Bool encoder );
+#endif
+
 
   Void    setPocLsbNotPresentFlag( Int i, Bool flag )                      { m_pocLsbNotPresentFlag[i] = flag; } 
@@ -1023,4 +1115,19 @@
   Int     getNumDirectRefLayers( Int layerIdInNuh )                        { return m_numDirectRefLayers[ layerIdInNuh ];  };                               
   Int     getRefLayerId        ( Int layerIdInNuh, Int idx );; 
+
+#if H_MV_HLS_8
+  Int     getNumRefLayers            ( Int i )        { return m_numRefLayers[i]; } 
+  Int     getNumPredictedLayers      ( Int i )        { return m_numPredictedLayers[i]; } 
+  Int     getPredictedLayerId        ( Int i, Int j ) { return m_predictedLayerId[i][j]; } 
+  Int     getNumIndependentLayers    (  )             { return m_numIndependentLayers; } 
+  Int     getNumLayersInTreePartition( Int i )        { return m_numLayersInTreePartition[i]; } 
+  Int     getTreePartitionLayerIdList( Int i, Int j ) { return m_treePartitionLayerIdList[i][j]; } 
+  Bool    getRecursiveRefLayerFlag   ( Int i, Int j ) { return m_recursiveRefLayerFlag[i][j]; } 
+
+#endif
+
+#if H_MV_HLS_8_SYN_39_19
+  Int     getNumLayerSets( )                                               { return getVpsNumLayerSetsMinus1() + 1 + getNumAddLayerSets();  };  
+#endif
   Bool    checkVPSExtensionSyntax(); 
   Int     scalTypeToScalIdx   ( ScalabilityType scalType );
@@ -1030,11 +1137,16 @@
 
   Int     getNumLayersInIdList ( Int lsIdx );
+#if H_MV_HLS_8_RPS_Q0100_36
+  Int     getLayerSetLayerIdList(Int lsIdx, Int j )                       { return m_layerSetLayerIdList[ lsIdx ][ j ]; }; 
+#endif
 
   Int     getNumOutputLayerSets() ;   
+#if !H_MV_HLS_8_DBP_NODOC_42
   Int     getNumSubDpbs( Int i )                                           { return getNumLayersInIdList( i ); };  
+#endif
   Bool    isOutputLayer( Int outLayerSetIdx, Int layerIdInNuh );   
   Void    deriveLayerSetLayerIdList();
 
-  Int     getLayerSetIdxForOutputLayerSet( Int i )                         { return ( i <= getVpsNumLayerSetsMinus1() ) ? i  : getOutputLayerSetIdxMinus1( i ) + 1 ; };
+  Int     olsIdxToLsIdx( Int i )                                           { return ( i <= getVpsNumLayerSetsMinus1() ) ? i  : getLayerSetIdxForOlsMinus1( i ) + 1 ; };
 
   Void    initTargetLayerIdLists  ( );
@@ -1048,4 +1160,23 @@
 
   Int     getMaxSubLayersInLayerSetMinus1( Int i );
+
+#if H_MV_HLS_8_SYN_39_19
+  Int     getHighestLayerIdxPlus1Len( Int j )                                   { return gCeilLog2( getNumLayersInTreePartition( j ) + 1 );   }; 
+#endif
+
+  
+#if H_MV_HLS_7_VPS_P0300_27
+  Bool     getAltOutputLayerFlagVar( Int i )
+  {  // Semantics variable not syntax element !
+
+    Bool altOptLayerFlag = false;     
+    if ( i > 0 && getNumOutputLayersInOutputLayerSet( i ) == 1 && 
+      getNumDirectRefLayers( getOlsHighestOutputLayerId( i ) ) > 0 )
+    {
+      altOptLayerFlag = getAltOutputLayerFlag( i ); 
+    }
+    return altOptLayerFlag; 
+  };
+#endif
 
   // inference
@@ -1055,4 +1186,25 @@
   // helpers
   Bool    getInDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Int depth = 0 );
+#if H_MV_HLS_8_RPS_Q0100_36
+  Int     getMaxNumPics( Int layerId )
+  {    
+    Int maxNumPics = MAX_INT; 
+    for( Int olsIdx = 0; olsIdx < getNumOutputLayerSets(); olsIdx++)
+    {
+      Int lsIdx = olsIdxToLsIdx( olsIdx ); 
+      for( Int j = 0; j < getNumLayersInIdList( lsIdx ); j++ )
+      {
+        if( getLayerSetLayerIdList(lsIdx, j ) ==  layerId )
+        {
+          Int maxSL = getMaxSubLayersInLayerSetMinus1( lsIdx ); 
+          maxNumPics = std::min( maxNumPics, getDpbSize()->getMaxVpsDecPicBufferingMinus1( olsIdx , j,  maxSL ) );
+        }
+      }
+    }
+    assert( maxNumPics != MAX_INT ); 
+    return maxNumPics; 
+  }
+#endif
+
   /// VPS EXTENSION 2 SYNTAX ELEMENTS
 #if H_3D  
@@ -1447,4 +1599,5 @@
 
   UInt        m_uiBitsForPOC;
+
   UInt        m_numLongTermRefPicSPS;
   UInt        m_ltRefPicPocLsbSps[33];
@@ -1476,6 +1629,17 @@
   TComVPS*    m_pcVPS; 
   // SPS 
-  Bool        m_spsExtensionFlag; 
-  Bool        m_spsExtensionTypeFlag[PS_EX_T_MAX_NUM];
+  Bool        m_spsExtensionPresentFlag; 
+#if H_MV_HLS_8_SPS_NODOC_48
+  Bool        m_spsRangeExtensionsFlag;
+  Bool        m_spsMultilayerExtensionFlag;
+#if H_3D
+  Bool        m_sps3dExtensionFlag;
+  Int         m_spsExtension5bits;
+#else
+  Int         m_spsExtension6bits;
+#endif
+#else
+  Bool        m_spsExtensionTypeFlag     [PS_EX_T_MAX_NUM];
+#endif
   Bool        m_spsInferScalingListFlag;
   Int         m_spsScalingListRefLayerId;
@@ -1591,4 +1755,7 @@
   UInt      getMaxTLayers()                           { return m_uiMaxTLayers; }
   Void      setMaxTLayers( UInt uiMaxTLayers )        { assert( uiMaxTLayers <= MAX_TLAYER ); m_uiMaxTLayers = uiMaxTLayers; }
+#if H_MV_HLS_8
+  UInt      getSpsMaxSubLayersMinus1()                { return ( m_uiMaxTLayers - 1); }
+#endif
 
   Bool      getTemporalIdNestingFlag()                { return m_bTemporalIdNestingFlag; }
@@ -1622,9 +1789,65 @@
   TComPTL* getPTL()     { return &m_pcPTL; }
 #if H_MV
-  Void setSpsExtensionFlag( Bool flag ) { m_spsExtensionFlag = flag; } 
-  Bool getSpsExtensionFlag( )  { return m_spsExtensionFlag; }
-
-  Void setSpsExtensionTypeFlag( Int i, Bool flag ) { m_spsExtensionTypeFlag[i] = flag; } 
-  Bool getSpsExtensionTypeFlag( Int i ) { return m_spsExtensionTypeFlag[i]; }
+
+#if H_MV_HLS_8_HRD_Q0102_08
+  Void inferSpsMaxDecPicBufferingMinus1( TComVPS* vps, Int targetOptLayerSetIdx, Int currLayerId, Bool encoder )
+  {
+    const std::vector<Int>& targetDecLayerIdList = vps->getTargetDecLayerIdList( vps->olsIdxToLsIdx( targetOptLayerSetIdx )); 
+
+    if (getLayerId() > 0 )
+    {
+      Int layerIdx = 0;         
+      while (layerIdx < (Int) targetDecLayerIdList.size() )
+      {
+        if ( targetDecLayerIdList[layerIdx] == currLayerId )
+        { 
+          break; 
+        }
+        layerIdx++; 
+      }
+
+      assert( layerIdx < (Int) targetDecLayerIdList.size() ); 
+
+      for (Int i = 0; i <= getSpsMaxSubLayersMinus1(); i++ ) 
+      {
+        Int maxDecPicBufferingMinus1 = vps->getDpbSize()->getMaxVpsDecPicBufferingMinus1( targetOptLayerSetIdx, layerIdx, i ) ; 
+
+        if ( encoder )
+        {
+          assert( getMaxDecPicBuffering( i ) - 1 == maxDecPicBufferingMinus1 ); 
+        }
+        else
+        {
+          setMaxDecPicBuffering(i, maxDecPicBufferingMinus1 + 1 ); 
+        }
+      }
+    }    
+  }
+#endif
+
+  Void setSpsExtensionPresentFlag( Bool flag ) { m_spsExtensionPresentFlag = flag; } 
+  Bool getSpsExtensionPresentFlag( )           { return m_spsExtensionPresentFlag; }
+
+#if H_MV_HLS_8_SPS_NODOC_48
+  Void setSpsRangeExtensionsFlag( Bool flag )            { m_spsRangeExtensionsFlag = flag; } 
+  Bool getSpsRangeExtensionsFlag(  )                     { return m_spsRangeExtensionsFlag; } 
+
+  Void setSpsMultilayerExtensionFlag( Bool flag )        { m_spsMultilayerExtensionFlag = flag; } 
+  Bool getSpsMultilayerExtensionFlag( )                  { return m_spsMultilayerExtensionFlag; } 
+#if H_3D
+  Void setSps3dExtensionFlag( Bool flag )                { m_sps3dExtensionFlag = flag; } 
+  Bool getSps3dExtensionFlag(  )                        { return m_sps3dExtensionFlag; } 
+
+  Void setSpsExtension5bits( Int  val )                  { m_spsExtension5bits = val; } 
+  Int  getSpsExtension5bits(  )                          { return m_spsExtension5bits; } 
+#else
+  Void setSpsExtension6bits( Int  val )                  { m_spsExtension6bits = val; } 
+  Int  getSpsExtension6bits(  )                          { return m_spsExtension6bits; } 
+#endif
+#else
+  Void setSpsExtensionTypeFlag( Int i, Bool flag )       { m_spsExtensionTypeFlag[i] = flag; } 
+  Bool getSpsExtensionTypeFlag( Int i )                  { return m_spsExtensionTypeFlag[i]; }
+#endif
+  
   Void      setVPS          ( TComVPS* pcVPS ) { m_pcVPS = pcVPS; }
   TComVPS*  getVPS          () { return m_pcVPS; }
@@ -1665,4 +1888,24 @@
 
   Void inferScalingList( TComSPS* spsSrc );
+
+#if H_MV_HLS_8_RPS_Q0100_36
+  // others
+  Void checkRpsMaxNumPics( TComVPS* vps, Int currLayerId ) 
+  {
+    // In spec, when rps is in SPS, nuh_layer_id of SPS is used instead 
+    // of nuh_layer_id of slice (currLayerId), this seems to be a bug.
+
+    for (Int i = 0; i < getRPSList()->getNumberOfReferencePictureSets(); i++ )
+    {
+      TComReferencePictureSet* rps = getRPSList()->getReferencePictureSet( i ); 
+      if ( !rps->getInterRPSPrediction() )
+      {
+        rps->checkMaxNumPics( vps->getVpsExtensionFlag(), vps->getMaxNumPics( currLayerId ), 
+          getLayerId(), getMaxDecPicBuffering( getSpsMaxSubLayersMinus1() ) - 1 );  
+      }
+    }
+  }
+#endif
+
 #endif
 #if H_3D_QTLPC
@@ -1776,5 +2019,17 @@
   Int  m_ppsScalingListRefLayerId;
 
+#if H_MV_HLS_8_SPS_NODOC_48
+  Bool m_ppsRangeExtensionsFlag;
+  Bool m_ppsMultilayerExtensionFlag;
+#if !H_3D
+  Int  m_ppsExtension6bits;
+#else
+  Bool m_pps3dExtensionFlag;
+  Int  m_ppsExtension5bits;
+#endif
+
+#else
   Bool m_ppsExtensionTypeFlag[PS_EX_T_MAX_NUM];
+#endif
   Bool m_pocResetInfoPresentFlag;
 #endif
@@ -1920,6 +2175,25 @@
   Int  getPpsScalingListRefLayerId(  ) { return m_ppsScalingListRefLayerId; } 
 
+#if H_MV_HLS_8_SPS_NODOC_48
+  Void setPpsRangeExtensionsFlag( Bool flag ) { m_ppsRangeExtensionsFlag = flag; } 
+  Bool getPpsRangeExtensionsFlag(  ) { return m_ppsRangeExtensionsFlag; } 
+
+  Void setPpsMultilayerExtensionFlag( Bool flag ) { m_ppsMultilayerExtensionFlag = flag; } 
+  Bool getPpsMultilayerExtensionFlag(  ) { return m_ppsMultilayerExtensionFlag; } 
+
+#if !H_3D
+  Void setPpsExtension6bits( Int  val ) { m_ppsExtension6bits = val; } 
+  Int  getPpsExtension6bits(  ) { return m_ppsExtension6bits; } 
+#else
+  Void setPps3dExtensionFlag( Bool flag ) { m_pps3dExtensionFlag = flag; } 
+  Bool getPps3dExtensionFlag(  ) { return m_pps3dExtensionFlag; } 
+
+  Void setPpsExtension5bits( Int  val ) { m_ppsExtension5bits = val; } 
+  Int  getPpsExtension5bits(  ) { return m_ppsExtension5bits; } 
+#endif
+#else
   Void setPpsExtensionTypeFlag( Int i, Bool flag ) { m_ppsExtensionTypeFlag[i] = flag; } 
   Bool getPpsExtensionTypeFlag( Int i ) { return m_ppsExtensionTypeFlag[i]; } 
+#endif
 
   Void setPocResetInfoPresentFlag( Bool flag ) { m_pocResetInfoPresentFlag = flag; } 
@@ -1957,4 +2231,7 @@
   Int         m_iPPSId;               ///< picture parameter set ID
   Bool        m_PicOutputFlag;        ///< pic_output_flag 
+#if H_MV_HLS_8_POC_Q0142_32
+  Int         m_slicePicOrderCntLsb;   
+#endif  
   Int         m_iPOC;
 #if H_MV
@@ -2010,4 +2287,10 @@
   UInt        m_colFromL0Flag;  // collocated picture from List0 flag
   
+#if SETTING_NO_OUT_PIC_PRIOR
+  Bool        m_noOutputPriorPicsFlag;
+  Bool        m_noRaslOutputFlag;
+  Bool        m_handleCraAsBlaFlag;
+#endif
+  
   UInt        m_colRefIdx;
   UInt        m_maxNumMergeCand;
@@ -2131,4 +2414,8 @@
   Void      setPicOutputFlag( Bool b )         { m_PicOutputFlag = b;    }
   Bool      getPicOutputFlag()                 { return m_PicOutputFlag; }
+#if H_MV_HLS_8_POC_Q0142_32
+  Void      setSlicePicOrderCntLsb( Int i ) { m_slicePicOrderCntLsb = i; }; 
+  Int       getSlicePicOrderCntLsb(  )      { return m_slicePicOrderCntLsb; }; 
+#endif
   Void      setSaoEnabledFlag(Bool s) {m_saoEnabledFlag =s; }
   Bool      getSaoEnabledFlag() { return m_saoEnabledFlag; }
@@ -2281,15 +2568,33 @@
   Void createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 );
   static Void markIvRefPicsAsShortTerm    ( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 );
-  static Void markCurrPic                 ( TComPic* currPic );; 
+  static Void markCurrPic                 ( TComPic* currPic );
+#if !H_MV_HLS_8_DBP_NODOC_42
   static Void markIvRefPicsAsUnused       ( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc  );
+#endif
   Void        printRefPicList();
 #endif
   Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
   Bool isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic );
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  Int       checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0, Bool bUseRecoveryPoint = false);
+  Void      createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP, Int pocRandomAccess = 0, Bool bUseRecoveryPoint = false);
+#else
   Int       checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0);
   Void      createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP);
+#endif
 
   Void setMaxNumMergeCand               (UInt val )         { m_maxNumMergeCand = val;                    }
   UInt getMaxNumMergeCand               ()                  { return m_maxNumMergeCand;                   }
+
+#if SETTING_NO_OUT_PIC_PRIOR
+  Void setNoOutputPriorPicsFlag              ( Bool val )         { m_noOutputPriorPicsFlag = val;                    }
+  Bool getNoOutputPriorPicsFlag              ()                   { return m_noOutputPriorPicsFlag;                   }
+
+  Void setNoRaslOutputFlag              ( Bool val )         { m_noRaslOutputFlag = val;                    }
+  Bool getNoRaslOutputFlag              ()                   { return m_noRaslOutputFlag;                   }
+
+  Void setHandleCraAsBlaFlag              ( Bool val )         { m_handleCraAsBlaFlag = val;                    }
+  Bool getHandleCraAsBlaFlag              ()                   { return m_handleCraAsBlaFlag;                   }
+#endif
 
   Void setSliceMode                     ( UInt uiMode )     { m_sliceMode = uiMode;                     }
@@ -2433,5 +2738,7 @@
   Void setPocResetIdc( Int  val ) { m_pocResetIdc = val; } 
   Int  getPocResetIdc(  ) { return m_pocResetIdc; } 
-
+#if H_MV_HLS_8_POC_Q0142_32
+  Void checkPocResetIdc( ) { assert( !(getVPS()->getPocLsbNotPresentFlag( getLayerIdInVps() ) )  || !(getSlicePicOrderCntLsb() > 0 ) || !( getPocResetIdc() == 2) ); }  
+#endif
   Void setPocResetPeriodId( Int  val ) { m_pocResetPeriodId = val; } 
   Int  getPocResetPeriodId(  ) { return m_pocResetPeriodId; } 
@@ -2442,4 +2749,7 @@
   Void setPocLsbVal( Int  val ) { m_pocLsbVal = val; } 
   Int  getPocLsbVal(  ) { return m_pocLsbVal; } 
+#if H_MV_HLS_8_POC_Q0142_32
+  Void checkPocLsbVal( ) { assert( !(getVPS()->getPocLsbNotPresentFlag( getLayerIdInVps() ) )  || !getFullPocResetFlag() || ( getPocLsbVal() == 0 ) ); }  
+#endif
 
   Void setPocMsbValPresentFlag( Bool flag ) { m_pocMsbValPresentFlag = flag; } 
@@ -2466,4 +2776,5 @@
 
   // Additional variables derived in slice header semantics 
+
   Int  getNumInterLayerRefPicsMinus1Len( ) { return gCeilLog2(  getVPS()->getNumDirectRefLayers( getLayerId() )); }
   Int  getInterLayerPredLayerIdcLen    ( ) { return gCeilLog2(  getVPS()->getNumDirectRefLayers( getLayerId() )); }
@@ -2483,4 +2794,26 @@
   TComPic* getPicFromRefPicSetInterLayer( Int setIdc, Int layerId );
 
+
+#if H_MV_HLS_8_POC_Q0146_15
+// Inference 
+  Bool inferPocMsbValPresentFlag()
+  {
+    Bool pocMsbValPresentFlag; 
+    if( getSliceSegmentHeaderExtensionLength() == 0 ) 
+    {
+      pocMsbValPresentFlag = false; 
+    }
+    else if ( getPocMsbValRequiredFlag() )
+    {
+      pocMsbValPresentFlag = true; 
+    }
+    else
+    {
+      pocMsbValPresentFlag = false; 
+    }
+
+    return pocMsbValPresentFlag; 
+  }  
+#endif
 #endif
 #if H_3D_DDD
Index: trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/TypeDef.h	(revision 951)
+++ trunk/source/Lib/TLibCommon/TypeDef.h	(revision 964)
@@ -66,5 +66,5 @@
 
 #define NTT_BUG_FIX_TK54    1
-
+#define BUG_FIX_TK65        1
 
 /////////////////////////////////////////////////////////////////////////////////////////
@@ -359,20 +359,91 @@
 #define MPI_SUBPU_DEFAULT_MV_H0077_H0099_H0111_H0133    1
 #endif
+
+#if H_MV
+#define H0044_POC_LSB_NOT_PRESENT        1      ///< JCT3V-H0044: Add constraint checking on the value of poc_reset_idc and poc_lsb_val
+#define H0056_EOS_CHECKS                 1      ///< JCT3V-H0056: Put checks on handling EOS
+#endif
 /////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////   TBD                  //////////////////////////////
 /////////////////////////////////////////////////////////////////////////////////////////
 
+
+#define H_MV_HLS_8                           1 // General changes
+#define H_MV_HLS_7_VPS_P0300_27              1 // Output part only. (VPS/P0300/alt output layer flag) #27 Change alt output layer flag to be signalled within the loop of output layer sets, from JCTVC-P0300-v2. Decision: Adopt. 
+#define MV_FIX_DEP_TYPES                     1
+
+
+#define H_MV_HLS7_GEN                        0  // General changes (not tested)
+
+// POC
 // #define H_MV_HLS_7_POC_P0041_3            0 // (POC/P0041/POC reset) #3 It was remarked that we should require each non-IRAP picture that has discardable_flag equal to 1 to have NUT value indicating that it is a sub-layer non-reference picture. This was agreed. Decision: Adopt (with constraint for discardable_flag as described above) 
 // #define H_MV_HLS_7_POC_P0041_FIXES        0 // (POC/P0041/Fixes) For each non-IRAP picture that has discardable_flag equal to 1 to have NUT value indicating that it is a sub-layer non-reference picture. 
 // #define H_MV_HLS_7_POC_P0056_4            0 // (POC/P0056/layer tree poc) #4 Proposal 1: If the POC reset approach is adopted as the basis for multi-layer POC derivation, it is proposed to derive the POC anchor picture from the previous TID0 picture (that is not a RASL picture, a RADL picture or a sub-layer non-reference picture and not with discardable_flag equal to 1) of  the current layer or any of its reference layer. This is asserted to improve loss resilience and reduce bit rate overhead. Decision: Adopt Proposal 1 (with the suggested modifications Ewith text provided as P0297).
 
-// #define H_MV_HLS_7_SEI_P0133_28           0 // (SEI/P0133/Recovery point SEI) #28 Decision: Adopt change to recover point semantics only (-v3)
-// #define H_MV_HLS_7_SEI_P0123_25           0 // (SEI/P0123/Alpha channel info) #25 Add alpha channel information SEI message Decision: Adopt. Constrain the bit depth indicated to be equal to the coded bit depth of the aux picture. 
-
+
+// OTHERS
 // #define H_MV_HLS_7_HRD_P0138_6            0 // (HRD/P0138/HRD parameters for bitstreams excluding) #6 Decision: Adopt (as revised in updated contribution, with the specification of a flag in the BP SEI (HRD/P0192/sub-DPB) #12 Establish sub-DPBs based on the representation format indicated at the VPS level. It was suggested that the expressed shared capacity limit would need to be less than or equal to the sum of the individual capacity limits. Decision: Adopt as modified. Further study is encouraged on profile/level constraint selections. 
-// #define H_MV_HLS_7_OTHER_P0187_1          0 // (OTHER/P0187/NoOutputOfPriorPicsFlag) #1 Inference of NoOutputOfPriorPicsFlag and proposes to take into account colour format and bit depth for the inference in addition to spatial resolution 
-// #define H_MV_HLS_7_VPS_P0300_27           0 // Output part only. (VPS/P0300/alt output layer flag) #27 Change alt output layer flag to be signalled within the loop of output layer sets, from JCTVC-P0300-v2. Decision: Adopt. 
-
-#define H_MV_HLS7_GEN                        0  // General changes (not tested)
+
+// SEI related
+//#define H_MV_HLS_8_SEI_NODOC_53  0 // #53 (SEI    /NODOC/Added Multiview view position SEI message) Plain copy from AVC.
+//#define H_MV_HLS_8_SEI_NODOC_52  0 // #52 (SEI    /NODOC/Added Multiview acquisition information SEI) Plain copy from AVC. 
+//#define H_MV_HLS_8_SEI_NODOC_51  0 // #51 (SEI    /NODOC/Added Multiview scene information SEI message)
+//#define H_MV_HLS_8_SEI_Q0189_35  0 // #35 (SEI    /Q0189/SEI message for indicating constraints on TMVP) Proposal 2.3,  SEI message for indicating constraints on TMVP
+//#define H_MV_HLS_8_EDF_Q0116_29  0 // #29 (ED.FIX /Q0116/Recovery point SEI) , consider adding a note regarding how random accessibility is affected by the recovery point SEI message
+//#define H_MV_HLS_8_GEN_Q0183_23  0 // #23 (GEN    /Q0183/SEI clean-ups) numerous small clean-ups on SEI messages.
+//#define H_MV_HLS_8_MIS_Q0247_49  0 // #49 (MISC   /Q0247/frame-field information SEI message)
+//#define H_MV_HLS_8_MIS_Q0189_34  0 // #34 (MISC   /Q0189/slice temporal mvp enabled flag) Proposal 2.2, clarification of semantics of slice temporal mvp enabled flag
+//#define H_MV_HLS_8_EDF_Q0081_01  0 // #1  (ED.FIX /Q0081/alpha channel persist) On reuse of alpha planes in auxiliary pictures. It was asked why there would not be a presumption that the alpha channel content would simply persist, without needing the flag to indicate it. Decision (Ed.): Delegated to editors to clarify, as necessary, that the alpha channel content persists until cancelled or updated in output order.
+//#define H_MV_HLS_8_SEI_Q0253_37  0 // #37 (SEI    /Q0253/layer not present), modified semantics of layers not present SEI message to correct bug introduced during editing 
+//#define H_MV_HLS_8_SEI_Q0045_11  0 // #11 (SEI    /Q0045/Overlay) Proposal for an SEI message on selectable overlays. Decision: Adopt (modified for variable-length strings).
+//#define H_MV_HLS_7_SEI_P0133_28  0 // (SEI/P0133/Recovery point SEI) #28 Decision: Adopt change to recover point semantics only (-v3)
+//#define H_MV_HLS_7_SEI_P0123_25  0 // (SEI/P0123/Alpha channel info) #25 Add alpha channel information SEI message Decision: Adopt. Constrain the bit depth indicated to be equal to the coded bit depth of the aux picture. 
+
+
+// Auxiliary picture related
+//#define H_MV_HLS_8_AUX_NODOC_40  0 // #40 (AUX    /NODOC/primary pic) Clarify that an auxiliary picture can be associated with more than one primary picture. Consider if the language associating an alpha auxiliary picture with a primary picture in the semantics of dimension_id[ ][ ] near the AuxId derivation could be moved to the alpha SEI message.
+//#define H_MV_HLS_8_AUX_Q0081_2   0 // #2  (AUX    /Q0081/primary) Decision: Remove the constraint that an alpha picture must be accompanied by a primary picture.
+//#define H_MV_HLS_8_AUX_Q0078_44  0 // #44 (AUX    /Q0078/concepts Auxiliary picture concepts:
+//#define H_MV_HLS_8_AUX_Q0078_39  0 // #39 (AUX    /Q0078/conformance): mechanism for signaling a profile/tier/level conformance point for auxiliary pictures
+
+// Profiles
+//#define H_MV_HLS_8_PRO_NODOC_50  0 // #50 (PROF   /NODOC/Monochrome) Add Monochrome 8-bit profile
+//#define H_MV_HLS_8_PRO_NODOC_31  0 // #31 (PROF   /NODOC/Profile constraint) Add a profile constraint to the Scalable Main, Scalable Main 10, and Stereo Main profiles against allowing layers with duplicate values of DependencyId (or ViewOrderIdx) when AuxId equal to 0.
+//#define H_MV_HLS_8_PRO_H0126_45  0 // #45 (PROF   /H0126/Stereo main) Phrasing used in specifying the Stereo Main profile. 
+//#define H_MV_HLS_8_PRO_Q0160_33  0 // #33 (PROF   /Q0160/alt_output_flag) v2: Add constraint to stereo main profile that it must contain exactly two texture views, and add a note to state that the constraint implies a restriction that alt_output_flag equal to 0. 
+
+// DPB
+//#define H_MV_HLS_8_HRD_Q0102_09  0 // #9  (HRD    /Q0102/NoOutputOfPriorPicsFlag) It was suggested that also the separate_colour_plane_flag should affect inference of NoOutputOfPriorPicsFlag. Decision (Ed.): Agreed (affects RExt text).
+//#define H_MV_HLS_8_DBP_Q0154_38  0 // #38 (DBP    /Q0154/VPS DPB) Proposal in C.5.2.1: Add in the decoding process that when a new VPS is activated, all pictures in the DPB are marked as unused for reference
+//#define H_MV_HLS_8_HRD_Q0154_10  0 // #10 (HRD    /Q0154/DPB Flushing and parameters) On picture flushing and DPB parameters Decision: Adopted (some details to be discussed further in BoG).
+//#define H_MV_HLS_7_OTHER_P0187_1 0 // (OTHER/P0187/NoOutputOfPriorPicsFlag) #1 Inference of NoOutputOfPriorPicsFlag and proposes to take into account colour format and bit depth for the inference in addition to spatial resolution 
+
+// Others
+//#define H_MV_HLS_8_HSB_Q0041_03  0 // #3  (HS     /Q0041/hybrid scalability) The proposed text was endorsed, with non-editorial open issues considered as follows 
+:// #define H_MV_HLS_7_OTHER_P0187_1          0 // (OTHER/P0187/NoOutputOfPriorPicsFlag) #1 Inference of NoOutputOfPriorPicsFlag and proposes to take into account colour format and bit depth for the inference in addition to spatial resolution 
+//#define H_MV_HLS_8_MIS_Q0078_24  0 // #24 (MISC   /Q0078/scan and pic type) , Items 3 b,c and 4, clarifying which pictures in an output layer sets are applied the values of general_progressive_source_flag, general_interlaced_source_flag, general_non_packed_constraint_flag and general_frame_only_constraint_flag.
+
+
+#define H_MV_HLS_8_SYN_Q0041_03    1   // #3  Syntax only (HS     /Q0041/hybrid scalability) The proposed text was endorsed, with non-editorial open issues considered as follows 
+:// #define H_MV_HLS_7_OTHER_P0187_1          0 // (OTHER/P0187/NoOutputOfPriorPicsFlag) #1 Inference of NoOutputOfPriorPicsFlag and proposes to take into account colour format and bit depth for the inference in addition to spatial resolution 
+#define H_MV_HLS_8_SYN_39_19       1   // #39 Syntax only + (PS/Q0165,Q0078/presence of num_add_output_layer_sets) proposal 2. change condition for presence of num_add_output_layer_sets to avoid sending it when there is only one layer set.
+#define H_MV_HLS_8_HRD_Q0101_04    1   // #4  (HRD    /Q0101/Bitstream part buffer) On Bitstream Partition Buffer. Decision (BF/Cleanup): Adopt (sub-proposals 111, refined as described).
+#define H_MV_HLS_8_PPS_NODOC_NN    1   // #NN (PPS    /NODOC/reserved flag): Add a flag in PPS for SHVC color gamut scalability
+#define H_MV_HLS_8_MIS_Q0177_47    1   // #47 (MISC   /Q0177/EOS NAL) proposal 2: clarification of description of end of sequence NAL unit
+#define H_MV_HLS_8_HRD_Q0182_05    1   // #5  (HRD    /Q0182/Bitstream part buffer) Decision (BF/Cleanup/Ed): Adopted (such that we use the main proposal for sub-proposal 1, and alternative 1 for sub-proposal 2). + #define H_MV_HLS_8_HRD_Q0182_06  0 // #6  (HRD    /Q0182/hrd_parameters) Sub-proposal 2 Alternative 1: Clarify that the VPS hrd_parameters( ) syntax structure that applies to the layer set which is associated with the bitstream partition initial arrival time SEI message is used to determine the lengths of the nal_initial_arrival_delay[ i ] and vcl_initial_arrival_delay[ i ] syntax elements. Decision (BF/Cleanup/Ed): Adopted alternative 1 for sub-proposal 2
+#define H_MV_HLS_8_SPS_NODOC_48    1   // #48 (SPS    /NODOC/PPS extension cleanups) Alignment with RExt
+#define H_MV_HLS_8_DBP_NODOC_42    1   // #42 (DBP    /NODOC/sharing) Remove sub-DPB sharing and processes that mark inter-layer reference pictures as "unused for reference"
+#define H_MV_HLS_8_RPS_Q0100_36    1   // #36 (RPS    /Q0100/constraint to semantics) v3, add constraint to RPS semantics
+#define H_MV_HLS_8_POC_Q0142_32    1   // #32 (POC    /Q0142/poc_lsb_not_present_flag) v2: Add semantic constraints to poc_lsb_not_present_flag.
+#define H_MV_HLS_8_HRD_Q0102_08    1   // #8  (HRD    /Q0102/sps_max_dec_pic_buffering_minus1) Sub-proposal 2: A semantics bug fix is proposed for sps_max_dec_pic_buffering_minus1 as a bug-fix. In discussion, the first option was preferred. Decision (BF/Cleanup/Ed.): Adopt. 
+#define H_MV_HLS_8_MIS_Q0102_30    1   // #30 (MISC   /Q0102/loop index) proposal 3, change the max loop index for signaling bit rate and pic rate info to MaxSubLayersInLayerSetMinus1
+#define H_MV_HLS_8_GEN_Q0108_13    1   // #13 (GEN    /Q0108/STSA TemporalId) Agreed to remove restriction from proposal 2, to allow STSA pics of non-base layers to have TemporalId equal to 0.
+#define H_MV_HLS_8_PMS_Q0195_21    1   // #21 (PS     /Q0195/constraint update_ref_format_flag) proposal 2: add a semantic constraint on the value of update_ref_format_flag
+#define H_MV_HLS_8_PMS_Q0195_20    1   // #20 (PS     /Q0195/syntax table rep format) proposal 1: restructure syntax table for sending of rep_format_idx_present_flag and vps_num_ref_formats_minus1
+#define H_MV_HLS_8_MIS_Q0177_22    1   // #22 (MISC   /Q0177/inference sps_temporal_id_nesting_flag) proposal 1: modify inference rule for sps_temporal_id_nesting_flag when it is not present
+#define H_MV_HLS_8_PMS_Q0165_18    1   // #18 (PS     /Q0165/disallow an empty layer set) proposal 1.a), add a constraint to disallow an empty layer set
+#define H_MV_HLS_8_RPS_Q0060_17    1   // #17 (RPS    /Q0060/condition refLayerPicIdc) Proposal 2: Add a condition to the derivation of refLayerPicIdc of (TemporalId == 0)
+#define H_MV_HLS_8_POC_Q0146_15    1   // #15 (POC    /Q0146/inference of poc_msb_val_present_flag) Proposal 1.1: Change inference rule in semantics of poc_msb_val_present_flag
+
 
 
@@ -380,8 +451,26 @@
 ///////////////////////////////////   HM RELATED DEFINES ////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////////////////
-#define BUGFIX_INTRAPERIOD 1
+#define HARMONIZE_GOP_FIRST_FIELD_COUPLE  1
+#define FIX_FIELD_DEPTH                 1
+#if H_MV
+#define EFFICIENT_FIELD_IRAP            0
+#else
+#define EFFICIENT_FIELD_IRAP            1
+#endif
+#define ALLOW_RECOVERY_POINT_AS_RAP     1
+#define BUGFIX_INTRAPERIOD              1
 #define SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1
 
+#define SAO_SGN_FUNC 1
+
 #define FIX1172 1 ///< fix ticket #1172
+
+#define SETTING_PIC_OUTPUT_MARK     1
+#define SETTING_NO_OUT_PIC_PRIOR    1
+#define FIX_EMPTY_PAYLOAD_NAL       1
+#define FIX_WRITING_OUTPUT          1
+#define FIX_OUTPUT_EOS              1
+
+#define FIX_POC_CRA_NORASL_OUTPUT   1
 
 #define MAX_NUM_PICS_IN_SOP           1024
@@ -923,4 +1012,5 @@
 #if H_MV
 
+#if !H_MV_HLS_8_SPS_NODOC_48
 enum PpsExtensionTypes
 {
@@ -944,5 +1034,5 @@
     PS_EX_T_MAX_NUM = 8
   };
-
+#endif
 /// scalability types
   enum ScalabilityType
Index: trunk/source/Lib/TLibDecoder/AnnexBread.h
===================================================================
--- trunk/source/Lib/TLibDecoder/AnnexBread.h	(revision 951)
+++ trunk/source/Lib/TLibDecoder/AnnexBread.h	(revision 964)
@@ -65,5 +65,5 @@
   , m_Input(istream)
   {
-    istream.exceptions(std::istream::eofbit);
+    istream.exceptions(std::istream::eofbit | std::istream::badbit);
   }
 
Index: trunk/source/Lib/TLibDecoder/NALread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/NALread.cpp	(revision 951)
+++ trunk/source/Lib/TLibDecoder/NALread.cpp	(revision 964)
@@ -127,8 +127,25 @@
   else
   {
+#if H_MV_HLS_8_GEN_Q0108_13
+
+    // If nal_unit_type is in the range of BLA_W_LP to RSV_IRAP_VCL23, inclusive, i.e. the coded 
+    // slice segment belongs to an IRAP picture, TemporalId shall be equal to 0. 
+    // Otherwise, when nal_unit_type is equal to TSA_R, TSA_N, STSA_R, or STSA_N, TemporalId shall not be equal to 0. 
+    // Otherwise, if nal_unit_type is equal to TSA or TSA_N, TemporalId shall not be equal to 0. 
+    // Otherwise, when nuh_layer_id is equal to 0 and nal_unit_type is equal to STSA_R or STSA_N, 
+    // TemporalId shall not be equal to 0.
+
+    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N    );
+
+    assert( nalu.m_layerId > 0 
+      || ( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
+        && 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
          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N );
+#endif
   }
 }
Index: trunk/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 951)
+++ trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 964)
@@ -399,21 +399,16 @@
 {
   UInt val; 
-  READ_CODE(4, val, "active_vps_id");      sei.activeVPSId = val; 
-  READ_FLAG( val, "full_random_access_flag");  sei.m_fullRandomAccessFlag = val ? true : false;
-  READ_FLAG( val, "no_param_set_update_flag"); sei.m_noParamSetUpdateFlag = val ? true : false;
+  READ_CODE(4, val, "active_video_parameter_set_id");   sei.activeVPSId = val; 
+  READ_FLAG(   val, "self_contained_cvs_flag");         sei.m_selfContainedCvsFlag = val ? true : false;
+  READ_FLAG(   val, "no_parameter_set_update_flag");    sei.m_noParameterSetUpdateFlag = val ? true : false;
   READ_UVLC(   val, "num_sps_ids_minus1"); sei.numSpsIdsMinus1 = val;
 
-  sei.activeSeqParamSetId.resize(sei.numSpsIdsMinus1 + 1);
+  sei.activeSeqParameterSetId.resize(sei.numSpsIdsMinus1 + 1);
   for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
   {
-    READ_UVLC(val, "active_seq_param_set_id");  sei.activeSeqParamSetId[i] = val; 
-  }
-
-  UInt uibits = m_pcBitstream->getNumBitsUntilByteAligned(); 
-  
-  while(uibits--)
-  {
-    READ_FLAG(val, "alignment_bit");
-  }
+    READ_UVLC(val, "active_seq_parameter_set_id");      sei.activeSeqParameterSetId[i] = val; 
+  }
+
+  xParseByteAlign();
 }
 
@@ -681,8 +676,13 @@
     case 4:
       {
-        READ_CODE( 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedValue = val;
-        if( sei.m_cameraIsoSpeedValue == 255) //Extended_ISO
+        READ_CODE( 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedIdc = val;
+        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
         {
           READ_CODE( 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
+        }
+        READ_CODE( 8, val, "exposure_index_idc" );                       sei.m_exposureIndexIdc = val;
+        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
+        {
+          READ_CODE( 32,   val,   "exposure_index_value" );              sei.m_exposureIndexValue = val;
         }
         READ_FLAG( val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 951)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 964)
@@ -364,9 +364,47 @@
   READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
   pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
-
+  
+#if H_MV
+  READ_FLAG( uiCode, "pps_extension_present_flag");
+#else
   READ_FLAG( uiCode, "pps_extension_flag");
+#endif
   if (uiCode)
   {
+
 #if H_MV
+#if H_MV_HLS_8_SPS_NODOC_48
+    READ_FLAG( uiCode, "pps_range_extensions_flag" ); pcPPS->setPpsRangeExtensionsFlag( uiCode == 1 );
+    READ_FLAG( uiCode, "pps_multilayer_extension_flag" ); pcPPS->setPpsMultilayerExtensionFlag( uiCode == 1 );
+#if !H_3D
+    READ_CODE( 6, uiCode, "pps_extension_6bits" ); pcPPS->setPpsExtension6bits( uiCode );
+#else
+    READ_FLAG( uiCode, "pps_3d_extension_flag" ); pcPPS->setPps3dExtensionFlag( uiCode == 1 );
+    READ_CODE( 5, uiCode, "pps_extension_5bits" ); pcPPS->setPpsExtension5bits( uiCode );
+#endif
+    if ( pcPPS->getPpsRangeExtensionsFlag() )
+    { 
+      assert(0); 
+    }
+
+    if ( pcPPS->getPpsMultilayerExtensionFlag() )
+    { 
+        READ_FLAG( uiCode, "poc_reset_info_present_flag" ); pcPPS->setPocResetInfoPresentFlag( uiCode == 1 );
+#if H_MV_HLS_8_PPS_NODOC_NN
+        READ_FLAG( uiCode, "pps_extension_reserved_zero_flag" );
+#endif
+    }
+#if !H_3D
+    if ( pcPPS->getPpsExtension6bits() )
+    {
+#else
+    if ( pcPPS->getPps3dExtensionFlag() )
+    { 
+      parsePPSExtension( pcPPS, pcVPS );
+    }
+    if ( pcPPS->getPpsExtension5bits() )
+    {
+#endif
+#else
     for ( Int i = 0; i < PPS_EX_T_MAX_NUM; i++ )
     {
@@ -395,4 +433,6 @@
     {
 #endif
+#endif
+
       while ( xMoreRbspData() )
       {
@@ -845,21 +885,9 @@
   for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
   {
-#if H_MV
     READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
-#else
-    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1");
-#endif
     pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
-#if H_MV
     READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
-#else
-    READ_UVLC ( uiCode, "sps_num_reorder_pics" );
-#endif
     pcSPS->setNumReorderPics(uiCode, i);
-#if H_MV
     READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
-#else
-    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1");
-#endif
     pcSPS->setMaxLatencyIncrease( uiCode, i );
 
@@ -978,13 +1006,49 @@
   }
 
+
+#if H_MV
+  READ_FLAG( uiCode, "sps_extension_present_flag");
+  pcSPS->setSpsExtensionPresentFlag( uiCode ); 
+  if (pcSPS->getSpsExtensionPresentFlag( ) )
+#else
   READ_FLAG( uiCode, "sps_extension_flag");
+  if (uiCode)
+#endif
+  {
 #if H_MV
-  pcSPS->setSpsExtensionFlag( uiCode ); 
-  if (pcSPS->getSpsExtensionFlag( ) )
-#else
-  if (uiCode)
-#endif
-  {
-#if H_MV
+#if H_MV_HLS_8_SPS_NODOC_48
+    READ_FLAG( uiCode, "sps_range_extensions_flag" ); pcSPS->setSpsRangeExtensionsFlag( uiCode == 1 );
+    READ_FLAG( uiCode, "sps_multilayer_extension_flag" ); pcSPS->setSpsMultilayerExtensionFlag( uiCode == 1 );
+#if !H_3D
+    READ_CODE( 6, uiCode, "sps_extension_6bits" ); pcSPS->setSpsExtension6bits( uiCode );
+#else
+    READ_FLAG( uiCode, "sps_3d_extension_flag" ); pcSPS->setSps3dExtensionFlag( uiCode == 1 );
+    READ_CODE( 5, uiCode, "sps_extension_5bits" ); pcSPS->setSpsExtension5bits( uiCode );
+#endif
+  }
+
+  if ( pcSPS->getSpsRangeExtensionsFlag() )
+  {
+    assert( 0 ); 
+  }
+
+  if ( pcSPS->getSpsMultilayerExtensionFlag() )
+  {
+    parseSPSExtension( pcSPS ); 
+  }
+
+#if H_3D
+  if ( pcSPS->getSps3dExtensionFlag() )
+  {
+    parseSPSExtension2( pcSPS, viewIndex, depthFlag  ); 
+  }
+
+  if ( pcSPS->getSpsExtension5bits() )
+  { 
+#else
+  if ( pcSPS->getSpsExtension6bits() )
+  { 
+#endif
+#else
     for (Int i = 0; i < PS_EX_T_MAX_NUM; i++)
     {
@@ -1012,9 +1076,10 @@
     {   
 #endif
+#endif
         while ( xMoreRbspData() )
         {
           READ_FLAG( uiCode, "sps_extension_data_flag");
         }
-#if H_MV
+#if H_MV && !H_MV_HLS_8_SPS_NODOC_48
     }
 #endif
@@ -1067,5 +1132,10 @@
   
   READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
+#if H_MV_HLS_8_SYN_Q0041_03
+  READ_FLAG( uiCode, "vps_base_layer_internal_flag" );            pcVPS->setVpsBaseLayerInternalFlag( uiCode == 1 );
+  READ_FLAG( uiCode, "vps_reserved_one_bit" );                    assert( uiCode == 1 ); 
+#else
   READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
+#endif
 #if H_MV
   READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayersMinus1( std::min( uiCode, (UInt) ( MAX_NUM_LAYER_IDS-1) )  );
@@ -1073,5 +1143,5 @@
   READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
 #endif
-  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );
+  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );    assert(uiCode+1 <= MAX_TLAYER);
   READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
   assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
@@ -1151,6 +1221,11 @@
     }
   }
+#if H_MV_HLS_8_RPS_Q0100_36
+  READ_FLAG( uiCode,  "vps_extension_flag" );                      pcVPS->setVpsExtensionFlag( uiCode == 1 ? true : false );
+  if ( pcVPS->getVpsExtensionFlag() )
+#else
   READ_FLAG( uiCode,  "vps_extension_flag" );
   if (uiCode)
+#endif
   {
 #if H_MV
@@ -1187,5 +1262,7 @@
 {
   UInt uiCode; 
+#if !H_MV_HLS_8_SYN_Q0041_03
   READ_FLAG( uiCode, "avc_base_layer_flag" );                     pcVPS->setAvcBaseLayerFlag( uiCode == 1 ? true : false );
+#endif
 
   READ_FLAG( uiCode, "splitting_flag" );                          pcVPS->setSplittingFlag( uiCode == 1 ? true : false );
@@ -1267,5 +1344,4 @@
       READ_CODE( 3, uiCode, "sub_layers_vps_max_minus1" ); pcVPS->setSubLayersVpsMaxMinus1( i, uiCode );    
       pcVPS->checkSubLayersVpsMaxMinus1( i ); 
-
     }
   }  
@@ -1294,5 +1370,4 @@
 
   READ_FLAG( uiCode, "all_ref_layers_active_flag" );             pcVPS->setAllRefLayersActiveFlag( uiCode == 1 );
-
   READ_UVLC( uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode );  
 
@@ -1309,25 +1384,52 @@
   }
 
-  READ_UVLC( uiCode, "num_add_output_layer_sets"      ); pcVPS->setNumAddOutputLayerSets( uiCode );
+#if H_MV_HLS_8_SYN_39_19
+  if ( pcVPS->getNumIndependentLayers() > 1 ) 
+  {
+   READ_UVLC( uiCode, "num_add_layer_sets"      ); pcVPS->setNumAddLayerSets( uiCode );
+  }
+  for (Int i = 0; i < pcVPS->getNumAddLayerSets(); i++)
+  {
+    for (Int j = 0; j < pcVPS->getNumIndependentLayers(); j++)
+    {
+      READ_CODE( pcVPS->getHighestLayerIdxPlus1Len( j ) , uiCode, "highest_layer_idx_plus1" ); pcVPS->setHighestLayerIdxPlus1( i, j, uiCode );
+    }
+  }
+  if (pcVPS->getNumLayerSets() > 1)
+  {
+    READ_UVLC( uiCode, "num_add_olss" ); pcVPS->setNumAddOlss( uiCode );
+    READ_CODE( 2, uiCode, "default_output_layer_idc" ); pcVPS->setDefaultOutputLayerIdc( std::min( uiCode, (UInt) 2 ) );    
+  }
+
+  pcVPS->initTargetLayerIdLists( ); 
+
+#else
+  READ_UVLC( uiCode, "num_add_layer_sets"      ); pcVPS->setNumAddLayerSets( uiCode );
   pcVPS->initTargetLayerIdLists( ); 
   if( pcVPS->getNumOutputLayerSets() > 1)
   {
-    READ_CODE( 2, uiCode, "default_target_output_layer_idc" ); pcVPS->setDefaultTargetOutputLayerIdc( std::min( uiCode, (UInt) 2 ) );    
+    READ_CODE( 2, uiCode, "default_output_layer_idc" ); pcVPS->setDefaultOutputLayerIdc( std::min( uiCode, (UInt) 2 ) );    
   }  
+#endif
 
   pcVPS->setOutputLayerFlag(0, 0, pcVPS->inferOutputLayerFlag( 0, 0 )); 
-  pcVPS->setOutputLayerSetIdxMinus1(0, -1); 
+  pcVPS->setLayerSetIdxForOlsMinus1(0, -1); 
 
   pcVPS->deriveTargetLayerIdList( 0 ); 
+
   for( Int i = 1; i < pcVPS->getNumOutputLayerSets( ); i++ )
   {
+#if H_MV_HLS_8_SYN_39_19
+    if( i >= pcVPS->getNumLayerSets( ) )    
+#else
     if( i > pcVPS->getVpsNumLayerSetsMinus1( ) )    
+#endif
     {        
-      READ_UVLC( uiCode,      "output_layer_set_idx_minus1[i]" ); pcVPS->setOutputLayerSetIdxMinus1( i, uiCode ); 
-    }
-
-    if ( i > pcVPS->getVpsNumLayerSetsMinus1() || pcVPS->getDefaultTargetOutputLayerIdc() == 2 )
+      READ_UVLC( uiCode,      "layer_set_idx_for_ols_minus1[i]" ); pcVPS->setLayerSetIdxForOlsMinus1( i, uiCode ); 
+    }
+
+    if ( i > pcVPS->getVpsNumLayerSetsMinus1() || pcVPS->getDefaultOutputLayerIdc() == 2 )
     {       
-      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->getLayerSetIdxForOutputLayerSet( i ) ); j++ )
+      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->olsIdxToLsIdx( i ) ); j++ )
       {
         READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( i, j, uiCode == 1 ); 
@@ -1336,5 +1438,5 @@
     else
     { 
-      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->getLayerSetIdxForOutputLayerSet( i ) ); j++ )
+      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->olsIdxToLsIdx( i ) ); j++ )
       {              
         pcVPS->setOutputLayerFlag(i,j, pcVPS->inferOutputLayerFlag( i, j )); 
@@ -1347,5 +1449,4 @@
       READ_CODE( pcVPS->getProfileLevelTierIdxLen(), uiCode,"profile_level_tier_idx[ i ]" );   pcVPS->setProfileLevelTierIdx( i , uiCode ); 
     }
-
     if( pcVPS->getNumOutputLayersInOutputLayerSet( i ) == 1 && pcVPS->getNumDirectRefLayers( pcVPS->getOlsHighestOutputLayerId( i ) ) > 0 )
     {
@@ -1354,4 +1455,5 @@
   }
 
+#if !H_MV_HLS_8_PMS_Q0195_20
   READ_FLAG( uiCode, "rep_format_idx_present_flag" ); pcVPS->setRepFormatIdxPresentFlag( uiCode == 1 );
   if ( pcVPS->getRepFormatIdxPresentFlag() )
@@ -1359,4 +1461,7 @@
     READ_UVLC( uiCode, "vps_num_rep_formats_minus1" ); pcVPS->setVpsNumRepFormatsMinus1( uiCode );
   }
+#else
+  READ_UVLC( uiCode, "vps_num_rep_formats_minus1" ); pcVPS->setVpsNumRepFormatsMinus1( uiCode );
+#endif
 
   for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
@@ -1369,14 +1474,41 @@
   }
 
+#if H_MV_HLS_8_PMS_Q0195_20
+  if ( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
+  {
+    READ_FLAG( uiCode, "rep_format_idx_present_flag" ); pcVPS->setRepFormatIdxPresentFlag( uiCode == 1 );
+  }
+#endif
   if( pcVPS->getRepFormatIdxPresentFlag() ) 
   {
+#if H_MV_HLS_8_SYN_Q0041_03
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 1 : 0; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+#else
     for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
-    {
+#endif
+    {
+#if !H_MV_HLS_8_PMS_Q0195_20
       if( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
       {
+#endif
         READ_CODE( pcVPS->getVpsRepFormatIdxLen(), uiCode, "vps_rep_format_idx[i]" ); pcVPS->setVpsRepFormatIdx( i, uiCode );
-      }
-    }
-  }
+#if !H_MV_HLS_8_PMS_Q0195_20
+      }
+#endif
+    }
+  }
+#if H_MV_HLS_8_PMS_Q0195_20
+  else
+  {
+#if H_MV_HLS_8_SYN_Q0041_03
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 1 : 0; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+#else
+    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+#endif
+    {
+      pcVPS->setVpsRepFormatIdx( i, pcVPS->inferVpsRepFormatIdx( i ) );
+    }
+  }
+#endif
 
   READ_FLAG( uiCode, "max_one_active_ref_layer_flag" ); pcVPS->setMaxOneActiveRefLayerFlag ( uiCode == 1 ); 
@@ -1403,7 +1535,13 @@
   }
 
+#if H_MV_HLS_8_SYN_Q0041_03
+  for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ?  1 : 2; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    for( Int j = pcVPS->getVpsBaseLayerInternalFlag() ?  0 : 1; j < i; j++ )
+#else
   for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
   {
     for( Int j = 0; j < i; j++ )
+#endif
     {
       if (pcVPS->getDirectDependencyFlag( i, j) )
@@ -1415,4 +1553,5 @@
         else
         {
+
           READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2,  uiCode, "direct_dependency_type[i][j]" ); pcVPS->setDirectDependencyType( i, j , uiCode);
         }
@@ -1420,5 +1559,4 @@
     }
   }  
-
   READ_UVLC( uiCode, "vps_non_vui_extension_length" ); pcVPS->setVpsNonVuiExtensionLength( uiCode ); 
   for ( Int i = 1; i <= pcVPS->getVpsNonVuiExtensionLength(); i++ )
@@ -1437,5 +1575,4 @@
     pcVPSVUI->inferVpsVui( false ); 
   }
-
   pcVPS->checkVPSExtensionSyntax(); 
 }
@@ -1492,7 +1629,15 @@
   if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
   {
+#if H_MV_HLS_8_SYN_Q0041_03
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <=  pcVPS->getVpsNumLayerSetsMinus1(); i++ )
+#else
     for( Int i = 0; i  <=  pcVPS->getVpsNumLayerSetsMinus1(); i++ )
-    {
+#endif
+    {
+#if H_MV_HLS_8_MIS_Q0102_30
+      for( Int j = 0; j  <=  pcVPS->getMaxSubLayersInLayerSetMinus1( i ); j++ ) 
+#else        
       for( Int j = 0; j  <=  pcVPS->getMaxTLayers(); j++ ) 
+#endif
       {
         if( pcVPSVUI->getBitRatePresentVpsFlag( ) )
@@ -1551,9 +1696,12 @@
     }
   }
-
   READ_FLAG( uiCode, "tiles_not_in_use_flag" ); pcVPSVUI->setTilesNotInUseFlag( uiCode == 1 );
   if( !pcVPSVUI->getTilesNotInUseFlag() ) 
   {      
+#if H_MV_HLS_8_SYN_Q0041_03
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+#else
     for( Int i = 0; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+#endif
     {
       READ_FLAG( uiCode, "tiles_in_use_flag[i]" ); pcVPSVUI->setTilesInUseFlag( i, uiCode == 1 );
@@ -1563,6 +1711,9 @@
       }
     }  
-
-    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )  
+#if H_MV_HLS_8_SYN_Q0041_03
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 1 : 2; i  <=  pcVPS->getMaxLayersMinus1(); i++ )  
+#else
+    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )      
+#endif
     {
       for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ) ; j++ )
@@ -1586,5 +1737,4 @@
     }
   }
-
   READ_CODE( 3, uiCode, "vps_vui_reserved_zero_3bits" ); 
   READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); pcVPSVUI->setIlpRestrictedRefLayersFlag( uiCode == 1 );
@@ -1596,13 +1746,20 @@
       for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ )
       {
-        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
-        if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
-        {
-          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag" ); pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, uiCode == 1 );
-          if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
+#if H_MV_HLS_8_SYN_Q0041_03
+        if( pcVPS->getVpsBaseLayerInternalFlag() || pcVPS->getRefLayerId( pcVPS->getLayerIdInNuh( i ), j ) > 0 )
+        {        
+#endif
+          READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
+          if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
           {
-            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1" ); pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, uiCode );
+            READ_FLAG( uiCode, "ctu_based_offset_enabled_flag" ); pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, uiCode == 1 );
+            if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
+            {
+              READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1" ); pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, uiCode );
+            }
           }
-        }
+#if H_MV_HLS_8_SYN_Q0041_03
+        }
+#endif
       }
     }
@@ -1613,5 +1770,5 @@
   {
     parseVpsVuiBspHrdParameters( pcVPS ); 
-}
+  }
   for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
   {
@@ -1651,4 +1808,9 @@
     for( Int i = 0; i < vpsVuiBspHrdP->getNumBitstreamPartitions( h ); i++ )  
     {
+#if H_MV_HLS_8_HRD_Q0101_04
+      for( Int j = 0; j < pcVPS->getNumLayersInIdList( h ); j++ )  
+      {
+        READ_FLAG( uiCode, "layer_in_bsp_flag" ); vpsVuiBspHrdP->setLayerInBspFlag( h, i, j, uiCode == 1 );
+#else
       for( Int j = 0; j <= pcVPS->getMaxLayersMinus1(); j++ )  
       {
@@ -1661,4 +1823,5 @@
           vpsVuiBspHrdP->setLayerInBspFlag( h, i, j, false ); // This inference seems to be missing in spec 
         }
+#endif
       }
     }
@@ -1667,11 +1830,22 @@
     if( vpsVuiBspHrdP->getNumBitstreamPartitions( h ) )
     {  
-      READ_UVLC( uiCode, "num_bsp_sched_combinations" ); vpsVuiBspHrdP->setNumBspSchedCombinations( h, uiCode );
-      for( Int i = 0; i < vpsVuiBspHrdP->getNumBspSchedCombinations( h ); i++ )
+      READ_UVLC( uiCode, "num_bsp_sched_combinations_minus1" ); vpsVuiBspHrdP->setNumBspSchedCombinationsMinus1( h, uiCode );
+#if H_MV_HLS_8_HRD_Q0182_05
+      for( Int i = 0; i <= vpsVuiBspHrdP->getNumBspSchedCombinationsMinus1( h ); i++ )
+#else
+      for( Int i = 0; i < vpsVuiBspHrdP->getNumBspSchedCombinationsMinus1( h ); i++ )
+#endif
       {
         for( Int j = 0; j < vpsVuiBspHrdP->getNumBitstreamPartitions( h ); j++ )
         {  
+#if H_MV_HLS_8_HRD_Q0101_04
+          READ_CODE( vpsVuiBspHrdP->getBspCombHrdIdxLen(), uiCode, "bsp_comb_hrd_idx" ); vpsVuiBspHrdP->setBspCombHrdIdx( h, i, j, uiCode );
+#else
           READ_UVLC( uiCode, "bsp_comb_hrd_idx" ); vpsVuiBspHrdP->setBspCombHrdIdx( h, i, j, uiCode );
+#endif
           READ_UVLC( uiCode, "bsp_comb_sched_idx" ); vpsVuiBspHrdP->setBspCombSchedIdx( h, i, j, uiCode );
+#if H_MV_HLS_8_HRD_Q0101_04
+          vpsVuiBspHrdP->checkBspCombHrdAndShedIdx( pcVPS, h, i, j ); 
+#endif
         }  
       }
@@ -1698,6 +1872,13 @@
   for( Int i = 1; i < vps->getNumOutputLayerSets(); i++ )
   {  
+#if H_MV_HLS_8_MIS_Q0102_30
+    Int currLsIdx = vps->olsIdxToLsIdx( i ); 
+#endif
     READ_FLAG( uiCode, "sub_layer_flag_info_present_flag" ); dpbSize->setSubLayerFlagInfoPresentFlag( i, uiCode == 1 );
+#if H_MV_HLS_8_MIS_Q0102_30
+    for( Int j = 0; j  <=  vps->getMaxSubLayersInLayerSetMinus1( currLsIdx ); j++ )
+#else
     for( Int j = 0; j  <=  vps->getMaxSubLayersInLayerSetMinus1( i ); j++ )
+#endif
     {  
       if( j > 0  &&  dpbSize->getSubLayerDpbInfoPresentFlag( i, j )  )  
@@ -1707,18 +1888,13 @@
       if( dpbSize->getSubLayerDpbInfoPresentFlag( i, j ) )
       {  
-        for( Int k = 0; k < vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i )); k++ )   
+#if H_MV_HLS_8_MIS_Q0102_30
+        for( Int k = 0; k < vps->getNumLayersInIdList( currLsIdx ); k++ )   
+#else
+        for( Int k = 0; k < vps->getNumSubDpbs( vps->olsIdxToLsIdx( i )); k++ )   
+#endif
         {
           READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1" ); dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
         }
         READ_UVLC( uiCode, "max_vps_num_reorder_pics" ); dpbSize->setMaxVpsNumReorderPics( i, j, uiCode );
-#if H_MV_HLS7_GEN
-        if( vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i ) ) != vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ) ) 
-        {
-          for( Int k = 0; k < vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ); k++ )
-          {
-            READ_UVLC( uiCode, "max_vps_layer_dec_pic_buff_minus1" ); dpbSize->setMaxVpsLayerDecPicBuffMinus1( i, k, j, uiCode );
-          }
-        }
-#endif
         READ_UVLC( uiCode, "max_vps_latency_increase_plus1" ); dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, uiCode );
       }
@@ -1727,5 +1903,9 @@
         if ( j > 0 )
         {
-          for( Int k = 0; k < vps->getNumSubDpbs( vps->getOutputLayerSetIdxMinus1( i ) + 1 ); k++ )   
+#if H_MV_HLS_8_DBP_NODOC_42
+          for( Int k = 0; k < vps->getNumLayersInIdList( vps->olsIdxToLsIdx( i ) ); k++ )   
+#else
+          for( Int k = 0; k < vps->getNumSubDpbs( vps->olsIdxToLsIdx( i ) ); k++ )   
+#endif
           {
             dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, dpbSize->getMaxVpsDecPicBufferingMinus1( i,k, j - 1 ) );
@@ -1858,5 +2038,9 @@
 #endif
 
+#if H_MV_HLS_8_HRD_Q0102_08
+Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, Int targetOlsIdx)
+#else
 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
+#endif
 {
   UInt  uiCode;
@@ -1876,6 +2060,12 @@
   if( rpcSlice->getRapPicFlag())
   { 
-    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
-  }
+    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored -- updated already
+#if SETTING_NO_OUT_PIC_PRIOR
+    rpcSlice->setNoOutputPriorPicsFlag(uiCode ? true : false);
+#else
+    rpcSlice->setNoOutputPicPrior( false );
+#endif
+  }
+
   READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
   pps = parameterSetManager->getPrefetchedPPS(uiCode);
@@ -1891,4 +2081,11 @@
   sps->inferRepFormat  ( vps , rpcSlice->getLayerId() ); 
   sps->inferScalingList( parameterSetManager->getActiveSPS( sps->getSpsScalingListRefLayerId() ) );   
+#if H_MV_HLS_8_HRD_Q0102_08
+  sps->inferSpsMaxDecPicBufferingMinus1( vps, targetOlsIdx, rpcSlice->getLayerId(), false ); 
+#endif
+#if H_MV_HLS_8_RPS_Q0100_36
+  vps->inferDbpSizeLayerSetZero( sps, false ); 
+#endif
+
   if ( sps->getVuiParametersPresentFlag() )
   {
@@ -1944,4 +2141,8 @@
   }
   
+#if H0044_POC_LSB_NOT_PRESENT
+    UInt slicePicOrderCntLsb = 0;
+#endif
+
   if(!rpcSlice->getDependentSliceSegmentFlag())
   {
@@ -1994,5 +2195,7 @@
 
 #if H_MV
+#if !H0044_POC_LSB_NOT_PRESENT
     UInt slicePicOrderCntLsb = 0;
+#endif
     Int iPOClsb = slicePicOrderCntLsb;  // Needed later
     if ( (rpcSlice->getLayerId() > 0 && !vps->getPocLsbNotPresentFlag( rpcSlice->getLayerIdInVps())) || !rpcSlice->getIdrPicFlag() )
@@ -2000,4 +2203,7 @@
       READ_CODE(sps->getBitsForPOC(), slicePicOrderCntLsb, "slice_pic_order_cnt_lsb");        
     }    
+#if H_MV_HLS_8_POC_Q0142_32
+    rpcSlice->setSlicePicOrderCntLsb( slicePicOrderCntLsb ); 
+#endif
 
     Bool picOrderCntMSBZeroFlag = false;     
@@ -2093,6 +2299,16 @@
       READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
       if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
-      {
+      {        
         parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
+#if H_MV_HLS_8_RPS_Q0100_36
+        if ( !rps->getInterRPSPrediction( ) )
+        { // check sum of num_positive_pics and num_negative_pics
+          rps->checkMaxNumPics( 
+            vps->getVpsExtensionFlag(), 
+            vps->getMaxNumPics( rpcSlice->getLayerId() ),
+            rpcSlice->getLayerId(), 
+            sps->getMaxDecPicBuffering( sps->getSpsMaxSubLayersMinus1() ) - 1 );
+        }
+#endif
       }
       else // use reference to short-term reference picture set in PPS
@@ -2198,4 +2414,14 @@
         rps->setNumberOfPictures(offset);        
       }  
+#if H_MV_HLS_8_RPS_Q0100_36
+      if ( !rps->getInterRPSPrediction( ) )
+      { // check sum of NumPositivePics, NumNegativePics, num_long_term_sps and num_long_term_pics 
+        rps->checkMaxNumPics( 
+          vps->getVpsExtensionFlag(), 
+          vps->getMaxNumPics( rpcSlice->getLayerId() ),
+          rpcSlice->getLayerId(), 
+          sps->getMaxDecPicBuffering( sps->getSpsMaxSubLayersMinus1() ) - 1 );
+      }
+#endif
       if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
@@ -2578,5 +2804,14 @@
       rpcSlice->setPocResetIdc( 0 );
     }
-
+#if H_MV_HLS_8_POC_Q0142_32
+    rpcSlice->checkPocResetIdc(); 
+#endif
+
+#if H0044_POC_LSB_NOT_PRESENT
+    if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && slicePicOrderCntLsb > 0 )
+    {
+      assert( rpcSlice->getPocResetIdc() != 2 );
+    }
+#endif
     if( rpcSlice->getPocResetIdc() !=  0 )
     {
@@ -2593,7 +2828,18 @@
       READ_FLAG( uiCode, "full_poc_reset_flag" ); rpcSlice->setFullPocResetFlag( uiCode == 1 );
       READ_CODE( rpcSlice->getPocLsbValLen() , uiCode, "poc_lsb_val" ); rpcSlice->setPocLsbVal( uiCode );
+#if !H_MV_HLS_8_POC_Q0142_32
+#if H0044_POC_LSB_NOT_PRESENT
+      if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && rpcSlice->getFullPocResetFlag() )
+      {
+        assert( rpcSlice->getPocLsbVal() == 0 );
+      }
+#endif
+#endif
     }          
-
-    // Derive the value of PocMsbValRequiredFlag
+#if H_MV_HLS_8_POC_Q0142_32
+    rpcSlice->checkPocLsbVal(); 
+#endif
+
+    // Derive the value of PocMs8bValRequiredFlag
     rpcSlice->setPocMsbValRequiredFlag( rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag()
                                           /* || TODO related to vps_poc_lsb_aligned_flag */
@@ -2606,4 +2852,7 @@
     else
     {
+#if H_MV_HLS_8_POC_Q0146_15
+      rpcSlice->setPocMsbValPresentFlag( rpcSlice->inferPocMsbValPresentFlag( ) ); 
+#else
       if( rpcSlice->getPocMsbValRequiredFlag() )
       {
@@ -2614,4 +2863,5 @@
         rpcSlice->setPocMsbValPresentFlag( false );
       }
+#endif
     }
 
@@ -2633,6 +2883,5 @@
       UInt ignore;
       READ_CODE(8,ignore,"slice_header_extension_data_byte");
-    }
-  }
+    }  
 #endif
   }
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 951)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 964)
@@ -67,4 +67,5 @@
   Int**    m_aaiTempOffset;
 #endif
+
 public:
 
@@ -80,7 +81,7 @@
   Void  parseRepFormat      ( Int i, TComRepFormat* curRepFormat, TComRepFormat* prevRepFormat );
   Void  parseVPSVUI         ( TComVPS* pcVPS );
-  Void parseVideoSignalInfo ( TComVideoSignalInfo* pcVideoSignalInfo ); 
+  Void  parseVideoSignalInfo( TComVideoSignalInfo* pcVideoSignalInfo ); 
   Void  parseDpbSize        ( TComVPS* pcVPS ); 
-  Void parseVpsVuiBspHrdParameters( TComVPS* pcVPS ); 
+  Void  parseVpsVuiBspHrdParameters( TComVPS* pcVPS ); 
 #endif
 
@@ -108,5 +109,9 @@
   Void  parseProfileTier    (ProfileTierLevel *ptl);
   Void  parseHrdParameters  (TComHRD *hrd, Bool cprms_present_flag, UInt tempLevelHigh);
+#if H_MV_HLS_8_HRD_Q0102_08
+  Void  parseSliceHeader    ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, Int targetOlsIdx);
+#else
   Void  parseSliceHeader    ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager);
+#endif
   Void  parseTerminatingBit ( UInt& ruiBit );
   
Index: trunk/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 951)
+++ trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 964)
@@ -1113,5 +1113,5 @@
 {
   UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
-  UInt  uiNumPart     = pcCU->getNumPartInter();
+  UInt  uiNumPart     = pcCU->getNumPartitions();
   UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
   
Index: trunk/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 951)
+++ trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 964)
@@ -67,5 +67,5 @@
   virtual Void  parseVPS                  ( TComVPS* pcVPS )                       = 0;
 #if H_3D
-  virtual Void  parseSPS                  ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag  )         = 0;
+  virtual Void  parseSPS                  ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag  )                    = 0;
 #else
   virtual Void  parseSPS                  ( TComSPS* pcSPS )                                      = 0;
@@ -77,5 +77,9 @@
 #endif
 
+#if H_MV_HLS_8_HRD_Q0102_08
+  virtual Void parseSliceHeader          ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, Int targetOlsIdx )       = 0;
+#else
   virtual Void parseSliceHeader          ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)       = 0;
+#endif
 
   virtual Void  parseTerminatingBit       ( UInt& ruilsLast )                                     = 0;
@@ -125,5 +129,5 @@
   virtual Void updateContextTables( SliceType eSliceType, Int iQp ) = 0;
   
-  virtual ~TDecEntropyIf() {}
+  virtual ~TDecEntropyIf() {}; 
 };
 
@@ -160,6 +164,9 @@
   Void    decodePPS                   ( TComPPS* pcPPS )    { m_pcEntropyDecoderIf->parsePPS(pcPPS);                    }
 #endif
+#if H_MV_HLS_8_HRD_Q0102_08
+  Void    decodeSliceHeader           ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, Int targetOlsIdx)  { m_pcEntropyDecoderIf->parseSliceHeader(rpcSlice, parameterSetManager, targetOlsIdx );         }
+#else
   Void    decodeSliceHeader           ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)  { m_pcEntropyDecoderIf->parseSliceHeader(rpcSlice, parameterSetManager);         }
-
+#endif
   Void    decodeTerminatingBit        ( UInt& ruiIsLast )       { m_pcEntropyDecoderIf->parseTerminatingBit(ruiIsLast);     }
   
Index: trunk/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 951)
+++ trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 964)
@@ -249,6 +249,12 @@
   }
 
+#if !H_MV_HLS_7_VPS_P0300_27
+#if SETTING_PIC_OUTPUT_MARK
+  rpcPic->setOutputMark(rpcPic->getSlice(0)->getPicOutputFlag() ? true : false);
+#else
   rpcPic->setOutputMark(true);
+#endif
   rpcPic->setReconMark(true);
+#endif
 }
 
Index: trunk/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 951)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 964)
@@ -957,7 +957,9 @@
         assert(0);
       }
+#endif
 #if H_MV_ENC_DEC_TRAC          
       DTRACE_CU("part_mode", eMode )
 #endif
+#if H_3D_QTLPC
     }
 #endif
Index: trunk/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 951)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 964)
@@ -87,5 +87,9 @@
 #endif
 
+#if H_MV_HLS_8_HRD_Q0102_08
+  Void  parseSliceHeader          ( TComSlice*& /*rpcSlice*/, ParameterSetManagerDecoder* /*parameterSetManager*/, Int targetOlsIdx ) {}
+#else
   Void  parseSliceHeader          ( TComSlice*& /*rpcSlice*/, ParameterSetManagerDecoder* /*parameterSetManager*/) {}
+#endif
   Void  parseTerminatingBit       ( UInt& ruiBit );
   Void  parseMVPIdx               ( Int& riMVPIdx          );
Index: trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 951)
+++ trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 964)
@@ -365,4 +365,13 @@
   m_prevSliceSkipped = false;
   m_skippedPOC = 0;
+#if SETTING_NO_OUT_PIC_PRIOR
+  m_bFirstSliceInBitstream  = true;
+  m_lastPOCNoOutputPriorPics = -1;
+  m_craNoRaslOutputFlag = false;
+  m_isNoOutputPriorPics = false;
+#endif
+#if H0056_EOS_CHECKS
+  m_isLastNALWasEos = false;
+#endif
 #if H_MV
   m_layerId = 0;
@@ -372,4 +381,7 @@
   m_isDepth = false;
   m_pcCamParsCollector = 0;
+#endif
+#if H_MV_HLS_8_HRD_Q0102_08
+  m_targetOptLayerSetIdx = -1; 
 #endif
 #endif
@@ -471,5 +483,5 @@
     TComVPS* vps         = pcSlice->getVPS();
     TComDpbSize* dpbSize = vps->getDpbSize(); 
-    Int lsIdx            = vps->getLayerSetIdxForOutputLayerSet( getTargetOutputLayerSetIdx()); // Is this correct, seems to be missing in spec?
+    Int lsIdx            = vps->olsIdxToLsIdx( getTargetOutputLayerSetIdx()); // Is this correct, seems to be missing in spec?
     Int layerIdx         = vps->getIdxInLayerSet     ( lsIdx, getLayerId() ); 
     Int subDpbIdx        = dpbSize->getSubDpbAssigned( lsIdx, layerIdx ); 
@@ -499,4 +511,7 @@
     {
       rpcPic->setOutputMark(false);
+#if H_MV_HLS_7_VPS_P0300_27
+      rpcPic->setPicOutputFlag(false); 
+#endif
       bBufferIsAvailable = true;
       break;
@@ -506,4 +521,7 @@
     {
       rpcPic->setOutputMark(false);
+#if H_MV_HLS_7_VPS_P0300_27
+      rpcPic->setPicOutputFlag(false); 
+#endif
       rpcPic->setReconMark( false );
       rpcPic->getPicYuvRec()->setBorderExtension( false );
@@ -550,10 +568,33 @@
   TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 );  
   TComSlice::markCurrPic( pcPic ); 
+#if !H_MV_HLS_8_DBP_NODOC_42
   TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
 #endif
+#endif
   m_bFirstSliceInPicture  = true;
 
   return;
 }
+
+#if SETTING_NO_OUT_PIC_PRIOR
+Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic)
+{
+  if (!rpcListPic || !m_isNoOutputPriorPics) return;
+
+  TComList<TComPic*>::iterator  iterPic   = rpcListPic->begin();
+
+  while (iterPic != rpcListPic->end())
+  {
+    TComPic*& pcPicTmp = *(iterPic++);
+    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
+    {
+      pcPicTmp->setOutputMark(false);
+#if H_MV_HLS_7_VPS_P0300_27
+      pcPicTmp->setPicOutputFlag(false); 
+#endif
+    }
+  }
+}
+#endif
 
 Void TDecTop::xCreateLostPicture(Int iLostPoc) 
@@ -620,5 +661,5 @@
   TComVPS* vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
   assert (vps != 0); 
-  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
+  if (!m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
 #else
   if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
@@ -628,4 +669,32 @@
     assert (0);
   }
+
+#if H_MV_HLS_8_HRD_Q0102_08
+  sps->inferSpsMaxDecPicBufferingMinus1( vps, m_targetOptLayerSetIdx, getLayerId(), false ); 
+#endif
+
+#if H_MV_HLS_8_RPS_Q0100_36
+  vps->inferDbpSizeLayerSetZero( sps, false ); 
+#endif
+
+#if H_MV_HLS_8_PMS_Q0195_21
+  // When the value of vps_num_rep_formats_minus1 in the active VPS is equal to 0
+  if ( vps->getVpsNumRepFormatsMinus1() == 0 )
+  {
+    //, it is a requirement of bitstream conformance that the value of update_rep_format_flag shall be equal to 0.
+    assert( sps->getUpdateRepFormatFlag() == false ); 
+  }
+#endif
+
+#if H_MV_HLS_8_RPS_Q0100_36
+  sps->checkRpsMaxNumPics( vps, getLayerId() ); 
+#endif
+
+#if H_MV_HLS_8_MIS_Q0177_22
+  if( m_layerId > 0 )
+  {
+    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
+  }
+#endif
 
   if( pps->getDependentSliceSegmentsEnabledFlag() )
@@ -719,6 +788,10 @@
   m_apcSlicePilot->setLayerId( nalu.m_layerId );
 #endif
+
+#if H_MV_HLS_8_HRD_Q0102_08
+  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_targetOptLayerSetIdx );
+#else
   m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
-
+#endif
   // set POC for dependent slices in skipped pictures
   if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
@@ -741,4 +814,59 @@
 #endif
 
+#if SETTING_NO_OUT_PIC_PRIOR
+  //For inference of NoOutputOfPriorPicsFlag
+  if (m_apcSlicePilot->getRapPicFlag())
+  {
+    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
+        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
+        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
+    {
+      m_apcSlicePilot->setNoRaslOutputFlag(true);
+    }
+    //the inference for NoOutputPriorPicsFlag
+    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
+    {
+      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
+      {
+        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
+      }
+    }
+    else
+    {
+      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
+    }
+
+    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
+    {
+      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
+    }
+  }
+  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
+  {
+    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
+    m_isNoOutputPriorPics = true;
+  }
+  else
+  {
+    m_isNoOutputPriorPics = false;
+  }
+
+  //For inference of PicOutputFlag
+  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
+  {
+    if ( m_craNoRaslOutputFlag )
+    {
+      m_apcSlicePilot->setPicOutputFlag(false);
+    }
+  }
+#endif
+
+#if FIX_POC_CRA_NORASL_OUTPUT
+  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
+  {
+    Int iMaxPOClsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
+    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
+  }
+#endif
 #if H_MV
     xCeckNoClrasOutput();
@@ -769,5 +897,5 @@
 
   //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))
+  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");
@@ -810,4 +938,7 @@
   }
   m_bFirstSliceInSequence = false;
+#if SETTING_NO_OUT_PIC_PRIOR  
+  m_bFirstSliceInBitstream  = false;
+#endif
   //detect lost reference picture and insert copy of earlier frame.
   Int lostPoc;
@@ -1127,8 +1258,8 @@
 #endif
 #if H_3D
-  // Preliminary fix. assuming that all sps refer to the same SPS. 
+  // Preliminary fix. assuming that all sps refer to the same VPS. 
   // Parsing dependency should be resolved!
   TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
-  assert( vps != 0 ); 
+  assert( vps != 0 );
   m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( m_layerId ), ( vps->getDepthId( m_layerId ) == 1 ) );
 #else
@@ -1182,9 +1313,9 @@
       SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
       m_parameterSetManagerDecoder.applyPrefetchedPS();
-      assert(seiAps->activeSeqParamSetId.size()>0);
-#if H_MV
-      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0], m_layerId ))
-#else
-      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
+      assert(seiAps->activeSeqParameterSetId.size()>0);
+#if H_MV
+      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0], m_layerId ))
+#else
+      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
 #endif
       {
@@ -1209,4 +1340,7 @@
     case NAL_UNIT_VPS:
       xDecodeVPS();
+#if H0056_EOS_CHECKS
+      m_isLastNALWasEos = false;
+#endif
       return false;
       
@@ -1221,4 +1355,10 @@
     case NAL_UNIT_PREFIX_SEI:
     case NAL_UNIT_SUFFIX_SEI:
+#if H0056_EOS_CHECKS
+      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
+      {
+        assert( m_isLastNALWasEos == false );
+      }
+#endif
       xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
       return false;
@@ -1240,4 +1380,18 @@
     case NAL_UNIT_CODED_SLICE_RASL_N:
     case NAL_UNIT_CODED_SLICE_RASL_R:
+#if H0056_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 H_MV
       return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
@@ -1247,4 +1401,14 @@
       break;
     case NAL_UNIT_EOS:
+#if H0056_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;
@@ -1264,4 +1428,9 @@
       return false;
       
+    case NAL_UNIT_FILLER_DATA:
+#if H_MV
+      assert( m_isLastNALWasEos == false );
+#endif
+      return false;
       
     case NAL_UNIT_RESERVED_VCL_N10:
@@ -1284,5 +1453,4 @@
     case NAL_UNIT_RESERVED_VCL31:
       
-    case NAL_UNIT_FILLER_DATA:
     case NAL_UNIT_RESERVED_NVCL41:
     case NAL_UNIT_RESERVED_NVCL42:
Index: trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 951)
+++ trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 964)
@@ -195,4 +195,7 @@
   Bool*                    m_layerInitilizedFlag; // initialization Layers
   static ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets 
+#if  H_MV_HLS_8_HRD_Q0102_08
+  Int                      m_targetOptLayerSetIdx; 
+#endif
 #else
   ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets 
@@ -225,4 +228,13 @@
   Bool                    m_prevSliceSkipped;
   Int                     m_skippedPOC;
+#if SETTING_NO_OUT_PIC_PRIOR  
+  Bool                    m_bFirstSliceInBitstream;
+  Int                     m_lastPOCNoOutputPriorPics;
+  Bool                    m_isNoOutputPriorPics;
+  Bool                    m_craNoRaslOutputFlag;    //value of variable NoRaslOutputFlag of the last CRA pic
+#endif
+#if H0056_EOS_CHECKS
+  Bool                    m_isLastNALWasEos;
+#endif
 
 #if H_MV
@@ -258,4 +270,12 @@
   
   Void  deletePicBuffer();
+#if H_MV
+#if H_MV_HLS_7_VPS_P0300_27
+  TComVPS* getActiveVPS() { return m_parameterSetManagerDecoder.getActiveVPS( ); }
+#endif
+  TComSPS* getActiveSPS() { return m_parameterSetManagerDecoder.getActiveSPS( m_layerId ); }
+#else
+  TComSPS* getActiveSPS() { return m_parameterSetManagerDecoder.getActiveSPS(); }
+#endif
 
 #if H_MV
@@ -265,4 +285,10 @@
 #endif
   
+#if SETTING_NO_OUT_PIC_PRIOR  
+  Void  checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic);
+
+  Bool  getNoOutputPriorPicsFlag () { return m_isNoOutputPriorPics; }
+  Void  setNoOutputPriorPicsFlag (bool val) { m_isNoOutputPriorPics = val; }
+#endif
 #if H_MV    
   TComPic*                getPic                ( Int poc );
@@ -270,4 +296,7 @@
   Void                    setIvPicLists         ( TComPicLists* picLists) { m_ivPicLists = picLists; }
   Void                    setLayerInitilizedFlags( Bool* val )    { m_layerInitilizedFlag = val; }
+#if  H_MV_HLS_8_HRD_Q0102_08
+  Void                    setTargetOptLayerSetIdx( Int targetOptLayerSetIdx ) { m_targetOptLayerSetIdx = targetOptLayerSetIdx; }    
+#endif
   TComVPS*                getPrefetchedVPS      ()               { return m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); }; //Assuming that currently only one VPS is present. 
   Int                     getCurrPoc            ()               { return m_apcSlicePilot->getPOC(); }
Index: trunk/source/Lib/TLibEncoder/AnnexBwrite.h
===================================================================
--- trunk/source/Lib/TLibEncoder/AnnexBwrite.h	(revision 951)
+++ trunk/source/Lib/TLibEncoder/AnnexBwrite.h	(revision 964)
@@ -58,5 +58,5 @@
 
     static const Char start_code_prefix[] = {0,0,0,1};
-    if (it == au.begin() || nalu.m_nalUnitType == NAL_UNIT_SPS || nalu.m_nalUnitType == NAL_UNIT_PPS)
+    if (it == au.begin() || nalu.m_nalUnitType == NAL_UNIT_VPS || nalu.m_nalUnitType == NAL_UNIT_SPS || nalu.m_nalUnitType == NAL_UNIT_PPS)
     {
       /* From AVC, When any of the following conditions are fulfilled, the
Index: trunk/source/Lib/TLibEncoder/NALwrite.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/NALwrite.cpp	(revision 951)
+++ trunk/source/Lib/TLibEncoder/NALwrite.cpp	(revision 964)
@@ -91,7 +91,8 @@
   vector<uint8_t>& rbsp   = nalu.m_Bitstream.getFIFO();
 
-#if H_MV  // This will handle situation when writing NAL with zero payload
-  if (rbsp.size() == 0) return;
-#endif
+  if (rbsp.size() == 0)
+  {
+    return;
+  }
 
   for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end();)
Index: trunk/source/Lib/TLibEncoder/SEIwrite.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 951)
+++ trunk/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 964)
@@ -267,27 +267,16 @@
 Void SEIWriter::xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei)
 {
-  WRITE_CODE(sei.activeVPSId,     4, "active_vps_id");
-  WRITE_FLAG(sei.m_fullRandomAccessFlag, "full_random_access_flag");
-  WRITE_FLAG(sei.m_noParamSetUpdateFlag, "no_param_set_update_flag");
+  WRITE_CODE(sei.activeVPSId,     4,         "active_video_parameter_set_id");
+  WRITE_FLAG(sei.m_selfContainedCvsFlag,     "self_contained_cvs_flag");
+  WRITE_FLAG(sei.m_noParameterSetUpdateFlag, "no_parameter_set_update_flag");
   WRITE_UVLC(sei.numSpsIdsMinus1,    "num_sps_ids_minus1");
 
-  assert (sei.activeSeqParamSetId.size() == (sei.numSpsIdsMinus1 + 1));
-
-  for (Int i = 0; i < sei.activeSeqParamSetId.size(); i++)
-  {
-    WRITE_UVLC(sei.activeSeqParamSetId[i], "active_seq_param_set_id"); 
-  }
-
-  UInt uiBits = m_pcBitIf->getNumberOfWrittenBits();
-  UInt uiAlignedBits = ( 8 - (uiBits&7) ) % 8;  
-  if(uiAlignedBits) 
-  {
-    WRITE_FLAG(1, "alignment_bit" );
-    uiAlignedBits--; 
-    while(uiAlignedBits--)
-    {
-      WRITE_FLAG(0, "alignment_bit" );
-    }
-  }
+  assert (sei.activeSeqParameterSetId.size() == (sei.numSpsIdsMinus1 + 1));
+
+  for (Int i = 0; i < sei.activeSeqParameterSetId.size(); i++)
+    {
+    WRITE_UVLC(sei.activeSeqParameterSetId[i], "active_seq_parameter_set_id"); 
+  }
+  xWriteByteAlign();
 }
 
@@ -478,4 +467,9 @@
         {
           WRITE_CODE( sei.m_cameraIsoSpeedValue,    32,    "camera_iso_speed_value" );
+        }
+        WRITE_CODE( sei.m_exposureIndexIdc,     8,    "exposure_index_idc" );
+        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
+        {
+          WRITE_CODE( sei.m_exposureIndexValue,     32,    "exposure_index_value" );
         }
         WRITE_FLAG( sei.m_exposureCompensationValueSignFlag,           "exposure_compensation_value_sign_flag" );
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 951)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 964)
@@ -140,4 +140,5 @@
     WRITE_UVLC( rps->getNumberOfNegativePictures(), "num_negative_pics" );
     WRITE_UVLC( rps->getNumberOfPositivePictures(), "num_positive_pics" );
+
     Int prev = 0;
     for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++)
@@ -276,5 +277,9 @@
         pcPPS->getLayerId() != 1  )
     {
-        pcPPS->setPpsExtensionTypeFlag( PPS_EX_T_3D, false );
+#if H_MV_HLS_8_SPS_NODOC_48
+      pcPPS->setPps3dExtensionFlag( false ); 
+#else
+      pcPPS->setPpsExtensionTypeFlag( PPS_EX_T_3D, false );
+#endif
     }
   #endif
@@ -283,6 +288,35 @@
   WRITE_FLAG( 0, "pps_extension_flag" );
 #else
-  WRITE_FLAG( 1, "pps_extension_flag" );
-
+  WRITE_FLAG( 1, "pps_extension_present_flag" );
+
+#if H_MV_HLS_8_SPS_NODOC_48
+    WRITE_FLAG( pcPPS->getPpsRangeExtensionsFlag( ) ? 1 : 0 , "pps_range_extensions_flag" );
+    WRITE_FLAG( pcPPS->getPpsMultilayerExtensionFlag( ) ? 1 : 0 , "pps_multilayer_extension_flag" );
+#if !H_3D
+    WRITE_CODE( pcPPS->getPpsExtension6bits( ), 6, "pps_extension_6bits" );
+#else
+    WRITE_FLAG( pcPPS->getPps3dExtensionFlag( ) ? 1 : 0 , "pps_3d_extension_flag" );
+    WRITE_CODE( pcPPS->getPpsExtension5bits( ), 5, "pps_extension_5bits" );
+#endif
+    if ( pcPPS->getPpsRangeExtensionsFlag() )
+    { 
+      assert(0); 
+    }
+
+    if ( pcPPS->getPpsMultilayerExtensionFlag() )
+    { 
+      WRITE_FLAG( pcPPS->getPocResetInfoPresentFlag( ) ? 1 : 0 , "poc_reset_info_present_flag" );
+#if H_MV_HLS_8_PPS_NODOC_NN
+      WRITE_FLAG( 0, "pps_extension_reserved_zero_flag" );
+#endif
+    }
+
+#if H_3D
+    if( pcPPS->getPps3dExtensionFlag( )  ) // This probably needs to be aligned with Rext and SHVC
+    {
+      codePPSExtension( pcPPS ); 
+    }
+#endif
+#else
   for ( Int i = 0; i < PPS_EX_T_MAX_NUM; i++ )
   {
@@ -305,4 +339,5 @@
     codePPSExtension( pcPPS ); 
   }
+#endif
 #endif
 
@@ -822,8 +857,37 @@
   WRITE_FLAG( 0, "sps_extension_flag" );
 #else
-  WRITE_FLAG( pcSPS->getSpsExtensionFlag(), "sps_extension_flag" );
-
-  if ( pcSPS->getSpsExtensionFlag() )
-  {
+  WRITE_FLAG( pcSPS->getSpsExtensionPresentFlag(), "sps_extension_present_flag" );
+
+  if ( pcSPS->getSpsExtensionPresentFlag() )
+  {
+#if H_MV_HLS_8_SPS_NODOC_48
+    WRITE_FLAG( pcSPS->getSpsRangeExtensionsFlag( ) ? 1 : 0 , "sps_range_extensions_flag" );
+    WRITE_FLAG( pcSPS->getSpsMultilayerExtensionFlag( ) ? 1 : 0 , "sps_multilayer_extension_flag" );
+#if !H_3D
+    WRITE_CODE( pcSPS->getSpsExtension6bits( ), 6, "sps_extension_6bits" );
+#else
+    WRITE_FLAG( pcSPS->getSps3dExtensionFlag( ) ? 1 : 0 , "sps_3d_extension_flag" );
+    WRITE_CODE( pcSPS->getSpsExtension5bits( ), 5, "sps_extension_5bits" );
+#endif
+ }
+
+  if ( pcSPS->getSpsRangeExtensionsFlag() )
+  {
+    assert( 0 ); 
+  }
+
+  if ( pcSPS->getSpsMultilayerExtensionFlag() )
+  {
+    codeSPSExtension( pcSPS ); 
+  }
+
+#if H_3D
+  if ( pcSPS->getSps3dExtensionFlag() )
+  {
+    codeSPSExtension2( pcSPS, viewIndex, depthFlag  ); 
+  }
+
+#endif
+#else
     for (Int i = 0; i < PS_EX_T_MAX_NUM; i++)
     {
@@ -848,4 +912,5 @@
 #endif
   }
+#endif
 #endif
 }
@@ -890,5 +955,10 @@
 {
   WRITE_CODE( pcVPS->getVPSId(),                    4,        "vps_video_parameter_set_id" );
+#if H_MV_HLS_8_SYN_Q0041_03
+  WRITE_FLAG( pcVPS->getVpsBaseLayerInternalFlag( ) ? 1 : 0 , "vps_base_layer_internal_flag" );
+  WRITE_FLAG( 1                                             , "vps_reserved_one_bit" );
+#else
   WRITE_CODE( 3,                                    2,        "vps_reserved_three_2bits" );
+#endif
 #if H_MV
   WRITE_CODE( pcVPS->getMaxLayersMinus1(),       6,        "vps_max_layers_minus1" );
@@ -972,5 +1042,9 @@
   }
 #if H_MV
+#if H_MV_HLS_8_RPS_Q0100_36
+  WRITE_FLAG( pcVPS->getVpsExtensionFlag(),                     "vps_extension_flag" );
+#else
   WRITE_FLAG( 1,                     "vps_extension_flag" );
+#endif
   m_pcBitIf->writeAlignOne();
   codeVPSExtension( pcVPS );                           
@@ -996,5 +1070,9 @@
 Void TEncCavlc::codeVPSExtension( TComVPS *pcVPS ) 
 {
+  
+#if !H_MV_HLS_8_SYN_Q0041_03
   WRITE_FLAG( pcVPS->getAvcBaseLayerFlag() ? 1 : 0,          "avc_base_layer_flag" );
+#endif
+
   WRITE_FLAG( pcVPS->getSplittingFlag() ? 1 : 0,             "splitting_flag" );
 
@@ -1010,5 +1088,5 @@
 
   if ( pcVPS->getSplittingFlag() )
-  { // Ignore old dimension id length
+  {
     pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1 ,pcVPS->inferLastDimsionIdLenMinus1() + 1 );       
   }    
@@ -1042,5 +1120,4 @@
   }
 
-
   WRITE_CODE( pcVPS->getViewIdLen( ), 4, "view_id_len" );
 
@@ -1068,4 +1145,5 @@
     }
   }
+
   WRITE_FLAG( pcVPS->getVpsSubLayersMaxMinus1PresentFlag( ) ? 1 : 0 , "vps_sub_layers_max_minus1_present_flag" );
   if ( pcVPS->getVpsSubLayersMaxMinus1PresentFlag() )
@@ -1109,25 +1187,50 @@
   }
 
-  WRITE_UVLC( pcVPS->getNumAddOutputLayerSets( ), "num_add_output_layer_sets" );
+#if H_MV_HLS_8_SYN_39_19
+  if ( pcVPS->getNumIndependentLayers() > 1 ) 
+  {
+   WRITE_UVLC( pcVPS->getNumAddLayerSets( ), "num_add_layer_sets" );
+  }
+  for (Int i = 0; i < pcVPS->getNumAddLayerSets(); i++)
+  {
+    for (Int j = 0; j < pcVPS->getNumIndependentLayers(); j++)
+    {
+      WRITE_CODE( pcVPS->getHighestLayerIdxPlus1( i, j ), pcVPS->getHighestLayerIdxPlus1Len( j )  , "highest_layer_idx_plus1" );
+    }
+  }
+  if (pcVPS->getNumLayerSets() > 1)
+  {
+    WRITE_UVLC( pcVPS->getNumAddOlss( ), "num_add_olss" );
+    WRITE_CODE( pcVPS->getDefaultOutputLayerIdc( ), 2, "default_output_layer_idc" );
+  }
+#else
+  WRITE_UVLC( pcVPS->getNumAddLayerSets( ), "num_add_layer_sets" );
 
   if( pcVPS->getNumOutputLayerSets() > 1)
   {
-    WRITE_CODE( pcVPS->getDefaultTargetOutputLayerIdc( ), 2, "default_target_output_layer_idc" );
+    WRITE_CODE( pcVPS->getDefaultOutputLayerIdc( ), 2, "default_output_layer_idc" );
   }  
-
+#endif
 
   assert( pcVPS->getOutputLayerFlag(0, 0) == pcVPS->inferOutputLayerFlag( 0, 0 )); 
-  assert( pcVPS->getOutputLayerSetIdxMinus1( 0 ) == -1 ); 
+  assert( pcVPS->getLayerSetIdxForOlsMinus1( 0 ) == -1 ); 
+
+
+
 
   for( Int i = 1; i < pcVPS->getNumOutputLayerSets( ); i++ )
   {
+#if H_MV_HLS_8_SYN_39_19
+    if( i >= pcVPS->getNumLayerSets( ) )    
+#else
     if( i > pcVPS->getVpsNumLayerSetsMinus1( ) )    
+#endif
     {      
-      WRITE_UVLC( pcVPS->getOutputLayerSetIdxMinus1( i ),      "output_layer_set_idx_minus1[i]" );
-    }
-
-    if ( i > pcVPS->getVpsNumLayerSetsMinus1() || pcVPS->getDefaultTargetOutputLayerIdc() == 2 )
+      WRITE_UVLC( pcVPS->getLayerSetIdxForOlsMinus1( i ),      "layer_set_idx_for_ols_minus1[i]" );
+    }
+
+    if ( i > pcVPS->getVpsNumLayerSetsMinus1() || pcVPS->getDefaultOutputLayerIdc() == 2 )
     {       
-      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->getLayerSetIdxForOutputLayerSet( i ) ); j++ )
+      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->olsIdxToLsIdx( i ) ); j++ )
       {
         WRITE_FLAG( pcVPS->getOutputLayerFlag( i, j) ? 1 : 0, "output_layer_flag" );
@@ -1136,9 +1239,10 @@
     else
     {
-      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->getLayerSetIdxForOutputLayerSet( i ) ) - 1; j++ )
+      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->olsIdxToLsIdx( i ) ) - 1; j++ )
       {              
         assert( pcVPS->getOutputLayerFlag( i , j ) == pcVPS->inferOutputLayerFlag( i, j )); 
       }
     }        
+
 
     if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
@@ -1152,4 +1256,5 @@
   }
 
+#if !H_MV_HLS_8_PMS_Q0195_20
   WRITE_FLAG( pcVPS->getRepFormatIdxPresentFlag( ) ? 1 : 0 , "rep_format_idx_present_flag" );
   if ( pcVPS->getRepFormatIdxPresentFlag() )
@@ -1157,22 +1262,55 @@
     WRITE_UVLC( pcVPS->getVpsNumRepFormatsMinus1( ), "vps_num_rep_formats_minus1" );
   }
+#else
+  WRITE_UVLC( pcVPS->getVpsNumRepFormatsMinus1( ), "vps_num_rep_formats_minus1" );
+#endif
 
   for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
   {    
+
     TComRepFormat* curRepFormat = pcVPS->getRepFormat(i);     
     TComRepFormat* prevRepFormat = i > 0 ? pcVPS->getRepFormat( i - 1) : NULL; 
     codeRepFormat( i, curRepFormat ,  prevRepFormat); 
-  }
-
+
+  }
+
+#if H_MV_HLS_8_PMS_Q0195_20
+  if ( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
+  {
+    WRITE_FLAG( pcVPS->getRepFormatIdxPresentFlag( ) ? 1 : 0 , "rep_format_idx_present_flag" );
+  }
+#endif
   if( pcVPS->getRepFormatIdxPresentFlag() ) 
   {
+#if H_MV_HLS_8_SYN_Q0041_03
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 1 : 0; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+#else
     for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
-    {
+#endif
+    {
+#if !H_MV_HLS_8_PMS_Q0195_20
       if( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
       {
+#endif
         WRITE_CODE( pcVPS->getVpsRepFormatIdx(i), pcVPS->getVpsRepFormatIdxLen(), "vps_rep_format_idx[i]" );
-      }
-    }
-  }
+#if !H_MV_HLS_8_PMS_Q0195_20
+      }
+#endif
+    }
+  }
+#if H_MV_HLS_8_PMS_Q0195_20
+  else
+  {
+#if H_MV_HLS_8_SYN_Q0041_03
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 1 : 0; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+#else
+    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+#endif
+    {
+      assert( pcVPS->getVpsRepFormatIdx( i ) ==  pcVPS->inferVpsRepFormatIdx( i ) );
+    }
+  }
+#endif
+
 
   WRITE_FLAG( pcVPS->getMaxOneActiveRefLayerFlag( ) ? 1 : 0, "max_one_active_ref_layer_flag" );
@@ -1187,4 +1325,5 @@
     }
   }
+
   WRITE_FLAG( 0, "vps_reserved_zero_flag" );
   codeDpbSize( pcVPS ); 
@@ -1193,5 +1332,4 @@
 
   WRITE_FLAG( pcVPS->getDefaultDirectDependencyFlag( ) ? 1 : 0 , "default_direct_dependency_flag" );
-
   if ( pcVPS->getDefaultDirectDependencyFlag( ) )
   {  
@@ -1199,7 +1337,13 @@
   }
 
+#if H_MV_HLS_8_SYN_Q0041_03
+  for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ?  1 : 2; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    for( Int j = pcVPS->getVpsBaseLayerInternalFlag() ?  0 : 1; j < i; j++ )
+#else
   for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
   {
     for( Int j = 0; j < i; j++ )
+#endif
     {
       if (pcVPS->getDirectDependencyFlag( i, j) )
@@ -1218,5 +1362,9 @@
   }  
   WRITE_UVLC( 0, "vps_non_vui_extension_length" );
-  WRITE_FLAG( pcVPS->getVpsVuiPresentFlag() ? 1 : 0 , "vps_vui_present_flag" );
+  
+
+
+
+WRITE_FLAG( pcVPS->getVpsVuiPresentFlag() ? 1 : 0 , "vps_vui_present_flag" );
   if( pcVPS->getVpsVuiPresentFlag() )
   {
@@ -1229,4 +1377,5 @@
     pcVPSVUI->inferVpsVui( true ); 
   }
+
 }
 
@@ -1248,6 +1397,13 @@
   for( Int i = 1; i < vps->getNumOutputLayerSets(); i++ )
   {  
+#if H_MV_HLS_8_MIS_Q0102_30
+    Int currLsIdx = vps->olsIdxToLsIdx( i ); 
+#endif
     WRITE_FLAG( dpbSize->getSubLayerFlagInfoPresentFlag( i ) ? 1 : 0 , "sub_layer_flag_info_present_flag" );
+#if H_MV_HLS_8_MIS_Q0102_30
+    for( Int j = 0; j  <=  vps->getMaxSubLayersInLayerSetMinus1( currLsIdx ); j++ )
+#else
     for( Int j = 0; j  <=  vps->getMaxSubLayersInLayerSetMinus1( i ); j++ )
+#endif
     {  
       if( j > 0  &&  dpbSize->getSubLayerDpbInfoPresentFlag( i, j )  )  
@@ -1257,18 +1413,13 @@
       if( dpbSize->getSubLayerDpbInfoPresentFlag( i, j ) )
       {  
-        for( Int k = 0; k < vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i )); k++ )   
+#if H_MV_HLS_8_MIS_Q0102_30
+        for( Int k = 0; k < vps->getNumLayersInIdList( currLsIdx ); k++ )   
+#else
+        for( Int k = 0; k < vps->getNumSubDpbs( vps->olsIdxToLsIdx( i )); k++ )   
+#endif
         {
           WRITE_UVLC( dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j ), "max_vps_dec_pic_buffering_minus1" );
         }
         WRITE_UVLC( dpbSize->getMaxVpsNumReorderPics( i, j ), "max_vps_num_reorder_pics" );
-#if H_MV_HLS7_GEN
-        if( vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i ) ) != vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ) ) 
-        {
-          for( Int k = 0; k < vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ); k++ )
-          {
-            WRITE_UVLC( dpbSize->getMaxVpsLayerDecPicBuffMinus1( i, k, j ), "max_vps_layer_dec_pic_buff_minus1" );
-          }
-        }
-#endif
         WRITE_UVLC( dpbSize->getMaxVpsLatencyIncreasePlus1( i, j ), "max_vps_latency_increase_plus1" );
       }
@@ -1277,5 +1428,9 @@
         if ( j > 0 )
         {
-          for( Int k = 0; k < vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i ) ); k++ )   
+#if H_MV_HLS_8_DBP_NODOC_42
+          for( Int k = 0; k < vps->getNumLayersInIdList( vps->olsIdxToLsIdx( i ) ); k++ )   
+#else
+          for( Int k = 0; k < vps->getNumSubDpbs( vps->olsIdxToLsIdx( i ) ); k++ )   
+#endif
           {
             assert( dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j ) == dpbSize->getMaxVpsDecPicBufferingMinus1( i,k, j - 1 ) );
@@ -1285,6 +1440,6 @@
         }
       }
-    }        
-  }  
+    }
+  }
 }
 
@@ -1324,4 +1479,5 @@
   assert( pcVPSVUI ); 
 
+
   WRITE_FLAG( pcVPSVUI->getCrossLayerPicTypeAlignedFlag( ) ? 1 : 0 , "cross_layer_pic_type_aligned_flag" );
   if ( !pcVPSVUI->getCrossLayerPicTypeAlignedFlag() )
@@ -1337,7 +1493,15 @@
   if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
   {
+#if H_MV_HLS_8_SYN_Q0041_03
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <=  pcVPS->getVpsNumLayerSetsMinus1(); i++ )
+#else
     for( Int i = 0; i  <=  pcVPS->getVpsNumLayerSetsMinus1(); i++ )
-    {
+#endif
+    {
+#if H_MV_HLS_8_MIS_Q0102_30
+      for( Int j = 0; j  <=  pcVPS->getMaxSubLayersInLayerSetMinus1( i ); j++ ) 
+#else          
       for( Int j = 0; j  <=  pcVPS->getMaxTLayers(); j++ ) 
+#endif
       {
         if( pcVPSVUI->getBitRatePresentVpsFlag( ) )
@@ -1399,5 +1563,9 @@
   if( !pcVPSVUI->getTilesNotInUseFlag() ) 
   {      
+#if H_MV_HLS_8_SYN_Q0041_03
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+#else
     for( Int i = 0; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+#endif
     {
       WRITE_FLAG( pcVPSVUI->getTilesInUseFlag( i ) ? 1 : 0 , "tiles_in_use_flag[i]" );
@@ -1407,6 +1575,9 @@
       }
     }  
-
+#if H_MV_HLS_8_SYN_Q0041_03
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 1 : 2; i  <=  pcVPS->getMaxLayersMinus1(); i++ )  
+#else
     for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )  
+#endif
     {
       for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ) ; j++ )
@@ -1439,4 +1610,8 @@
       for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ )
       {
+#if H_MV_HLS_8_SYN_Q0041_03
+        if( pcVPS->getVpsBaseLayerInternalFlag() || pcVPS->getRefLayerId( pcVPS->getLayerIdInNuh( i ), j ) > 0 )
+        {        
+#endif
         WRITE_UVLC( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ), "min_spatial_segment_offset_plus1" );
         if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
@@ -1448,4 +1623,7 @@
           }
         }
+#if H_MV_HLS_8_SYN_Q0041_03
+        }
+#endif
       }
     }
@@ -1495,4 +1673,9 @@
     for( Int i = 0; i < vpsVuiBspHrdP->getNumBitstreamPartitions( h ); i++ )  
     {
+#if H_MV_HLS_8_HRD_Q0101_04
+      for( Int j = 0; j < pcVPS->getNumLayersInIdList( h ); j++ )  
+      {
+        WRITE_FLAG( vpsVuiBspHrdP->getLayerInBspFlag( h, i, j ) ? 1 : 0 , "layer_in_bsp_flag" );
+#else
       for( Int j = 0; j <= pcVPS->getMaxLayersMinus1(); j++ )  
       {
@@ -1505,4 +1688,5 @@
           vpsVuiBspHrdP->setLayerInBspFlag( h, i, j, false ); // This inference seems to be missing in spec 
         }
+#endif
       }
     }
@@ -1510,12 +1694,24 @@
 
     if( vpsVuiBspHrdP->getNumBitstreamPartitions( h ) )
-    {  
-      WRITE_UVLC( vpsVuiBspHrdP->getNumBspSchedCombinations( h ), "num_bsp_sched_combinations" );
-      for( Int i = 0; i < vpsVuiBspHrdP->getNumBspSchedCombinations( h ); i++ )
+    { 
+      WRITE_UVLC( vpsVuiBspHrdP->getNumBspSchedCombinationsMinus1( h ), "num_bsp_sched_combinations_minus1" );
+#if H_MV_HLS_8_HRD_Q0182_05
+      for( Int i = 0; i <= vpsVuiBspHrdP->getNumBspSchedCombinationsMinus1( h ); i++ )
+#else
+      for( Int i = 0; i < vpsVuiBspHrdP->getNumBspSchedCombinationsMinus1( h ); i++ )
+#endif
       {
         for( Int j = 0; j < vpsVuiBspHrdP->getNumBitstreamPartitions( h ); j++ )
         {  
+#if H_MV_HLS_8_HRD_Q0101_04
+          WRITE_CODE( vpsVuiBspHrdP->getBspCombHrdIdx( h, i, j ),  vpsVuiBspHrdP->getBspCombHrdIdxLen(), "bsp_comb_hrd_idx" ); 
+#else
           WRITE_UVLC( vpsVuiBspHrdP->getBspCombHrdIdx( h, i, j ), "bsp_comb_hrd_idx" );
+#endif
           WRITE_UVLC( vpsVuiBspHrdP->getBspCombSchedIdx( h, i, j ), "bsp_comb_sched_idx" );
+
+#if H_MV_HLS_8_HRD_Q0101_04
+          vpsVuiBspHrdP->checkBspCombHrdAndShedIdx( pcVPS, h, i, j ); 
+#endif
         }  
       }
@@ -1636,5 +1832,9 @@
   if ( pcSlice->getRapPicFlag() )
   {
+#if SETTING_NO_OUT_PIC_PRIOR
+    WRITE_FLAG( pcSlice->getNoOutputPriorPicsFlag() ? 1 : 0, "no_output_of_prior_pics_flag" );
+#else
     WRITE_FLAG( 0, "no_output_of_prior_pics_flag" );
+#endif
   }
 #if PPS_FIX_DEPTH
@@ -1707,5 +1907,9 @@
       Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
       WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "slice_pic_order_cnt_lsb");
-    }
+#if H_MV_HLS_8_POC_Q0142_32
+      pcSlice->setSlicePicOrderCntLsb( picOrderCntLSB ); 
+#endif
+    }
+
 #endif
     if( !pcSlice->getIdrPicFlag() )
@@ -2137,4 +2341,8 @@
     }
 
+#if H_MV_HLS_8_POC_Q0142_32
+    pcSlice->checkPocResetIdc(); 
+#endif
+
     if( pcSlice->getPocResetIdc() !=  0 )
     {
@@ -2147,9 +2355,18 @@
       WRITE_CODE( pcSlice->getPocLsbVal( ), pcSlice->getPocLsbValLen() , "poc_lsb_val" );
     }              
-    
+#if H_MV_HLS_8_POC_Q0142_32
+    pcSlice->checkPocLsbVal(); 
+#endif
+
     if( !pcSlice->getPocMsbValRequiredFlag() /* TODO &&  pcSlice->getVPS()->getVpsPocLsbAlignedFlag() */ )
     {
       WRITE_FLAG( pcSlice->getPocMsbValPresentFlag( ) ? 1 : 0 , "poc_msb_val_present_flag" );
     }
+#if H_MV_HLS_8_POC_Q0146_15
+    else
+    {
+      assert( pcSlice->getPocMsbValPresentFlag() ==  pcSlice->inferPocMsbValPresentFlag( ) ); 
+    }
+#endif
     
     if( pcSlice->getPocMsbValPresentFlag() )
Index: trunk/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 951)
+++ trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 964)
@@ -256,4 +256,6 @@
   Int       m_cameraIsoSpeedIdc;
   Int       m_cameraIsoSpeedValue;
+  Int       m_exposureIndexIdc;
+  Int       m_exposureIndexValue;
   Int       m_exposureCompensationValueSignFlag;
   Int       m_exposureCompensationValueNumerator;
@@ -495,5 +497,5 @@
   Void      setMaxRefPicNum                 ( Int iMaxRefPicNum )           { m_iMaxRefPicNum = iMaxRefPicNum;  }
 
-  Bool      getMaxTempLayer                 ()                              { return m_maxTempLayer;              } 
+  Int       getMaxTempLayer                 ()                              { return m_maxTempLayer;              } 
   Void      setMaxTempLayer                 ( Int maxTempLayer )            { m_maxTempLayer = maxTempLayer;      }
 
@@ -753,4 +755,8 @@
   Void  setTMISEICameraIsoSpeedValue(Int b)                  {  m_cameraIsoSpeedValue = b;  }
   Int   getTMISEICameraIsoSpeedValue()                       {  return m_cameraIsoSpeedValue;  }
+  Void  setTMISEIExposureIndexIdc(Int b)                     {  m_exposureIndexIdc = b;  }
+  Int   getTMISEIExposurIndexIdc()                           {  return m_exposureIndexIdc;  }
+  Void  setTMISEIExposureIndexValue(Int b)                   {  m_exposureIndexValue = b;  }
+  Int   getTMISEIExposurIndexValue()                         {  return m_exposureIndexValue;  }
   Void  setTMISEIExposureCompensationValueSignFlag(Int b)    {  m_exposureCompensationValueSignFlag = b;  }
   Int   getTMISEIExposureCompensationValueSignFlag()         {  return m_exposureCompensationValueSignFlag;  }
Index: trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 951)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 964)
@@ -75,4 +75,7 @@
   m_iNumPicCoded        = 0; //Niko
   m_bFirst              = true;
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  m_iLastRecoveryPicPOC = 0;
+#endif
   
   m_pcCfg               = NULL;
@@ -167,9 +170,9 @@
   SEIActiveParameterSets *seiActiveParameterSets = new SEIActiveParameterSets(); 
   seiActiveParameterSets->activeVPSId = m_pcCfg->getVPS()->getVPSId(); 
-  seiActiveParameterSets->m_fullRandomAccessFlag = false;
-  seiActiveParameterSets->m_noParamSetUpdateFlag = false;
+  seiActiveParameterSets->m_selfContainedCvsFlag = false;
+  seiActiveParameterSets->m_noParameterSetUpdateFlag = false;
   seiActiveParameterSets->numSpsIdsMinus1 = 0;
-  seiActiveParameterSets->activeSeqParamSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1); 
-  seiActiveParameterSets->activeSeqParamSetId[0] = sps->getSPSId();
+  seiActiveParameterSets->activeSeqParameterSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1); 
+  seiActiveParameterSets->activeSeqParameterSetId[0] = sps->getSPSId();
   return seiActiveParameterSets;
 }
@@ -274,4 +277,7 @@
        seiToneMappingInfo->m_cameraIsoSpeedValue = m_pcCfg->getTMISEICameraIsoSpeedValue();
        assert( seiToneMappingInfo->m_cameraIsoSpeedValue !=0 );
+       seiToneMappingInfo->m_exposureIndexIdc = m_pcCfg->getTMISEIExposurIndexIdc();
+       seiToneMappingInfo->m_exposureIndexValue = m_pcCfg->getTMISEIExposurIndexValue();
+       assert( seiToneMappingInfo->m_exposureIndexValue !=0 );
        seiToneMappingInfo->m_exposureCompensationValueSignFlag = m_pcCfg->getTMISEIExposureCompensationValueSignFlag();
        seiToneMappingInfo->m_exposureCompensationValueNumerator = m_pcCfg->getTMISEIExposureCompensationValueNumerator();
@@ -428,8 +434,83 @@
   UInt *accumNalsDU = NULL;
   SEIDecodingUnitInfo decodingUnitInfoSEI;
+#if EFFICIENT_FIELD_IRAP
+  Int IRAPGOPid = -1;
+  Bool IRAPtoReorder = false;
+  Bool swapIRAPForward = false;
+  if(isField)
+  {
+    Int pocCurr;
+#if !H_MV
+    for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ )
+#endif
+    {
+      // determine actual POC
+      if(iPOCLast == 0) //case first frame or first top field
+      {
+        pocCurr=0;
+      }
+      else if(iPOCLast == 1 && isField) //case first bottom field, just like the first frame, the poc computation is not right anymore, we set the right value
+      {
+        pocCurr = 1;
+      }
+      else
+      {
+        pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - isField;
+      }
+
+      // check if POC corresponds to IRAP
+      NalUnitType tmpUnitType = getNalUnitType(pocCurr, m_iLastIDR, isField);
+      if(tmpUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP && tmpUnitType <= NAL_UNIT_CODED_SLICE_CRA) // if picture is an IRAP
+      {
+        if(pocCurr%2 == 0 && iGOPid < m_iGopSize-1 && m_pcCfg->getGOPEntry(iGOPid).m_POC == m_pcCfg->getGOPEntry(iGOPid+1).m_POC-1)
+        { // if top field and following picture in enc order is associated bottom field
+          IRAPGOPid = iGOPid;
+          IRAPtoReorder = true;
+          swapIRAPForward = true; 
+          break;
+        }
+        if(pocCurr%2 != 0 && iGOPid > 0 && m_pcCfg->getGOPEntry(iGOPid).m_POC == m_pcCfg->getGOPEntry(iGOPid-1).m_POC+1)
+        {
+          // if picture is an IRAP remember to process it first
+          IRAPGOPid = iGOPid;
+          IRAPtoReorder = true;
+          swapIRAPForward = false; 
+          break;
+        }
+      }
+    }
+  }
+#endif
 #if !H_MV
   for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ )
 #endif
   {
+#if EFFICIENT_FIELD_IRAP
+    if(IRAPtoReorder)
+    {
+      if(swapIRAPForward)
+      {
+        if(iGOPid == IRAPGOPid)
+        {
+          iGOPid = IRAPGOPid +1;
+        }
+        else if(iGOPid == IRAPGOPid +1)
+        {
+          iGOPid = IRAPGOPid;
+        }
+      }
+      else
+      {
+        if(iGOPid == IRAPGOPid -1)
+        {
+          iGOPid = IRAPGOPid;
+        }
+        else if(iGOPid == IRAPGOPid)
+        {
+          iGOPid = IRAPGOPid -1;
+        }
+      }
+    }
+#endif
     UInt uiColDir = 1;
     //-- For time output for each slice
@@ -500,4 +581,33 @@
     if(pocCurr>=m_pcCfg->getFramesToBeEncoded())
     {
+#if EFFICIENT_FIELD_IRAP
+      if(IRAPtoReorder)
+      {
+        if(swapIRAPForward)
+        {
+          if(iGOPid == IRAPGOPid)
+          {
+            iGOPid = IRAPGOPid +1;
+            IRAPtoReorder = false;
+          }
+          else if(iGOPid == IRAPGOPid +1)
+          {
+            iGOPid --;
+          }
+        }
+        else
+        {
+          if(iGOPid == IRAPGOPid)
+          {
+            iGOPid = IRAPGOPid -1;
+          }
+          else if(iGOPid == IRAPGOPid -1)
+          {
+            iGOPid = IRAPGOPid;
+            IRAPtoReorder = false;
+          }
+        }
+      }
+#endif
 #if H_MV
       delete pcBitstreamRedirect;
@@ -635,8 +745,5 @@
     }
 
-    // Do decoding refresh marking if any 
-    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic);
-    m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid);
-    pcSlice->getRPS()->setNumberOfLongtermPictures(0);
+#if EFFICIENT_FIELD_IRAP
 #if FIX1172
     if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
@@ -653,9 +760,42 @@
     pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC);
 #endif
-
+#endif
+    // Do decoding refresh marking if any 
+    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic);
+    m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid);
+    pcSlice->getRPS()->setNumberOfLongtermPictures(0);
+#if EFFICIENT_FIELD_IRAP
+#else
+#if FIX1172
+    if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
+      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
+      || 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 )  // IRAP picture
+    {
+      m_associatedIRAPType = pcSlice->getNalUnitType();
+      m_associatedIRAPPOC = pocCurr;
+    }
+    pcSlice->setAssociatedIRAPType(m_associatedIRAPType);
+    pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC);
+#endif
+#endif
+
+#if ALLOW_RECOVERY_POINT_AS_RAP
+    if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false, m_iLastRecoveryPicPOC, m_pcCfg->getDecodingRefreshType() == 3) != 0) || (pcSlice->isIRAP()) 
+#if EFFICIENT_FIELD_IRAP
+      || (isField && pcSlice->getAssociatedIRAPType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getAssociatedIRAPType() <= NAL_UNIT_CODED_SLICE_CRA && pcSlice->getAssociatedIRAPPOC() == pcSlice->getPOC()+1)
+#endif
+      )
+    {
+      pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP(), m_iLastRecoveryPicPOC, m_pcCfg->getDecodingRefreshType() == 3);
+    }
+#else
     if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP()))
     {
       pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP());
     }
+#endif
     pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS());
 
@@ -1411,5 +1551,12 @@
       }
       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 .
-      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded;
+      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(pcSlice->getSPS()->getMaxTLayers()-1) + pcSlice->getPOC() - m_totalCoded;
+#if EFFICIENT_FIELD_IRAP
+      if(IRAPGOPid > 0 && IRAPGOPid < m_iGopSize)
+      {
+        // if pictures have been swapped there is likely one more picture delay on their tid. Very rough approximation
+        pictureTimingSEI.m_picDpbOutputDelay ++;
+      }
+#endif
       Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2;
       pictureTimingSEI.m_picDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay;
@@ -1518,4 +1665,10 @@
       sei_recovery_point.m_exactMatchingFlag = ( pcSlice->getPOC() == 0 ) ? (true) : (false);
       sei_recovery_point.m_brokenLinkFlag    = false;
+#if ALLOW_RECOVERY_POINT_AS_RAP
+      if(m_pcCfg->getDecodingRefreshType() == 3)
+      {
+        m_iLastRecoveryPicPOC = pocCurr;
+      }
+#endif
 
       m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_recovery_point, pcSlice->getSPS() );
@@ -1641,4 +1794,23 @@
           }
           m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+
+#if SETTING_NO_OUT_PIC_PRIOR
+          if (pcSlice->isIRAP())
+          {
+            if (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP)
+            {
+              pcSlice->setNoRaslOutputFlag(true);
+            }
+            //the inference for NoOutputPriorPicsFlag
+            if (!m_bFirst && pcSlice->isIRAP() && pcSlice->getNoRaslOutputFlag())
+            {
+              if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
+              {
+                pcSlice->setNoOutputPriorPicsFlag(true);
+              }
+            }
+          }
+#endif
+
           tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits();
           m_pcEntropyCoder->encodeSliceHeader(pcSlice);
@@ -2153,5 +2325,7 @@
       std::vector<Int> temp; 
       TComSlice::markCurrPic( pcPic ); 
+#if !H_MV_HLS_8_DBP_NODOC_42
       TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, temp, pcPic->getSlice(0)->getVPS(), m_layerId, pcPic->getPOC() ); 
+#endif
 #endif
       m_bFirst = false;
@@ -2163,4 +2337,34 @@
 
       delete[] pcSubstreamsOut;
+
+#if EFFICIENT_FIELD_IRAP
+    if(IRAPtoReorder)
+    {
+      if(swapIRAPForward)
+      {
+        if(iGOPid == IRAPGOPid)
+        {
+          iGOPid = IRAPGOPid +1;
+          IRAPtoReorder = false;
+        }
+        else if(iGOPid == IRAPGOPid +1)
+        {
+          iGOPid --;
+        }
+      }
+      else
+      {
+        if(iGOPid == IRAPGOPid)
+        {
+          iGOPid = IRAPGOPid -1;
+        }
+        else if(iGOPid == IRAPGOPid -1)
+        {
+          iGOPid = IRAPGOPid;
+          IRAPtoReorder = false;
+        }
+      }
+    }
+#endif
   }
   delete pcBitstreamRedirect;
@@ -2435,5 +2639,7 @@
     case NAL_UNIT_CODED_SLICE_CRA: return "CRA";
     case NAL_UNIT_CODED_SLICE_RADL_R:     return "RADL_R";
+    case NAL_UNIT_CODED_SLICE_RADL_N:     return "RADL_N";
     case NAL_UNIT_CODED_SLICE_RASL_R:     return "RASL_R";
+    case NAL_UNIT_CODED_SLICE_RASL_N:     return "RASL_N";
     case NAL_UNIT_VPS: return "VPS";
     case NAL_UNIT_SPS: return "SPS";
@@ -2838,5 +3044,17 @@
     return NAL_UNIT_CODED_SLICE_IDR_W_RADL;
   }
+#if EFFICIENT_FIELD_IRAP
+  if(isField && pocCurr == 1)
+  {
+    // to avoid the picture becoming an IRAP
+    return NAL_UNIT_CODED_SLICE_TRAIL_R;
+  }
+#endif
+
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  if(m_pcCfg->getDecodingRefreshType() != 3 && (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0)
+#else
   if ((pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0)
+#endif
   {
     if (m_pcCfg->getDecodingRefreshType() == 1)
Index: trunk/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 951)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 964)
@@ -85,4 +85,7 @@
   Int                     m_iNumPicCoded;
   Bool                    m_bFirst;
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  Int                     m_iLastRecoveryPicPOC;
+#endif
   
   //  Access channel
Index: trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 951)
+++ trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 964)
@@ -920,8 +920,16 @@
         for (y=0; y<endY; y++)
         {
+#if SAO_SGN_FUNC
+          signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]);
+#else
           signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
+#endif
           for (x=startX; x<endX; x++)
           {
+#if SAO_SGN_FUNC
+            signRight =  (Char)sgn(srcLine[x] - srcLine[x+1]);
+#else
             signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]]; 
+#endif
             edgeType  =  signRight + signLeft;
             signLeft  = -signRight;
@@ -943,8 +951,16 @@
             for(y=0; y<skipLinesB[typeIdx]; y++)
             {
+#if SAO_SGN_FUNC
+              signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]);
+#else
               signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
+#endif
               for (x=startX; x<endX; x++)
               {
+#if SAO_SGN_FUNC
+                signRight =  (Char)sgn(srcLine[x] - srcLine[x+1]);
+#else
                 signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]]; 
+#endif
                 edgeType  =  signRight + signLeft;
                 signLeft  = -signRight;
@@ -994,5 +1010,9 @@
 #endif
         {
+#if SAO_SGN_FUNC
+          signUpLine[x] = (Char)sgn(srcLine[x] - srcLineAbove[x]);
+#else
           signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
+#endif
         }
 
@@ -1008,5 +1028,9 @@
 #endif
           {
+#if SAO_SGN_FUNC
+            signDown  = (Char)sgn(srcLine[x] - srcLineBelow[x]); 
+#else
             signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]]; 
+#endif
             edgeType  = signDown + signUpLine[x];
             signUpLine[x]= -signDown;
@@ -1033,5 +1057,9 @@
               for (x=startX; x<endX; x++)
               {
+#if SAO_SGN_FUNC
+                edgeType = sgn(srcLine[x] - srcLineBelow[x]) + sgn(srcLine[x] - srcLineAbove[x]);
+#else
                 edgeType = m_sign[srcLine[x] - srcLineBelow[x]] + m_sign[srcLine[x] - srcLineAbove[x]];
+#endif
                 diff [edgeType] += (orgLine[x] - srcLine[x]);
                 count[edgeType] ++;
@@ -1076,5 +1104,9 @@
         for (x=startX; x<endX+1; x++)
         {
+#if SAO_SGN_FUNC
+          signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x-1]);
+#else
           signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x-1]];
+#endif
         }
 
@@ -1090,5 +1122,9 @@
         for(x=firstLineStartX; x<firstLineEndX; x++)
         {
+#if SAO_SGN_FUNC
+          edgeType = sgn(srcLine[x] - srcLineAbove[x-1]) - signUpLine[x+1];
+#else
           edgeType = m_sign[srcLine[x] - srcLineAbove[x-1]] - signUpLine[x+1];
+#endif
           diff [edgeType] += (orgLine[x] - srcLine[x]);
           count[edgeType] ++;
@@ -1105,5 +1141,9 @@
           for (x=startX; x<endX; x++)
           {
+#if SAO_SGN_FUNC
+            signDown = (Char)sgn(srcLine[x] - srcLineBelow[x+1]);
+#else
             signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+1]] ;
+#endif
             edgeType = signDown + signUpLine[x];
             diff [edgeType] += (orgLine[x] - srcLine[x]);
@@ -1112,5 +1152,9 @@
             signDownLine[x+1] = -signDown; 
           }
+#if SAO_SGN_FUNC
+          signDownLine[startX] = (Char)sgn(srcLineBelow[startX] - srcLine[startX-1]);
+#else
           signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
+#endif
 
           signTmpLine  = signUpLine;
@@ -1136,5 +1180,9 @@
               for (x=startX; x< endX; x++)
               {
+#if SAO_SGN_FUNC
+                edgeType = sgn(srcLine[x] - srcLineBelow[x+1]) + sgn(srcLine[x] - srcLineAbove[x-1]);
+#else
                 edgeType = m_sign[srcLine[x] - srcLineBelow[x+1]] + m_sign[srcLine[x] - srcLineAbove[x-1]];
+#endif
                 diff [edgeType] += (orgLine[x] - srcLine[x]);
                 count[edgeType] ++;
@@ -1174,5 +1222,9 @@
         for (x=startX-1; x<endX; x++)
         {
+#if SAO_SGN_FUNC
+          signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x+1]);
+#else
           signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
+#endif
         }
 
@@ -1193,5 +1245,9 @@
         for(x=firstLineStartX; x<firstLineEndX; x++)
         {
+#if SAO_SGN_FUNC
+          edgeType = sgn(srcLine[x] - srcLineAbove[x+1]) - signUpLine[x-1];
+#else
           edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] - signUpLine[x-1];
+#endif
           diff [edgeType] += (orgLine[x] - srcLine[x]);
           count[edgeType] ++;
@@ -1208,5 +1264,9 @@
           for(x=startX; x<endX; x++)
           {
+#if SAO_SGN_FUNC
+            signDown = (Char)sgn(srcLine[x] - srcLineBelow[x-1]);
+#else
             signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
+#endif
             edgeType = signDown + signUpLine[x];
 
@@ -1216,5 +1276,9 @@
             signUpLine[x-1] = -signDown; 
           }
+#if SAO_SGN_FUNC
+          signUpLine[endX-1] = (Char)sgn(srcLineBelow[endX-1] - srcLine[endX]);
+#else
           signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
+#endif
           srcLine  += srcStride;
           orgLine  += orgStride;
@@ -1235,5 +1299,9 @@
               for (x=startX; x<endX; x++)
               {
+#if SAO_SGN_FUNC
+                edgeType = sgn(srcLine[x] - srcLineBelow[x-1]) + sgn(srcLine[x] - srcLineAbove[x+1]);
+#else
                 edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + m_sign[srcLine[x] - srcLineAbove[x+1]];
+#endif
                 diff [edgeType] += (orgLine[x] - srcLine[x]);
                 count[edgeType] ++;
Index: trunk/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 951)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 964)
@@ -2809,5 +2809,5 @@
 {
   UInt    uiDepth        = pcCU->getDepth(0);
-  UInt    uiNumPU        = pcCU->getNumPartInter();
+  UInt    uiNumPU        = pcCU->getNumPartitions();
   UInt    uiInitTrDepth  = pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1;
   UInt    uiWidth        = pcCU->getWidth (0) >> uiInitTrDepth;
@@ -3971,5 +3971,5 @@
   TComMv        cMvTemp[2][33];
   
-  Int           iNumPart    = pcCU->getNumPartInter();
+  Int           iNumPart    = pcCU->getNumPartitions();
   Int           iNumPredDir = pcCU->getSlice()->isInterP() ? 1 : 2;
   
@@ -5644,14 +5644,5 @@
     
       m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
-#if 0 // check
-    {
-      m_pcEntropyCoder->resetBits();
-      m_pcEntropyCoder->encodeCoeff( pcCU, 0, pcCU->getDepth(0), pcCU->getWidth(0), pcCU->getHeight(0) );
-      const UInt uiBitsForCoeff = m_pcEntropyCoder->getNumberOfWrittenBits();
-        m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
-      if( uiBitsForCoeff != uiBits )
-        assert( 0 );
-    }
-#endif
+
     uiBits = 0;
     {
Index: trunk/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 951)
+++ trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 964)
@@ -221,5 +221,17 @@
   Int depth;
   {
+#if FIX_FIELD_DEPTH    
+    Int poc = rpcSlice->getPOC();
+    if(isField)
+    {
+      poc = (poc/2)%(m_pcCfg->getGOPSize()/2);
+    }
+    else
+    {
+      poc = poc%m_pcCfg->getGOPSize();   
+    }
+#else
     Int poc = rpcSlice->getPOC()%m_pcCfg->getGOPSize();
+#endif
     if ( poc == 0 )
     {
@@ -244,4 +256,17 @@
       }
     }
+#if FIX_FIELD_DEPTH  
+#if HARMONIZE_GOP_FIRST_FIELD_COUPLE
+    if(poc != 0)
+    {
+#endif
+    if(isField && rpcSlice->getPOC()%2 == 1)
+    {
+      depth ++;
+    }
+#if HARMONIZE_GOP_FIRST_FIELD_COUPLE
+  }
+#endif
+#endif
   }
   
@@ -266,8 +291,26 @@
   
   eSliceType=B_SLICE;
+#if EFFICIENT_FIELD_IRAP
+  if(!(isField && pocLast == 1))
+  {
+#endif // EFFICIENT_FIELD_IRAP
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  if(m_pcCfg->getDecodingRefreshType() == 3)
+  {
+    eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0             || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+  }
+  else
+  {
+    eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+  }
+#else
   eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+#endif
+#if EFFICIENT_FIELD_IRAP
+  }
+#endif
+#endif
   
   rpcSlice->setSliceType    ( eSliceType );
-#endif
 
   // ------------------------------------------------------------------------------------------------------------------
@@ -450,5 +493,24 @@
   }
 #else
-eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+#if EFFICIENT_FIELD_IRAP
+  if(!(isField && pocLast == 1))
+  {
+#endif // EFFICIENT_FIELD_IRAP
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  if(m_pcCfg->getDecodingRefreshType() == 3)
+  {
+    eSliceType = (pocLast == 0 || (pocCurr)           % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+
+  }
+  else
+  {
+  eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+  }
+#else
+  eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+#endif
+#if EFFICIENT_FIELD_IRAP
+  }
+#endif // EFFICIENT_FIELD_IRAP
 #endif
 
@@ -566,5 +628,7 @@
   // store lambda
   slice->setSliceQp( sliceQP );
+#if ADAPTIVE_QP_SELECTION
   slice->setSliceQpBase ( sliceQP );
+#endif
   m_pcRdCost ->setLambda( lambda );
   // for RDO
@@ -1105,5 +1169,7 @@
 
         m_pcRateCtrl->setRCQP( estQP );
+#if ADAPTIVE_QP_SELECTION
         pcCU->getSlice()->setSliceQpBase( estQP );
+#endif
       }
 
Index: trunk/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 951)
+++ trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 964)
@@ -697,8 +697,16 @@
   m_cSPS.setSpsInferScalingListFlag       ( m_layerId > 0 && m_cVPS->getInDirectDependencyFlag( getLayerIdInVps(), 0 ) ); 
   m_cSPS.setSpsScalingListRefLayerId      ( 0              ); 
-  m_cSPS.setSpsExtensionFlag              ( true ); 
+  m_cSPS.setSpsExtensionPresentFlag              ( true ); 
+#if H_MV_HLS_8_SPS_NODOC_48
+  m_cSPS.setSpsMultilayerExtensionFlag    ( true ); 
+#else
   m_cSPS.setSpsExtensionTypeFlag          ( PS_EX_T_MV ,true ); 
+#endif
 #if H_3D
+#if H_MV_HLS_8_SPS_NODOC_48
+  m_cSPS.setSps3dExtensionFlag            ( true ); 
+#else
   m_cSPS.setSpsExtensionTypeFlag          ( PS_EX_T_3D ,true ); 
+#endif
 #endif
 #endif
@@ -769,4 +777,20 @@
     m_cSPS.setNumReorderPics(m_numReorderPics[i], i);
   }
+#if H_MV_HLS_8_HRD_Q0102_08
+  for ( Int ols = 0; ols < m_cVPS->getNumOutputLayerSets(); ols++)
+  {
+    // Check MaxDecPicBuffering
+    const std::vector<Int>& targetDecLayerIdList = m_cVPS->getTargetDecLayerIdList( m_cVPS->olsIdxToLsIdx( ols )); 
+    for( Int is = 0; is < targetDecLayerIdList.size(); is++  )
+    {
+      m_cSPS.inferSpsMaxDecPicBufferingMinus1( m_cVPS, ols, targetDecLayerIdList[is], true );       
+    }
+  }
+
+#if H_MV_HLS_8_RPS_Q0100_36
+  m_cVPS->inferDbpSizeLayerSetZero( &m_cSPS, true ); 
+#endif
+
+#endif
   m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma);
   m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma);
@@ -829,8 +853,14 @@
   m_cPPS.setPPSId( getLayerIdInVps() );
   m_cPPS.setSPSId( getLayerIdInVps() );
-
+#if H_MV_HLS_8_SPS_NODOC_48
+  m_cPPS.setPpsMultilayerExtensionFlag    ( true ); 
+#if H_3D
+  m_cPPS.setPps3dExtensionFlag            ( true ); 
+#endif
+#else
   m_cPPS.setPpsExtensionTypeFlag          ( PPS_EX_T_MV ,true ); 
 #if H_3D
   m_cPPS.setPpsExtensionTypeFlag          ( PPS_EX_T_3D ,true ); 
+#endif
 #endif
 #endif
