Index: /trunk/source/App/TAppDecoder/TAppDecCfg.cpp
===================================================================
--- /trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 546)
+++ /trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 547)
@@ -144,4 +144,7 @@
   m_tgtLayerId = nLayerNum - 1;
   assert( m_tgtLayerId >= 0 );
+#if O0137_MAX_LAYERID
+  assert( m_tgtLayerId < MAX_NUM_LAYER_IDS );
+#endif
 #if OUTPUT_LAYER_SET_INDEX  
   this->getCommonDecoderParams()->setOutputLayerSetIdx( olsIdx       );
Index: /trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 546)
+++ /trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 547)
@@ -2579,10 +2579,10 @@
   printf("ENCODER_FAST_MODE: %d ", ENCODER_FAST_MODE);
   printf("REF_IDX_MFM: %d ", REF_IDX_MFM);
-#else
-  printf("RecalQP:%d", m_recalculateQPAccordingToLambda ? 1 : 0 );
-#endif
   printf("O0194_DIFFERENT_BITDEPTH_EL_BL: %d ", O0194_DIFFERENT_BITDEPTH_EL_BL);
   printf("O0194_JOINT_US_BITSHIFT: %d ", O0194_JOINT_US_BITSHIFT);
   printf("O0194_WEIGHTED_PREDICTION_CGS: %d ",O0194_WEIGHTED_PREDICTION_CGS);
+#else
+  printf("RecalQP:%d", m_recalculateQPAccordingToLambda ? 1 : 0 );
+#endif
   printf("\n\n");
   
Index: /trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 546)
+++ /trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 547)
@@ -1171,5 +1171,9 @@
   vps->setNumOutputLayerSets(vps->getNumLayerSets());
   vps->setNumProfileTierLevel(vps->getNumLayerSets());
+#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
+  vps->setDefaultOneTargetOutputLayerIdc(1);
+#else
   vps->setDefaultOneTargetOutputLayerFlag(true);
+#endif
   for(i = 1; i < vps->getNumLayerSets(); i++)
   {
Index: /trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 546)
+++ /trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 547)
@@ -2038,5 +2038,9 @@
 , m_moreOutputLayerSetsThanDefaultFlag (false)
 , m_numAddOutputLayerSets     (0)
+#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
+, m_defaultOneTargetOutputLayerIdc     (0)
+#else
 , m_defaultOneTargetOutputLayerFlag    (false)
+#endif
 #if VPS_VUI_BITRATE_PICRATE
 , m_bitRatePresentVpsFlag     (false)
@@ -2048,5 +2052,12 @@
 #endif
 #if VIEW_ID_RELATED_SIGNALING 
+#if O0109_VIEW_ID_LEN
+, m_viewIdLen                (0)
+#else
 , m_viewIdLenMinus1           (0)
