Index: trunk/cfg/3D-HEVC/NonCTC/gopCfg_IBP_3view+depth.cfg
===================================================================
--- trunk/cfg/3D-HEVC/NonCTC/gopCfg_IBP_3view+depth.cfg	(revision 609)
+++ trunk/cfg/3D-HEVC/NonCTC/gopCfg_IBP_3view+depth.cfg	(revision 622)
@@ -38,5 +38,5 @@
 
 #                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
-#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     collocatedRefLayerIdx
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     
 Frame1:     B    8     1     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0
 Frame2:     B    4     2     0.3536   0        0        0        2      3     -4 -6  4           1     4     5     1 1 0 0 1       0
@@ -58,43 +58,43 @@
 Frame8_l1:  B    7     4     0.68     0        0        0        2      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0             
 
-FrameI_l2:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1  
-Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 1            0         1          -1        -1  
-Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       1            0         1          -1        -1  
-Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         1            0         1          -1        -1  
-Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       1            0         1          -1        -1  
-Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       1            0         2          -1        -1  
-Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       1            0         2          -1        -1  
-Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       1            0         2          -1        -1  
-Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       1            0         2          -1        -1  
+FrameI_l2:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1         
+Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 1            0         1          -1         
+Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       1            0         1          -1         
+Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         1            0         1          -1         
+Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       1            0         1          -1         
+Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       1            0         2          -1         
+Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       1            0         2          -1         
+Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       1            0         2          -1         
+Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       1            0         2          -1         
 
-FrameI_l3:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1  
-Frame1_l3:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 1            0         1          -1        -1  
-Frame2_l3:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       1            0         1          -1        -1  
-Frame3_l3:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         1            0         1          -1        -1  
-Frame4_l3:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       1            0         1          -1        -1  
-Frame5_l3:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       1            0         2          -1        -1  
-Frame6_l3:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       1            0         2          -1        -1  
-Frame7_l3:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       1            0         2          -1        -1  
-Frame8_l3:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       1            0         2          -1        -1  
+FrameI_l3:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1         
+Frame1_l3:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 1            0         1          -1         
+Frame2_l3:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       1            0         1          -1         
+Frame3_l3:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         1            0         1          -1         
+Frame4_l3:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       1            0         1          -1         
+Frame5_l3:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       1            0         2          -1         
+Frame6_l3:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       1            0         2          -1         
+Frame7_l3:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       1            0         2          -1         
+Frame8_l3:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       1            0         2          -1         
 
-FrameI_l4:  B    0     3     0.442    0        0        0        1      0                        0                                 2            0 1       0 -1       -1 0      -1
-Frame1_l4:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 2            0 1       1 -1       -1 1      -1
-Frame2_l4:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       2            0 1       1 -1       -1 1      -1
-Frame3_l4:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         2            0 1       1 -1       -1 1      -1
-Frame4_l4:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       2            0 1       1 -1       -1 1      -1
-Frame5_l4:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       2            0 1       2 -1       -1 2      -1
-Frame6_l4:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       2            0 1       2 -1       -1 2      -1
-Frame7_l4:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       2            0 1       2 -1       -1 2      -1
-Frame8_l4:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       2            0 1       2 -1       -1 2      -1
+FrameI_l4:  B    0     3     0.442    0        0        0        1      0                        0                                 2            0 1       0 -1       -1 0     
+Frame1_l4:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 2            0 1       1 -1       -1 1     
+Frame2_l4:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       2            0 1       1 -1       -1 1     
+Frame3_l4:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         2            0 1       1 -1       -1 1     
+Frame4_l4:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       2            0 1       1 -1       -1 1     
+Frame5_l4:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       2            0 1       2 -1       -1 2     
+Frame6_l4:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       2            0 1       2 -1       -1 2     
+Frame7_l4:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       2            0 1       2 -1       -1 2     
+Frame8_l4:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       2            0 1       2 -1       -1 2     
 
-FrameI_l5:  B    0     3     0.442    0        0        0        1      0                        0                                 2            0 1       0 -1       -1 0      -1  
-Frame1_l5:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 2            0 1       1 -1       -1 1      -1  
-Frame2_l5:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       2            0 1       1 -1       -1 1      -1  
-Frame3_l5:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         2            0 1       1 -1       -1 1      -1  
-Frame4_l5:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       2            0 1       1 -1       -1 1      -1  
-Frame5_l5:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       2            0 1       2 -1       -1 2      -1  
-Frame6_l5:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       2            0 1       2 -1       -1 2      -1  
-Frame7_l5:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       2            0 1       2 -1       -1 2      -1  
-Frame8_l5:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       2            0 1       2 -1       -1 2      -1  
+FrameI_l5:  B    0     3     0.442    0        0        0        1      0                        0                                 2            0 1       0 -1       -1 0       
+Frame1_l5:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 2            0 1       1 -1       -1 1       
+Frame2_l5:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       2            0 1       1 -1       -1 1       
+Frame3_l5:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         2            0 1       1 -1       -1 1       
+Frame4_l5:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       2            0 1       1 -1       -1 1       
+Frame5_l5:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       2            0 1       2 -1       -1 2       
+Frame6_l5:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       2            0 1       2 -1       -1 2       
+Frame7_l5:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       2            0 1       2 -1       -1 2       
+Frame8_l5:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       2            0 1       2 -1       -1 2       
 
 ### DO NOT ADD ANYTHING BELOW THIS LINE ###
Index: trunk/cfg/3D-HEVC/NonCTC/gopCfg_IBP_3view.cfg
===================================================================
--- trunk/cfg/3D-HEVC/NonCTC/gopCfg_IBP_3view.cfg	(revision 609)
+++ trunk/cfg/3D-HEVC/NonCTC/gopCfg_IBP_3view.cfg	(revision 622)
@@ -1,14 +1,15 @@
 # Following parameters must be set in the correct order  
-InputFile_0 : leftView.yuv
-InputFile_1 : rightView.yuv
-InputFile_2 : middleView.yuv
-ViewId      : 0 2 1
-BaseViewCameraNumbers: 1 5 3 # (when left view is 1, right view is 5 and middle view is 3
+#InputFile_0          : leftView.yuv   # For layer with LayerIdx in vps equal to 0. 
+#InputFile_1          : rightView.yuv  # For layer with LayerIdx in vps equal to 1.
+#InputFile_2          : middleView.yuv # For layer with LayerIdx in vps equal to 2.
+#ViewOrderIndex       : 0 1 2          # Per layer, corresponds to coding order, needs to be increasing  
+#ViewId               : 0 2 1          # Per view, arbitary identifier, might correspond to spatial position of cameras
+#BaseViewCameraNumbers: 1 5 3          # Per view, numbers in camera parameter file ( e.g. leftView is 1, rightView is 5 and middleView is 3)
 
 #======== VPS / Layer sets ================
 VpsNumLayerSets               : 3            # Number of layer sets    
-LayerIdsInSet_0               : 0            # LayerIds in vps of layer set
-LayerIdsInSet_1               : 0 1          # LayerIds in vps of layer set
-LayerIdsInSet_3               : 0 1 2        # LayerIds in vps of layer set
+LayerIdsInSet_0               : 0            # LayerIdcs in vps of layer set
+LayerIdsInSet_1               : 0 1          # LayerIdcs in vps of layer set
+LayerIdsInSet_2               : 0 1 2        # LayerIdcs in vps of layer set
 
 DefaultOneTargetOutputLayerFlag: 0           # Output highest layer of layer sets by default
@@ -25,5 +26,5 @@
 
 #                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
-#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     collocatedRefLayerIdx
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     
 
 Frame1:     B    8     1     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   0
@@ -36,23 +37,23 @@
 Frame8:     B    7     4     0.68     0        0        0        2      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         0
                                                                                                                                    
-FrameI_l1:  P    0     3     0.442    0        0        0        1      0                        0                                   1          0         0          -1        -1
-Frame1_l1:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   1          0         1          -1        -1
-Frame2_l1:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         1          0         1          -1        -1
-Frame3_l1:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           1          0         1          -1        -1
-Frame4_l1:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         1          0         1          -1        -1
-Frame5_l1:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         1          0         2          -1        -1
-Frame6_l1:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         1          0         2          -1        -1
-Frame7_l1:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         1          0         2          -1        -1
-Frame8_l1:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         1          0         2          -1        -1
+FrameI_l1:  P    0     3     0.442    0        0        0        1      0                        0                                   1          0         0          -1  
+Frame1_l1:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   1          0         1          -1  
+Frame2_l1:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         1          0         1          -1  
+Frame3_l1:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           1          0         1          -1  
+Frame4_l1:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         1          0         1          -1  
+Frame5_l1:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         1          0         2          -1  
+Frame6_l1:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         1          0         2          -1  
+Frame7_l1:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         1          0         2          -1  
+Frame8_l1:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         1          0         2          -1  
                                                                                                                                                                                
-FrameI_l2:  B    0     3     0.442    0        0        0        1      0                        0                                   2          0 1       0 -1       -1 0      -1
-Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   2          0 1       1 -1       -1 1      -1
-Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         2          0 1       1 -1       -1 1      -1
-Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           2          0 1       1 -1       -1 1      -1
-Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         2          0 1       1 -1       -1 1      -1
-Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         2          0 1       2 -1       -1 2      -1
-Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         2          0 1       2 -1       -1 2      -1
-Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         2          0 1       2 -1       -1 2      -1
-Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         2          0 1       2 -1       -1 2      -1
+FrameI_l2:  B    0     3     0.442    0        0        0        1      0                        0                                   2          0 1       0 -1       -1 0
+Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   2          0 1       1 -1       -1 1
+Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         2          0 1       1 -1       -1 1
+Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           2          0 1       1 -1       -1 1
+Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         2          0 1       1 -1       -1 1
+Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         2          0 1       2 -1       -1 2
+Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         2          0 1       2 -1       -1 2
+Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         2          0 1       2 -1       -1 2
+Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         2          0 1       2 -1       -1 2
 
 ### DO NOT ADD ANYTHING BELOW THIS LINE ###
Index: trunk/cfg/3D-HEVC/NonCTC/gopCfg_ILP_on_IRAP_3view+depth.cfg
===================================================================
--- trunk/cfg/3D-HEVC/NonCTC/gopCfg_ILP_on_IRAP_3view+depth.cfg	(revision 609)
+++ trunk/cfg/3D-HEVC/NonCTC/gopCfg_ILP_on_IRAP_3view+depth.cfg	(revision 622)
@@ -29,5 +29,5 @@
 
 #                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
-#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     collocatedRefLayerIdx
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0    
 Frame1:     B    8     1     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0
 Frame2:     B    4     2     0.3536   0        0        0        2      3     -4 -6  4           1     4     5     1 1 0 0 1       0
@@ -49,5 +49,5 @@
 Frame8_l1:  B    7     4     0.68     0        0        0        2      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0             
 
-FrameI_l2:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1  
+FrameI_l2:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1     
 Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0
 Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       0
@@ -59,5 +59,5 @@
 Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0
 
-FrameI_l3:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1  
+FrameI_l3:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1     
 Frame1_l3:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0  
 Frame2_l3:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       0  
@@ -69,5 +69,5 @@
 Frame8_l3:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0  
 
-FrameI_l4:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1
+FrameI_l4:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1     
 Frame1_l4:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0  
 Frame2_l4:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       0  
@@ -79,5 +79,5 @@
 Frame8_l4:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0  
 
-FrameI_l5:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1  
+FrameI_l5:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1     
 Frame1_l5:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0    
 Frame2_l5:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       0    
Index: trunk/cfg/3D-HEVC/NonCTC/gopCfg_NoIv_2view.cfg
===================================================================
--- trunk/cfg/3D-HEVC/NonCTC/gopCfg_NoIv_2view.cfg	(revision 609)
+++ trunk/cfg/3D-HEVC/NonCTC/gopCfg_NoIv_2view.cfg	(revision 622)
@@ -16,5 +16,5 @@
 
 #                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
-#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     collocatedRefLayerIdx
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0   
 
 Frame1:     B    8     1     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   0
Index: trunk/cfg/3D-HEVC/NonCTC/gopCfg_NoIv_3view+depth.cfg
===================================================================
--- trunk/cfg/3D-HEVC/NonCTC/gopCfg_NoIv_3view+depth.cfg	(revision 609)
+++ trunk/cfg/3D-HEVC/NonCTC/gopCfg_NoIv_3view+depth.cfg	(revision 622)
@@ -27,5 +27,5 @@
 
 #                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
-#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     collocatedRefLayerIdx
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0   
 Frame1:     B    8     1     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0
 Frame2:     B    4     2     0.3536   0        0        0        2      3     -4 -6  4           1     4     5     1 1 0 0 1       0
Index: trunk/cfg/3D-HEVC/NonCTC/gopCfg_NoIv_3view.cfg
===================================================================
--- trunk/cfg/3D-HEVC/NonCTC/gopCfg_NoIv_3view.cfg	(revision 609)
+++ trunk/cfg/3D-HEVC/NonCTC/gopCfg_NoIv_3view.cfg	(revision 622)
@@ -19,5 +19,5 @@
 
 #                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
-#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     collocatedRefLayerIdx
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     
 
 Frame1:     B    8     1     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   0
Index: trunk/cfg/3D-HEVC/baseCfg_2view+depth.cfg
===================================================================
--- trunk/cfg/3D-HEVC/baseCfg_2view+depth.cfg	(revision 609)
+++ trunk/cfg/3D-HEVC/baseCfg_2view+depth.cfg	(revision 622)
@@ -20,10 +20,11 @@
 
 #======== VPS ============================
-ScalabilityMask               : 3           # Scalability Mask             ( 1: View Scalability, 3: View + Depth Scalability )
-DimensionIdLen                : 2 1         # Number of bits to store Ids,  per scalability dimension, (m)
-ViewId                        : 1 1 0 0     # ViewId     (m) 
+ScalabilityMask               : 3           # Scalability Mask             ( 2: View Scalability, 3: View + Depth Scalability )
+DimensionIdLen                : 1 2         # Number of bits to store Ids,  per scalability dimension, (m)
+ViewOrderIndex                : 0 0 1 1     # ViewOrderIndex (m)
 DepthFlag                     : 0 1 0 1     # DepthFlag  (m) 
 LayerIdInNuh                  : 0           # Layer Id in NAL unit header, (0: no explicit signalling ) (m)
 SplittingFlag                 : 0           # Splitting Flag 
+ViewId                        : 1 0         # ViewId per ViewOrderIndex (m)
 
 #======== VPS/ Layer sets ================
@@ -68,5 +69,5 @@
 
 #                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
-#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     collocatedRefLayerIdx
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id   #ref_pics                 predict     #ref_idcs         #ActiveRefLayerPics     refLayerPicPosIl_L0     
 Frame1:     B    8     1        0.442    0            0              0           4                4         -8 -10 -12 -16     0                                          0
 Frame2:     B    4     2        0.3536   0            0              0           2                3         -4 -6  4           1       4        5         1 1 0 0 1       0
Index: trunk/cfg/3D-HEVC/baseCfg_2view.cfg
===================================================================
--- trunk/cfg/3D-HEVC/baseCfg_2view.cfg	(revision 609)
+++ trunk/cfg/3D-HEVC/baseCfg_2view.cfg	(revision 622)
@@ -17,9 +17,10 @@
 
 #======== VPS ============================
-ScalabilityMask               : 1           # Scalability Mask             ( 1: View Scalability, shall be 1 for MV-HEVC )
+ScalabilityMask               : 2           # Scalability Mask             ( 2: View Scalability, 3: View + Depth Scalability )
 DimensionIdLen                : 3           # Number of bits to store Ids,  per scalability dimension, (m)
-ViewId                        : 0 1         # ViewId  (m) 
+ViewOrderIndex                : 0 1         # ViewOrderIndex (m)
 LayerIdInNuh                  : 0           # Layer Id in NAL unit header, (0: no explicit signalling ) (m)
 SplittingFlag                 : 0           # Splitting Flag 
+ViewId                        : 1 0         # ViewId per ViewOrderIndex (m)
 
 #======== VPS/ Layer sets ================
@@ -59,5 +60,5 @@
 
 #                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
-#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     collocatedRefLayerIdx
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id   #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     
 Frame1:     B    8     1        0.442    0            0              0           4                4         -8 -10 -12 -16     0                                          0
 Frame2:     B    4     2        0.3536   0            0              0           2                3         -4 -6  4           1       4        5         1 1 0 0 1       0
@@ -69,13 +70,13 @@
 Frame8:     B    7     4        0.68     0            0              0           2                4         -1 -3 -7 1         1      -2        5         1 1 1 1 0       0
     
-FrameI_l1:  P    0     3     0.442    0        0        0        1      0                        0                                   1          0          0          -1        -1
-Frame1_l1:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   1          0          1          -1        -1
-Frame2_l1:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         1          0          1          -1        -1
-Frame3_l1:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           1          0          1          -1        -1
-Frame4_l1:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         1          0          1          -1        -1
-Frame5_l1:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         1          0          2          -1        -1
-Frame6_l1:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         1          0          2          -1        -1
-Frame7_l1:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         1          0          2          -1        -1
-Frame8_l1:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         1          0          2          -1        -1
+FrameI_l1:  P    0     3     0.442    0        0        0      1     0                         0                                  1          0          0          -1
+Frame1_l1:  B    8     4     0.442    0        0        0      4     4      -8 -10 -12 -16     0                                  1          0          1          -1
+Frame2_l1:  B    4     5     0.3536   0        0        0      3     3      -4 -6  4           1       4   5      1 1 0 0 1       1          0          1          -1
+Frame3_l1:  B    2     6     0.3536   0        0        0      3     4      -2 -4  2 6         1       2   4      1 1 1 1         1          0          1          -1
+Frame4_l1:  B    1     7     0.68     0        0        0      3     4      -1  1  3 7         1       1   5      1 0 1 1 1       1          0          1          -1
+Frame5_l1:  B    3     7     0.68     0        0        0      3     4      -1 -3  1 5         1      -2   5      1 1 1 1 0       1          0          2          -1
+Frame6_l1:  B    6     6     0.3536   0        0        0      3     4      -2 -4 -6 2         1      -3   5      1 1 1 1 0       1          0          2          -1
+Frame7_l1:  B    5     7     0.68     0        0        0      3     4      -1 -5  1 3         1       1   5      1 0 1 1 1       1          0          2          -1
+Frame8_l1:  B    7     7     0.68     0        0        0      3     4      -1 -3 -7 1         1      -2   5      1 1 1 1 0       1          0          2          -1
 
 #=========== Motion Search =============
Index: trunk/cfg/3D-HEVC/baseCfg_3view+depth.cfg
===================================================================
--- trunk/cfg/3D-HEVC/baseCfg_3view+depth.cfg	(revision 609)
+++ trunk/cfg/3D-HEVC/baseCfg_3view+depth.cfg	(revision 622)
@@ -24,10 +24,11 @@
 
 #======== VPS ============================
-ScalabilityMask               : 3           # Scalability Mask             ( 1: View Scalability, 3: View + Depth Scalability )
-DimensionIdLen                : 2 1         # Number of bits to store Ids,  per scalability dimension, (m)
-ViewId                        : 1 1 0 0 2 2 # ViewId     (m) 
+ScalabilityMask               : 3           # Scalability Mask             ( 2: View Scalability, 3: View + Depth Scalability )
+DimensionIdLen                : 1 2         # Number of bits to store Ids,  per scalability dimension, (m)
+ViewOrderIndex                : 0 0 1 1 2 2 # ViewOrderIndex (m)
 DepthFlag                     : 0 1 0 1 0 1 # DepthFlag  (m) 
 LayerIdInNuh                  : 0           # Layer Id in NAL unit header, (0: no explicit signalling ) (m)
 SplittingFlag                 : 0           # Splitting Flag 
+ViewId                        : 1 0 2       # ViewId per ViewOrderIndex (m)
 
 #======== VPS/ Layer sets ================
@@ -79,5 +80,5 @@
 
 #                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
-#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     collocatedRefLayerIdx
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0   
 Frame1:     B    8     1        0.442    0            0              0           4                4         -8 -10 -12 -16     0                                          0
 Frame2:     B    4     2        0.3536   0            0              0           2                3         -4 -6  4           1       4        5         1 1 0 0 1       0
@@ -99,43 +100,43 @@
 Frame8_l1:  B    7     4        0.68     0            0              0           2                4         -1 -3 -7 1         1      -2        5         1 1 1 1 0       0             
 
-FrameI_l2:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1  
-Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 1            0         1          -1        -1  
-Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       1            0         1          -1        -1  
-Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         1            0         1          -1        -1  
-Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       1            0         1          -1        -1  
-Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       1            0         2          -1        -1  
-Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       1            0         2          -1        -1  
-Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       1            0         2          -1        -1  
-Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       1            0         2          -1        -1  
-
-FrameI_l3:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1  
-Frame1_l3:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 1            0         1          -1        -1  
-Frame2_l3:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       1            0         1          -1        -1  
-Frame3_l3:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         1            0         1          -1        -1  
-Frame4_l3:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       1            0         1          -1        -1  
-Frame5_l3:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       1            0         2          -1        -1  
-Frame6_l3:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       1            0         2          -1        -1  
-Frame7_l3:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       1            0         2          -1        -1  
-Frame8_l3:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       1            0         2          -1        -1  
-
-FrameI_l4:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1  
-Frame1_l4:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 1            0         1          -1        -1  
-Frame2_l4:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       1            0         1          -1        -1  
-Frame3_l4:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         1            0         1          -1        -1  
-Frame4_l4:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       1            0         1          -1        -1  
-Frame5_l4:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       1            0         2          -1        -1  
-Frame6_l4:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       1            0         2          -1        -1  
-Frame7_l4:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       1            0         2          -1        -1  
-Frame8_l4:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       1            0         2          -1        -1  
-
-FrameI_l5:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1  
-Frame1_l5:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 1            0         1          -1        -1  
-Frame2_l5:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       1            0         1          -1        -1  
-Frame3_l5:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         1            0         1          -1        -1  
-Frame4_l5:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       1            0         1          -1        -1  
-Frame5_l5:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       1            0         2          -1        -1  
-Frame6_l5:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       1            0         2          -1        -1  
-Frame7_l5:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       1            0         2          -1        -1  
-Frame8_l5:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       1            0         2          -1        -1  
+FrameI_l2:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1    
+Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 1            0         1          -1    
+Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       1            0         1          -1    
+Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         1            0         1          -1    
+Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       1            0         1          -1    
+Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       1            0         2          -1    
+Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       1            0         2          -1    
+Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       1            0         2          -1    
+Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       1            0         2          -1    
+
+FrameI_l3:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1    
+Frame1_l3:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 1            0         1          -1    
+Frame2_l3:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       1            0         1          -1    
+Frame3_l3:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         1            0         1          -1    
+Frame4_l3:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       1            0         1          -1    
+Frame5_l3:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       1            0         2          -1    
+Frame6_l3:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       1            0         2          -1    
+Frame7_l3:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       1            0         2          -1    
+Frame8_l3:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       1            0         2          -1    
+
+FrameI_l4:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1    
+Frame1_l4:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 1            0         1          -1    
+Frame2_l4:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       1            0         1          -1    
+Frame3_l4:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         1            0         1          -1    
+Frame4_l4:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       1            0         1          -1    
+Frame5_l4:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       1            0         2          -1    
+Frame6_l4:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       1            0         2          -1    
+Frame7_l4:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       1            0         2          -1    
+Frame8_l4:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       1            0         2          -1    
+
+FrameI_l5:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1    
+Frame1_l5:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 1            0         1          -1    
+Frame2_l5:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       1            0         1          -1    
+Frame3_l5:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         1            0         1          -1    
+Frame4_l5:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       1            0         1          -1    
+Frame5_l5:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       1            0         2          -1    
+Frame6_l5:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       1            0         2          -1    
+Frame7_l5:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       1            0         2          -1    
+Frame8_l5:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       1            0         2          -1    
 
 #=========== Motion Search =============
Index: trunk/cfg/3D-HEVC/baseCfg_3view.cfg
===================================================================
--- trunk/cfg/3D-HEVC/baseCfg_3view.cfg	(revision 609)
+++ trunk/cfg/3D-HEVC/baseCfg_3view.cfg	(revision 622)
@@ -18,9 +18,10 @@
 
 #======== VPS ============================
-ScalabilityMask               : 1           # Scalability Mask             ( 1: View Scalability, shall be 1 for MV-HEVC )
+ScalabilityMask               : 2           # Scalability Mask             ( 2: View Scalability, 3: View + Depth Scalability )
 DimensionIdLen                : 3           # Number of bits to store Ids,  per scalability dimension, (m)
-ViewId                        : 0 1 2       # ViewId  (m) 
+ViewOrderIndex                : 0 1 2       # ViewOrderIndex (m)
 LayerIdInNuh                  : 0           # Layer Id in NAL unit header, (0: no explicit signalling ) (m)
 SplittingFlag                 : 0           # Splitting Flag 
+ViewId                        : 1 0 2       # ViewId per ViewOrderIndex (m)
 
 #======== VPS / Layer sets ================
@@ -64,5 +65,5 @@
 
 #                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
-#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     collocatedRefLayerIdx
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0
 
 Frame1:     B    8     1        0.442    0            0              0           4                4         -8 -10 -12 -16     0                                          0
@@ -75,23 +76,23 @@
 Frame8:     B    7     4        0.68     0            0              0           2                4         -1 -3 -7 1         1      -2        5         1 1 1 1 0       0
     
-FrameI_l1:  P    0     3     0.442    0        0        0        1      0                        0                                   1          0         0          -1        -1
-Frame1_l1:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   1          0         1          -1        -1
-Frame2_l1:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         1          0         1          -1        -1
-Frame3_l1:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           1          0         1          -1        -1
-Frame4_l1:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         1          0         1          -1        -1
-Frame5_l1:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         1          0         2          -1        -1
-Frame6_l1:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         1          0         2          -1        -1
-Frame7_l1:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         1          0         2          -1        -1
-Frame8_l1:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         1          0         2          -1        -1
+FrameI_l1:  P    0     3     0.442    0        0        0        1      0                        0                                  1          0         0          -1
+Frame1_l1:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                  1          0         1          -1
+Frame2_l1:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1       4    5     1 1 0 0 1       1          0         1          -1
+Frame3_l1:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1       2    4     1 1 1 1         1          0         1          -1
+Frame4_l1:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1       1    5     1 0 1 1 1       1          0         1          -1
+Frame5_l1:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1      -2    5     1 1 1 1 0       1          0         2          -1
+Frame6_l1:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1      -3    5     1 1 1 1 0       1          0         2          -1
+Frame7_l1:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1       1    5     1 0 1 1 1       1          0         2          -1
+Frame8_l1:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1      -2    5     1 1 1 1 0       1          0         2          -1
 
-FrameI_l2:  P    0     3     0.442    0        0        0        1      0                        0                                   1          0         0          -1        -1
-Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   1          0         1          -1        -1
-Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         1          0         1          -1        -1
-Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           1          0         1          -1        -1
-Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         1          0         1          -1        -1
-Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         1          0         2          -1        -1
-Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         1          0         2          -1        -1
-Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         1          0         2          -1        -1
-Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         1          0         2          -1        -1
+FrameI_l2:  P    0     3     0.442    0        0        0        1      0                        0                                  1          0         0          -1
+Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                  1          0         1          -1
+Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1       4    5     1 1 0 0 1       1          0         1          -1
+Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1       2    4     1 1 1 1         1          0         1          -1
+Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1       1    5     1 0 1 1 1       1          0         1          -1
+Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1      -2    5     1 1 1 1 0       1          0         2          -1
+Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1      -3    5     1 1 1 1 0       1          0         2          -1
+Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1       1    5     1 0 1 1 1       1          0         2          -1
+Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1      -2    5     1 1 1 1 0       1          0         2          -1
 
 #=========== Motion Search =============
Index: trunk/cfg/3D-HEVC/fullCfg.cfg
===================================================================
--- trunk/cfg/3D-HEVC/fullCfg.cfg	(revision 609)
+++ trunk/cfg/3D-HEVC/fullCfg.cfg	(revision 622)
@@ -28,10 +28,11 @@
 
 #======== VPS ============================
-ScalabilityMask               : 3           # Scalability Mask             ( 1: View Scalability, 3: View + Depth Scalability )
-DimensionIdLen                : 2 1         # Number of bits to store Ids,  per scalability dimension, (m)
-ViewId                        : 1 1 0 0 2 2 # ViewId     (m) 
+ScalabilityMask               : 3           # Scalability Mask             ( 2: View Scalability, 3: View + Depth Scalability )
+DimensionIdLen                : 1 2         # Number of bits to store Ids,  per scalability dimension, (m)
+ViewOrderIndex                : 0 0 1 1 2 2 # ViewOrderIndex (m)
 DepthFlag                     : 0 1 0 1 0 1 # DepthFlag  (m) 
 LayerIdInNuh                  : 0           # Layer Id in NAL unit header, (0: no explicit signalling ) (m)
 SplittingFlag                 : 0           # Splitting Flag 
+ViewId                        : 1 0 2       # ViewId per ViewOrderIndex (m)
 
 #======== VPS/ Layer sets ================
Index: trunk/cfg/MV-HEVC/NonCTC/gopCfg_IBP_3view.cfg
===================================================================
--- trunk/cfg/MV-HEVC/NonCTC/gopCfg_IBP_3view.cfg	(revision 622)
+++ trunk/cfg/MV-HEVC/NonCTC/gopCfg_IBP_3view.cfg	(revision 622)
@@ -0,0 +1,60 @@
+# Following parameters must be set in the correct order:   
+#InputFile_0          : leftView.yuv   # For layer with LayerIdx in vps equal to 0. 
+#InputFile_1          : rightView.yuv  # For layer with LayerIdx in vps equal to 1.
+#InputFile_2          : middleView.yuv # For layer with LayerIdx in vps equal to 2.
+#ViewOrderIndex       : 0 1 2          # Per layer, corresponds to coding order, needs to be increasing  
+#ViewId               : 0 2 1          # Per view, arbitary identifier, might correspond to spatial position of cameras
+#BaseViewCameraNumbers: 1 5 3          # Per view, numbers in camera parameter file ( e.g. leftView is 1, rightView is 5 and middleView is 3)
+
+#======== VPS / Layer sets ================
+VpsNumLayerSets               : 3            # Number of layer sets    
+LayerIdsInSet_0               : 0            # LayerIdcs in vps of layer set
+LayerIdsInSet_1               : 0 1          # LayerIdcs in vps of layer set
+LayerIdsInSet_2               : 0 1 2        # LayerIdcs in vps of layer set
+
+DefaultOneTargetOutputLayerFlag: 0           # Output highest layer of layer sets by default
+OutputLayerSetIdx             : 1 2          # Indices of layer sets used as additional output layer sets
+LayerIdsInAddOutputLayerSet_0 : 1            # LayerIds in vps of additional output layers
+LayerIdsInAddOutputLayerSet_1 : 2            # LayerIds in vps of additional output layers
+ProfileLevelTierIdx           : 0 0 0 0 0    # Indices to profile level tier (TBD)
+
+#======== VPS / Dependencies ================
+DirectRefLayers_1             : 0           # LayerIds in vps of direct reference layers 
+DirectRefLayers_2             : 0 1         # LayerIds in vps of direct reference layers 
+DependencyTypes_1             : 2           # Dependency types of direct reference layers, 0: Sample 1: Motion 2: Sample+Motion
+DependencyTypes_2             : 2 2         # Dependency types of direct reference layers, 0: Sample 1: Motion 2: Sample+Motion
+
+#                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     
+
+Frame1:     B    8     1     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   0
+Frame2:     B    4     2     0.3536   0        0        0        2      3     -4 -6  4           1     4     5     1 1 0 0 1         0
+Frame3:     B    2     3     0.3536   0        0        0        2      4     -2 -4  2 6         1     2     4     1 1 1 1           0
+Frame4:     B    1     4     0.68     0        0        0        2      4     -1  1  3 7         1     1     5     1 0 1 1 1         0
+Frame5:     B    3     4     0.68     0        0        0        2      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         0
+Frame6:     B    6     3     0.3536   0        0        0        2      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         0
+Frame7:     B    5     4     0.68     0        0        0        2      4     -1 -5  1 3         1     1     5     1 0 1 1 1         0
+Frame8:     B    7     4     0.68     0        0        0        2      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         0
+                                                                                                                                   
+FrameI_l1:  P    0     3     0.442    0        0        0        1      0                        0                                   1          0         0          -1  
+Frame1_l1:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   1          0         1          -1  
+Frame2_l1:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         1          0         1          -1  
+Frame3_l1:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           1          0         1          -1  
+Frame4_l1:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         1          0         1          -1  
+Frame5_l1:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         1          0         2          -1  
+Frame6_l1:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         1          0         2          -1  
+Frame7_l1:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         1          0         2          -1  
+Frame8_l1:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         1          0         2          -1  
+                                                                                                                                                                         
+FrameI_l2:  B    0     3     0.442    0        0        0        1      0                        0                                   2          0 1       0 -1       -1 0
+Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   2          0 1       1 -1       -1 1
+Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         2          0 1       1 -1       -1 1
+Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           2          0 1       1 -1       -1 1
+Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         2          0 1       1 -1       -1 1
+Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         2          0 1       2 -1       -1 2
+Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         2          0 1       2 -1       -1 2
+Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         2          0 1       2 -1       -1 2
+Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         2          0 1       2 -1       -1 2
+
+### DO NOT ADD ANYTHING BELOW THIS LINE ###
+### DO NOT DELETE THE EMPTY LINE BELOW ###
Index: trunk/cfg/MV-HEVC/NonCTC/gopCfg_ILP_on_IRAP_3view+depth.cfg
===================================================================
--- trunk/cfg/MV-HEVC/NonCTC/gopCfg_ILP_on_IRAP_3view+depth.cfg	(revision 622)
+++ trunk/cfg/MV-HEVC/NonCTC/gopCfg_ILP_on_IRAP_3view+depth.cfg	(revision 622)
@@ -0,0 +1,92 @@
+# Inter layer prediction only at IRAP pictures
+#
+#======== VPS/ Layer sets ================
+VpsNumLayerSets               : 4           # Number of layer sets    
+LayerIdsInSet_0               : 0           # LayerIds in vps of layer set
+LayerIdsInSet_1               : 0 1         # LayerIds in vps of layer set
+LayerIdsInSet_2               : 0 1 2 3     # LayerIds in vps of layer set
+LayerIdsInSet_3               : 0 1 2 3 4 5 # LayerIds in vps of layer set
+
+DefaultOneTargetOutputLayerFlag: 0           # Output highest layer of layer sets by default
+OutputLayerSetIdx             : 2 3          # Indices of layer sets used as additional output layer sets
+LayerIdsInAddOutputLayerSet_0 : 2 3          # LayerIds of additional output layers
+LayerIdsInAddOutputLayerSet_1 : 4 5          # LayerIds of additional output layers
+ProfileLevelTierIdx           : 0 0 0 0 0 0 0 # Indices to profile level tier (TBD)
+
+#======== VPS / Dependencies ================
+DirectRefLayers_1             :             # LayerIds in vps of direct reference layers 
+DirectRefLayers_2             : 0           # LayerIds in vps of direct reference layers 
+DirectRefLayers_3             : 1           # LayerIds in vps of direct reference layers 
+DirectRefLayers_4             : 0 2         # LayerIds in vps of direct reference layers 
+DirectRefLayers_5             : 1 3         # LayerIds in vps of direct reference layers 
+
+DependencyTypes_1             :             # Dependency types of direct reference layers, 0: Sample 1: Motion 2: Sample+Motion
+DependencyTypes_2             : 2           # Dependency types of direct reference layers, 0: Sample 1: Motion 2: Sample+Motion
+DependencyTypes_3             : 2           # Dependency types of direct reference layers, 0: Sample 1: Motion 2: Sample+Motion
+DependencyTypes_4             : 2 2         # Dependency types of direct reference layers, 0: Sample 1: Motion 2: Sample+Motion
+DependencyTypes_5             : 2 2         # Dependency types of direct reference layers, 0: Sample 1: Motion 2: Sample+Motion
+
+
+#                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     collocatedRefLayerIdx
+Frame1:     B    8     1     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0
+Frame2:     B    4     2     0.3536   0        0        0        2      3     -4 -6  4           1     4     5     1 1 0 0 1       0
+Frame3:     B    2     3     0.3536   0        0        0        2      4     -2 -4  2 6         1     2     4     1 1 1 1         0
+Frame4:     B    1     4     0.68     0        0        0        2      4     -1  1  3 7         1     1     5     1 0 1 1 1       0
+Frame5:     B    3     4     0.68     0        0        0        2      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       0
+Frame6:     B    6     3     0.3536   0        0        0        2      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       0
+Frame7:     B    5     4     0.68     0        0        0        2      4     -1 -5  1 3         1     1     5     1 0 1 1 1       0
+Frame8:     B    7     4     0.68     0        0        0        2      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0
+    
+FrameI_l1:  I    0     0     0.442    0        0        0        0      0                        0                                 0             
+Frame1_l1:  B    8     1     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0             
+Frame2_l1:  B    4     2     0.3536   0        0        0        2      3     -4 -6  4           1     4     5     1 1 0 0 1       0             
+Frame3_l1:  B    2     3     0.3536   0        0        0        2      4     -2 -4  2 6         1     2     4     1 1 1 1         0             
+Frame4_l1:  B    1     4     0.68     0        0        0        2      4     -1  1  3 7         1     1     5     1 0 1 1 1       0             
+Frame5_l1:  B    3     4     0.68     0        0        0        2      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       0             
+Frame6_l1:  B    6     3     0.3536   0        0        0        2      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       0             
+Frame7_l1:  B    5     4     0.68     0        0        0        2      4     -1 -5  1 3         1     1     5     1 0 1 1 1       0             
+Frame8_l1:  B    7     4     0.68     0        0        0        2      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0             
+
+FrameI_l2:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1  
+Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0
+Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       0
+Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         0
+Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       0
+Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       0
+Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       0
+Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       0
+Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0
+
+FrameI_l3:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1  
+Frame1_l3:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0  
+Frame2_l3:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       0  
+Frame3_l3:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         0  
+Frame4_l3:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       0  
+Frame5_l3:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       0  
+Frame6_l3:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       0  
+Frame7_l3:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       0  
+Frame8_l3:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0  
+
+FrameI_l4:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1
+Frame1_l4:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0  
+Frame2_l4:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       0  
+Frame3_l4:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         0  
+Frame4_l4:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       0  
+Frame5_l4:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       0  
+Frame6_l4:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       0  
+Frame7_l4:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       0  
+Frame8_l4:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0  
+
+FrameI_l5:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1        -1  
+Frame1_l5:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0    
+Frame2_l5:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       0    
+Frame3_l5:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         0    
+Frame4_l5:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       0    
+Frame5_l5:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       0    
+Frame6_l5:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       0    
+Frame7_l5:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       0    
+Frame8_l5:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0    
+
+### DO NOT ADD ANYTHING BELOW THIS LINE ###
+### DO NOT DELETE THE EMPTY LINE BELOW ###
Index: trunk/cfg/MV-HEVC/NonCTC/gopCfg_IPB_on_IRAP_3view.cfg
===================================================================
--- trunk/cfg/MV-HEVC/NonCTC/gopCfg_IPB_on_IRAP_3view.cfg	(revision 622)
+++ trunk/cfg/MV-HEVC/NonCTC/gopCfg_IPB_on_IRAP_3view.cfg	(revision 622)
@@ -0,0 +1,56 @@
+# Inter layer prediction only at IRAP pictures
+#
+#======== VPS / Layer sets ================
+VpsNumLayerSets               : 4            # Number of layer sets    
+LayerIdsInSet_0               : 0            # LayerIds in vps of layer set
+LayerIdsInSet_1               : 0 1          # LayerIds in vps of layer set
+LayerIdsInSet_2               : 0 2          # LayerIds in vps of layer set
+LayerIdsInSet_3               : 0 1 2        # LayerIds in vps of layer set
+
+DefaultOneTargetOutputLayerFlag: 0           # Output highest layer of layer sets by default
+OutputLayerSetIdx             : 1 2          # Indices of layer sets used as additional output layer sets
+LayerIdsInAddOutputLayerSet_0 : 1            # LayerIds in vps of additional output layers
+LayerIdsInAddOutputLayerSet_1 : 2            # LayerIds in vps of additional output layers
+ProfileLevelTierIdx           : 0 0 0 0 0 0  # Indices to profile level tier (TBD)
+
+#======== VPS / Dependencies ================
+DirectRefLayers_1             : 0           # LayerIds in vps of direct reference layers 
+DirectRefLayers_2             : 0 1         # LayerIds in vps of direct reference layers 
+DependencyTypes_1             : 2           # Dependency types of direct reference layers, 0: Sample 1: Motion 2: Sample+Motion
+DependencyTypes_2             : 2 2         # Dependency types of direct reference layers, 0: Sample 1: Motion 2: Sample+Motion
+
+
+#                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     
+Frame1:     B    8     1     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0
+Frame2:     B    4     2     0.3536   0        0        0        2      3     -4 -6  4           1     4     5     1 1 0 0 1       0
+Frame3:     B    2     3     0.3536   0        0        0        2      4     -2 -4  2 6         1     2     4     1 1 1 1         0
+Frame4:     B    1     4     0.68     0        0        0        2      4     -1  1  3 7         1     1     5     1 0 1 1 1       0
+Frame5:     B    3     4     0.68     0        0        0        2      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       0
+Frame6:     B    6     3     0.3536   0        0        0        2      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       0
+Frame7:     B    5     4     0.68     0        0        0        2      4     -1 -5  1 3         1     1     5     1 0 1 1 1       0
+Frame8:     B    7     4     0.68     0        0        0        2      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0
+    
+FrameI_l1:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1
+Frame1_l1:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0
+Frame2_l1:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       0
+Frame3_l1:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         0
+Frame4_l1:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       0
+Frame5_l1:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       0
+Frame6_l1:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       0
+Frame7_l1:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       0
+Frame8_l1:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0
+
+FrameI_l2:  B    0     3     0.442    0        0        0        1      0                        0                                 2            0 1       0 -1      -1 0
+Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 1            0         0         -1
+Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       0  
+Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         0  
+Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       0  
+Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       0  
+Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       0  
+Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       0  
+Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0  
+
+
+### DO NOT ADD ANYTHING BELOW THIS LINE ###
+### DO NOT DELETE THE EMPTY LINE BELOW ###
Index: trunk/cfg/MV-HEVC/NonCTC/gopCfg_NoIv_3view.cfg
===================================================================
--- trunk/cfg/MV-HEVC/NonCTC/gopCfg_NoIv_3view.cfg	(revision 622)
+++ trunk/cfg/MV-HEVC/NonCTC/gopCfg_NoIv_3view.cfg	(revision 622)
@@ -0,0 +1,52 @@
+#======== VPS / Layer sets ================
+VpsNumLayerSets               : 4            # Number of layer sets    
+LayerIdsInSet_0               : 0            # LayerIds in vps of layer set
+LayerIdsInSet_1               : 0 1          # LayerIds in vps of layer set
+LayerIdsInSet_2               : 0 2          # LayerIds in vps of layer set
+LayerIdsInSet_3               : 0 1 2        # LayerIds in vps of layer set
+
+DefaultOneTargetOutputLayerFlag: 0           # Output highest layer of layer sets by default
+OutputLayerSetIdx             : 1 2          # Indices of layer sets used as additional output layer sets
+LayerIdsInAddOutputLayerSet_0 : 1            # LayerIds in vps of additional output layers
+LayerIdsInAddOutputLayerSet_1 : 2            # LayerIds in vps of additional output layers
+ProfileLevelTierIdx           : 0 0 0 0 0 0  # Indices to profile level tier (TBD)
+
+#======== VPS / Dependencies ================
+DirectRefLayers_1             :             # LayerIds in vps of direct reference layers 
+DirectRefLayers_2             :             # LayerIds in vps of direct reference layers 
+DependencyTypes_1             :             # Dependency types of direct reference layers, 0: Sample 1: Motion 2: Sample+Motion
+DependencyTypes_2             :             # Dependency types of direct reference layers, 0: Sample 1: Motion 2: Sample+Motion
+
+#                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     
+Frame1:     B    8     1     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   0
+Frame2:     B    4     2     0.3536   0        0        0        2      3     -4 -6  4           1     4     5     1 1 0 0 1         0
+Frame3:     B    2     3     0.3536   0        0        0        2      4     -2 -4  2 6         1     2     4     1 1 1 1           0
+Frame4:     B    1     4     0.68     0        0        0        2      4     -1  1  3 7         1     1     5     1 0 1 1 1         0
+Frame5:     B    3     4     0.68     0        0        0        2      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         0
+Frame6:     B    6     3     0.3536   0        0        0        2      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         0
+Frame7:     B    5     4     0.68     0        0        0        2      4     -1 -5  1 3         1     1     5     1 0 1 1 1         0
+Frame8:     B    7     4     0.68     0        0        0        2      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         0
+                                                                                                                                   
+FrameI_l1:  I    0     3     0.442    0        0        0        1      0                        0                                   0
+Frame1_l1:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   0
+Frame2_l1:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         0
+Frame3_l1:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           0
+Frame4_l1:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         0
+Frame5_l1:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         0
+Frame6_l1:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         0
+Frame7_l1:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         0
+Frame8_l1:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         0
+                                                                                                                                     
+FrameI_l2:  I    0     3     0.442    0        0        0        1      0                        0                                   0
+Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   0
+Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         0
+Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           0
+Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         0
+Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         0
+Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         0
+Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         0
+Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         0
+
+### DO NOT ADD ANYTHING BELOW THIS LINE ###
+### DO NOT DELETE THE EMPTY LINE BELOW ###
Index: trunk/cfg/MV-HEVC/NonCTC/gopCfg_PIP_on_IRAP_3view.cfg
===================================================================
--- trunk/cfg/MV-HEVC/NonCTC/gopCfg_PIP_on_IRAP_3view.cfg	(revision 622)
+++ trunk/cfg/MV-HEVC/NonCTC/gopCfg_PIP_on_IRAP_3view.cfg	(revision 622)
@@ -0,0 +1,56 @@
+# Inter layer prediction only at IRAP pictures
+#
+#======== VPS / Layer sets ================
+VpsNumLayerSets               : 4            # Number of layer sets    
+LayerIdsInSet_0               : 0            # LayerIds in vps of layer set
+LayerIdsInSet_1               : 0 1          # LayerIds in vps of layer set
+LayerIdsInSet_2               : 0 2          # LayerIds in vps of layer set
+LayerIdsInSet_3               : 0 1 2        # LayerIds in vps of layer set
+
+DefaultOneTargetOutputLayerFlag: 0           # Output highest layer of layer sets by default
+OutputLayerSetIdx             : 1 2          # Indices of layer sets used as additional output layer sets
+LayerIdsInAddOutputLayerSet_0 : 1            # LayerIds in vps of additional output layers
+LayerIdsInAddOutputLayerSet_1 : 2            # LayerIds in vps of additional output layers
+ProfileLevelTierIdx           : 0 0 0 0 0 0  # Indices to profile level tier (TBD)
+
+#======== VPS / Dependencies ================
+DirectRefLayers_1             : 0           # LayerIds in vps of direct reference layers 
+DirectRefLayers_2             : 0           # LayerIds in vps of direct reference layers 
+DependencyTypes_1             : 2           # Dependency types of direct reference layers, 0: Sample 1: Motion 2: Sample+Motion
+DependencyTypes_2             : 2           # Dependency types of direct reference layers, 0: Sample 1: Motion 2: Sample+Motion
+
+
+#                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     
+Frame1:     B    8     1     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0
+Frame2:     B    4     2     0.3536   0        0        0        2      3     -4 -6  4           1     4     5     1 1 0 0 1       0
+Frame3:     B    2     3     0.3536   0        0        0        2      4     -2 -4  2 6         1     2     4     1 1 1 1         0
+Frame4:     B    1     4     0.68     0        0        0        2      4     -1  1  3 7         1     1     5     1 0 1 1 1       0
+Frame5:     B    3     4     0.68     0        0        0        2      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       0
+Frame6:     B    6     3     0.3536   0        0        0        2      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       0
+Frame7:     B    5     4     0.68     0        0        0        2      4     -1 -5  1 3         1     1     5     1 0 1 1 1       0
+Frame8:     B    7     4     0.68     0        0        0        2      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0
+    
+FrameI_l1:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1
+Frame1_l1:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0
+Frame2_l1:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       0
+Frame3_l1:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         0
+Frame4_l1:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       0
+Frame5_l1:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       0
+Frame6_l1:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       0
+Frame7_l1:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       0
+Frame8_l1:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0
+
+FrameI_l2:  P    0     3     0.442    0        0        0        1      0                        0                                 1            0         0          -1
+Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                 0  
+Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1       0  
+Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1         0  
+Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1       0  
+Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0       0  
+Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0       0  
+Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1       0  
+Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0       0  
+
+
+### DO NOT ADD ANYTHING BELOW THIS LINE ###
+### DO NOT DELETE THE EMPTY LINE BELOW ###
Index: trunk/cfg/MV-HEVC/baseCfg_2view.cfg
===================================================================
--- trunk/cfg/MV-HEVC/baseCfg_2view.cfg	(revision 609)
+++ trunk/cfg/MV-HEVC/baseCfg_2view.cfg	(revision 622)
@@ -16,9 +16,10 @@
 
 #======== VPS ============================
-ScalabilityMask               : 1           # Scalability Mask             ( 1: View Scalability, shall be 1 for MV-HEVC )
+ScalabilityMask               : 2           # Scalability Mask             ( 2: View Scalability, shall be 2 for MV-HEVC )
 DimensionIdLen                : 3           # Number of bits to store Ids,  per scalability dimension, (m)
-ViewId                        : 0 1         # ViewId  (m) 
+ViewOrderIndex                : 0 1         # ViewOrderIndex (m)
 LayerIdInNuh                  : 0           # Layer Id in NAL unit header, (0: no explicit signalling ) (m)
 SplittingFlag                 : 0           # Splitting Flag 
+ViewId                        : 1 0         # ViewId per ViewOrderIndex (m)
 
 #======== VPS/ Layer sets ================
@@ -53,5 +54,5 @@
 
 #                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
-#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     collocatedRefLayerIdx
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     
 Frame1:     B    8     1        0.442    0            0              0           4                4         -8 -10 -12 -16     0                                          0
 Frame2:     B    4     2        0.3536   0            0              0           2                3         -4 -6  4           1       4        5         1 1 0 0 1       0
@@ -63,13 +64,13 @@
 Frame8:     B    7     4        0.68     0            0              0           2                4         -1 -3 -7 1         1      -2        5         1 1 1 1 0       0
     
-FrameI_l1:  P    0     3     0.442    0        0        0        1      0                        0                                   1          0          0          -1        -1
-Frame1_l1:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   1          0          1          -1        -1
-Frame2_l1:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         1          0          1          -1        -1
-Frame3_l1:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           1          0          1          -1        -1
-Frame4_l1:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         1          0          1          -1        -1
-Frame5_l1:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         1          0          2          -1        -1
-Frame6_l1:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         1          0          2          -1        -1
-Frame7_l1:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         1          0          2          -1        -1
-Frame8_l1:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         1          0          2          -1        -1
+FrameI_l1:  P    0     3     0.442    0        0        0        1      0                        0                                   1          0          0          -1       
+Frame1_l1:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   1          0          1          -1       
+Frame2_l1:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         1          0          1          -1       
+Frame3_l1:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           1          0          1          -1       
+Frame4_l1:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         1          0          1          -1       
+Frame5_l1:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         1          0          2          -1       
+Frame6_l1:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         1          0          2          -1       
+Frame7_l1:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         1          0          2          -1       
+Frame8_l1:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         1          0          2          -1       
 
 #=========== Motion Search =============
Index: trunk/cfg/MV-HEVC/baseCfg_3view.cfg
===================================================================
--- trunk/cfg/MV-HEVC/baseCfg_3view.cfg	(revision 609)
+++ trunk/cfg/MV-HEVC/baseCfg_3view.cfg	(revision 622)
@@ -18,9 +18,10 @@
 
 #======== VPS ============================
-ScalabilityMask               : 1           # Scalability Mask             ( 1: View Scalability, shall be 1 for MV-HEVC )
+ScalabilityMask               : 2           # Scalability Mask             ( 2: View Scalability, shall be 2 for MV-HEVC )
 DimensionIdLen                : 3           # Number of bits to store Ids,  per scalability dimension, (m)
-ViewId                        : 0 1 2       # ViewId  (m) 
-LayerIdInNuh                  : 0           # Layer Id in NAL unit header, (0: no explicit signalling ) (m)
+ViewOrderIndex                : 0 1 2       # ViewOrderIndex, per layer (m)
+LayerIdInNuh                  : 0           # Layer Id in NAL unit header, (0: no explicit signalling, otherwise per layer ) (m)
 SplittingFlag                 : 0           # Splitting Flag 
+ViewId                        : 1 0 2       # ViewId, per ViewOrderIndex (m)
 
 #======== VPS / Layer sets ================
@@ -60,5 +61,5 @@
 
 #                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
-#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     collocatedRefLayerIdx
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     
 
 Frame1:     B    8     1        0.442    0            0              0           4                4         -8 -10 -12 -16     0                                          0
@@ -71,23 +72,23 @@
 Frame8:     B    7     4        0.68     0            0              0           2                4         -1 -3 -7 1         1      -2        5         1 1 1 1 0       0
     
-FrameI_l1:  P    0     3     0.442    0        0        0        1      0                        0                                   1          0         0          -1        -1
-Frame1_l1:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   1          0         1          -1        -1
-Frame2_l1:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         1          0         1          -1        -1
-Frame3_l1:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           1          0         1          -1        -1
-Frame4_l1:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         1          0         1          -1        -1
-Frame5_l1:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         1          0         2          -1        -1
-Frame6_l1:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         1          0         2          -1        -1
-Frame7_l1:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         1          0         2          -1        -1
-Frame8_l1:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         1          0         2          -1        -1
+FrameI_l1:  P    0     3     0.442    0        0        0        1      0                        0                                   1          0         0          -1        
+Frame1_l1:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   1          0         1          -1        
+Frame2_l1:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         1          0         1          -1        
+Frame3_l1:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           1          0         1          -1        
+Frame4_l1:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         1          0         1          -1        
+Frame5_l1:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         1          0         2          -1        
+Frame6_l1:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         1          0         2          -1        
+Frame7_l1:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         1          0         2          -1        
+Frame8_l1:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         1          0         2          -1        
 
-FrameI_l2:  P    0     3     0.442    0        0        0        1      0                        0                                   1          0         0          -1        -1
-Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   1          0         1          -1        -1
-Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         1          0         1          -1        -1
-Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           1          0         1          -1        -1
-Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         1          0         1          -1        -1
-Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         1          0         2          -1        -1
-Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         1          0         2          -1        -1
-Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         1          0         2          -1        -1
-Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         1          0         2          -1        -1
+FrameI_l2:  P    0     3     0.442    0        0        0        1      0                        0                                   1          0         0          -1        
+Frame1_l2:  B    8     4     0.442    0        0        0        4      4     -8 -10 -12 -16     0                                   1          0         1          -1        
+Frame2_l2:  B    4     5     0.3536   0        0        0        3      3     -4 -6  4           1     4     5     1 1 0 0 1         1          0         1          -1        
+Frame3_l2:  B    2     6     0.3536   0        0        0        3      4     -2 -4  2 6         1     2     4     1 1 1 1           1          0         1          -1        
+Frame4_l2:  B    1     7     0.68     0        0        0        3      4     -1  1  3 7         1     1     5     1 0 1 1 1         1          0         1          -1        
+Frame5_l2:  B    3     7     0.68     0        0        0        3      4     -1 -3  1 5         1    -2     5     1 1 1 1 0         1          0         2          -1        
+Frame6_l2:  B    6     6     0.3536   0        0        0        3      4     -2 -4 -6 2         1    -3     5     1 1 1 1 0         1          0         2          -1        
+Frame7_l2:  B    5     7     0.68     0        0        0        3      4     -1 -5  1 3         1     1     5     1 0 1 1 1         1          0         2          -1        
+Frame8_l2:  B    7     7     0.68     0        0        0        3      4     -1 -3 -7 1         1    -2     5     1 1 1 1 0         1          0         2          -1        
 
 #=========== Motion Search =============
Index: trunk/cfg/MV-HEVC/fullCfg.cfg
===================================================================
--- trunk/cfg/MV-HEVC/fullCfg.cfg	(revision 609)
+++ trunk/cfg/MV-HEVC/fullCfg.cfg	(revision 622)
@@ -22,9 +22,10 @@
 
 #======== VPS ============================
-ScalabilityMask               : 1           # Scalability Mask             ( 1: View Scalability, shall be 1 for MV-HEVC )
+ScalabilityMask               : 2           # Scalability Mask             ( 2: View Scalability, shall be 2 for MV-HEVC )
 DimensionIdLen                : 3           # Number of bits to store Ids,  per scalability dimension, (m)
-ViewId                        : 0 1 2       # ViewId  (m) 
+ViewOrderIndex                : 0 1 2       # View Order Index (m)
 LayerIdInNuh                  : 0           # Layer Id in NAL unit header, (0: no explicit signalling ) (m)
 SplittingFlag                 : 0           # Splitting Flag 
+ViewId                        : 1 0 2       # ViewId per ViewOrderIndex (m)
 
 #======== VPS/ Layer sets ================
@@ -56,5 +57,7 @@
 DecodingRefreshType           : 1           # Random Accesss 0:none, 1:CDR, 2:IDR
 GOPSize                       : 8           # GOP Size (number of B slice = GOPSize-1)
-#         Type  POC QPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active #ref_pics reference pictures predict deltaRPS #ref_idcs reference idcs #IL_ref_pics IL reference pics IL ref list pos L0      L1 
+
+#                           QPfactor      betaOffsetDiv2   #ref_pics_active  reference pictures     deltaRPS     reference idcs          ilPredLayerIdc       refLayerPicPosIl_L1
+#         Type  POC QPoffset     tcOffsetDiv2      temporal_id      #ref_pics                 predict     #ref_idcs        #ActiveRefLayerPics     refLayerPicPosIl_L0     
 Frame1:     B    8     1        0.442    0            0              0           4                4         -8 -10 -12 -16     0                                          0
 Frame2:     B    4     2        0.3536   0            0              0           2                3         -4 -6  4           1       4        5         1 1 0 0 1       0
Index: trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 609)
+++ trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 622)
@@ -504,4 +504,8 @@
         const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
 #if H_MV
+#if H_MV5
+        assert( conf   .getScaledFlag() );
+        assert( defDisp.getScaledFlag() );
+#endif
         m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
 #else
@@ -577,4 +581,8 @@
         const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
 #if H_MV
+#if H_MV5
+        assert( conf   .getScaledFlag() );
+        assert( defDisp.getScaledFlag() );
+#endif
         m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
 #else
Index: trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 609)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 622)
@@ -224,8 +224,10 @@
     in>>entry.m_interViewRefPosL[1][i];
   }
+#if !H_MV5
   if (entry.m_numActiveRefLayerPics > 0 )
   {
     in>>entry.m_collocatedRefLayerIdx; 
   }
+#endif
 #endif
   return in;
@@ -367,10 +369,19 @@
   ("NumberOfLayers",        m_numberOfLayers     , 1,                     "Number of layers")
 #if !H_3D
+#if H_MV5
+  ("ScalabilityMask",       m_scalabilityMask    , 2                    , "Scalability Mask")    
+#else
   ("ScalabilityMask",       m_scalabilityMask    , 1                    , "Scalability Mask")    
+#endif
 #else
   ("ScalabilityMask",       m_scalabilityMask    , 3                    , "Scalability Mask, 1: Texture 3: Texture + Depth ")    
 #endif  
   ("DimensionIdLen",        m_dimensionIdLen     , cfg_dimensionLength  , "Number of bits used to store dimensions Id")
+#if H_MV5
+  ("ViewOrderIndex",        m_viewOrderIndex     , std::vector<Int>(1,0), "View Order Index per layer")
+  ("ViewId",                m_viewId             , std::vector<Int>(1,0), "View Id per View Order Index")
+#else
   ("ViewId",                m_viewId             , std::vector<Int>(1,0), "View Id")
+#endif
 #if H_3D
   ("DepthFlag",             m_depthFlag          , std::vector<Int>(1,0), "Depth Flag")
@@ -587,4 +598,24 @@
   ("TargetBitrate,-tbr", m_targetBitrate, 0, "Input target bitrate")
   ("NumLCUInUnit,-nu", m_numLCUInUnit, 0, "Number of LCUs in an Unit")
+#endif
+
+#if H_MV5
+#if H_MV
+  // VPS VUI
+  ("VpsVuiPresentFlag"           , m_vpsVuiPresentFlag           , false                                           , "VpsVuiPresentFlag           ")
+  ("BitRatePresentVpsFlag"       , m_bitRatePresentVpsFlag       , false                                           , "BitRatePresentVpsFlag       ")
+  ("PicRatePresentVpsFlag"       , m_picRatePresentVpsFlag       , false                                           , "PicRatePresentVpsFlag       ")
+  ("BitRatePresentFlag"          , m_bitRatePresentFlag          , std::vector< Bool >(1,0)  ,MAX_VPS_OP_SETS_PLUS1, "BitRatePresentFlag per sub layer for the N-th layer set")
+  ("PicRatePresentFlag"          , m_picRatePresentFlag          , std::vector< Bool >(1,0)  ,MAX_VPS_OP_SETS_PLUS1, "PicRatePresentFlag per sub layer for the N-th layer set")
+  ("AvgBitRate"                  , m_avgBitRate                  , std::vector< Int  >(1,0)  ,MAX_VPS_OP_SETS_PLUS1, "AvgBitRate         per sub layer for the N-th layer set")
+  ("MaxBitRate"                  , m_maxBitRate                  , std::vector< Int  >(1,0)  ,MAX_VPS_OP_SETS_PLUS1, "MaxBitRate         per sub layer for the N-th layer set")
+  ("ConstantPicRateIdc"          , m_constantPicRateIdc          , std::vector< Int  >(1,0)  ,MAX_VPS_OP_SETS_PLUS1, "ConstantPicRateIdc per sub layer for the N-th layer set")
+  ("AvgPicRate"                  , m_avgPicRate                  , std::vector< Int  >(1,0)  ,MAX_VPS_OP_SETS_PLUS1, "AvgPicRate         per sub layer for the N-th layer set")
+  ("TileBoundariesAlignedFlag"   , m_tileBoundariesAlignedFlag   , std::vector< Bool >(1,0)  ,MAX_NUM_LAYERS       , "TileBoundariesAlignedFlag    per direct reference for the N-th layer")
+  ("IlpRestrictedRefLayersFlag"  , m_ilpRestrictedRefLayersFlag  , false                                           , "IlpRestrictedRefLayersFlag")
+  ("MinSpatialSegmentOffsetPlus1", m_minSpatialSegmentOffsetPlus1, std::vector< Int  >(1,0)  ,MAX_NUM_LAYERS       , "MinSpatialSegmentOffsetPlus1 per direct reference for the N-th layer")
+  ("CtuBasedOffsetEnabledFlag"   , m_ctuBasedOffsetEnabledFlag   , std::vector< Bool >(1,0)  ,MAX_NUM_LAYERS       , "CtuBasedOffsetEnabledFlag    per direct reference for the N-th layer")
+  ("MinHorizontalCtuOffsetPlus1" , m_minHorizontalCtuOffsetPlus1 , std::vector< Int  >(1,0)  ,MAX_NUM_LAYERS       , "MinHorizontalCtuOffsetPlus1  per direct reference for the N-th layer")
+#endif
 #endif
 
@@ -719,5 +750,5 @@
   ("ViewSynthesisPred",               m_viewSynthesisPredFlag,  true           , "view synthesis prediction " )  
 #endif
-#if H_3D_TMVP
+#if H_3D
   ("IvMvScaling",                     m_ivMvScalingFlag      ,  true            , "inter view motion vector scaling" )    
 #endif
@@ -731,4 +762,7 @@
     if( k == 0 )
     {
+#if H_MV5
+      m_GOPListMvc[0][0].m_sliceType = 'I'; 
+#endif
       for( Int i = 1; i < MAX_GOP + 1; i++ ) 
       {
@@ -934,4 +968,26 @@
   // allocate slice-based dQP values
 #if H_MV
+#if H_MV5
+  xResizeVector( m_viewOrderIndex    ); 
+
+  std::vector<Int> uniqueViewOrderIndices; 
+  for( Int layer = 0; layer < m_numberOfLayers; layer++ )
+  {    
+    Bool isIn = false; 
+    for ( Int i = 0 ; i < uniqueViewOrderIndices.size(); i++ )
+    {
+      isIn = isIn || ( m_viewOrderIndex[ layer ] == uniqueViewOrderIndices[ i ] ); 
+    }
+    if ( !isIn ) 
+    {
+      uniqueViewOrderIndices.push_back( m_viewOrderIndex[ layer ] ); 
+    } 
+  }
+  m_iNumberOfViews = (Int) uniqueViewOrderIndices.size(); 
+
+#if H_3D
+  xResizeVector( m_depthFlag ); 
+#endif
+#else
   xResizeVector( m_viewId    ); 
 #if H_3D
@@ -954,4 +1010,5 @@
 #endif
 
+#endif
   xResizeVector( m_fQP ); 
 
@@ -1226,4 +1283,20 @@
   xConfirmPara( (m_layerIdInNuh.size()!=1) && (m_layerIdInNuh.size() < m_numberOfLayers) , "LayerIdInNuh must be given for all layers. ");
   
+#if H_MV5
+#if H_3D
+  xConfirmPara( m_scalabilityMask != 2 && m_scalabilityMask != 3, "Scalability Mask must be equal to 2 or 3. ");
+#else
+  xConfirmPara( m_scalabilityMask != 2 , "Scalability Mask must be equal to 2. ");
+#endif
+
+#if H_3D
+  if ( m_scalabilityMask & ( 1 << DEPTH_ID ) )
+  {
+    m_dimIds.push_back( m_depthFlag ); 
+  }
+#endif
+
+  m_dimIds.push_back( m_viewOrderIndex );   
+#else
 #if H_3D
   xConfirmPara( m_scalabilityMask != 1 && m_scalabilityMask != 3, "Scalability Mask must be equal to 1 or 3. ");
@@ -1239,4 +1312,5 @@
 #endif
 
+#endif
   xConfirmPara(  m_dimensionIdLen.size() < m_dimIds.size(), "DimensionIdLen must be given for all dimensions. "   );   Int dimBitOffset[MAX_NUM_SCALABILITY_TYPES+1]; 
 
@@ -1255,5 +1329,9 @@
   {    
     xConfirmPara( m_dimIds[j].size() < m_numberOfLayers,  "DimensionId must be given for all layers and all dimensions. ");   
+#if H_MV5   
+    xConfirmPara( (m_dimIds[j][0] != 0)                 , "DimensionId of layer 0 must be 0. " );
+#else
     xConfirmPara( ( j != viewDimPosition ) &&  (m_dimIds[j][0] != 0), "DimensionId of layer 0 must be 0. " );
+#endif
     xConfirmPara( m_dimensionIdLen[j] < 1 || m_dimensionIdLen[j] > 8, "DimensionIdLen must be greater than 0 and less than 9 in all dimensions. " ); 
      
@@ -1297,16 +1375,31 @@
      {
        Bool inc = m_dimIds[ lastDiff ][ i ] > m_dimIds[ lastDiff ][ j ]; 
+#if H_MV5
+       Bool shallBeButIsNotIncreasing = ( !inc  ) ; 
+#else
        Bool shallBeButIsNotIncreasing = ( !inc && ( lastDiff != viewDimPosition ) ) ; 
+#endif
        if ( shallBeButIsNotIncreasing )
        {       
          printf( "\nError: Positions of Layers %d and %d is not increasing in dimension %d \n", i, j, lastDiff);        
        }
+#if H_MV5
+       xConfirmPara( shallBeButIsNotIncreasing,  "DimensionIds shall be increasing within one dimension. " );
+#else
        xConfirmPara( shallBeButIsNotIncreasing && ( lastDiff != viewDimPosition ),  "DimensionIds shall be increasing within one dimension. " );
+#endif
      }
    }
  }
 
+#if H_MV5
+ /// ViewId 
+ xConfirmPara( m_viewId.size() != m_iNumberOfViews, "The number of ViewIds must be equal to the number of views." ); 
+
   /// Layer sets
+  xConfirmPara( m_vpsNumLayerSets < 0 || m_vpsNumLayerSets > 1024, "VpsNumLayerSets must be greater than 0 and less than 1025. ") ; 
+#else
   xConfirmPara( m_vpsNumLayerSets < 0 || m_vpsNumLayerSets > 1024, "VpsNumLayerSets must be greater than 0 and less than 1025") ; 
+#endif
   for( Int lsIdx = 0; lsIdx < m_vpsNumLayerSets; lsIdx++ )
   {
@@ -2068,4 +2161,28 @@
   }
 #endif
+#if H_MV5
+#if H_MV
+  // VPS VUI
+  for(Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++ )
+  { 
+    for (Int j = 0; j < MAX_TLAYER; j++)
+    {    
+      if ( j < m_avgBitRate        [i].size() ) xConfirmPara( m_avgBitRate[i][j]         <  0 || m_avgBitRate[i][j]         > 65535, "avg_bit_rate            must be more than or equal to     0 and less than 65536" );
+      if ( j < m_maxBitRate        [i].size() ) xConfirmPara( m_maxBitRate[i][j]         <  0 || m_maxBitRate[i][j]         > 65535, "max_bit_rate            must be more than or equal to     0 and less than 65536" );
+      if ( j < m_constantPicRateIdc[i].size() ) xConfirmPara( m_constantPicRateIdc[i][j] <  0 || m_constantPicRateIdc[i][j] >     3, "constant_pic_rate_idc   must be more than or equal to     0 and less than     4" );
+      if ( j < m_avgPicRate        [i].size() ) xConfirmPara( m_avgPicRate[i][j]         <  0 || m_avgPicRate[i][j]         > 65535, "avg_pic_rate            must be more than or equal to     0 and less than 65536" );
+    }
+  }
+  // todo: replace value of 100 with requirement in spec
+  for(Int i = 0; i < MAX_NUM_LAYERS; i++ )
+  { 
+    for (Int j = 0; j < MAX_NUM_LAYERS; j++)
+    {    
+      if ( j < m_minSpatialSegmentOffsetPlus1[i].size() ) xConfirmPara( m_minSpatialSegmentOffsetPlus1[i][j] < 0 || m_minSpatialSegmentOffsetPlus1[i][j] >   100, "min_spatial_segment_offset_plus1 must be more than or equal to     0 and less than   101" );
+      if ( j < m_minHorizontalCtuOffsetPlus1[i] .size() ) xConfirmPara( m_minHorizontalCtuOffsetPlus1[i][j]  < 0 || m_minHorizontalCtuOffsetPlus1[i][j]  >   100, "min_horizontal_ctu_offset_plus1  must be more than or equal to     0 and less than   101" );
+    }
+  }
+#endif
+#endif
 
   xConfirmPara(!m_TransquantBypassEnableFlag && m_CUTransquantBypassFlagValue, "CUTransquantBypassFlagValue cannot be 1 when TransquantBypassEnableFlag is 0");
@@ -2133,5 +2250,10 @@
 #endif
 #if H_MV
+#if H_MV5
+  xPrintParaVector( "ViewIdVal"     , m_viewId ); 
+  xPrintParaVector( "ViewOrderIndex", m_viewOrderIndex ); 
+#else
   xPrintParaVector( "ViewId", m_viewId ); 
+#endif
 #endif
 #if H_3D
@@ -2283,5 +2405,5 @@
   printf("ViewSynthesisPred:%d ", m_viewSynthesisPredFlag );
 #endif
-#if H_3D_TMVP
+#if H_3D
   printf("IvMvScaling:%d ", m_ivMvScalingFlag ? 1 : 0  );
 #endif
Index: trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 609)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 622)
@@ -69,6 +69,10 @@
   std::vector<char*>     m_pchReconFileList;                  ///< output reconstruction file names
   Int                    m_numberOfLayers;                    ///< number of Layers to Encode
+#if H_MV5
+  Int                    m_iNumberOfViews;                    ///< number of Layers that are views
+#else
 #if H_3D
   Int                    m_iNumberOfViews;                    ///< number of Layers that are views
+#endif
 #endif
 #else
@@ -79,4 +83,7 @@
   std::vector< std::vector<Int> > m_dimIds;                   ///< dimension ids ( pointers to m_viewId and m_depthFlag 
   std::vector<Int>       m_viewId;                            ///< view id
+#if H_MV5
+  std::vector<Int>       m_viewOrderIndex;                    ///< view order index  
+#endif
 #if H_3D
   std::vector<Int>       m_depthFlag;                         ///< depth flag
@@ -99,4 +106,22 @@
   std::vector< std::vector<Int> > m_dependencyTypes;          ///< Dependency types of direct reference layers
 
+#if H_MV5
+  // VPS VUI
+  Bool m_vpsVuiPresentFlag;
+  Bool m_bitRatePresentVpsFlag;
+  Bool m_picRatePresentVpsFlag;
+  std::vector< std::vector<Bool > > m_bitRatePresentFlag;
+  std::vector< std::vector<Bool > > m_picRatePresentFlag;
+  std::vector< std::vector<Int  > > m_avgBitRate;
+  std::vector< std::vector<Int  > > m_maxBitRate;
+  std::vector< std::vector<Int  > > m_constantPicRateIdc;
+  std::vector< std::vector<Int  > > m_avgPicRate;
+  std::vector< std::vector<Bool > > m_tileBoundariesAlignedFlag;  
+  Bool m_ilpRestrictedRefLayersFlag;
+  std::vector< std::vector<Int  > > m_minSpatialSegmentOffsetPlus1;
+  std::vector< std::vector<Bool > > m_ctuBasedOffsetEnabledFlag;
+  std::vector< std::vector<Int  > > m_minHorizontalCtuOffsetPlus1;
+#endif
+
 #if H_3D_IV_MERGE
   Bool                   m_ivMvPredFlag;                      ///< Interview motion vector prediction 
@@ -115,5 +140,5 @@
   Bool m_viewSynthesisPredFlag;
 #endif
-#if H_3D_TMVP
+#if H_3D
   Bool m_ivMvScalingFlag; 
 #endif
Index: trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 609)
+++ trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 622)
@@ -88,5 +88,9 @@
     vps.setTemporalNestingFlag(true);
   }
+#if H_MV5
+  vps.setMaxLayersMinus1( m_numberOfLayers - 1);
+#else
   vps.setMaxLayers( m_numberOfLayers );
+#endif
   for(Int i = 0; i < MAX_TLAYER; i++)
   {
@@ -120,12 +124,25 @@
   xSetDependencies( vps );
   xSetProfileTierLevel     ( vps ); 
+#if H_MV5
+  xSetRepFormat            ( vps ); 
+#endif
   xSetLayerSets            ( vps ); 
+#if H_MV5
+  xSetVPSVUI               ( vps ); 
+#endif
 #if H_3D
+#if !H_MV5
   vps.initViewIndex(); 
+#endif
   xSetVPSExtension2        ( vps ); 
   m_ivPicLists.setVPS      ( &vps ); 
 #endif
 
+
+#if H_MV5
+  for(Int layerIdInVps = 0; layerIdInVps < m_numberOfLayers; layerIdInVps++)
+#else 
   for(Int layer = 0; layer < m_numberOfLayers; layer++)
+#endif
   {
     m_frameRcvd                 .push_back(0);
@@ -134,5 +151,14 @@
     m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv);
     m_picYuvRec                 .push_back(new TComList<TComPicYuv*>) ;
-
+#if H_MV5   
+    m_ivPicLists.push_back( m_acTEncTopList[ layerIdInVps ]->getListPic()  ); 
+    TEncTop& m_cTEncTop = *m_acTEncTopList[ layerIdInVps ];  // It is not a member, but this name helps avoiding code duplication !!!
+
+    Int layerId = vps.getLayerIdInNuh( layerIdInVps );
+    m_cTEncTop.setLayerIdInVps                 ( layerIdInVps ); 
+    m_cTEncTop.setLayerId                      ( layerId );    
+    m_cTEncTop.setViewId                       ( vps.getViewId      (  layerId ) );
+    m_cTEncTop.setViewIndex                    ( vps.getViewIndex   (  layerId ) );
+#else
     m_ivPicLists.push_back( m_acTEncTopList[ layer ]->getListPic()  ); 
     TEncTop& m_cTEncTop = *m_acTEncTopList[ layer ];  // It is not a member, but this name helps avoiding code duplication !!!
@@ -141,7 +167,13 @@
     m_cTEncTop.setLayerId                      ( vps.getLayerIdInNuh( layer ) );    
     m_cTEncTop.setViewId                       ( vps.getViewId      ( layer ) );
+
+#endif
 #if H_3D
+#if H_MV5
+    Bool isDepth = ( vps.getDepthId     ( layerId ) != 0 ) ;
+#else
     Bool isDepth = ( vps.getDepthId     ( layer ) != 0 ) ;
     m_cTEncTop.setViewIndex                    ( vps.getViewIndex   ( layer ) );
+#endif
     m_cTEncTop.setIsDepth                      ( isDepth );
     //====== Camera Parameters =========
@@ -169,4 +201,14 @@
     m_cTEncTop.setDWeight                      ( isDepth ? m_iDWeight             : 0     );
 #endif // H_3D_VSO
+#if H_MV5
+#if H_3D_ARP
+    //====== Advanced Inter-view Residual Prediction =========
+    m_cTEncTop.setUseAdvRP                     ( ( isDepth || 0==layerIdInVps ) ? 0 : m_uiUseAdvResPred );
+    m_cTEncTop.setARPStepNum                   ( ( isDepth || 0==layerIdInVps ) ? 1 : H_3D_ARP_WFNR     );
+#endif
+#if H_3D_IC
+    m_cTEncTop.setUseIC                        ( vps.getViewIndex( layerId ) == 0 ? false : m_abUseIC[isDepth ? 1 : 0] );
+#endif
+#else
 #if H_3D_ARP
     //====== Advanced Inter-view Residual Prediction =========
@@ -176,4 +218,5 @@
 #if H_3D_IC
     m_cTEncTop.setUseIC                        ( vps.getViewIndex( layer ) == 0 ? false : m_abUseIC[isDepth ? 1 : 0] );
+#endif
 #endif
   //========== Depth intra modes ==========
@@ -217,4 +260,13 @@
   m_cTEncTop.setGOPSize                      ( m_iGOPSize );
 #if H_MV
+#if H_MV5
+m_cTEncTop.setGopList                      ( m_GOPListMvc[layerIdInVps] );
+  m_cTEncTop.setExtraRPSs                    ( m_extraRPSsMvc[layerIdInVps] );
+  for(Int i = 0; i < MAX_TLAYER; i++)
+  {
+    m_cTEncTop.setNumReorderPics             ( m_numReorderPicsMvc[layerIdInVps][i], i );
+    m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBufferingMvc[layerIdInVps][i], i );
+  }
+#else
   m_cTEncTop.setGopList                      ( m_GOPListMvc[layer] );
   m_cTEncTop.setExtraRPSs                    ( m_extraRPSsMvc[layer] );
@@ -224,4 +276,5 @@
     m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBufferingMvc[layer][i], i );
   }
+#endif
 #else
   m_cTEncTop.setGopList                      ( m_GOPList );
@@ -238,5 +291,9 @@
   }
 #if H_MV
+#if H_MV5
+  m_cTEncTop.setQP                           ( m_iQP[layerIdInVps] );
+#else
   m_cTEncTop.setQP                           ( m_iQP[layer] );
+#endif
 #else
   m_cTEncTop.setQP                           ( m_iQP );
@@ -246,5 +303,9 @@
 
 #if H_MV
+#if H_MV5
+  m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayerMvc[layerIdInVps] );
+#else
   m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayerMvc[layer] );
+#endif
 #else
   m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayer );
@@ -256,5 +317,9 @@
   //====== Loop/Deblock Filter ========
 #if H_MV
+#if H_MV5
+  m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable[layerIdInVps]);
+#else
   m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable[layer]);
+#endif
 #else
   m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable       );
@@ -286,5 +351,9 @@
 
 #if H_MV
+#if H_MV5
+  if ((m_iMaxDeltaQP == 0 ) && (m_iQP[layerIdInVps] == lowestQP) && (m_useLossless == true))
+#else
   if ((m_iMaxDeltaQP == 0 ) && (m_iQP[layer] == lowestQP) && (m_useLossless == true))
+#endif
 #else
   if ((m_iMaxDeltaQP == 0 ) && (m_iQP == lowestQP) && (m_useLossless == true))
@@ -303,5 +372,9 @@
   m_cTEncTop.setUseLossless                  ( m_useLossless );
 #if H_MV
+#if H_MV5
+  m_cTEncTop.setdQPs                         ( m_aidQP[layerIdInVps]   );
+#else
   m_cTEncTop.setdQPs                         ( m_aidQP[layer]   );
+#endif
 #else
   m_cTEncTop.setdQPs                         ( m_aidQP        );
@@ -362,5 +435,9 @@
   m_cTEncTop.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
 #if H_MV
+#if H_MV5
+  m_cTEncTop.setUseSAO ( m_bUseSAO[layerIdInVps] );
+#else
   m_cTEncTop.setUseSAO ( m_bUseSAO[layer] );
+#endif
 #else
   m_cTEncTop.setUseSAO ( m_bUseSAO );
@@ -1044,13 +1121,37 @@
 Void TAppEncTop::xSetDimensionIdAndLength( TComVPS& vps )
 {   
+#if H_MV5
+  vps.setScalabilityMaskFlag( m_scalabilityMask ); 
+#else
   vps.setScalabilityMask( m_scalabilityMask ); 
+#endif
   for( Int dim = 0; dim < m_dimIds.size(); dim++ )
   {
     vps.setDimensionIdLen( dim, m_dimensionIdLen[ dim ] );
+#if H_MV5
+    for( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ )
+#else
     for( Int layer = 0; layer < vps.getMaxLayers(); layer++ )
+#endif
+
     {        
       vps.setDimensionId( layer, dim, m_dimIds[ dim ][ layer ] );        
     }  
   }
+
+#if H_MV5
+  Int maxViewId = xGetMax( m_viewId ); 
+
+  Int viewIdLenMinus1 = std::max( gCeilLog2( maxViewId + 1 ) - 1, 0 ) ; 
+  const Int maxViewIdLenMinus1 = ( 1 << 4 ) - 1; 
+  assert( viewIdLenMinus1 <= maxViewIdLenMinus1  ); 
+  vps.setViewIdLenMinus1( viewIdLenMinus1 ); 
+  for (Int i = 0; i < m_iNumberOfViews; i++)
+  {
+    vps.setViewIdVal( i, m_viewId[ i] ); 
+  }
+
+  assert( m_iNumberOfViews == vps.getNumViews() ); 
+#endif
 }
 
@@ -1078,5 +1179,8 @@
   }
 
-  // Max temporal id for inter layer reference pictures
+  // Max temporal id for inter layer reference pictures + presence flag
+#if H_MV5
+  Bool maxTidRefPresentFlag = false; 
+#endif
   for ( Int refLayerIdInVps = 0; refLayerIdInVps < m_numberOfLayers; refLayerIdInVps++)
     {
@@ -1099,13 +1203,27 @@
     }
     vps.setMaxTidIlRefPicPlus1( refLayerIdInVps, maxTid + 1 );
-  }
-
+#if H_MV5
+    maxTidRefPresentFlag = maxTidRefPresentFlag || ( maxTid != 6 );    
+#endif
+  }
+
+#if H_MV5
+  vps.setMaxTidRefPresentFlag( maxTidRefPresentFlag );
+#endif
   // Max one active ref layer flag
   Bool maxOneActiveRefLayerFlag = true;  
+#if H_MV5
+  for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && maxOneActiveRefLayerFlag; layerIdInVps++)
+#else
   for ( Int currLayerIdInVps = 1; currLayerIdInVps < m_numberOfLayers && maxOneActiveRefLayerFlag; currLayerIdInVps++)
+#endif
   {
     for( Int i = 0; i < ( getGOPSize() + 1) && maxOneActiveRefLayerFlag; i++ ) 
     {        
+#if H_MV5
+      GOPEntry ge =  m_GOPListMvc[layerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]; 
+#else
       GOPEntry ge =  m_GOPListMvc[currLayerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]; 
+#endif
       maxOneActiveRefLayerFlag =  maxOneActiveRefLayerFlag && (ge.m_numActiveRefLayerPics <= 1); 
     }            
@@ -1113,7 +1231,43 @@
 
   vps.setMaxOneActiveRefLayerFlag( maxOneActiveRefLayerFlag );
+  
+  
+#if H_MV5
+  // All Ref layers active flag
+  Bool allRefLayersActiveFlag = true; 
+  for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && allRefLayersActiveFlag; layerIdInVps++)
+  {    
+    for( Int i = 0; i < ( getGOPSize() + 1) && allRefLayersActiveFlag; i++ ) 
+    {        
+      GOPEntry ge =  m_GOPListMvc[layerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]; 
+      allRefLayersActiveFlag = allRefLayersActiveFlag && (ge.m_numActiveRefLayerPics == m_directRefLayers[ layerIdInVps ].size() ); 
+    }            
+  }
+
+  vps.setAllRefLayersActiveFlag( allRefLayersActiveFlag );
+
+  // Currently cross layer irap aligned is always true.   
+  vps.setCrossLayerIrapAlignedFlag( true ); 
+#endif
   vps.setRefLayers(); 
 }; 
 
+#if H_MV5
+GOPEntry* TAppEncTop::xGetGopEntry( Int layerIdInVps, Int poc )
+{
+  GOPEntry* geFound = NULL; 
+  for( Int i = 0; i < ( getGOPSize() + 1) && geFound == NULL ; i++ ) 
+  {
+    GOPEntry* ge = &(m_GOPListMvc[layerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]);
+    if ( ge->m_POC == poc )
+    {
+      geFound = ge;       
+    }
+  }
+  assert( geFound != NULL ); 
+  return geFound; 
+}
+#endif
+
 Void TAppEncTop::xSetLayerIds( TComVPS& vps )
 {
@@ -1137,5 +1291,7 @@
   Int maxVec = 0; 
   for ( Int i = 0; i < vec.size(); i++)    
+  {
     maxVec = max( vec[i], maxVec ); 
+  }
   return maxVec;
 }
@@ -1152,4 +1308,30 @@
 }
 
+#if H_MV5
+
+Void TAppEncTop::xSetRepFormat( TComVPS& vps )
+{
+  vps.setRepFormatIdxPresentFlag( true ); 
+  vps.setVpsNumRepFormatsMinus1 ( 0    ); 
+
+  TComRepFormat* repFormat = new TComRepFormat; 
+
+  repFormat->setBitDepthVpsChromaMinus8   ( g_bitDepthC - 8 ); 
+  repFormat->setBitDepthVpsLumaMinus8     ( g_bitDepthY - 8 );
+  repFormat->setChromaFormatVpsIdc        ( CHROMA_420      );
+  repFormat->setPicHeightVpsInLumaSamples ( m_iSourceHeight );
+  repFormat->setPicWidthVpsInLumaSamples  ( m_iSourceWidth  );    
+  // ToDo not supported yet. 
+  //repFormat->setSeparateColourPlaneVpsFlag( );
+
+  assert( vps.getRepFormat( 0 ) == NULL ); 
+  vps.setRepFormat( 0 , repFormat );
+
+  for(Int i = 0; i <= vps.getMaxLayersMinus1(); i++ )
+  {
+    vps.setVpsRepFormatIdx( i , 0 ); 
+  }
+}
+#endif
 
 Void TAppEncTop::xSetLayerSets( TComVPS& vps )
@@ -1204,9 +1386,106 @@
   }
 }
+#if H_MV5
+
+Void TAppEncTop::xSetVPSVUI( TComVPS& vps )
+{
+  vps.setVpsVuiPresentFlag( m_vpsVuiPresentFlag ); 
+
+  if ( m_vpsVuiPresentFlag )
+  {
+    TComVPSVUI* pcVPSVUI = vps.getVPSVUI(  ); 
+
+    assert( pcVPSVUI ); 
+
+    pcVPSVUI->setBitRatePresentVpsFlag( m_bitRatePresentVpsFlag );
+    pcVPSVUI->setPicRatePresentVpsFlag( m_picRatePresentVpsFlag );
+
+    if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
+    {
+      for( Int i = 0; i  <=  vps.getVpsNumberLayerSetsMinus1(); i++ )
+      {
+        for( Int j = 0; j  <=  vps.getMaxTLayers(); j++ ) 
+        {
+          if( pcVPSVUI->getBitRatePresentVpsFlag( ) && m_bitRatePresentFlag[i].size() > j )
+          {
+            pcVPSVUI->setBitRatePresentFlag( i, j, m_bitRatePresentFlag[i][j] );            
+          }
+          if( pcVPSVUI->getPicRatePresentVpsFlag( ) && m_picRatePresentFlag[i].size() > j   )
+          {
+            pcVPSVUI->setPicRatePresentFlag( i, j, m_picRatePresentFlag[i][j] );
+          }
+          if( pcVPSVUI->getBitRatePresentFlag( i, j )  && m_avgBitRate[i].size() > j )
+          {
+            pcVPSVUI->setAvgBitRate( i, j, m_avgBitRate[i][j] );          
+          }
+          if( pcVPSVUI->getBitRatePresentFlag( i, j )  && m_maxBitRate[i].size() > j )
+          {
+            pcVPSVUI->setMaxBitRate( i, j, m_maxBitRate[i][j] );
+          }
+          if( pcVPSVUI->getPicRatePresentFlag( i, j ) && m_constantPicRateIdc[i].size() > j )
+          {
+            pcVPSVUI->setConstantPicRateIdc( i, j, m_constantPicRateIdc[i][j] );
+          }
+          if( pcVPSVUI->getPicRatePresentFlag( i, j ) && m_avgPicRate[i].size() > j )
+          {
+            pcVPSVUI->setAvgPicRate( i, j, m_avgPicRate[i][j] );
+          }
+        }
+      }
+    }
+
+    for( Int i = 1; i  <=  vps.getMaxLayersMinus1(); i++ )
+    {
+      for( Int  j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ); j++ ) 
+      {
+        if ( m_tileBoundariesAlignedFlag[i].size() > j )
+        {
+          pcVPSVUI->setTileBoundariesAlignedFlag( i, j, m_tileBoundariesAlignedFlag[i][j]);
+        }
+      }
+    }
+
+    pcVPSVUI->setIlpRestrictedRefLayersFlag( m_ilpRestrictedRefLayersFlag );
+
+    if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
+    {
+      for( Int i = 1; i  <=  vps.getMaxLayersMinus1(); i++ )
+      {
+        for( Int j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ); j++ )
+        {
+          if ( m_minSpatialSegmentOffsetPlus1[i].size() > j )
+          {        
+            pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, m_minSpatialSegmentOffsetPlus1[i][j] );
+          }
+          if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
+          {
+            if ( m_ctuBasedOffsetEnabledFlag[i].size() > j )
+            {        
+              pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, m_ctuBasedOffsetEnabledFlag[i][j] );
+            }
+            if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
+            {
+              if ( m_minHorizontalCtuOffsetPlus1[i].size() > j )
+              {
+                pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, m_minHorizontalCtuOffsetPlus1[i][j] );
+              }
+            }
+          }
+        }
+      }
+    }      
+  }
+}
+#endif
 #endif
 #if H_3D
 Void TAppEncTop::xSetVPSExtension2( TComVPS& vps )
 {
+#if H_MV5
+
+  for ( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ )
+#else
   for ( Int layer = 0; layer < vps.getMaxLayers(); layer++ )
+#endif
   {
     Bool isDepth      = ( vps.getDepthId( layer ) == 1 ) ;
@@ -1242,5 +1521,5 @@
 #endif
   }  
-#if H_3D_TMVP
+#if H_3D
   vps.setIvMvScalingFlag( m_ivMvScalingFlag );   
 #endif
Index: trunk/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.h	(revision 609)
+++ trunk/source/App/TAppEncoder/TAppEncTop.h	(revision 622)
@@ -121,4 +121,9 @@
   Void xSetLayerSets              ( TComVPS& vps );
   Void xSetProfileTierLevel       ( TComVPS& vps );
+#if H_MV5
+  Void xSetRepFormat              ( TComVPS& vps );
+  Void xSetVPSVUI                 ( TComVPS& vps );
+  GOPEntry* xGetGopEntry( Int layerIdInVps, Int poc );
+#endif
   Int  xGetMax( std::vector<Int>& vec);
 #endif
Index: trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/CommonDef.h	(revision 609)
+++ trunk/source/Lib/TLibCommon/CommonDef.h	(revision 622)
@@ -48,4 +48,7 @@
 #endif // _MSC_VER > 1000
 #include "TypeDef.h"
+#if H_MV
+#include <assert.h>
+#endif
 
 //! \ingroup TLibCommon
@@ -183,4 +186,15 @@
     return (t < 0) ? T(-1) : T(1);
 }
+
+#if H_MV5
+template <typename T>
+__inline T gCeilLog2( T val )
+{
+  assert( val > 0 ); 
+  Int ceilLog2 = 0;
+  while( val > ( 1 << ceilLog2 ) ) ceilLog2++;
+  return ceilLog2;
+}
+#endif
 
 #define RemoveBitIncrement( exp ) ( exp >> ( g_bitDepthY - 8 ) )
Index: trunk/source/Lib/TLibCommon/ContextTables.h
===================================================================
--- trunk/source/Lib/TLibCommon/ContextTables.h	(revision 609)
+++ trunk/source/Lib/TLibCommon/ContextTables.h	(revision 622)
@@ -112,5 +112,5 @@
 #if H_3D_DIM_DMM
 #define NUM_DMM1_DATA_CTX             1       ///< number of context models for DMM1 data
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
 #define NUM_DMM2_DATA_CTX             1       ///< number of context models for DMM2 data
 #endif
@@ -429,5 +429,5 @@
   { CNU }, 
 };
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
 static const UChar
 INIT_DMM2_DATA[3][NUM_DMM2_DATA_CTX] = 
Index: trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 622)
@@ -120,5 +120,5 @@
     m_dmmWedgeTabIdx[i] = NULL;
   }
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   m_dmm2DeltaEnd    = NULL;
 #endif
@@ -146,7 +146,4 @@
 #if H_3D_VSP
   m_piVSPFlag            = NULL;
-#if MTK_VSP_FIX_E0172
-  m_piVSPDir             = NULL;
-#endif
 #endif
 #if H_3D_ARP
@@ -200,7 +197,4 @@
 #if H_3D_VSP
     m_piVSPFlag          = (Char*  )xMalloc(Char,   uiNumPartition);
-#if MTK_VSP_FIX_E0172
-    m_piVSPDir           = (Char*  )xMalloc(Char,   uiNumPartition);
-#endif
 #endif
     m_puhLumaIntraDir    = (UChar* )xMalloc(UChar,  uiNumPartition);
@@ -280,5 +274,5 @@
       m_dmmWedgeTabIdx[i]    = (UInt*)xMalloc(UInt, uiNumPartition);
     }
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
     m_dmm2DeltaEnd    = (Int* )xMalloc(Int,  uiNumPartition);
 #endif
@@ -363,7 +357,4 @@
 #if H_3D_VSP
     if ( m_piVSPFlag          ) { xFree(m_piVSPFlag);           m_piVSPFlag         = NULL; }
-#if MTK_VSP_FIX_E0172
-    if ( m_piVSPDir           ) { xFree(m_piVSPDir  );          m_piVSPDir          = NULL; }
-#endif
 #endif
     if ( m_puhLumaIntraDir    ) { xFree(m_puhLumaIntraDir);     m_puhLumaIntraDir   = NULL; }
@@ -419,5 +410,5 @@
       if ( m_dmmWedgeTabIdx[i] ) { xFree( m_dmmWedgeTabIdx[i] ); m_dmmWedgeTabIdx[i] = NULL; }
     }
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
     if ( m_dmm2DeltaEnd    ) { xFree( m_dmm2DeltaEnd    ); m_dmm2DeltaEnd    = NULL; }
 #endif
@@ -573,7 +564,4 @@
 #if H_3D_VSP
     m_piVSPFlag[ui] = pcFrom->m_piVSPFlag[ui];
-#if MTK_VSP_FIX_E0172
-    m_piVSPDir  [ui] = pcFrom->m_piVSPDir[ui];
-#endif
 #endif
     m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
@@ -618,7 +606,4 @@
 #if H_3D_VSP
     memset( m_piVSPFlag         + firstElement, 0,                        numElements * sizeof( *m_piVSPFlag ) );
-#if MTK_VSP_FIX_E0172
-    memset( m_piVSPDir          + firstElement, 0,                        numElements * sizeof( *m_piVSPDir   ) );
-#endif
 #endif
     memset( m_puhLumaIntraDir   + firstElement, DC_IDX,                   numElements * sizeof( *m_puhLumaIntraDir ) );
@@ -646,5 +631,5 @@
       memset( m_dmmWedgeTabIdx[i] + firstElement, 0,                      numElements * sizeof( *m_dmmWedgeTabIdx[i] ) );
     }
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
     memset( m_dmm2DeltaEnd      + firstElement, 0,                        numElements * sizeof( *m_dmm2DeltaEnd    ) );
 #endif
@@ -802,7 +787,4 @@
 #if H_3D_VSP
       m_piVSPFlag[ui] = 0;
-#if MTK_VSP_FIX_E0172
-      m_piVSPDir  [ui] = 0;
-#endif
 #endif
       m_puhLumaIntraDir[ui] = DC_IDX;
@@ -829,5 +811,5 @@
         m_dmmWedgeTabIdx[i] [ui] = 0;
       }
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
       m_dmm2DeltaEnd    [ui] = 0;
 #endif
@@ -906,7 +888,4 @@
 #if H_3D_VSP
   memset( m_piVSPFlag,          0, sizeof( Char  ) * m_uiNumPartition );
-#if MTK_VSP_FIX_E0172
-  memset( m_piVSPDir  ,         0, sizeInChar );
-#endif
 #endif
   memset( m_puhLumaIntraDir,    DC_IDX, iSizeInUchar );
@@ -946,5 +925,5 @@
     memset( m_dmmWedgeTabIdx[i], 0, sizeof(UInt) * m_uiNumPartition );
   }
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   memset( m_dmm2DeltaEnd   , 0, sizeof(Int ) * m_uiNumPartition );
 #endif
@@ -1005,10 +984,5 @@
 #if H_3D_VSP
       m_piVSPFlag[ui]=pcCU->m_piVSPFlag[uiPartOffset+ui];
-#if MTK_VSP_FIX_ALIGN_WD_E0172
       m_pDvInfo[ ui ] = pcCU->m_pDvInfo[uiPartOffset+ui];
-#endif
-#if MTK_VSP_FIX_E0172
-      m_piVSPDir[ui]=pcCU->m_piVSPDir[uiPartOffset+ui];
-#endif
 #endif
       m_puhLumaIntraDir[ui]=pcCU->m_puhLumaIntraDir[uiPartOffset+ui];
@@ -1036,5 +1010,5 @@
         m_dmmWedgeTabIdx[i] [ui] = pcCU->m_dmmWedgeTabIdx[i] [uiPartOffset+ui];
       }
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
       m_dmm2DeltaEnd    [ui] = pcCU->m_dmm2DeltaEnd   [uiPartOffset+ui];
 #endif
@@ -1162,7 +1136,4 @@
 #if H_3D_VSP
   m_piVSPFlag           = pcCU->getVSPFlag()          + uiPart;
-#if MTK_VSP_FIX_E0172
-  m_piVSPDir            = pcCU->getVSPDir  ()         + uiPart;
-#endif
 #endif
 
@@ -1196,5 +1167,5 @@
     m_dmmWedgeTabIdx[i] = pcCU->getDmmWedgeTabIdx( i ) + uiPart;
   }
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   m_dmm2DeltaEnd    = pcCU->getDmm2DeltaEnd()    + uiPart;
 #endif
@@ -1321,10 +1292,5 @@
 #if H_3D_VSP
   m_piVSPFlag          = pcCU->getVSPFlag()               + uiAbsPartIdx;
-#if MTK_VSP_FIX_ALIGN_WD_E0172
   m_pDvInfo            = pcCU->getDvInfo()                + uiAbsPartIdx;
-#endif
-#if MTK_VSP_FIX_E0172
-  m_piVSPDir           = pcCU->getVSPDir  ()              + uiAbsPartIdx;
-#endif
 #endif
 
@@ -1374,10 +1340,6 @@
 #if H_3D_VSP
   memcpy( m_piVSPFlag           + uiOffset, pcCU->getVSPFlag(),           sizeof( Char ) * uiNumPartition );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
   memcpy( m_pDvInfo             + uiOffset, pcCU->getDvInfo(),            sizeof( *m_pDvInfo ) * uiNumPartition );
-#endif
-#if MTK_VSP_FIX_E0172
-  memcpy( m_piVSPDir            + uiOffset, pcCU->getVSPDir  (),          sizeInChar );
-#endif
+
 #endif
   memcpy( m_puhLumaIntraDir     + uiOffset, pcCU->getLumaIntraDir(),      iSizeInUchar );
@@ -1404,5 +1366,5 @@
     memcpy( m_dmmWedgeTabIdx[i] + uiOffset, pcCU->getDmmWedgeTabIdx( i ), sizeof(UInt) * uiNumPartition );
   }
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   memcpy( m_dmm2DeltaEnd    + uiOffset, pcCU->getDmm2DeltaEnd()   , sizeof(Int ) * uiNumPartition );
 #endif
@@ -1509,10 +1471,5 @@
 #if H_3D_VSP
   memcpy( rpcCU->getVSPFlag()           + m_uiAbsIdxInLCU, m_piVSPFlag,           sizeof( Char ) * m_uiNumPartition );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
   memcpy( rpcCU->getDvInfo()            + m_uiAbsIdxInLCU, m_pDvInfo,             sizeof( *m_pDvInfo ) * m_uiNumPartition );
-#endif
-#if MTK_VSP_FIX_E0172
-  memcpy( rpcCU->getVSPDir  ()          + m_uiAbsIdxInLCU, m_piVSPDir  ,          sizeInChar );
-#endif
 #endif
   memcpy( rpcCU->getLumaIntraDir()      + m_uiAbsIdxInLCU, m_puhLumaIntraDir,     iSizeInUchar );
@@ -1539,5 +1496,5 @@
     memcpy( rpcCU->getDmmWedgeTabIdx( i ) + m_uiAbsIdxInLCU, m_dmmWedgeTabIdx[i], sizeof(UInt) * m_uiNumPartition );
   }
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   memcpy( rpcCU->getDmm2DeltaEnd()    + m_uiAbsIdxInLCU, m_dmm2DeltaEnd   , sizeof(Int ) * m_uiNumPartition );
 #endif
@@ -1632,7 +1589,4 @@
 #if H_3D_VSP
   memcpy( rpcCU->getVSPFlag()           + uiPartOffset, m_piVSPFlag,           sizeof(Char) * uiQNumPart );
-#if MTK_VSP_FIX_E0172
-  memcpy( rpcCU->getVSPDir  ()          + uiPartOffset, m_piVSPDir  ,          sizeInChar );
-#endif
 #endif
   memcpy( rpcCU->getLumaIntraDir()      + uiPartOffset, m_puhLumaIntraDir,     iSizeInUchar );
@@ -1658,5 +1612,5 @@
     memcpy( rpcCU->getDmmWedgeTabIdx( i ) + uiPartOffset, m_dmmWedgeTabIdx[i], sizeof(UInt) * uiQNumPart );
   }
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   memcpy( rpcCU->getDmm2DeltaEnd()    + uiPartOffset, m_dmm2DeltaEnd   , sizeof(Int ) * uiQNumPart );
 #endif
@@ -2761,5 +2715,5 @@
   setSubPart<Char>( iVSPFlag, m_piVSPFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
 }
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
 template<typename T>
 Void TComDataCU::setSubPartT( T uiParameter, T* puhBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
@@ -2895,10 +2849,4 @@
   }
 
-}
-#endif
-#if MTK_VSP_FIX_E0172
-Void TComDataCU::setVSPDirSubParts ( Char iVSPDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
-{
-  setSubPart<Char>( iVSPDir, m_piVSPDir, uiAbsPartIdx, uiDepth, uiPartIdx );
 }
 #endif
@@ -3355,58 +3303,39 @@
  *   false: otherwise
  */
-#if MTK_VSP_FIX_E0172
-inline Bool TComDataCU::xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
-                                    Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag, Int* vspDir )
-#else
-inline Bool TComDataCU::xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
+inline Bool TComDataCU::xAddVspCand( Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
                                      Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag )
-#endif
-{
-  if ( ucVspMergePos != H_3D_VSP_POSITION || 0 == m_pcSlice->getViewIndex() || !m_pcSlice->getVPS()->getViewSynthesisPredFlag( m_pcSlice->getLayerIdInVps() ) || m_pcSlice->getIsDepth() )
+{
+  if ( m_pcSlice->getViewIndex() == 0 || !m_pcSlice->getVPS()->getViewSynthesisPredFlag( m_pcSlice->getLayerIdInVps() ) || m_pcSlice->getIsDepth() )
+  {
     return false;
+  }
 
   Int refViewIdx = pDInfo->m_aVIdxCan;
   TComPic* picDepth = getSlice()->getIvPic( true, refViewIdx );
+  
   if( picDepth == NULL ) // No depth reference avail
+  {
+    // Is this allowed to happen? When not an assertion should be added here!
     return false;
-  
-  Bool refViewAvailFlag = false;
-  UChar predFlag[2] = {0, 0};
-  Int  iRefListIdX = 0;
-  Int  iRefListIdY = 0;
-  Int  i;
-#if MTK_VSP_FIX_ALIGN_WD_E0172
-  Int currViewId = m_pcSlice->getViewId();
-  Int derivedViewId = -1;
-  Int otherViewId = -1;
-#endif
-#if MTK_VSP_FIX_E0172
-  Int currViewId = m_pcSlice->getViewId();
-  Int derivedViewId = -1;
-  Int otherViewId = -1;
-#endif
-  for( iRefListIdX = 0; iRefListIdX < 2 && !refViewAvailFlag; iRefListIdX++ )
-  {
-    RefPicList eRefPicList = RefPicList( iRefListIdX );
-    for ( i = 0; i < m_pcSlice->getNumRefIdx(eRefPicList) && !refViewAvailFlag; i++ )
-    {
-      Int viewIdxRefInList = m_pcSlice->getRefPic(eRefPicList, i)->getViewIndex();
-      if ( viewIdxRefInList == refViewIdx )
-      {
-        refViewAvailFlag = true;
+  }
+  
+  Bool  refViewAvailFlag = false;
+  UChar predFlag[2]      = {0, 0};  
+  Int   refListIdY       = 0;    
+  Int   viewIdInRefListX = -1;
+  
+  for( Int iRefListIdX = 0; iRefListIdX < 2 && !refViewAvailFlag; iRefListIdX++ )
+  {
+    RefPicList eRefPicListX = RefPicList( iRefListIdX );
+    for ( Int i = 0; i < m_pcSlice->getNumRefIdx(eRefPicListX) && !refViewAvailFlag; i++ )
+    {
+      Int viewIdxRefInListX = m_pcSlice->getRefPic(eRefPicListX, i)->getViewIndex();
+      if ( viewIdxRefInListX == refViewIdx )
+      {
+        refViewAvailFlag      = true;
         predFlag[iRefListIdX] = 1;
-#if MTK_VSP_FIX_ALIGN_WD_E0172
-        derivedViewId = m_pcSlice->getRefPic(eRefPicList, i)->getViewId();
-#endif
-#if MTK_VSP_FIX_E0172
-        vspDir[iCount] = iRefListIdX;
-        derivedViewId = m_pcSlice->getRefPic(eRefPicList, i)->getViewId(); 
-#endif
-        iRefListIdY = 1 - iRefListIdX;
-#if H_3D_FIX_BVSP
+        viewIdInRefListX      = m_pcSlice->getRefPic(eRefPicListX, i)->getViewId();
+        refListIdY            = 1 - iRefListIdX;
         pcMvFieldNeighbours[(iCount<<1)+iRefListIdX].setMvField( pDInfo->m_acNBDV, i );
-#else
-        pcMvFieldNeighbours[(iCount<<1)+iRefListIdX].setMvField( pDInfo->m_acDoNBDV, i );
-#endif
 #if H_3D_NBDV
         pcMvFieldNeighbours[(iCount<<1)+iRefListIdX].getMv().setIDVFlag (false);
@@ -3418,21 +3347,24 @@
   if (m_pcSlice->isInterB() && refViewAvailFlag)
   {
-    RefPicList eRefPicList = RefPicList( iRefListIdY );
+    RefPicList eRefPicListY = RefPicList( refListIdY );
     refViewAvailFlag = false;
-    for ( i = 0; i < m_pcSlice->getNumRefIdx(eRefPicList) && !refViewAvailFlag; i++ )
-    {
-      Int viewIdxRefInList = m_pcSlice->getRefPic(eRefPicList, i)->getViewIndex();
-      if ( viewIdxRefInList != refViewIdx && viewIdxRefInList != m_pcSlice->getViewIndex() )
+    for ( Int i = 0; i < m_pcSlice->getNumRefIdx(eRefPicListY) && !refViewAvailFlag; i++ )
+    {
+      Int viewIdxRefInListY = m_pcSlice->getRefPic(eRefPicListY, i)->getViewIndex();
+      if ( viewIdxRefInListY != refViewIdx && viewIdxRefInListY != m_pcSlice->getViewIndex() )
       {
         refViewAvailFlag = true;
-        predFlag[iRefListIdY] = 1;
-#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
-#if H_3D_FIX_BVSP
+        predFlag[refListIdY] = 1;
         TComMv  cMv = pDInfo->m_acNBDV;
-#else
-        TComMv  cMv = pDInfo->m_acDoNBDV;
-#endif
-        otherViewId = m_pcSlice->getRefPic( eRefPicList, i)->getViewId();
-        Int iScale = xGetDistScaleFactor( currViewId, otherViewId, currViewId, derivedViewId );
+        
+        Int viewIdInRefListY = m_pcSlice->getRefPic( eRefPicListY, i)->getViewId();
+        Int currViewId       = m_pcSlice->getViewId();
+        
+        //// Following might be added here when MV-HEVC 5 HLS is included (and derivations above removed): 
+        // Int viewIdInRefListX = m_pcSlice->getVPS()->getViewIdVal( refViewIdx  ); 
+        
+        Int iScale      = xGetDistScaleFactor( currViewId, viewIdInRefListY, currViewId, viewIdInRefListX );
+        
+        // Can iScale == 4096 happen?, I guess not since viewIdInRefListY is always unequal to viewIdInRefListX.
         if ( iScale != 4096 && m_pcSlice->getVPS()->getIvMvScalingFlag() ) 
         {
@@ -3445,14 +3377,7 @@
         }
         clipMv( cMv );
-        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].setMvField( cMv, i );
-#else
-#if H_3D_FIX_BVSP
-        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].setMvField( pDInfo->m_acNBDV, i );
-#else
-        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].setMvField( pDInfo->m_acDoNBDV, i );
-#endif
-#endif
+        pcMvFieldNeighbours[(iCount<<1)+refListIdY].setMvField( cMv, i );
 #if H_3D_NBDV
-        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].getMv().setIDVFlag (false);
+        pcMvFieldNeighbours[(iCount<<1)+refListIdY].getMv().setIDVFlag (false);
 #endif
       }
@@ -3461,10 +3386,12 @@
 
   // Set values to be returned
-  abCandIsInter[iCount] = true;
+  abCandIsInter        [iCount] = true;
   puhInterDirNeighbours[iCount] = (predFlag[0] | (predFlag[1] << 1));
-  vspFlag[iCount] = 1;
+  vspFlag              [iCount] = 1;
 
   if ( mrgCandIdx == iCount )
+  {
     return true;
+  }
 
   iCount++;
@@ -3475,14 +3402,15 @@
 #endif
 
-#if QC_INRIA_MTK_MRG_E0126
-inline Bool TComDataCU::xAddIvMRGCand( Int mrgCandIdx, Int& iCount, Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int*   iPdmDir, TComMv* acPdmMv, 
-                                       Int* aiPdmRefIdx, Int iPosDmv, Int* vspFlag )
-{
-  for(Int iLoop = 0; iLoop  < 2; iLoop ++ ) 
-  {
+#if H_3D_IV_MERGE
+inline Bool TComDataCU::xAddIvMRGCand( Int mrgCandIdx, Int& iCount, Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* ivCandDir, TComMv* ivCandMv, 
+                                       Int* ivCandRefIdx, Int iPosIvDC, Int* vspFlag )
+{
+  for(Int iLoop = 0; iLoop < 2; iLoop ++ ) 
+  {
+    // IvDcShift (Derived from spatial Iv neighboring blocks)
     if( iLoop == 1 )
     {
       Int iFirDispCand = -1;
-      if (xFirstDmvAvai(iCount, pcMvFieldNeighbours, iPdmDir, iPosDmv, vspFlag, iFirDispCand))
+      if (xGetPosFirstAvailDmvCand(iCount, pcMvFieldNeighbours, ivCandDir, iPosIvDC, vspFlag, iFirDispCand))
       {
         TComMv cMv;
@@ -3494,40 +3422,46 @@
         }
         clipMv( cMv );
-        abCandIsInter[ iCount ] = true;
+        abCandIsInter        [ iCount ] = true;
         puhInterDirNeighbours[ iCount ] = puhInterDirNeighbours[iFirDispCand];
-        pcMvFieldNeighbours[ iCount<<1  ].setMvField(cMv, pcMvFieldNeighbours[( iFirDispCand << 1)].getRefIdx() );
-        pcMvFieldNeighbours[ (iCount<<1)+1 ].setMvField(pcMvFieldNeighbours[(iFirDispCand << 1) + 1].getMv(), pcMvFieldNeighbours[( iFirDispCand << 1) + 1].getRefIdx() );
+        pcMvFieldNeighbours  [ iCount << 1      ].setMvField(cMv, pcMvFieldNeighbours[( iFirDispCand << 1)].getRefIdx() );
+        pcMvFieldNeighbours  [(iCount << 1) + 1 ].setMvField(pcMvFieldNeighbours[(iFirDispCand << 1) + 1].getMv(), pcMvFieldNeighbours[( iFirDispCand << 1) + 1].getRefIdx() );
+        
         if( mrgCandIdx == iCount ) 
         {
           return true;
         }
+
         iCount++;
         break;
       }
     }
-    if(iPdmDir[iLoop + 2])
-    {
-      abCandIsInter[ iCount ] = true;
-      puhInterDirNeighbours[ iCount ] = iPdmDir[iLoop + 2];
-      if( ( iPdmDir[iLoop + 2] & 1 ) == 1 )
-      {
-        pcMvFieldNeighbours[ iCount<<1 ].setMvField( acPdmMv[ (iLoop<<1) + 4 ], aiPdmRefIdx[ (iLoop<<1) + 4 ] ); 
-      }
-      if( ( iPdmDir[iLoop + 2] & 2 ) == 2 )
-      {
-        pcMvFieldNeighbours[ (iCount<<1)+1 ].setMvField( acPdmMv[ (iLoop<<1) + 5 ], aiPdmRefIdx[ (iLoop<<1) + 5 ] );
+
+    /// iLoop = 0 --> IvMCShift
+    /// iLoop = 1 --> IvDCShift  (Derived from IvDC)
+    if(ivCandDir[iLoop + 2])
+    {
+      abCandIsInter        [ iCount ] = true;
+      puhInterDirNeighbours[ iCount ] = ivCandDir[iLoop + 2];
+      if( ( ivCandDir[iLoop + 2] & 1 ) == 1 )
+      {
+        pcMvFieldNeighbours[ iCount<<1 ].setMvField( ivCandMv[ (iLoop<<1) + 4 ], ivCandRefIdx[ (iLoop<<1) + 4 ] ); 
+      }
+      if( ( ivCandDir[iLoop + 2] & 2 ) == 2 )
+      {
+        pcMvFieldNeighbours[ (iCount<<1)+1 ].setMvField( ivCandMv[ (iLoop<<1) + 5 ], ivCandRefIdx[ (iLoop<<1) + 5 ] );
       }
      
-      bool bRemove = false;
-      if(!iLoop && iPdmDir[0] > 0)
-      {
-        if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[0] && pcMvFieldNeighbours[0]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[1]==pcMvFieldNeighbours[(iCount<<1)+1])
+      // Prune IvMC vs. IvMcShift
+      Bool bRemove = false;      
+      if( !iLoop && ivCandDir[0] > 0)
+      {
+        if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[0] && pcMvFieldNeighbours[0 ]== pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[1]==pcMvFieldNeighbours[(iCount<<1)+1])
         {
-            bRemove                      = true;
+            bRemove                         = true;
             abCandIsInter        [ iCount ] = false;  
-            puhInterDirNeighbours[iCount]   = 0;
+            puhInterDirNeighbours[ iCount ] = 0;
             TComMv  cZeroMv;
-            pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
-            pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
+            pcMvFieldNeighbours  [ iCount<<1   ].setMvField( cZeroMv, NOT_VALID );
+            pcMvFieldNeighbours  [(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
         }
       }
@@ -3535,5 +3469,5 @@
       {
 #if H_3D_NBDV
-        if(iLoop)
+        if(iLoop) // For IvMcShift candidate
         {
           pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
@@ -3553,15 +3487,16 @@
 } 
 
-inline Bool TComDataCU::xFirstDmvAvai( Int& iCount, TComMvField* pcMvFieldNeighbours, Int* iPdmDir, Int iPosDmv, Int* vspFlag, Int& iFirDispCand )
-{
-  for ( Int i = (iPdmDir[0] ? 1: 0); i < iCount; i++ )
-  {
-    if ( ( i == iPosDmv ) || ( vspFlag[ i ] == 1 ) )
+inline Bool TComDataCU::xGetPosFirstAvailDmvCand( Int iCount, TComMvField* pcMvFieldNeighbours, Int* ivCandDir, Int posIvDC, Int* vspFlag, Int& posFirstAvailDmvCand )
+{
+  // ivCandDir[0] == true --> IvMC is available and excluded in loop over merge list. 
+  for ( Int currListPos = (ivCandDir[0] ? 1 : 0); currListPos < iCount; currListPos++ )
+  {
+    if ( ( currListPos == posIvDC ) || ( vspFlag[ currListPos ] == 1 ) )
     {
       continue;
     }
-    else if((pcMvFieldNeighbours[i<<1].getRefIdx()!=-1) && (getSlice()->getViewIndex() != getSlice()->getRefPic(RefPicList(0), pcMvFieldNeighbours[i<<1].getRefIdx())->getViewIndex()))
-    {
-      iFirDispCand = i;
+    else if((pcMvFieldNeighbours[currListPos<<1].getRefIdx() != -1 ) && (getSlice()->getViewIndex() != getSlice()->getRefPic(RefPicList(0), pcMvFieldNeighbours[currListPos<<1].getRefIdx())->getViewIndex()))
+    {
+      posFirstAvailDmvCand = currListPos;
       return true;
     }
@@ -3582,10 +3517,5 @@
 #if H_3D_VSP
       , Int* vspFlag
-#if MTK_VSP_FIX_ALIGN_WD_E0172
       , InheritedVSPDisInfo*  inheritedVSPDisInfo
-#endif
-#if MTK_VSP_FIX_E0172
-      , Int* vspDir
-#endif
 #endif
       , Int& numValidMergeCand, Int mrgCandIdx
@@ -3594,4 +3524,7 @@
   UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
 #if H_3D_IV_MERGE
+  ////////////////////////////
+  //////// INIT LISTS ////////
+  ////////////////////////////
   TComMv cZeroMv;
   Bool abCandIsInter[ MRG_MAX_NUM_CANDS_MEM ];
@@ -3611,4 +3544,9 @@
   }
   numValidMergeCand = getSlice()->getMaxNumMergeCand();
+#if H_3D
+  //////////////////////////////////
+  //////// DERIVE LOCATIONS ////////
+  //////////////////////////////////
+#endif
   // compute the location of the current PU
   Int xP, yP, nPSW, nPSH;
@@ -3622,33 +3560,9 @@
   deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
 #if H_3D_IV_MERGE
-  Bool ivMvPredFlag   = getSlice()->getVPS()->getIvMvPredFlag( getSlice()->getLayerIdInVps() );
-
-  //===== add merge with predicted depth maps =====
-#if QC_INRIA_MTK_MRG_E0126
-  TComMv acPdmMv         [8];
-  Int aiPdmRefIdx        [8] = {-1, -1, -1, -1, -1, -1, -1, -1};
-  Int iPosDmv                = -1;
-#else 
-  TComMv  acPdmMv       [4];
-  Int     aiPdmRefIdx   [4] = {-1, -1, -1, -1};
-#endif
-  Bool    bLeftAvai         = false;
-  Int     iPosLeftAbove[2]  = {-1, -1};
-
-
-  DisInfo cDisInfo;
-
-  cDisInfo.bDV = getDvInfo(uiAbsPartIdx).bDV;
-#if H_3D_NBDV_REF
-  cDisInfo.m_acDoNBDV = getDvInfo(uiAbsPartIdx).m_acDoNBDV;
-#endif //H_3D_NBDV_REF
-  cDisInfo.m_acNBDV = getDvInfo(uiAbsPartIdx).m_acNBDV;
-  cDisInfo.m_aVIdxCan = getDvInfo(uiAbsPartIdx).m_aVIdxCan;
-#if MTK_VSP_FIX_ALIGN_WD_E0172
-  for(Int i = 0; i < MRG_MAX_NUM_CANDS_MEM; i++)
-  {
-    inheritedVSPDisInfo[i].m_acDvInfo = cDisInfo;
-  }
-#endif
+  
+  /////////////////////////////////////////////
+  //////// TEXTURE MERGE CANDIDATE (T) ////////
+  /////////////////////////////////////////////
+
   if( m_pcSlice->getIsDepth())
   {
@@ -3659,5 +3573,4 @@
     if ( pcTextureCU && !pcTextureCU->isIntra( uiPartIdxCenter ) )
     {
-#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
       pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
       Int iValidDepRef = getPic()->isTextRefValid( REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1].getRefIdx() );
@@ -3699,96 +3612,58 @@
         iCount ++;
       }
-#else
-      abCandIsInter[iCount] = true;      
-      puhInterDirNeighbours[iCount] = pcTextureCU->getInterDir( uiPartIdxCenter );
-#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
-      pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
-      if (pcMvFieldNeighbours[iCount<<1].getRefIdx()>=0)
-#else
-      if( ( puhInterDirNeighbours[iCount] & 1 ) == 1 )
-#endif
-      {
-#if !MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
-        pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
-#endif
-        TComMv cMvPred = pcMvFieldNeighbours[iCount<<1].getMv();
-
-#if H_3D_IC
-        const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
-        cMvPred+=cAdd;
-        cMvPred>>=2;
-        clipMv(cMvPred);
-#endif
-        //pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,pcMvFieldNeighbours[iCount<<1].getRefIdx());
-#if H_3D //Notes from QC: for BVSP coded blocks, the reference index shall not be equal to -1 due to the adoption of JCT3V-D0191
-        pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,pcMvFieldNeighbours[iCount<<1].getRefIdx());
-#endif
-      }
-      
-      if ( getSlice()->isInterB() )
-      {
-#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
-        pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
-        if (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()>=0)
-#else
-        if( ( puhInterDirNeighbours[iCount] & 2 ) == 2 )
-#endif
-        {
-#if !MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
-          pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
-#endif
-          TComMv cMvPred = pcMvFieldNeighbours[(iCount<<1)+1].getMv();
-#if H_3D_IC
-          const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
-          cMvPred+=cAdd;
-          cMvPred>>=2;
-          clipMv(cMvPred);
-#endif
-          pcMvFieldNeighbours[(iCount<<1)+1].setMvField(cMvPred,pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx());
-        }
-      }
-#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
-      puhInterDirNeighbours[iCount] = (pcMvFieldNeighbours[iCount<<1].getRefIdx()>=0)?1:0;
-      puhInterDirNeighbours[iCount] += (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()>=0)?2:0;
-#endif
-#if H_3D_NBDV
-      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
-      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
-#endif
-      if ( mrgCandIdx == iCount )
-      {
-        return;
-      }
-      iCount ++;
-#endif//Bug fix
-    }
-  }
-
-#if QC_INRIA_MTK_MRG_E0126
-  Int iPdmDir[4] = {0, 0, 0, 0};
-#else
-  Int iPdmDir[2] = {0, 0};
-#endif
+    }
+  }
+
+  //////////////////////////////////
+  //////// GET DISPARITIES  ////////
+  //////////////////////////////////
+
+  DisInfo cDisInfo = getDvInfo(uiAbsPartIdx);
+
+  for(Int i = 0; i < MRG_MAX_NUM_CANDS_MEM; i++)
+  {
+    inheritedVSPDisInfo[i].m_acDvInfo = cDisInfo;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  //////// DERIVE IvMC, IvMCShift,IvDCShift, IvDC  Candidates /////
+  /////////////////////////////////////////////////////////////////
+
+  Int  posIvDC          = -1;
+  Bool bLeftAvai        = false;
+  Int  iPosLeftAbove[2] = {-1, -1};
+
+
+  // { IvMCL0, IvMCL1, IvDCL0, IvDCL1, IvMCL0Shift, IvMCL1Shift, IvDCL0Shift, IvDCL1Shift };  
+  // An enumerator would be appropriate here! 
+  TComMv ivCandMv    [8];
+  Int    ivCandRefIdx[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
+
+  // { IvMC, IvDC, IvMCShift, IvDCShift };  
+  Int    ivCandDir   [4] = {0, 0, 0, 0};
+
+  Bool ivMvPredFlag   = getSlice()->getVPS()->getIvMvPredFlag( getSlice()->getLayerIdInVps() );
   
   if ( ivMvPredFlag )
   {
-    getInterViewMergeCands(uiPUIdx, aiPdmRefIdx, acPdmMv, &cDisInfo, iPdmDir );
+    getInterViewMergeCands(uiPUIdx, ivCandRefIdx, ivCandMv, &cDisInfo, ivCandDir );
   }  
-    
-  Int iPdmInterDir;
-
-  if( iPdmDir[0] )
+  
+  ///////////////////////////////////////////////
+  //////// INTER VIEW MOTION COMP(IvMC) /////////
+  ///////////////////////////////////////////////
+
+  if( ivCandDir[0] )
   {
     abCandIsInter        [ iCount ] = true;
-    puhInterDirNeighbours[ iCount ] = iPdmDir[0];
-    iPdmInterDir                    = iPdmDir[0];
-
-    if( ( iPdmInterDir & 1 ) == 1 )
-    {
-      pcMvFieldNeighbours[ iCount<<1    ].setMvField( acPdmMv[ 0 ], aiPdmRefIdx[ 0 ] );
-    }
-    if( ( iPdmInterDir & 2 ) == 2 )
-    {
-      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( acPdmMv[ 1 ], aiPdmRefIdx[ 1 ] );
+    puhInterDirNeighbours[ iCount ] = ivCandDir[0];    
+
+    if( ( ivCandDir[0] & 1 ) == 1 )
+    {
+      pcMvFieldNeighbours[ iCount<<1    ].setMvField( ivCandMv[ 0 ], ivCandRefIdx[ 0 ] );
+    }
+    if( ( ivCandDir[0] & 2 ) == 2 )
+    {
+      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( ivCandMv[ 1 ], ivCandRefIdx[ 1 ] );
     }
 
@@ -3799,4 +3674,5 @@
     iCount ++;
   } 
+
   // early termination
   if (iCount == getSlice()->getMaxNumMergeCand()) 
@@ -3806,4 +3682,9 @@
 #endif
 
+#if H_3D
+  ////////////////////////////
+  //////// LEFT (A1) /////////
+  ////////////////////////////
+#endif
   //left
   UInt uiLeftPartIdx = 0;
@@ -3852,17 +3733,9 @@
 #if H_3D_VSP
       if (pcCULeft->getVSPFlag(uiLeftPartIdx) == 1)
-#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
-      {
-#endif
+      {
         vspFlag[iCount] = 1;
-#if MTK_VSP_FIX_ALIGN_WD_E0172
         xInheritVSPDisInfo(pcCULeft,uiLeftPartIdx,iCount,inheritedVSPDisInfo);
       }
 #endif
-#if MTK_VSP_FIX_E0172
-        vspDir[iCount] = pcCULeft->getVSPDir( uiLeftPartIdx );
-      }
-#endif
-#endif
       if ( mrgCandIdx == iCount )
       {
@@ -3871,5 +3744,5 @@
       iCount ++;
     }
-#else
+#else // H_3D_IV_MERGE 
     if ( mrgCandIdx == iCount )
     {
@@ -3877,5 +3750,5 @@
     }
     iCount ++;
-#endif
+#endif // H_3D_IV_MERGE 
   }
   
@@ -3885,4 +3758,9 @@
     return;
   }
+#if H_3D
+  ////////////////////////////
+  //////// ABOVE (B1) ////////
+  ////////////////////////////
+#endif
   // above
   UInt uiAbovePartIdx = 0;
@@ -3917,9 +3795,10 @@
         puhInterDirNeighbours[iCount]   = 0;
 
-        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
+        pcMvFieldNeighbours[iCount<<1]    .setMvField( cZeroMv, NOT_VALID );
         pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
         break;
       }
     }
+
     if(!bRemoveSpa)
     {
@@ -3931,17 +3810,10 @@
 #if H_3D_VSP
       if (pcCUAbove->getVSPFlag(uiAbovePartIdx) == 1)
-#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
-      {
-#endif
+      {
+
         vspFlag[iCount] = 1;
-#if MTK_VSP_FIX_ALIGN_WD_E0172
         xInheritVSPDisInfo(pcCUAbove,uiAbovePartIdx,iCount,inheritedVSPDisInfo);
       }
 #endif
-#if MTK_VSP_FIX_E0172
-        vspDir[iCount] = pcCUAbove->getVSPDir( uiAbovePartIdx );
-      }
-#endif
-#endif
       if ( mrgCandIdx == iCount )
       {
@@ -3950,5 +3822,5 @@
       iCount ++;
     }
-#else
+#else // H_3D_IV_MERGE 
     if ( mrgCandIdx == iCount )
     {
@@ -3956,5 +3828,5 @@
     }
     iCount ++;
-#endif
+#endif // H_3D_IV_MERGE 
   }
   // early termination
@@ -3963,4 +3835,10 @@
     return;
   }
+
+#if H_3D
+  //////////////////////////////////
+  //////// ABOVE RIGHT (B0) ////////
+  //////////////////////////////////
+#endif
 
   // above right
@@ -3988,16 +3866,8 @@
 #if H_3D_VSP
     if (pcCUAboveRight->getVSPFlag(uiAboveRightPartIdx) == 1)
-#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
-    {
-#endif
+    {
       vspFlag[iCount] = 1;
-#if MTK_VSP_FIX_ALIGN_WD_E0172
       xInheritVSPDisInfo(pcCUAboveRight,uiAboveRightPartIdx,iCount,inheritedVSPDisInfo);
     }
-#endif
-#if MTK_VSP_FIX_E0172
-      vspDir[iCount] = pcCUAboveRight->getVSPDir( uiAboveRightPartIdx);
-    }
-#endif
 #endif
     if ( mrgCandIdx == iCount )
@@ -4014,16 +3884,20 @@
 
 #if H_3D_IV_MERGE 
-  if( iPdmDir[1] )
+  /////////////////////////////////////////////
+  //////// INTER VIEW DISP COMP (IvDC) ////////
+  /////////////////////////////////////////////
+
+  if( ivCandDir[1] )
   {
     assert(iCount < getSlice()->getMaxNumMergeCand());
     abCandIsInter        [ iCount ] = true;
-    puhInterDirNeighbours[ iCount ] = iPdmDir[1];
-    if( ( iPdmDir[1] & 1 ) == 1 )
-    {
-      pcMvFieldNeighbours[ iCount<<1    ].setMvField( acPdmMv[ 2 ], aiPdmRefIdx[ 2 ] );
-    }
-    if( ( iPdmDir[1] & 2 ) == 2 )
-    {
-      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( acPdmMv[ 3 ], aiPdmRefIdx[ 3 ] );
+    puhInterDirNeighbours[ iCount ] = ivCandDir[1];
+    if( ( ivCandDir[1] & 1 ) == 1 )
+    {
+      pcMvFieldNeighbours[ iCount<<1    ].setMvField( ivCandMv[ 2 ], ivCandRefIdx[ 2 ] );
+    }
+    if( ( ivCandDir[1] & 2 ) == 2 )
+    {
+      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( ivCandMv[ 3 ], ivCandRefIdx[ 3 ] );
     }
 
@@ -4032,6 +3906,8 @@
     {
       Int iCnloop = iPosLeftAbove[i];
-      if(iCnloop == -1) 
+      if ( iCnloop == -1 ) 
+      {
         continue;
+      }
       if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
       {
@@ -4051,7 +3927,5 @@
       pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
 #endif
-#if QC_INRIA_MTK_MRG_E0126
-      iPosDmv  = iCount;
-#endif
+      posIvDC  = iCount;
       if ( mrgCandIdx == iCount )
         return;
@@ -4065,16 +3939,26 @@
     }
   } 
-#endif
+#endif // H_3D_IV_MERGE 
 
 #if H_3D_VSP
-#if MTK_VSP_FIX_E0172
-  if ( xAddVspCand( H_3D_VSP_POSITION, mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, vspDir ) )
-#else
-  if ( xAddVspCand( H_3D_VSP_POSITION, mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag ) )
-#endif
+  /////////////////////////////////////////////////
+  //////// VIEW SYNTHESIS PREDICTION (VSP) ////////
+  /////////////////////////////////////////////////
+
+  if ( xAddVspCand( mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag ) )
+  {
     return;
+  }
+
   // early termination
   if (iCount == getSlice()->getMaxNumMergeCand())
+  {
     return;
+  }
+#endif
+#if H_3D
+  ///////////////////////////////////
+  //////// LEFT BOTTOM (A0) ////////
+  ///////////////////////////////////
 #endif
 
@@ -4103,16 +3987,8 @@
 #if H_3D_VSP
     if (pcCULeftBottom->getVSPFlag(uiLeftBottomPartIdx) == 1)
-#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
-    {
-#endif
+    {
       vspFlag[iCount] = 1;
-#if MTK_VSP_FIX_ALIGN_WD_E0172
       xInheritVSPDisInfo(pcCULeftBottom,uiLeftBottomPartIdx,iCount,inheritedVSPDisInfo);
     }
-#endif
-#if MTK_VSP_FIX_E0172
-      vspDir[iCount] = pcCULeftBottom->getVSPDir( uiLeftBottomPartIdx);
-    }
-#endif
 #endif
     if ( mrgCandIdx == iCount )
@@ -4127,4 +4003,10 @@
     return;
   }
+#if H_3D
+  ///////////////////////////////////
+  //////// LEFT ABOVE (B2) ////////
+  ///////////////////////////////////
+#endif
+
   // above left 
   if( iCount < 4 )
@@ -4154,16 +4036,8 @@
 #if H_3D_VSP
       if (pcCUAboveLeft->getVSPFlag(uiAboveLeftPartIdx) == 1)
-#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
-      {
-#endif
+      {
         vspFlag[iCount] = 1;
-#if MTK_VSP_FIX_ALIGN_WD_E0172
         xInheritVSPDisInfo(pcCUAboveLeft,uiAboveLeftPartIdx,iCount,inheritedVSPDisInfo);
       }
-#endif
-#if MTK_VSP_FIX_E0172
-        vspDir[iCount] = pcCUAboveLeft->getVSPDir( uiAboveLeftPartIdx);
-      }
-#endif
 #endif
       if ( mrgCandIdx == iCount )
@@ -4179,8 +4053,12 @@
     return;
   }
-#if QC_INRIA_MTK_MRG_E0126
+#if H_3D_IV_MERGE
+  ////////////////////////////////////////////////////
+  //////// SHIFTED IV (IvMCShift + IvDCShift) ////////
+  ////////////////////////////////////////////////////
+
   if(  ivMvPredFlag  ) 
   {
-    if(xAddIvMRGCand( mrgCandIdx,  iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, iPdmDir, acPdmMv, aiPdmRefIdx, iPosDmv, vspFlag))
+    if(xAddIvMRGCand( mrgCandIdx,  iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, ivCandDir, ivCandMv, ivCandRefIdx, posIvDC, vspFlag))
     {
       return;
@@ -4192,4 +4070,9 @@
     }
   }
+#endif
+#if H_3D
+  /////////////////////////////////
+  //////// Collocate (COL) ////////
+  /////////////////////////////////
 #endif
   if ( getSlice()->getEnableTMVPFlag())
@@ -4311,7 +4194,11 @@
       Bool bValid = true;
       if ( vspFlag[i] == 1 || vspFlag[j] == 1 )
+      {
         bValid = false;
+      }
       if( !m_pcSlice->getVPS()->getViewSynthesisPredFlag( m_pcSlice->getLayerIdInVps() ) )
+      {
         assert(bValid == true);
+      }
 #endif
 #if H_3D_VSP
@@ -4374,5 +4261,5 @@
   numValidMergeCand = uiArrayAddr;
 }
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
 inline Void TComDataCU::xInheritVSPDisInfo(TComDataCU* pcCURef, UInt uiAbsPartIdx, Int iCount, InheritedVSPDisInfo*  inheritedVSPDisInfo)
 {
@@ -4943,4 +4830,7 @@
 
   // use coldir.
+#if H_MV5
+  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
+#else
 #if H_MV
   TComPic *pColPic;  
@@ -4955,4 +4845,5 @@
 #else
   TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
+#endif
 #endif
   TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
@@ -5770,7 +5661,4 @@
           pDInfo->m_acNBDV = cDispVec;
           pDInfo->m_aVIdxCan = cIDVInfo.m_aVIdxCan[iList][ curPos ];
-#if !MTK_DVMCP_FIX_E0172
-          assert(pDInfo->m_aVIdxCan == 0); //Notes from QC: only works for CTC
-#endif
 #if H_3D_NBDV_REF
           TComPic* picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
@@ -5942,9 +5830,5 @@
           paIDVInfo->m_acMvCand[iList][ uiMvpDvPos ] = TComMv( cMvPred.getIDVHor(), cMvPred.getIDVVer() );
           //Notes from QC: DvMCP is implemented in a way that doesnE½t carry the reference view identifier as NBDV. It only works for CTC and needs to be fixed to be aligned with other part of the NBDV design.
-#if MTK_DVMCP_FIX_E0172
           paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = cMvPred.getIDVVId();
-#else  
-          paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = 0; 
-#endif
           paIDVInfo->m_bAvailab[iList][ uiMvpDvPos ] = true;
           paIDVInfo->m_bFound                        = true; 
@@ -6011,5 +5895,5 @@
   }
 }
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
 Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth )
 {
@@ -6150,6 +6034,7 @@
 TComDataCU::getInterViewMergeCands(UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* availableMcDc )
 {
-  TComSlice*    pcSlice         = getSlice ();  
-  Int iViewIndex = pDInfo->m_aVIdxCan;
+  TComSlice*    pcSlice = getSlice ();  
+  Int iViewIndex        = pDInfo->m_aVIdxCan;
+  
   //--- get base CU/PU and check prediction mode ---
   TComPic*    pcBasePic   = pcSlice->getIvPic( false, iViewIndex );
@@ -6174,38 +6059,27 @@
   TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
   
-#if !QC_INRIA_MTK_MRG_E0126
-  Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
-  Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
-
-  Int         iBaseCUAddr;
-  Int         iBaseAbsPartIdx;
-  pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
-
-  TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
-#endif
-#if QC_INRIA_MTK_MRG_E0126
   Bool abPdmAvailable[8] =  {false, false, false, false, false, false, false, false};
-#else
-  Bool abPdmAvailable[4] = {false, false, false, false};
-#endif
 #if H_3D_NBDV
-#if QC_INRIA_MTK_MRG_E0126
   for( Int i = 0; i < 8; i++)
-#else
-  for( Int i = 0; i < 4; i++)
-#endif
   {
     pacPdmMv[i].setIDVFlag   (false);
   }
 #endif
-#if QC_INRIA_MTK_MRG_E0126
-  for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
-  {
+
+  ////////////////////////////////
+  /////// IvMC + IvMCShift ///////
+  ////////////////////////////////
+
+  for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)  
+  {
+    // iLoopCan == 0 --> IvMC
+    // iLoopCan == 1 --> IvMCShift 
+
     Int         iBaseCUAddr;
     Int         iBaseAbsPartIdx;
 
-    Int offsetW = (iLoopCan == 0) ? 0 : ( ((iWidth/2)*4)  + 4 );
+    Int offsetW = (iLoopCan == 0) ? 0 : ( ((iWidth /2)*4) + 4 );
     Int offsetH = (iLoopCan == 0) ? 0 : ( ((iHeight/2)*4) + 4 );
-    
+
     Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + offsetW + 2 ) >> 2 ) );
     Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + offsetH + 2 ) >> 2 ) ); 
@@ -6213,28 +6087,28 @@
 
     TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
-#endif
-  if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
-  {
-    for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
-    {
-      RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
-
-      Bool stopLoop = false;
-      for(Int iLoop = 0; iLoop < 2 && !stopLoop; ++iLoop)
-      {
-        RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
-        TComMvField cBaseMvField;
-        pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
-        Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
-        if (iBaseRefIdx >= 0)
+    if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
+    {
+      // Loop reference picture list of current slice (X in spec). 
+      for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )       
+      {
+        RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
+
+        Bool stopLoop = false;
+        // Loop reference picture list of candidate slice (Y in spec)
+        for(Int iLoop = 0; iLoop < 2 && !stopLoop; ++iLoop)
         {
-          Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
-          if (iBaseRefPOC != pcSlice->getPOC())    
+          RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
+          TComMvField cBaseMvField;
+          pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
+          Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
+          if (iBaseRefIdx >= 0)
           {
-            for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
+            Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
+            if (iBaseRefPOC != pcSlice->getPOC())    
             {
-              if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
+              for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
               {
-#if QC_INRIA_MTK_MRG_E0126
+                if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
+                {
                   abPdmAvailable[ (uiCurrRefListId + (iLoopCan<<2)) ] = true;
                   TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
@@ -6243,28 +6117,12 @@
                   cMv.setIDVHor    (cDv.getHor());                  
                   cMv.setIDVVer    (cDv.getVer());  
-#if MTK_DVMCP_FIX_E0172
                   cMv.setIDVVId    (iViewIndex); 
-#endif
 #endif
                   clipMv( cMv );
                   paiPdmRefIdx  [ (uiCurrRefListId + (iLoopCan<<2)) ] = iPdmRefIdx;
                   pacPdmMv      [ (uiCurrRefListId + (iLoopCan<<2)) ] = cMv;
-#else
-                abPdmAvailable[ uiCurrRefListId ] = true;
-                TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
-#if H_3D_NBDV 
-                cMv.setIDVFlag   (true);
-                cMv.setIDVHor    (cDv.getHor());                  
-                cMv.setIDVVer    (cDv.getVer());  
-#if MTK_DVMCP_FIX_E0172
-                cMv.setIDVVId    (iViewIndex); 
-#endif
-#endif
-                clipMv( cMv );
-                paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
-                pacPdmMv      [ uiCurrRefListId ] = cMv;
-#endif
-                stopLoop = true;
-                break;
+                  stopLoop = true;
+                  break;
+                }
               }
             }
@@ -6274,15 +6132,14 @@
     }
   }
-#if QC_INRIA_MTK_MRG_E0126
-  }
-#endif
-#if QC_INRIA_MTK_MRG_E0126
   for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
   {
     availableMcDc[(iLoopCan << 1)] = ( abPdmAvailable[(iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[1 + (iLoopCan<<2)] ? 2 : 0);
   }
-#else
-  availableMcDc[0] = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
-#endif
+  
+  
+  ////////////////////////////////
+  /////// IvDC + IvDCShift ///////
+  ////////////////////////////////
+  
   for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
   {
@@ -6291,11 +6148,6 @@
     for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
     {
-#if MTK_DIVMC_FIX_E0172
       if(( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC()) && (pcSlice->getRefPic( eRefPicListDMV, iPdmRefIdx )->getViewIndex() == pDInfo->m_aVIdxCan))
-#else
-      if( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC())
-#endif
-      {
-#if QC_INRIA_MTK_MRG_E0126
+      {
         for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
         {
@@ -6312,27 +6164,11 @@
         }
         break;
-#else
-        abPdmAvailable[ iRefListId+2 ] = true;
-        paiPdmRefIdx  [ iRefListId+2 ] = iPdmRefIdx;
-
-#if H_3D_NBDV_REF
-        TComMv cMv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
-#endif // H_3D_NBDV_REF
-        cMv.setVer(0);
-        clipMv( cMv );
-        pacPdmMv      [ iRefListId + 2] = cMv;
-        break;
-#endif
-      }
-    }
-  }
-#if QC_INRIA_MTK_MRG_E0126
+      }
+    }
+  }
   for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
   {
     availableMcDc[1 + (iLoopCan << 1)] = ( abPdmAvailable[2 + (iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[3 + (iLoopCan<<2)] ? 2 : 0 );
   }
-#else
-  availableMcDc[1] = ( abPdmAvailable[2] ? 1 : 0 ) + ( abPdmAvailable[3] ? 2 : 0 );
-#endif
   return false;
 }
@@ -6406,5 +6242,5 @@
   for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmmWedgeTabIdx[dmmType][uiAbsPartIdx+ui] = tabIdx; }
 }
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
 Void  TComDataCU::setDmm2DeltaEndSubParts( Int iDelta, UInt uiAbsPartIdx, UInt uiDepth )
 {
Index: trunk/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 622)
@@ -197,7 +197,4 @@
   Char*         m_piVSPFlag;          ///< array of VSP flags to indicate whehter a block uses VSP or not
                                       ///< 0: non-VSP; 1: VSP
-#if MTK_VSP_FIX_E0172
-  Char*         m_piVSPDir;           ///< 0: LIST0; 1: LIST1
-#endif
 #endif
 #if H_3D_ARP
@@ -211,5 +208,5 @@
 #if H_3D_DIM_DMM
   UInt*         m_dmmWedgeTabIdx[DMM_NUM_TYPE]; 
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   Int*          m_dmm2DeltaEnd;
 #endif
@@ -256,16 +253,11 @@
   Bool          xAddMVPCandOrder      ( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir );
 #if H_3D_VSP
-#if MTK_VSP_FIX_E0172
-  Bool          xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
-                             Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag, Int* vspDir );
-#else
-  Bool          xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
+  Bool          xAddVspCand( Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
                              Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag );
 #endif
-#endif
-#if QC_INRIA_MTK_MRG_E0126
-  Bool          xAddIvMRGCand( Int mrgCandIdx, Int& iCount, Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int*   iPdmDir, TComMv* acPdmMv, 
-                               Int* aiPdmRefIdx, Int iPosDmv, Int* vspFlag ); 
-  Bool          xFirstDmvAvai( Int& iCount, TComMvField* pcMvFieldNeighbours, Int*  iPdmDir, Int iPosDmv, Int* vspFlag, Int& iFirDispCand );
+#if H_3D_IV_MERGE
+  Bool          xAddIvMRGCand( Int mrgCandIdx, Int& iCount, Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int*   ivCandDir, TComMv* ivCandMv, 
+                               Int* ivCandRefIdx, Int posIvDC, Int* vspFlag ); 
+  Bool          xGetPosFirstAvailDmvCand( Int iCount, TComMvField* pcMvFieldNeighbours, Int*  ivCandDir, Int posIvDC, Int* vspFlag, Int& iFirDispCand );
 #endif
 
@@ -442,5 +434,5 @@
   template <typename T>
   Void          setSubPart            ( T bParameter, T* pbBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
   template<typename T>
   Void          setSubPartT           ( T uiParameter, T* puhBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx );
@@ -471,7 +463,5 @@
 #if H_3D_NBDV
   Void          setDvInfoSubParts     ( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiDepth );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
   Void          setDvInfoSubParts     ( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth);
-#endif
   DisInfo*      getDvInfo             ()                        { return m_pDvInfo;                 }
   DisInfo       getDvInfo             (UInt uiIdx)              { return m_pDvInfo[uiIdx];          }
@@ -555,5 +545,5 @@
   Void  setDmmWedgeTabIdxSubParts     ( UInt tabIdx, UInt dmmType, UInt uiAbsPartIdx, UInt uiDepth );
 
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   Int*  getDmm2DeltaEnd               ()                      { return m_dmm2DeltaEnd;        }
   Int   getDmm2DeltaEnd               ( UInt uiIdx )          { return m_dmm2DeltaEnd[uiIdx]; }
@@ -682,26 +672,15 @@
 #if H_3D_VSP
                                             , Int* vspFlag
-#if MTK_VSP_FIX_ALIGN_WD_E0172
                                             , InheritedVSPDisInfo*  inheritedVSPDisInfo
 #endif
-#if MTK_VSP_FIX_E0172
-                                            , Int* vspDir
-#endif
-#endif
                                             , Int& numValidMergeCand, Int mrgCandIdx = -1 );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
-  inline Void xInheritVSPDisInfo(TComDataCU* pcCURef, UInt uiAbsPartIdx, Int iCount,  InheritedVSPDisInfo*  inheritedVSPDisInfo);
-#endif
+
 #if H_3D_VSP
+  inline Void   xInheritVSPDisInfo(TComDataCU* pcCURef, UInt uiAbsPartIdx, Int iCount,  InheritedVSPDisInfo*  inheritedVSPDisInfo);
+
   Char*         getVSPFlag        ()                        { return m_piVSPFlag;          }
   Char          getVSPFlag        ( UInt uiIdx )            { return m_piVSPFlag[uiIdx];   }
   Void          setVSPFlag        ( UInt uiIdx, Int n )     { m_piVSPFlag[uiIdx] = n;      }
   Void          setVSPFlagSubParts( Char iVSPFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
-#if MTK_VSP_FIX_E0172
-  Char*         getVSPDir          ()                        { return m_piVSPDir;                           }
-  Char          getVSPDir          ( UInt uiIdx )            { return m_piVSPDir[uiIdx];                  }
-  Void          setVSPDir          ( UInt uiIdx, Int n )     { m_piVSPDir[uiIdx] = n;  }
-  Void          setVSPDirSubParts  ( Char iVSPDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
-#endif
 #endif
   Void          deriveLeftRightTopIdxGeneral  ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT );
Index: trunk/source/Lib/TLibCommon/TComMotionInfo.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComMotionInfo.h	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComMotionInfo.h	(revision 622)
@@ -77,5 +77,5 @@
 } IDVInfo;
 #endif
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
 typedef struct _InheritedVSPDisCand 
 {
Index: trunk/source/Lib/TLibCommon/TComMv.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComMv.h	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComMv.h	(revision 622)
@@ -58,7 +58,5 @@
   Short m_iIDVHor;    
   Short m_iIDVVer;   
-#if MTK_DVMCP_FIX_E0172
   Short m_iIDVVId;  //view index of the IDV
-#endif
 #endif
 public:
@@ -75,7 +73,5 @@
   , m_iIDVHor(0)
   , m_iIDVVer(0)
-#if MTK_DVMCP_FIX_E0172
   , m_iIDVVId(0) 
-#endif
 #endif
   {
@@ -89,7 +85,5 @@
   , m_iIDVHor(0)
   , m_iIDVVer(0)
-#if MTK_DVMCP_FIX_E0172
-  , m_iIDVVId(0) 
-#endif
+  , m_iIDVVId(0)
 #endif
   {
@@ -106,7 +100,5 @@
  #if H_3D_NBDV
    m_bIDV = false; m_iIDVHor = m_iIDVVer = 0;
-#if MTK_DVMCP_FIX_E0172
    m_iIDVVId = 0; 
-#endif
 #endif
   }
@@ -115,7 +107,5 @@
   Void   setIDVVer  (Short i)                    {m_iIDVVer = i;}
   Void   setIDVFlag (Bool b )                    {m_bIDV    = b;}
-#if MTK_DVMCP_FIX_E0172
   Void   setIDVVId  (Short i)                    {m_iIDVVId = i;}
-#endif
 #endif
   // ------------------------------------------------------------------------------------------------------------------
@@ -131,7 +121,6 @@
   Short getIDVVer () const { return m_iIDVVer;       }
   Bool  getIDVFlag() const { return m_bIDV;          }
-#if MTK_DVMCP_FIX_E0172
   Short getIDVVId () const { return m_iIDVVId;       }
-#endif
+
 #endif
   // ------------------------------------------------------------------------------------------------------------------
Index: trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 622)
@@ -456,5 +456,5 @@
         dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]);
       } break;
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
     case( DMM2_IDX ):
       {
@@ -588,5 +588,5 @@
     pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
 #if H_3D_VSP
-    if ( 0 == pcCU->getVSPFlag(uiPartAddr) )
+    if ( pcCU->getVSPFlag(uiPartAddr) == 0)
     {
 #endif
@@ -622,7 +622,11 @@
     {
       if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
+      {
         xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
+      }
       else
+      {
         xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
+      }
     }
 #endif
@@ -635,5 +639,5 @@
 
 #if H_3D_VSP
-    if ( 0 == pcCU->getVSPFlag(uiPartAddr) )
+    if ( pcCU->getVSPFlag(uiPartAddr) == 0 )
     {
 #endif
@@ -669,7 +673,11 @@
     {
       if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
+      {
         xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
+      }
       else
+      {
         xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
+      }
     }
 #endif
@@ -722,12 +730,5 @@
 {
   // Get depth reference
-#if MTK_VSP_FIX_E0172 
-  Int vspDir = pcCU->getVSPDir( uiPartAddr );
-  RefPicList privateRefPicList = (vspDir == 0) ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
-  Int privateRefIdx = pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
-  Int depthRefViewIdx = pcCU->getSlice()->getRefPic(privateRefPicList, privateRefIdx)->getViewIndex();
-#else
-  Int depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
-#endif
+  Int       depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
   TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
   assert(pRefPicBaseDepth != NULL);
@@ -748,13 +749,5 @@
 
   // Do compensation
-#if MTK_VSP_FIX_ALIGN_WD_E0172 
   TComMv cDv  = pcCU->getDvInfo(uiPartAddr).m_acNBDV;
-#else
-#if MTK_VSP_FIX_E0172
-  TComMv cDv  = pcCU->getCUMvField( privateRefPicList )->getMv( uiPartAddr );
-#else
-  TComMv cDv  = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); // cDv is the disparity vector derived from the neighbors
-#endif
-#endif // end of MTK_VSP_FIX_ALIGN_WD_E0172 
   pcCU->clipMv(cDv);
 
@@ -935,5 +928,7 @@
 
     if ( iRefIdx[iRefList] < 0 )
+    {
       continue;
+    }
     assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
 
@@ -2773,4 +2768,5 @@
 
 #if H_3D_DIM_DMM
+#if !SEC_DMM2_E0146_HHIFIX
 UInt TComPrediction::xPredWedgeFromIntra( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd )
 {
@@ -2784,9 +2780,5 @@
   {
     UInt dimType =  getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
-#if SEC_DMM2_E0146
-    if( DMM1_IDX == dimType || DMM3_IDX == dimType )
-#else
     if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
-#endif
     {
       // get offset between current and reference block
@@ -2813,9 +2805,5 @@
   {
     UInt dimType = getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
-#if SEC_DMM2_E0146
-    if( DMM1_IDX == dimType || DMM3_IDX == dimType )
-#else
     if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
-#endif
     {
       // get offset between current and reference block
@@ -2849,4 +2837,5 @@
   return 0;
 }
+#endif
 
 UInt TComPrediction::xPredWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx )
@@ -2858,6 +2847,11 @@
   Int           uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
 
+#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
+  assert( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 );
+  return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx);
+#else
   if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 ) { return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx); }
   else                                                     { return g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])].at(intraTabIdx).getPatternIdx(); }
+#endif
 }
 
@@ -2914,4 +2908,5 @@
 }
 
+#if !SEC_DMM2_E0146_HHIFIX
 Void TComPrediction::xGetBlockOffset( TComDataCU* pcCU, UInt uiAbsPartIdx, TComDataCU* pcRefCU, UInt uiRefAbsPartIdx, UInt& ruiOffsetX, UInt& ruiOffsetY )
 {
@@ -3302,4 +3297,5 @@
 }
 #endif
+#endif
 #if H_3D_DIM_RBC
 Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Pel& rDeltaDC )
Index: trunk/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 622)
@@ -154,5 +154,7 @@
   Void xAssignBiSegDCs          ( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel   valDC1, Pel   valDC2 );
 #if H_3D_DIM_DMM
+#if !SEC_DMM2_E0146_HHIFIX
   UInt xPredWedgeFromIntra      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd = 0 );
+#endif
   UInt xPredWedgeFromTex        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx );
   Void xPredContourFromTex      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge );
@@ -160,8 +162,10 @@
   Void xCopyTextureLumaBlock    ( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight );
 
+#if !SEC_DMM2_E0146_HHIFIX
   Void xGetBlockOffset          ( TComDataCU* pcCU, UInt uiAbsPartIdx, TComDataCU* pcRefCU, UInt uiRefAbsPartIdx, UInt& ruiOffsetX, UInt& ruiOffsetY );
   Bool xGetWedgeIntraDirPredData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int& riSlopeX, Int& riSlopeY, UInt& ruiStartPosX, UInt& ruiStartPosY );
   Void xGetWedgeIntraDirStartEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int iDeltaX, Int iDeltaY, UInt uiPMSPosX, UInt uiPMSPosY, UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, Int iDeltaEnd = 0 );
   UInt xGetWedgePatternIdx      ( UInt uiBlockSize, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe );
+#endif
 #endif
 #if H_3D_DIM_RBC
Index: trunk/source/Lib/TLibCommon/TComRdCost.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 622)
@@ -484,5 +484,5 @@
 }
 
-#if SCU_HS_FAST_DEPTH_INTRA_E0238
+#if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
 
 UInt TComRdCost::calcVAR (Pel* pi0, Int stride, Int width, Int height, Int cuDepth)
Index: trunk/source/Lib/TLibCommon/TComRdCost.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRdCost.h	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComRdCost.h	(revision 622)
@@ -235,5 +235,5 @@
   UInt    calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
   
-#if SCU_HS_FAST_DEPTH_INTRA_E0238
+#if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
   UInt    calcVAR(Pel* pi0, Int stride, Int width, Int height, Int cuDepth);
 #endif  
Index: trunk/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 622)
@@ -347,5 +347,5 @@
 { //2x2   4x4   8x8 16x16 32x32 64x64
      0,    7,   10,   11,   11,   13 };
-#if LGE_PKU_DMM3_OVERLAP_E0159
+#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
 const UChar g_dmm3IntraTabIdxBits[6] =
 { //2x2   4x4   8x8 16x16 32x32 64x64
@@ -380,5 +380,8 @@
 Bool g_traceTU = true; 
 Bool g_disableHLSTrace = false; 
-UInt64 g_stopAtCounter   = 10803; 
+UInt64 g_stopAtCounter       = 48; 
+Bool g_traceCopyBack         = false; 
+Bool g_decTraceDispDer       = false; 
+Bool g_decTraceMvFromMerge   = false; 
 #endif
 #endif
@@ -611,5 +614,9 @@
 std::vector< std::vector< std::vector<UInt> > > g_aauiWdgLstM3;
 
+#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
+Void initWedgeLists( Bool initNodeList )
+#else
 Void initWedgeLists( Bool initRefinements )
+#endif
 {
   if( !g_dmmWedgeLists.empty() ) return;
@@ -624,4 +631,8 @@
     g_dmmWedgeRefLists.push_back( acWedgeRefList );
 
+#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
+    if( initNodeList )
+    {
+#endif
     // create WedgeNodeList
     std::vector<TComWedgeNode> acWedgeNodeList;
@@ -633,6 +644,8 @@
         cWedgeNode.setPatternIdx( uiPos );
 
+#if !LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
         if( initRefinements )
         {
+#endif
           UInt uiRefPos = 0;
           for( Int iOffS = -1; iOffS <= 1; iOffS++ )
@@ -681,9 +694,14 @@
             }
           }
+#if !LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
         }
+#endif
         acWedgeNodeList.push_back( cWedgeNode );
       }
     }
     g_dmmWedgeNodeLists.push_back( acWedgeNodeList );
+#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
+  }
+#endif
   }
   return;
Index: trunk/source/Lib/TLibCommon/TComRom.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.h	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComRom.h	(revision 622)
@@ -174,5 +174,9 @@
 extern       std::vector< std::vector< std::vector<UInt> > > g_aauiWdgLstM3;
 
+#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
+Void initWedgeLists( Bool initNodeList = false );
+#else
 Void initWedgeLists( Bool initRefinements = false );
+#endif
 Void createWedgeList( UInt uiWidth, UInt uiHeight, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList, WedgeResolution eWedgeRes );
 Void addWedgeletToList( TComWedgelet cWedgelet, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList );
@@ -194,5 +198,5 @@
 
 #ifndef ENC_DEC_TRACE
-# define ENC_DEC_TRACE 0
+#define ENC_DEC_TRACE   0
 #endif
 
@@ -220,6 +224,9 @@
  extern Bool   g_tracePU; 
  extern Bool   g_traceTU; 
- extern Bool   g_disableHLSTrace; 
- extern UInt64 g_stopAtCounter; 
+ extern Bool   g_disableHLSTrace;       // USE g_HLSTraceEnable to toggle HLS trace. Not this one!
+ 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_decTraceMvFromMerge;   // Trace motion vectors obtained from merge (decoder only) 
 
 #define DTRACE_CU(x,y)             writeToTraceFile( x,y, g_traceCU );
Index: trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 622)
@@ -101,17 +101,32 @@
 , m_enableTMVPFlag                ( true )
 #if H_MV
+#if H_MV5
+, m_refPicSetInterLayer0           ( NULL )
+, m_refPicSetInterLayer1           ( NULL )
+#else
 , m_refPicSetInterLayer           ( NULL )
+#endif
 , m_layerId                       (0)
 , m_viewId                        (0)
+#if H_MV5
+, m_viewIndex                     (0)
+#endif
 #if H_3D
+#if !H_MV5
 , m_viewIndex                     (0)
+#endif
 , m_isDepth                       (false)
+#endif
+#if H_MV5
+, m_pocResetFlag                  (false)
 #endif
 , m_discardableFlag               (false)
 , m_interLayerPredEnabledFlag     (false)
 , m_numInterLayerRefPicsMinus1    (0)
+#if !H_MV5
 , m_interLayerSamplePredOnlyFlag  (false)
 , m_altCollocatedIndicationFlag   (0)
 , m_collocatedRefLayerIdx         (0)
+#endif
 #if H_3D_IC
 , m_bApplyIC                      ( false )
@@ -149,5 +164,9 @@
   for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
   {
+#if H_MV5
+   m_interLayerPredLayerIdc[ i ] = i;
+#else
    m_interLayerPredLayerIdc[ i ] = 0;
+#endif
   }
 #endif
@@ -162,12 +181,18 @@
   {
     if ( m_depthToDisparityB && m_depthToDisparityB[ i ] )
+    {
       delete[] m_depthToDisparityB [ i ];
+    }
 
     if ( m_depthToDisparityF && m_depthToDisparityF[ i ] ) 
+    {
       delete[] m_depthToDisparityF [ i ];
   }
+  }
 
   if ( m_depthToDisparityF )
+  {
     delete[] m_depthToDisparityF; 
+  }
 
   m_depthToDisparityF = NULL;
@@ -362,7 +387,6 @@
   }
 }
-#if H_MV
-Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer , Bool checkNumPocTotalCurr)
-#else
+#if H_MV5
+#if !H_MV
 #if FIX1071
 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
@@ -370,5 +394,4 @@
 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
 #endif
-#endif
 {
 #if FIX1071
@@ -380,12 +403,10 @@
       ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
       ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
-      
+
       return;
     }
-    
-#if !H_MV
+
     m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
     m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
-#endif
   }
 
@@ -411,4 +432,352 @@
     }
   }
+
+  for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
+  {
+    if(m_pcRPS->getUsed(i))
+    {
+      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
+      pcRefPic->setIsLongTerm(0);
+      pcRefPic->getPicYuvRec()->extendPicBorder();
+      RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
+      NumPocStCurr1++;
+      pcRefPic->setCheckLTMSBPresent(false);  
+    }
+  }
+
+  for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
+  {
+    if(m_pcRPS->getUsed(i))
+    {
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
+      pcRefPic->setIsLongTerm(1);
+      pcRefPic->getPicYuvRec()->extendPicBorder();
+      RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
+      NumPocLtCurr++;
+    }
+    if(pcRefPic==NULL) 
+    {
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
+    }
+    pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i));  
+  }
+
+  // ref_pic_list_init
+  TComPic*  rpsCurrList0[MAX_NUM_REF+1];
+  TComPic*  rpsCurrList1[MAX_NUM_REF+1];
+  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
+
+#if FIX1071
+  if (checkNumPocTotalCurr)
+  {
+    // 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 (getRapPicFlag())
+    {
+      assert(numPocTotalCurr == 0);
+    }
+
+    if (m_eSliceType == I_SLICE)
+    {
+      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
+      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
+
+      return;
+    }
+
+    assert(numPocTotalCurr > 0);
+
+    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
+    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
+  }
+#endif
+
+  Int cIdx = 0;
+  for ( i=0; i<NumPocStCurr0; i++, cIdx++)
+  {
+    rpsCurrList0[cIdx] = RefPicSetStCurr0[i];
+  }
+  for ( i=0; i<NumPocStCurr1; i++, cIdx++)
+  {
+    rpsCurrList0[cIdx] = RefPicSetStCurr1[i];
+  }
+  for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
+  {
+    rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
+  }
+  assert(cIdx == numPocTotalCurr);
+
+  if (m_eSliceType==B_SLICE)
+  {
+    cIdx = 0;
+    for ( i=0; i<NumPocStCurr1; i++, cIdx++)
+    {
+      rpsCurrList1[cIdx] = RefPicSetStCurr1[i];
+    }
+    for ( i=0; i<NumPocStCurr0; i++, cIdx++)
+    {
+      rpsCurrList1[cIdx] = RefPicSetStCurr0[i];
+    }
+    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
+    {
+      rpsCurrList1[cIdx] = RefPicSetLtCurr[i];
+    }
+    assert(cIdx == numPocTotalCurr);
+  }
+
+  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
+
+  for (Int rIdx = 0; rIdx < m_aiNumRefIdx[0]; rIdx ++)
+  {
+    cIdx = m_RefPicListModification.getRefPicListModificationFlagL0() ? m_RefPicListModification.getRefPicSetIdxL0(rIdx) : rIdx % numPocTotalCurr;
+    assert(cIdx >= 0 && cIdx < numPocTotalCurr);
+    m_apcRefPicList[0][rIdx] = rpsCurrList0[ cIdx ];
+    m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
+  }
+  if ( m_eSliceType != B_SLICE )
+  {
+    m_aiNumRefIdx[1] = 0;
+    ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
+  }
+  else
+  {
+    for (Int rIdx = 0; rIdx < m_aiNumRefIdx[1]; rIdx ++)
+    {
+      cIdx = m_RefPicListModification.getRefPicListModificationFlagL1() ? m_RefPicListModification.getRefPicSetIdxL1(rIdx) : rIdx % numPocTotalCurr;
+      assert(cIdx >= 0 && cIdx < numPocTotalCurr);
+      m_apcRefPicList[1][rIdx] = rpsCurrList1[ cIdx ];
+      m_bIsUsedAsLongTerm[1][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
+    }
+  }
+}
+
+#else
+Void TComSlice::getTempRefPicLists( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1,                                     
+                                   std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int& numPocTotalCurr, Bool checkNumPocTotalCurr )
+{
+  if (!checkNumPocTotalCurr)
+  {
+    if (m_eSliceType == I_SLICE)
+    {      
+      return;
+    }    
+  }
+
+  TComPic*  pcRefPic= NULL;
+  TComPic*  RefPicSetStCurr0[16];
+  TComPic*  RefPicSetStCurr1[16];
+  TComPic*  RefPicSetLtCurr[16];
+  UInt NumPocStCurr0 = 0;
+  UInt NumPocStCurr1 = 0;
+  UInt NumPocLtCurr = 0;
+  Int i;
+
+  for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
+  {
+    if(m_pcRPS->getUsed(i))
+    {
+      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
+      pcRefPic->setIsLongTerm(0);
+      pcRefPic->getPicYuvRec()->extendPicBorder();
+      RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
+      NumPocStCurr0++;
+      pcRefPic->setCheckLTMSBPresent(false);  
+    }
+  }
+  
+  for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
+  {
+    if(m_pcRPS->getUsed(i))
+    {
+      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
+      pcRefPic->setIsLongTerm(0);
+      pcRefPic->getPicYuvRec()->extendPicBorder();
+      RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
+      NumPocStCurr1++;
+      pcRefPic->setCheckLTMSBPresent(false);  
+    }
+  }
+  
+  for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
+  {
+    if(m_pcRPS->getUsed(i))
+    {
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
+      pcRefPic->setIsLongTerm(1);
+      pcRefPic->getPicYuvRec()->extendPicBorder();
+      RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
+      NumPocLtCurr++;
+    }
+    if(pcRefPic==NULL) 
+    {
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
+    }
+    pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i));  
+  }
+
+  Int numPocInterCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; 
+  numPocTotalCurr = numPocInterCurr + getNumActiveRefLayerPics( );
+  assert( numPocTotalCurr == getNumRpsCurrTempList() );
+
+  if (checkNumPocTotalCurr)
+  {
+    // 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 nuh_layer_id is equal to 0 and the current picture is a BLA picture or a 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() && m_layerId == 0 )
+    {
+      assert(numPocTotalCurr == 0);
+    }
+
+    if (m_eSliceType == I_SLICE)
+    {
+      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
+      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
+      
+      return;
+    }
+    
+    assert(numPocTotalCurr > 0);
+    
+    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
+    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
+  }
+
+  std::vector<TComPic*>* refPicSetInterLayer[2] = { &refPicSetInterLayer0, &refPicSetInterLayer1}; 
+  Int numPocInterLayer[2] = { getNumActiveRefLayerPics0( ), getNumActiveRefLayerPics1( ) }; 
+  
+  TComPic**             refPicSetStCurr    [2] = { RefPicSetStCurr0, RefPicSetStCurr1 };
+  Int numPocStCurr[2] = { NumPocStCurr0, NumPocStCurr1 }; 
+
+  for (Int li = 0; li < ((m_eSliceType==B_SLICE) ? 2 : 1); li++)
+  { 
+    rpsCurrList   [li].resize(MAX_NUM_REF+1,NULL ); 
+    usedAsLongTerm[li].resize(MAX_NUM_REF+1,false); 
+
+    Int cIdx = 0;
+    for ( i=0; i < numPocStCurr[li]; i++, cIdx++)
+    {
+      rpsCurrList[li][cIdx] = refPicSetStCurr[li][i];
+      usedAsLongTerm [li][cIdx] = false;  
+    }
+
+    for ( i=0; i < numPocInterLayer[li];  i++, cIdx++)
+    {    
+      rpsCurrList[li][cIdx] = (*refPicSetInterLayer[li])[i];
+      usedAsLongTerm [li][cIdx] = true;  
+    }
+
+    for ( i=0; i < numPocStCurr[1-li]; i++, cIdx++)
+    {
+      rpsCurrList[li][cIdx] = refPicSetStCurr[1-li][i];
+      usedAsLongTerm [li][cIdx] = false;  
+    }
+
+    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
+    {
+      rpsCurrList[li][cIdx] = RefPicSetLtCurr[i];
+      usedAsLongTerm [li][cIdx] = true;  
+    }
+
+    for ( i=0; i < numPocInterLayer[1-li];  i++, cIdx++)
+    {    
+      assert( cIdx < MAX_NUM_REF );    
+      rpsCurrList[li][cIdx] = (*refPicSetInterLayer[1-li])[i];
+      usedAsLongTerm [li][cIdx] = true;  
+    }
+
+    assert(cIdx == numPocTotalCurr);
+  }
+}
+
+Void TComSlice::setRefPicList( std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int numPocTotalCurr, Bool checkNumPocTotalCurr )
+
+{
+  if (!checkNumPocTotalCurr)
+  {
+    if (m_eSliceType == I_SLICE)
+    {
+      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
+      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
+
+      return;
+    }    
+  }
+
+  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
+
+  for (Int li = 0; li < 2; li++)
+  {
+    if ( m_eSliceType == P_SLICE && li == 1 )
+    {
+      m_aiNumRefIdx[1] = 0;
+      ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
+    } 
+    else
+    {
+      for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[ li ] - 1 ); rIdx ++)
+      { 
+        Bool listModified             =                m_RefPicListModification.getRefPicListModificationFlagL( li ); 
+        Int orgIdx                    = listModified ? m_RefPicListModification.getRefPicSetIdxL(li, rIdx) : (rIdx % numPocTotalCurr); 
+
+        assert( rpsCurrList[li][ orgIdx ] != NULL ); 
+        m_apcRefPicList    [li][rIdx] = rpsCurrList    [li][ orgIdx ];
+        m_bIsUsedAsLongTerm[li][rIdx] = usedAsLongTerm [li][ orgIdx ] ; 
+      }
+    }
+  }
+}
+#endif
+#else
+#if H_MV
+Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer , Bool checkNumPocTotalCurr)
+#else
+#if FIX1071
+Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
+#else
+Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
+#endif
+#endif
+{
+#if FIX1071
+  if (!checkNumPocTotalCurr)
+#endif
+  {
+    if (m_eSliceType == I_SLICE)
+    {
+      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
+      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
+      
+      return;
+    }
+    
+#if !H_MV
+    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
+    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
+#endif
+  }
+
+  TComPic*  pcRefPic= NULL;
+  TComPic*  RefPicSetStCurr0[16];
+  TComPic*  RefPicSetStCurr1[16];
+  TComPic*  RefPicSetLtCurr[16];
+  UInt NumPocStCurr0 = 0;
+  UInt NumPocStCurr1 = 0;
+  UInt NumPocLtCurr = 0;
+  Int i;
+
+  for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
+  {
+    if(m_pcRPS->getUsed(i))
+    {
+      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
+      pcRefPic->setIsLongTerm(0);
+      pcRefPic->getPicYuvRec()->extendPicBorder();
+      RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
+      NumPocStCurr0++;
+      pcRefPic->setCheckLTMSBPresent(false);  
+    }
+  }
   
   for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
@@ -458,10 +827,10 @@
     // 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 H_MV
-    // – If nuh_layer_id is equal to 0 and the current picture is a BLA picture or a 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 nuh_layer_id is equal to 0 and the current picture is a BLA picture or a 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() && m_layerId == 0 )
 #else
-    // – 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())
 #endif
@@ -593,4 +962,5 @@
 }
 
+#endif
 Int TComSlice::getNumRpsCurrTempList()
 {
@@ -609,5 +979,7 @@
   }
 #if H_MV
+#if !H_MV5
   assert( ( numRpsCurrTempList == 0 ) || getInterRefEnabledInRPLFlag() ); 
+#endif
   numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics();
 #endif
@@ -923,4 +1295,7 @@
 #if H_MV
   // Additional slice header syntax elements 
+#if H_MV5
+  m_pocResetFlag               = pSrc->m_pocResetFlag; 
+#endif
   m_discardableFlag            = pSrc->m_discardableFlag; 
   m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag; 
@@ -931,5 +1306,5 @@
     m_interLayerPredLayerIdc[ layer ] = pSrc->m_interLayerPredLayerIdc[ layer ]; 
   }
-  
+#if !H_MV5
   m_interLayerSamplePredOnlyFlag = pSrc->m_interLayerSamplePredOnlyFlag;
   m_altCollocatedIndicationFlag  = pSrc->m_altCollocatedIndicationFlag ;   
@@ -941,4 +1316,5 @@
     m_interLayerPredLayerIdc[layer] = pSrc->m_interLayerPredLayerIdc[layer];
   }
+#endif
 #endif
 #if H_3D_IC
@@ -1405,5 +1781,13 @@
 : m_VPSId                     (  0)
 , m_uiMaxTLayers              (  1)
+#if H_MV5
+#if H_MV
+, m_uiMaxLayersMinus1         (  0)
+#else
 , m_uiMaxLayers               (  1)
+#endif
+#else
+, m_uiMaxLayers               (  1)
+#endif
 , m_bTemporalIdNestingFlag    (false)
 , m_numHrdParameters          (  0)
@@ -1416,4 +1800,9 @@
 , m_hrdOpSetIdx               (NULL)
 , m_cprmsPresentFlag          (NULL)
+#if H_MV5
+#if H_MV
+, m_vpsVUI                 (  NULL )
+#endif
+#endif
 {
   for( Int i = 0; i < MAX_TLAYER; i++)
@@ -1459,9 +1848,16 @@
 
   m_avcBaseLayerFlag = false;
+#if H_MV5
+  m_vpsVuiOffset     = 0; 
+#endif
   m_splittingFlag    = false;
   
   for( Int i = 0; i < MAX_NUM_SCALABILITY_TYPES; i++ )
   {
+#if H_MV5
+    m_scalabilityMaskFlag[i] = false;
+#else
     m_scalabilityMask[i] = false;
+#endif
     m_dimensionIdLen [i]  = -1; 
   }
@@ -1489,5 +1885,13 @@
     m_layerIdInNuh      [i] = ( i == 0 ) ? 0 : -1; 
     m_numDirectRefLayers[i] = 0; 
+#if H_MV5
+    m_maxTidIlRefPicPlus1[i] = 7;
+    m_vpsRepFormatIdx    [i] = 0; 
+    m_repFormat          [i] = NULL; 
+    m_viewIdVal          [i] = 0; 
+#else
     m_maxTidIlRefPicPlus1[i] = -1; 
+#endif
+
 #if H_3D
     m_viewIndex         [i] = -1; 
@@ -1510,5 +1914,5 @@
     }
 #endif
-#if H_3D_TMVP
+#if H_3D
     m_ivMvScalingFlag = true; 
 #endif
@@ -1531,4 +1935,7 @@
 #endif
   }
+#if H_MV5
+  m_vpsVUI = new TComVPSVUI; 
+#endif
 #if H_3D
   for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
@@ -1556,4 +1963,26 @@
   if( m_hrdOpSetIdx      != NULL )     delete[] m_hrdOpSetIdx;
   if( m_cprmsPresentFlag != NULL )     delete[] m_cprmsPresentFlag;
+#if H_MV5
+#if H_MV
+  if ( m_vpsVUI          != NULL )     delete m_vpsVUI; 
+  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
+  {
+    if (m_repFormat[ i ] != NULL )      delete m_repFormat[ i ];    
+#if H_3D_DIM_DLT
+    if ( m_iDepthValue2Idx[i] != 0 ) 
+    {
+       xFree( m_iDepthValue2Idx[i] );
+       m_iDepthValue2Idx[i] = 0; 
+    }
+
+    if ( m_iIdx2DepthValue[i] != 0 ) 
+    {
+      xFree( m_iIdx2DepthValue[i] );
+      m_iIdx2DepthValue[i] = 0; 
+    }
+#endif
+  }
+#endif
+#else
 #if H_3D_DIM_DLT
   for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
@@ -1572,4 +2001,5 @@
     }
   }
+#endif
 #endif
 }
@@ -1642,5 +2072,9 @@
 Bool TComVPS::checkVPSExtensionSyntax()
 {
+#if H_MV5
+  for( Int layer = 1; layer <= getMaxLayersMinus1(); layer++ )
+#else
   for( Int layer = 1; layer < getMaxLayers(); layer++ )
+#endif
   {
     // check layer_id_in_nuh constraint
@@ -1658,15 +2092,31 @@
 {
   assert( scalType >= 0 && scalType <= MAX_NUM_SCALABILITY_TYPES ); 
+#if H_MV5
+  assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMaskFlag( scalType ) );
+#else
   assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMask( scalType ) );
-
+#endif
   Int scalIdx = 0; 
   for( Int curScalType = 0; curScalType < scalType; curScalType++ )
   {
+#if H_MV5
+    scalIdx += ( getScalabilityMaskFlag( curScalType ) ? 1 : 0 );
+#else
     scalIdx += ( getScalabilityMask( curScalType ) ? 1 : 0 );
+#endif
+
   }
 
   return scalIdx; 
 }
-
+#if H_MV5
+Void TComVPS::setScalabilityMaskFlag( UInt val )
+{
+  for ( Int scalType = 0; scalType < MAX_NUM_SCALABILITY_TYPES; scalType++ ) 
+  {
+    setScalabilityMaskFlag( scalType, ( val & (1 << scalType ) ) != 0 );
+  }
+}
+#else
 Void TComVPS::setScalabilityMask( UInt val )
 {
@@ -1675,4 +2125,56 @@
 }
 
+#endif
+
+#if H_MV5
+Void TComVPS::setRefLayers()
+{
+  for( Int i = 0; i  <= getMaxLayersMinus1(); i++ )
+  {
+    Int iNuhLId = getLayerIdInNuh( i ); 
+    m_numDirectRefLayers[ iNuhLId ] = 0; 
+    for( Int j = 0; j < i; j++ )
+    {
+      if( getDirectDependencyFlag(i , j) )
+      {
+        m_refLayerId[ iNuhLId ][m_numDirectRefLayers[ iNuhLId ]++ ] = getLayerIdInNuh( j );
+      }
+    }
+  }
+}
+
+Int TComVPS::getRefLayerId( Int layerIdInNuh, Int idx )
+{
+  assert( idx >= 0 && idx < m_numDirectRefLayers[layerIdInNuh] );     
+  Int refLayerIdInNuh = m_refLayerId[ layerIdInNuh ][ idx ];    
+  assert ( refLayerIdInNuh >= 0 ); 
+  return refLayerIdInNuh;
+}
+
+Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType )
+{
+  return getScalabilityMaskFlag( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0;
+}
+
+#if H_3D
+Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag )
+{
+  Int foundLayerIdinNuh = -1; 
+
+  for (Int layerIdInVps = 0 ; layerIdInVps <= getMaxLayersMinus1(); layerIdInVps++ )
+  {
+    Int layerIdInNuh = getLayerIdInNuh( layerIdInVps ); 
+    if( ( getViewIndex( layerIdInNuh ) == viewIndex ) && ( getDepthId( layerIdInNuh ) == ( depthFlag ? 1 : 0 ) )  )
+    {
+      foundLayerIdinNuh = layerIdInNuh; 
+      break; 
+    }
+  }
+  assert( foundLayerIdinNuh != -1 ); 
+
+  return foundLayerIdinNuh;
+}
+#endif // H_3D
+#else
 Void TComVPS::setRefLayers()
 {
@@ -1793,4 +2295,6 @@
 }
 
+#endif // H_MV5
+
 
 Int TComVPS::xGetDimBitOffset( Int j )
@@ -1832,4 +2336,35 @@
   return numLayersInIdList;
 }
+#if H_MV5
+Int TComVPS::getNumViews()
+{
+  Int numViews = 1; 
+  for( Int i = 0; i <=  getMaxLayersMinus1(); i++ )
+  {
+    Int lId = getLayerIdInNuh( i ); 
+    if ( i > 0 && ( getViewIndex( lId ) != getScalabilityId( i - 1, VIEW_ORDER_INDEX ) ) )
+    {
+      numViews++; 
+    }    
+  }
+
+  return numViews;
+}
+
+Bool TComVPS::getInDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Int depth /*= 0 */ )
+{
+  assert( depth < 65 ); 
+  Bool dependentFlag = getDirectDependencyFlag( depLayeridInVps, refLayeridInVps ); 
+
+  for( Int i = 0; i < depLayeridInVps && !dependentFlag; i++ )
+  {
+    if ( getDirectDependencyFlag( depLayeridInVps, i ) )
+    {
+      dependentFlag = getInDirectDependencyFlag( i, refLayeridInVps, depth++ ); 
+    }
+  }
+  return dependentFlag;
+}
+#endif
 #endif // H_MV
 
@@ -1882,6 +2417,14 @@
 , m_vuiParameters             ()
 #if H_MV
+#if H_MV5
+, m_pcVPS                     ( NULL )
+, m_spsInferScalingListFlag   ( false )
+, m_spsScalingListRefLayerId  ( 0 )
+, m_updateRepFormatFlag       ( true ) 
+, m_interViewMvVertConstraintFlag (false)
+#else
 , m_interViewMvVertConstraintFlag (false)
 , m_numIlpRestrictedRefLayers ( 0 )
+#endif
 #endif
 #if H_3D
@@ -1898,4 +2441,5 @@
   ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
   ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
+#if !H_MV5
 #if H_MV
   for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
@@ -1905,4 +2449,5 @@
     m_minHorizontalCtuOffsetPlus1 [ i ] = 0;
   }
+#endif
 #endif
 }
@@ -2058,4 +2603,10 @@
 , m_listsModificationPresentFlag(  0)
 , m_numExtraSliceHeaderBits(0)
+#if H_MV5
+#if H_MV
+, m_ppsInferScalingListFlag(false)
+, m_ppsScalingListRefLayerId(0)
+#endif
+#endif
 {
   m_scalingList = new TComScalingList;
@@ -2077,4 +2628,57 @@
 }
 
+#if H_MV5
+#if H_MV
+Void TComSPS::inferRepFormat( TComVPS* vps, Int layerIdCurr )
+{
+  if ( layerIdCurr > 0 )
+  { 
+    TComRepFormat* repFormat = vps->getRepFormat( vps->getVpsRepFormatIdx( vps->getLayerIdInVps( layerIdCurr ) ) ); 
+    if ( !getUpdateRepFormatFlag() )
+    {        
+      setChromaFormatIdc( repFormat->getChromaFormatVpsIdc() );         
+      //// ToDo: add when supported: 
+      // setSeperateColourPlaneFlag( repFormat->getSeparateColourPlaneVpsFlag() ) ; 
+
+      setPicWidthInLumaSamples ( repFormat->getPicWidthVpsInLumaSamples()  ); 
+      setPicHeightInLumaSamples( repFormat->getPicHeightVpsInLumaSamples() ); 
+
+      setBitDepthY             ( repFormat->getBitDepthVpsLumaMinus8()   + 8 ); 
+      setQpBDOffsetY           ( (Int) (6*( getBitDepthY() - 8 )) );
+
+      setBitDepthC             ( repFormat->getBitDepthVpsChromaMinus8() + 8 ); 
+      setQpBDOffsetC           ( (Int) (6* ( getBitDepthC() -8 ) ) );
+    }
+    else
+    {
+      assert( getChromaFormatIdc()      <=  repFormat->getChromaFormatVpsIdc()         ); 
+      //// ToDo: add when supported: 
+      // assert( getSeperateColourPlaneFlag() <=  repFormat->getSeparateColourPlaneVpsFlag() ) ; 
+
+      assert( getPicWidthInLumaSamples()  <= repFormat->getPicWidthVpsInLumaSamples()    ); 
+      assert( getPicHeightInLumaSamples() <= repFormat->getPicHeightVpsInLumaSamples()   ); 
+
+      assert( getBitDepthY()              <= repFormat->getBitDepthVpsLumaMinus8()   + 8 );         
+      assert( getBitDepthC()              <= repFormat->getBitDepthVpsChromaMinus8() + 8 ); 
+    }
+  }
+
+  // Set conformance window
+  Int scal = TComSPS::getWinUnitX( getChromaFormatIdc() ) ;
+  getConformanceWindow().scaleOffsets( scal );
+  getVuiParameters()->getDefaultDisplayWindow().scaleOffsets( scal );
+}
+
+Void TComSPS::inferScalingList( TComSPS* spsSrc )
+{
+  if ( getSpsInferScalingListFlag() ) 
+  {
+    assert( spsSrc != NULL ); 
+    assert( !spsSrc->getSpsInferScalingListFlag() );             
+    getScalingList()->inferFrom( spsSrc->getScalingList() ); 
+  }
+}
+#endif
+#endif
 #if H_3D
 Void
@@ -2346,7 +2950,9 @@
 
 #if H_MV
-Void TComSlice::createAndApplyIvReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer )
-{
-  refPicSetInterLayer.clear(); 
+#if H_MV5
+Void TComSlice::createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 )
+{
+  refPicSetInterLayer0.clear(); 
+  refPicSetInterLayer1.clear(); 
 
   for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) 
@@ -2360,4 +2966,35 @@
     picRef->getSlice(0)->setReferenced( true );       
 
+    Int viewIdCur  = getVPS()->getViewId( getLayerId() ); 
+    Int viewIdZero = getVPS()->getViewId( 0 );
+    Int viewIdRef  = getVPS()->getViewId( layerIdRef ); 
+
+    if (  ( viewIdCur <= viewIdZero && viewIdCur <= viewIdRef ) || ( viewIdCur >= viewIdZero && viewIdCur >= viewIdRef ) )
+    {
+      refPicSetInterLayer0.push_back( picRef ); 
+    }
+    else
+    {
+      refPicSetInterLayer1.push_back( picRef ); 
+    }
+    // Consider to check here: 
+    // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer0 and RefPicSetInterLayer1 that is a RASL picture. "    
+  }
+}
+#else
+Void TComSlice::createAndApplyIvReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer )
+{
+  refPicSetInterLayer.clear(); 
+
+  for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) 
+  {
+    Int layerIdRef = getRefPicLayerId( i ); 
+    TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ; 
+    assert ( picRef != 0 ); 
+
+    picRef->getPicYuvRec()->extendPicBorder(); 
+    picRef->setIsLongTerm( true );        
+    picRef->getSlice(0)->setReferenced( true );       
+
     // Consider to check here: 
     // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer that is a RASL picture. "
@@ -2365,5 +3002,22 @@
   }
 }
-
+#endif
+
+#if H_MV5
+Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 )
+{
+  // Mark as shortterm 
+  for ( Int i = 0; i < refPicSetInterLayer0.size(); i++ ) 
+  {
+    refPicSetInterLayer0[i]->setIsLongTerm( false ); 
+  }
+
+  for ( Int i = 0; i < refPicSetInterLayer1.size(); i++ ) 
+  {
+    refPicSetInterLayer1[i]->setIsLongTerm( false ); 
+  }
+
+}
+#else
 Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer )
 {
@@ -2375,4 +3029,5 @@
 }
 
+#endif
 Void TComSlice::markIvRefPicsAsUnused( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc )
 {
@@ -2380,5 +3035,9 @@
   if (targetDecLayerIdSet.size() == 0 )    
   {
+#if H_MV5
+    for ( Int layerIdInVps = 0; layerIdInVps <= vps->getMaxLayersMinus1(); layerIdInVps++ )
+#else
     for ( Int layerIdInVps = 0; layerIdInVps < vps->getMaxLayers(); layerIdInVps++ )
+#endif
     {
       targetDecLayerIdSet.push_back( vps->getLayerIdInNuh( layerIdInVps ) ); 
@@ -2391,5 +3050,7 @@
   {
     if ( targetDecLayerIdSet[ latestDecIdx ] == curLayerId )
+    {
       break; 
+  }        
   }        
 
@@ -2407,11 +3068,22 @@
           if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ j ] ) )
           {
+#if H_MV5
+            for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdSet[ j ] ); k++ )
+            {
+              if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdSet[ j ],  k  ) )
+#else
             Int targetDecLayerIdinVPS = vpsSlice->getLayerIdInVps( targetDecLayerIdSet[ j ] ); 
             for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdinVPS ); k++ )
+            {
               if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdinVPS,  k  ) )
+#endif
+              {
                 remainingInterLayerReferencesFlag = true;
           }
         }
+          }
+        }
         if( !remainingInterLayerReferencesFlag )
+        {
           pcPic->getSlice(0)->setReferenced( false );                   
       }
@@ -2419,6 +3091,11 @@
   }
 }
-
+}
+
+#if H_MV5
+Void TComSlice::printRefPicList()
+#else
 Void TComSlice::xPrintRefPicList()
+#endif
 {  
   for ( Int li = 0; li < 2; li++)
@@ -2433,4 +3110,5 @@
   }
 }
+#if !H_MV5
 Int TComSlice::xCeilLog2( Int val )
 {
@@ -2440,4 +3118,5 @@
   return ceilLog2;
 }
+#endif
 
 Void TComSlice::markCurrPic( TComPic* currPic )
@@ -2454,4 +3133,30 @@
 }
 
+#if H_MV5
+Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1 )
+{
+  m_refPicSetInterLayer0 = refPicSetInterLayer0; 
+  m_refPicSetInterLayer1 = refPicSetInterLayer1; 
+}
+
+TComPic* TComSlice::getPicFromRefPicSetInterLayer(Int setIdc, Int layerId )
+{
+  assert ( setIdc == 0 || setIdc == 1);   
+  std::vector<TComPic*>* refPicSetInterLayer = ( setIdc == 0 ? m_refPicSetInterLayer0 : m_refPicSetInterLayer1);   
+  assert( refPicSetInterLayer != 0 ); 
+  
+  TComPic* pcPic = NULL; 
+  for ( Int i = 0; i < (*refPicSetInterLayer).size(); i++ )
+  {
+    if ((*refPicSetInterLayer)[ i ]->getLayerId() == layerId )
+    {
+      pcPic = (*refPicSetInterLayer)[ i ]; 
+    }
+  }
+
+  assert(pcPic != NULL); 
+  return pcPic;
+}
+#else
 Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer )
 {
@@ -2474,9 +3179,24 @@
   return pcPic;
 }
-
+#endif
 Int TComSlice::getNumActiveRefLayerPics()
 {
   Int numActiveRefLayerPics; 
 
+#if H_MV5
+  if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerId() ) ==  0 )
+  {
+    numActiveRefLayerPics = 0; 
+  }
+  else if (getVPS()->getAllRefLayersActiveFlag() )
+  {
+    numActiveRefLayerPics = getVPS()->getNumDirectRefLayers( getLayerId() );
+  }
+  else if ( !getInterLayerPredEnabledFlag() )
+  {
+    numActiveRefLayerPics = 0; 
+  }
+  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerId() ) == 1 )
+#else
   if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) ==  0 || !getInterLayerPredEnabledFlag() )
   {
@@ -2484,4 +3204,5 @@
   }
   else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) == 1 )
+#endif
   {
     numActiveRefLayerPics = 1; 
@@ -2496,7 +3217,12 @@
 Int TComSlice::getRefPicLayerId( Int i )
 {
+#if H_MV5
+  return getVPS()->getRefLayerId( getLayerId(), getInterLayerPredLayerIdc( i ) );
+#else
   return getVPS()->getRefLayerId( getLayerIdInVps(), getInterLayerPredLayerIdc( i ) );
-}
-
+#endif
+}
+
+#if !H_MV5
 Void TComSlice::setActiveMotionPredRefLayers()
 {
@@ -2527,4 +3253,5 @@
   return interRefEnabledInRPLFlag;
 }
+#endif
 #if H_3D_ARP
 Void TComSlice::setARPStepNum()                                  
@@ -2804,4 +3531,20 @@
 }
 
+#if H_MV5
+#if H_MV
+Void TComScalingList::inferFrom( TComScalingList* srcScLi )
+{
+  for(Int sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
+  {
+    for(Int listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
+    {
+      setRefMatrixId  (sizeId,listId, srcScLi->getRefMatrixId  (sizeId,listId));
+      setScalingListDC(sizeId,listId, srcScLi->getScalingListDC(sizeId,listId));          
+      ::memcpy(getScalingListAddress(sizeId, listId),srcScLi->getScalingListAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
+    }
+  }
+}
+#endif
+#endif
 /** initialization process of quantization matrix array
  */
@@ -2893,7 +3636,22 @@
 , m_ppsMap(MAX_NUM_PPS)
 , m_activeVPSId(-1)
+#if H_MV5
+#if !H_MV
 , m_activeSPSId(-1)
 , m_activePPSId(-1)
 {
+#else
+{
+  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
+  {
+    m_activeSPSId[ i ] = -1; 
+    m_activePPSId[ i ] = -1; 
+  }
+#endif
+#else
+, m_activeSPSId(-1)
+, m_activePPSId(-1)
+{
+#endif
 }
 
@@ -2905,5 +3663,13 @@
 //! activate a SPS from a active parameter sets SEI message
 //! \returns true, if activation is successful
+#if H_MV5
+#if H_MV
+Bool ParameterSetManager::activateSPSWithSEI(Int spsId, Int layerId )
+#else
 Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
+#endif
+#else
+Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
+#endif
 {
   TComSPS *sps = m_spsMap.getPS(spsId);
@@ -2914,5 +3680,13 @@
     {
       m_activeVPSId = vpsId;
+#if !H_MV5
       m_activeSPSId = spsId;
+#else
+#if H_MV
+      m_activeSPSId[ layerId ] = spsId;
+#else
+      m_activeSPSId = spsId;
+#endif
+#endif
       return true;
     }
@@ -2931,4 +3705,46 @@
 //! activate a PPS and depending on isIDR parameter also SPS and VPS
 //! \returns true, if activation is successful
+#if H_MV5
+#if H_MV
+Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP, Int layerId )
+#else
+Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
+#endif
+{
+  TComPPS *pps = m_ppsMap.getPS(ppsId);
+  if (pps)
+  {
+    Int spsId = pps->getSPSId();
+#if H_MV
+    if (!isIRAP && (spsId != m_activeSPSId[ layerId ]))
+#else
+    if (!isIRAP && (spsId != m_activeSPSId))
+#endif
+    {
+      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP.");
+      return false;
+    }
+
+    TComSPS *sps = m_spsMap.getPS(spsId);
+    if (sps)
+    {
+      Int vpsId = sps->getVPSId();
+      if (!isIRAP && (vpsId != m_activeVPSId))
+      {
+        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP.");
+        return false;
+      }
+      if (m_vpsMap.getPS(vpsId))
+      {
+#if H_MV
+        m_activePPSId[ layerId ] = ppsId;
+        m_activeVPSId = vpsId;
+        m_activeSPSId[ layerId ] = spsId;
+#else
+        m_activePPSId = ppsId;
+        m_activeVPSId = vpsId;
+        m_activeSPSId = spsId;
+#endif
+#else
 Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
 {
@@ -2960,4 +3776,5 @@
         m_activeVPSId = vpsId;
         m_activeSPSId = spsId;
+#endif
         return true;
       }
@@ -3009,14 +3826,38 @@
 }
 #endif
-#if SIGNAL_BITRATE_PICRATE_IN_VPS
-TComBitRatePicRateInfo::TComBitRatePicRateInfo()
-{
-  ::memset(m_bitRateInfoPresentFlag, 0, sizeof(m_bitRateInfoPresentFlag));
-  ::memset(m_picRateInfoPresentFlag, 0, sizeof(m_picRateInfoPresentFlag));
-  ::memset(m_avgBitRate,             0, sizeof(m_avgBitRate));
-  ::memset(m_maxBitRate,             0, sizeof(m_maxBitRate));
-  ::memset(m_constantPicRateIdc,     0, sizeof(m_constantPicRateIdc));
-  ::memset(m_avgPicRate,             0, sizeof(m_avgPicRate));
-}
-#endif
 //! \}
+
+#if H_MV5
+#if H_MV
+TComVPSVUI::TComVPSVUI()
+{
+  m_bitRatePresentVpsFlag = false;
+  m_picRatePresentVpsFlag = false;
+  for ( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++)
+  {    
+    for ( Int j = 0; j < MAX_TLAYER; j++)
+    {    
+      m_bitRatePresentFlag          [i][j] = false;
+      m_picRatePresentFlag          [i][j] = false;
+      m_avgBitRate                  [i][j] = -1;
+      m_maxBitRate                  [i][j] = -1;
+      m_constantPicRateIdc          [i][j] = -1;
+      m_avgPicRate                  [i][j] = -1;
+    }
+  }
+
+  m_ilpRestrictedRefLayersFlag = false;
+
+  for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
+  {          
+    for ( Int j = 0; j < MAX_NUM_LAYERS; j++)
+    {    
+      m_tileBoundariesAlignedFlag   [i][j] = false;
+      m_minSpatialSegmentOffsetPlus1[i][j] = 0;
+      m_ctuBasedOffsetEnabledFlag   [i][j] = false;
+      m_minHorizontalCtuOffsetPlus1 [i][j] = -1;
+    }
+  }
+}
+#endif
+#endif
Index: trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.h	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComSlice.h	(revision 622)
@@ -169,4 +169,9 @@
   Void     processRefMatrix               (UInt sizeId, UInt listId , UInt refListId );
   Bool     xParseScalingList              (Char* pchFile);
+#if H_MV5
+#if H_MV
+  Void     inferFrom                      ( TComScalingList* srcScLi );
+#endif
+#endif
 
 private:
@@ -402,4 +407,101 @@
 };
 
+#if H_MV5
+#if H_MV
+class TComVPSVUI
+{
+private:
+  Bool m_bitRatePresentVpsFlag;
+  Bool m_picRatePresentVpsFlag;
+  Bool m_bitRatePresentFlag          [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
+  Bool m_picRatePresentFlag          [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
+  Int  m_avgBitRate                  [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
+  Int  m_maxBitRate                  [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
+  Int  m_constantPicRateIdc          [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
+  Int  m_avgPicRate                  [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
+  Bool m_tileBoundariesAlignedFlag   [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+  Bool m_ilpRestrictedRefLayersFlag;
+  Int  m_minSpatialSegmentOffsetPlus1[MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+  Bool m_ctuBasedOffsetEnabledFlag   [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+  Int  m_minHorizontalCtuOffsetPlus1 [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+
+public: 
+  TComVPSVUI();;
+
+  Void setBitRatePresentVpsFlag( Bool flag ) { m_bitRatePresentVpsFlag = flag; } 
+  Bool getBitRatePresentVpsFlag(  ) { return m_bitRatePresentVpsFlag; } 
+
+  Void setPicRatePresentVpsFlag( Bool flag ) { m_picRatePresentVpsFlag = flag; } 
+  Bool getPicRatePresentVpsFlag(  ) { return m_picRatePresentVpsFlag; } 
+
+  Void setBitRatePresentFlag( Int i, Int j, Bool flag ) { m_bitRatePresentFlag[i][j] = flag; } 
+  Bool getBitRatePresentFlag( Int i, Int j ) { return m_bitRatePresentFlag[i][j]; } 
+
+  Void setPicRatePresentFlag( Int i, Int j, Bool flag ) { m_picRatePresentFlag[i][j] = flag; } 
+  Bool getPicRatePresentFlag( Int i, Int j ) { return m_picRatePresentFlag[i][j]; } 
+
+  Void setAvgBitRate( Int i, Int j, Int  val ) { m_avgBitRate[i][j] = val; } 
+  Int  getAvgBitRate( Int i, Int j ) { return m_avgBitRate[i][j]; } 
+
+  Void setMaxBitRate( Int i, Int j, Int  val ) { m_maxBitRate[i][j] = val; } 
+  Int  getMaxBitRate( Int i, Int j ) { return m_maxBitRate[i][j]; } 
+
+  Void setConstantPicRateIdc( Int i, Int j, Int  val ) { m_constantPicRateIdc[i][j] = val; } 
+  Int  getConstantPicRateIdc( Int i, Int j ) { return m_constantPicRateIdc[i][j]; } 
+
+  Void setAvgPicRate( Int i, Int j, Int  val ) { m_avgPicRate[i][j] = val; } 
+  Int  getAvgPicRate( Int i, Int j ) { return m_avgPicRate[i][j]; } 
+
+  Void setTileBoundariesAlignedFlag( Int i, Int j, Bool flag ) { m_tileBoundariesAlignedFlag[i][j] = flag; } 
+  Bool getTileBoundariesAlignedFlag( Int i, Int j ) { return m_tileBoundariesAlignedFlag[i][j]; } 
+
+  Void setIlpRestrictedRefLayersFlag( Bool flag ) { m_ilpRestrictedRefLayersFlag = flag; } 
+  Bool getIlpRestrictedRefLayersFlag(  ) { return m_ilpRestrictedRefLayersFlag; } 
+
+  Void setMinSpatialSegmentOffsetPlus1( Int i, Int j, Int  val ) { m_minSpatialSegmentOffsetPlus1[i][j] = val; } 
+  Int  getMinSpatialSegmentOffsetPlus1( Int i, Int j ) { return m_minSpatialSegmentOffsetPlus1[i][j]; } 
+
+  Void setCtuBasedOffsetEnabledFlag( Int i, Int j, Bool flag ) { m_ctuBasedOffsetEnabledFlag[i][j] = flag; } 
+  Bool getCtuBasedOffsetEnabledFlag( Int i, Int j ) { return m_ctuBasedOffsetEnabledFlag[i][j]; } 
+
+  Void setMinHorizontalCtuOffsetPlus1( Int i, Int j, Int  val ) { m_minHorizontalCtuOffsetPlus1[i][j] = val; } 
+  Int  getMinHorizontalCtuOffsetPlus1( Int i, Int j ) { return m_minHorizontalCtuOffsetPlus1[i][j]; } 
+
+};
+
+class TComRepFormat
+{
+private:
+  Int  m_chromaFormatVpsIdc;
+  Bool m_separateColourPlaneVpsFlag;
+  Int  m_picWidthVpsInLumaSamples;
+  Int  m_picHeightVpsInLumaSamples;
+  Int  m_bitDepthVpsLumaMinus8;
+  Int  m_bitDepthVpsChromaMinus8;
+
+public: 
+  TComRepFormat() { };  
+
+  Void setChromaFormatVpsIdc( Int  val ) { m_chromaFormatVpsIdc = val; } 
+  Int  getChromaFormatVpsIdc(  ) { return m_chromaFormatVpsIdc; } 
+
+  Void setSeparateColourPlaneVpsFlag( Bool flag ) { m_separateColourPlaneVpsFlag = flag; } 
+  Bool getSeparateColourPlaneVpsFlag(  ) { return m_separateColourPlaneVpsFlag; } 
+
+  Void setPicWidthVpsInLumaSamples( Int  val ) { m_picWidthVpsInLumaSamples = val; } 
+  Int  getPicWidthVpsInLumaSamples(  ) { return m_picWidthVpsInLumaSamples; } 
+
+  Void setPicHeightVpsInLumaSamples( Int  val ) { m_picHeightVpsInLumaSamples = val; } 
+  Int  getPicHeightVpsInLumaSamples(  ) { return m_picHeightVpsInLumaSamples; } 
+
+  Void setBitDepthVpsLumaMinus8( Int  val ) { m_bitDepthVpsLumaMinus8 = val; } 
+  Int  getBitDepthVpsLumaMinus8(  ) { return m_bitDepthVpsLumaMinus8; } 
+
+  Void setBitDepthVpsChromaMinus8( Int  val ) { m_bitDepthVpsChromaMinus8 = val; } 
+  Int  getBitDepthVpsChromaMinus8(  ) { return m_bitDepthVpsChromaMinus8; } 
+};
+#endif
+#endif
+
 class TComVPS
 {
@@ -407,5 +509,14 @@
   Int         m_VPSId;
   UInt        m_uiMaxTLayers;
+
+#if H_MV5
+#if H_MV
+  UInt        m_uiMaxLayersMinus1;
+#else
   UInt        m_uiMaxLayers;
+#endif
+#else
+  UInt        m_uiMaxLayers;
+#endif
   Bool        m_bTemporalIdNestingFlag;
   
@@ -440,12 +551,29 @@
   /// VPS EXTENSION SYNTAX ELEMENTS
   Bool        m_avcBaseLayerFlag;
+#if H_MV5
+  Int         m_vpsVuiOffset;
+#endif
   Bool        m_splittingFlag;
+#if H_MV5
+  Bool        m_scalabilityMaskFlag          [MAX_NUM_SCALABILITY_TYPES];
+#else
   Bool        m_scalabilityMask          [MAX_NUM_SCALABILITY_TYPES];
+#endif
   Int         m_dimensionIdLen           [MAX_NUM_SCALABILITY_TYPES];
   Bool        m_vpsNuhLayerIdPresentFlag;
   Int         m_layerIdInNuh             [MAX_NUM_LAYER_IDS];
   Int         m_dimensionId              [MAX_NUM_LAYER_IDS][MAX_NUM_SCALABILITY_TYPES];  
+#if H_MV5
+  Int         m_viewIdLenMinus1;
+  Int         m_viewIdVal                [MAX_NUM_LAYERS];
+#endif
   Bool        m_directDependencyFlag     [MAX_NUM_LAYER_IDS][MAX_NUM_LAYER_IDS];
+#if H_MV5
+  Bool        m_maxTidRefPresentFlag;
+#endif
   Int         m_maxTidIlRefPicPlus1      [MAX_NUM_LAYERS];
+#if H_MV5
+  Bool        m_allRefLayersActiveFlag;
+#endif
   Int         m_vpsNumberLayerSetsMinus1; 
   Int         m_vpsNumProfileTierLevelMinus1;   
@@ -458,6 +586,19 @@
   Bool        m_outputLayerFlag          [MAX_VPS_OUTPUTLAYER_SETS][MAX_VPS_NUH_LAYER_ID_PLUS1];
   Int         m_profileLevelTierIdx      [MAX_VPS_OUTPUTLAYER_SETS ];
+#if H_MV5
+  Bool        m_repFormatIdxPresentFlag;
+  Int         m_vpsNumRepFormatsMinus1;
+  Int         m_vpsRepFormatIdx          [MAX_NUM_LAYERS];
+  TComRepFormat* m_repFormat             [MAX_NUM_LAYERS]; 
+#endif
   Bool        m_maxOneActiveRefLayerFlag;       
+#if H_MV5
+  Bool        m_crossLayerIrapAlignedFlag;
+#endif
   Int         m_directDepTypeLenMinus2;         
+#if H_MV5
+  Bool        m_vpsVuiPresentFlag;
+  TComVPSVUI* m_vpsVUI; 
+#endif
   Int         m_directDependencyType     [MAX_NUM_LAYERS] [MAX_NUM_LAYERS];
 
@@ -475,4 +616,7 @@
   Bool        m_motionPredEnabledFlag    [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
   Int         m_motionPredRefLayerId     [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+#if H_MV5
+  Int         m_viewIndex                [MAX_NUM_LAYERS   ];
+#else
 #if H_3D
   Int         m_viewIndex                [MAX_NUM_LAYERS   ];
@@ -480,6 +624,8 @@
 
   Int         xCeilLog2       ( Int val );
+#endif
   Int         xGetDimBitOffset( Int j );
   
+  // VPS EXTENSION 2 SYNTAX ELEMENTS
 #if H_3D_ARP
   UInt        m_uiUseAdvResPred          [MAX_NUM_LAYERS   ];
@@ -504,5 +650,5 @@
   Int*        m_iIdx2DepthValue          [MAX_NUM_LAYERS   ];
 #endif
-#if H_3D_TMVP
+#if H_3D
   Bool        m_ivMvScalingFlag; 
 #endif
@@ -535,6 +681,16 @@
   Void    setMaxTLayers  (UInt t)             { m_uiMaxTLayers = t; }
   
+#if H_MV5
+#if H_MV    
+  UInt    getMaxLayersMinus1()                { return m_uiMaxLayersMinus1;  }; 
+  Void    setMaxLayersMinus1(UInt l)          { m_uiMaxLayersMinus1 = l; }
+#else
   UInt    getMaxLayers   ()                   { return m_uiMaxLayers;   }
   Void    setMaxLayers   (UInt l)             { m_uiMaxLayers = l; }
+#endif
+#else
+  UInt    getMaxLayers   ()                   { return m_uiMaxLayers;   }
+  Void    setMaxLayers   (UInt l)             { m_uiMaxLayers = l; }
+#endif
 
   Bool    getTemporalNestingFlag   ()         { return m_bTemporalIdNestingFlag;   }
@@ -579,12 +735,22 @@
   Bool    getAvcBaseLayerFlag()                                            { return m_avcBaseLayerFlag; } 
 
+#if H_MV5
+  Void    setVpsVuiOffset( Int  val )                                      { m_vpsVuiOffset = val; } 
+  Int     getVpsVuiOffset(  )                                              { return m_vpsVuiOffset; } 
+#endif
+
   Void    setSplittingFlag( Bool val )                                     { m_splittingFlag = val;  }
   Bool    getSplittingFlag()                                               { return m_splittingFlag; }
 
+#if H_MV5
+  Void    setScalabilityMaskFlag( UInt val );
+  Void    setScalabilityMaskFlag( Int scalType, Bool val )                     { m_scalabilityMaskFlag[scalType] = val;  }
+  Bool    getScalabilityMaskFlag( Int scalType )                               { return m_scalabilityMaskFlag[scalType]; }
+#else
   Void    setScalabilityMask( UInt val );
 
   Void    setScalabilityMask( Int scalType, Bool val )              { m_scalabilityMask[scalType] = val;  }
   Bool    getScalabilityMask( Int scalType )                        { return m_scalabilityMask[scalType]; }
-
+#endif
   Int     getNumScalabilityTypes( );
 
@@ -603,10 +769,24 @@
   Int     getDimensionId( Int layerIdInVps, Int scalIdx )                  { return m_dimensionId[layerIdInVps][scalIdx]; }
 
+#if H_MV5
+  Void    setViewIdLenMinus1( Int  val )                                   { m_viewIdLenMinus1 = val; } 
+  Int     getViewIdLenMinus1(  )                                           { return m_viewIdLenMinus1; } 
+
+  Void    setViewIdVal( Int viewOrderIndex, Int  val )                     { m_viewIdVal[viewOrderIndex] = val; } 
+  Int     getViewIdVal( Int viewOrderIndex )                               { return m_viewIdVal[viewOrderIndex]; } 
+#endif
   Void    setDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Bool val ) { m_directDependencyFlag[depLayeridInVps][refLayeridInVps] = val;  }
   Bool    getDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps )           { return m_directDependencyFlag[depLayeridInVps][refLayeridInVps]; }
 
+#if H_MV5
+  Void    setMaxTidRefPresentFlag( Bool flag )                             { m_maxTidRefPresentFlag = flag; } 
+  Bool    getMaxTidRefPresentFlag(  )                                      { return m_maxTidRefPresentFlag; } 
+#endif
   Void    setMaxTidIlRefPicPlus1( Int layerIdInVps, Int val )              { m_maxTidIlRefPicPlus1[ layerIdInVps ] = val;  } 
   Int     getMaxTidIlRefPicPlus1( Int layerIdInVps )                       { return m_maxTidIlRefPicPlus1[ layerIdInVps ]; } 
-  
+#if H_MV5
+  Void    setAllRefLayersActiveFlag( Bool flag )                           { m_allRefLayersActiveFlag = flag; } 
+  Bool    getAllRefLayersActiveFlag(  )                                    { return m_allRefLayersActiveFlag; } 
+#endif
   Void    setVpsNumberLayerSetsMinus1( Int val )                           { m_vpsNumberLayerSetsMinus1 = val;  } 
   Int     getVpsNumberLayerSetsMinus1( )                                   { return m_vpsNumberLayerSetsMinus1; } 
@@ -639,7 +819,23 @@
   Int     getProfileLevelTierIdx( Int outLayerSetIdx )                     { return m_profileLevelTierIdx[ outLayerSetIdx ]; } 
 
+#if H_MV5
+  Void    setRepFormatIdxPresentFlag( Bool flag )                          { m_repFormatIdxPresentFlag = flag; } 
+  Bool    getRepFormatIdxPresentFlag(  )                                   { return m_repFormatIdxPresentFlag; } 
+
+  Void    setVpsNumRepFormatsMinus1( Int  val )                            { m_vpsNumRepFormatsMinus1 = val; } 
+  Int     getVpsNumRepFormatsMinus1(  )                                    { return m_vpsNumRepFormatsMinus1; } 
+
+  Void    setVpsRepFormatIdx( Int i, Int  val )                            { m_vpsRepFormatIdx[i] = val; } 
+  Int     getVpsRepFormatIdx( Int i )                                      { return m_vpsRepFormatIdx[i]; } 
+
+  Void    setRepFormat( Int i, TComRepFormat* val )                        { m_repFormat[i] = val;  }
+  TComRepFormat* getRepFormat( Int i )                                     { return m_repFormat[i]; }
+#endif
   Void    setMaxOneActiveRefLayerFlag( Bool flag)                          { m_maxOneActiveRefLayerFlag = flag; } 
   Bool    getMaxOneActiveRefLayerFlag( )                                   { return m_maxOneActiveRefLayerFlag; } 
-
+#if H_MV5
+  Void    setCrossLayerIrapAlignedFlag( Bool flag )                        { m_crossLayerIrapAlignedFlag = flag; } 
+  Bool    getCrossLayerIrapAlignedFlag(  )                                 { return m_crossLayerIrapAlignedFlag; } 
+#endif
   Void    setDirectDepTypeLenMinus2( Int val)                              { m_directDepTypeLenMinus2 = val; } 
   Int     getDirectDepTypeLenMinus2( )                                     { return m_directDepTypeLenMinus2; } 
@@ -647,6 +843,10 @@
   Void    setDirectDependencyType( Int depLayeridInVps, Int refLayeridInVps, Int val) { m_directDependencyType[ depLayeridInVps ][ refLayeridInVps ] = val; } 
   Int     getDirectDependencyType( Int depLayeridInVps, Int refLayeridInVps)   { return m_directDependencyType[ depLayeridInVps ][ refLayeridInVps ]; } 
-
-
+#if H_MV5  
+  Void    setVpsVuiPresentFlag( Bool flag )                                { m_vpsVuiPresentFlag = flag; } 
+  Bool    getVpsVuiPresentFlag(  )                                         { return m_vpsVuiPresentFlag; } 
+
+  TComVPSVUI* getVPSVUI(  )                                                { return m_vpsVUI;  }
+#endif
   // VPS EXTENSION SEMANTICS VARIABLES
   Void    setLayerIdInVps( Int layerIdInNuh, Int val )                     { m_layerIdInVps[layerIdInNuh] = val;  }
@@ -654,8 +854,19 @@
 
   Int     getScalabilityId ( Int layerIdInVps, ScalabilityType scalType );
+#if H_MV5
+  Int     getViewId        ( Int layerIdInNuh )                            { return m_viewIdVal[ getViewIndex( getLayerIdInVps( layerIdInNuh) )]; }
+#else
   Int     getViewId  ( Int layerIdInVps )                                  { return getScalabilityId( layerIdInVps, VIEW_ID  ); }
 
+#endif
   Void    setRefLayers(); 
 
+#if H_MV5
+  Int     getViewIndex    ( Int layerIdInNuh )                             { return getScalabilityId( getLayerIdInVps(layerIdInNuh), VIEW_ORDER_INDEX  ); }    
+  Int     getNumViews();
+
+  Int     getNumDirectRefLayers( Int layerIdInNuh )                        { return m_numDirectRefLayers[ layerIdInNuh ];  };                               
+  Int     getRefLayerId        ( Int layerIdInNuh, Int idx );; 
+#else
   Int     getNumDirectRefLayers( Int layerIdInVps )          { return m_numDirectRefLayers[ layerIdInVps ];  };                               
   Int     getRefLayerId        ( Int layerIdInVps, Int idx );; 
@@ -668,9 +879,14 @@
   Bool    getMotionPredEnabledFlag ( Int layerIdInVps, Int idx ) { return m_motionPredEnabledFlag [layerIdInVps][idx]; } 
   Int     getMotionPredRefLayerId  ( Int layerIdInVps, Int idx ) { return m_motionPredRefLayerId  [layerIdInVps][idx]; } 
-
+#endif  
   Bool    checkVPSExtensionSyntax(); 
   Int     scalTypeToScalIdx   ( ScalabilityType scalType );
 
+  #if H_MV5
+Int     getProfileLevelTierIdxLen()                                      { return gCeilLog2( getVpsNumProfileTierLevelMinus1() + 1 ); };       
+#else
   Int     getProfileLevelTierIdxLen() { return xCeilLog2( getVpsNumProfileTierLevelMinus1() + 1 ); };       
+#endif
+
   Int     getNumLayersInIdList              ( Int lsIdx );; 
 
@@ -679,8 +895,17 @@
   Int     inferLastDimsionIdLenMinus1();
 
+#if H_MV5
+  // helpers
+  Bool    getInDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Int depth = 0 );
+#endif
+  /// VPS EXTENSION 2 SYNTAX ELEMENTS
 #if H_3D  
+#if H_MV5
+  Int     getDepthId      ( Int layerIdInNuh)                             { return getScalabilityId( getLayerIdInVps(layerIdInNuh), DEPTH_ID ); }
+#else
   Void    initViewIndex(); 
   Int     getViewIndex    ( Int layerIdInVps )                             { return m_viewIndex[ layerIdInVps ]; }    
   Int     getDepthId      ( Int layerIdInVps )                             { return getScalabilityId( layerIdInVps, DEPTH_ID ); }
+#endif
   Int     getLayerIdInNuh( Int viewIndex, Bool depthFlag );   
 
@@ -716,8 +941,6 @@
 #endif
 
-#if H_3D_TMVP
   Bool    getIvMvScalingFlag   (  )                       { return m_ivMvScalingFlag; }
   Void    setIvMvScalingFlag   ( Bool b )                 { m_ivMvScalingFlag = b;    }  
-#endif
 #if LGE_INTER_SDC_E0156
   Bool    getInterSDCFlag      ( Int layerIdInVps )           { return m_bInterSDCFlag[layerIdInVps]; }
@@ -737,4 +960,9 @@
   Int           m_winTopOffset;
   Int           m_winBottomOffset;
+#if H_MV5
+#if H_MV
+  Bool          m_scaledFlag; 
+#endif
+#endif
 public:
   Window()
@@ -744,4 +972,9 @@
   , m_winTopOffset      (0)
   , m_winBottomOffset   (0)
+#if H_MV5
+#if H_MV
+  , m_scaledFlag(true)
+#endif
+#endif
   { }
 
@@ -757,4 +990,21 @@
   Void          setWindowBottomOffset(Int val)    { m_winBottomOffset = val; m_enabledFlag = true; }
 
+#if H_MV5
+#if H_MV
+  Void          setScaledFlag(Bool flag)          { m_scaledFlag = flag;  } 
+  Bool          getScaledFlag() const             { return m_scaledFlag;  } 
+  Void          scaleOffsets( Int scal )          
+  {
+    if (! m_scaledFlag )
+    {
+      m_scaledFlag         = true; 
+      m_winLeftOffset     *= scal; 
+      m_winRightOffset    *= scal; 
+      m_winTopOffset      *= scal; 
+      m_winBottomOffset   *= scal; 
+    }
+  }
+#endif
+#endif
   Void          setWindow(Int offsetLeft, Int offsetLRight, Int offsetLTop, Int offsetLBottom)
   {
@@ -804,6 +1054,8 @@
   TComHRD m_hrdParameters;
   TimingInfo m_timingInfo;
+#if !H_MV5
 #if H_MV
   Bool m_tileBoundariesAlignedFlag;
+#endif
 #endif
 
@@ -839,6 +1091,8 @@
     ,m_log2MaxMvLengthHorizontal(15)
     ,m_log2MaxMvLengthVertical(15)
+#if !H_MV5
 #if H_MV
     ,m_tileBoundariesAlignedFlag(true)
+#endif
 #endif
   {}
@@ -937,8 +1191,11 @@
   TComHRD* getHrdParameters                 ()             { return &m_hrdParameters; }
   TimingInfo* getTimingInfo() { return &m_timingInfo; }
+#if !H_MV5
 #if H_MV
 Bool getTileBoundariesAlignedFlag(  ) { return m_tileBoundariesAlignedFlag; } 
   Void setTileBoundariesAlignedFlag( Bool flag ) { m_tileBoundariesAlignedFlag = flag; } 
 #endif
+#endif
+
 };
 
@@ -1024,9 +1281,19 @@
   TComPTL     m_pcPTL;
 #if H_MV
+#if H_MV5
+  TComVPS*    m_pcVPS; 
+  // SPS 
+  Bool        m_spsInferScalingListFlag;
+  Int         m_spsScalingListRefLayerId;
+  Bool        m_updateRepFormatFlag;
+#endif
+  // SPS Extension 
   Bool        m_interViewMvVertConstraintFlag;
+#if !H_MV5
   Int         m_numIlpRestrictedRefLayers        ;
   Int         m_minSpatialSegmentOffsetPlus1[MAX_NUM_LAYERS];
   Bool        m_ctuBasedOffsetEnabledFlag   [MAX_NUM_LAYERS];
   Int         m_minHorizontalCtuOffsetPlus1 [MAX_NUM_LAYERS];
+#endif
 #endif
 #if H_3D
@@ -1165,8 +1432,26 @@
   TComPTL* getPTL()     { return &m_pcPTL; }
 #if H_MV
+#if H_MV5
+  Void      setVPS          ( TComVPS* pcVPS ) { m_pcVPS = pcVPS; }
+  TComVPS*  getVPS          () { return m_pcVPS; }
+
+  Void setSpsInferScalingListFlag( Bool flag ) { m_spsInferScalingListFlag = flag; } 
+  Bool getSpsInferScalingListFlag(  )          { return m_spsInferScalingListFlag; } 
+
+  Void setSpsScalingListRefLayerId( Int  val ) { m_spsScalingListRefLayerId = val; } 
+  Int  getSpsScalingListRefLayerId(  )         { return m_spsScalingListRefLayerId; } 
+
+  Void setUpdateRepFormatFlag( Bool flag )     { m_updateRepFormatFlag = flag; } 
+  Bool getUpdateRepFormatFlag(  )              { return m_updateRepFormatFlag; } 
+#endif
+  // SPS Extension 
   Void setInterViewMvVertConstraintFlag(Bool val) { m_interViewMvVertConstraintFlag = val; }
   Bool getInterViewMvVertConstraintFlag()         { return m_interViewMvVertConstraintFlag;}
-
-  ////  sps_extension_vui_parameters( )
+#if H_MV5
+  // Inference 
+  Void inferRepFormat( TComVPS* vps, Int layerIdCurr );
+
+  Void inferScalingList( TComSPS* spsSrc );
+#else
   Void setNumIlpRestrictedRefLayers   ( Int val )        { m_numIlpRestrictedRefLayers         = val;}
   Int  getNumIlpRestrictedRefLayers   ( )                { return m_numIlpRestrictedRefLayers        ;}
@@ -1180,4 +1465,6 @@
   Void setMinHorizontalCtuOffsetPlus1 ( Int i, Int val )   { m_minHorizontalCtuOffsetPlus1 [ i ] = val;}
   Int  getMinHorizontalCtuOffsetPlus1 ( Int i )            { return m_minHorizontalCtuOffsetPlus1 [ i ];}
+
+#endif
 #endif
 #if H_3D_QTLPC
@@ -1295,4 +1582,11 @@
   Int m_numExtraSliceHeaderBits;
 
+#if H_MV5
+#if H_MV
+  Int  m_layerId; 
+  Bool m_ppsInferScalingListFlag;
+  Int  m_ppsScalingListRefLayerId;
+#endif
+#endif
 public:
   TComPPS();
@@ -1416,4 +1710,16 @@
   Bool getSliceHeaderExtensionPresentFlag   ()                    { return m_sliceHeaderExtensionPresentFlag; }
   Void setSliceHeaderExtensionPresentFlag   (Bool val)            { m_sliceHeaderExtensionPresentFlag = val; }
+#if H_MV5
+#if H_MV
+  Void setLayerId( Int  val ) { m_layerId = val; } 
+  Int  getLayerId(  ) { return m_layerId; } 
+
+  Void setPpsInferScalingListFlag( Bool flag ) { m_ppsInferScalingListFlag = flag; } 
+  Bool getPpsInferScalingListFlag(  ) { return m_ppsInferScalingListFlag; } 
+
+  Void setPpsScalingListRefLayerId( Int  val ) { m_ppsScalingListRefLayerId = val; } 
+  Int  getPpsScalingListRefLayerId(  ) { return m_ppsScalingListRefLayerId; } 
+#endif
+#endif
 };
 
@@ -1448,4 +1754,9 @@
   Bool        m_PicOutputFlag;        ///< pic_output_flag 
   Int         m_iPOC;
+#if H_MV5
+#if H_MV
+  Int         m_iPOCBeforeReset; 
+#endif
+#endif
   Int         m_iLastIDR;
   static Int  m_prevPOC;
@@ -1542,4 +1853,14 @@
   Bool       m_enableTMVPFlag;
 #if H_MV
+#if H_MV5
+  std::vector<TComPic*>* m_refPicSetInterLayer0; 
+  std::vector<TComPic*>* m_refPicSetInterLayer1; 
+  Int        m_layerId; 
+  Int        m_viewId;
+  Int        m_viewIndex; 
+#if H_3D
+  Bool       m_isDepth;
+#endif
+#else
   std::vector<TComPic*>* m_refPicSetInterLayer; 
   Int        m_layerId; 
@@ -1549,10 +1870,15 @@
   Bool       m_isDepth;
 #endif
+#endif
 
 // Additional slice header syntax elements 
+#if H_MV5
+  Bool       m_pocResetFlag; 
+#endif
   Bool       m_discardableFlag;
   Bool       m_interLayerPredEnabledFlag;
   Int        m_numInterLayerRefPicsMinus1;
   Int        m_interLayerPredLayerIdc       [MAX_NUM_LAYERS];
+#if !H_MV5
   Bool       m_interLayerSamplePredOnlyFlag;
   Bool       m_altCollocatedIndicationFlag;
@@ -1562,4 +1888,5 @@
   Int        m_activeMotionPredRefLayerId   [ MAX_NUM_LAYER_IDS ];
 
+#endif
   Int        m_aaiCodedScale [2][MAX_NUM_LAYERS];
   Int        m_aaiCodedOffset[2][MAX_NUM_LAYERS];
@@ -1640,5 +1967,5 @@
   TComPic*  getIvPic            ( Bool depthFlag, Int viewIndex){ return  m_ivPicsCurrPoc[ depthFlag ? 1 : 0 ][ viewIndex ]; }
 #endif
-#if H_3D_IV_MERGE
+#if H_3D
   TComPic*  getTexturePic       ()                              { return  m_ivPicsCurrPoc[0][ m_viewIndex ]; }
 #endif
@@ -1695,9 +2022,18 @@
   
 #if H_MV
+#if H_MV5
+  Void      setPocBeforeReset   ( Int i )                       { m_iPOCBeforeReset = i; }
+  Int       getPocBeforeReset   ( )                             { return m_iPOCBeforeReset; }
+#endif
   Int       getRefLayerId        ( RefPicList e, Int iRefIdx)    { return  m_aiRefLayerIdList[e][iRefIdx]; }
   Void      setRefLayerId        ( Int i, RefPicList e, Int iRefIdx ) { m_aiRefLayerIdList[e][iRefIdx] = i; }
-#endif
-#if H_MV
+#if H_MV5
+  Void      getTempRefPicLists   ( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1,                                     
+                                   std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int& numPocTotalCurr, Bool checkNumPocTotalCurr = false );
+
+  Void      setRefPicList        ( std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int numPocTotalCurr, Bool checkNumPocTotalCurr = false ); 
+#else
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& interLayerRefPicSet , Bool checkNumPocTotalCurr = false );
+#endif
 #else
 #if FIX1071
@@ -1748,9 +2084,18 @@
   Void applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *RPSList);
 #if H_MV
+#if !H_MV5
   Void createAndApplyIvReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer );
   static Void markIvRefPicsAsShortTerm    ( std::vector<TComPic*> refPicSetInterLayer );
+#else
+  Void createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 );
+  static Void markIvRefPicsAsShortTerm    ( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 );
+#endif
   static Void markCurrPic                 ( TComPic* currPic );; 
   static Void markIvRefPicsAsUnused       ( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc  );
+#if H_MV5
+  Void        printRefPicList();
+#else
   Void        xPrintRefPicList();
+#endif
 #endif
   Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
@@ -1839,4 +2184,8 @@
   Void      setViewId             ( Int viewId )     { m_viewId = viewId;   }
   Int       getViewId             ()                 { return m_viewId;     }
+#if H_MV5
+  Void      setViewIndex          ( Int viewIndex )  { m_viewIndex = viewIndex;   }
+  Int       getViewIndex          ()                 { return m_viewIndex;     }
+#endif
 #if H_3D
 #if H_3D_TMVP
@@ -1845,6 +2194,8 @@
   Int       getAlterRefIdx          ( RefPicList e )        { return  m_aiAlterRefIdx[e];     }
 #endif
+#if !H_MV5
   Void      setViewIndex          ( Int viewIndex )  { m_viewIndex = viewIndex;   }
   Int       getViewIndex          ()                 { return m_viewIndex;     }
+#endif
   Void      setIsDepth            ( Bool isDepth )   { m_isDepth = isDepth; }
   Bool      getIsDepth            ()                 { return m_isDepth; }
@@ -1867,4 +2218,10 @@
 #if H_MV
 // Additional slice header syntax elements
+
+#if H_MV5
+  Void setPocResetFlag( Bool flag ) { m_pocResetFlag = flag; } 
+  Bool getPocResetFlag(  ) { return m_pocResetFlag; } 
+#endif
+
 Void setDiscardableFlag( Bool flag ) { m_discardableFlag = flag; } 
 Bool getDiscardableFlag(  ) { return m_discardableFlag; } 
@@ -1879,4 +2236,19 @@
 Int  getInterLayerPredLayerIdc( Int i ) { return m_interLayerPredLayerIdc[i]; } 
 
+#if H_MV5 
+  // Additional variables derived in slice header semantics 
+  Int  getNumInterLayerRefPicsMinus1Len( ) { return gCeilLog2(  getVPS()->getNumDirectRefLayers( getLayerId() )); }
+  Int  getInterLayerPredLayerIdcLen    ( ) { return gCeilLog2(  getVPS()->getNumDirectRefLayers( getLayerId() )); }
+
+  Int  getNumActiveRefLayerPics( );
+
+  Int  getNumActiveRefLayerPics0( )        { return (Int) m_refPicSetInterLayer0->size();  };
+  Int  getNumActiveRefLayerPics1( )        { return (Int) m_refPicSetInterLayer1->size();  };
+
+  Int  getRefPicLayerId               ( Int i );
+
+  Void     setRefPicSetInterLayer       ( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1);
+  TComPic* getPicFromRefPicSetInterLayer( Int setIdc, Int layerId );
+#else
 Void setInterLayerSamplePredOnlyFlag( Bool flag ) { m_interLayerSamplePredOnlyFlag = flag; } 
 Bool getInterLayerSamplePredOnlyFlag(  ) { return m_interLayerSamplePredOnlyFlag; } 
@@ -1905,4 +2277,5 @@
 TComPic* getPicFromRefPicSetInterLayer( Int layerId );
 
+#endif
 #endif
 protected:
@@ -1911,5 +2284,7 @@
 TComPic*  xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb);
 #if H_MV
+#if !H_MV5
   Int       xCeilLog2( Int val );
+#endif
   TComPic*  xGetInterLayerRefPic( std::vector<TComPic*>& rcListIlPic, Int layerId );  
 #endif
@@ -1993,4 +2368,5 @@
   //! activate a SPS from a active parameter sets SEI message
   //! \returns true, if activation is successful
+#if !H_MV5
   Bool activateSPSWithSEI(Int SPSId);
 
@@ -2012,4 +2388,43 @@
   Int m_activeSPSId;
   Int m_activePPSId;
+#else
+#if H_MV
+  Bool activateSPSWithSEI(Int SPSId, Int layerId );
+#else
+  Bool activateSPSWithSEI(Int SPSId);
+#endif
+
+  //! activate a PPS and depending on isIDR parameter also SPS and VPS
+  //! \returns true, if activation is successful
+#if H_MV
+  Bool activatePPS(Int ppsId, Bool isIRAP, Int layerId );
+#else
+  Bool activatePPS(Int ppsId, Bool isIRAP);
+#endif
+
+  TComVPS* getActiveVPS(){ return m_vpsMap.getPS(m_activeVPSId); };
+#if H_MV
+  TComSPS* getActiveSPS( Int layerId ){ return m_spsMap.getPS( m_activeSPSId[ layerId ] ); };
+  TComPPS* getActivePPS( Int layerId ){ return m_ppsMap.getPS( m_activePPSId[ layerId ] ); };
+#else
+  TComSPS* getActiveSPS(){ return m_spsMap.getPS(m_activeSPSId); };
+  TComPPS* getActivePPS(){ return m_ppsMap.getPS(m_activePPSId); };
+#endif
+protected:
+  
+  ParameterSetMap<TComVPS> m_vpsMap;
+  ParameterSetMap<TComSPS> m_spsMap; 
+  ParameterSetMap<TComPPS> m_ppsMap;
+
+  Int m_activeVPSId;
+#if H_MV
+  Int m_activeSPSId[ MAX_NUM_LAYERS ];
+  Int m_activePPSId[ MAX_NUM_LAYERS ];
+#else
+  Int m_activeSPSId;
+  Int m_activePPSId;
+#endif
+
+#endif
 };
 
Index: trunk/source/Lib/TLibCommon/TComWedgelet.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComWedgelet.cpp	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComWedgelet.cpp	(revision 622)
@@ -175,4 +175,5 @@
 }
 
+#if !SEC_DMM2_E0146_HHIFIX
 Bool TComWedgelet::checkPredDirAbovePossible( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset )
 {
@@ -642,4 +643,5 @@
   }
 }
+#endif
 
 Void TComWedgelet::xGenerateWedgePattern()
Index: trunk/source/Lib/TLibCommon/TComWedgelet.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComWedgelet.h	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComWedgelet.h	(revision 622)
@@ -50,5 +50,5 @@
 enum DIM_IDX
 {
-#if SEC_DMM2_E0146
+#if SEC_DMM2_E0146_HHIFIX
   DMM1_IDX = 0,
   DMM3_IDX = 1,
@@ -63,5 +63,5 @@
 #endif
 };
-#if SEC_DMM2_E0146
+#if SEC_DMM2_E0146_HHIFIX
 #define DMM_NUM_TYPE   3
 #else
@@ -86,5 +86,5 @@
 #define DMM_NO_WEDGEINDEX       MAX_UINT
 #define DMM_NUM_WEDGE_REFINES   8
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
 #define DMM2_DELTAEND_MAX       4
 #endif
@@ -151,4 +151,5 @@
   Bool  checkInvIdentical( Bool* pbRefPattern );
 
+#if !SEC_DMM2_E0146_HHIFIX
   // functions for DMM2 prediction
   Bool  checkPredDirAbovePossible( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffsett );
@@ -156,4 +157,5 @@
   Void  getPredDirStartEndAbove( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd );
   Void  getPredDirStartEndLeft ( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd );
+#endif
 };  // END CLASS DEFINITION TComWedgelet
 
Index: trunk/source/Lib/TLibCommon/TComYuv.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComYuv.cpp	(revision 609)
+++ trunk/source/Lib/TLibCommon/TComYuv.cpp	(revision 622)
@@ -110,4 +110,16 @@
   {
     ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth);
+
+#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
+    if ( g_traceCopyBack && g_nSymbolCounter >= g_stopAtCounter )
+    { 
+      for ( Int x = 0; x < iWidth; x++)
+      {      
+        std::cout << pSrc[ x ] << " " ; 
+      }
+      std::cout << std::endl;
+    }
+#endif
+
     pDst += iDstStride;
     pSrc += iSrcStride;
Index: trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/TypeDef.h	(revision 609)
+++ trunk/source/Lib/TLibCommon/TypeDef.h	(revision 622)
@@ -92,4 +92,5 @@
                                               // QC_CU_NBDV_D0181
                                               // SEC_DEFAULT_DV_D0112
+                                              // MTK_DVMCP_FIX_E0172               1 // fix the mismatch between software and WD for DV derivation from DVMCP blocks, issue 2 in JCT3V-E0172
 #define H_3D_ARP                          1   // Advanced residual prediction (ARP), JCT3V-D0177
 #define H_3D_IC                           1   // Illumination Compensation, JCT3V-B0045, JCT3V-C0046, JCT3V-D0060
@@ -110,5 +111,5 @@
                                               // QC_D0191: Clean up
                                               // LG_D0092: Multiple VSP candidate allowed
-
+                                              // MTK_VSP_FIX_ALIGN_WD_E0172
 #define H_3D_IV_MERGE                     1   // Inter-view motion merge candidate
                                               // HHI_INTER_VIEW_MOTION_PRED 
@@ -119,4 +120,5 @@
                                               // QC_AMVP_MRG_UNIFY_IVCAN_C0051     
                                               // TEXTURE MERGING CANDIDATE     , JCT3V-C0137
+                                              // QC_INRIA_MTK_MRG_E0126            
 #define H_3D_TMVP                         1   // QC_TMVP_C0047 
                                               // Sony_M23639
@@ -161,10 +163,4 @@
 #define MTK_DIVMC_FIX_E0172               1 // fix the issue of derivation of disparity inter-view merge candidate, issue 5 in JCT3V-E0172
 #define MTK_NBDV_TN_FIX_E0172             1 // fix the issue of DV derivation from the temporal neighboring blocks, issue 7 in JCT3V-E0172
-#define MTK_DVMCP_FIX_E0172               1 // fix the mismatch between software and WD for DV derivation from DVMCP blocks, issue 2 in JCT3V-E0172
-#define MTK_VSP_FIX_ALIGN_WD_E0172        1 // fix the issues related to VSP merge candidate, issue 3, 4 in JCT3V-E0172, using an implementation aligned with WD
-
-#if !MTK_VSP_FIX_ALIGN_WD_E0172
-#define MTK_VSP_FIX_E0172                 1 // fix the issues related to VSP merge candidate, issue 3, 4 in JCT3V-E0172
-#endif
 #endif // MTK_RVS_BUGFIX_E0172
 
@@ -175,14 +171,10 @@
 #endif // H_3D_NBDV
 
-#if H_3D_IV_MERGE
-#define QC_INRIA_MTK_MRG_E0126            1   // additional merge candidates JCT3V-E0126
-#endif
-
 #if H_3D_DIM
-#define SEC_DMM2_E0146                    1   // Removal of DMM2 from DMMs
+#define SEC_DMM2_E0146_HHIFIX             1   // Removal of DMM2 from DMMs
 #define ZJU_DEPTH_INTRA_MODE_E0204        1   // Simplified Binarization for depth_intra_mode
 #define KWU_SDC_SIMPLE_DC_E0117           1   // Simplified DC calculation for SDC
 #define SCU_HS_DMM4_REMOVE_DIV_E0242      1   // DMM4 Division Removal
-#define SCU_HS_FAST_DEPTH_INTRA_E0238     1   // Fast DMM and RBC Mode Selection
+#define SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX     1   // Fast DMM and RBC Mode Selection
 #endif
 
@@ -215,6 +207,9 @@
 
 
-
-
+/// FIXES
+#if H_MV
+#define H_MV_FIX_LID_PIC_HASH_SEI_T40                      1   // Fix wrong layer_id in decoded picture hash SEI 
+#define H_MV5                                              1   // Update to MV-HEVC 5 HLS
+#endif
 /////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////   DERIVED DEFINES ///////////////////////////////////  
@@ -265,5 +260,5 @@
 #endif
 #if H_3D_DIM_DMM
-#define LGE_PKU_DMM3_OVERLAP_E0159        1   // Removal of overlap between DMM3 and DMM1
+#define LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX 1   // Removal of overlap between DMM3 and DMM1
 #endif
 #endif
@@ -271,5 +266,4 @@
 ///// ***** VIEW SYNTHESIS PREDICTION *********
 #if H_3D_VSP
-#define H_3D_VSP_POSITION                 3   // The only supported position
 #define H_3D_VSP_BLOCKSIZE                4   // Supported values: 1, 2, and 4
 #if H_3D_VSP_BLOCKSIZE == 1
@@ -799,8 +793,15 @@
   enum ScalabilityType
   {
+#if H_MV5
+#if H_3D
+    DEPTH_ID = 0,    
+#endif    
+    VIEW_ORDER_INDEX  = 1,
+#else
     VIEW_ID  = 0,
 #if H_3D
     DEPTH_ID = 1,    
 #endif    
+#endif
   };
 #endif
Index: trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp	(revision 609)
+++ trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp	(revision 622)
@@ -50,5 +50,5 @@
   xReadCode (length, rValue);
 #if H_MV_ENC_DEC_TRAC
-  if ( g_disableHLSTrace )
+  if ( g_disableHLSTrace || !g_HLSTraceEnable )
   {
     return; 
@@ -71,5 +71,5 @@
   xReadUvlc (rValue);
 #if H_MV_ENC_DEC_TRAC
-  if ( g_disableHLSTrace )
+  if ( g_disableHLSTrace  || !g_HLSTraceEnable )
   {
     return; 
@@ -85,5 +85,5 @@
   xReadSvlc(rValue);
 #if H_MV_ENC_DEC_TRAC
-  if ( g_disableHLSTrace )
+  if ( g_disableHLSTrace  || !g_HLSTraceEnable  )
   {
     return; 
@@ -99,5 +99,5 @@
   xReadFlag(rValue);
 #if H_MV_ENC_DEC_TRAC
-  if ( g_disableHLSTrace )
+  if ( g_disableHLSTrace  || !g_HLSTraceEnable )
   {
     return; 
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 609)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 622)
@@ -330,4 +330,19 @@
     }
   }
+#if H_MV5
+#if H_MV
+  if ( pcPPS->getLayerId() > 0 )
+  {
+    READ_FLAG( uiCode, "pps_infer_scaling_list_flag" ); pcPPS->setPpsInferScalingListFlag( uiCode == 1 );    
+  }
+
+  if( pcPPS->getPpsInferScalingListFlag( ) ) 
+  {
+    READ_CODE( 6, uiCode, "pps_scaling_list_ref_layer_id" ); pcPPS->setPpsScalingListRefLayerId( uiCode );
+  }
+  else
+  {  
+#endif
+#endif
   READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
   if(pcPPS->getScalingListPresentFlag ())
@@ -335,4 +350,9 @@
     parseScalingList( pcPPS->getScalingList() );
   }
+#if H_MV5
+#if H_MV
+  }
+#endif
+#endif
 
   READ_FLAG( uiCode, "lists_modification_present_flag");
@@ -410,8 +430,23 @@
   {
     Window &defDisp = pcVUI->getDefaultDisplayWindow();
+#if !H_MV5
     READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
     READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
     READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
     READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
+#else
+#if H_MV
+    defDisp.setScaledFlag( false ); 
+    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode );
+    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode );
+    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode );
+    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode );
+#else
+    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
+    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
+    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
+    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
+#endif
+#endif
   }
   TimingInfo *timingInfo = pcVUI->getTimingInfo();
@@ -436,4 +471,5 @@
   {
     READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
+#if !H_MV5
 #if H_MV
     if ( pcSPS->getLayerId() > 0 )
@@ -441,4 +477,5 @@
       READ_FLAG( uiCode, "tile_boundaries_aligned_flag" ); pcVUI->setTileBoundariesAlignedFlag( uiCode == 1 );
     }
+#endif
 #endif
     READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
@@ -560,5 +597,15 @@
   READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
   assert(uiCode <= 15);
+#if H_MV5
+#if H_MV
+  if ( pcSPS->getLayerId() > 0 )
+  {
+    READ_FLAG( uiCode, "update_rep_format_flag" );               pcSPS->setUpdateRepFormatFlag( uiCode == 1 );
+  }
   
+  if ( pcSPS->getUpdateRepFormatFlag() )
+  { 
+#endif
+#endif
   READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
   assert(uiCode <= 3);
@@ -572,14 +619,41 @@
   READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
   READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
+#if H_MV5
+#if H_MV
+  }
+#endif
+#endif
   READ_FLAG(     uiCode, "conformance_window_flag");
   if (uiCode != 0)
   {
     Window &conf = pcSPS->getConformanceWindow();
+#if H_MV5
+#if H_MV
+    // Needs to be scaled later, when ChromaFormatIdc is known. 
+    conf.setScaledFlag( false ); 
+    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode  );
+    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode  );
+    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode  );
+    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode  );    
+#else
     READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
     READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
     READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
     READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
-  }
-
+#endif
+#else
+    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
+    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
+    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
+    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
+#endif
+  }
+
+#if H_MV5
+#if H_MV
+  if ( pcSPS->getUpdateRepFormatFlag() )
+  { 
+#endif
+#endif
   READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
   assert(uiCode <= 6);
@@ -591,4 +665,9 @@
   pcSPS->setBitDepthC( uiCode + 8 );
   pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
+#if H_MV5
+#if H_MV
+  }
+#endif
+#endif
 
   READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
@@ -613,7 +692,11 @@
     pcSPS->setNumReorderPics(uiCode, i);
 #if H_MV
+#if H_MV5
+    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
+#else
     READ_UVLC ( uiCode, "sps_max_latency_increase[i]");
+#endif
 #else
-    READ_UVLC ( uiCode, "sps_max_latency_increase");
+    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1");
 #endif
     pcSPS->setMaxLatencyIncrease( uiCode, i );
@@ -653,4 +736,19 @@
   if(pcSPS->getScalingListFlag())
   {
+#if H_MV5
+#if H_MV
+    if ( pcSPS->getLayerId() > 0 )
+    {    
+      READ_FLAG( uiCode, "sps_infer_scaling_list_flag" ); pcSPS->setSpsInferScalingListFlag( uiCode == 1 );
+    }
+
+    if ( pcSPS->getSpsInferScalingListFlag() )
+    {
+      READ_CODE( 6, uiCode, "sps_scaling_list_ref_layer_id" ); pcSPS->setSpsScalingListRefLayerId( uiCode );
+    }
+    else
+    {    
+#endif
+#endif
     READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
     if(pcSPS->getScalingListPresentFlag ())
@@ -658,4 +756,9 @@
       parseScalingList( pcSPS->getScalingList() );
     }
+#if H_MV5
+#if H_MV
+    }
+#endif
+#endif
   }
   READ_FLAG( uiCode, "amp_enabled_flag" );                          pcSPS->setUseAMP( uiCode );
@@ -711,4 +814,5 @@
   if (uiCode)
   {
+#if !H_MV5
 #if !H_MV
     while ( xMoreRbspData() )
@@ -789,4 +893,75 @@
   }
 }
+#else 
+#if H_MV
+    parseSPSExtension( pcSPS ); 
+    READ_FLAG( uiCode, "sps_extension2_flag");
+    if ( uiCode )
+    {
+#if H_3D
+      parseSPSExtension2( pcSPS, viewIndex, depthFlag ); 
+      READ_FLAG( uiCode, "sps_extension3_flag");
+      if ( uiCode )
+      {
+#endif
+#endif
+        while ( xMoreRbspData() )
+        {
+          READ_FLAG( uiCode, "sps_extension_data_flag");
+        }
+#if H_MV      
+#if H_3D
+      }
+#endif
+    }
+#endif
+  }
+}
+#endif
+#if H_MV5
+Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
+{
+  UInt uiCode; 
+  READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false);
+  READ_UVLC( uiCode, "sps_shvc_reserved_zero_idc" ); 
+}
+
+#if H_3D
+Void TDecCavlc::parseSPSExtension2( TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
+{ 
+  UInt uiCode; 
+#if H_3D_QTLPC
+  //GT: This has to go to VPS
+  if( depthFlag )
+  {
+    READ_FLAG( uiCode, "use_qtl_flag" );
+    pcSPS->setUseQTL( uiCode );
+    READ_FLAG( uiCode, "use_pc_flag" );
+    pcSPS->setUsePC( uiCode );
+  }
+#endif
+
+  UInt uiCamParPrecision = 0; 
+  Bool bCamParSlice      = false; 
+  if ( !depthFlag )
+  {      
+    READ_UVLC( uiCamParPrecision, "cp_precision" );
+    READ_FLAG( uiCode, "cp_in_slice_header_flag" );    bCamParSlice = ( uiCode == 1 );
+    if( !bCamParSlice )
+    {       
+      for( UInt uiBaseIndex = 0; uiBaseIndex < viewIndex; uiBaseIndex++ )
+      {
+        Int iCode; 
+        READ_SVLC( iCode, "cp_scale" );                m_aaiTempScale  [ uiBaseIndex ][ viewIndex ]   = iCode;
+        READ_SVLC( iCode, "cp_off" );                  m_aaiTempOffset [ uiBaseIndex ][ viewIndex ]   = iCode;
+        READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); m_aaiTempScale  [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ viewIndex ];
+        READ_SVLC( iCode, "cp_inv_off_plus_off" );     m_aaiTempOffset [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ viewIndex ];
+      }
+    }
+  }
+  pcSPS->initCamParaSPS( viewIndex, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset ); 
+}
+#endif
+#endif
 
 Void TDecCavlc::parseVPS(TComVPS* pcVPS)
@@ -797,5 +972,9 @@
   READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
 #if H_MV
+#if H_MV5
+  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayersMinus1( uiCode  );
+#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);
@@ -882,4 +1061,5 @@
   if (uiCode)
   {
+#if !H_MV5
 #if H_MV
     m_pcBitstream->readOutTrailingBits();
@@ -1099,4 +1279,375 @@
   return;
 }
+#else
+#if H_MV
+    m_pcBitstream->readOutTrailingBits();
+    parseVPSExtension( pcVPS );   
+    READ_FLAG( uiCode,  "vps_extension2_flag" );
+    if (uiCode)
+    {
+#if H_3D
+      m_pcBitstream->readOutTrailingBits();
+      parseVPSExtension2( pcVPS );   
+      READ_FLAG( uiCode,  "vps_extension3_flag" );
+      if (uiCode)
+      {      
+#endif
+#endif  
+        while ( xMoreRbspData() )
+        {
+          READ_FLAG( uiCode, "vps_extension_data_flag");
+        }
+#if H_MV
+#if H_3D
+      }
+#endif
+    }
+#endif
+  }
+}
+#endif
+
+#if H_MV5
+#if H_MV
+Void TDecCavlc::parseVPSExtension( TComVPS* pcVPS )
+{
+  UInt uiCode; 
+  READ_FLAG( uiCode, "avc_base_layer_flag" );                     pcVPS->setAvcBaseLayerFlag( uiCode == 1 ? true : false );
+  READ_CODE( 16, uiCode, "vps_vui_offset" );                      pcVPS->setVpsVuiOffset( uiCode );
+  READ_FLAG( uiCode, "splitting_flag" );                          pcVPS->setSplittingFlag( uiCode == 1 ? true : false );
+
+  for( Int sIdx = 0; sIdx < MAX_NUM_SCALABILITY_TYPES; sIdx++ )
+  {
+    READ_FLAG( uiCode,  "scalability_mask_flag[i]" );             pcVPS->setScalabilityMaskFlag( sIdx, uiCode == 1 ? true : false );      
+  }
+
+  for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
+  {
+    READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" );       pcVPS->setDimensionIdLen( sIdx, uiCode + 1 );
+  }
+
+  if ( pcVPS->getSplittingFlag() )
+  {
+    pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1, pcVPS->inferLastDimsionIdLenMinus1() );       
+  }
+
+  READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" );           pcVPS->setVpsNuhLayerIdPresentFlag( uiCode == 1 ? true : false );
+
+  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    if ( pcVPS->getVpsNuhLayerIdPresentFlag() )
+    {
+      READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" );                pcVPS->setLayerIdInNuh( i, uiCode );
+    }
+    else
+    {
+      pcVPS->setLayerIdInNuh( i, i );; 
+    }
+
+    pcVPS->setLayerIdInVps( pcVPS->getLayerIdInNuh( i ), i ); 
+
+    for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ ) 
+    {
+      if ( !pcVPS->getSplittingFlag() )
+      {
+        READ_CODE( pcVPS->getDimensionIdLen( j ), uiCode, "dimension_id[i][j]" );  pcVPS->setDimensionId( i, j, uiCode );
+      }
+      else
+      {
+        pcVPS->setDimensionId( i, j, pcVPS->inferDimensionId( i, j)  );
+      }
+    }
+  }
+
+  // GT spec says: trac #39
+  // if ( pcVPS->getNumViews() > 1 )  
+  //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val. 
+  {
+    READ_CODE( 4, uiCode, "view_id_len_minus1" ); pcVPS->setViewIdLenMinus1( uiCode );
+  }
+
+  for( Int i = 0; i < pcVPS->getNumViews(); i++ )
+  {
+    READ_CODE( pcVPS->getViewIdLenMinus1( ) + 1, uiCode, "view_id_val[i]" ); pcVPS->setViewIdVal( i, uiCode );
+  }
+
+  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    for( Int j = 0; j < i; j++ )
+    {
+      READ_FLAG( uiCode, "direct_dependency_flag[i][j]" );             pcVPS->setDirectDependencyFlag( i, j, uiCode );
+    }
+  }
+
+  READ_FLAG( uiCode, "max_tid_ref_present_flag" ); pcVPS->setMaxTidRefPresentFlag( uiCode == 1 );
+
+  if ( pcVPS->getMaxTidRefPresentFlag() )
+  {    
+    for( Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      READ_CODE( 3, uiCode,       "max_tid_il_ref_pics_plus1[i]" );      pcVPS->setMaxTidIlRefPicPlus1( i , uiCode ); 
+    }
+  }
+
+  READ_FLAG( uiCode, "all_ref_layers_active_flag" );             pcVPS->setAllRefLayersActiveFlag( uiCode == 1 );
+  READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1"      );  pcVPS->setVpsNumberLayerSetsMinus1    ( uiCode ); 
+  READ_CODE( 6,  uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode );
+
+  for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
+  {
+    READ_FLAG(  uiCode, "vps_profile_present_flag[i]" );    pcVPS->setVpsProfilePresentFlag( i, uiCode == 1 );
+    if( !pcVPS->getVpsProfilePresentFlag( i ) )
+    {
+      READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); pcVPS->setProfileRefMinus1( i, uiCode );
+    }
+    parsePTL ( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers()-1);
+    if( !pcVPS->getVpsProfilePresentFlag( i ) )
+    {
+      TComPTL temp = *pcVPS->getPTL( i );
+      *pcVPS->getPTL( i ) = *pcVPS->getPTL( pcVPS->getProfileRefMinus1( i ) + 1 );
+      pcVPS->getPTL( i )->copyLevelFrom( &temp );
+    }
+  }
+
+  Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1; 
+
+  READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); pcVPS->setMoreOutputLayerSetsThanDefaultFlag( uiCode == 1 );
+
+  if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
+  {
+    READ_CODE( 10, uiCode, "num_add_output_layer_sets_minus1"      ); pcVPS->setNumAddOutputLayerSetsMinus1( uiCode );
+    numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1); 
+  }
+
+  if( numOutputLayerSets > 1)
+  {
+    READ_FLAG( uiCode, "default_one_target_output_layer_flag" ); pcVPS->setDefaultOneTargetOutputLayerFlag(  uiCode == 1); 
+  }  
+
+  for( Int i = 1; i < numOutputLayerSets; i++ )
+  {
+    if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
+    {        
+      READ_UVLC( uiCode,      "output_layer_set_idx_minus1[i]" ); pcVPS->setOutputLayerSetIdxMinus1( i, uiCode ); 
+      for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1; j++ )
+      {
+        READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( i, j, uiCode == 1 ); 
+      }        
+    }
+    if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
+    {      
+      READ_CODE( pcVPS->getProfileLevelTierIdxLen(), uiCode,"profile_level_tier_idx[ i ]" );   pcVPS->setProfileLevelTierIdx( i , uiCode ); 
+    }
+  }
+
+  READ_FLAG( uiCode, "rep_format_idx_present_flag" ); pcVPS->setRepFormatIdxPresentFlag( uiCode == 1 );
+  if ( pcVPS->getRepFormatIdxPresentFlag() )
+  {
+    READ_CODE( 4, uiCode, "vps_num_rep_formats_minus1" ); pcVPS->setVpsNumRepFormatsMinus1( uiCode );
+  }
+
+  for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
+  { 
+    assert( pcVPS->getRepFormat(i) == NULL ); 
+    TComRepFormat* repFormat = new TComRepFormat(); 
+    parseRepFormat( repFormat );
+    pcVPS->setRepFormat(i, repFormat ); 
+  }
+
+  if( pcVPS->getRepFormatIdxPresentFlag() ) 
+  {
+    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      if( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
+      {
+        READ_CODE( 4, uiCode, "vps_rep_format_idx" ); pcVPS->setVpsRepFormatIdx( i, uiCode );
+      }
+    }
+  }
+
+  READ_FLAG( uiCode, "max_one_active_ref_layer_flag" ); pcVPS->setMaxOneActiveRefLayerFlag ( uiCode == 1 ); 
+  READ_FLAG( uiCode, "cross_layer_irap_aligned_flag" ); pcVPS->setCrossLayerIrapAlignedFlag( uiCode == 1 );
+  READ_UVLC( uiCode, "direct_dep_type_len_minus2")    ; pcVPS->setDirectDepTypeLenMinus2   ( uiCode ); 
+
+  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    for( Int j = 0; j < i; j++ )
+    {
+      if (pcVPS->getDirectDependencyFlag( i, j) )
+      {        
+        READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2,  uiCode, "direct_dependency_type[i][j]" ); pcVPS->setDirectDependencyType( i, j , uiCode);
+      }
+    }
+  }
+
+  READ_FLAG( uiCode, "vps_shvc_reserved_zero_flag" ); 
+  READ_FLAG( uiCode, "vps_vui_present_flag" )       ; pcVPS->setVpsVuiPresentFlag( uiCode == 1 );
+
+  if( pcVPS->getVpsVuiPresentFlag() )
+  {
+    m_pcBitstream->readOutTrailingBits(); // vps_vui_alignment_bit_equal_to_one
+    parseVPSVUI( pcVPS ); 
+  }     
+
+  pcVPS->checkVPSExtensionSyntax(); 
+  pcVPS->setRefLayers(); 
+}
+
+Void TDecCavlc::parseRepFormat( TComRepFormat* pcRepFormat )
+{
+  assert( pcRepFormat ); 
+
+  UInt uiCode; 
+  READ_CODE( 2,  uiCode, "chroma_format_vps_idc" );          pcRepFormat->setChromaFormatVpsIdc       ( uiCode );
+  if ( pcRepFormat->getChromaFormatVpsIdc() == 3 )
+  {
+    READ_FLAG( uiCode, "separate_colour_plane_vps_flag" ); pcRepFormat->setSeparateColourPlaneVpsFlag( uiCode == 1 ); 
+  }
+  READ_CODE( 16, uiCode, "pic_width_vps_in_luma_samples" );  pcRepFormat->setPicWidthVpsInLumaSamples ( uiCode );
+  READ_CODE( 16, uiCode, "pic_height_vps_in_luma_samples" ); pcRepFormat->setPicHeightVpsInLumaSamples( uiCode );
+  READ_CODE( 4,  uiCode, "bit_depth_vps_luma_minus8" );      pcRepFormat->setBitDepthVpsLumaMinus8    ( uiCode );
+  READ_CODE( 4,  uiCode, "bit_depth_vps_chroma_minus8" );    pcRepFormat->setBitDepthVpsChromaMinus8  ( uiCode );
+}
+
+
+Void TDecCavlc::parseVPSVUI( TComVPS* pcVPS )
+{
+  assert( pcVPS ); 
+
+  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
+
+  assert( pcVPSVUI ); 
+
+  UInt uiCode; 
+  READ_FLAG( uiCode, "bit_rate_present_vps_flag" ); pcVPSVUI->setBitRatePresentVpsFlag( uiCode == 1 );
+  READ_FLAG( uiCode, "pic_rate_present_vps_flag" ); pcVPSVUI->setPicRatePresentVpsFlag( uiCode == 1 );
+  if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
+  {
+    for( Int i = 0; i  <=  pcVPS->getVpsNumberLayerSetsMinus1(); i++ )
+    {
+      for( Int j = 0; j  <=  pcVPS->getMaxTLayers(); j++ ) 
+      {
+        if( pcVPSVUI->getBitRatePresentVpsFlag( ) )
+        {
+          READ_FLAG( uiCode, "bit_rate_present_flag" ); pcVPSVUI->setBitRatePresentFlag( i, j, uiCode == 1 );            
+        }
+        if( pcVPSVUI->getPicRatePresentVpsFlag( )  )
+        {
+          READ_FLAG( uiCode, "pic_rate_present_flag" ); pcVPSVUI->setPicRatePresentFlag( i, j, uiCode == 1 );
+        }
+        if( pcVPSVUI->getBitRatePresentFlag( i, j ) )
+        {
+          READ_CODE( 16, uiCode, "avg_bit_rate" ); pcVPSVUI->setAvgBitRate( i, j, uiCode );
+          READ_CODE( 16, uiCode, "max_bit_rate" ); pcVPSVUI->setMaxBitRate( i, j, uiCode );
+        }
+        if( pcVPSVUI->getPicRatePresentFlag( i, j ) )
+        {
+          READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); pcVPSVUI->setConstantPicRateIdc( i, j, uiCode );
+          READ_CODE( 16, uiCode, "avg_pic_rate" );          pcVPSVUI->setAvgPicRate( i, j, uiCode );
+        }
+      }
+    }
+  }
+
+  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    for( Int  j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ ) 
+    {
+      READ_FLAG( uiCode, "tile_boundaries_aligned_flag" ); pcVPSVUI->setTileBoundariesAlignedFlag( i, j, uiCode == 1 );
+    }
+  }
+
+  READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); pcVPSVUI->setIlpRestrictedRefLayersFlag( uiCode == 1 );
+
+  if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
+  {
+    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      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 ) )
+          {
+            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1" ); pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, uiCode );
+          }
+        }
+      }
+    }
+  }
+}
+#endif
+
+#if H_3D
+Void TDecCavlc::parseVPSExtension2( TComVPS* pcVPS )
+{
+  UInt uiCode; 
+  for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+#if H_3D_ARP
+    pcVPS->setUseAdvRP  ( i, 0 );
+    pcVPS->setARPStepNum( i, 1 );
+#endif  
+    if ( i != 0 )
+    {
+      if( !( pcVPS->getDepthId( i ) == 1 ) )
+      {
+#if H_3D_IV_MERGE
+        READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
+#endif
+#if H_3D_ARP
+        READ_FLAG( uiCode, "iv_res_pred_flag[i]"  );       pcVPS->setUseAdvRP  ( i, uiCode ); pcVPS->setARPStepNum( i, uiCode ? H_3D_ARP_WFNR : 1 );
+
+#endif
+#if H_3D_NBDV_REF
+        READ_FLAG( uiCode, "depth_refinement_flag[i]");    pcVPS->setDepthRefinementFlag  ( i, uiCode == 1 ? true : false );
+#endif
+#if H_3D_VSP
+        READ_FLAG( uiCode, "view_synthesis_pred_flag[i]"); pcVPS->setViewSynthesisPredFlag( i, uiCode == 1 ? true : false );
+#endif
+      }
+      else
+      {
+
+        READ_FLAG( uiCode, "vps_depth_modes_flag[i]" );             pcVPS->setVpsDepthModesFlag( i, uiCode == 1 ? true : false );
+        //          READ_FLAG( uiCode, "lim_qt_pred_flag[i]");                  pcVPS->setLimQtPreFlag     ( i, uiCode == 1 ? true : false ); 
+#if H_3D_DIM_DLT
+        if( pcVPS->getVpsDepthModesFlag( i ) )
+        {
+          READ_FLAG( uiCode, "dlt_flag[i]" );                       pcVPS->setUseDLTFlag( i, uiCode == 1 ? true : false );
+        }
+        if( pcVPS->getUseDLTFlag( i ) )
+        {
+          // decode mapping
+          UInt uiNumDepthValues;
+          // parse number of values in DLT
+          READ_UVLC(uiNumDepthValues, "num_depth_values_in_dlt[i]");
+
+          // parse actual DLT values
+          Int* aiIdx2DepthValue = (Int*) calloc(uiNumDepthValues, sizeof(Int));
+          for(Int d=0; d<uiNumDepthValues; d++)
+          {
+            READ_UVLC(uiCode, "dlt_depth_value[i][d]");
+            aiIdx2DepthValue[d] = (Int)uiCode;
+          }
+
+          pcVPS->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
+
+          // clean memory
+          free(aiIdx2DepthValue);
+        }
+#endif
+#if LGE_INTER_SDC_E0156
+            READ_FLAG( uiCode, "depth_inter_SDC_flag" );              pcVPS->setInterSDCFlag( i, uiCode ? true : false );
+#endif
+      }
+    }
+  }
+  READ_FLAG( uiCode, "iv_mv_scaling_flag");                       pcVPS->setIvMvScalingFlag( uiCode == 1 ? true : false ); 
+}
+#endif
+#endif
 
 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
@@ -1129,4 +1680,17 @@
 #if H_MV
   vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
+#if H_MV5
+  assert( vps != NULL );
+  
+  sps->inferRepFormat  ( vps , rpcSlice->getLayerId() ); 
+  sps->inferScalingList( parameterSetManager->getActiveSPS( sps->getSpsScalingListRefLayerId() ) );   
+
+  rpcSlice->setVPS(vps);      
+  rpcSlice->setViewId   ( vps->getViewId   ( rpcSlice->getLayerId() )      );
+  rpcSlice->setViewIndex( vps->getViewIndex( rpcSlice->getLayerId() )      );  
+#if H_3D  
+  rpcSlice->setIsDepth  ( vps->getDepthId  ( rpcSlice->getLayerId() ) == 1 );
+#endif
+#else
   assert(vps!=0);
   rpcSlice->setVPS(vps);      
@@ -1137,4 +1701,5 @@
 #endif
 #endif
+#endif
   rpcSlice->setSPS(sps);
   rpcSlice->setPPS(pps);
@@ -1182,4 +1747,20 @@
   {
 #if H_MV    
+#if H_MV5
+    Int esb = 0; //Don't use i, otherwise will shadow something below
+    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
+    {
+      esb++; 
+      READ_FLAG( uiCode, "poc_reset_flag" ); rpcSlice->setPocResetFlag( uiCode == 1 );
+    }
+
+    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
+    {
+      esb++; 
+      READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
+    }
+
+    for (; esb < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)    
+#else
     if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
     {
@@ -1188,4 +1769,5 @@
 
     for (Int i = 1; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)    
+#endif
 #else
     for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
@@ -1251,5 +1833,14 @@
       }
       rpcSlice->setPOC              (iPOCmsb+iPOClsb);
-
+#if H_MV5
+#if H_MV
+      if ( rpcSlice->getPocResetFlag() )  
+      {
+        rpcSlice->setPocBeforeReset   ( rpcSlice->getPOC() ); 
+        rpcSlice->setPOC              ( 0 );
+
+      }      
+#endif
+#endif
       TComReferencePictureSet* rps;
       rps = rpcSlice->getLocalRPS();
@@ -1379,4 +1970,24 @@
     }
 #if H_MV
+#if H_MV5
+    Int layerId       = rpcSlice->getLayerId(); 
+    if( rpcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )    {   
+      READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); rpcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
+      if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerId ) > 1 )
+      {            
+        if( !vps->getMaxOneActiveRefLayerFlag())  
+        {
+          READ_CODE( rpcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); rpcSlice->setNumInterLayerRefPicsMinus1( uiCode );
+        }
+        if ( rpcSlice->getNumActiveRefLayerPics() != vps->getNumDirectRefLayers( layerId ) )
+        {
+          for( Int idx = 0; idx < rpcSlice->getNumActiveRefLayerPics(); idx++ )   
+          {
+            READ_CODE( rpcSlice->getInterLayerPredLayerIdcLen( ), uiCode, "inter_layer_pred_layer_idc" ); rpcSlice->setInterLayerPredLayerIdc( idx, uiCode );
+          }
+        }
+      }  
+    }
+#else
     Int layerIdInVps       = rpcSlice->getLayerIdInVps(); 
     if( rpcSlice->getLayerId() > 0 && vps->getNumDirectRefLayers( layerIdInVps ) > 0 )
@@ -1402,5 +2013,5 @@
       READ_FLAG( uiCode, "inter_layer_sample_pred_only_flag" ); rpcSlice->setInterLayerSamplePredOnlyFlag( uiCode == 1 );
     }
-
+#endif
 #endif
     if(sps->getUseSAO())
@@ -1544,4 +2155,5 @@
     if ( rpcSlice->getEnableTMVPFlag() )
     {
+#if !H_MV5
 #if H_MV
       if( rpcSlice->getLayerId() > 0 && rpcSlice->getNumActiveMotionPredRefLayers() > 0 )
@@ -1557,4 +2169,5 @@
       {
 #endif
+#endif
       if ( rpcSlice->getSliceType() == B_SLICE )
       {
@@ -1578,6 +2191,8 @@
         rpcSlice->setColRefIdx(0);
       }
-#if H_MV
-      }
+#if !H_MV5
+#if H_MV
+      }
+#endif
 #endif
     }
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 609)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 622)
@@ -76,5 +76,20 @@
   Void  parseQtRootCbf      ( UInt uiAbsPartIdx, UInt& uiQtRootCbf );
   Void  parseVPS            ( TComVPS* pcVPS );
+#if H_MV5
+#if H_MV
+  Void  parseVPSExtension   ( TComVPS* pcVPS ); 
+  Void  parseRepFormat      ( TComRepFormat* pcRepFormat );
+  Void  parseVPSVUI         ( TComVPS* pcVPS );
+#endif
+
+#if H_MV
+  Void  parseSPSExtension   ( TComSPS* pcSPS );  
+#endif
+#endif
 #if H_3D
+#if H_MV5
+  Void  parseVPSExtension2  ( TComVPS* pcVPS ); 
+  Void  parseSPSExtension2  ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag );
+#endif
   Void  parseSPS            ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag );
 #else
Index: trunk/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 609)
+++ trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 622)
@@ -315,8 +315,23 @@
 #if H_3D_NBDV_REF
       if(pcCU->getSlice()->getVPS()->getDepthRefinementFlag( pcCU->getSlice()->getLayerIdInVps() ))  //Notes from QC: please check the condition for DoNBDV. Remove this comment once it is done.
+      {
         DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo, true);
+      }
       else
 #endif
+      {
         DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo);
+      }
+
+#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC   
+      if ( g_decTraceDispDer )
+      {
+        DTRACE_CU( "RefViewIdx",  DvInfo.m_aVIdxCan );       
+        DTRACE_CU( "MvDisp[x]", DvInfo.m_acNBDV.getHor() );
+        DTRACE_CU( "MvDisp[y]", DvInfo.m_acNBDV.getVer() );
+        DTRACE_CU( "MvRefinedDisp[x]", DvInfo.m_acDoNBDV.getHor() );
+        DTRACE_CU( "MvRefinedDisp[y]", DvInfo.m_acDoNBDV.getVer() );
+      }
+#endif
 
       pcCU->setDvInfoSubParts(DvInfo, uiAbsPartIdx, uiDepth);
@@ -366,22 +381,11 @@
     Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
     memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
-#if MTK_VSP_FIX_ALIGN_WD_E0172
     InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
     m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, numValidMergeCand, uiMergeIndex );
-#else
-#if MTK_VSP_FIX_E0172
-    Int vspDir[MRG_MAX_NUM_CANDS_MEM];
-    memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
-    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag,vspDir, numValidMergeCand, uiMergeIndex );
-    pcCU->setVSPDirSubParts( vspDir[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
-#else
-    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, numValidMergeCand, uiMergeIndex );
-#endif
-#endif// end of MTK_VSP_FIX_ALIGN_WD_E0172
     pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
 #else
     m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
 #endif
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
     if(vspFlag[uiMergeIndex])
     {
@@ -400,4 +404,21 @@
         pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
         pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
+#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC   
+        if ( g_decTraceMvFromMerge )
+        {        
+          if ( uiRefListIdx == 0 )
+          {
+            DTRACE_PU( "mvL0[0]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getHor());
+            DTRACE_PU( "mvL0[1]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getVer());
+            DTRACE_PU( "refIdxL0   ", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx());
+          }
+          else
+          {
+            DTRACE_PU( "mvL1[0]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getHor());
+            DTRACE_PU( "mvL1[1]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getVer());
+            DTRACE_PU( "refIdxL1", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx());
+          }
+        }
+#endif
       }
     }
Index: trunk/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 609)
+++ trunk/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 622)
@@ -243,24 +243,12 @@
           Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
           memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
-#if MTK_VSP_FIX_ALIGN_WD_E0172
           InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
           pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, numValidMergeCand );
-#else
-#if MTK_VSP_FIX_E0172
-          Int vspDir[MRG_MAX_NUM_CANDS_MEM];
-          memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
-          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, vspDir, numValidMergeCand );
-          pcCU->setVSPDirSubParts( vspDir[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
-#else
-          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, numValidMergeCand );
-#endif
-#endif//end of MTK_VSP_FIX_ALIGN_WD_E0172
           pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+
           if(vspFlag[uiMergeIndex])
           {
             pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
           }
-#endif
 #else
           pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
@@ -272,28 +260,15 @@
       else
       {
-        uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx); // Redundant line
+        uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
 #if H_3D_VSP
         Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
         memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
-#if MTK_VSP_FIX_ALIGN_WD_E0172
         InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
         pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, inheritedVSPDisInfo,numValidMergeCand, uiMergeIndex );
-#else
-#if MTK_VSP_FIX_E0172
-        Int vspDir[MRG_MAX_NUM_CANDS_MEM];
-        memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
-        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, vspDir,numValidMergeCand, uiMergeIndex );
-        pcCU->setVSPDirSubParts( vspDir[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
-#else
-        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, numValidMergeCand, uiMergeIndex );
-#endif
-#endif//end of MTK_VSP_FIX_ALIGN_WD_E0172
         pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
         if(vspFlag[uiMergeIndex])
         {
           pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeIndex].m_acDvInfo, uiSubPartIdx, uiPartIdx, uiDepth);
         }
-#endif
 #else
         pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
@@ -327,5 +302,5 @@
       }
     }
-#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
     if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) && (pcCU->getVSPFlag(uiSubPartIdx) == false))
 #else
Index: trunk/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 609)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 622)
@@ -89,5 +89,5 @@
 #if H_3D_DIM_DMM
 , m_cDmm1DataSCModel          ( 1,             1,               NUM_DMM1_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
 , m_cDmm2DataSCModel          ( 1,             1,               NUM_DMM2_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
 #endif
@@ -179,5 +179,5 @@
 #if H_3D_DIM_DMM
   m_cDmm1DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM1_DATA );
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   m_cDmm2DataSCModel.initBuffer          ( sliceType, qp, (UChar*)INIT_DMM2_DATA );
 #endif
@@ -255,5 +255,5 @@
 #if H_3D_DIM_DMM
   m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   m_cDmm2DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA );
 #endif
@@ -444,5 +444,5 @@
   ruiTabIdx = uiIdx;
 }
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
 Void TDecSbac::xParseDmm2Offset( Int& riOffset )
 {
@@ -584,8 +584,15 @@
   m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
   
+#if H_MV_ENC_DEC_TRAC
+  DTRACE_CU("sdc_residual_flag[i]", uiResidual)
+#endif
+  
   if (uiResidual)
   {
     // decode residual sign bit
     m_pcTDecBinIf->decodeBinEP(uiSign);
+#if H_MV_ENC_DEC_TRAC
+    DTRACE_CU("sdc_residual_sign_flag[i]", uiSign)
+#endif
     
     // decode residual magnitude
@@ -617,5 +624,11 @@
     }
     else
+    {
       uiAbsIdx = uiCount;
+    }
+  
+#if H_MV_ENC_DEC_TRAC
+    DTRACE_CU("sdc_residual_abs_minus1[i]", uiAbsIdx)
+#endif
     
     uiAbsIdx += 1;
@@ -1162,5 +1175,5 @@
       pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, absPartIdx, depth );
     } break;
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   case( DMM2_IDX ):
     {
@@ -1333,9 +1346,9 @@
         binNum = 0;
 #if LGE_SDC_REMOVE_DC_E0158
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
         while( symbol && binNum < 2 )
 #endif
 #else
-#if SEC_DMM2_E0146
+#if SEC_DMM2_E0146_HHIFIX
         while( symbol && binNum < 2 )
 #else
@@ -1358,5 +1371,5 @@
     else if( modeCode == 6  ) { dir = (2*DMM3_IDX+DIM_OFFSET); sdcFlag = 0;}
 #if LGE_SDC_REMOVE_DC_E0158
-#if SEC_DMM2_E0146
+#if SEC_DMM2_E0146_HHIFIX
     else if( modeCode == 7 )  { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
 #else
@@ -1366,5 +1379,5 @@
 #else
     else if( modeCode == 14 ) { dir =      DC_IDX;             sdcFlag = 1;}
-#if SEC_DMM2_E0146
+#if SEC_DMM2_E0146_HHIFIX
     else if( modeCode == 15 ) { dir = (2* RBC_IDX+DIM_OFFSET); sdcFlag = 0;}
 #else
Index: trunk/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 609)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 622)
@@ -102,5 +102,5 @@
 #if H_3D_DIM_DMM
   Void  xParseDmm1WedgeIdx   ( UInt& ruiTabIdx, Int iNumBit );
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   Void  xParseDmm2Offset     ( Int& riOffset );
 #endif
@@ -216,5 +216,5 @@
 #if H_3D_DIM_DMM
   ContextModel3DBuffer m_cDmm1DataSCModel;
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   ContextModel3DBuffer m_cDmm2DataSCModel;
 #endif
Index: trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 609)
+++ trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 622)
@@ -436,4 +436,10 @@
   Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
 
+#if H_MV5
+#if H_MV
+    assert( conformanceWindow   .getScaledFlag() ); 
+    assert( defaultDisplayWindow.getScaledFlag() );
+#endif
+#endif
   for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
   {
@@ -512,5 +518,9 @@
   m_cCuDecoder.destroy();        
 #if H_MV 
+#if H_MV5
+  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 );  
+#else
   TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer );  
+#endif
   TComSlice::markCurrPic( pcPic ); 
   TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
@@ -581,5 +591,15 @@
   assert (sps != 0);
 
+#if H_MV5
+#if H_MV
+  TComVPS* vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
+  assert (vps != 0); 
+  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
+#else
   if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
+#endif
+#else
+  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
+#endif
   {
     printf ("Parameter set activation failed!");
@@ -607,5 +627,11 @@
   m_apcSlicePilot->setSPS(sps);
 #if H_MV
+#if H_MV5
+  m_apcSlicePilot->setVPS(vps);  
+  sps->inferRepFormat  ( vps , m_layerId ); 
+  sps->inferScalingList( m_parameterSetManagerDecoder.getActiveSPS( sps->getSpsScalingListRefLayerId() ) ); 
+#else
   m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getActiveVPS() );
+#endif
 #endif
   pps->setSPS(sps);
@@ -669,5 +695,9 @@
 
 #if H_MV
+#if H_MV5
+  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
+#else
   m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer ); 
+#endif
   m_apcSlicePilot->setLayerId( nalu.m_layerId );
 #endif
@@ -676,4 +706,13 @@
 #if H_MV  
   TComVPS* vps     = m_apcSlicePilot->getVPS();
+#if H_MV5
+  Int layerId  = nalu.m_layerId;   
+  setViewId   ( vps->getViewId   ( layerId )      );  
+#if H_3D
+  setViewIndex( vps->getViewIndex( layerId )      );  
+  setIsDepth  ( vps->getDepthId  ( layerId ) == 1 );  
+  m_ivPicLists->setVPS( vps ); 
+#endif
+#else
   Int layerIdInVps = vps->getLayerIdInVps( nalu.m_layerId );  
   setViewId   ( vps->getViewId   ( layerIdInVps )      );  
@@ -684,4 +723,5 @@
 #endif
 #endif
+#endif
     // Skip pictures due to random access
     if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
@@ -723,4 +763,13 @@
 #endif
   // actual decoding starts here
+#if H_MV5
+#if H_MV
+   // This part needs further testing !
+   if ( m_apcSlicePilot->getPocResetFlag() )
+   {   
+     xResetPocInPicBuffer();
+   }
+#endif
+#endif
   xActivateParameterSets();
 
@@ -742,5 +791,9 @@
     m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
 #if H_MV
+#if H_MV5
+    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
+#else
     m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
+#endif
 #endif
     //  Get a new picture buffer
@@ -888,9 +941,19 @@
     // Set reference list
 #if H_MV    
+#if H_MV5
+    std::vector< TComPic* > tempRefPicLists[2];
+    std::vector< Bool     > usedAsLongTerm [2];
+    Int       numPocTotalCurr;
+
+    pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
+    pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
+#else
     pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true );    
+#endif
 #if H_3D_ARP
     pcSlice->setARPStepNum();
     if( pcSlice->getARPStepNum() > 1 )
     {
+      // GT: This seems to be broken, not all nuh_layer_ids are necessarily present
       for(Int iLayerId = 0; iLayerId < nalu.m_layerId; iLayerId ++ )
       {
@@ -1021,6 +1084,10 @@
   TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
   assert( vps != 0 ); 
+#if H_MV5
+  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( m_layerId ), ( vps->getDepthId( m_layerId ) == 1 ) );
+#else
   Int layerIdInVPS = vps->getLayerIdInVps( m_layerId ); 
   m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( layerIdInVPS ), ( vps->getDepthId( layerIdInVPS ) == 1 ) );
+#endif
 #else
   m_cEntropyDecoder.decodeSPS( sps );
@@ -1032,4 +1099,9 @@
 {
   TComPPS* pps = new TComPPS();
+#if H_MV5
+#if H_MV
+  pps->setLayerId( getLayerId() ); 
+#endif
+#endif
   m_cEntropyDecoder.decodePPS( pps );
   m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
@@ -1040,9 +1112,25 @@
   if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
   {
+#if H_MV5
+#if H_MV
+    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
+#else
     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
+#endif
+#else
+    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );  
+#endif
   }
   else
   {
+#if H_MV5
+#if H_MV
+    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
+#else
     m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
+#endif
+#else
+    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
+#endif
     SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
     if (activeParamSets.size()>0)
@@ -1051,5 +1139,13 @@
       m_parameterSetManagerDecoder.applyPrefetchedPS();
       assert(seiAps->activeSeqParamSetId.size()>0);
+#if H_MV5
+#if H_MV
+      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0], m_layerId ))
+#else
       if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
+#endif
+#else
+      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
+#endif
       {
         printf ("Warning SPS activation with Active parameter set SEI failed");
@@ -1210,4 +1306,22 @@
 }
 
+#if H_MV5
+Void TDecTop::xResetPocInPicBuffer()
+{
+  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
+  while (iterPic != m_cListPic.end())
+  {
+    TComPic* pic = *(iterPic++);
+    if ( pic->getReconMark() )
+    {
+      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
+      {
+        TComSlice* slice = pic->getSlice( i ); 
+        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );            
+      }         
+    }     
+  }
+}
+#endif
 #endif
 //! \}
Index: trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 609)
+++ trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 622)
@@ -216,5 +216,10 @@
   Int                     m_viewId;
   TComPicLists*           m_ivPicLists;
+#if H_MV5
+  std::vector<TComPic*>   m_refPicSetInterLayer0; 
+  std::vector<TComPic*>   m_refPicSetInterLayer1; 
+#else
   std::vector<TComPic*>   m_refPicSetInterLayer; 
+#endif
 #if H_3D
   Int                     m_viewIndex; 
@@ -274,4 +279,7 @@
   TComPic*  xGetPic( Int layerId, Int poc ); 
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag );  
+#if H_MV5
+  Void      xResetPocInPicBuffer();
+#endif
 #else
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay);
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 609)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 622)
@@ -229,4 +229,19 @@
     }
   }
+#if H_MV5
+#if H_MV
+  if ( pcPPS->getLayerId() > 0 )
+  {
+    WRITE_FLAG( pcPPS->getPpsInferScalingListFlag( ) ? 1 : 0 , "pps_infer_scaling_list_flag" );
+  }
+
+  if( pcPPS->getPpsInferScalingListFlag( ) ) 
+  {
+    WRITE_CODE( pcPPS->getPpsScalingListRefLayerId( ), 6, "pps_scaling_list_ref_layer_id" );
+  }
+  else
+  {  
+#endif  
+#endif
   WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0,                          "pps_scaling_list_data_present_flag" ); 
   if( pcPPS->getScalingListPresentFlag() )
@@ -237,4 +252,9 @@
     codeScalingList( m_pcSlice->getScalingList() );
   }
+#if H_MV5
+#if H_MV
+  }
+#endif
+#endif
   WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag");
   WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2");
@@ -319,4 +339,5 @@
   {
     WRITE_FLAG(pcVUI->getTilesFixedStructureFlag(),             "tiles_fixed_structure_flag");
+#if !H_MV5
 #if H_MV
     if ( pcSPS->getLayerId() > 0 )
@@ -324,4 +345,5 @@
       WRITE_FLAG( pcVUI->getTileBoundariesAlignedFlag( ) ? 1 : 0 , "tile_boundaries_aligned_flag" );
     }
+#endif
 #endif
     WRITE_FLAG(pcVUI->getMotionVectorsOverPicBoundariesFlag(),  "motion_vectors_over_pic_boundaries_flag");
@@ -429,4 +451,15 @@
 #endif
   WRITE_UVLC( pcSPS->getSPSId (),                   "sps_seq_parameter_set_id" );
+#if H_MV5
+#if H_MV
+  if ( pcSPS->getLayerId() > 0 )
+  {
+    WRITE_FLAG( pcSPS->getUpdateRepFormatFlag( ) ? 1 : 0 , "update_rep_format_flag" );
+  }
+
+  if ( pcSPS->getUpdateRepFormatFlag() )
+  { 
+#endif
+#endif
   WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
   assert(pcSPS->getChromaFormatIdc () == 1);
@@ -439,4 +472,9 @@
   WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
   WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
+#if H_MV5
+#if H_MV
+  }
+#endif
+#endif
   Window conf = pcSPS->getConformanceWindow();
 
@@ -449,8 +487,17 @@
     WRITE_UVLC( conf.getWindowBottomOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_bottom_offset" );
   }
-
+#if H_MV5
+#if H_MV
+  if ( pcSPS->getUpdateRepFormatFlag() )
+  { 
+#endif
+#endif
   WRITE_UVLC( pcSPS->getBitDepthY() - 8,             "bit_depth_luma_minus8" );
   WRITE_UVLC( pcSPS->getBitDepthC() - 8,             "bit_depth_chroma_minus8" );
-
+#if H_MV5
+#if H_MV
+  }
+#endif
+#endif
   WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
 
@@ -478,4 +525,19 @@
   if(pcSPS->getScalingListFlag())
   {
+#if H_MV5
+#if H_MV
+    if ( pcSPS->getLayerId() > 0 )
+    {    
+      WRITE_FLAG( pcSPS->getSpsInferScalingListFlag( ) ? 1 : 0 , "sps_infer_scaling_list_flag" );
+    }
+
+    if ( pcSPS->getSpsInferScalingListFlag() )
+    {
+      WRITE_CODE( pcSPS->getSpsScalingListRefLayerId( ), 6, "sps_scaling_list_ref_layer_id" );
+    }
+    else
+    {    
+#endif
+#endif
     WRITE_FLAG( pcSPS->getScalingListPresentFlag() ? 1 : 0,                          "sps_scaling_list_data_present_flag" ); 
     if(pcSPS->getScalingListPresentFlag())
@@ -486,4 +548,9 @@
       codeScalingList( m_pcSlice->getScalingList() );
     }
+#if H_MV5
+#if H_MV
+    }
+#endif
+#endif
   }
   WRITE_FLAG( pcSPS->getUseAMP() ? 1 : 0,                                            "amp_enabled_flag" );
@@ -531,4 +598,5 @@
   }
 
+#if !H_MV5
 #if H_MV
   WRITE_FLAG( 1, "sps_extension_flag" );
@@ -586,4 +654,57 @@
 #endif
 }
+#else
+#if !H_MV
+  WRITE_FLAG( 0, "sps_extension_flag" );
+#else
+  WRITE_FLAG( 1, "sps_extension_flag" );
+  codeSPSExtension( pcSPS ); 
+#if !H_3D
+  WRITE_FLAG( 0, "sps_extension2_flag" );
+#else
+  WRITE_FLAG( 1, "sps_extension2_flag" );
+  codeSPSExtension2( pcSPS, viewIndex, depthFlag ); 
+  WRITE_FLAG( 0, "sps_extension3_flag" );
+#endif  
+#endif
+}
+
+#if H_MV
+Void TEncCavlc::codeSPSExtension( TComSPS* pcSPS )
+{
+  WRITE_FLAG( pcSPS->getInterViewMvVertConstraintFlag() ? 1 : 0, "inter_view_mv_vert_constraint_flag" );
+  WRITE_UVLC( 0, "sps_shvc_reserved_zero_idc" ); 
+}
+#endif
+
+#if H_3D
+Void TEncCavlc::codeSPSExtension2( TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
+{
+#if H_3D_QTLPC
+//GT: This has to go to VPS
+if( depthFlag )
+{
+  WRITE_FLAG( pcSPS->getUseQTL() ? 1 : 0, "use_qtl_flag");
+  WRITE_FLAG( pcSPS->getUsePC()  ? 1 : 0, "use_pc_flag");
+}
+#endif
+  if (!depthFlag )
+  {
+    WRITE_UVLC( pcSPS->getCamParPrecision(), "cp_precision" );
+    WRITE_FLAG( pcSPS->hasCamParInSliceHeader() ? 1 : 0, "cp_in_slice_header_flag" );
+    if( !pcSPS->hasCamParInSliceHeader() )
+    {
+      for( UInt uiIndex = 0; uiIndex < viewIndex; uiIndex++ )
+      {
+        WRITE_SVLC( pcSPS->getCodedScale    ()[ uiIndex ],                                      "cp_scale" );
+        WRITE_SVLC( pcSPS->getCodedOffset   ()[ uiIndex ],                                      "cp_off" );
+        WRITE_SVLC( pcSPS->getInvCodedScale ()[ uiIndex ] + pcSPS->getCodedScale ()[ uiIndex ], "cp_inv_scale_plus_scale" );
+        WRITE_SVLC( pcSPS->getInvCodedOffset()[ uiIndex ] + pcSPS->getCodedOffset()[ uiIndex ], "cp_inv_off_plus_off" );
+      }
+    }
+  }
+}
+#endif
+#endif
 
 Void TEncCavlc::codeVPS( TComVPS* pcVPS )
@@ -592,5 +713,9 @@
   WRITE_CODE( 3,                                    2,        "vps_reserved_three_2bits" );
 #if H_MV
+#if H_MV5
+  WRITE_CODE( pcVPS->getMaxLayersMinus1(),       6,        "vps_max_layers_minus1" );
+#else
   WRITE_CODE( pcVPS->getMaxLayers() - 1,            6,        "vps_max_layers_minus1" );
+#endif
 #else
   WRITE_CODE( 0,                                    6,        "vps_reserved_zero_6bits" );
@@ -675,4 +800,5 @@
     }
   }
+#if !H_MV5
 #if H_MV
   WRITE_FLAG( 1,                                             "vps_extension_flag" );
@@ -848,7 +974,5 @@
     }  
   }
-#if H_3D_TMVP
   WRITE_FLAG( pcVPS->getIvMvScalingFlag( ) ? 1 : 0 ,          "iv_mv_scaling_flag" );
-#endif
 #else
   WRITE_FLAG( 0,                                             "vps_extension2_flag" );
@@ -862,4 +986,339 @@
   return;
 }
+#else
+#if H_MV
+  WRITE_FLAG( 1,                     "vps_extension_flag" );
+  m_pcBitIf->writeAlignOne();
+  codeVPSExtension( pcVPS );                           
+#if H_3D
+  WRITE_FLAG( 1,                     "vps_extension2_flag" );
+  m_pcBitIf->writeAlignOne();      
+  codeVPSExtension2( pcVPS ); 
+  WRITE_FLAG( 0,                     "vps_extension3_flag" );
+#else
+  WRITE_FLAG( 0,                     "vps_extension2_flag" );
+#endif
+#else
+  WRITE_FLAG( 0,                     "vps_extension_flag" );
+#endif
+  //future extensions here..
+}
+
+#endif
+
+
+#if H_MV5
+#if H_MV
+Void TEncCavlc::codeVPSExtension( TComVPS *pcVPS ) 
+{
+  WRITE_FLAG( pcVPS->getAvcBaseLayerFlag() ? 1 : 0,          "avc_base_layer_flag" );
+  WRITE_CODE( pcVPS->getVpsVuiOffset( ), 16,                 "vps_vui_offset" );  // TBD
+  WRITE_FLAG( pcVPS->getSplittingFlag() ? 1 : 0,             "splitting_flag" );
+  
+  for( Int type = 0; type < MAX_NUM_SCALABILITY_TYPES; type++ )
+  {
+    WRITE_FLAG( pcVPS->getScalabilityMaskFlag( type ) ? 1 : 0,   "scalability_mask_flag[i]" );
+  }
+
+  for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
+  {
+    WRITE_CODE( pcVPS->getDimensionIdLen( sIdx ) - 1 , 3,    "dimension_id_len_minus1[j]");    
+  }
+
+  if ( pcVPS->getSplittingFlag() )
+  { // Ignore old dimension id length
+    pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1 ,pcVPS->inferLastDimsionIdLenMinus1() + 1 );       
+  }    
+
+  WRITE_FLAG( pcVPS->getVpsNuhLayerIdPresentFlag() ? 1 : 0,  "vps_nuh_layer_id_present_flag");
+
+  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    if ( pcVPS->getVpsNuhLayerIdPresentFlag() )
+    {      
+      WRITE_CODE( pcVPS->getLayerIdInNuh( i ), 6,          "layer_id_in_nuh[i]");
+  }
+    else
+    {
+      assert( pcVPS->getLayerIdInNuh( i ) == i ); 
+  }
+
+    assert(  pcVPS->getLayerIdInVps( pcVPS->getLayerIdInNuh( i ) ) == i ); 
+
+    for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ )
+    {
+      if ( !pcVPS->getSplittingFlag() )
+      {
+        WRITE_CODE( pcVPS->getDimensionId( i, j ), pcVPS->getDimensionIdLen( j ), "dimension_id[i][j]");      
+      }
+      else
+      {
+        assert( pcVPS->getDimensionId( i, j ) ==  pcVPS->inferDimensionId( i, j )  );
+      }
+    }
+  }
+
+  // GT spec says: trac #39
+  // if ( pcVPS->getNumViews() > 1 )  
+  //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val. 
+  {
+    WRITE_CODE( pcVPS->getViewIdLenMinus1( ), 4, "view_id_len_minus1" );
+  }
+
+  for( Int i = 0; i < pcVPS->getNumViews(); i++ )
+  {
+    WRITE_CODE( pcVPS->getViewIdVal( i ), pcVPS->getViewIdLenMinus1( ) + 1, "view_id_val[i]" );
+  }
+
+  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    for( Int j = 0; j < i; j++ )
+    {
+      WRITE_FLAG( pcVPS->getDirectDependencyFlag( i, j ),    "direct_dependency_flag[i][j]" );
+    }
+  }
+
+  WRITE_FLAG( pcVPS->getMaxTidRefPresentFlag( ) ? 1 : 0 , "max_tid_ref_present_flag" );
+
+  if ( pcVPS->getMaxTidRefPresentFlag() )
+  {    
+    for( Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      WRITE_CODE( pcVPS->getMaxTidIlRefPicPlus1( i ), 3,       "max_tid_il_ref_pics_plus1[i]" );
+    }
+  }
+
+  WRITE_FLAG( pcVPS->getAllRefLayersActiveFlag( ) ? 1 : 0 , "all_ref_layers_active_flag" );
+  WRITE_CODE( pcVPS->getVpsNumberLayerSetsMinus1( )    , 10,    "vps_number_layer_sets_minus1"      );
+  WRITE_CODE( pcVPS->getVpsNumProfileTierLevelMinus1( ), 6,     "vps_num_profile_tier_level_minus1" );
+
+  for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
+  {
+    WRITE_FLAG( pcVPS->getVpsProfilePresentFlag( i ) ? 1 : 0, "vps_profile_present_flag[i]" );
+    if( !pcVPS->getVpsProfilePresentFlag( i ) )
+    {    
+      WRITE_CODE( pcVPS->getProfileRefMinus1( i ), 6, "profile_ref_minus1[i]" );
+    }
+    codePTL( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers() - 1 );
+  }
+
+  Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1; 
+
+  WRITE_FLAG( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) ? 1 : 0, "more_output_layer_sets_than_default_flag" );
+
+  if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
+  {
+    WRITE_CODE( pcVPS->getNumAddOutputLayerSetsMinus1( )    , 10,    "num_add_output_layer_sets_minus1"      );
+    numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1 ); 
+  }
+
+  if( numOutputLayerSets > 1)
+  {
+    WRITE_FLAG( pcVPS->getDefaultOneTargetOutputLayerFlag( ) ? 1 : 0, "default_one_target_output_layer_flag" );
+  }  
+
+  for( Int i = 1; i < numOutputLayerSets; i++ )
+  {
+    if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
+    {      
+      WRITE_UVLC( pcVPS->getOutputLayerSetIdxMinus1( i ),      "output_layer_set_idx_minus1[i]" );
+      for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1 ; j++ )
+      {
+        WRITE_FLAG( pcVPS->getOutputLayerFlag( i, j) ? 1 : 0, "output_layer_flag" );
+      }      
+    }
+    if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
+    {      
+      WRITE_CODE( pcVPS->getProfileLevelTierIdx( i ), pcVPS->getProfileLevelTierIdxLen() ,"profile_level_tier_idx[ i ]" );   
+    }
+  }
+
+  WRITE_FLAG( pcVPS->getRepFormatIdxPresentFlag( ) ? 1 : 0 , "rep_format_idx_present_flag" );
+  if ( pcVPS->getRepFormatIdxPresentFlag() )
+  {
+    WRITE_CODE( pcVPS->getVpsNumRepFormatsMinus1( ), 4, "vps_num_rep_formats_minus1" );
+  }
+
+  for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
+  {    
+    TComRepFormat* pcRepFormat = pcVPS->getRepFormat(i);     
+    codeRepFormat( pcRepFormat ); 
+  }
+
+  if( pcVPS->getRepFormatIdxPresentFlag() ) 
+  {
+    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      if( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
+      {
+        WRITE_CODE( pcVPS->getVpsRepFormatIdx( i ), 4, "vps_rep_format_idx" );
+      }
+    }
+  }
+
+  WRITE_FLAG( pcVPS->getMaxOneActiveRefLayerFlag( ) ? 1 : 0, "max_one_active_ref_layer_flag" );
+  WRITE_FLAG( pcVPS->getCrossLayerIrapAlignedFlag( ) ? 1 : 0 , "cross_layer_irap_aligned_flag" );
+  WRITE_UVLC( pcVPS->getDirectDepTypeLenMinus2 ( ),         "direct_dep_type_len_minus2"); 
+
+    for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      for( Int j = 0; j < i; j++ )
+      {
+        if (pcVPS->getDirectDependencyFlag( i, j) )
+        {        
+          assert ( pcVPS->getDirectDependencyType( i, j ) != -1 ); 
+          WRITE_CODE( pcVPS->getDirectDependencyType( i, j ),pcVPS->getDirectDepTypeLenMinus2( ) + 2,  "direct_dependency_type[i][j]" );
+        }
+      }
+    }
+    
+    WRITE_FLAG ( 0,                                      "vps_shvc_reserved_zero_flag" ); 
+    WRITE_FLAG( pcVPS->getVpsVuiPresentFlag( ) ? 1 : 0 , "vps_vui_present_flag" );
+
+    if( pcVPS->getVpsVuiPresentFlag() )
+    {
+      m_pcBitIf->writeAlignOne();  // vps_vui_alignment_bit_equal_to_one
+      codeVPSVUI( pcVPS ); 
+    }     
+}
+
+Void TEncCavlc::codeRepFormat( TComRepFormat* pcRepFormat )
+{
+  assert( pcRepFormat ); 
+
+  WRITE_CODE( pcRepFormat->getChromaFormatVpsIdc( ), 2, "chroma_format_vps_idc" );
+
+  if ( pcRepFormat->getChromaFormatVpsIdc() == 3 )
+  {
+    WRITE_FLAG( pcRepFormat->getSeparateColourPlaneVpsFlag( ) ? 1 : 0 , "separate_colour_plane_vps_flag" );
+  }
+  WRITE_CODE( pcRepFormat->getPicWidthVpsInLumaSamples( ),  16, "pic_width_vps_in_luma_samples" );
+  WRITE_CODE( pcRepFormat->getPicHeightVpsInLumaSamples( ), 16, "pic_height_vps_in_luma_samples" );
+  WRITE_CODE( pcRepFormat->getBitDepthVpsLumaMinus8( ),      4, "bit_depth_vps_luma_minus8" );
+  WRITE_CODE( pcRepFormat->getBitDepthVpsChromaMinus8( ),    4, "bit_depth_vps_chroma_minus8" );
+}
+
+Void TEncCavlc::codeVPSVUI( TComVPS* pcVPS )
+{
+  assert( pcVPS ); 
+
+  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
+
+  assert( pcVPSVUI ); 
+
+  WRITE_FLAG( pcVPSVUI->getBitRatePresentVpsFlag( ) ? 1 : 0 , "bit_rate_present_vps_flag" );
+  WRITE_FLAG( pcVPSVUI->getPicRatePresentVpsFlag( ) ? 1 : 0 , "pic_rate_present_vps_flag" );
+  if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
+  {
+    for( Int i = 0; i  <=  pcVPS->getVpsNumberLayerSetsMinus1(); i++ )
+    {
+      for( Int j = 0; j  <=  pcVPS->getMaxTLayers(); j++ ) 
+      {
+        if( pcVPSVUI->getBitRatePresentVpsFlag( ) )
+        {
+          WRITE_FLAG( pcVPSVUI->getBitRatePresentFlag( i, j ) ? 1 : 0 , "bit_rate_present_flag" );
+        }
+        if( pcVPSVUI->getBitRatePresentVpsFlag( )  )
+        {
+          WRITE_FLAG( pcVPSVUI->getPicRatePresentFlag( i, j ) ? 1 : 0 , "pic_rate_present_flag" );
+        }
+        if( pcVPSVUI->getBitRatePresentFlag( i, j ) )
+        {
+          WRITE_CODE( pcVPSVUI->getAvgBitRate( i, j ), 16, "avg_bit_rate" );
+          WRITE_CODE( pcVPSVUI->getMaxBitRate( i, j ), 16, "max_bit_rate" );
+        }
+        if( pcVPSVUI->getPicRatePresentFlag( i, j ) )
+        {
+          WRITE_CODE( pcVPSVUI->getConstantPicRateIdc( i, j ), 2, "constant_pic_rate_idc" );
+          WRITE_CODE( pcVPSVUI->getAvgPicRate( i, j ), 16, "avg_pic_rate" );
+        }
+      }
+    }
+  }
+
+  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    for( Int  j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ ) 
+    {
+      WRITE_FLAG( pcVPSVUI->getTileBoundariesAlignedFlag( i, j ) ? 1 : 0 , "tile_boundaries_aligned_flag" );
+    }
+  }
+
+  WRITE_FLAG( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) ? 1 : 0 , "ilp_restricted_ref_layers_flag" );
+
+  if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
+  {
+    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ )
+      {
+        WRITE_UVLC( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ), "min_spatial_segment_offset_plus1" );
+        if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
+        {
+          WRITE_FLAG( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) ? 1 : 0 , "ctu_based_offset_enabled_flag" );
+          if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
+          {
+            WRITE_UVLC( pcVPSVUI->getMinHorizontalCtuOffsetPlus1( i, j ), "min_horizontal_ctu_offset_plus1" );
+          }
+        }
+      }
+    }
+  }
+}
+#endif
+
+#if H_3D
+Void TEncCavlc::codeVPSExtension2( TComVPS* pcVPS )
+{ 
+  for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    if (i!= 0)
+    {
+      if ( !( pcVPS->getDepthId( i ) == 1 ) )
+      {
+#if H_3D_IV_MERGE
+        WRITE_FLAG( pcVPS->getIvMvPredFlag         ( i ) ? 1 : 0 , "iv_mv_pred_flag[i]");
+#endif
+#if H_3D_ARP
+        WRITE_FLAG( pcVPS->getUseAdvRP             ( i ) ? 1 : 0,  "iv_res_pred_flag[i]"  );
+#endif
+#if H_3D_NBDV_REF
+        WRITE_FLAG( pcVPS->getDepthRefinementFlag  ( i ) ? 1 : 0 , "depth_refinement_flag[i]");
+#endif
+#if H_3D_VSP
+        WRITE_FLAG( pcVPS->getViewSynthesisPredFlag( i ) ? 1 : 0 , "view_synthesis_pred_flag[i]");
+#endif
+      }          
+      else
+      {
+        WRITE_FLAG( pcVPS->getVpsDepthModesFlag( i ) ? 1 : 0 ,          "vps_depth_modes_flag[i]" );
+        //WRITE_FLAG( pcVPS->getLimQtPredFlag    ( i ) ? 1 : 0 ,          "lim_qt_pred_flag[i]"     ); 
+#if H_3D_DIM_DLT
+        if( pcVPS->getVpsDepthModesFlag( i ) )
+        {
+          WRITE_FLAG( pcVPS->getUseDLTFlag( i ) ? 1 : 0, "dlt_flag[i]" );
+        }
+        if( pcVPS->getUseDLTFlag( i ) )
+        {
+          // code mapping
+          WRITE_UVLC(pcVPS->getNumDepthValues(i), "num_depth_values_in_dlt[i]");
+          for(Int d=0; d<pcVPS->getNumDepthValues(i); d++)
+          {
+            WRITE_UVLC( pcVPS->idx2DepthValue(i, d), "dlt_depth_value[i][d]" );
+          }
+        }        
+#endif
+#if LGE_INTER_SDC_E0156
+        WRITE_FLAG( pcVPS->getInterSDCFlag( i ) ? 1 : 0, "depth_inter_SDC_flag" );
+#endif
+      }
+    }  
+  }
+#if H_3D_TMVP
+  WRITE_FLAG( pcVPS->getIvMvScalingFlag( ) ? 1 : 0 ,          "iv_mv_scaling_flag" );
+#endif
+}
+#endif
+#endif
 
 Void TEncCavlc::codeSliceHeader         ( TComSlice* pcSlice )
@@ -911,4 +1370,20 @@
   {
 #if H_MV    
+#if H_MV5
+    Int esb = 0;  //Don't use i, otherwise will shadow something below
+    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
+    {
+      esb++; 
+      WRITE_FLAG( pcSlice->getPocResetFlag( ) ? 1 : 0 , "poc_reset_flag" );
+    }
+
+    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
+    {
+      esb++; 
+      WRITE_FLAG( pcSlice->getDiscardableFlag( ) ? 1 : 0 , "discardable_flag" );
+    }
+
+    for (; esb < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)    
+#else
     if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
     {
@@ -917,4 +1392,5 @@
 
     for (Int i = 1; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)    
+#endif
 #else
     for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
@@ -1054,4 +1530,25 @@
     }
 #if H_MV
+#if H_MV5
+    Int layerId = pcSlice->getLayerId(); 
+    if( pcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )
+    {   
+      WRITE_FLAG( pcSlice->getInterLayerPredEnabledFlag( ) ? 1 : 0 , "inter_layer_pred_enabled_flag" );
+      if( pcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerId ) > 1 )
+      {            
+        if( !vps->getMaxOneActiveRefLayerFlag())  
+        {
+          WRITE_CODE( pcSlice->getNumInterLayerRefPicsMinus1( ), pcSlice->getNumInterLayerRefPicsMinus1Len( ), "num_inter_layer_ref_pics_minus1" );
+        }
+        if ( pcSlice->getNumActiveRefLayerPics() != vps->getNumDirectRefLayers( layerId ) )
+        {        
+          for( Int idx = 0; idx < pcSlice->getNumActiveRefLayerPics(); idx++ )   
+          {
+            WRITE_CODE( pcSlice->getInterLayerPredLayerIdc( idx ), pcSlice->getInterLayerPredLayerIdcLen( ), "inter_layer_pred_layer_idc" );
+          }
+        }
+      }  
+    }
+#else
     Int layerIdInVps       = pcSlice->getLayerIdInVps(); 
     if( pcSlice->getLayerId() > 0 && vps->getNumDirectRefLayers( layerIdInVps ) > 0 )
@@ -1076,4 +1573,5 @@
     }
 
+#endif
 #endif
     if(pcSlice->getSPS()->getUseSAO())
@@ -1180,4 +1678,5 @@
     if ( pcSlice->getEnableTMVPFlag() )
     {
+#if !H_MV5
 #if H_MV
       if( pcSlice->getLayerId() > 0 && pcSlice->getNumActiveMotionPredRefLayers() > 0 )
@@ -1192,4 +1691,5 @@
       {
 #endif
+#endif
       if ( pcSlice->getSliceType() == B_SLICE )
       {
@@ -1204,6 +1704,8 @@
       }
     }
+#if !H_MV5
 #if H_MV
     }
+#endif
 #endif
     if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPred() && pcSlice->getSliceType()==B_SLICE) )
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 609)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 622)
@@ -84,6 +84,22 @@
   UInt  getCoeffCost          ()                { return  m_uiCoeffCost;  }
   Void  codeVPS                 ( TComVPS* pcVPS );
+#if H_MV5
+#if H_MV
+  Void  codeVPSExtension       ( TComVPS *pcVPS );
+  Void  codeRepFormat          ( TComRepFormat* pcRepFormat );
+  Void  codeVPSVUI             ( TComVPS* pcVPS );
+#endif 
+#endif
   Void  codeVUI                 ( TComVUI *pcVUI, TComSPS* pcSPS );
+#if H_MV5
+#if H_MV
+  Void  codeSPSExtension        ( TComSPS* pcSPS ); 
+#endif
+#endif
 #if H_3D
+#if H_MV5
+  Void  codeVPSExtension2       ( TComVPS* pcVPS ); 
+  Void  codeSPSExtension2       ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag  ); 
+#endif
   Void  codeSPS                 ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag );
 #else
Index: trunk/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 609)
+++ trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 622)
@@ -77,5 +77,7 @@
   Int m_interLayerPredLayerIdc [MAX_NUM_REF_PICS];
   Int m_interViewRefPosL[2][MAX_NUM_REF_PICS];  
+#if !H_MV5
   Int m_collocatedRefLayerIdx; 
+#endif
 #endif
   GOPEntry()
@@ -95,5 +97,7 @@
 #if H_MV
   , m_numActiveRefLayerPics(0)
+#if !H_MV5
   , m_collocatedRefLayerIdx(-1)
+#endif
 #endif
   {
@@ -357,8 +361,13 @@
   Int       m_layerIdInVps;
   Int       m_viewId;
+#if H_MV5
+  Int       m_viewIndex; 
+#endif
 #endif 
 
 #if H_3D
+#if !H_MV5
   Int       m_viewIndex; 
+#endif
   Bool      m_isDepth;
 
@@ -417,6 +426,11 @@
   , m_layerIdInVps(-1)
   , m_viewId(-1)
+#if H_MV5
+  , m_viewIndex(-1)
+#endif
 #if H_3D
+#if !H_MV5
   , m_viewIndex(-1)
+#endif
   , m_isDepth(false)
   , m_bUseVSO(false)
@@ -451,7 +465,13 @@
   Void      setViewId                        ( Int viewId  )      { m_viewId  = viewId;  }
   Int       getViewId                        ()                   { return m_viewId;    }
-#if H_3D
+#if H_MV5
   Void      setViewIndex                     ( Int viewIndex  )   { m_viewIndex  = viewIndex;  }
   Int       getViewIndex                     ()                   { return m_viewIndex;    }
+#endif
+#if H_3D
+#if !H_MV5
+  Void      setViewIndex                     ( Int viewIndex  )   { m_viewIndex  = viewIndex;  }
+  Int       getViewIndex                     ()                   { return m_viewIndex;    }
+#endif
   Void      setIsDepth                       ( Bool isDepth )   { m_isDepth = isDepth; }
   Bool      getIsDepth                       ()                 { return m_isDepth; }
Index: trunk/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 609)
+++ trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 622)
@@ -416,5 +416,5 @@
 
   Bool    bTrySplitDQP  = true;
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
   DisInfo DvInfo; 
   DvInfo.bDV = false;
@@ -530,13 +530,4 @@
 
 #if H_3D_NBDV
-#if !MTK_VSP_FIX_ALIGN_WD_E0172
-      DisInfo DvInfo; 
-      DvInfo.bDV = false;
-      DvInfo.m_acNBDV.setZero();
-      DvInfo.m_aVIdxCan = 0;
-#if H_3D_NBDV_REF
-      DvInfo.m_acDoNBDV.setZero();
-#endif
-#endif
       if( rpcTempCU->getSlice()->getSliceType() != I_SLICE )
       {
@@ -598,5 +589,5 @@
           xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N
 #endif
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
           rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -611,5 +602,5 @@
 #endif
         rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
         rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -638,5 +629,5 @@
             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
 #endif
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
             rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -725,5 +716,5 @@
 #endif
                 rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
                 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -745,5 +736,5 @@
 #endif
             rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
             rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -765,5 +756,5 @@
 #endif
             rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
             rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -804,5 +795,5 @@
 #endif
                 rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
                 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -824,5 +815,5 @@
 #endif
                 rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
                 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -848,5 +839,5 @@
 #endif
                 rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
                 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -868,5 +859,5 @@
 #endif
                 rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
                 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -894,5 +885,5 @@
 #endif
                 rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
                 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -914,5 +905,5 @@
 #endif
                 rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
                 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -934,5 +925,5 @@
 #endif
                 rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
                 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -954,5 +945,5 @@
 #endif
                 rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
                 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -968,10 +959,10 @@
               xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
               rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
               rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
               xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
               rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
               rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -983,10 +974,10 @@
               xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
               rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
               rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
               xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
               rpcTempCU->initEstData( uiDepth, iQP );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
               rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
 #endif
@@ -1761,16 +1752,6 @@
   Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
   memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
-#if MTK_VSP_FIX_ALIGN_WD_E0172
   InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
   rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag,inheritedVSPDisInfo, numValidMergeCand );
-#else
-#if MTK_VSP_FIX_E0172
-  Int vspDir[MRG_MAX_NUM_CANDS_MEM];
-  memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
-  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag,vspDir, numValidMergeCand );
-#else
-  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag, numValidMergeCand );
-#endif
-#endif//end of MTK_VSP_FIX_ALIGN_WD_E0172
 #else
   rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
@@ -1840,10 +1821,5 @@
 #if H_3D_VSP
           rpcTempCU->setVSPFlagSubParts( vspFlag[uiMergeCand], 0, 0, uhDepth );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
           rpcTempCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeCand].m_acDvInfo, 0, 0, uhDepth );
-#endif
-#if MTK_VSP_FIX_E0172
-          rpcTempCU->setVSPDirSubParts( vspDir[uiMergeCand], 0, 0, uhDepth );
-#endif
 #endif
           rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
Index: trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 609)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 622)
@@ -471,13 +471,26 @@
     pcPic->setCurrSliceIdx(0);
 
+
+#if H_MV5
+#if H_MV
+    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), getLayerId() );     
+#else
+    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
+#endif
+#else
 #if H_3D
     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), getLayerId() );     
 #else
     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
+#endif
 #endif
     pcSlice->setLastIDR(m_iLastIDR);
     pcSlice->setSliceIdx(0);
 #if H_MV
+#if H_MV5
+    pcSlice->setRefPicSetInterLayer ( &m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
+#else
     pcSlice->setRefPicSetInterLayer ( &m_refPicSetInterLayer ); 
+#endif
     pcPic  ->setLayerId     ( getLayerId()   );
     pcPic  ->setViewId      ( getViewId()    );    
@@ -642,4 +655,48 @@
     refPicListModification->setRefPicListModificationFlagL1(0);
 #if H_MV
+#if H_MV5
+    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 1 )
+    {
+      // Some more sophisticated algorithm to determine discardable_flag might be added here. 
+      pcSlice->setDiscardableFlag           ( false );     
+    }    
+
+    TComVPS*           vps = pcSlice->getVPS();     
+    Int numDirectRefLayers = vps    ->getNumDirectRefLayers( getLayerId() ); 
+    GOPEntry gopEntry      = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && getLayerId() > 0) ? MAX_GOP : iGOPid );     
+    
+    if ( getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && numDirectRefLayers > 0 )
+    {         
+      pcSlice->setInterLayerPredEnabledFlag ( gopEntry.m_numActiveRefLayerPics > 0 );     
+      if ( pcSlice->getInterLayerPredEnabledFlag() && numDirectRefLayers > 1 )
+      {
+        if ( !vps->getMaxOneActiveRefLayerFlag() )
+        {    
+          pcSlice->setNumInterLayerRefPicsMinus1( gopEntry.m_numActiveRefLayerPics - 1 ); 
+        }
+        if ( gopEntry.m_numActiveRefLayerPics != vps->getNumDirectRefLayers( getLayerId() ) )
+        {        
+          for (Int i = 0; i < gopEntry.m_numActiveRefLayerPics; i++ )
+          {
+            pcSlice->setInterLayerPredLayerIdc( i, gopEntry.m_interLayerPredLayerIdc[ i ] ); 
+          }
+        }
+      }
+    }
+    assert( pcSlice->getNumActiveRefLayerPics() == gopEntry.m_numActiveRefLayerPics ); 
+    
+    pcSlice->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
+    pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer0.size() + (Int) m_refPicSetInterLayer1.size()) ) );
+    pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer0.size() + (Int) m_refPicSetInterLayer1.size()) ) );
+
+    std::vector< TComPic* >    tempRefPicLists[2];
+    std::vector< Bool     >    usedAsLongTerm [2];
+    Int       numPocTotalCurr;
+
+    pcSlice->getTempRefPicLists( rcListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true );
+    
+
+    xSetRefPicListModificationsMv( tempRefPicLists, pcSlice, iGOPid );    
+#else
     if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
     {
@@ -692,4 +749,5 @@
     }
 
+#endif
 #else
     pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
@@ -702,4 +760,28 @@
 
     //  Set reference list
+#if H_MV5
+#if H_MV    
+    pcSlice->setRefPicList( tempRefPicLists, usedAsLongTerm, numPocTotalCurr ); 
+#else
+    pcSlice->setRefPicList ( rcListPic );
+#endif
+  
+#if H_3D_ARP
+    //GT: This seems to be broken when layerId in vps is not equal to layerId in nuh
+    pcSlice->setARPStepNum();
+    if(pcSlice->getARPStepNum() > 1)
+    {
+      for(Int iLayerId = 0; iLayerId < getLayerId(); iLayerId ++ )
+      {
+        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
+        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
+        if( iViewIdx<getViewIndex() && !bIsDepth )
+        {
+          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
+        }
+      }
+    }
+#endif
+#else
 #if H_MV    
     pcSlice->setRefPicList( rcListPic, m_refPicSetInterLayer );
@@ -722,5 +804,5 @@
     pcSlice->setRefPicList ( rcListPic );
 #endif
-
+#endif
 #if H_3D
     pcSlice->setIvPicLists( m_ivPicLists );         
@@ -1816,5 +1898,9 @@
           digestStr = digestToString(sei_recon_picture_digest.digest, 4);
         }
+#if H_MV_FIX_LID_PIC_HASH_SEI_T40
+        OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer(), getLayerId() );
+#else
         OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer());
+#endif
 
         /* write the SEI messages */
@@ -2080,5 +2166,9 @@
       pcPic->setReconMark   ( true );
 #if H_MV
+#if H_MV5
+      TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 );  
+#else
       TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer );  
+#endif
       std::vector<Int> temp; 
       TComSlice::markCurrPic( pcPic ); 
@@ -2912,4 +3002,89 @@
 
 #if H_MV
+#if H_MV5
+Void TEncGOP::xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid )
+{ 
+  
+  if( pcSlice->getSliceType() == I_SLICE || !(pcSlice->getPPS()->getListsModificationPresentFlag()) || pcSlice->getNumActiveRefLayerPics() == 0 )
+  {
+    return;
+  }
+  
+  GOPEntry ge = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && ( pcSlice->getLayerId( ) > 0) ) ? MAX_GOP : iGOPid );
+  assert( ge.m_numActiveRefLayerPics == pcSlice->getNumActiveRefLayerPics() ); 
+
+  Int numPicsInTempList     = pcSlice->getNumRpsCurrTempList();  
+
+  // GT: check if SliceType should be checked here. 
+  for (Int li = 0; li < 2; li ++) // Loop over lists L0 and L1
+  {
+    Int numPicsInFinalRefList = pcSlice->getNumRefIdx( ( li == 0 ) ? REF_PIC_LIST_0 : REF_PIC_LIST_1 ); 
+            
+    Int finalIdxToTempIdxMap[16];
+    for( Int k = 0; k < 16; k++ )
+    {
+      finalIdxToTempIdxMap[ k ] = -1;
+    }
+
+    Bool isModified = false;
+    if ( numPicsInTempList > 1 )
+    {
+      for( Int k = 0; k < pcSlice->getNumActiveRefLayerPics(); k++ )
+      {
+        // get position in temp. list
+        Int refPicLayerId = pcSlice->getRefPicLayerId(k);
+        Int idxInTempList = 0; 
+        for (; idxInTempList < numPicsInTempList; idxInTempList++)
+        {
+          if ( (tempPicLists[li][idxInTempList])->getLayerId() == refPicLayerId )
+          {
+            break; 
+          }
+        }
+
+        Int idxInFinalList = ge.m_interViewRefPosL[ li ][ k ];
+        
+        // Add negative from behind 
+        idxInFinalList = ( idxInFinalList < 0 )? ( numPicsInTempList + idxInFinalList ) : idxInFinalList; 
+        
+        Bool curIsModified = ( idxInFinalList != idxInTempList ) && ( ( idxInTempList < numPicsInFinalRefList ) || ( idxInFinalList < numPicsInFinalRefList ) ) ;
+        if ( curIsModified )
+        {
+          isModified = true; 
+          assert( finalIdxToTempIdxMap[ idxInFinalList ] == -1 ); // Assert when two inter layer reference pictures are sorted to the same position
+        }
+        finalIdxToTempIdxMap[ idxInFinalList ] = idxInTempList;              
+      }
+    }
+
+    TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
+    refPicListModification->setRefPicListModificationFlagL( li, isModified );  
+
+    if( isModified )
+    {
+      Int refIdx = 0;
+      
+      for( Int i = 0; i < numPicsInFinalRefList; i++ )
+      {
+        if( finalIdxToTempIdxMap[i] >= 0 ) 
+        {
+          refPicListModification->setRefPicSetIdxL( li, i, finalIdxToTempIdxMap[i] );
+        }
+        else
+        {
+          ///* Fill gaps with temporal references *///
+          // Forward inter layer reference pictures
+          while( ( refIdx < numPicsInTempList ) && ( tempPicLists[li][refIdx]->getLayerId() != getLayerId())  )
+          {
+            refIdx++; 
+          }
+          refPicListModification->setRefPicSetIdxL( li, i, refIdx );
+          refIdx++;
+        }
+      }
+    }
+  }
+}
+#else
 Void TEncGOP::xSetRefPicListModificationsMv( TComSlice* pcSlice, UInt iGOPid )
 { 
@@ -2975,3 +3150,4 @@
 }
 #endif
+#endif
 //! \}
Index: trunk/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 609)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 622)
@@ -99,5 +99,10 @@
 #if H_MV
   TComPicLists*           m_ivPicLists;
+#if H_MV5
+  std::vector<TComPic*>   m_refPicSetInterLayer0; 
+  std::vector<TComPic*>   m_refPicSetInterLayer1; 
+#else
   std::vector<TComPic*>   m_refPicSetInterLayer; 
+#endif
 
   Int                     m_pocLastCoded;
@@ -211,5 +216,9 @@
   }
 #if H_MV
+#if H_MV5
+   Void  xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid );
+#else
    Void  xSetRefPicListModificationsMv( TComSlice* pcSlice, UInt iGOPid );
+#endif
 #endif
   Void dblMetric( TComPic* pcPic, UInt uiNumSlices );
Index: trunk/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 609)
+++ trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 622)
@@ -95,5 +95,5 @@
 #if H_3D_DIM_DMM
 , m_cDmm1DataSCModel          ( 1,             1,               NUM_DMM1_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
 , m_cDmm2DataSCModel          ( 1,             1,               NUM_DMM2_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
 #endif
@@ -177,5 +177,5 @@
 #if H_3D_DIM_DMM
   m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   m_cDmm2DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA );
 #endif
@@ -268,5 +268,5 @@
 #if H_3D_DIM_DMM
       curCost += m_cDmm1DataSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_DMM1_DATA );
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
       curCost += m_cDmm2DataSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_DMM2_DATA );
 #endif
@@ -340,5 +340,5 @@
 #if H_3D_DIM_DMM
   m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   m_cDmm2DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA );
 #endif
@@ -549,5 +549,5 @@
 }
 
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
 Void TEncSbac::xCodeDmm2Offset( Int iOffset )
 {
@@ -649,4 +649,7 @@
   // residual flag
   m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
+#if H_MV_ENC_DEC_TRAC
+  DTRACE_CU("sdc_residual_flag[i]", uiResidual)
+#endif  
   
   if (uiResidual)
@@ -654,4 +657,7 @@
     // encode sign bit of residual
     m_pcBinIf->encodeBinEP( uiSign );
+#if H_MV_ENC_DEC_TRAC
+    DTRACE_CU("sdc_residual_sign_flag[i]", uiSign)
+#endif
     
 #if H_3D_DIM_DLT
@@ -664,7 +670,14 @@
     // encode residual magnitude
     uiAbsIdx -= 1;
+
+#if H_MV_ENC_DEC_TRAC
+    DTRACE_CU("sdc_residual_abs_minus1[i]", uiAbsIdx)
+#endif
+
     // prefix part
     if ( uiAbsIdx == 0 )
+    {
       m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) );
+    }
     else
     {
@@ -679,8 +692,9 @@
       }
       if ( uiAbsIdx < uiPrefixThreshold )
+      {
         m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) );
-      // suffix part
+      }      
       else
-      {
+      { // suffix part
         uiAbsIdx -= uiPrefixThreshold;
         UInt uiSuffixLength = numBitsForValue(uiNumDepthValues - uiPrefixThreshold);
@@ -1226,5 +1240,5 @@
       xCodeDmm1WedgeIdx( pcCU->getDmmWedgeTabIdx( dimType, absPartIdx ), g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
     } break;
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   case( DMM2_IDX ):
     {
@@ -1285,5 +1299,5 @@
 #else
 #if LGE_SDC_REMOVE_DC_E0158
-#if SEC_DMM2_E0146
+#if SEC_DMM2_E0146_HHIFIX
   UInt codeWordTable[3][7] =    {{0, 0, 0, 2, 0,6, 7},{0, 2, 3, 4, 5, 6, 7},{0, 1, 0, 0, 0, 0, 0}};
   UInt codeWordLenTable[3][7] = {{0, 1, 0, 2, 0,3, 3},{2, 3, 3, 3, 3, 3, 3},{1, 1, 0, 0, 0, 0, 0}};
@@ -1293,5 +1307,5 @@
 #endif
 #else
-#if SEC_DMM2_E0146
+#if SEC_DMM2_E0146_HHIFIX
   UInt codeWordTable[3][8] =    {{0, 0, 0, 2, 0,6, 0, 7},{0, 2, 3, 4, 5, 6, 14, 15},{0, 2, 0, 0, 0, 0, 3, 0}};
   UInt codeWordLenTable[3][8] = {{0, 1, 0, 2, 0,3, 0, 3},{2, 3, 3, 3, 3, 3,  4,  4},{1, 2, 0, 0, 0, 0, 2, 0}};
@@ -1318,5 +1332,5 @@
     case DMM3_IDX: codeIdx = 5; break;
 #if LGE_SDC_REMOVE_DC_E0158
-#if SEC_DMM2_E0146
+#if SEC_DMM2_E0146_HHIFIX
     case  RBC_IDX: codeIdx = 6; break;
 #else
@@ -1325,5 +1339,5 @@
 #endif
 #else
-#if SEC_DMM2_E0146
+#if SEC_DMM2_E0146_HHIFIX
     case  RBC_IDX: codeIdx = 7; break;
 #else
Index: trunk/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSbac.h	(revision 609)
+++ trunk/source/Lib/TLibEncoder/TEncSbac.h	(revision 622)
@@ -121,5 +121,5 @@
 #if H_3D_DIM_DMM
   Void  xCodeDmm1WedgeIdx    ( UInt uiTabIdx, Int iNumBit );
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   Void  xCodeDmm2Offset      ( Int iOffset );
 #endif
@@ -256,5 +256,5 @@
 #if H_3D_DIM_DMM
   ContextModel3DBuffer m_cDmm1DataSCModel;
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   ContextModel3DBuffer m_cDmm2DataSCModel;
 #endif
Index: trunk/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 609)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 622)
@@ -2851,5 +2851,5 @@
     {
 
-#if SCU_HS_FAST_DEPTH_INTRA_E0238
+#if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
       Int  threshold    = max(((pcCU->getQP(0))>>3)-1,3);
       Int  varThreshold = (Int)( threshold * threshold - 8 );
@@ -2857,9 +2857,8 @@
 #endif
 
-
 #if H_3D_DIM_DMM
       if( m_pcEncCfg->getUseDMM()
-#if SCU_HS_FAST_DEPTH_INTRA_E0238
-         && (uiRdModeList[0] != 0 || varCU >= varThreshold)
+#if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
+         && (uiRdModeList[0] != PLANAR_IDX || varCU >= varThreshold)
 #endif
         )
@@ -2878,5 +2877,5 @@
               biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]);
             } break;
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
           case( DMM2_IDX ):
             {
@@ -2893,5 +2892,5 @@
           case( DMM3_IDX ):
             {
-#if LGE_PKU_DMM3_OVERLAP_E0159
+#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
               TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
               TComDataCU* pcColTexCU = pcPicTex->getCU( pcCU->getAddr() );
@@ -2903,9 +2902,13 @@
 #endif
               UInt uiIntraTabIdx = 0;
+#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
+              xSearchDmm3Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx, uiIntraTabIdx, uiColTexIntraDir );
+#else
               xSearchDmm3Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx, uiIntraTabIdx );
+#endif
               pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dmmType, uiPartOffset, uiDepth + uiInitTrDepth );
               pcCU->setDmm3IntraTabIdxSubParts( uiIntraTabIdx, uiPartOffset, uiDepth + uiInitTrDepth );
               biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]);
-#if LGE_PKU_DMM3_OVERLAP_E0159
+#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
               }
 #endif
@@ -2938,6 +2941,6 @@
 #if H_3D_DIM_RBC
       if( m_pcEncCfg->getUseRBC()
-#if SCU_HS_FAST_DEPTH_INTRA_E0238
-          && (uiRdModeList[0] != 0 || varCU >= varThreshold)
+#if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
+          && (uiRdModeList[0] != PLANAR_IDX || varCU >= varThreshold)
 #endif
         )
@@ -3600,10 +3603,5 @@
 #if H_3D_VSP
                                  , Int* vspFlag
-#if MTK_VSP_FIX_ALIGN_WD_E0172
                                  , InheritedVSPDisInfo*  inheritedVSPDisInfo
-#endif
-#if MTK_VSP_FIX_E0172
-                                 , Int* vspDir
-#endif
 #endif
                                  , Int& numValidMergeCand
@@ -3625,10 +3623,5 @@
 #if H_3D_VSP
                                    , vspFlag
-#if MTK_VSP_FIX_ALIGN_WD_E0172
                                    , inheritedVSPDisInfo
-#endif
-#if MTK_VSP_FIX_E0172
-                                   , vspDir
-#endif
 #endif
                                    , numValidMergeCand
@@ -3642,19 +3635,15 @@
 #if H_3D_VSP
                                  , vspFlag
-#if MTK_VSP_FIX_ALIGN_WD_E0172
                                  , inheritedVSPDisInfo
-#endif
-#if MTK_VSP_FIX_E0172
-                                 , vspDir
-#endif
 #endif
                                  , numValidMergeCand
                                  );
   }
-#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
   xRestrictBipredMergeCand( pcCU, iPUIdx, cMvFieldNeighbours, uhInterDirNeighbours,vspFlag, numValidMergeCand );
 #else
   xRestrictBipredMergeCand( pcCU, iPUIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
 #endif
+
 
   ruiCost = MAX_UINT;
@@ -3672,10 +3661,5 @@
 #if H_3D_VSP
       pcCU->setVSPFlagSubParts( vspFlag[uiMergeCand], uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
       pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeCand].m_acDvInfo, uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
-#endif
-#if MTK_VSP_FIX_E0172
-      pcCU->setVSPDirSubParts( vspDir[uiMergeCand], uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
-#endif
 #endif
 
@@ -3707,5 +3691,5 @@
  * \returns Void
  */
-#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
 Void TEncSearch::xRestrictBipredMergeCand( TComDataCU* pcCU, UInt puIdx, TComMvField* mvFieldNeighbours, UChar* interDirNeighbours, Int* vspFlag, Int numValidMergeCand )
 #else
@@ -3717,5 +3701,5 @@
     for( UInt mergeCand = 0; mergeCand < numValidMergeCand; ++mergeCand )
     {
-#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
       if ( (interDirNeighbours[mergeCand] == 3) && (vspFlag[mergeCand] == false) )
 #else
@@ -3848,7 +3832,4 @@
 #if H_3D_VSP
     pcCU->setVSPFlagSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr) );
-#if MTK_VSP_FIX_E0172
-    pcCU->setVSPDirSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr) );
-#endif
 #endif
     
@@ -4346,5 +4327,4 @@
       Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
       memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
-#if MTK_VSP_FIX_ALIGN_WD_E0172
       InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
       UInt uiAbsPartIdx = 0;
@@ -4354,19 +4334,9 @@
       DisInfo OriginalDvInfo = pcCU->getDvInfo(uiAbsPartIdx);
 #endif
-#if MTK_VSP_FIX_E0172
-      Int vspDir[MRG_MAX_NUM_CANDS_MEM];
-      memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
-#endif
-#endif
 
       xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost, cMvFieldNeighbours, uhInterDirNeighbours
 #if H_3D_VSP
                       , vspFlag
-#if MTK_VSP_FIX_ALIGN_WD_E0172
                       , inheritedVSPDisInfo
-#endif
-#if MTK_VSP_FIX_E0172
-                      , vspDir
-#endif
 #endif
                       , numValidMergeCand
@@ -4379,10 +4349,5 @@
 #if H_3D_VSP
         pcCU->setVSPFlagSubParts( vspFlag[uiMRGIndex], uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
         pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMRGIndex].m_acDvInfo, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
-#endif
-#if MTK_VSP_FIX_E0172
-        pcCU->setVSPDirSubParts( vspDir[uiMRGIndex], uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
-#endif
 #endif
         pcCU->setInterDirSubParts  ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
@@ -4407,10 +4372,5 @@
 #if H_3D_VSP
         pcCU->setVSPFlagSubParts ( 0,             uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
-#if MTK_VSP_FIX_ALIGN_WD_E0172
         pcCU->setDvInfoSubParts(OriginalDvInfo, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
-#endif
-#if MTK_VSP_FIX_E0172
-        pcCU->setVSPDirSubParts ( 0,             uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
-#endif
 #endif
         {
@@ -7361,5 +7321,5 @@
 }
 
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
 Void TEncSearch::xSearchDmm2Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, Int& riWedgeDeltaEnd )
 {
@@ -7429,5 +7389,6 @@
 #endif
 
-Void TEncSearch::xSearchDmm3Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx )
+#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
+Void TEncSearch::xSearchDmm3Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx, UInt colTexIntraDir )
 {
   ruiTabIdx       = 0;
@@ -7446,4 +7407,41 @@
   Pel refDC1 = 0; Pel refDC2 = 0;
 
+  std::vector< std::vector<UInt> > pauiWdgLstSz = g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]];
+  std::vector<UInt>* pauiWdgLst = &pauiWdgLstSz[colTexIntraDir-2];
+  for( UInt uiIdxW = 0; uiIdxW < pauiWdgLst->size(); uiIdxW++ )
+  {
+    UInt uiIdx     =   pauiWdgLst->at(uiIdxW);
+    TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiIdx));
+    xCalcBiSegDCs  ( piRef,  uiRefStride,  pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
+    xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
+
+    UInt uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
+    if( uiActDist < uiBestDist || uiBestDist == MAX_UINT )
+    {
+      uiBestDist     = uiActDist;
+      ruiTabIdx      = uiIdx;
+      ruiIntraTabIdx = uiIdxW;
+    }
+  }
+  cPredYuv.destroy();
+}
+#else
+Void TEncSearch::xSearchDmm3Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx )
+{
+  ruiTabIdx       = 0;
+  ruiIntraTabIdx  = 0;
+
+  // local pred buffer
+  TComYuv cPredYuv; 
+  cPredYuv.create( uiWidth, uiHeight ); 
+  cPredYuv.clear();
+  Pel* piPred = cPredYuv.getLumaAddr();
+  UInt uiPredStride = cPredYuv.getStride();
+
+  // wedge search
+  UInt uiBestDist = MAX_UINT;
+  WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
+  Pel refDC1 = 0; Pel refDC2 = 0;
+
   TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
   assert( pcPicTex != NULL );
@@ -7496,4 +7494,5 @@
   cPredYuv.destroy();
 }
+#endif
 #endif
 #if H_3D_DIM_RBC
Index: trunk/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 609)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 622)
@@ -352,8 +352,12 @@
   Void xSearchDmmDeltaDCs         ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piOrig, Pel* piPredic, UInt uiStride, Bool* biSegPattern, Int patternStride, UInt uiWidth, UInt uiHeight, Pel& rDeltaDC1, Pel& rDeltaDC2 );
   Void xSearchDmm1Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx );
-#if !SEC_DMM2_E0146
+#if !SEC_DMM2_E0146_HHIFIX
   Void xSearchDmm2Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, Int& riWedgeDeltaEnd );
 #endif
+#if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
+  Void xSearchDmm3Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx, UInt colTexIntraDir );
+#else
   Void xSearchDmm3Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx );
+#endif
 #endif
 #if H_3D_DIM_RBC
@@ -427,10 +431,5 @@
 #if H_3D_VSP
                                   , Int* vspFlag
-#if MTK_VSP_FIX_ALIGN_WD_E0172
                                   , InheritedVSPDisInfo*  inheritedVSPDisInfo
-#endif
-#if MTK_VSP_FIX_E0172
-                                  , Int* vspDir
-#endif
 #endif
                                   , Int& numValidMergeCand
@@ -441,5 +440,5 @@
                                     TComMvField*    mvFieldNeighbours, 
                                     UChar*          interDirNeighbours, 
-#if MTK_VSP_FIX_E0172 || MTK_VSP_FIX_ALIGN_WD_E0172
+#if H_3D_VSP
                                     Int* vspFlag,
 #endif
Index: trunk/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 609)
+++ trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 622)
@@ -176,8 +176,16 @@
  \param pPPS          PPS associated with the slice
  */
+#if H_MV5
+#if H_MV
+Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId )
+#else
+Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
+#endif
+#else
 #if H_3D
 Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId )
 #else
 Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
+#endif
 #endif
 {
@@ -186,4 +194,15 @@
   
   rpcSlice = pcPic->getSlice(0);
+
+#if H_MV5
+  rpcSlice->setVPS( pVPS ); 
+
+  rpcSlice->setLayerId     ( layerId );
+  rpcSlice->setViewId      ( pVPS->getViewId      ( layerId ) );    
+  rpcSlice->setViewIndex   ( pVPS->getViewIndex   ( layerId ) );
+#if H_3D
+  rpcSlice->setIsDepth     ( pVPS->getDepthId     ( layerId ) != 0 );    
+#endif
+#else
 #if H_3D
   // GT: Should also be activated for MV-HEVC at some stage
@@ -195,4 +214,5 @@
   rpcSlice->setViewIndex   ( pVPS->getViewIndex   ( vpsLayerId ) );
   rpcSlice->setIsDepth     ( pVPS->getDepthId     ( vpsLayerId ) != 0 );    
+#endif
 #endif
   rpcSlice->setSPS( pSPS );
Index: trunk/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSlice.h	(revision 609)
+++ trunk/source/Lib/TLibEncoder/TEncSlice.h	(revision 622)
@@ -116,4 +116,13 @@
   
   /// preparation of slice encoding (reference marking, QP and lambda)
+#if H_MV5
+#if H_MV
+  Void    initEncSlice        ( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, 
+                                Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId ); 
+#else
+  Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
+                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
+#endif
+#else
 #if H_3D
   Void    initEncSlice        ( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, 
@@ -122,4 +131,5 @@
   Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
                                 Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
+#endif
 #endif
 #if RATE_CONTROL_LAMBDA_DOMAIN
Index: trunk/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 609)
+++ trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 622)
@@ -515,5 +515,8 @@
   // mark it should be extended
   rpcPic->getPicYuvRec()->setBorderExtension(false);
+
+#if H_MV
   rpcPic->getPicYuvOrg()->setBorderExtension(false);
+#endif
 }
 
@@ -548,4 +551,11 @@
    * that chooses the actual compatibility based upon options */
 
+#if H_MV5
+#if H_MV  
+  m_cSPS.setUpdateRepFormatFlag           ( m_layerId == 0 );    
+  m_cSPS.setSpsInferScalingListFlag       ( m_layerId > 0 && m_cVPS->getInDirectDependencyFlag( getLayerIdInVps(), 0 ) ); 
+  m_cSPS.setSpsScalingListRefLayerId      ( 0              ); 
+#endif
+#endif
   m_cSPS.setPicWidthInLumaSamples         ( m_iSourceWidth      );
   m_cSPS.setPicHeightInLumaSamples        ( m_iSourceHeight     );
@@ -670,5 +680,10 @@
 {
 #if H_MV
+#if H_MV5
+  m_cPPS.setLayerId( getLayerId() );
+  if( getVPS()->getNumDirectRefLayers( getLayerId() ) > 0 )
+#else
   if( getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) > 0 )
+#endif
   {
     m_cPPS.setListsModificationPresentFlag( true );
@@ -736,23 +751,12 @@
   m_cPPS.setOutputFlagPresentFlag( false );
 #if H_MV
+#if H_MV5
+  m_cPPS.setNumExtraSliceHeaderBits( 2 ); 
+#else
   m_cPPS.setNumExtraSliceHeaderBits( 1 ); 
 #endif
+#endif
   m_cPPS.setSignHideFlag(getSignHideFlag());
-#if L0386_DB_METRIC
-  if ( getDeblockingFilterMetric() )
-  {
-    m_cPPS.setDeblockingFilterControlPresentFlag (true);
-    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
-    m_cPPS.setPicDisableDeblockingFilterFlag(false);
-    m_cPPS.setDeblockingFilterBetaOffsetDiv2(0);
-    m_cPPS.setDeblockingFilterTcOffsetDiv2(0);
-  } 
-  else
-  {
   m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
-  }
-#else
-  m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
-#endif
   m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
   m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
Index: trunk/source/Lib/TLibExtractor/TExtrTop.cpp
===================================================================
--- trunk/source/Lib/TLibExtractor/TExtrTop.cpp	(revision 609)
+++ trunk/source/Lib/TLibExtractor/TExtrTop.cpp	(revision 622)
@@ -100,4 +100,19 @@
 Void TExtrTop::dumpVpsInfo( std::ostream& rcVpsInfoHandle )
 { 
+#if H_MV5
+  rcVpsInfoHandle << "MaxLayers      = " << m_cVPS.getMaxLayersMinus1() + 1 << std::endl; 
+  rcVpsInfoHandle << "MaxNuhLayerId  = " << m_cVPS.getVpsMaxLayerId() << std::endl;                      
+
+  for ( Int layerIdxInVps = 0; layerIdxInVps <= m_cVPS.getMaxLayersMinus1(); layerIdxInVps++ )
+  {  
+    Int layerId = m_cVPS.getLayerIdInNuh( layerIdxInVps ); 
+    rcVpsInfoHandle << "LayerIdxInVps  = " << layerIdxInVps                       << std::endl; 
+    rcVpsInfoHandle << "LayerIdInNuh   = " << layerId                             << std::endl; 
+    rcVpsInfoHandle << "ViewOrderIndex = " << m_cVPS.getViewIndex     ( layerId ) << std::endl;     
+#if H_3D    
+    rcVpsInfoHandle << "DepthFlag      = " << m_cVPS.getDepthId       ( layerId ) << std::endl;     
+#endif
+    rcVpsInfoHandle << "ViewId         = " << m_cVPS.getViewId        ( layerId ) << std::endl;     
+#else
   rcVpsInfoHandle << "MaxLayers = "     << m_cVPS.getMaxLayers()     << std::endl; 
   rcVpsInfoHandle << "MaxNuhLayerId = " << m_cVPS.getVpsMaxLayerId() << std::endl; 
@@ -112,4 +127,5 @@
     rcVpsInfoHandle << "DepthFlag = "      << m_cVPS.getDepthId     ( layerIdxInVps ) << std::endl;     
 #endif
+#endif
   }
 }