+#endif
+#endif
+#if VPS_VUI_OFFSET
+, m_vpsVuiOffset (0)
 #endif
 {
Index: /trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComSlice.h	(revision 546)
+++ /trunk/source/Lib/TLibCommon/TComSlice.h	(revision 547)
@@ -540,5 +540,9 @@
   Bool       m_moreOutputLayerSetsThanDefaultFlag;
   Int        m_numAddOutputLayerSets;
+#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
+  UInt       m_defaultOneTargetOutputLayerIdc;
+#else
   Bool       m_defaultOneTargetOutputLayerFlag;
+#endif
   Int        m_profileLevelTierIdx[64];     
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
@@ -622,5 +626,9 @@
 #endif
 #if VIEW_ID_RELATED_SIGNALING 
+#if O0109_VIEW_ID_LEN
+  Int         m_viewIdLen;
+#else
   Int         m_viewIdLenMinus1;
+#endif
   Int         m_viewIdVal                [MAX_LAYERS];
 #endif
@@ -642,5 +650,13 @@
   Int     m_numSubDpbs                  [MAX_VPS_OP_LAYER_SETS_PLUS1];
 #endif
+
+#if O0109_MOVE_VPS_VUI_FLAG
+  Bool       m_vpsVuiPresentFlag;
+#endif
+
 #endif //SVC_EXTENSION
+#if VPS_VUI_OFFSET
+  Int     m_vpsVuiOffset;
+#endif
 public:
   TComVPS();
@@ -811,7 +827,11 @@
   Void   setNumAddOutputLayerSets(Int x)                         { m_numAddOutputLayerSets = x   ; }
 
+#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
+  UInt   getDefaultOneTargetOutputLayerIdc()                 { return m_defaultOneTargetOutputLayerIdc;}
+  Void   setDefaultOneTargetOutputLayerIdc(UInt x)           { m_defaultOneTargetOutputLayerIdc= x    ;}
+#else
   Bool   getDefaultOneTargetOutputLayerFlag()                 { return m_defaultOneTargetOutputLayerFlag;}
   Void   setDefaultOneTargetOutputLayerFlag(Bool x)           { m_defaultOneTargetOutputLayerFlag= x    ;}
-
+#endif
   Int    getProfileLevelTierIdx(Int i)                        { return m_profileLevelTierIdx[i]; }
   Void   setProfileLevelTierIdx(Int i, Int x)                 { m_profileLevelTierIdx[i] = x   ; }
@@ -946,6 +966,11 @@
 #endif
 #if VIEW_ID_RELATED_SIGNALING
+#if O0109_VIEW_ID_LEN
+  Void    setViewIdLen( Int  val )                                   { m_viewIdLen = val; } 
+  Int     getViewIdLen(  )                                           { return m_viewIdLen; } 
+#else
   Void    setViewIdLenMinus1( Int  val )                                   { m_viewIdLenMinus1 = val; } 
   Int     getViewIdLenMinus1(  )                                           { return m_viewIdLenMinus1; } 
+#endif
 
   Void    setViewIdVal( Int viewOrderIndex, Int  val )                     { m_viewIdVal[viewOrderIndex] = val; } 
@@ -985,4 +1010,14 @@
   Int     getNumSubDpbs(Int i)                          { return m_numSubDpbs[i]; }
   Void    setNumSubDpbs(Int i, Int x)                   { m_numSubDpbs[i] = x;    }
+#endif
+
+#if O0109_MOVE_VPS_VUI_FLAG
+  Bool   getVpsVuiPresentFlag()                                 { return m_vpsVuiPresentFlag; }
+  Void   setVpsVuiPresentFlag(Bool x)                           { m_vpsVuiPresentFlag = x; }
+#endif
+
+#if VPS_VUI_OFFSET
+  Int     getVpsVuiOffset()         { return m_vpsVuiOffset; }
+  Void    setVpsVuiOffset(Int x)    { m_vpsVuiOffset = x; }
 #endif
 #endif //SVC_EXTENSION
Index: /trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TypeDef.h	(revision 546)
+++ /trunk/source/Lib/TLibCommon/TypeDef.h	(revision 547)
@@ -43,7 +43,19 @@
 #define SYNTAX_BYTES                     10      ///< number of bytes taken by syntaxes per 4x4 block [RefIdxL0(1byte), RefIdxL1(1byte), MVxL0(2bytes), MVyL0(2bytes), MVxL1(2bytes), MVyL1(2bytes)]
 
+#define VPS_VUI_OFFSET                   1      ///< N0085: Signal VPS VUI offset in the VPS extension 
+
 #define RANDOM_ACCESS_SEI_FIX            1
 #if SVC_EXTENSION
 #define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
+
+#define O0137_MAX_LAYERID                1      ///< JCTVC-O0137, JCTVC-O0200, JCTVC-O0223: restrict nuh_layer_id and vps_max_layers_minus1
+
+#define O0109_O0199_FLAGS_TO_VUI         1      ///< JCTVC-O0109, O0199: move single_layer_for_non_irap_flag and higher_layer_flag to vps_vui
+#define O0109_VIEW_ID_LEN                1      ///< JCTVC-O0109: view_id_len_minus1 to view_id_len, and add constraint (1<<view_id_len) is greater than or equal to NumViews
+#define O0109_PROF_REF_MINUS1            1      ///< JCTVC-O0109: constraint that profile_ref_minus1[i] shall be less than or equal to i
+#define O0109_DEFAULT_ONE_OUT_LAYER_IDC  1      ///< JCTVC-O0109: default_one_target_output_layer_flag to default_one_target_output_layer_idc
+#define O0109_MOVE_VPS_VUI_FLAG          1      ///< JCTVC-O0109: move vps_vui_present_flag before vps_vui_offset
+
+#define O0135_DEFAULT_ONE_OUT_SEMANTIC   1      ///< JCTVC-O0135: semantics change of default_one_target_output_layer_idc for auxiliary pictures
 
 #define O0194_DIFFERENT_BITDEPTH_EL_BL   1      ///< JCTVC-O0194: Support for different bitdepth values for BL and EL, add required configuration parameters (and Some bugfixes when REPN_FORMAT_IN_VPS (JCTVC-N0092) is enabled)
@@ -96,6 +108,6 @@
 
 #if VPS_VUI
-#define VPS_VUI_TILES_NOT_IN_USE__FLAG    1      ///< JCTVC-O0226: VPS VUI flag to indicate tile not in use
-#define VPS_VUI_WPP_NOT_IN_USE__FLAG    1      ///< JCTVC-O0226: VPS VUI flag to indicate tile not in use
+#define VPS_VUI_TILES_NOT_IN_USE__FLAG   1      ///< JCTVC-O0226: VPS VUI flag to indicate tile not in use
+#define VPS_VUI_WPP_NOT_IN_USE__FLAG     1      ///< JCTVC-O0226: VPS VUI flag to indicate tile not in use
 #define TILE_BOUNDARY_ALIGNED_FLAG       1      ///< JCTVC-N0160/JCTVC-N0199 proposal 2 variant 2: VPS VUI flag to indicate tile boundary alignment
 #define N0160_VUI_EXT_ILP_REF            1      ///< VUI extension inter-layer dependency offset signalling
@@ -177,5 +189,5 @@
 #define RC_SHVC_HARMONIZATION            1      ///< JCTVC-M0037: rate control for SHVC
 
-#define VIEW_ID_RELATED_SIGNALING        1      ///< Introduce syntax elements view_id_len_minus1 and view_id_val
+#define VIEW_ID_RELATED_SIGNALING        1      ///< Introduce syntax elements view_id and view_id_val
 #define M0043_LAYERS_PRESENT_SEI         0      ///< JCTVC-M0043: add layers present SEI. Macro shall be equal to 0 according to the JCTVC-N0174 discussion. The code is to be removed.
 #define N0383_IL_CONSTRAINED_TILE_SETS_SEI  1
@@ -243,6 +255,9 @@
 
 #define MAX_CPB_CNT                     32  ///< Upper bound of (cpb_cnt_minus1 + 1)
+#if O0137_MAX_LAYERID
+#define MAX_NUM_LAYER_IDS                63
+#else
 #define MAX_NUM_LAYER_IDS                64
-
+#endif
 #define COEF_REMAIN_BIN_REDUCTION        3 ///< indicates the level at which the VLC 
                                            ///< transitions from Golomb-Rice to TU+EG(k)
Index: /trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 546)
+++ /trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 547)
@@ -866,5 +866,9 @@
   READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
 #if VPS_RENAME
-  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( uiCode + 1);
+#if O0137_MAX_LAYERID
+  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( min( 62u, uiCode) + 1 );
+#else
+  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( uiCode + 1 );
+#endif
 #else
   READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
@@ -990,4 +994,16 @@
 
   READ_FLAG( uiCode, "avc_base_layer_flag" ); vps->setAvcBaseLayerFlag(uiCode ? true : false);
+
+#if O0109_MOVE_VPS_VUI_FLAG
+  READ_FLAG( uiCode, "vps_vui_present_flag"); vps->setVpsVuiPresentFlag(uiCode ? true : false);
+  if ( uiCode )
+  {
+#endif
+#if VPS_VUI_OFFSET
+  READ_CODE( 16, uiCode, "vps_vui_offset" );  vps->setVpsVuiOffset( uiCode );
+#endif
+#if O0109_MOVE_VPS_VUI_FLAG
+  }
+#endif
   READ_FLAG( uiCode, "splitting_flag" ); vps->setSplittingFlag(uiCode ? true : false);
 
@@ -1048,7 +1064,20 @@
   //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val.
   {
+#if O0109_VIEW_ID_LEN
+    READ_CODE( 4, uiCode, "view_id_len" ); vps->setViewIdLen( uiCode );
+#else
     READ_CODE( 4, uiCode, "view_id_len_minus1" ); vps->setViewIdLenMinus1( uiCode );
-  }
-
+#endif
+  }
+
+#if O0109_VIEW_ID_LEN
+  if ( vps->getViewIdLen() > 0 )
+  {
+    for(  i = 0; i < vps->getNumViews(); i++ )
+    {
+      READ_CODE( vps->getViewIdLen( ), uiCode, "view_id_val[i]" ); vps->setViewIdVal( i, uiCode );
+    }
+  }
+#else
   for(  i = 0; i < vps->getNumViews(); i++ )
   {
@@ -1056,4 +1085,5 @@
   }
 #endif
+#endif // view id related signaling
 #if VPS_EXTN_DIRECT_REF_LAYERS
   // For layer 0
@@ -1165,6 +1195,9 @@
     {
       READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); vps->setProfileLayerSetRef(idx, uiCode + 1);
+#if O0109_PROF_REF_MINUS1
+      assert( vps->getProfileLayerSetRef(idx) <= idx );
+#else
       assert( vps->getProfileLayerSetRef(idx) < idx );
-
+#endif
       // Copy profile information as indicated
       vps->getPTLForExtn(idx)->copyProfileInfo( vps->getPTLForExtn( vps->getProfileLayerSetRef(idx) ) );
@@ -1187,5 +1220,9 @@
   if( numOutputLayerSets > 1 )
   {
+#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
+    READ_CODE( 2, uiCode, "default_one_target_output_layer_idc" );   vps->setDefaultOneTargetOutputLayerIdc( uiCode );
+#else
     READ_FLAG( uiCode, "default_one_target_output_layer_flag" );   vps->setDefaultOneTargetOutputLayerFlag( uiCode ? true : false );
+#endif
   }
   vps->setNumOutputLayerSets( numOutputLayerSets );
@@ -1215,4 +1252,28 @@
       // Assign OutputLayerFlag depending on default_one_target_output_layer_flag
       Int lsIdx = i;
+#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
+      if( vps->getDefaultOneTargetOutputLayerIdc() == 1 )
+      {
+        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
+        {
+#if O0135_DEFAULT_ONE_OUT_SEMANTIC
+          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)) && (vps->getDimensionId(j,1)==0) );
+#else
+          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)));
+#endif
+        }
+      }
+      else if ( vps->getDefaultOneTargetOutputLayerIdc() == 0 )
+      {
+        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
+        {
+          vps->setOutputLayerFlag(i, j, 1);
+        }
+      }
+      else
+      {
+        // Other values of default_one_target_output_layer_idc than 0 and 1 are reserved for future use.
+      }
+#else
       if( vps->getDefaultOneTargetOutputLayerFlag() )
       {
@@ -1229,4 +1290,5 @@
         }
       }
+#endif
     }
     Int numBits = 1;
@@ -1408,4 +1470,5 @@
 #endif
 
+#if !O0109_O0199_FLAGS_TO_VUI
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   READ_FLAG(uiCode, "single_layer_for_non_irap_flag" ); vps->setSingleLayerForNonIrapFlag(uiCode == 1 ? true : false);
@@ -1414,7 +1477,12 @@
   READ_FLAG(uiCode, "higher_layer_irap_skip_flag" ); vps->setHigherLayerIrapSkipFlag(uiCode == 1 ? true : false);
 #endif
-
+#endif
+
+#if O0109_MOVE_VPS_VUI_FLAG
+  if ( vps->getVpsVuiPresentFlag() )
+#else
   READ_FLAG( uiCode,  "vps_vui_present_flag" );
   if (uiCode)
+#endif
   {
 #if VPS_VUI
@@ -1593,4 +1661,14 @@
   }
 #endif
+
+#if O0109_O0199_FLAGS_TO_VUI
+#if M0040_ADAPTIVE_RESOLUTION_CHANGE
+  READ_FLAG(uiCode, "single_layer_for_non_irap_flag" ); vps->setSingleLayerForNonIrapFlag(uiCode == 1 ? true : false);
+#endif
+#if HIGHER_LAYER_IRAP_SKIP_FLAG
+  READ_FLAG(uiCode, "higher_layer_irap_skip_flag" ); vps->setHigherLayerIrapSkipFlag(uiCode == 1 ? true : false);
+#endif
+#endif
+
 #if N0160_VUI_EXT_ILP_REF
     READ_FLAG( uiCode, "num_ilp_restricted_ref_layers" ); vps->setNumIlpRestrictedRefLayers( uiCode == 1 );
Index: /trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 546)
+++ /trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 547)
@@ -1734,4 +1734,11 @@
   m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
 
+#if O0137_MAX_LAYERID
+  // ignore any NAL units with nuh_layer_id == 63
+  if (nalu.m_layerId == 63 )
+  {  
+    return false;
+  }
+#endif
   switch (nalu.m_nalUnitType)
   {
Index: /trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 546)
+++ /trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 547)
@@ -669,4 +669,7 @@
   UInt numBytesInVps = this->m_pcBitIf->getNumberOfWrittenBits();
 #endif
+#if VPS_VUI_OFFSET
+   m_vpsVuiCounter = this->m_pcBitIf->getNumberOfWrittenBits();
+#endif
   WRITE_CODE( pcVPS->getVPSId(),                    4,        "vps_video_parameter_set_id" );
   WRITE_CODE( 3,                                    2,        "vps_reserved_three_2bits" );
@@ -795,5 +798,25 @@
 
   WRITE_FLAG( vps->getAvcBaseLayerFlag(),              "avc_base_layer_flag" );
+#if O0109_MOVE_VPS_VUI_FLAG
+#if !VPS_VUI
+  WRITE_FLAG( 0,                     "vps_vui_present_flag" );
+  vps->setVpsVuiPresentFlag(false);
+#else
+  WRITE_FLAG( 1,                     "vps_vui_present_flag" );
+  vps->setVpsVuiPresentFlag(true);
+#endif
+  if ( vps->getVpsVuiPresentFlag() ) 
+  {
+#if VPS_VUI_OFFSET
+    WRITE_CODE( vps->getVpsVuiOffset(  ), 16,             "vps_vui_offset" );
+#endif
+    WRITE_FLAG( vps->getSplittingFlag(),                 "splitting_flag" );
+  }
+#else
+#if VPS_VUI_OFFSET
+  WRITE_CODE( vps->getVpsVuiOffset(  ), 16,             "vps_vui_offset" );  
+#endif
   WRITE_FLAG( vps->getSplittingFlag(),                 "splitting_flag" );
+#endif // O0109_MOVE_VPS_VUI_FLAG
 
   for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++)
@@ -841,12 +864,29 @@
   //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val. 
   {
+#if O0109_VIEW_ID_LEN
+    WRITE_CODE( vps->getViewIdLen( ), 4, "view_id_len" );
+    assert ( vps->getNumViews() >= (1<<vps->getViewIdLen()) );
+#else
     WRITE_CODE( vps->getViewIdLenMinus1( ), 4, "view_id_len_minus1" );
-  }
-
+#endif
+  }
+
+#if O0109_VIEW_ID_LEN
+  if ( vps->getViewIdLen() > 0 )
+  {
+#endif
   for(  i = 0; i < vps->getNumViews(); i++ )
   {
+#if O0109_VIEW_ID_LEN
+    WRITE_CODE( vps->getViewIdVal( i ), vps->getViewIdLen( ), "view_id_val[i]" );
+#else
     WRITE_CODE( vps->getViewIdVal( i ), vps->getViewIdLenMinus1( ) + 1, "view_id_val[i]" );
-  }
-#endif
+#endif
+  }
+#if O0109_VIEW_ID_LEN
+  }
+#endif
+#endif // VIEW_ID_RELATED_SIGNALING
+
 #if VPS_EXTN_DIRECT_REF_LAYERS
   for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
@@ -931,5 +971,9 @@
   if( numOutputLayerSets > 1 )
   {
+#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
+    WRITE_CODE( vps->getDefaultOneTargetOutputLayerIdc(), 2, "default_one_target_output_layer_idc" );   
+#else
     WRITE_FLAG( vps->getDefaultOneTargetOutputLayerFlag(), "default_one_target_output_layer_flag" );   
+#endif
   }
 
@@ -1072,4 +1116,6 @@
 #endif
 #endif
+
+#if !O0109_O0199_FLAGS_TO_VUI
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   WRITE_FLAG(vps->getSingleLayerForNonIrapFlag(), "single_layer_for_non_irap_flag" );
@@ -1078,5 +1124,7 @@
   WRITE_FLAG(vps->getHigherLayerIrapSkipFlag(), "higher_layer_irap_skip_flag" );
 #endif
-
+#endif
+
+#if !O0109_MOVE_VPS_VUI_FLAG
 #if !VPS_VUI
   WRITE_FLAG( 0,                     "vps_vui_present_flag" );
@@ -1089,7 +1137,27 @@
       WRITE_FLAG(1,                  "vps_vui_alignment_bit_equal_to_one");
     }
+#if VPS_VUI_OFFSET
+    Int vpsVuiOffsetValeInBits = this->m_pcBitIf->getNumberOfWrittenBits() - m_vpsVuiCounter + 16; // 2 bytes for NUH
+    assert( vpsVuiOffsetValeInBits % 8 == 0 );
+    vps->setVpsVuiOffset( vpsVuiOffsetValeInBits >> 3 );
+#endif
     codeVPSVUI(vps);  
   }
 #endif 
+#else
+  if(vps->getVpsVuiPresentFlag())   // Should be conditioned on the value of vps_vui_present_flag
+  {
+    while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
+    {
+      WRITE_FLAG(1,                  "vps_vui_alignment_bit_equal_to_one");
+    }
+#if VPS_VUI_OFFSET
+    Int vpsVuiOffsetValeInBits = this->m_pcBitIf->getNumberOfWrittenBits() - m_vpsVuiCounter + 16; // 2 bytes for NUH
+    assert( vpsVuiOffsetValeInBits % 8 == 0 );
+    vps->setVpsVuiOffset( vpsVuiOffsetValeInBits >> 3 );
+#endif
+    codeVPSVUI(vps);  
+  }
+#endif // 0109_MOVE_VPS_FLAG
 }
 #endif
@@ -1225,4 +1293,13 @@
     }
   }
+#endif
+
+#if O0109_O0199_FLAGS_TO_VUI
+#if M0040_ADAPTIVE_RESOLUTION_CHANGE
+  WRITE_FLAG(vps->getSingleLayerForNonIrapFlag(), "single_layer_for_non_irap_flag" );
+#endif
+#if HIGHER_LAYER_IRAP_SKIP_FLAG
+  WRITE_FLAG(vps->getHigherLayerIrapSkipFlag(), "higher_layer_irap_skip_flag" );
+#endif
 #endif
 #if N0160_VUI_EXT_ILP_REF
Index: /trunk/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 546)
+++ /trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 547)
@@ -68,5 +68,7 @@
   TComSlice*    m_pcSlice;
   UInt          m_uiCoeffCost;
-
+#if VPS_VUI_OFFSET
+  Int m_vpsVuiCounter;
+#endif
   Void codeShortTermRefPicSet              ( TComSPS* pcSPS, TComReferencePictureSet* pcRPS, Bool calledFromSliceHeader, Int idx );
   Bool findMatchingLTRP ( TComSlice* pcSlice, UInt *ltrpsIndex, Int ltrpPOC, Bool usedFlag );
Index: /trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 546)
+++ /trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 547)
@@ -1753,4 +1753,7 @@
       OutputNALUnit nalu(NAL_UNIT_VPS);
 #endif
+#if VPS_VUI_OFFSET
+      // The following code also calculates the VPS VUI offset
+#endif
 #if VPS_EXTN_OFFSET_CALC
       OutputNALUnit tempNalu(NAL_UNIT_VPS, 0, 0        ); // The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
