Index: /trunk/cfg/encoder_lowdelay_P_main.cfg
===================================================================
--- /trunk/cfg/encoder_lowdelay_P_main.cfg	(revision 441)
+++ /trunk/cfg/encoder_lowdelay_P_main.cfg	(revision 442)
@@ -22,9 +22,9 @@
 DecodingRefreshType           : 0           # Random Accesss 0:none, 1:CDR, 2:IDR
 GOPSize                       : 4           # 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 
-Frame1:  P    1   3        0.4624   0            0               0           4                4         -1 -5 -9 -13       0
-Frame2:  P    2   2        0.4624   0            0               0           4                4         -1 -2 -6 -10       1      -1       5         1 1 1 0 1
-Frame3:  P    3   3        0.4624   0            0               0           4                4         -1 -3 -7 -11       1      -1       5         0 1 1 1 1            
-Frame4:  P    4   1        0.578    0            0               0           4                4         -1 -4 -8 -12       1      -1       5         0 1 1 1 1
+#        Type POC QPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2  temporal_id #ref_pics_active #ref_pics reference pictures predict deltaRPS #ref_idcs reference idcs #UseExtUsedByCurr  ExtUsedByCurr(for each ref pic)
+Frame1:  P    1   3        0.4624   0            0               0           4                4         -1 -5 -9 -13       0                                           0
+Frame2:  P    2   2        0.4624   0            0               0           4                4         -1 -2 -6 -10       1      -1       5         1 1 1 0 1         0
+Frame3:  P    3   3        0.4624   0            0               0           4                4         -1 -3 -7 -11       1      -1       5         0 1 1 1 1         0
+Frame4:  P    4   1        0.578    0            0               0           4                4         -1 -4 -8 -12       1      -1       5         0 1 1 1 1         0
 
 #=========== Motion Search =============
Index: /trunk/cfg/encoder_lowdelay_P_main10.cfg
===================================================================
--- /trunk/cfg/encoder_lowdelay_P_main10.cfg	(revision 441)
+++ /trunk/cfg/encoder_lowdelay_P_main10.cfg	(revision 442)
@@ -22,9 +22,9 @@
 DecodingRefreshType           : 0           # Random Accesss 0:none, 1:CDR, 2:IDR
 GOPSize                       : 4           # 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 
-Frame1:  P    1   3        0.4624   0            0               0           4                4         -1 -5 -9 -13       0
-Frame2:  P    2   2        0.4624   0            0               0           4                4         -1 -2 -6 -10       1      -1       5         1 1 1 0 1
-Frame3:  P    3   3        0.4624   0            0               0           4                4         -1 -3 -7 -11       1      -1       5         0 1 1 1 1            
-Frame4:  P    4   1        0.578    0            0               0           4                4         -1 -4 -8 -12       1      -1       5         0 1 1 1 1
+#        Type POC QPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2  temporal_id #ref_pics_active #ref_pics reference pictures predict deltaRPS #ref_idcs reference idcs #UseExtUsedByCurr  ExtUsedByCurr(for each ref pic)
+Frame1:  P    1   3        0.4624   0            0               0           4                4         -1 -5 -9 -13       0                                           0
+Frame2:  P    2   2        0.4624   0            0               0           4                4         -1 -2 -6 -10       1      -1       5         1 1 1 0 1         0
+Frame3:  P    3   3        0.4624   0            0               0           4                4         -1 -3 -7 -11       1      -1       5         0 1 1 1 1         0
+Frame4:  P    4   1        0.578    0            0               0           4                4         -1 -4 -8 -12       1      -1       5         0 1 1 1 1         0
 
 #=========== Motion Search =============
Index: /trunk/cfg/encoder_lowdelay_main.cfg
===================================================================
--- /trunk/cfg/encoder_lowdelay_main.cfg	(revision 441)
+++ /trunk/cfg/encoder_lowdelay_main.cfg	(revision 442)
@@ -22,9 +22,9 @@
 DecodingRefreshType           : 0           # Random Accesss 0:none, 1:CDR, 2:IDR
 GOPSize                       : 4           # 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 
-Frame1:  B    1   3        0.4624   0            0               0           4                4         -1 -5 -9 -13       0
-Frame2:  B    2   2        0.4624   0            0               0           4                4         -1 -2 -6 -10       1      -1       5         1 1 1 0 1
-Frame3:  B    3   3        0.4624   0            0               0           4                4         -1 -3 -7 -11       1      -1       5         0 1 1 1 1            
-Frame4:  B    4   1        0.578    0            0               0           4                4         -1 -4 -8 -12       1      -1       5         0 1 1 1 1
+#        Type POC QPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2  temporal_id #ref_pics_active #ref_pics reference pictures predict deltaRPS #ref_idcs reference idcs #UseExtUsedByCurr  ExtUsedByCurr(for each ref pic)
+Frame1:  B    1   3        0.4624   0            0               0           4                4         -1 -5 -9 -13       0                                           0
+Frame2:  B    2   2        0.4624   0            0               0           4                4         -1 -2 -6 -10       1      -1       5         1 1 1 0 1         0
+Frame3:  B    3   3        0.4624   0            0               0           4                4         -1 -3 -7 -11       1      -1       5         0 1 1 1 1         0
+Frame4:  B    4   1        0.578    0            0               0           4                4         -1 -4 -8 -12       1      -1       5         0 1 1 1 1         0
 
 #=========== Motion Search =============
Index: /trunk/cfg/encoder_lowdelay_main10.cfg
===================================================================
--- /trunk/cfg/encoder_lowdelay_main10.cfg	(revision 441)
+++ /trunk/cfg/encoder_lowdelay_main10.cfg	(revision 442)
@@ -22,9 +22,9 @@
 DecodingRefreshType           : 0           # Random Accesss 0:none, 1:CDR, 2:IDR
 GOPSize                       : 4           # 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 
-Frame1:  B    1   3        0.4624   0            0               0           4                4         -1 -5 -9 -13       0
-Frame2:  B    2   2        0.4624   0            0               0           4                4         -1 -2 -6 -10       1      -1       5         1 1 1 0 1
-Frame3:  B    3   3        0.4624   0            0               0           4                4         -1 -3 -7 -11       1      -1       5         0 1 1 1 1            
-Frame4:  B    4   1        0.578    0            0               0           4                4         -1 -4 -8 -12       1      -1       5         0 1 1 1 1
+#        Type POC QPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2  temporal_id #ref_pics_active #ref_pics reference pictures predict deltaRPS #ref_idcs reference idcs #UseExtUsedByCurr  ExtUsedByCurr(for each ref pic)
+Frame1:  B    1   3        0.4624   0            0               0           4                4         -1 -5 -9 -13       0                                           0
+Frame2:  B    2   2        0.4624   0            0               0           4                4         -1 -2 -6 -10       1      -1       5         1 1 1 0 1         0
+Frame3:  B    3   3        0.4624   0            0               0           4                4         -1 -3 -7 -11       1      -1       5         0 1 1 1 1         0
+Frame4:  B    4   1        0.578    0            0               0           4                4         -1 -4 -8 -12       1      -1       5         0 1 1 1 1         0
 
 #=========== Motion Search =============
Index: /trunk/cfg/encoder_randomaccess_main.cfg
===================================================================
--- /trunk/cfg/encoder_randomaccess_main.cfg	(revision 441)
+++ /trunk/cfg/encoder_randomaccess_main.cfg	(revision 442)
@@ -22,22 +22,22 @@
 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 
-Frame1:  B    8   1        0.442    0            0              0           4                4         -8 -10 -12 -16         0
-Frame2:  B    4   2        0.3536   0            0              0           2                3         -4 -6  4               1       4        5         1 1 0 0 1
-Frame3:  B    2   3        0.3536   0            0              0           2                4         -2 -4  2 6             1       2        4         1 1 1 1  
-Frame4:  B    1   4        0.68     0            0              0           2                4         -1  1  3 7             1       1        5         1 0 1 1 1 
-Frame5:  B    3   4        0.68     0            0              0           2                4         -1 -3  1 5             1      -2        5         1 1 1 1 0
-Frame6:  B    6   3        0.3536   0            0              0           2                4         -2 -4 -6 2             1      -3        5         1 1 1 1 0
-Frame7:  B    5   4        0.68     0            0              0           2                4         -1 -5  1 3             1       1        5         1 0 1 1 1  
-Frame8:  B    7   4        0.68     0            0              0           2                4         -1 -3 -7 1             1      -2        5         1 1 1 1 0
+#        Type POC QPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active #ref_pics reference pictures     predict deltaRPS #ref_idcs reference idcs #UseExtUsedByCurr  ExtUsedByCurr(for each ref pic)
+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
 
-FrameEL1:  B    8   1        0.442    0            0              0           4                4         -8 -10 -12 -16         0
-FrameEL2:  B    4   2        0.3536   0            0              0           2                3         -4 -6  4               1       4        5         1 1 0 0 1
-FrameEL3:  B    2   3        0.3536   0            0              0           2                4         -2 -4  2 6             1       2        4         1 1 1 1
-FrameEL4:  B    1   4        0.68     0            0              0           2                4         -1  1  3 7             1       1        5         1 0 1 1 1
-FrameEL5:  B    3   4        0.68     0            0              0           2                4         -1 -3  1 5             1      -2        5         1 1 1 1 0
-FrameEL6:  B    6   3        0.3536   0            0              0           2                4         -2 -4 -6 2             0
-FrameEL7:  B    5   4        0.68     0            0              0           2                4         -1 -5  1 3             0
-FrameEL8:  B    7   4        0.68     0            0              0           2                4         -1 -3 -7 1             0
+FrameEL1:  B    8   1        0.442    0            0              0           4                4         -8 -10 -12 -16         0                                          0
+FrameEL2:  B    4   2        0.3536   0            0              0           2                3         -4 -6  4               1       4        5         1 1 0 0 1       0
+FrameEL3:  B    2   3        0.3536   0            0              0           2                4         -2 -4  2 6             1       2        4         1 1 1 1         0
+FrameEL4:  B    1   4        0.68     0            0              0           2                4         -1  1  3 7             1       1        5         1 0 1 1 1       0
+FrameEL5:  B    3   4        0.68     0            0              0           2                4         -1 -3  1 5             1      -2        5         1 1 1 1 0       0
+FrameEL6:  B    6   3        0.3536   0            0              0           2                4         -2 -4 -6 2             0                                          1    1 1 0 1
+FrameEL7:  B    5   4        0.68     0            0              0           2                4         -1 -5  1 3             0                                          0
+FrameEL8:  B    7   4        0.68     0            0              0           2                4         -1 -3 -7 1             0                                          1    1 1 0 1
 #=========== Motion Search =============
 FastSearch                    : 1           # 0:Full search  1:TZ search
Index: /trunk/cfg/encoder_randomaccess_main10.cfg
===================================================================
--- /trunk/cfg/encoder_randomaccess_main10.cfg	(revision 441)
+++ /trunk/cfg/encoder_randomaccess_main10.cfg	(revision 442)
@@ -22,22 +22,22 @@
 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 
-Frame1:  B    8   1        0.442    0            0              0           4                4         -8 -10 -12 -16         0
-Frame2:  B    4   2        0.3536   0            0              0           2                3         -4 -6  4               1       4        5         1 1 0 0 1
-Frame3:  B    2   3        0.3536   0            0              0           2                4         -2 -4  2 6             1       2        4         1 1 1 1  
-Frame4:  B    1   4        0.68     0            0              0           2                4         -1  1  3 7             1       1        5         1 0 1 1 1 
-Frame5:  B    3   4        0.68     0            0              0           2                4         -1 -3  1 5             1      -2        5         1 1 1 1 0
-Frame6:  B    6   3        0.3536   0            0              0           2                4         -2 -4 -6 2             1      -3        5         1 1 1 1 0
-Frame7:  B    5   4        0.68     0            0              0           2                4         -1 -5  1 3             1       1        5         1 0 1 1 1  
-Frame8:  B    7   4        0.68     0            0              0           2                4         -1 -3 -7 1             1      -2        5         1 1 1 1 0
+#        Type POC QPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active #ref_pics reference pictures     predict deltaRPS #ref_idcs reference idcs #UseExtUsedByCurr  ExtUsedByCurr(for each ref pic)
+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
 
-FrameEL1:  B    8   1        0.442    0            0              0           4                4         -8 -10 -12 -16         0
-FrameEL2:  B    4   2        0.3536   0            0              0           2                3         -4 -6  4               1       4        5         1 1 0 0 1
-FrameEL3:  B    2   3        0.3536   0            0              0           2                4         -2 -4  2 6             1       2        4         1 1 1 1
-FrameEL4:  B    1   4        0.68     0            0              0           2                4         -1  1  3 7             1       1        5         1 0 1 1 1
-FrameEL5:  B    3   4        0.68     0            0              0           2                4         -1 -3  1 5             1      -2        5         1 1 1 1 0
-FrameEL6:  B    6   3        0.3536   0            0              0           2                4         -2 -4 -6 2             0
-FrameEL7:  B    5   4        0.68     0            0              0           2                4         -1 -5  1 3             0
-FrameEL8:  B    7   4        0.68     0            0              0           2                4         -1 -3 -7 1             0
+FrameEL1:  B    8   1        0.442    0            0              0           4                4         -8 -10 -12 -16         0                                          0
+FrameEL2:  B    4   2        0.3536   0            0              0           2                3         -4 -6  4               1       4        5         1 1 0 0 1       0
+FrameEL3:  B    2   3        0.3536   0            0              0           2                4         -2 -4  2 6             1       2        4         1 1 1 1         0
+FrameEL4:  B    1   4        0.68     0            0              0           2                4         -1  1  3 7             1       1        5         1 0 1 1 1       0
+FrameEL5:  B    3   4        0.68     0            0              0           2                4         -1 -3  1 5             1      -2        5         1 1 1 1 0       0
+FrameEL6:  B    6   3        0.3536   0            0              0           2                4         -2 -4 -6 2             0                                          1    1 1 0 1
+FrameEL7:  B    5   4        0.68     0            0              0           2                4         -1 -5  1 3             0                                          0
+FrameEL8:  B    7   4        0.68     0            0              0           2                4         -1 -3 -7 1             0                                          1    1 1 0 1
 #=========== Motion Search =============
 FastSearch                    : 1           # 0:Full search  1:TZ search
Index: /trunk/cfg/layers.cfg
===================================================================
--- /trunk/cfg/layers.cfg	(revision 441)
+++ /trunk/cfg/layers.cfg	(revision 442)
@@ -1,11 +1,11 @@
 NumLayers                     : 2
 AvcBase                       : 0
-ScalabilityMask0              : 0           # Multiview
-ScalabilityMask1              : 1           # Scalable
+ScalabilityMask1              : 0           # Multiview
+ScalabilityMask2              : 1           # Scalable
 AdaptiveResolutionChange      : 0           # Resolution change frame (0: disable)
-
+MaxTidRefPresentFlag          : 1           # max_tid_ref_present_flag (0=not present, 1=present(default))
 #============= LAYER 0 ==================
 QP0                           : 22
-
+MaxTidIlRefPicsPlus10         : 1           # max_tid_il_ref_pics_plus1 for layer0
 #============ Rate Control ==============
 RateControl0                  : 0           # Rate control: enable rate control for layer 0
Index: /trunk/cfg/layers_avcbase.cfg
===================================================================
--- /trunk/cfg/layers_avcbase.cfg	(revision 441)
+++ /trunk/cfg/layers_avcbase.cfg	(revision 442)
@@ -1,6 +1,6 @@
 NumLayers                     : 2
 AvcBase                       : 1
-ScalabilityMask0              : 0           # Multiview
-ScalabilityMask1              : 1           # Scalable
+ScalabilityMask1              : 0           # Multiview
+ScalabilityMask2              : 1           # Scalable
 AdaptiveResolutionChange      : 0           # Resolution change frame (0: disable)
 
Index: /trunk/cfg/per-sequence-svc-avcbase/BQTerrace-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/BQTerrace-1.5x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/BQTerrace-1.5x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc-avcbase/BQTerrace-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/BQTerrace-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/BQTerrace-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 544         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc-avcbase/BQTerrace-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/BQTerrace-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/BQTerrace-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1088        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,6 +17,8 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
+NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
 ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
 QP1                           : 20
Index: /trunk/cfg/per-sequence-svc-avcbase/BasketballDrive-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/BasketballDrive-1.5x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/BasketballDrive-1.5x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc-avcbase/BasketballDrive-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/BasketballDrive-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/BasketballDrive-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 544         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc-avcbase/BasketballDrive-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/BasketballDrive-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/BasketballDrive-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1088        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,6 +17,8 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
+NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
 ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
 QP1                           : 20
Index: /trunk/cfg/per-sequence-svc-avcbase/Cactus-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/Cactus-1.5x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/Cactus-1.5x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc-avcbase/Cactus-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/Cactus-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/Cactus-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 544         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc-avcbase/Cactus-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/Cactus-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/Cactus-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1088        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,6 +17,8 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
+NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
 ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
 QP1                           : 20
Index: /trunk/cfg/per-sequence-svc-avcbase/Kimono-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/Kimono-1.5x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/Kimono-1.5x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc-avcbase/Kimono-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/Kimono-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/Kimono-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 544         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc-avcbase/Kimono-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/Kimono-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/Kimono-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1088        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,6 +17,8 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
+NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
 ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
 QP1                           : 20
Index: /trunk/cfg/per-sequence-svc-avcbase/ParkScene-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/ParkScene-1.5x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/ParkScene-1.5x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc-avcbase/ParkScene-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/ParkScene-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/ParkScene-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 544         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc-avcbase/ParkScene-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/ParkScene-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/ParkScene-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1088        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,6 +17,8 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
+NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
 ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
 QP1                           : 20
Index: /trunk/cfg/per-sequence-svc-avcbase/PeopleOnStreet-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/PeopleOnStreet-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/PeopleOnStreet-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 800         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc-avcbase/PeopleOnStreet-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/PeopleOnStreet-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/PeopleOnStreet-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 2560        # Input  frame width
 SourceHeight0                 : 1600        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc-avcbase/Traffic-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/Traffic-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/Traffic-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 800         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc-avcbase/Traffic-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc-avcbase/Traffic-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc-avcbase/Traffic-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 2560        # Input  frame width
 SourceHeight0                 : 1600        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/BQTerrace-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/BQTerrace-1.5x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/BQTerrace-1.5x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/BQTerrace-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/BQTerrace-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/BQTerrace-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/BQTerrace-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/BQTerrace-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/BQTerrace-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/BasketballDrive-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/BasketballDrive-1.5x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/BasketballDrive-1.5x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/BasketballDrive-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/BasketballDrive-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/BasketballDrive-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/BasketballDrive-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/BasketballDrive-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/BasketballDrive-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Cactus-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Cactus-1.5x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/Cactus-1.5x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Cactus-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Cactus-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/Cactus-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Cactus-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Cactus-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/Cactus-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Kimono-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Kimono-1.5x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/Kimono-1.5x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Kimono-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Kimono-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/Kimono-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Kimono-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Kimono-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/Kimono-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/ParkScene-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/ParkScene-1.5x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/ParkScene-1.5x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/ParkScene-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/ParkScene-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/ParkScene-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/ParkScene-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/ParkScene-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/ParkScene-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/PeopleOnStreet-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/PeopleOnStreet-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/PeopleOnStreet-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 800         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/PeopleOnStreet-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/PeopleOnStreet-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/PeopleOnStreet-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 2560        # Input  frame width
 SourceHeight0                 : 1600        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Traffic-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Traffic-2x.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/Traffic-2x.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 800         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Traffic-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Traffic-SNR.cfg	(revision 441)
+++ /trunk/cfg/per-sequence-svc/Traffic-SNR.cfg	(revision 442)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 2560        # Input  frame width
 SourceHeight0                 : 1600        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- /trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 441)
+++ /trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 442)
@@ -56,5 +56,4 @@
 TAppDecTop::TAppDecTop()
 {
-  ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag));
   for(UInt layer=0; layer < MAX_LAYERS; layer++)
   {
@@ -67,5 +66,4 @@
 : m_iPOCLastDisplay(-MAX_INT)
 {
-  ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag));
 }
 #endif
@@ -146,8 +144,8 @@
 
   // main decoder loop
-  Bool recon_opened[MAX_LAYERS]; // reconstruction file not yet opened. (must be performed after SPS is seen)
+  Bool openedReconFile[MAX_LAYERS]; // reconstruction file not yet opened. (must be performed after SPS is seen)
   for(UInt layer=0; layer<=m_tgtLayerId; layer++)
   {
-    recon_opened[layer] = false;
+    openedReconFile[layer] = false;
     m_aiPOCLastDisplay[layer] += m_iSkipFrame;      // set the last displayed POC correctly for skip forward.
   }
@@ -228,9 +226,12 @@
     {
       m_acTDecTop[curLayerId].executeLoopFilters(poc, pcListPic);
+#if EARLY_REF_PIC_MARKING
+      m_acTDecTop[curLayerId].earlyPicMarking(m_iMaxTemporalLayer, m_targetDecLayerIdSet);
+#endif
     }
 
     if( pcListPic )
     {
-      if ( m_pchReconFile[curLayerId] && !recon_opened[curLayerId] )
+      if ( m_pchReconFile[curLayerId] && !openedReconFile[curLayerId] )
       {
         if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; }        
@@ -239,5 +240,5 @@
         m_acTVideoIOYuvReconFile[curLayerId].open( m_pchReconFile[curLayerId], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
 
-        recon_opened[curLayerId] = true;
+        openedReconFile[curLayerId] = true;
       }
       if ( bNewPicture && bNewPOC && 
@@ -263,4 +264,6 @@
   // delete buffers
 #if AVC_BASE
+  UInt layerIdmin = m_acTDecTop[0].getBLReconFile()->is_open() ? 1 : 0;
+
   if( streamYUV.is_open() )
   {
@@ -273,7 +276,7 @@
   }
 #endif
-  pcBLPic.destroy();
-
-  for(UInt layer = 1; layer <= m_tgtLayerId; layer++)
+  pcBLPic.destroy();  
+
+  for(UInt layer = layerIdmin; layer <= m_tgtLayerId; layer++)
 #else
   for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
@@ -307,5 +310,5 @@
 
   // main decoder loop
-  Bool recon_opened = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
+  Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
 
 #if SYNTAX_OUTPUT
@@ -338,5 +341,4 @@
     streampos location = bitstreamFile.tellg();
     AnnexBStats stats = AnnexBStats();
-    Bool bPreviousPictureDecoded = false;
 
     vector<uint8_t> nalUnit;
@@ -360,14 +362,6 @@
       if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  )
       {
-        if(bPreviousPictureDecoded)
-        {
-          bNewPicture = true;
-          bPreviousPictureDecoded = false;
-        }
-        else
-        {
           bNewPicture = false;
         }
-      }
       else
       {
@@ -383,5 +377,4 @@
           bytestream.reset();
         }
-        bPreviousPictureDecoded = true; 
       }
     }
@@ -393,5 +386,5 @@
     if( pcListPic )
     {
-      if ( m_pchReconFile && !recon_opened )
+      if ( m_pchReconFile && !openedReconFile )
       {
         if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; }
@@ -399,5 +392,5 @@
 
         m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
-        recon_opened = true;
+        openedReconFile = true;
       }
       if ( bNewPicture && 
@@ -470,5 +463,5 @@
     if ( m_pchReconFile[layer] )
     {
-      m_acTVideoIOYuvReconFile[layer]. close();
+      m_acTVideoIOYuvReconFile[layer].close();
     }
 
@@ -505,6 +498,6 @@
 
 /** \param pcListPic list of pictures to be written to file
-    \todo            DYN_REF_FREE should be revised
- */
+\todo            DYN_REF_FREE should be revised
+*/
 #if SVC_EXTENSION
 Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt layerId, UInt tId )
@@ -514,5 +507,5 @@
 {
   TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
-  Int not_displayed = 0;
+  Int numPicsNotYetDisplayed = 0;
 
   while (iterPic != pcListPic->end())
@@ -525,76 +518,194 @@
 #endif
     {
-       not_displayed++;
+      numPicsNotYetDisplayed++;
     }
     iterPic++;
   }
   iterPic   = pcListPic->begin();
-  
-  while (iterPic != pcListPic->end())
-  {
-    TComPic* pcPic = *(iterPic);
-    
-#if SVC_EXTENSION
-    if ( pcPic->getOutputMark() && (not_displayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_aiPOCLastDisplay[layerId]))
-#else
-    if ( pcPic->getOutputMark() && (not_displayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
-#endif
-    {
-      // write to file
-       not_displayed--;
-#if SVC_EXTENSION
-      if ( m_pchReconFile[layerId] )
-      {
-        const Window &conf = pcPic->getConformanceWindow();
-        const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
-        m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
-                                       conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
-                                       conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
-                                       conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-                                       conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
-      }
-      
-      // update POC of display order
-      m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
-#else
-      if ( m_pchReconFile )
-      {
-#if SYNTAX_OUTPUT && ILP_DECODED_PICTURE
-        m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec() );
-#else
-        const Window &conf = pcPic->getConformanceWindow();
-        const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
-        m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
-                                       conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
-                                       conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
-                                       conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-                                       conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
-#endif
-      }
-      
-      // update POC of display order
-      m_iPOCLastDisplay = pcPic->getPOC();
-#endif
-      
-      // erase non-referenced picture in the reference picture list after display
-      if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
-      {
+  if (numPicsNotYetDisplayed>2)
+  {
+    iterPic++;
+  }
+
+  TComPic* pcPic = *(iterPic);
+  if (numPicsNotYetDisplayed>2 && pcPic->isField()) //Field Decoding
+  {
+    TComList<TComPic*>::iterator endPic   = pcListPic->end();
+    endPic--;
+    iterPic   = pcListPic->begin();
+    while (iterPic != endPic)
+    {
+      TComPic* pcPicTop = *(iterPic);
+      iterPic++;
+      TComPic* pcPicBottom = *(iterPic);
+
+#if SVC_EXTENSION
+      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
+        && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_aiPOCLastDisplay[layerId]+1 || m_aiPOCLastDisplay[layerId]<0)))
+#else
+      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
+        && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay<0)))
+#endif
+      {
+        // write to file
+        numPicsNotYetDisplayed = numPicsNotYetDisplayed-2;
+#if SVC_EXTENSION
+        if ( m_pchReconFile[layerId] )
+        {
+          const Window &conf = pcPicTop->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
+          const Bool isTff = pcPicTop->isTopField();
+#if REPN_FORMAT_IN_VPS
+          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
+          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
+          m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+            conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset()   * yScal + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset(), isTff );
+
+#else
+          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
+#endif
+        }
+
+        // update POC of display order
+        m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC();
+#else
+        if ( m_pchReconFile )
+        {
+          const Window &conf = pcPicTop->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
+          const Bool isTff = pcPicTop->isTopField();
+          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
+        }
+
+        // update POC of display order
+        m_iPOCLastDisplay = pcPicBottom->getPOC();
+#endif
+
+        // erase non-referenced picture in the reference picture list after display
+        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
+        {
 #if !DYN_REF_FREE
-        pcPic->setReconMark(false);
-        
-        // mark it should be extended later
-        pcPic->getPicYuvRec()->setBorderExtension( false );
-        
-#else
-        pcPic->destroy();
-        pcListPic->erase( iterPic );
-        iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
-        continue;
-#endif
-      }
-      pcPic->setOutputMark(false);
-    }
-    
-    iterPic++;
+          pcPicTop->setReconMark(false);
+
+          // mark it should be extended later
+          pcPicTop->getPicYuvRec()->setBorderExtension( false );
+
+#else
+          pcPicTop->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
+        {
+#if !DYN_REF_FREE
+          pcPicBottom->setReconMark(false);
+
+          // mark it should be extended later
+          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
+
+#else
+          pcPicBottom->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        pcPicTop->setOutputMark(false);
+        pcPicBottom->setOutputMark(false);
+      }
+    }
+  }
+  else if (!pcPic->isField()) //Frame Decoding
+  {
+    iterPic = pcListPic->begin();
+    while (iterPic != pcListPic->end())
+    {
+      pcPic = *(iterPic);
+
+#if SVC_EXTENSION
+      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_aiPOCLastDisplay[layerId]))
+#else
+      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
+#endif
+      {
+        // write to file
+        numPicsNotYetDisplayed--;
+#if SVC_EXTENSION
+        if ( m_pchReconFile[layerId] )
+        {
+          const Window &conf = pcPic->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+#if REPN_FORMAT_IN_VPS
+          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
+          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
+          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
+            conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset()   * yScal + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() );
+
+#else
+          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
+            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
+#endif
+        }
+
+        // update POC of display order
+        m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
+#else
+        if ( m_pchReconFile )
+        {
+#if SYNTAX_OUTPUT
+          const Window &conf = pcPic->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
+            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
+#endif
+        }
+
+        // update POC of display order
+        m_iPOCLastDisplay = pcPic->getPOC();
+#endif
+
+        // erase non-referenced picture in the reference picture list after display
+        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
+        {
+#if !DYN_REF_FREE
+          pcPic->setReconMark(false);
+
+          // mark it should be extended later
+          pcPic->getPicYuvRec()->setBorderExtension( false );
+
+#else
+          pcPic->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        pcPic->setOutputMark(false);
+      }
+
+      iterPic++;
+    }
   }
 }
@@ -616,71 +727,194 @@
 
   iterPic   = pcListPic->begin();
-  
-  while (iterPic != pcListPic->end())
-  {
-    TComPic* pcPic = *(iterPic);
-
-    if ( pcPic->getOutputMark() )
-    {
-      // write to file
-#if SVC_EXTENSION
-      if ( m_pchReconFile[layerId] )
-      {
-        const Window &conf = pcPic->getConformanceWindow();
-        const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
-        m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
-                                       conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
-                                       conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
-                                       conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-                                       conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
-      }
-      
-      // update POC of display order
-      m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
-#else
-      if ( m_pchReconFile )
-      {
-        const Window &conf = pcPic->getConformanceWindow();
-        const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
-        m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
-                                       conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
-                                       conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
-                                       conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-                                       conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
-      }
-      
-      // update POC of display order
-      m_iPOCLastDisplay = pcPic->getPOC();
-#endif
-      
-      // erase non-referenced picture in the reference picture list after display
-      if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
-      {
+  TComPic* pcPic = *(iterPic);
+
+  if (pcPic->isField()) //Field Decoding
+  {
+    TComList<TComPic*>::iterator endPic   = pcListPic->end();
+    endPic--;
+    TComPic *pcPicTop, *pcPicBottom = NULL;
+    while (iterPic != endPic)
+    {
+      pcPicTop = *(iterPic);
+      iterPic++;
+      pcPicBottom = *(iterPic);
+
+      if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && !(pcPicTop->getPOC()%2) && (pcPicBottom->getPOC() == pcPicTop->getPOC()+1) )
+      {
+        // write to file
+#if SVC_EXTENSION
+        if ( m_pchReconFile[layerId] )
+        {
+          const Window &conf = pcPicTop->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
+          const Bool isTff = pcPicTop->isTopField();
+#if REPN_FORMAT_IN_VPS
+          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
+          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
+          m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+            conf.getWindowLeftOffset()  *xScal + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset()   *yScal + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset(), isTff );
+
+#else
+          m_cTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
+#endif
+        }
+
+        // update POC of display order
+        m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC();
+#else
+        if ( m_pchReconFile )
+        {
+          const Window &conf = pcPicTop->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
+          const Bool isTff = pcPicTop->isTopField();
+          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
+        }
+
+        // update POC of display order
+        m_iPOCLastDisplay = pcPicBottom->getPOC();
+#endif
+
+        // erase non-referenced picture in the reference picture list after display
+        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
+        {
 #if !DYN_REF_FREE
-        pcPic->setReconMark(false);
-        
-        // mark it should be extended later
-        pcPic->getPicYuvRec()->setBorderExtension( false );
-        
-#else
-        pcPic->destroy();
-        pcListPic->erase( iterPic );
-        iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
-        continue;
-#endif
-      }
-      pcPic->setOutputMark(false);
-    }
+          pcPicTop->setReconMark(false);
+
+          // mark it should be extended later
+          pcPicTop->getPicYuvRec()->setBorderExtension( false );
+
+#else
+          pcPicTop->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
+        {
+#if !DYN_REF_FREE
+          pcPicBottom->setReconMark(false);
+
+          // mark it should be extended later
+          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
+
+#else
+          pcPicBottom->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        pcPicTop->setOutputMark(false);
+        pcPicBottom->setOutputMark(false);
+
+#if !DYN_REF_FREE
+        if(pcPicTop)
+        {
+          pcPicTop->destroy();
+          delete pcPicTop;
+          pcPicTop = NULL;
+        }
+#endif
+      }
+    }
+    if(pcPicBottom)
+    {
+      pcPicBottom->destroy();
+      delete pcPicBottom;
+      pcPicBottom = NULL;
+    }
+  }
+  else //Frame decoding
+  {
+    while (iterPic != pcListPic->end())
+    {
+      pcPic = *(iterPic);
+
+      if ( pcPic->getOutputMark() )
+      {
+        // write to file
+#if SVC_EXTENSION
+        if ( m_pchReconFile[layerId] )
+        {
+          const Window &conf = pcPic->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+#if REPN_FORMAT_IN_VPS
+          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
+          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
+          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
+            conf.getWindowLeftOffset()  *xScal + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset()   *yScal + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset() );
+
+#else
+          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
+            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
+#endif
+        }
+
+        // update POC of display order
+        m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
+#else
+        if ( m_pchReconFile )
+        {
+          const Window &conf = pcPic->getConformanceWindow();
+          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
+            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
+        }
+
+        // update POC of display order
+        m_iPOCLastDisplay = pcPic->getPOC();
+#endif
+
+        // erase non-referenced picture in the reference picture list after display
+        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
+        {
+#if !DYN_REF_FREE
+          pcPic->setReconMark(false);
+
+          // mark it should be extended later
+          pcPic->getPicYuvRec()->setBorderExtension( false );
+
+#else
+          pcPic->destroy();
+          pcListPic->erase( iterPic );
+          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
+          continue;
+#endif
+        }
+        pcPic->setOutputMark(false);
+      }
 #if !SVC_EXTENSION
 #if !DYN_REF_FREE
-    if(pcPic)
-    {
-      pcPic->destroy();
-      delete pcPic;
-      pcPic = NULL;
-    }
+      if(pcPic)
+      {
+        pcPic->destroy();
+        delete pcPic;
+        pcPic = NULL;
+      }
 #endif    
 #endif
-    iterPic++;
+      iterPic++;
+    }
   }
 #if SVC_EXTENSION
Index: /trunk/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- /trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 441)
+++ /trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 442)
@@ -70,6 +70,5 @@
 #endif
   
-  // for output control
-  Bool                            m_abDecFlag[ MAX_GOP ];         ///< decoded flag in one GOP
+  // for output control  
 #if SVC_EXTENSION
   Int                             m_aiPOCLastDisplay [MAX_LAYERS]; ///< last POC in display order
Index: /trunk/source/App/TAppDownConvert/TAppDownConvert.cpp
===================================================================
--- /trunk/source/App/TAppDownConvert/TAppDownConvert.cpp	(revision 441)
+++ /trunk/source/App/TAppDownConvert/TAppDownConvert.cpp	(revision 442)
@@ -270,6 +270,6 @@
   FILE * outfile;
 
-  int M,N;
-  int ratio;
+  int M = -1 ,N = -1;
+  int ratio = -1;
   int Frames=0;
   int totalFrames=0;
@@ -326,19 +326,18 @@
     return -1;
   }
-  if ( ratio > 1 || ratio < 0)
-  {
+
+  switch( ratio )
+  {
+  default:
     printf("\ndown sampling parameter %d is not supported (0: 2x downsampling, 1: 1.5x downsampling)\n", ratio);
     return -1;
-  }
-
-  if (ratio==0)
-  {
+  case 0:
     M=4;
     N=8;
-  }
-  else if (ratio==1)
-  {
+    break;
+  case 1:
     M=8;
     N=12;
+    break;
   }
 
Index: /trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 441)
+++ /trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 442)
@@ -69,10 +69,11 @@
 , m_avcBaseLayerFlag(0)
 #endif
+#if N0120_MAX_TID_REF_CFG
+, m_maxTidRefPresentFlag(1)
+#endif 
 , m_pColumnWidth()
 , m_pRowHeight()
 , m_scalingListFile()
-#if REF_IDX_FRAMEWORK
 , m_elRapSliceBEnabled(0)
-#endif
 {
   for(UInt layer=0; layer<MAX_LAYERS; layer++)
@@ -217,4 +218,16 @@
     {
       in>>entry.m_refIdc[i];
+    }
+  }
+#endif
+#if EXTERNAL_USEDBYCURR_N0082
+  if(entry.m_numRefPics>0){
+    in>>entry.m_UseExtusedByCurrPic;
+    if(entry.m_UseExtusedByCurrPic)
+    {
+      for ( Int i = 0; i < entry.m_numRefPics; i++ )
+      {
+        in>>entry.m_ExtusedByCurrPic[i];
+      }
     }
   }
@@ -335,10 +348,13 @@
   
 #if SVC_EXTENSION
-  string  cfg_LayerCfgFile  [MAX_LAYERS];
+  string  cfg_LayerCfgFile   [MAX_LAYERS];
   string  cfg_BitstreamFile;
-  string* cfg_InputFile     [MAX_LAYERS];
-  string* cfg_ReconFile     [MAX_LAYERS];
-  Double* cfg_fQP           [MAX_LAYERS];
-
+  string* cfg_InputFile      [MAX_LAYERS];
+  string* cfg_ReconFile      [MAX_LAYERS];
+  Double* cfg_fQP            [MAX_LAYERS];
+
+#if REPN_FORMAT_IN_VPS
+  Int*    cfg_repFormatIdx  [MAX_LAYERS];
+#endif
   Int*    cfg_SourceWidth   [MAX_LAYERS]; 
   Int*    cfg_SourceHeight  [MAX_LAYERS];
@@ -384,4 +400,7 @@
   Bool*   cfg_RCForceIntraQP       [MAX_LAYERS];
 #endif
+#if N0120_MAX_TID_REF_CFG
+  Int*    cfg_maxTidIlRefPicsPlus1[MAX_LAYERS]; 
+#endif 
   for(UInt layer = 0; layer < MAX_LAYERS; layer++)
   {
@@ -389,4 +408,7 @@
     cfg_ReconFile[layer]    = &m_acLayerCfg[layer].m_cReconFile;
     cfg_fQP[layer]          = &m_acLayerCfg[layer].m_fQP;
+#if REPN_FORMAT_IN_VPS
+    cfg_repFormatIdx[layer] = &m_acLayerCfg[layer].m_repFormatIdx;
+#endif
     cfg_SourceWidth[layer]  = &m_acLayerCfg[layer].m_iSourceWidth;
     cfg_SourceHeight[layer] = &m_acLayerCfg[layer].m_iSourceHeight;
@@ -426,4 +448,7 @@
     cfg_RCForceIntraQP[layer]        = &m_acLayerCfg[layer].m_RCForceIntraQP;
 #endif
+#if N0120_MAX_TID_REF_CFG
+    cfg_maxTidIlRefPicsPlus1[layer] = &m_acLayerCfg[layer].m_maxTidIlRefPicsPlus1; 
+#endif 
   }
 #if AVC_BASE
@@ -432,4 +457,7 @@
 #if AVC_SYNTAX
   string  cfg_BLSyntaxFile;
+#endif
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  string  cfg_tileSets;
 #endif
 #else
@@ -459,4 +487,7 @@
   ("FrameRate%d,-fr%d",       cfg_FrameRate,  0, MAX_LAYERS, "Frame rate for layer %d")
   ("LambdaModifier%d,-LM%d",  m_adLambdaModifier, ( double )1.0, MAX_TLAYER, "Lambda modifier for temporal layer %d")
+#if REPN_FORMAT_IN_VPS
+  ("RepFormatIdx%d",          cfg_repFormatIdx, -1, MAX_LAYERS, "Index to the representation format structure used from the VPS")
+#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -474,6 +505,11 @@
   ("NumLayers",               m_numLayers, 1, "Number of layers to code")
   ("ConformanceMode%d",       cfg_conformanceMode,0, MAX_LAYERS, "Window conformance mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
+#if SCALABILITY_MASK_E0104
+  ("ScalabilityMask1",        m_scalabilityMask[1], 0, "scalability_mask[1] (multiview)")
+  ("ScalabilityMask2",        m_scalabilityMask[2], 1, "scalability_mask[2] (scalable)" )
+#else
   ("ScalabilityMask0",        m_scalabilityMask[0], 0, "scalability_mask[0] (multiview)")
   ("ScalabilityMask1",        m_scalabilityMask[1], 1, "scalability_mask[1] (scalable)" )
+#endif
   ("BitstreamFile,b",         cfg_BitstreamFile, string(""), "Bitstream output file name")
   ("InputBitDepth",           m_inputBitDepthY,    8, "Bit-depth of input file")
@@ -495,4 +531,8 @@
                                                                  " bottom-right luma sample of the EL picture, in units of two luma samples")
 #endif
+#if N0120_MAX_TID_REF_CFG
+  ("MaxTidRefPresentFlag", m_maxTidRefPresentFlag, true, "max_tid_ref_present_flag (0: not present, 1: present(default)) " )
+  ("MaxTidIlRefPicsPlus1%d", cfg_maxTidIlRefPicsPlus1, 1, MAX_LAYERS, "allowed maximum temporal_id for inter-layer prediction")
+#endif 
 #if AVC_BASE
   ("AvcBase,-avc",            m_avcBaseLayerFlag,     0, "avc_base_layer_flag")
@@ -502,11 +542,9 @@
 #endif
 #endif
-#if REF_IDX_FRAMEWORK
   ("EnableElRapB,-use-rap-b",  m_elRapSliceBEnabled, 0, "Set ILP over base-layer I picture to B picture (default is P picture)")
-#endif  
 #if M0457_IL_SAMPLE_PRED_ONLY_FLAG
   ("IlSampleOnlyPred%d",       m_ilSampleOnlyPred, 0, MAX_LAYERS, "Set inter_layer_sample_pred_only_flag for all slices")
 #endif
-#else  
+#else
   ("InputFile,i",           cfg_InputFile,     string(""), "Original YUV input file name")
   ("BitstreamFile,b",       cfg_BitstreamFile, string(""), "Bitstream output file name")
@@ -530,4 +568,8 @@
   ("FrameRate,-fr",         m_iFrameRate,          0, "Frame rate")
 #endif
+
+  //Field coding parameters
+  ("FieldCoding", m_isField, false, "Signals if it's a field based coding")
+  ("TopFieldFirst, Tff", m_isTopFieldFirst, false, "In case of field based coding, signals whether if it's a top field first or not")
   ("FrameSkip,-fs",         m_FrameSkip,          0u, "Number of frames to skip at start of input YUV")
   ("FramesToBeEncoded,f",   m_framesToBeEncoded,   0, "Number of frames to be encoded (default=all)")
@@ -810,4 +852,9 @@
   ("AdaptiveResolutionChange",     m_adaptiveResolutionChange, 0, "Adaptive resolution change frame number. Should coincide with EL RAP picture. (0: disable)")
 #endif
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  ("SEIInterLayerConstrainedTileSets", m_interLayerConstrainedTileSetsSEIEnabled, false, "Control generation of inter layer constrained tile sets SEI message")
+  ("IlNumSetsInMessage",               m_ilNumSetsInMessage,                         0u, "Number of inter layer constrained tile sets")
+  ("TileSetsArray",                    cfg_tileSets,                         string(""), "Array containing tile sets params (TopLeftTileIndex, BottonRightTileIndex and ilcIdc for each set) ")
+#endif
   ;
   
@@ -827,4 +874,24 @@
   const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
 
+  if(m_isField)
+  {
+#if SVC_EXTENSION
+    for(Int layer = 0; layer < MAX_LAYERS; layer++)
+    {
+      //Frame height
+      m_acLayerCfg[layer].m_iSourceHeightOrg = m_acLayerCfg[layer].m_iSourceHeight;
+      //Field height
+      m_acLayerCfg[layer].m_iSourceHeight = m_acLayerCfg[layer].m_iSourceHeight >> 1;
+    }
+#else
+    //Frame height
+    m_iSourceHeightOrg = m_iSourceHeight;
+    //Field height
+    m_iSourceHeight = m_iSourceHeight >> 1;
+#endif
+    //number of fields to encode
+    m_framesToBeEncoded *= 2;
+  }
+  
   for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
   {
@@ -1119,5 +1186,12 @@
 #endif
   m_scalingListFile = cfg_ScalingListFile.empty() ? NULL : strdup(cfg_ScalingListFile.c_str());
-  
+
+#if REPN_FORMAT_IN_VPS_123
+  for(Int layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    m_acLayerCfg[layer].setSourceHeight( m_repFormatCfg[ m_acLayerCfg[layer].getRepFormatIdx() ].m_picHeightInLumaSamples);
+    m_acLayerCfg[layer].setSourceWidth ( m_repFormatCfg[ m_acLayerCfg[layer].getRepFormatIdx() ].m_picWidthInLumaSamples );
+  }
+#endif
   /* rules for input, output and internal bitdepths as per help text */
   if (!m_internalBitDepthY) { m_internalBitDepthY = m_inputBitDepthY; }
@@ -1151,4 +1225,9 @@
         m_aiPad[1] = m_confBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
         m_iSourceHeight += m_confBottom;
+        if ( m_isField )
+        {
+          m_iSourceHeightOrg += m_confBottom << 1;
+          m_aiPad[1] = m_confBottom << 1;
+        }
       }
       if (m_aiPad[0] % TComSPS::getWinUnitX(CHROMA_420) != 0)
@@ -1284,4 +1363,48 @@
     }
   }
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  if (m_interLayerConstrainedTileSetsSEIEnabled)
+  {
+    if (m_iNumColumnsMinus1 == 0 && m_iNumRowsMinus1 == 0)
+    {
+      printf( "Tiles are not defined (needed for inter-layer comnstrained tile sets SEI).\n" );
+      exit( EXIT_FAILURE );
+    }
+    Char* pTileSets = cfg_tileSets.empty() ? NULL : strdup(cfg_tileSets.c_str());
+    int i = 0;
+    char *topLeftTileIndex = strtok(pTileSets, " ,");
+    while(topLeftTileIndex != NULL)
+    {
+      if( i >= m_ilNumSetsInMessage )
+      {
+        printf( "The number of tile sets is larger than defined by IlNumSetsInMessage.\n" );
+        exit( EXIT_FAILURE );
+      }
+      *( m_topLeftTileIndex + i ) = atoi( topLeftTileIndex );
+      char *bottonRightTileIndex = strtok(NULL, " ,");
+      if( bottonRightTileIndex == NULL )
+      {
+        printf( "BottonRightTileIndex is missing in the tile sets.\n" );
+        exit( EXIT_FAILURE );
+      }
+      *( m_bottomRightTileIndex + i ) = atoi( bottonRightTileIndex );
+      char *ilcIdc = strtok(NULL, " ,");
+      if( ilcIdc == NULL )
+      {
+        printf( "IlcIdc is missing in the tile sets.\n" );
+        exit( EXIT_FAILURE );
+      }
+      *( m_ilcIdc + i ) = atoi( ilcIdc );
+      topLeftTileIndex = strtok(NULL, " ,");
+      i++;
+    }
+    if( i < m_ilNumSetsInMessage )
+    {
+      printf( "The number of tile sets is smaller than defined by IlNumSetsInMessage.\n" );
+      exit( EXIT_FAILURE );
+    }
+    m_skippedTileSetPresentFlag = false;
+  }
+#endif
   // check validity of input parameters
   xCheckParameter();
@@ -1467,14 +1590,18 @@
 #endif
   
-#if !FINAL_RPL_CHANGE_N0082
+#if EXTERNAL_USEDBYCURR_N0082|| !FINAL_RPL_CHANGE_N0082
   Bool verifiedGOP=false;
 #endif
   Bool errorGOP=false;
-#if !FINAL_RPL_CHANGE_N0082
+#if  EXTERNAL_USEDBYCURR_N0082|| !FINAL_RPL_CHANGE_N0082
   Int checkGOP=1;
-  Int numRefs = 1;
+  Int numRefs = m_isField ? 2 : 1;
 #endif
   Int refList[MAX_NUM_REF_PICS+1];
   refList[0]=0;
+  if(m_isField)
+  {
+    refList[1] = 1;
+  }
   Bool isOK[MAX_GOP];
   for(Int i=0; i<MAX_GOP; i++) 
@@ -1482,5 +1609,5 @@
     isOK[i]=false;
   }
-#if !FINAL_RPL_CHANGE_N0082
+#if  EXTERNAL_USEDBYCURR_N0082|| !FINAL_RPL_CHANGE_N0082
   Int numOK=0;
 #endif
@@ -1504,5 +1631,5 @@
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
-    if(m_acLayerCfg[layer].xCheckParameter())
+    if(m_acLayerCfg[layer].xCheckParameter(m_isField))
     {
       printf("\nError: invalid configuration parameter found in layer %d \n", layer);
@@ -1530,5 +1657,6 @@
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
-    if (m_acLayerCfg[layer].m_GOPListLayer[0].m_POC<0){
+    if (m_acLayerCfg[layer].m_GOPListLayer[0].m_POC<0)
+    {
       memcpy( m_acLayerCfg[layer].m_GOPListLayer, m_GOPList, sizeof(GOPEntry)*MAX_GOP );
     }
@@ -1536,6 +1664,12 @@
     xConfirmPara(errorGOP,"Invalid GOP structure given");
   }
+#if TEMP_SCALABILITY_FIX
+  if( m_acLayerCfg[1].m_GOPListLayer[5].m_POC == 6  && m_acLayerCfg[1].m_GOPListLayer[7].m_POC == 7  && 
+    m_acLayerCfg[1].m_GOPListLayer[5].m_temporalId == 0 && m_acLayerCfg[1].m_GOPListLayer[7].m_temporalId == 0)
+#else
   //tentative for encoder
-  if( m_acLayerCfg[1].m_GOPListLayer[5].m_POC == 6  && m_acLayerCfg[1].m_GOPListLayer[7].m_POC == 7 ){
+  if( m_acLayerCfg[1].m_GOPListLayer[5].m_POC == 6  && m_acLayerCfg[1].m_GOPListLayer[7].m_POC == 7 )
+#endif
+  {
     //RA, POC5
     m_acLayerCfg[1].m_GOPListLayer[5].m_usedByCurrPic[2] = 0;
@@ -1545,5 +1679,6 @@
     m_acLayerCfg[1].m_GOPListLayer[7].m_refIdc[2] = 0;
   }
-#else
+#endif
+#if  EXTERNAL_USEDBYCURR_N0082|| !FINAL_RPL_CHANGE_N0082
   m_extraRPSs=0;
   //start looping through frames in coding order until we can verify that the GOP structure is correct.
@@ -1742,4 +1877,19 @@
   xConfirmPara(errorGOP,"Invalid GOP structure given");
 #endif
+#if EXTERNAL_USEDBYCURR_N0082
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    for (Int i=0; i< m_iGOPSize; i++){
+      if (m_acLayerCfg[layer].m_GOPListLayer[i].m_UseExtusedByCurrPic == 1 )
+      {
+        for(Int j=0; j<m_acLayerCfg[layer].m_GOPListLayer[i].m_numRefPics; j++ )
+        {
+          m_acLayerCfg[layer].m_GOPListLayer[i].m_usedByCurrPic[j] = m_acLayerCfg[layer].m_GOPListLayer[i].m_ExtusedByCurrPic[j];
+          m_acLayerCfg[layer].m_GOPListLayer[i].m_refIdc[j] = m_acLayerCfg[layer].m_GOPListLayer[i].m_ExtusedByCurrPic[j];
+        }
+      }
+    }
+  }
+#endif
   m_maxTempLayer = 1;
   for(Int i=0; i<m_iGOPSize; i++) 
@@ -2045,4 +2195,10 @@
   }
 #endif
+#if N0120_MAX_TID_REF_CFG
+  for (UInt layer=0; layer < MAX_LAYERS-1; layer++)
+  {
+    xConfirmPara(m_acLayerCfg[layer].m_maxTidIlRefPicsPlus1 < 0 || m_acLayerCfg[layer].m_maxTidIlRefPicsPlus1 > 7, "MaxTidIlRefPicsPlus1 must be in range 0 to 7");
+  }
+#endif 
 #undef xConfirmPara
   if (check_failed)
@@ -2081,6 +2237,11 @@
 #if SVC_EXTENSION  
   printf("Total number of layers        : %d\n", m_numLayers       );
+#if SCALABILITY_MASK_E0104
+  printf("Multiview                     : %d\n", m_scalabilityMask[1] );
+  printf("Scalable                      : %d\n", m_scalabilityMask[2] );
+#else
   printf("Multiview                     : %d\n", m_scalabilityMask[0] );
   printf("Scalable                      : %d\n", m_scalabilityMask[1] );
+#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   printf("Adaptive Resolution Change    : %d\n", m_adaptiveResolutionChange );
@@ -2105,5 +2266,22 @@
   printf("Internal Format              : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
 #endif
-  printf("Frame index                  : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
+  if (m_isField)
+  {
+    printf("Frame/Field          : Field based coding\n");
+    printf("Field index          : %u - %d (%d fields)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
+    if (m_isTopFieldFirst)
+    {
+      printf("Field Order            : Top field first\n");
+    }
+    else
+    {
+      printf("Field Order            : Bottom field first\n");
+    }
+  }
+  else
+  {
+    printf("Frame/Field                  : Frame based coding\n");
+    printf("Frame index                  : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
+  }
   printf("CU size / depth              : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth );
   printf("RQT trans. size (min / max)  : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize );
@@ -2209,11 +2387,8 @@
   printf("AvcBase:%d ", 0);
 #endif
-#if REF_IDX_FRAMEWORK
-  printf("REF_IDX_FRAMEWORK:%d ", REF_IDX_FRAMEWORK);
   printf("EL_RAP_SliceType: %d ", m_elRapSliceBEnabled);
   printf("REF_IDX_ME_ZEROMV: %d ", REF_IDX_ME_ZEROMV);
   printf("ENCODER_FAST_MODE: %d ", ENCODER_FAST_MODE);
   printf("REF_IDX_MFM: %d ", REF_IDX_MFM);
-#endif
 #else
   printf("RecalQP:%d", m_recalculateQPAccordingToLambda ? 1 : 0 );
Index: /trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 441)
+++ /trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 442)
@@ -59,5 +59,5 @@
   // file I/O
 #if SVC_EXTENSION
-  TAppEncLayerCfg m_acLayerCfg [MAX_LAYERS]; 
+  TAppEncLayerCfg m_acLayerCfg [MAX_LAYERS];
   Int       m_numLayers;                                      ///< number of layers
   Int       m_scalabilityMask[MAX_VPS_NUM_SCALABILITY_TYPES]; ///< scalability_mask
@@ -68,5 +68,5 @@
   Int       m_framesToBeEncoded;                              ///< number of encoded frames
 #if AVC_BASE
-  Int       m_avcBaseLayerFlag;                               ///< AVC_BASElayer_flag
+  Int       m_avcBaseLayerFlag;                               ///< avc_baselayer_flag
 #endif
 #if AVC_SYNTAX
@@ -76,4 +76,7 @@
   Int       m_ilSampleOnlyPred[ MAX_LAYERS ];
 #endif
+#if N0120_MAX_TID_REF_CFG
+  Bool      m_maxTidRefPresentFlag; 
+#endif 
 #else
   Char*     m_pchInputFile;                                   ///< source file name
@@ -85,5 +88,9 @@
   UInt      m_FrameSkip;                                      ///< number of skipped frames from the beginning
   Int       m_iSourceWidth;                                   ///< source width in pixel
-  Int       m_iSourceHeight;                                  ///< source height in pixel
+  Int       m_iSourceHeight;                                  ///< source height in pixel (when interlaced = field height)
+  
+  Int       m_iSourceHeightOrg;                               ///< original source height in pixel (when interlaced = frame height)
+  
+  
   Int       m_conformanceMode;
   Int       m_confLeft;
@@ -94,4 +101,7 @@
   Int       m_aiPad[2];                                       ///< number of padded pixels for width and height
 #endif  
+
+  Bool      m_isField;                                        ///< enable field coding
+  Bool      m_isTopFieldFirst;
 
   // profile/level
@@ -340,5 +350,5 @@
   Int       m_log2MaxMvLengthVertical;                        ///< Indicate the maximum absolute value of a decoded vertical MV component in quarter-pel luma units
 
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   Int       m_elRapSliceBEnabled;
 #endif
@@ -353,4 +363,15 @@
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   Int       m_adaptiveResolutionChange;                       ///< Indicate adaptive resolution change frame
+#endif
+#if REPN_FORMAT_IN_VPS
+  RepFormatCfg m_repFormatCfg[16];                            ///< Rep_format structures
+#endif
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Bool      m_interLayerConstrainedTileSetsSEIEnabled;
+  UInt      m_ilNumSetsInMessage;
+  Bool      m_skippedTileSetPresentFlag;
+  UInt      m_topLeftTileIndex[1024];
+  UInt      m_bottomRightTileIndex[1024];
+  UInt      m_ilcIdc[1024];
 #endif
 public:
@@ -381,4 +402,7 @@
   Void cfgStringToArray(Int **arr, string cfgString, Int numEntries, const char* logString);
 #endif
+#if REPN_FORMAT_IN_VPS
+  RepFormatCfg* getRepFormatCfg(Int i)  { return &m_repFormatCfg[i]; }
+#endif
 #endif
 };// END CLASS DEFINITION TAppEncCfg
Index: /trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 441)
+++ /trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 442)
@@ -32,4 +32,7 @@
   m_conformanceMode( 0 ),
   m_aidQP(NULL)
+#if REPN_FORMAT_IN_VPS
+, m_repFormatIdx (-1)
+#endif
 {
   m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
@@ -158,5 +161,5 @@
 Bool confirmPara(Bool bflag, const char* message);
 
-Bool TAppEncLayerCfg::xCheckParameter()
+Bool TAppEncLayerCfg::xCheckParameter( Bool isField )
 {
   switch (m_conformanceMode)
@@ -182,4 +185,9 @@
         m_aiPad[1] = m_confBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
         m_iSourceHeight += m_confBottom;
+        if ( isField )
+        {
+          m_iSourceHeightOrg += m_confBottom << 1;
+          m_aiPad[1] = m_confBottom << 1;
+        }
       }
       break;
Index: /trunk/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 441)
+++ /trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 442)
@@ -33,5 +33,6 @@
   Int       m_iFrameRate;                                     ///< source frame-rates (Hz)
   Int       m_iSourceWidth;                                   ///< source width in pixel
-  Int       m_iSourceHeight;                                  ///< source height in pixel
+  Int       m_iSourceHeight;                                  ///< source height in pixel (when interlaced = field height)
+  Int       m_iSourceHeightOrg;                               ///< original source height in pixel (when interlaced = frame height)
   Int       m_conformanceMode;
   Int       m_confLeft;
@@ -66,4 +67,7 @@
 #endif
 
+#if N0120_MAX_TID_REF_CFG
+  Int       m_maxTidIlRefPicsPlus1;
+#endif 
 #if SVC_EXTENSION
   Int       m_iWaveFrontSubstreams; //< If iWaveFrontSynchro, this is the number of substreams per frame (dependent tiles) or per tile (independent tiles).
@@ -84,4 +88,7 @@
   GOPEntry  m_GOPListLayer[MAX_GOP];                            ///< for layer
 #endif
+#if REPN_FORMAT_IN_VPS
+  Int       m_repFormatIdx;
+#endif
 public:
   TAppEncLayerCfg();
@@ -98,5 +105,5 @@
   Void  xPrintParameter();
 #endif
-  Bool  xCheckParameter();
+  Bool  xCheckParameter( Bool isField );
 
   Void    setAppEncCfg(TAppEncCfg* p) {m_cAppEncCfg = p;          }
@@ -107,4 +114,5 @@
   Int     getSourceWidth()            {return m_iSourceWidth;     }
   Int     getSourceHeight()           {return m_iSourceHeight;    }
+  Int     getSourceHeightOrg()        {return m_iSourceHeightOrg; }
   Int     getConformanceMode()        { return m_conformanceMode; }
   Int*    getPad()                    {return m_aiPad;            }
@@ -147,4 +155,13 @@
   GOPEntry getGOPEntry(Int i )        {return m_GOPListLayer[i];  }
 #endif
+#if REPN_FORMAT_IN_VPS
+  Int     getRepFormatIdx()           { return m_repFormatIdx;  }
+  Void    setRepFormatIdx(Int x)      { m_repFormatIdx = x;     }
+  Void    setSourceWidth(Int x)       { m_iSourceWidth = x;     }
+  Void    setSourceHeight(Int x)      { m_iSourceHeight = x;    }
+#endif
+#if N0120_MAX_TID_REF_CFG
+  Int     getMaxTidIlRefPicsPlus1()   { return m_maxTidIlRefPicsPlus1; }
+#endif 
 }; // END CLASS DEFINITION TAppEncLayerCfg
 
Index: /trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 441)
+++ /trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 442)
@@ -90,5 +90,65 @@
     vps->setMaxDecPicBuffering             ( m_maxDecPicBuffering[i], i );
   }
-
+#if REPN_FORMAT_IN_VPS
+  vps->setRepFormatIdxPresentFlag( true );   // Could be disabled to optimize in some cases.
+  Int maxRepFormatIdx = -1;
+  Int formatIdx = -1;
+  for(UInt layer=0; layer < m_numLayers; layer++)
+  {
+    // Auto generation of the format index
+    if( m_acLayerCfg[layer].getRepFormatIdx() == -1 )
+    {
+      // Currently only picture width and height are considred. It has to be updated if different chroma format and bit-depth will are used.
+      Bool found = false;
+      for( UInt idx = 0; idx < layer; idx++ )
+      {
+        if( m_acLayerCfg[layer].getSourceWidth() == m_acLayerCfg[idx].getSourceWidth() && m_acLayerCfg[layer].getSourceHeight() == m_acLayerCfg[idx].getSourceHeight() )
+        {
+          found = true;
+          break;
+        }
+      }
+      if( !found )
+      {
+        formatIdx++;
+      }
+
+      m_acLayerCfg[layer].setRepFormatIdx( formatIdx );
+    }
+
+    assert( m_acLayerCfg[layer].getRepFormatIdx() != -1 && "RepFormatIdx not assigned for a layer" );   
+    vps->setVpsRepFormatIdx( layer, m_acLayerCfg[layer].getRepFormatIdx() );
+    maxRepFormatIdx = std::max( m_acLayerCfg[layer].getRepFormatIdx(), maxRepFormatIdx );
+  }
+  assert( vps->getVpsRepFormatIdx( 0 ) == 0 );  // Base layer should point to the first one.
+  Int* mapIdxToLayer = new Int[maxRepFormatIdx + 1];
+  // Check that all the indices from 0 to maxRepFormatIdx are used in the VPS
+  for(Int i = 0; i <= maxRepFormatIdx; i++)
+  {
+    mapIdxToLayer[i] = -1;
+    UInt layer;
+    for(layer=0; layer < m_numLayers; layer++)
+    {
+      if( vps->getVpsRepFormatIdx(layer) == i )
+      {
+        mapIdxToLayer[i] = layer;
+        break;
+      }
+    }
+    assert( layer != m_numLayers );   // One of the VPS Rep format indices not set
+  }
+  vps->setVpsNumRepFormats( maxRepFormatIdx + 1 );
+  for(UInt idx=0; idx < vps->getVpsNumRepFormats(); idx++)
+  {
+    RepFormat *repFormat = vps->getVpsRepFormat( idx );    
+    repFormat->setPicWidthVpsInLumaSamples  ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceWidth()   );
+    repFormat->setPicHeightVpsInLumaSamples ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceHeight()  );
+    repFormat->setChromaFormatVpsIdc        ( 1                                             );  // Need modification to change for each layer - corresponds to 420
+    repFormat->setSeparateColourPlaneVpsFlag( 0                                             );  // Need modification to change for each layer
+    repFormat->setBitDepthVpsLuma           ( getInternalBitDepthY()                        );  // Need modification to change for each layer
+    repFormat->setBitDepthVpsChroma         ( getInternalBitDepthC()                        );  // Need modification to change for each layer
+  }
+  delete [] mapIdxToLayer;
+#endif
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
@@ -157,4 +217,10 @@
     m_acTEncTop[layer].setMaxTempLayer                 ( m_maxTempLayer );
     m_acTEncTop[layer].setUseAMP( m_enableAMP );
+#if N0120_MAX_TID_REF_CFG
+    if (layer<m_numLayers-1)
+    {
+       m_acTEncTop[layer].setMaxTidIlRefPicsPlus1 ( m_acLayerCfg[layer].getMaxTidIlRefPicsPlus1()); 
+    }
+#endif 
 #if VPS_EXTN_DIRECT_REF_LAYERS
     if(layer)
@@ -195,5 +261,5 @@
         {
           m_acTEncTop[layer].setMotionPredRefLayerId   ( i, m_acLayerCfg[layer].getMotionPredRefLayerId(i));
-          m_acTEncTop[layer].setMotionPredEnabledFlag  (m_acLayerCfg[layer].getSamplePredRefLayerId(i), true);
+          m_acTEncTop[layer].setMotionPredEnabledFlag  (m_acLayerCfg[layer].getMotionPredRefLayerId(i), true);
         }        
       }
@@ -397,4 +463,12 @@
     m_acTEncTop[layer].setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled );
     m_acTEncTop[layer].setScalableNestingSEIEnabled( m_scalableNestingSEIEnabled );
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+    m_acTEncTop[layer].setInterLayerConstrainedTileSetsSEIEnabled( m_interLayerConstrainedTileSetsSEIEnabled );
+    m_acTEncTop[layer].setIlNumSetsInMessage( m_ilNumSetsInMessage );
+    m_acTEncTop[layer].setSkippedTileSetPresentFlag( m_skippedTileSetPresentFlag );
+    m_acTEncTop[layer].setTopLeftTileIndex( m_topLeftTileIndex );
+    m_acTEncTop[layer].setBottomRightTileIndex( m_bottomRightTileIndex );
+    m_acTEncTop[layer].setIlcIdc( m_ilcIdc );
+#endif
     m_acTEncTop[layer].setUniformSpacingIdr          ( m_iUniformSpacingIdr );
     m_acTEncTop[layer].setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
@@ -475,7 +549,5 @@
     m_acTEncTop[layer].setLog2MaxMvLengthHorizontal( m_log2MaxMvLengthHorizontal );
     m_acTEncTop[layer].setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
-#if REF_IDX_FRAMEWORK
     m_acTEncTop[layer].setElRapSliceTypeB(layer == 0? 0 : m_elRapSliceBEnabled);
-#endif
 #if SCALED_REF_LAYER_OFFSETS
     if( layer > 0 )
@@ -824,10 +896,10 @@
 }
 
-Void TAppEncTop::xInitLib()
+Void TAppEncTop::xInitLib(Bool isFieldCoding)
 {
 #if SVC_EXTENSION
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
-    m_acTEncTop[layer].init();
+    m_acTEncTop[layer].init(isFieldCoding);
   }
 #if VPS_RENAME
@@ -889,10 +961,18 @@
 #endif
 #if N0120_MAX_TID_REF_PRESENT_FLAG
-  vps->setMaxTidIlRefPicsPlus1PresentFlag(true);
-  if (vps->getMaxTidIlRefPicsPlus1PresentFlag())
+#if N0120_MAX_TID_REF_CFG
+  vps->setMaxTidRefPresentFlag(m_maxTidRefPresentFlag);
+#else 
+  vps->setMaxTidRefPresentFlag(true);
+#endif 
+  if (vps->getMaxTidRefPresentFlag())
   {
     for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
     {
-      vps->setMaxSublayerForIlpPlus1(i, vps->getMaxTLayers()+1);
+#if N0120_MAX_TID_REF_CFG
+      vps->setMaxTidIlRefPicsPlus1(i, m_acTEncTop[i].getMaxTidIlRefPicsPlus1()); 
+#else 
+      vps->setMaxTidIlRefPicsPlus1(i, vps->getMaxTLayers()+1);
+#endif 
     }
   }
@@ -901,5 +981,5 @@
     for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
     {
-      vps->setMaxSublayerForIlpPlus1(i, 7);
+      vps->setMaxTidIlRefPicsPlus1(i, 7);
     }
   }
@@ -983,14 +1063,49 @@
 #endif
   }
+#if IL_SL_SIGNALLING_N0371
+  for(i = 1; i < vps->getMaxLayers(); i++)
+  {
+    for(Int j = 0; j < i; j++)
+    {
+      vps->setScalingListLayerDependency( i, j, vps->checkLayerDependency( i,j ) );
+    }
+  }
+#endif
 #endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG        
     vps->setMaxOneActiveRefLayerFlag(maxDirectRefLayers > 1 ? false : true); 
 #endif 
+#if N0147_IRAP_ALIGN_FLAG    
+    vps->setCrossLayerIrapAlignFlag(true); 
+    for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+    {
+      for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
+      {
+        if (vps->getDirectDependencyFlag( layerCtr, refLayerCtr))
+        {          
+          if(m_acTEncTop[layerCtr].getIntraPeriod() !=  m_acTEncTop[refLayerCtr].getIntraPeriod())
+          {
+            vps->setCrossLayerIrapAlignFlag(false);
+            break;
+          }
+        }
+      }
+    }
+
+    if( vps->getAvcBaseLayerFlag() )
+    {
+      vps->setCrossLayerIrapAlignFlag(false);
+    }
+#endif 
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   vps->setSingleLayerForNonIrapFlag(m_adaptiveResolutionChange > 0 ? true : false);
 #endif
-#else
-  m_cTEncTop.init();
-#endif
+#if VPS_EXTN_OFFSET
+  // to be updated according to the current semantics
+  vps->setExtensionOffset( 0xffff );
+#endif
+#else //SVC_EXTENSION
+  m_cTEncTop.init(isFieldCoding);
+#endif //SVC_EXTENSION
 }
 
@@ -1023,5 +1138,5 @@
   xInitLibCfg();
   xCreateLib();
-  xInitLib();
+  xInitLib(m_isField);
 
   // main encoder loop
@@ -1035,9 +1150,20 @@
     // allocate original YUV buffer
     pcPicYuvOrg[layer] = new TComPicYuv;
+    if( m_isField )
+    {
 #if SVC_UPSAMPLING
-    pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
-#else
-    pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
-#endif
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#else
+      pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
+#endif
+    }
+    else
+    {
+#if SVC_UPSAMPLING
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#else
+      pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
+#endif
+    }
   }
 
@@ -1081,8 +1207,15 @@
           m_iFrameRcvd++;
           // check end of file
-          bEos = (m_iFrameRcvd == m_framesToBeEncoded);
+          bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) );
         }
 
-        m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer] );
+        if ( m_isField )
+        {
+          m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer], m_isTopFieldFirst );
+        }
+        else
+        {
+          m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer] );
+        }
       }
 
@@ -1131,5 +1264,12 @@
       {
         // call encoding function for one frame
-        m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP );
+        if ( m_isField )
+        {
+          m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP, m_isTopFieldFirst );
+        }
+        else
+        {
+          m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP );
+        }
       }
     }
@@ -1168,5 +1308,5 @@
     if (bEos)
     {
-      printOutSummary();
+      printOutSummary(m_isTopFieldFirst);
     }
 
@@ -1200,5 +1340,5 @@
 }
 
-Void TAppEncTop::printOutSummary()
+Void TAppEncTop::printOutSummary(Bool isField)
 {
   UInt layer;
@@ -1207,8 +1347,18 @@
   for(layer = 0; layer < m_numLayers; layer++)
   {
-    m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate());
-    m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
-    m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
-    m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
+    if(isField)
+    {
+      m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2);
+      m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2 );
+      m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2 );
+      m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2 );
+    }
+    else
+    {
+      m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate());
+      m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
+      m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
+      m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
+    }
   }
 
@@ -1241,4 +1391,19 @@
     m_gcAnalyzeB[layer].printOut('b', layer);
   }
+
+  if(isField)
+  {
+    for(layer = 0; layer < m_numLayers; layer++)
+    {
+      //-- interlaced summary
+      m_gcAnalyzeAll_in.setFrmRate( m_acLayerCfg[layer].getFrameRate());
+      printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" );
+      m_gcAnalyzeAll_in.printOutInterlaced('a',  m_gcAnalyzeAll[layer].getBits());
+
+#if _SUMMARY_OUT_
+      m_gcAnalyzeAll_in.printSummaryOutInterlaced();
+#endif
+    }
+  }
 }
 
@@ -1259,5 +1424,5 @@
   xInitLibCfg();
   xCreateLib();
-  xInitLib();
+  xInitLib(m_isField);
 
   // main encoder loop
@@ -1268,5 +1433,12 @@
 
   // allocate original YUV buffer
-  pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
+  if( m_isField )
+  {
+    pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeightOrg, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
+  }
+  else
+  {
+    pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
+  }
 
   while ( !bEos )
@@ -1281,6 +1453,5 @@
     m_iFrameRcvd++;
 
-    bEos = (m_iFrameRcvd == m_framesToBeEncoded);
-
+    bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) );
     Bool flush = 0;
     // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
@@ -1294,5 +1465,12 @@
 
     // call encoding function for one frame
+    if ( m_isField )
+    {
+      m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded, m_isTopFieldFirst);
+    }
+    else
+    {
     m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded );
+    }
 
     // write bistream to file if necessary
@@ -1304,5 +1482,5 @@
   }
 
-  m_cTEncTop.printSummary();
+  m_cTEncTop.printSummary(m_isField);
 
   // delete original YUV buffer
@@ -1378,24 +1556,53 @@
 Void TAppEncTop::xWriteRecon(UInt layer, Int iNumEncoded)
 {
-  Int i;
-
-  TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end();
-
-  for ( i = 0; i < iNumEncoded; i++ )
-  {
-    --iterPicYuvRec;
-  }
-
-  for ( i = 0; i < iNumEncoded; i++ )
-  {
-    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
+  if (m_isField)
+  {
+    //Reinterlace fields
+    Int i;
+    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end();
+
+    for ( i = 0; i < iNumEncoded; i++ )
+    {
+      --iterPicYuvRec;
+    }
+
+    for ( i = 0; i < iNumEncoded/2; i++ )
+    {
+      TComPicYuv*  pcPicYuvRecTop  = *(iterPicYuvRec++);
+      TComPicYuv*  pcPicYuvRecBottom  = *(iterPicYuvRec++);
+
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
-    if (!m_acLayerCfg[layer].getReconFile().empty() && pcPicYuvRec->isReconstructed())
-#else
-    if (!m_acLayerCfg[layer].getReconFile().empty())
-#endif
-    {
-      m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(), 
-        m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom() );
+      if (!m_acLayerCfg[layer].getReconFile().empty() && pcPicYuvRecTop->isReconstructed() && pcPicYuvRecBottom->isReconstructed())
+#else
+      if (!m_acLayerCfg[layer].getReconFile().empty())
+#endif
+      {
+        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRecTop, pcPicYuvRecBottom, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(), m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom(), m_isTopFieldFirst );
+      }
+    }
+  }
+  else
+  {
+    Int i;
+
+    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end();
+
+    for ( i = 0; i < iNumEncoded; i++ )
+    {
+      --iterPicYuvRec;
+    }
+
+    for ( i = 0; i < iNumEncoded; i++ )
+    {
+      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
+#if M0040_ADAPTIVE_RESOLUTION_CHANGE
+      if (!m_acLayerCfg[layer].getReconFile().empty() && pcPicYuvRec->isReconstructed())
+#else
+      if (!m_acLayerCfg[layer].getReconFile().empty())
+#endif
+      {
+        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(), 
+          m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom() );
+      }
     }
   }
@@ -1404,17 +1611,41 @@
 Void TAppEncTop::xWriteStream(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
 {
-  Int i;
-
-  list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
+  if (m_isField)
+  {
+    //Reinterlace fields
+    Int i;
+    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
 
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
-  for ( i = 0; i < iNumEncoded && iterBitstream != accessUnits.end(); i++ )
-#else
-  for ( i = 0; i < iNumEncoded; i++ )
-#endif
-  {
-    const AccessUnit& au = *(iterBitstream++);
-    const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
-    rateStatsAccum(au, stats);
+    for ( i = 0; i < iNumEncoded/2 && iterBitstream != accessUnits.end(); i++ )
+#else
+    for ( i = 0; i < iNumEncoded/2; i++ )
+#endif
+    {      
+      const AccessUnit& auTop = *(iterBitstream++);
+      const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
+      rateStatsAccum(auTop, statsTop);
+
+      const AccessUnit& auBottom = *(iterBitstream++);
+      const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom);
+      rateStatsAccum(auBottom, statsBottom);
+    }
+  }
+  else
+  {
+    Int i;
+
+    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
+
+#if M0040_ADAPTIVE_RESOLUTION_CHANGE
+    for ( i = 0; i < iNumEncoded && iterBitstream != accessUnits.end(); i++ )
+#else
+    for ( i = 0; i < iNumEncoded; i++ )
+#endif
+    {
+      const AccessUnit& au = *(iterBitstream++);
+      const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
+      rateStatsAccum(au, stats);
+    }
   }
 }
@@ -1460,29 +1691,61 @@
 Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
 {
-  Int i;
-
-  TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
-  list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
-
-  for ( i = 0; i < iNumEncoded; i++ )
-  {
-    --iterPicYuvRec;
-  }
-
-  for ( i = 0; i < iNumEncoded; i++ )
-  {
-    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
-    if (m_pchReconFile)
-    {
-#if SYNTAX_OUTPUT && ILP_DECODED_PICTURE
-      m_cTVideoIOYuvReconFile.write( pcPicYuvRec );
-#else
-      m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
-#endif
-    }
-
-    const AccessUnit& au = *(iterBitstream++);
-    const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
-    rateStatsAccum(au, stats);
+  if (m_isField)
+  {
+    //Reinterlace fields
+    Int i;
+    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
+    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
+
+    for ( i = 0; i < iNumEncoded; i++ )
+    {
+      --iterPicYuvRec;
+    }
+
+    for ( i = 0; i < iNumEncoded/2; i++ )
+    {
+      TComPicYuv*  pcPicYuvRecTop  = *(iterPicYuvRec++);
+      TComPicYuv*  pcPicYuvRecBottom  = *(iterPicYuvRec++);
+
+      if (m_pchReconFile)
+      {
+        m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, m_confLeft, m_confRight, m_confTop, m_confBottom, m_isTopFieldFirst );
+      }
+
+      const AccessUnit& auTop = *(iterBitstream++);
+      const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
+      rateStatsAccum(auTop, statsTop);
+
+      const AccessUnit& auBottom = *(iterBitstream++);
+      const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom);
+      rateStatsAccum(auBottom, statsBottom);
+    }
+  }
+  else
+  {
+    Int i;
+
+    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
+    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
+
+    for ( i = 0; i < iNumEncoded; i++ )
+    {
+      --iterPicYuvRec;
+    }
+
+    for ( i = 0; i < iNumEncoded; i++ )
+    {
+      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
+      if (m_pchReconFile)
+      {
+#if SYNTAX_OUTPUT
+        m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
+#endif
+      }
+
+      const AccessUnit& au = *(iterBitstream++);
+      const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
+      rateStatsAccum(au, stats);
+    }
   }
 }
Index: /trunk/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncTop.h	(revision 441)
+++ /trunk/source/App/TAppEncoder/TAppEncTop.h	(revision 442)
@@ -82,5 +82,5 @@
   Void  xCreateLib        ();                               ///< create files & encoder class
   Void  xInitLibCfg       ();                               ///< initialize internal variables
-  Void  xInitLib          ();                               ///< initialize encoder class
+  Void  xInitLib          (Bool isFieldCoding);             ///< initialize encoder class
   Void  xDestroyLib       ();                               ///< destroy encoder class
   
@@ -99,5 +99,5 @@
   Void xWriteRecon(UInt layer, Int iNumEncoded);
   Void xWriteStream(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits);
-  Void printOutSummary();
+  Void printOutSummary(Bool isField);
 #else
   Void xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits); ///< write bitstream to file
Index: /trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- /trunk/source/Lib/TLibCommon/CommonDef.h	(revision 441)
+++ /trunk/source/Lib/TLibCommon/CommonDef.h	(revision 442)
@@ -57,7 +57,7 @@
 
 #if SVC_EXTENSION
-#define NV_VERSION        "3.0.1"                 ///< Current software version
-#else
-#define NV_VERSION        "11.0"                ///< Current software version
+#define NV_VERSION        "3.1"                 ///< Current software version
+#else
+#define NV_VERSION        "12.0"                ///< Current software version
 #endif
 
Index: /trunk/source/Lib/TLibCommon/SEI.h
===================================================================
--- /trunk/source/Lib/TLibCommon/SEI.h	(revision 441)
+++ /trunk/source/Lib/TLibCommon/SEI.h	(revision 442)
@@ -75,4 +75,7 @@
     LAYERS_PRESENT                       = 137,
 #endif
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+    INTER_LAYER_CONSTRAINED_TILE_SETS    = 138
+#endif
   };
   
@@ -381,4 +384,28 @@
 };
 
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+class SEIInterLayerConstrainedTileSets : public SEI
+{
+public:
+  PayloadType payloadType() const { return INTER_LAYER_CONSTRAINED_TILE_SETS; }
+
+  SEIInterLayerConstrainedTileSets() {}
+  virtual ~SEIInterLayerConstrainedTileSets() {}
+
+  Bool m_ilAllTilesExactSampleValueMatchFlag;
+  Bool m_ilOneTilePerTileSetFlag;
+  UInt m_ilNumSetsInMessageMinus1;
+  Bool m_skippedTileSetPresentFlag;
+  UInt m_ilctsId[256];
+  UInt m_ilNumTileRectsInSetMinus1[256];
+  UInt m_ilTopLeftTileIndex[256][440];
+  UInt m_ilBottomRightTileIndex[256][440];
+  UInt m_ilcIdc[256];
+  Bool m_ilExactSampleValueMatchFlag[256];
+  UInt m_allTilesIlcIdc;
+};
+#endif
+
+
 typedef std::list<SEI*> SEIMessages;
 
Index: /trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 442)
@@ -1273,5 +1273,9 @@
   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
   
+#if REPN_FORMAT_IN_VPS
+  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getPicWidthInLumaSamples() )
+#else
   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
+#endif
   {
     uiARPartUnitIdx = MAX_UINT;
@@ -1335,6 +1339,10 @@
   UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhHeight[0] / m_pcPic->getMinCUHeight() - 1)*m_pcPic->getNumPartInWidth();
   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
-  
+
+#if REPN_FORMAT_IN_VPS
+  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getPicHeightInLumaSamples() )
+#else
   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
+#endif
   {
     uiBLPartUnitIdx = MAX_UINT;
@@ -1384,5 +1392,9 @@
   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
   
+#if REPN_FORMAT_IN_VPS
+  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getPicHeightInLumaSamples())
+#else
   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples())
+#endif
   {
     uiBLPartUnitIdx = MAX_UINT;
@@ -1432,5 +1444,9 @@
   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
   
+#if REPN_FORMAT_IN_VPS
+  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getPicWidthInLumaSamples() )
+#else
   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
+#endif
   {
     uiARPartUnitIdx = MAX_UINT;
@@ -1703,7 +1719,7 @@
 {
   // check BL mode
-  UInt          uiCUAddrBase, uiAbsPartAddrBase;
+  UInt          uiCUAddrBase = 0, uiAbsPartAddrBase = 0;
   // the right reference layerIdc should be specified, currently it is set to m_layerId-1
-  TComDataCU*   pcTempCU = getBaseColCU(m_layerId - 1, uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase );
+  TComDataCU*   pcTempCU = getBaseColCU(m_layerId - 1, uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase, 0 );
 
   if( pcTempCU->getPredictionMode( uiAbsPartAddrBase ) != MODE_INTRA )
@@ -2684,4 +2700,12 @@
     Int uiLCUIdx = -1;
 
+#if REPN_FORMAT_IN_VPS
+    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getPicWidthInLumaSamples() )  // image boundary check
+    {
+    }
+    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getPicHeightInLumaSamples() )
+    {
+    }
+#else
     if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
     {
@@ -2690,4 +2714,5 @@
     {
     }
+#endif
     else
     {
@@ -3020,4 +3045,12 @@
     uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
     Int uiLCUIdx = -1;
+#if REPN_FORMAT_IN_VPS
+    if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getPicWidthInLumaSamples() )  // image boundary check
+    {
+    }
+    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getPicHeightInLumaSamples() )
+    {
+    }
+#else
     if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
     {
@@ -3026,4 +3059,5 @@
     {
     }
+#endif
     else
     {
@@ -3095,8 +3129,16 @@
   Int  iMvShift = 2;
   Int iOffset = 8;
+#if REPN_FORMAT_IN_VPS
+  Int iHorMax = ( m_pcSlice->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
+#else
   Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
+#endif
   Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
   
+#if REPN_FORMAT_IN_VPS
+  Int iVerMax = ( m_pcSlice->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
+#else
   Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
+#endif
   Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
   
@@ -3946,82 +3988,16 @@
 }
 
-#if SVC_COL_BLK
-TComDataCU*  TComDataCU::getBaseColCU( UInt refLayerIdc, UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
-{
-#if 1 // it should provide identical resutls
+#if SVC_EXTENSION
+TComDataCU*  TComDataCU::getBaseColCU( UInt refLayerIdc, UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase, Int iMotionMapping )
+{
   UInt uiPelX = getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiCuAbsPartIdx] ];
   UInt uiPelY = getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiCuAbsPartIdx] ];
 
-  return getBaseColCU( refLayerIdc, uiPelX, uiPelY, uiCUAddrBase, uiAbsPartIdxBase );
-#else
-  TComPic* cBaseColPic = m_pcSlice->getBaseColPic();
-
-#if SVC_UPSAMPLING
-  Int widthBL   = cBaseColPic->getPicYuvRec()->getWidth () - cBaseColPic->getPicYuvRec()->getPicCropLeftOffset() - cBaseColPic->getPicYuvRec()->getPicCropRightOffset();
-  Int heightBL  = cBaseColPic->getPicYuvRec()->getHeight() - cBaseColPic->getPicYuvRec()->getPicCropTopOffset() - cBaseColPic->getPicYuvRec()->getPicCropBottomOffset();
-
-  Int widthEL   = m_pcPic->getPicYuvRec()->getWidth() - m_pcPic->getPicYuvRec()->getPicCropLeftOffset() - m_pcPic->getPicYuvRec()->getPicCropRightOffset();
-  Int heightEL  = m_pcPic->getPicYuvRec()->getHeight() - m_pcPic->getPicYuvRec()->getPicCropTopOffset() - m_pcPic->getPicYuvRec()->getPicCropBottomOffset();
-#else
-  Int widthBL   = cBaseColPic->getPicYuvRec()->getWidth();
-  Int heightBL  = cBaseColPic->getPicYuvRec()->getHeight();
-
-  Int widthEL   = m_pcPic->getPicYuvRec()->getWidth();
-  Int heightEL  = m_pcPic->getPicYuvRec()->getHeight();
-#endif
-
-  if (widthBL == widthEL && heightEL == heightBL)
-  {
-    uiAbsPartIdxBase = uiCuAbsPartIdx + m_uiAbsIdxInLCU;
-    uiCUAddrBase = m_uiCUAddr;
-  }
-  else
-  {
-    UInt uiMinUnitSize = m_pcPic->getMinCUWidth();
-    UInt uiRasterAddr  = g_auiZscanToRaster[uiCuAbsPartIdx];
-    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
-
-    Int iEX = m_uiCUPelX + uiMinUnitSize*(uiRasterAddr%uiNumPartInCUWidth);
-    Int iEY = m_uiCUPelY + uiMinUnitSize*(uiRasterAddr/uiNumPartInCUWidth);
-
-    Int iBX = (iEX*widthBL + widthEL/2)/widthEL;
-    Int iBY = (iEY*heightBL+ heightEL/2)/heightEL;
-
-    uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
-
-    assert(uiCUAddrBase < cBaseColPic->getNumCUsInFrame());
-    
-    UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*cBaseColPic->getNumPartInWidth()
-                          + (iBX - (iBX/g_uiMaxCUWidth)*g_uiMaxCUWidth)/uiMinUnitSize;
-
-    uiAbsPartIdxBase = g_auiRasterToZscan[uiRasterAddrBase];
-  }
-
-  return cBaseColPic->getCU(uiCUAddrBase);
-#endif
-}
-
-TComDataCU*  TComDataCU::getBaseColCU( UInt refLayerIdc, UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
+  return getBaseColCU( refLayerIdc, uiPelX, uiPelY, uiCUAddrBase, uiAbsPartIdxBase, iMotionMapping );
+}
+
+TComDataCU*  TComDataCU::getBaseColCU( UInt refLayerIdc, UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase, Int iMotionMapping )
 {
   TComPic* cBaseColPic = m_pcSlice->getBaseColPic(refLayerIdc);
-
-#if !SIMPLIFIED_MV_POS_SCALING
-#if SVC_UPSAMPLING && !ILP_DECODED_PICTURE
-  const Window &confBL = cBaseColPic->getPicYuvRec()->getConformanceWindow();
-  const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
-
-  Int widthBL   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-  Int heightBL  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-
-  Int widthEL   = m_pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
-  Int heightEL  = m_pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-#else
-  Int widthBL   = cBaseColPic->getPicYuvRec()->getWidth();
-  Int heightBL  = cBaseColPic->getPicYuvRec()->getHeight();
-
-  Int widthEL   = m_pcPic->getPicYuvRec()->getWidth();
-  Int heightEL  = m_pcPic->getPicYuvRec()->getHeight();
-#endif
-#endif
 
   uiPelX = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getWidth() - 1, uiPelX);
@@ -4030,5 +4006,4 @@
   UInt uiMinUnitSize = m_pcPic->getMinCUWidth();
 
-#if SIMPLIFIED_MV_POS_SCALING
 #if SCALED_REF_LAYER_OFFSETS
   Int leftStartL = this->getSlice()->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowLeftOffset();
@@ -4040,12 +4015,11 @@
   Int iBY = (uiPelY*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
 #endif
-#else
-  Int iBX = (uiPelX*widthBL + widthEL/2)/widthEL;
-  Int iBY = (uiPelY*heightBL+ heightEL/2)/heightEL;
-#endif
 
 #if N0139_POSITION_ROUNDING_OFFSET
-  iBX += 4;
-  iBY += 4;
+  if( iMotionMapping == 1 )
+  {
+    iBX += 4;
+    iBY += 4;
+  }
 #endif
 
@@ -4060,18 +4034,4 @@
   }
 
-#if AVC_SYNTAX && !ILP_DECODED_PICTURE
-#if !ILP_DECODED_PICTURE
-  const Window &confBL = cBaseColPic->getPicYuvRec()->getConformanceWindow();
-  const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
-
-  Int widthBL   = m_pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-  Int heightBL  = m_pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-#endif
-  if( iBX >= widthBL || iBY >= heightBL ) //outside of the reference layer cropped picture
-  {
-    return NULL;
-  }
-#endif
-
   uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
 
@@ -4090,21 +4050,6 @@
   TComMvField cMvFieldBase;
   TComMv cMv;
-#if SIMPLIFIED_MV_POS_SCALING
+
   cMv = rcMvFieldBase.getMv().scaleMv( g_mvScalingFactor[refLayerIdc][0], g_mvScalingFactor[refLayerIdc][1] );
-#else
-  const Window &confBL = m_pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
-  const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
-
-  Int widthBL   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-  Int heightBL  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-
-  Int widthEL   = m_pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
-  Int heightEL  = m_pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-
-  Int iMvX = (rcMvFieldBase.getHor()*widthEL + (widthBL/2 -1) * (rcMvFieldBase.getHor() > 0 ? 1: -1) )/widthBL;
-  Int iMvY = (rcMvFieldBase.getVer()*heightEL + (heightBL/2 -1) * (rcMvFieldBase.getVer() > 0 ? 1: -1) )/heightBL;
-
-  cMv.set(iMvX, iMvY);
-#endif
 
   rcMvFieldEnhance.setMvField( cMv, rcMvFieldBase.getRefIdx() );
Index: /trunk/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 442)
@@ -516,5 +516,5 @@
   UInt&         getTotalBins            ()                            { return m_uiTotalBins;                                                                                                  }
 
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
 #if FAST_INTRA_SHVC
   Int           reduceSetOfIntraModes              (  UInt   uiAbsPartIdx, Int* uiIntraDirPred, Int &fullSetOfModes );
@@ -538,10 +538,8 @@
   UInt          getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra);
 
-#if REF_IDX_FRAMEWORK
-#if SVC_COL_BLK 
-  TComDataCU*   getBaseColCU( UInt refLayerIdc, UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase );
-  TComDataCU*   getBaseColCU( UInt refLayerIdc, UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase );
+#if SVC_EXTENSION
+  TComDataCU*   getBaseColCU( UInt refLayerIdc, UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase, Int iMotionMapping = 0 );
+  TComDataCU*   getBaseColCU( UInt refLayerIdc, UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase, Int iMotionMapping = 0 );
   Void          scaleBaseMV( UInt refLayerIdc, TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase );
-#endif
 #endif
 };
Index: /trunk/source/Lib/TLibCommon/TComLoopFilter.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 442)
@@ -180,5 +180,9 @@
       UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsZorderIdx] ];
       UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsZorderIdx] ];
+#if REPN_FORMAT_IN_VPS
+      if( ( uiLPelX < pcCU->getSlice()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getPicHeightInLumaSamples() ) )
+#else
       if( ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
       {
         xDeblockCU( pcCU, uiAbsZorderIdx, uiDepth+1, Edge );
Index: /trunk/source/Lib/TLibCommon/TComMv.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComMv.h	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComMv.h	(revision 442)
@@ -40,4 +40,5 @@
 
 #include "CommonDef.h"
+#include <cstdlib>
 
 //! \ingroup TLibCommon
@@ -149,5 +150,5 @@
     return TComMv( mvx, mvy );
   }
-#if SIMPLIFIED_MV_POS_SCALING
+#if SVC_EXTENSION
   const TComMv scaleMv( Int iScaleX, Int iScaleY ) const
   {
Index: /trunk/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 442)
@@ -53,5 +53,4 @@
 , m_bUsedByCurr                           (false)
 , m_bIsLongTerm                           (false)
-, m_bIsUsedAsLongTerm                     (false)
 , m_apcPicSym                             (NULL)
 , m_pcPicYuvPred                          (NULL)
@@ -213,6 +212,11 @@
   UInt maxNumSUInLCU = getNumPartInCU();
   UInt numLCUInPic   = getNumCUsInFrame();
+#if REPN_FORMAT_IN_VPS
+  UInt picWidth      = getSlice(0)->getPicWidthInLumaSamples();
+  UInt picHeight     = getSlice(0)->getPicHeightInLumaSamples();
+#else
   UInt picWidth      = getSlice(0)->getSPS()->getPicWidthInLumaSamples();
   UInt picHeight     = getSlice(0)->getSPS()->getPicHeightInLumaSamples();
+#endif
   Int  numLCUsInPicWidth = getFrameWidthInCU();
   Int  numLCUsInPicHeight= getFrameHeightInCU();
@@ -524,5 +528,5 @@
 }
 
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
 Void copyOnetoOnePicture(    // SVC_NONCOLL
                   Pel *in,        
@@ -570,15 +574,4 @@
 Void TComPic::copyUpsampledMvField(UInt refLayerIdc, TComPic* pcPicBase)
 {
-#if AVC_SYNTAX && !ILP_DECODED_PICTURE
-  const Window &confBL = pcPicBase->getConformanceWindow();
-  const Window &confEL = getPicYuvRec()->getConformanceWindow();
-
-  Int widthBL   = pcPicBase->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-  Int heightBL  = pcPicBase->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-
-  Int widthEL   = getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
-  Int heightEL  = getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-#endif
-
   UInt numPartitions   = 1<<(g_uiMaxCUDepth<<1);
   UInt widthMinPU      = g_uiMaxCUWidth/(1<<g_uiMaxCUDepth);
@@ -598,14 +591,7 @@
 
       TComDataCU *pcColCU = 0;
-      pcColCU = pcCUDes->getBaseColCU(refLayerIdc, pelX + 8, pelY + 8, baseCUAddr, baseAbsPartIdx);
-
-#if AVC_SYNTAX && !ILP_DECODED_PICTURE
-      Int xBL = ( (pelX + 8) * widthBL + widthEL/2 ) / widthEL;
-      Int yBL = ( (pelY + 8) * heightBL+ heightEL/2 ) / heightEL;
-
-      if( ( xBL < widthBL && yBL < heightBL ) && pcColCU && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_NONE) && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
-#else
+      pcColCU = pcCUDes->getBaseColCU(refLayerIdc, pelX + 8, pelY + 8, baseCUAddr, baseAbsPartIdx, 1);
+
       if( pcColCU && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_NONE) && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
-#endif
       {
         for(UInt refPicList = 0; refPicList < 2; refPicList++)  //for each reference list
@@ -670,12 +656,7 @@
   }
 
-#if ILP_DECODED_PICTURE
   UInt   width      = this->getPicYuvRec()->getWidth();
   UInt   height     = this->getPicYuvRec()->getHeight();
-#else
-  const Window &conf = this->getPicYuvRec()->getConformanceWindow();
-  UInt   width      = this->getPicYuvRec()->getWidth() - conf.getWindowLeftOffset() - conf.getWindowRightOffset();
-  UInt   height     = this->getPicYuvRec()->getHeight() - conf.getWindowTopOffset() - conf.getWindowBottomOffset();
-#endif
+
   UInt64 poc        = (UInt64)this->getPOC();
   UInt   partWidth  = width / 4;
@@ -754,12 +735,6 @@
   }
 
-#if ILP_DECODED_PICTURE
   UInt   width       = this->getPicYuvRec()->getWidth();
   UInt   height      = this->getPicYuvRec()->getHeight();
-#else
-  const Window &conf = this->getConformanceWindow();
-  UInt   width       = this->getPicYuvRec()->getWidth() - conf.getWindowLeftOffset() - conf.getWindowRightOffset();
-  UInt   height      = this->getPicYuvRec()->getHeight() - conf.getWindowTopOffset() - conf.getWindowBottomOffset();
-#endif
 
   UInt64 poc        = (UInt64)this->getPOC();
Index: /trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPic.h	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComPic.h	(revision 442)
@@ -66,5 +66,4 @@
   Bool                  m_bUsedByCurr;            //  Used by current picture
   Bool                  m_bIsLongTerm;            //  IS long term picture
-  Bool                  m_bIsUsedAsLongTerm;      //  long term picture is used as reference before
   TComPicSym*           m_apcPicSym;              //  Symbol
   
@@ -88,4 +87,7 @@
   Window                m_defaultDisplayWindow;
 
+  Bool                  m_isTop;
+  Bool                  m_isField;
+  
   std::vector<std::vector<TComDataCU*> > m_vSliceCUDataLink;
 
@@ -194,4 +196,11 @@
   std::vector<TComDataCU*>& getOneSliceCUDataForNDBFilter      (Int sliceID) { return m_vSliceCUDataLink[sliceID];}
 
+  /* field coding parameters*/
+
+  Void              setTopField(bool b)                  {m_isTop = b;}
+  Bool              isTopField()                         {return m_isTop;}
+  Void              setField(bool b)                     {m_isField = b;}
+  Bool              isField()                            {return m_isField;}
+
   /** transfer ownership of seis to this picture */
   void setSEIs(SEIMessages& seis) { m_SEIs = seis; }
@@ -207,10 +216,10 @@
   const SEIMessages& getSEIs() const { return m_SEIs; }
 
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   Void  copyUpsampledPictureYuv(TComPicYuv*   pcPicYuvIn, TComPicYuv*   pcPicYuvOut); 
-#endif
 #if AVC_SYNTAX
   Void readBLSyntax( fstream* filestream, UInt numBytes );
 #endif
+#endif
 #if SYNTAX_OUTPUT
   Void wrireBLSyntax( fstream* filestream, UInt numBytes );
Index: /trunk/source/Lib/TLibCommon/TComPicSym.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPicSym.cpp	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComPicSym.cpp	(revision 442)
@@ -61,5 +61,4 @@
 ,m_uiNumAllocatedSlice (0)
 ,m_apcTComDataCU (NULL)
-,m_iTileBoundaryIndependenceIdr (0)
 ,m_iNumColumnsMinus1 (0)
 ,m_iNumRowsMinus1(0)
@@ -116,4 +115,9 @@
   m_puiCUOrderMap = new UInt[m_uiNumCUsInFrame+1];
   m_puiTileIdxMap = new UInt[m_uiNumCUsInFrame];
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  m_piTileSetIdxMap = new Int[m_uiNumCUsInFrame];
+  m_pucTileSetType = new UChar[m_uiNumCUsInFrame];
+  m_pbSkippedTileSetFlag = new Bool[m_uiNumCUsInFrame];
+#endif
   m_puiInverseCUOrderMap = new UInt[m_uiNumCUsInFrame+1];
 
@@ -147,5 +151,5 @@
   m_apcTComDataCU = NULL;
 
-#if AVC_BASE || REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   if( m_apcTComTile )
   {
@@ -156,5 +160,5 @@
   }
   delete [] m_apcTComTile;
-#if AVC_BASE || REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   }
 #endif
@@ -167,4 +171,12 @@
   delete [] m_puiTileIdxMap;
   m_puiTileIdxMap = NULL;
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  delete [] m_piTileSetIdxMap;
+  m_piTileSetIdxMap = NULL;
+  delete [] m_pucTileSetType;
+  m_pucTileSetType = NULL;
+  delete [] m_pbSkippedTileSetFlag;
+  m_pbSkippedTileSetFlag = NULL;
+#endif
 
   delete [] m_puiInverseCUOrderMap;
Index: /trunk/source/Lib/TLibCommon/TComPicSym.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPicSym.h	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComPicSym.h	(revision 442)
@@ -100,5 +100,4 @@
   TComDataCU**  m_apcTComDataCU;        ///< array of CU data
   
-  Int           m_iTileBoundaryIndependenceIdr;
   Int           m_iNumColumnsMinus1; 
   Int           m_iNumRowsMinus1;
@@ -106,4 +105,9 @@
   UInt*         m_puiCUOrderMap;       //the map of LCU raster scan address relative to LCU encoding order 
   UInt*         m_puiTileIdxMap;       //the map of the tile index relative to LCU raster scan address 
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Int*          m_piTileSetIdxMap;     //the map of the tile set index relative to LCU raster scan address
+  UChar*        m_pucTileSetType;
+  Bool*         m_pbSkippedTileSetFlag;
+#endif
   UInt*         m_puiInverseCUOrderMap;
 
@@ -144,4 +148,15 @@
   UInt         getCUOrderMap( Int encCUOrder )                       { return *(m_puiCUOrderMap + (encCUOrder>=m_uiNumCUsInFrame ? m_uiNumCUsInFrame : encCUOrder)); }
   UInt         getTileIdxMap( Int i )                                { return *(m_puiTileIdxMap + i); }
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Void         setTileSetIdxMap( Int i, Int tileSetIdx, UChar setType, Bool skipFlag )
+  {
+    m_piTileSetIdxMap[i]       = tileSetIdx;
+    m_pucTileSetType[i]        = setType;
+    m_pbSkippedTileSetFlag[i]  = skipFlag;
+  }
+  Int          getTileSetIdxMap( Int i )                             { return *(m_piTileSetIdxMap + i); }
+  UChar        getTileSetType( Int i )                               { return *(m_pucTileSetType + i); }
+  Bool         getSkippedTileSetFlag( Int i )                        { return *(m_pbSkippedTileSetFlag + i); }
+#endif
   Void         setInverseCUOrderMap( Int cuAddr, Int encCUOrder )    { *(m_puiInverseCUOrderMap + cuAddr) = encCUOrder; }
   UInt         getInverseCUOrderMap( Int cuAddr )                    { return *(m_puiInverseCUOrderMap + (cuAddr>=m_uiNumCUsInFrame ? m_uiNumCUsInFrame : cuAddr)); }
Index: /trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 442)
@@ -696,5 +696,5 @@
   Int k, l, bottomLeft, topRight;
   Int horPred;
-  Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
+  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
   UInt blkSize = width;
   UInt offset2D = width;
Index: /trunk/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 442)
@@ -118,5 +118,5 @@
   Int  getPredicBufHeight()       { return m_iYuvExtHeight; }
 
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
 #if SVC_UPSAMPLING
 #if SCALED_REF_LAYER_OFFSETS
Index: /trunk/source/Lib/TLibCommon/TComRdCost.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComRdCost.h	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComRdCost.h	(revision 442)
@@ -116,6 +116,4 @@
 private:
   // for distortion
-  Int                     m_iBlkWidth;
-  Int                     m_iBlkHeight;
   
 #if AMP_SAD
Index: /trunk/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 442)
@@ -55,10 +55,9 @@
   ::memset( g_aucConvertToBit,   -1, sizeof( g_aucConvertToBit ) );
   c=0;
-  for ( i=4; i<MAX_CU_SIZE; i*=2 )
+  for ( i=4; i<=MAX_CU_SIZE; i*=2 )
   {
     g_aucConvertToBit[ i ] = c;
     c++;
   }
-  g_aucConvertToBit[ i ] = c;
   
   c=2;
@@ -278,5 +277,5 @@
 
 #if FAST_UDI_USE_MPM
-const UChar g_aucIntraModeNumFast[7] =
+const UChar g_aucIntraModeNumFast[MAX_CU_DEPTH] =
 {
   3,  //   2x2
@@ -285,9 +284,8 @@
   3,  //  16x16   
   3,  //  32x32   
-  3,  //  64x64   
-  3   // 128x128  
+  3   //  64x64   
 };
 #else // FAST_UDI_USE_MPM
-const UChar g_aucIntraModeNumFast[7] =
+const UChar g_aucIntraModeNumFast[MAX_CU_DEPTH] =
 {
   3,  //   2x2
@@ -296,6 +294,5 @@
   4,  //  16x16   33
   4,  //  32x32   33
-  5,  //  64x64   33
-  4   // 128x128  33
+  5   //  64x64   33
 };
 #endif // FAST_UDI_USE_MPM
@@ -523,7 +520,14 @@
 Int  g_eTTable[4] = {0,3,1,2};
 
-#if SIMPLIFIED_MV_POS_SCALING
+#if SVC_EXTENSION
 Int g_mvScalingFactor  [MAX_LAYERS][2] = {{0,0}, {0,0}};
 Int g_posScalingFactor [MAX_LAYERS][2] = {{0,0}, {0,0}};
+
+#if IL_SL_SIGNALLING_N0371
+Int ref_scalingListDC         [MAX_LAYERS][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM];
+Int ref_scalingListCoef       [MAX_LAYERS][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][MAX_MATRIX_COEF_NUM];
+Int activeRefPPSId            [MAX_LAYERS];
+Int activeRefSPSId            [MAX_LAYERS];
+#endif 
 #endif
 
Index: /trunk/source/Lib/TLibCommon/TComRom.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComRom.h	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComRom.h	(revision 442)
@@ -51,5 +51,5 @@
 // ====================================================================================================================
 
-#define     MAX_CU_DEPTH            7                           // log2(LCUSize)
+#define     MAX_CU_DEPTH            6                           // log2(LCUSize)
 #define     MAX_CU_SIZE             (1<<(MAX_CU_DEPTH))         // maximum allowable size of CU
 #define     MIN_PU_SIZE             4
@@ -131,5 +131,5 @@
 // ====================================================================================================================
 
-extern const UChar  g_aucIntraModeNumFast[7];
+extern const UChar  g_aucIntraModeNumFast[ MAX_CU_DEPTH ];
 
 #if FAST_INTRA_SHVC
@@ -279,7 +279,14 @@
 extern Int  g_eTTable[4];
 
-#if SIMPLIFIED_MV_POS_SCALING
+#if SVC_EXTENSION
 extern Int g_mvScalingFactor  [MAX_LAYERS][2];
 extern Int g_posScalingFactor [MAX_LAYERS][2];
+
+#if IL_SL_SIGNALLING_N0371
+extern Int ref_scalingListDC         [MAX_LAYERS][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM];
+extern Int ref_scalingListCoef       [MAX_LAYERS][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][MAX_MATRIX_COEF_NUM];
+extern Int activeRefPPSId            [MAX_LAYERS];
+extern Int activeRefSPSId            [MAX_LAYERS];  
+#endif   
 #endif
 
Index: /trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 442)
@@ -1414,5 +1414,9 @@
       UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsZorderIdx] ];
       UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsZorderIdx] ];
+#if REPN_FORMAT_IN_VPS
+      if( ( uiLPelX < pcCU->getSlice()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getPicHeightInLumaSamples() ) )
+#else
       if( ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
         xPCMCURestoration( pcCU, uiAbsZorderIdx, uiDepth+1 );
     }
Index: /trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 442)
@@ -46,6 +46,10 @@
 
 #if SVC_EXTENSION
-  ParameterSetMap<TComVPS> ParameterSetManager::m_vpsMap(MAX_NUM_VPS);
-  Int ParameterSetManager::m_activeVPSId = -1;
+ParameterSetMap<TComVPS> ParameterSetManager::m_vpsMap(MAX_NUM_VPS);
+Int ParameterSetManager::m_activeVPSId = -1;
+#if IL_SL_SIGNALLING_N0371
+TComSPS* TComSPS::m_pcSPS[MAX_LAYERS];
+TComPPS* TComPPS::m_pcPPS[MAX_LAYERS];
+#endif
 #endif
 
@@ -71,4 +75,7 @@
 , m_iDepth                        ( 0 )
 , m_bRefenced                     ( false )
+#if POC_RESET_FLAG
+, m_bPocResetFlag                 ( false )
+#endif
 #if SH_DISCARDABLE_FLAG
 , m_bDiscardableFlag              ( false )
@@ -116,5 +123,4 @@
 #if SVC_EXTENSION
   memset( m_pcBaseColPic, 0, sizeof( m_pcBaseColPic ) );
-#if REF_IDX_FRAMEWORK
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   m_activeNumILRRefIdx        = 0; 
@@ -133,5 +139,4 @@
 #endif
 #endif
-#endif
 
   initEqualRef();
@@ -168,8 +173,4 @@
 #if SVC_EXTENSION
   m_layerId = layerId;
-#endif
-  m_aiNumRefIdx[0]      = 0;
-  m_aiNumRefIdx[1]      = 0;
-#if REF_IDX_FRAMEWORK
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   m_activeNumILRRefIdx        = 0;
@@ -177,5 +178,5 @@
 #else
   m_numILRRefIdx              = 0;
-#endif  
+#endif
 #if M0457_IL_SAMPLE_PRED_ONLY_FLAG
   m_numSamplePredRefLayers       = 0;
@@ -183,4 +184,7 @@
 #endif
 #endif
+  m_aiNumRefIdx[0]      = 0;
+  m_aiNumRefIdx[1]      = 0;
+  
   m_colFromL0Flag = 1;
   
@@ -273,4 +277,7 @@
     pcPic = *(iterPic);
   }
+#if POC_RESET_FLAG
+  assert( pcPic->getSlice(0)->isReferenced() );
+#endif
   return  pcPic;
 }
@@ -286,5 +293,5 @@
   if (!pocHasMsb)
   {
-    poc = poc % pocCycle;
+    poc = poc & (pocCycle - 1);
   }
   
@@ -297,5 +304,5 @@
       if (!pocHasMsb)
       {
-        picPoc = picPoc % pocCycle;
+        picPoc = picPoc & (pocCycle - 1);
       }
       
@@ -384,5 +391,5 @@
   Int i;
 
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   if( m_layerId == 0 || ( m_layerId > 0 && ( m_activeNumILRRefIdx == 0 || !((getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) && (getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)) ) ) )
   {
@@ -439,9 +446,9 @@
     pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i));  
   }
-#if REF_IDX_FRAMEWORK
-  }
-#endif
-
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
+  }
+#endif
+
+#if SVC_EXTENSION
   for( i = 0; i < m_activeNumILRRefIdx; i++ )
   {
@@ -450,6 +457,6 @@
 
 #if ILR_RESTR
-    Int maxSubLayerForILPPlus1 = ( m_layerId > 0 && m_activeNumILRRefIdx > 0)? m_pcVPS->getMaxSublayerForIlpPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId()) : 0;
-    if( m_layerId > 0 && m_activeNumILRRefIdx > 0 && ( ( (Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=  maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )  ) 
+    Int maxTidIlRefPicsPlus1 = ( m_layerId > 0 && m_activeNumILRRefIdx > 0)? m_pcVPS->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId()) : 0;
+    if( m_layerId > 0 && m_activeNumILRRefIdx > 0 && ( ( (Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=  maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )  ) 
 #else //#if ILR_RESTR
     if( m_layerId > 0 && m_activeNumILRRefIdx > 0 )
@@ -477,5 +484,5 @@
   TComPic*  rpsCurrList0[MAX_NUM_REF+1];
   TComPic*  rpsCurrList1[MAX_NUM_REF+1];
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
 #if ILR_RESTR
   Int numInterLayerRPSPics = 0;
@@ -488,6 +495,6 @@
     for( i=0; i < m_pcVPS->getNumDirectRefLayers( m_layerId ); i++ )
     {
-      Int maxSubLayerForILPPlus1 = getVPS()->getMaxSublayerForIlpPlus1(ilpPic[i]->getSlice(0)->getLayerId());
-      if( ((Int)(ilpPic[i]->getSlice(0)->getTLayer())<= maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[i]->getSlice(0)->getRapPicFlag() ) )
+      Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[i]->getSlice(0)->getLayerId());
+      if( ((Int)(ilpPic[i]->getSlice(0)->getTLayer())<= maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[i]->getSlice(0)->getRapPicFlag() ) )
       {
         numInterLayerRPSPics++;
@@ -499,8 +506,17 @@
       m_activeNumILRRefIdx = numInterLayerRPSPics;
     }
-#if MAX_ONE_RESAMPLING_DIRECT_LAYERS && SIMPLIFIED_MV_POS_SCALING
+#if MAX_ONE_RESAMPLING_DIRECT_LAYERS
+#if SCALABILITY_MASK_E0104
+    if( m_pcVPS->getScalabilityMask(2) )
+#else
     if( m_pcVPS->getScalabilityMask(1) )
+#endif
     {
       Int numResampler = 0;
+#if MOTION_RESAMPLING_CONSTRAINT
+      Int numMotionResamplers = 0;
+      Int refResamplingLayer[MAX_LAYERS];
+      memset( refResamplingLayer, 0, sizeof( refResamplingLayer ) );
+#endif
       const Window &scalEL = getSPS()->getScaledRefLayerWindow(m_interLayerPredLayerIdc[i]);
       Int scalingOffset = ((scalEL.getWindowLeftOffset()   == 0 ) && 
@@ -513,12 +529,40 @@
       {
         UInt refLayerIdc = m_interLayerPredLayerIdc[i];
-        if(!( g_posScalingFactor[refLayerIdc][0] == 65536 && g_posScalingFactor[refLayerIdc][1] == 65536 ) && (scalingOffset)) // ratio 1x
+        if(!( g_posScalingFactor[refLayerIdc][0] == 65536 && g_posScalingFactor[refLayerIdc][1] == 65536 ) || (!scalingOffset)) // ratio 1x
         {
+#if MOTION_RESAMPLING_CONSTRAINT
+          UInt predType = m_pcVPS->getDirectDependencyType( m_layerId, m_pcVPS->getRefLayerId( m_layerId, refLayerIdc ) ) + 1;
+
+          if( predType & 0x1 )
+          {
+            numResampler++;
+            refResamplingLayer[i] = refLayerIdc + 1;
+          }
+
+          if( predType & 0x2 )
+          {
+            numMotionResamplers++;
+            refResamplingLayer[i] -= refLayerIdc + 1;
+          }
+#else
           numResampler++;
+#endif
         }
       }
-
-      //Bitstream constraint for SHVC: The picture resampling process as specified in subclause G.8.1.4.1 shall not be invoked more than once for decoding of each particular picture.
+      
+      // When both picture sample values and picture motion field resampling processes are invoked for decoding of a particular picture, they shall be applied to the same reference layer picture.
+      if( m_activeNumILRRefIdx > 1 && numResampler > 0 )
+      {
+        for( i=0; i < m_activeNumILRRefIdx; i++ )
+        {
+          assert( refResamplingLayer[i] >= 0 && "Motion and sample inter-layer prediction shall be from the same layer" );
+        }
+      }
+
+      // Bitstream constraint for SHVC: The picture resampling process as specified in subclause G.8.1.4.1 shall not be invoked more than once for decoding of each particular picture.
       assert(numResampler <= 1);
+#if MOTION_RESAMPLING_CONSTRAINT
+      assert( numMotionResamplers <= 1  && "Up to 1 motion resampling is allowed" );
+#endif
     }
 #endif 
@@ -584,6 +628,6 @@
       rpsCurrList0[cIdx] = RefPicSetStCurr0[i];
     }
+#if SVC_EXTENSION
 #if RPL_INIT_N0316_N0082
-#if REF_IDX_FRAMEWORK
     if( m_layerId > 0 )
     {
@@ -596,6 +640,6 @@
         Int refLayerIdc = m_interLayerPredLayerIdc[i];
 #if ILR_RESTR
-        Int maxSubLayerForILPPlus1 = getVPS()->getMaxSublayerForIlpPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
-        if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
+        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+        if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
 #endif
           rpsCurrList0[cIdx] = ilpPic[refLayerIdc];
@@ -613,5 +657,5 @@
     }    
 #if !RPL_INIT_N0316_N0082
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
     if( m_layerId > 0 )
     {
@@ -624,6 +668,6 @@
         Int refLayerIdc = m_interLayerPredLayerIdc[i];
 #if ILR_RESTR
-         Int maxSubLayerForILPPlus1 = getVPS()->getMaxSublayerForIlpPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
-        if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
+         Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+        if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
 #endif
         rpsCurrList0[cIdx] = ilpPic[refLayerIdc];
@@ -650,5 +694,5 @@
     }    
 
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
     if( m_layerId > 0 )
     {
@@ -661,6 +705,6 @@
         Int refLayerIdc = m_interLayerPredLayerIdc[i];
 #if ILR_RESTR
-        Int maxSubLayerForILPPlus1 = getVPS()->getMaxSublayerForIlpPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
-        if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
+        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+        if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
 #endif
         rpsCurrList1[cIdx] = ilpPic[refLayerIdc];
@@ -680,5 +724,5 @@
     m_apcRefPicList[0][rIdx] = rpsCurrList0[ cIdx ];
 #if RPL_INIT_N0316_N0082
-    m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 && cIdx < NumPocStCurr0 + m_activeNumILRRefIdx );
+    m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 && cIdx < NumPocStCurr0 + m_activeNumILRRefIdx ) || ( cIdx >= NumPocStCurr0 + NumPocStCurr1 + m_activeNumILRRefIdx );
 #else
     m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
@@ -702,5 +746,5 @@
 }
 
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
 Void TComSlice::setRefPicListModificationSvc()
 {
@@ -721,6 +765,11 @@
 #endif
 
+#if N0147_IRAP_ALIGN_FLAG
+  assert(m_aiNumRefIdx[REF_PIC_LIST_0] > 0);
+  assert(m_aiNumRefIdx[REF_PIC_LIST_1] > 0);
+#else
   assert(m_aiNumRefIdx[REF_PIC_LIST_0] > 1);
   assert(m_aiNumRefIdx[REF_PIC_LIST_1] > 1);
+#endif
 
   //set L0 inter-layer reference picture modification
@@ -729,4 +778,7 @@
 #else
   Bool hasModification = (m_aiNumRefIdx[REF_PIC_LIST_0] == numberOfRpsCurrTempList) ? false : true;
+#endif
+#if N0147_IRAP_ALIGN_FLAG
+  hasModification = hasModification && ( m_aiNumRefIdx[REF_PIC_LIST_0] > 1 );
 #endif
 #if FINAL_RPL_CHANGE_N0082
@@ -758,10 +810,14 @@
 #if RPL_INIT_N0316_N0082
         if((numberOfPocBeforeCurr) >= m_aiNumRefIdx[REF_PIC_LIST_0])
+        {
           refPicListModification->setRefPicSetIdxL0(m_aiNumRefIdx[REF_PIC_LIST_0] - i, numberOfPocBeforeCurr);
+        }
         else
         {
           refPicListModification->setRefPicSetIdxL0(m_aiNumRefIdx[REF_PIC_LIST_0] - i, numberOfPocBeforeCurr);
           for (Int j = numberOfPocBeforeCurr; j < (m_aiNumRefIdx[REF_PIC_LIST_0] - i); j++)
+          {
             refPicListModification->setRefPicSetIdxL0(j, j + m_activeNumILRRefIdx);
+          }
         }
 #else
@@ -774,4 +830,8 @@
   //set L1 inter-layer reference picture modification
   hasModification = (m_aiNumRefIdx[REF_PIC_LIST_1] == numberOfRpsCurrTempList) ? false : true;
+#if N0147_IRAP_ALIGN_FLAG
+  hasModification = hasModification && ( m_aiNumRefIdx[REF_PIC_LIST_1] > 1 );
+#endif
+
   refPicListModification->setRefPicListModificationFlagL1(hasModification);
   if(hasModification)
@@ -828,5 +888,5 @@
   Int numRpsCurrTempList = 0;
 
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   if( m_eSliceType == I_SLICE || ( m_pcSPS->getLayerId() && 
     (m_eNalUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
@@ -836,5 +896,5 @@
 #endif 
   {
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
     return m_activeNumILRRefIdx;
@@ -853,5 +913,5 @@
     }
   }
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   if( m_layerId > 0 )
   {
@@ -907,5 +967,5 @@
 }
 
-Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic)
+Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic)
 {
   for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++)
@@ -933,10 +993,10 @@
   {
     pocCRA = getPOC();
-    prevRAPisBLA = false;
+    associatedIRAPType = getNalUnitType();
   }
   else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
   {
     pocCRA = getPOC();
-    prevRAPisBLA = false;
+    associatedIRAPType = getNalUnitType();
   }
   else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
@@ -945,5 +1005,5 @@
   {
     pocCRA = getPOC();
-    prevRAPisBLA = true;
+    associatedIRAPType = getNalUnitType();
   }
 }
@@ -970,4 +1030,5 @@
 {
   TComPic*                 rpcPic;
+  setAssociatedIRAPPOC(pocCRA);
   Int pocCurr = getPOC(); 
 
@@ -1076,6 +1137,4 @@
   m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag;
   memcpy( m_interLayerPredLayerIdc, pSrc->m_interLayerPredLayerIdc, sizeof( m_interLayerPredLayerIdc ) );
-#elif REF_IDX_FRAMEWORK
-  m_numILRRefIdx               = pSrc->m_numILRRefIdx;
 #endif
 #endif
@@ -1138,5 +1197,5 @@
 }
 
-Int TComSlice::m_prevPOC = 0;
+Int TComSlice::m_prevTid0POC = 0;
 
 /** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag.
@@ -1193,4 +1252,164 @@
 }
 
+
+Void TComSlice::checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic)
+{
+  TComPic* rpcPic;
+
+  Int nalUnitType = this->getNalUnitType();
+
+  // When a picture is a leading picture, it shall be a RADL or RASL picture.
+  if(this->getAssociatedIRAPPOC() > this->getPOC())
+  {
+    // Do not check IRAP pictures since they may get a POC lower than their associated IRAP
+    if(nalUnitType < NAL_UNIT_CODED_SLICE_BLA_W_LP ||
+       nalUnitType > NAL_UNIT_RESERVED_IRAP_VCL23)
+    {
+      assert(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
+             nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
+             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
+             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R);
+    }
+  }
+
+  // When a picture is a trailing picture, it shall not be a RADL or RASL picture.
+  if(this->getAssociatedIRAPPOC() < this->getPOC())
+  {
+    assert(nalUnitType != NAL_UNIT_CODED_SLICE_RASL_N &&
+           nalUnitType != NAL_UNIT_CODED_SLICE_RASL_R &&
+           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_N &&
+           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_R);
+  }
+
+  // No RASL pictures shall be present in the bitstream that are associated
+  // with a BLA picture having nal_unit_type equal to BLA_W_RADL or BLA_N_LP.
+  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
+     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
+  {
+    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_W_RADL &&
+           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP);
+  }
+
+  // No RASL pictures shall be present in the bitstream that are associated with
+  // an IDR picture.
+  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
+     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
+  {
+    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP   &&
+           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL);
+  }
+
+  // No RADL pictures shall be present in the bitstream that are associated with
+  // a BLA picture having nal_unit_type equal to BLA_N_LP or that are associated
+  // with an IDR picture having nal_unit_type equal to IDR_N_LP.
+  if(nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
+     nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
+  {
+    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP   &&
+           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP);
+  }
+
+  // loop through all pictures in the reference picture buffer
+  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
+  while ( iterPic != rcListPic.end())
+  {
+    rpcPic = *(iterPic++);
+    if (rpcPic->getPOC() == this->getPOC())
+    {
+      continue;
+    }
+
+    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
+    // in decoding order shall precede the IRAP picture in output order.
+    // (Note that any picture following in output order would be present in the DPB)
+    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
+    {
+      if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP    ||
+         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP    ||
+         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL  ||
+         nalUnitType == NAL_UNIT_CODED_SLICE_CRA         ||
+         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP    ||
+         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
+      {
+        assert(rpcPic->getPOC() < this->getPOC());
+      }
+    }
+
+    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
+    // in decoding order shall precede any RADL picture associated with the IRAP
+    // picture in output order.
+    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
+    {
+      if((nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
+          nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R))
+      {
+        // rpcPic precedes the IRAP in decoding order
+        if(this->getAssociatedIRAPPOC() > rpcPic->getSlice(0)->getAssociatedIRAPPOC())
+        {
+          // rpcPic must not be the IRAP picture
+          if(this->getAssociatedIRAPPOC() != rpcPic->getPOC())
+          {
+            assert(rpcPic->getPOC() < this->getPOC());
+          }
+        }
+      }
+    }
+
+    // When a picture is a leading picture, it shall precede, in decoding order,
+    // all trailing pictures that are associated with the same IRAP picture.
+    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
+       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
+       nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
+       nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
+    {
+      if(rpcPic->getSlice(0)->getAssociatedIRAPPOC() == this->getAssociatedIRAPPOC())
+      {
+        // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB
+        // rpcPic would violate the constraint if it was a trailing picture
+        assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC());
+      }
+    }
+
+    // Any RASL picture associated with a CRA or BLA picture shall precede any
+    // RADL picture associated with the CRA or BLA picture in output order
+    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
+       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
+    { 
+      if((this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
+          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
+          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
+          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)       &&
+          this->getAssociatedIRAPPOC() == rpcPic->getSlice(0)->getAssociatedIRAPPOC())
+      {
+        if(rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N ||
+           rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R)
+        {
+          assert(rpcPic->getPOC() > this->getPOC());
+        }
+      }
+    }
+
+    // Any RASL picture associated with a CRA picture shall follow, in output
+    // order, any IRAP picture that precedes the CRA picture in decoding order.
+    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
+       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
+    {
+      if(this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)
+      {
+        if(rpcPic->getSlice(0)->getPOC() < this->getAssociatedIRAPPOC() &&
+           (rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
+            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
+            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
+            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP   ||
+            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL ||
+            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
+        {
+          assert(this->getPOC() > rpcPic->getSlice(0)->getPOC());
+        }
+      }
+    }
+  }
+}
+
 /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
 */
@@ -1199,4 +1418,6 @@
   TComPic* rpcPic;
   Int i, isReference;
+
+  checkLeadingPictureRestrictions(rcListPic);
 
   // loop through all pictures in the reference picture buffer
@@ -1235,5 +1456,8 @@
       else 
       {
-        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()))
+        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
+        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1);
+        Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1);
+        if(rpcPic->getIsLongTerm() && curPoc == refPoc)
         {
           isReference = 1;
@@ -1295,5 +1519,8 @@
       else 
       {
-        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced())
+        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
+        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1);
+        Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1);
+        if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced())
         {
           isAvailable = 1;
@@ -1314,6 +1541,6 @@
         if (!pReferencePictureSet->getCheckLTMSBPresent(i))
         {
-          curPoc = curPoc % pocCycle;
-          refPoc = refPoc % pocCycle;
+          curPoc = curPoc & (pocCycle - 1);
+          refPoc = refPoc & (pocCycle - 1);
         }
         
@@ -1589,4 +1816,99 @@
 }
 
+#if REPN_FORMAT_IN_VPS
+UInt TComSlice::getPicWidthInLumaSamples()
+{
+  TComSPS *sps = getSPS();
+  TComVPS *vps = getVPS();
+  UInt retVal, layerId = getLayerId();
+  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
+  {
+    retVal = sps->getPicWidthInLumaSamples();
+  }
+  else
+  {
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getPicWidthVpsInLumaSamples();
+  }
+  return retVal;
+}
+UInt TComSlice::getPicHeightInLumaSamples()
+{
+  TComSPS *sps = getSPS();
+  TComVPS *vps = getVPS();
+  UInt retVal, layerId = getLayerId();
+  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
+  {
+    retVal = sps->getPicHeightInLumaSamples();
+  }
+  else
+  {
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getPicHeightVpsInLumaSamples();
+  }
+  return retVal;
+}
+UInt TComSlice::getChromaFormatIdc()
+{
+  TComSPS *sps = getSPS();
+  TComVPS *vps = getVPS();
+  UInt retVal, layerId = getLayerId();
+  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
+  {
+    retVal = sps->getChromaFormatIdc();
+  }
+  else
+  {
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getChromaFormatVpsIdc();
+  }
+  return retVal;
+}
+UInt TComSlice::getBitDepthY()
+{
+  TComSPS *sps = getSPS();
+  TComVPS *vps = getVPS();
+  UInt retVal, layerId = getLayerId();
+  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
+  {
+    retVal = sps->getBitDepthY();
+  }
+  else
+  {
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsLuma();
+  }
+  return retVal;
+}
+UInt TComSlice::getBitDepthC()
+{
+  TComSPS *sps = getSPS();
+  TComVPS *vps = getVPS();
+  UInt retVal, layerId = getLayerId();
+  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
+  {
+    retVal = sps->getBitDepthC();
+  }
+  else
+  {
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsChroma();
+  }
+  return retVal;
+}
+Int TComSlice::getQpBDOffsetY()
+{
+  return (getBitDepthY() - 8) * 6;
+}
+Int TComSlice::getQpBDOffsetC()
+{
+  return (getBitDepthC() - 8) * 6;
+}
+
+RepFormat::RepFormat()
+: m_chromaFormatVpsIdc          (0)
+, m_separateColourPlaneVpsFlag  (false)
+, m_picWidthVpsInLumaSamples    (0)
+, m_picHeightVpsInLumaSamples   (0)
+, m_bitDepthVpsLuma             (0)
+, m_bitDepthVpsChroma           (0)
+{}
+#endif
+
 // ------------------------------------------------------------------------------------------------
 // Video parameter set (VPS)
@@ -1617,4 +1939,15 @@
 , m_defaultOneTargetOutputLayerFlag    (false)
 #endif
+#if VPS_VUI_BITRATE_PICRATE
+, m_bitRatePresentVpsFlag     (false)
+, m_picRatePresentVpsFlag     (false)
+#endif
+#if REPN_FORMAT_IN_VPS
+, m_repFormatIdxPresentFlag   (true)
+, m_vpsNumRepFormats          (1)
+#endif
+#if VIEW_ID_RELATED_SIGNALING 
+, m_viewIdLenMinus1           (0)
+#endif
 {
   for( Int i = 0; i < MAX_TLAYER; i++)
@@ -1665,12 +1998,38 @@
   m_maxOneActiveRefLayerFlag = true;
 #endif
+#if N0147_IRAP_ALIGN_FLAG
+  m_crossLayerIrapAlignFlag = true;
+#endif 
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
 #if N0120_MAX_TID_REF_PRESENT_FLAG
-  m_maxTidIlRefPicsPlus1PresentFlag = true;
+  m_maxTidRefPresentFlag = true;
 #endif 
   for( Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++)
   {
-    m_maxSublayerForIlpPlus1[i] = m_uiMaxTLayers + 1;
-  }
+    m_maxTidIlRefPicsPlus1[i] = m_uiMaxTLayers + 1;
+  }
+#endif
+#if TILE_BOUNDARY_ALIGNED_FLAG
+   ::memset(m_tileBoundariesAlignedFlag,  0, sizeof(m_tileBoundariesAlignedFlag));
+#endif 
+#if N0160_VUI_EXT_ILP_REF
+   m_numIlpRestrictedRefLayers = false;
+   ::memset(m_minSpatialSegmentOffsetPlus1,  0, sizeof(m_minSpatialSegmentOffsetPlus1));
+   ::memset(m_ctuBasedOffsetEnabledFlag,     0, sizeof(m_ctuBasedOffsetEnabledFlag));
+   ::memset(m_minHorizontalCtuOffsetPlus1,   0, sizeof(m_minHorizontalCtuOffsetPlus1));
+#endif
+#if VPS_VUI_BITRATE_PICRATE  
+  ::memset(m_bitRatePresentFlag, 0, sizeof(m_bitRatePresentFlag));
+  ::memset(m_picRatePresentFlag, 0, sizeof(m_picRatePresentFlag));
+  ::memset(m_avgBitRate        , 0, sizeof(m_avgBitRate)        );
+  ::memset(m_maxBitRate        , 0, sizeof(m_maxBitRate)        );
+  ::memset(m_constPicRateIdc   , 0, sizeof(m_constPicRateIdc)   );
+  ::memset(m_avgPicRate        , 0, sizeof(m_avgPicRate)        );
+#endif
+#if REPN_FORMAT_IN_VPS
+  ::memset( m_vpsRepFormatIdx, 0, sizeof(m_vpsRepFormatIdx) );
+#endif
+#if VIEW_ID_RELATED_SIGNALING 
+  ::memset(m_viewIdVal, 0, sizeof(m_viewIdVal));
 #endif
 }
@@ -1704,4 +2063,59 @@
     setNumLayersInIdList(i, n);
   }
+}
+#endif
+
+#if IL_SL_SIGNALLING_N0371
+Bool TComVPS::checkLayerDependency(UInt i, UInt j)
+{
+  if( this->getDirectDependencyFlag(i, j) == true )
+  {                                                                                                                                    
+    return true;                                                                                                                       
+  }                                                                                                                                    
+  else                                                                                                                                   
+  {                                                                                                                                    
+    for(UInt k=i-1; k>j; k--)
+    {                                                                                                                                
+      if( this->getDirectDependencyFlag(i, k) == true )
+      {                                                                                                                            
+        checkLayerDependency( k,j );                                                                                           
+      }
+    }
+  }
+  return false;        
+}
+#endif
+
+#if VIEW_ID_RELATED_SIGNALING 
+Int TComVPS::getNumViews()
+{
+  Int numViews = 1; 
+  for( Int i = 0; i <= getMaxLayers() - 1; i++ )
+  {
+    Int lId = getLayerIdInNuh( i ); 
+    if ( i > 0 && ( getViewIndex( lId ) != getScalabilityId( i - 1, VIEW_ORDER_INDEX ) ) )
+    {
+      numViews++; 
+    }    
+  }
+
+  return numViews;
+}
+Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType )
+{
+  return getScalabilityMask( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0;
+}  
+Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType )
+{
+  assert( scalType >= 0 && scalType <= MAX_VPS_NUM_SCALABILITY_TYPES ); 
+  assert( scalType == MAX_VPS_NUM_SCALABILITY_TYPES || getScalabilityMask( scalType ) );
+  Int scalIdx = 0; 
+  for( Int curScalType = 0; curScalType < scalType; curScalType++ )
+  {
+    scalIdx += ( getScalabilityMask( curScalType ) ? 1 : 0 );
+
+  }
+
+  return scalIdx; 
 }
 #endif
@@ -1759,4 +2173,7 @@
 , m_numScaledRefLayerOffsets  (0)
 #endif
+#if REPN_FORMAT_IN_VPS
+, m_updateRepFormatFlag       (false)
+#endif
 {
   for ( Int i = 0; i < MAX_TLAYER; i++ )
@@ -1802,94 +2219,105 @@
 
   TimingInfo *timingInfo = vui->getTimingInfo();
-  timingInfo->setTimingInfoPresentFlag( true );
-  switch( frameRate )
-  {
-  case 24:
-    timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
-    break;
-  case 25:
-    timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
-    break;
-  case 30:
-    timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
-    break;
-  case 50:
-    timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
-    break;
-  case 60:
-    timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
-    break;
-  default:
-    timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
-    break;
-  }
-
-  Bool rateCnt = ( bitRate > 0 );
-  hrd->setNalHrdParametersPresentFlag( rateCnt );
-  hrd->setVclHrdParametersPresentFlag( rateCnt );
-
-  hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
-
-  if( hrd->getSubPicCpbParamsPresentFlag() )
-  {
-    hrd->setTickDivisorMinus2( 100 - 2 );                          // 
-    hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
-    hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
-    hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
+#if TIMING_INFO_NONZERO_LAYERID_SPS
+  if( getLayerId() > 0 )
+  {
+    timingInfo->setTimingInfoPresentFlag( false );
   }
   else
   {
-    hrd->setSubPicCpbParamsInPicTimingSEIFlag( false );  
-  }
-
-  hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
-  hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
-  hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
+#endif
+    timingInfo->setTimingInfoPresentFlag( true );
+    switch( frameRate )
+    {
+    case 24:
+      timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
+      break;
+    case 25:
+      timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
+      break;
+    case 30:
+      timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
+      break;
+    case 50:
+      timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
+      break;
+    case 60:
+      timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
+      break;
+    default:
+      timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
+      break;
+    }
+
+    Bool rateCnt = ( bitRate > 0 );
+    hrd->setNalHrdParametersPresentFlag( rateCnt );
+    hrd->setVclHrdParametersPresentFlag( rateCnt );
+
+    hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
+
+    if( hrd->getSubPicCpbParamsPresentFlag() )
+    {
+      hrd->setTickDivisorMinus2( 100 - 2 );                          // 
+      hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
+      hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
+      hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
+    }
+    else
+    {
+      hrd->setSubPicCpbParamsInPicTimingSEIFlag( false );  
+    }
+
+    hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
+    hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
+    hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
   
-  hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
-  if( randomAccess )
-  {
-    hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
-    hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
-  }
-  else
-  {
-    hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
-    hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
-  }
+    hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
+    if( randomAccess )
+    {
+      hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
+      hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
+    }
+    else
+    {
+      hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
+      hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
+    }
 
 /*
-   Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
+     Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
 */
-  Int i, j;
-  UInt birateValue, cpbSizeValue;
-  UInt ducpbSizeValue;
-  UInt duBitRateValue = 0;
-
-  for( i = 0; i < MAX_TLAYER; i ++ )
-  {
-    hrd->setFixedPicRateFlag( i, 1 );
-    hrd->setPicDurationInTcMinus1( i, 0 );
-    hrd->setLowDelayHrdFlag( i, 0 );
-    hrd->setCpbCntMinus1( i, 0 );
-
-    birateValue  = bitRate;
-    cpbSizeValue = bitRate;                                     // 1 second
-    ducpbSizeValue = bitRate/numDU;
-    duBitRateValue = bitRate;
-    for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
-    {
-      hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
-      hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
-      hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
-      hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
-
-      hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
-      hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
-      hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
-      hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
-      hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
-    }
-  }
+    Int i, j;
+    UInt birateValue, cpbSizeValue;
+    UInt ducpbSizeValue;
+    UInt duBitRateValue = 0;
+
+    for( i = 0; i < MAX_TLAYER; i ++ )
+    {
+      hrd->setFixedPicRateFlag( i, 1 );
+      hrd->setPicDurationInTcMinus1( i, 0 );
+      hrd->setLowDelayHrdFlag( i, 0 );
+      hrd->setCpbCntMinus1( i, 0 );
+
+      birateValue  = bitRate;
+      cpbSizeValue = bitRate;                                     // 1 second
+      ducpbSizeValue = bitRate/numDU;
+      duBitRateValue = bitRate;
+      for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
+      {
+        hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
+        hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
+        hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
+        hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
+
+        hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
+        hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
+        hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
+        hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
+        hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
+      }
+    }
+#if TIMING_INFO_NONZERO_LAYERID_SPS
+  }
+#endif
 }
 const Int TComSPS::m_winUnitX[]={1,2,2,1};
@@ -2152,7 +2580,7 @@
 TComScalingList::TComScalingList()
 {
-  m_useTransformSkip = false;
   init();
 }
+
 TComScalingList::~TComScalingList()
 {
@@ -2162,5 +2590,9 @@
 /** set default quantization matrix to array
 */
+#if IL_SL_SIGNALLING_N0371
+Void TComSlice::setDefaultScalingList( UInt layerId )
+#else
 Void TComSlice::setDefaultScalingList()
+#endif
 {
   for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
@@ -2168,5 +2600,9 @@
     for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
     {
+#if IL_SL_SIGNALLING_N0371
+      getScalingList()->processDefaultMarix(sizeId, listId, layerId);
+#else
       getScalingList()->processDefaultMarix(sizeId, listId);
+#endif
     }
   }
@@ -2343,13 +2779,38 @@
  * \param Index of input matrix
  */
+#if IL_SL_SIGNALLING_N0371
+Void TComScalingList::processDefaultMarix(UInt sizeId, UInt listId, UInt layerId)
+#else
 Void TComScalingList::processDefaultMarix(UInt sizeId, UInt listId)
-{
+#endif
+{
+#if IL_SL_SIGNALLING_N0371
+  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
+  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32; 
+  Int *src = getScalingListDefaultAddress(sizeId, listId);   
+#endif
+
   ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
+
+#if IL_SL_SIGNALLING_N0371
+  for(i = 0; i < coefNum; i++) 
+  {
+    ref_scalingListCoef[layerId][sizeId][listId][i] = src[scan[i]];
+  }
+#endif
+
   setScalingListDC(sizeId,listId,SCALING_LIST_DC);
+#if IL_SL_SIGNALLING_N0371
+  ref_scalingListDC[layerId][sizeId][listId] = SCALING_LIST_DC;
+#endif
 }
 
 /** check DC value of matrix for default matrix signaling
  */
+#if IL_SL_SIGNALLING_N0371
+Void TComScalingList::checkDcOfMatrix( UInt layerId )
+#else
 Void TComScalingList::checkDcOfMatrix()
+#endif
 {
   for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
@@ -2360,5 +2821,9 @@
       if(getScalingListDC(sizeId,listId) == 0)
       {
+#if IL_SL_SIGNALLING_N0371
+        processDefaultMarix(sizeId, listId, layerId);
+#else
         processDefaultMarix(sizeId, listId);
+#endif
       }
     }
@@ -2441,4 +2906,10 @@
         m_activeVPSId = vpsId;
         m_activeSPSId = spsId;
+
+#if IL_SL_SIGNALLING_N0371
+        activeRefPPSId[ sps->getLayerId() ] = ppsId;
+        activeRefSPSId[ sps->getLayerId() ] = spsId;
+#endif
+
         return true;
       }
@@ -2554,5 +3025,16 @@
     return;
   }        
+#if POC_RESET_FLAG
+  if( this->getPocResetFlag() )
+  {
+    setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, 0)); 
+  }
+  else
+  {
+    setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC())); 
+  }
+#else
   setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC())); 
+#endif
 }
 #endif 
@@ -2568,5 +3050,5 @@
     //set reference picture POC of each ILP reference 
     Int thePoc = ilpPic[refLayerIdc]->getPOC(); 
-    assert(thePoc >= 0); 
+    assert(thePoc >= 0);
     assert(thePoc == pcRefPicBL->getPOC());
 
Index: /trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComSlice.h	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComSlice.h	(revision 442)
@@ -156,6 +156,14 @@
   Void     setScalingListPresentFlag    (Bool b)                               { m_scalingListPresentFlag = b;    }
   Bool     getScalingListPresentFlag    ()                                     { return m_scalingListPresentFlag; }
-  Bool     getUseTransformSkip    ()                                     { return m_useTransformSkip; }      
-  Void     setUseTransformSkip    (Bool b)                               { m_useTransformSkip = b;    }
+
+#if IL_SL_SIGNALLING_N0371
+  UInt     m_layerId;
+
+  Void     setPredScalingListFlag    (Bool b)                               { m_predScalingListFlag = b;    }
+  Bool     getPredScalingListFlag    ()                                     { return m_predScalingListFlag; }
+  Void     setScalingListRefLayerId  (UInt b)                               { m_scalingListRefLayerId = b;  }
+  UInt     getScalingListRefLayerId  ()                                     { return m_scalingListRefLayerId; }
+#endif
+
   Int*     getScalingListAddress          (UInt sizeId, UInt listId)           { return m_scalingListCoef[sizeId][listId]; } //!< get matrix coefficient
   Bool     checkPredMode                  (UInt sizeId, UInt listId);
@@ -163,9 +171,23 @@
   UInt     getRefMatrixId                 (UInt sizeId, UInt listId)           { return m_refMatrixId[sizeId][listId]; }     //!< get reference matrix ID
   Int*     getScalingListDefaultAddress   (UInt sizeId, UInt listId);                                                        //!< get default matrix coefficient
+
+#if IL_SL_SIGNALLING_N0371
+  Void     processDefaultMarix            (UInt sizeId, UInt listId, UInt layerId );
+#else
   Void     processDefaultMarix            (UInt sizeId, UInt listId);
+#endif
+
   Void     setScalingListDC               (UInt sizeId, UInt listId, UInt u)   { m_scalingListDC[sizeId][listId] = u; }      //!< set DC value
 
   Int      getScalingListDC               (UInt sizeId, UInt listId)           { return m_scalingListDC[sizeId][listId]; }   //!< get DC value
+
+#if IL_SL_SIGNALLING_N0371
+  Void     setLayerId(UInt layerId) { m_layerId = layerId; }
+  UInt     getLayerId() { return m_layerId; }
+  Void     checkDcOfMatrix                ( UInt m_layerId );
+#else
   Void     checkDcOfMatrix                ();
+#endif
+
   Void     processRefMatrix               (UInt sizeId, UInt listId , UInt refListId );
   Bool     xParseScalingList              (Char* pchFile);
@@ -178,7 +200,12 @@
   UInt     m_refMatrixId                 [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< RefMatrixID
   Bool     m_scalingListPresentFlag;                                                //!< flag for using default matrix
+
+#if IL_SL_SIGNALLING_N0371
+  Bool     m_predScalingListFlag;                                                   //!< flag for inter-layer scaling-list prediction
+  UInt     m_scalingListRefLayerId;                                                 //!< scaling_list_ref_layer_id  
+#endif
+
   UInt     m_predMatrixId                [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< reference list index
-  Int      *m_scalingListCoef            [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< quantization matrix
-  Bool     m_useTransformSkip;                                                      //!< transform skipping flag for setting default scaling matrix for 4x4
+  Int      *m_scalingListCoef            [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< quantization matrix                                            
 };
 
@@ -406,4 +433,36 @@
 };
 
+#if REPN_FORMAT_IN_VPS
+class RepFormat
+{
+  Int  m_chromaFormatVpsIdc;
+  Bool m_separateColourPlaneVpsFlag;
+  Int  m_picWidthVpsInLumaSamples;
+  Int  m_picHeightVpsInLumaSamples;
+  Int  m_bitDepthVpsLuma;               // coded as minus8
+  Int  m_bitDepthVpsChroma;             // coded as minus8
+
+public:
+  RepFormat();
+
+  Int  getChromaFormatVpsIdc()        { return m_chromaFormatVpsIdc; }
+  Void setChromaFormatVpsIdc(Int x)   { m_chromaFormatVpsIdc = x;    }
+
+  Bool getSeparateColourPlaneVpsFlag()        { return m_separateColourPlaneVpsFlag; }
+  Void setSeparateColourPlaneVpsFlag(Bool x)  { m_separateColourPlaneVpsFlag = x;    }
+
+  Int  getPicWidthVpsInLumaSamples()        { return m_picWidthVpsInLumaSamples; }
+  Void setPicWidthVpsInLumaSamples(Int x)   { m_picWidthVpsInLumaSamples = x;    }
+
+  Int  getPicHeightVpsInLumaSamples()        { return m_picHeightVpsInLumaSamples; }
+  Void setPicHeightVpsInLumaSamples(Int x)   { m_picHeightVpsInLumaSamples = x;    }
+
+  Int  getBitDepthVpsLuma()           { return m_bitDepthVpsLuma;   }
+  Void setBitDepthVpsLuma(Int x)      { m_bitDepthVpsLuma = x;      }
+
+  Int  getBitDepthVpsChroma()           { return m_bitDepthVpsChroma;   }
+  Void setBitDepthVpsChroma(Int x)      { m_bitDepthVpsChroma = x;      }
+};
+#endif
 class TComVPS
 {
@@ -436,4 +495,10 @@
   Int         m_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
   Int         m_numLayerInIdList[MAX_VPS_LAYER_SETS_PLUS1];
+#endif
+#if IL_SL_SIGNALLING_N0371
+  Bool        m_scalingListLayerDependency[MAX_LAYERS][MAX_LAYERS];  // layer dependency for scaling list
+#endif
+#if VPS_EXTN_OFFSET
+  UInt        m_extensionOffset;
 #endif
   TComPTL     m_pcPTL;
@@ -491,12 +556,44 @@
   Bool       m_maxOneActiveRefLayerFlag;
 #endif
+#if N0147_IRAP_ALIGN_FLAG
+  Bool       m_crossLayerIrapAlignFlag;
+#endif
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
-  UInt       m_maxSublayerForIlpPlus1[MAX_VPS_LAYER_ID_PLUS1 - 1];
+  UInt       m_maxTidIlRefPicsPlus1[MAX_VPS_LAYER_ID_PLUS1 - 1];
 #endif
 #if N0120_MAX_TID_REF_PRESENT_FLAG
-  Bool       m_maxTidIlRefPicsPlus1PresentFlag;
+  Bool       m_maxTidRefPresentFlag;
 #endif 
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   Bool       m_singleLayerForNonIrapFlag;
+#endif
+#if TILE_BOUNDARY_ALIGNED_FLAG
+  Bool       m_tileBoundariesAlignedFlag[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+#endif 
+#if N0160_VUI_EXT_ILP_REF    
+  Bool        m_numIlpRestrictedRefLayers;
+  Int         m_minSpatialSegmentOffsetPlus1[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  Bool        m_ctuBasedOffsetEnabledFlag   [MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  Int         m_minHorizontalCtuOffsetPlus1 [MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+#endif 
+#if VPS_VUI_BITRATE_PICRATE
+  Bool        m_bitRatePresentVpsFlag;
+  Bool        m_picRatePresentVpsFlag;
+  Bool        m_bitRatePresentFlag  [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Bool        m_picRatePresentFlag  [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Int         m_avgBitRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Int         m_maxBitRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Int         m_constPicRateIdc     [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Int         m_avgPicRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+#endif
+#if REPN_FORMAT_IN_VPS
+  Bool       m_repFormatIdxPresentFlag;
+  Int        m_vpsNumRepFormats;            // coded as minus1
+  RepFormat  m_vpsRepFormat[16];
+  Int        m_vpsRepFormatIdx[16];
+#endif
+#if VIEW_ID_RELATED_SIGNALING 
+  Int         m_viewIdLenMinus1;
+  Int         m_viewIdVal                [MAX_LAYERS];
 #endif
 public:
@@ -565,4 +662,11 @@
   Void    deriveLayerIdListVariables();
 #endif
+
+#if IL_SL_SIGNALLING_N0371
+  Bool    checkLayerDependency(UInt i, UInt j);
+  Bool    getScalingListLayerDependency  ( UInt layerId, UInt refLayerId )            { return m_scalingListLayerDependency[layerId][refLayerId]; }
+  Void    setScalingListLayerDependency  ( UInt layerId, UInt refLayerId, Bool val  ) { m_scalingListLayerDependency[layerId][refLayerId] = val;  }
+#endif
+
   TComPTL* getPTL() { return &m_pcPTL; }
   TimingInfo* getTimingInfo() { return &m_timingInfo; }
@@ -659,15 +763,87 @@
   Void   setMaxOneActiveRefLayerFlag(Bool x)                                    { m_maxOneActiveRefLayerFlag = x;                         }
 #endif 
+#if N0147_IRAP_ALIGN_FLAG
+  Bool   getCrossLayerIrapAlignFlag()                                           { return m_crossLayerIrapAlignFlag;                      }
+  Void   setCrossLayerIrapAlignFlag(Bool x)                                     { m_crossLayerIrapAlignFlag = x;                         }
+#endif 
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
-  Bool   getMaxSublayerForIlpPlus1(Int layerId)                     { return m_maxSublayerForIlpPlus1[layerId];                   }
-  Void   setMaxSublayerForIlpPlus1(Int layerId, UInt maxSublayer)   { m_maxSublayerForIlpPlus1[layerId] = maxSublayer;            }
+  UInt   getMaxTidIlRefPicsPlus1(Int layerId)                     { return m_maxTidIlRefPicsPlus1[layerId];                   }
+  Void   setMaxTidIlRefPicsPlus1(Int layerId, UInt maxSublayer)   { m_maxTidIlRefPicsPlus1[layerId] = maxSublayer;            }
 #endif
 #if N0120_MAX_TID_REF_PRESENT_FLAG
-  Bool   getMaxTidIlRefPicsPlus1PresentFlag()                   { return m_maxTidIlRefPicsPlus1PresentFlag ;}
-  Void   setMaxTidIlRefPicsPlus1PresentFlag(Bool x)             { m_maxTidIlRefPicsPlus1PresentFlag = x;}
+  Bool   getMaxTidRefPresentFlag()                                  { return m_maxTidRefPresentFlag ;}
+  Void   setMaxTidRefPresentFlag(Bool x)                            { m_maxTidRefPresentFlag = x;}
 #endif 
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   Bool   getSingleLayerForNonIrapFlag()                             { return m_singleLayerForNonIrapFlag; }
   Void   setSingleLayerForNonIrapFlag(Bool x)                       { m_singleLayerForNonIrapFlag = x;    }
+#endif
+#if TILE_BOUNDARY_ALIGNED_FLAG  
+  Bool   getTileBoundariesAlignedFlag(Int currLayerId, Int refLayerId)           { return m_tileBoundariesAlignedFlag[currLayerId][refLayerId]; }
+  Void   setTileBoundariesAlignedFlag(Int currLayerId, Int refLayerId, Bool x)   { m_tileBoundariesAlignedFlag[currLayerId][refLayerId] = x; } 
+#endif 
+#if N0160_VUI_EXT_ILP_REF  
+  Bool  getNumIlpRestrictedRefLayers   ( )                                         { return m_numIlpRestrictedRefLayers        ;}
+  Void  setNumIlpRestrictedRefLayers   ( Int val )                                 { m_numIlpRestrictedRefLayers         = val;}
+  
+  Int  getMinSpatialSegmentOffsetPlus1( Int currLayerId, Int refLayerId )          { return m_minSpatialSegmentOffsetPlus1[currLayerId][refLayerId];}
+  Void setMinSpatialSegmentOffsetPlus1( Int currLayerId, Int refLayerId, Int val ) { m_minSpatialSegmentOffsetPlus1[currLayerId][refLayerId] = val;}
+  
+  Bool getCtuBasedOffsetEnabledFlag   ( Int currLayerId, Int refLayerId )            { return m_ctuBasedOffsetEnabledFlag[currLayerId][refLayerId];}
+  Void setCtuBasedOffsetEnabledFlag   ( Int currLayerId, Int refLayerId, Bool flag ) { m_ctuBasedOffsetEnabledFlag[currLayerId][refLayerId] = flag;}
+  
+  Int  getMinHorizontalCtuOffsetPlus1 ( Int currLayerId, Int refLayerId )            { return m_minHorizontalCtuOffsetPlus1[currLayerId][refLayerId];}
+  Void setMinHorizontalCtuOffsetPlus1 ( Int currLayerId, Int refLayerId, Int val )   { m_minHorizontalCtuOffsetPlus1[currLayerId][refLayerId] = val;}  
+#endif
+#if VPS_VUI_BITRATE_PICRATE
+  Bool getBitRatePresentVpsFlag()       { return m_bitRatePresentVpsFlag; }
+  Void setBitRatePresentVpsFlag(Bool x) { m_bitRatePresentVpsFlag = x;    }
+  Bool getPicRatePresentVpsFlag()       { return m_picRatePresentVpsFlag; }
+  Void setPicRatePresentVpsFlag(Bool x) { m_picRatePresentVpsFlag = x;    }
+
+  Bool getBitRatePresentFlag(Int i, Int j)          { return m_bitRatePresentFlag[i][j]; }
+  Void setBitRatePresentFlag(Int i, Int j, Bool x)  { m_bitRatePresentFlag[i][j] = x;    }
+  Bool getPicRatePresentFlag(Int i, Int j)          { return m_picRatePresentFlag[i][j]; }
+  Void setPicRatePresentFlag(Int i, Int j, Bool x)  { m_picRatePresentFlag[i][j] = x;    }
+  
+  Int  getAvgBitRate(Int i, Int j)          { return m_avgBitRate[i][j]; }
+  Void setAvgBitRate(Int i, Int j, Int x)   { m_avgBitRate[i][j] = x;    }
+  Int  getMaxBitRate(Int i, Int j)          { return m_maxBitRate[i][j]; }
+  Void setMaxBitRate(Int i, Int j, Int x)   { m_maxBitRate[i][j] = x;    }
+  
+  Int  getConstPicRateIdc(Int i, Int j)          { return m_constPicRateIdc[i][j]; }
+  Void setConstPicRateIdc(Int i, Int j, Int x)   { m_constPicRateIdc[i][j] = x;    }
+  Int  getAvgPicRate(Int i, Int j)          { return m_avgPicRate[i][j]; }
+  Void setAvgPicRate(Int i, Int j, Int x)   { m_avgPicRate[i][j] = x;    }
+#endif
+
+#if REPN_FORMAT_IN_VPS
+  Bool   getRepFormatIdxPresentFlag()       { return m_repFormatIdxPresentFlag; }
+  Void   setRepFormatIdxPresentFlag(Bool x) { m_repFormatIdxPresentFlag = x;    }
+
+  Int    getVpsNumRepFormats()              { return m_vpsNumRepFormats;        }
+  Void   setVpsNumRepFormats(Int x)         { m_vpsNumRepFormats = x;           }
+
+  RepFormat* getVpsRepFormat(Int idx)       { return &m_vpsRepFormat[idx];      }
+
+  Int    getVpsRepFormatIdx(Int idx)        { return m_vpsRepFormatIdx[idx];   }
+  Void   setVpsRepFormatIdx(Int idx, Int x) { m_vpsRepFormatIdx[idx] = x;      }         
+#endif
+#if VIEW_ID_RELATED_SIGNALING
+  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]; } 
+  Int     getScalabilityId(Int, ScalabilityType scalType );
+
+  Int     getViewIndex    ( Int layerIdInNuh )                             { return getScalabilityId( getLayerIdInVps(layerIdInNuh), VIEW_ORDER_INDEX  ); }    
+
+  Int     getNumViews();
+  Int     scalTypeToScalIdx( ScalabilityType scalType );
+#endif
+#if VPS_EXTN_OFFSET
+  Int     getExtensionOffset()                 { return m_extensionOffset;   }
+  Void    setExtensionOffset( UInt offset )    { m_extensionOffset = offset; }
 #endif
 };
@@ -951,5 +1127,7 @@
   Bool        m_scalingListEnabledFlag;
   Bool        m_scalingListPresentFlag;
+
   TComScalingList*     m_scalingList;   //!< ScalingList class pointer
+
   UInt        m_uiMaxDecPicBuffering[MAX_TLAYER]; 
   UInt        m_uiMaxLatencyIncrease[MAX_TLAYER];  // Really max latency increase plus 1 (value 0 expresses no limit)
@@ -975,4 +1153,12 @@
 #if SVC_EXTENSION
   UInt m_layerId;
+
+#if IL_SL_SIGNALLING_N0371
+  TComVPS*    m_pVPS;
+  static TComSPS* m_pcSPS[MAX_LAYERS];
+  Bool        m_predScalingListFlag;
+  UInt        m_scalingListRefLayerId;
+#endif
+
 #endif
 #if REF_IDX_MFM
@@ -984,4 +1170,7 @@
   UInt        m_numScaledRefLayerOffsets;
   Window      m_scaledRefLayerWindow[MAX_LAYERS];
+#endif
+#if REPN_FORMAT_IN_VPS
+  Bool m_updateRepFormatFlag;
 #endif
 public:
@@ -1094,6 +1283,20 @@
   Bool getScalingListPresentFlag()         { return m_scalingListPresentFlag;     }
   Void setScalingListPresentFlag( Bool b ) { m_scalingListPresentFlag  = b;       }
+
+#if IL_SL_SIGNALLING_N0371
+  Bool getPredScalingListFlag()         { return m_predScalingListFlag;     }
+  Void setPredScalingListFlag( Bool b ) { m_predScalingListFlag  = b;       }
+  UInt getScalingListRefLayerId()         { return m_scalingListRefLayerId;   }
+  Void setScalingListRefLayerId( UInt b ) { m_scalingListRefLayerId  = b;       }
+
+  TComVPS*  getVPS()                      { return  m_pVPS; }
+  Void      setVPS( TComVPS* vps )        { m_pVPS = vps;   }
+  static   TComSPS* getSPS(UInt layerId)               { return m_pcSPS[layerId]; }
+  static   Void     setSPS(UInt layerId, TComSPS* sps) { m_pcSPS[layerId] = sps;  }
+#endif
+
   Void setScalingList      ( TComScalingList *scalingList);
   TComScalingList* getScalingList ()       { return m_scalingList; }               //!< get ScalingList class pointer in SPS
+
   UInt getMaxDecPicBuffering  (UInt tlayer)            { return m_uiMaxDecPicBuffering[tlayer]; }
   Void setMaxDecPicBuffering  ( UInt ui, UInt tlayer ) { m_uiMaxDecPicBuffering[tlayer] = ui;   }
@@ -1142,4 +1345,8 @@
   Void     setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x; }
   Window&  getScaledRefLayerWindow( Int x )   { return m_scaledRefLayerWindow[x]; }
+#endif
+#if REPN_FORMAT_IN_VPS
+  Bool     getUpdateRepFormatFlag()       { return m_updateRepFormatFlag; }
+  Void     setUpdateRepFormatFlag(Bool x) { m_updateRepFormatFlag = x;    }
 #endif
 };
@@ -1225,5 +1432,18 @@
   Int      m_deblockingFilterTcOffsetDiv2;      //< tc offset for deblocking filter
   Bool     m_scalingListPresentFlag;
+
+#if SVC_EXTENSION
+  UInt m_layerId;
+
+#if IL_SL_SIGNALLING_N0371
+  static TComPPS* m_pcPPS[MAX_LAYERS];
+  Bool     m_predScalingListFlag;
+  UInt     m_scalingListRefLayerId;
+#endif
+
+#endif
+
   TComScalingList*     m_scalingList;   //!< ScalingList class pointer
+
   Bool m_listsModificationPresentFlag;
   UInt m_log2ParallelMergeLevelMinus2;
@@ -1339,4 +1559,18 @@
   Bool     getScalingListPresentFlag()         { return m_scalingListPresentFlag;     }
   Void     setScalingListPresentFlag( Bool b ) { m_scalingListPresentFlag  = b;       }
+
+#if IL_SL_SIGNALLING_N0371
+  Void     setLayerId(UInt layerId) { m_layerId = layerId; }
+  UInt     getLayerId() { return m_layerId; }
+
+  Bool     getPredScalingListFlag()         { return m_predScalingListFlag;     }
+  Void     setPredScalingListFlag( Bool b ) { m_predScalingListFlag  = b;       }
+  UInt     getScalingListRefLayerId()         { return m_scalingListRefLayerId;     }
+  Void     setScalingListRefLayerId( UInt b ) { m_scalingListRefLayerId  = b;       }
+
+  static   TComPPS* getPPS(UInt layerId)               { return m_pcPPS[layerId]; }
+  static   Void     setPPS(UInt layerId, TComPPS* pps) { m_pcPPS[layerId] = pps;  }
+#endif
+
   Void     setScalingList      ( TComScalingList *scalingList);
   TComScalingList* getScalingList ()          { return m_scalingList; }         //!< get ScalingList class pointer in PPS
@@ -1384,5 +1618,7 @@
   Int         m_iPOC;
   Int         m_iLastIDR;
-  static Int  m_prevPOC;
+  Int         m_iAssociatedIRAP;
+  NalUnitType m_iAssociatedIRAPType;
+  static Int  m_prevTid0POC;
   TComReferencePictureSet *m_pcRPS;
   TComReferencePictureSet m_LocalRPS;
@@ -1404,5 +1640,5 @@
   Int         m_interLayerPredLayerIdc  [MAX_VPS_LAYER_ID_PLUS1];
 #else
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   Int         m_numILRRefIdx;       //< for inter-layer reference picture ser
 #endif
@@ -1429,8 +1665,11 @@
   Bool        m_bRefenced;
   
+#if POC_RESET_FLAG
+  Bool        m_bPocResetFlag;
+  Int         m_pocValueBeforeReset;
+#endif  
 #if SH_DISCARDABLE_FLAG
   Bool        m_bDiscardableFlag;
 #endif
-
   // access channel
   TComVPS*    m_pcVPS;
@@ -1460,5 +1699,5 @@
   TComPic*    m_pcBaseColPic[MAX_LAYERS];
   TComPicYuv* m_pcFullPelBaseRec[MAX_LAYERS];
-#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
+#if M0457_COL_PICTURE_SIGNALING
   Int         m_numMotionPredRefLayers;
 #if REF_IDX_MFM
@@ -1542,8 +1781,12 @@
   Void      setRPSidx          ( Int iBDidx ) { m_iBDidx = iBDidx; }
   Int       getRPSidx          () { return m_iBDidx; }
-  Int       getPrevPOC      ()                          { return  m_prevPOC;       }
+  Int       getPrevTid0POC      ()                        { return  m_prevTid0POC;       }
   TComRefPicListModification* getRefPicListModification() { return &m_RefPicListModification; }
   Void      setLastIDR(Int iIDRPOC)                       { m_iLastIDR = iIDRPOC; }
   Int       getLastIDR()                                  { return m_iLastIDR; }
+  Void      setAssociatedIRAPPOC(Int iAssociatedIRAPPOC)             { m_iAssociatedIRAP = iAssociatedIRAPPOC; }
+  Int       getAssociatedIRAPPOC()                        { return m_iAssociatedIRAP; }
+  Void      setAssociatedIRAPType(NalUnitType associatedIRAPType)    { m_iAssociatedIRAPType = associatedIRAPType; }
+  NalUnitType getAssociatedIRAPType()                        { return m_iAssociatedIRAPType; }
   SliceType getSliceType    ()                          { return  m_eSliceType;         }
   Int       getPOC          ()                          { return  m_iPOC;           }
@@ -1571,4 +1814,5 @@
   Void      checkColRefIdx      (UInt curSliceIdx, TComPic* pic);
   Bool      getIsUsedAsLongTerm (Int i, Int j)                  { return m_bIsUsedAsLongTerm[i][j]; }
+  Void      setIsUsedAsLongTerm (Int i, Int j, Bool value)      { m_bIsUsedAsLongTerm[i][j] = value; }
   Bool      getCheckLDC     ()                                  { return m_bCheckLDC; }
   Bool      getMvdL1ZeroFlag ()                                  { return m_bLMvdL1Zero;    }
@@ -1580,5 +1824,6 @@
   Void      setReferenced(Bool b)                               { m_bRefenced = b; }
   Bool      isReferenced()                                      { return m_bRefenced; }
-  Void      setPOC              ( Int i )                       { m_iPOC              = i; if(getTLayer()==0) m_prevPOC=i; }
+  Bool      isReferenceNalu()                                   { return ((getNalUnitType() <= NAL_UNIT_RESERVED_VCL_R15) && (getNalUnitType()%2 != 0)) || ((getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) && (getNalUnitType() <= NAL_UNIT_RESERVED_IRAP_VCL23) ); }
+  Void      setPOC              ( Int i )                       { m_iPOC              = i; if ((getTLayer()==0) && (isReferenceNalu() && (getNalUnitType()!=NAL_UNIT_CODED_SLICE_RASL_R)&& (getNalUnitType()!=NAL_UNIT_CODED_SLICE_RADL_R))) {m_prevTid0POC=i;} }
   Void      setNalUnitType      ( NalUnitType e )               { m_eNalUnitType      = e;      }
   NalUnitType getNalUnitType    () const                        { return m_eNalUnitType;        }
@@ -1591,4 +1836,10 @@
 #endif
 
+#if POC_RESET_FLAG
+  Bool      getPocResetFlag  ()                              { return m_bPocResetFlag; }
+  Void      setPocResetFlag  (Bool b)                        { m_bPocResetFlag = b; }
+  Int       getPocValueBeforeReset ()                        { return m_pocValueBeforeReset; }
+  Void      setPocValueBeforeReset (Int x)                   { m_pocValueBeforeReset = x ; }
+#endif
 #if SH_DISCARDABLE_FLAG
   Bool      getDiscardableFlag  ()                              { return m_bDiscardableFlag; }
@@ -1596,5 +1847,5 @@
 #endif
 
-  Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic);
+  Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic);
   Void      decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic);
   Void      setSliceType        ( SliceType e )                 { m_eSliceType        = e;      }
@@ -1665,4 +1916,5 @@
   Void setTLayerInfo( UInt uiTLayer );
   Void decodingMarking( TComList<TComPic*>& rcListPic, Int iGOPSIze, Int& iMaxRefPicNum ); 
+  Void checkLeadingPictureRestrictions( TComList<TComPic*>& rcListPic );
   Void applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *RPSList);
   Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
@@ -1731,5 +1983,11 @@
   Void  setScalingList              ( TComScalingList* scalingList ) { m_scalingList = scalingList; }
   TComScalingList*   getScalingList ()                               { return m_scalingList; }
+
+#if IL_SL_SIGNALLING_N0371
+  Void  setDefaultScalingList       ( UInt m_layerId );
+#else
   Void  setDefaultScalingList       ();
+#endif
+
   Bool  checkDefaultScalingList     ();
   Void      setCabacInitFlag  ( Bool val ) { m_cabacInitFlag = val;      }  //!< set CABAC initial flag 
@@ -1761,5 +2019,4 @@
 #endif
 
-#if REF_IDX_FRAMEWORK
   Void      setRefPicListModificationSvc();
   Int       getNumILRRefIdx     ( )                     { return  m_pcVPS->getNumDirectRefLayers( m_layerId ); }
@@ -1789,5 +2046,5 @@
 #endif
 
-#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
+#if M0457_COL_PICTURE_SIGNALING
   Void      setNumMotionPredRefLayers(int i)            { m_numMotionPredRefLayers = i; }
   Int       getNumMotionPredRefLayers()                 { return m_numMotionPredRefLayers; }
@@ -1806,16 +2063,17 @@
 #endif
 
-#else
-  // temporal solution for IntraBL. Only one reference layer is supported.
-  Int       getActiveNumILRRefIdx     ( )               { return  1; }
-  Int       getInterLayerPredLayerIdc (UInt layerIdx)   { return  m_layerId - 1;}
-  Void      setActiveNumILRRefIdx     ( Int i )         {}
-  Void      setInterLayerPredEnabledFlag( Bool   val )  {}
-#endif
-
 TComPic* getRefPic(TComList<TComPic*>& rcListPic, Int poc) { return xGetRefPic( rcListPic, poc ); } 
 
 #endif //SVC_EXTENSION
 
+#if REPN_FORMAT_IN_VPS
+  UInt getPicWidthInLumaSamples();
+  UInt getPicHeightInLumaSamples();
+  UInt getChromaFormatIdc();
+  UInt getBitDepthY();
+  UInt getBitDepthC();
+  Int getQpBDOffsetY();
+  Int getQpBDOffsetC();
+#endif
 protected:
   TComPic*  xGetRefPic  (TComList<TComPic*>& rcListPic,
Index: /trunk/source/Lib/TLibCommon/TComTrQuant.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 442)
@@ -42,5 +42,5 @@
 #include "TComPic.h"
 #include "ContextTables.h"
-
+#define MAYBE_BUGFIX 1
 typedef struct
 {
@@ -50,4 +50,14 @@
   Double d64SigCost;
   Double d64SigCost_0;
+#if MAYBE_BUGFIX
+  Void init()
+  {
+    iNNZbeforePos0 = 0;
+  d64CodedLevelandDist = 0;
+  d64UncodedDist = 0;
+  d64SigCost = 0;
+  d64SigCost_0 = 0;
+  }
+#endif
 } coeffGroupRDStats;
 
@@ -1033,5 +1043,9 @@
 
     Int qpScaled;
+#if REPN_FORMAT_IN_VPS
+    Int qpBDOffset = (eTType == TEXT_LUMA)? pcCU->getSlice()->getQpBDOffsetY() : pcCU->getSlice()->getQpBDOffsetC();
+#else
     Int qpBDOffset = (eTType == TEXT_LUMA)? pcCU->getSlice()->getSPS()->getQpBDOffsetY() : pcCU->getSlice()->getSPS()->getQpBDOffsetC();
+#endif
 
     if(eTType == TEXT_LUMA)
@@ -1581,6 +1595,9 @@
     UInt uiCGPosY   = uiCGBlkPos / uiNumBlkSide;
     UInt uiCGPosX   = uiCGBlkPos - (uiCGPosY * uiNumBlkSide);
+#if MAYBE_BUGFIX
+    rdStats.init();
+#else
     ::memset( &rdStats, 0, sizeof (coeffGroupRDStats));
-    
+#endif
     const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, uiCGPosX, uiCGPosY, uiWidth, uiHeight);
     for (Int iScanPosinCG = uiCGSize-1; iScanPosinCG >= 0; iScanPosinCG--)
@@ -2477,5 +2494,9 @@
 /** set flat matrix value to quantized coefficient
  */
+#if IL_SL_SIGNALLING_N0371
+Void TComTrQuant::setFlatScalingList( UInt m_layerId )
+#else
 Void TComTrQuant::setFlatScalingList()
+#endif
 {
   UInt size,list;
@@ -2486,4 +2507,12 @@
     for(list = 0; list <  g_scalingListNum[size]; list++)
     {
+#if IL_SL_SIGNALLING_N0371
+      ref_scalingListDC[m_layerId][size][list] = SCALING_LIST_DC;
+      for(UInt i=0; i<MAX_MATRIX_COEF_NUM; i++)
+      {
+        ref_scalingListCoef[m_layerId][size][list][i] = SCALING_LIST_DC;
+      }
+#endif
+
       for(qp=0;qp<SCALING_LIST_REM_NUM;qp++)
       {
Index: /trunk/source/Lib/TLibCommon/TComTrQuant.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComTrQuant.h	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComTrQuant.h	(revision 442)
@@ -181,5 +181,11 @@
   Void setUseScalingList   ( Bool bUseScalingList){ m_scalingListEnabledFlag = bUseScalingList; };
   Bool getUseScalingList   (){ return m_scalingListEnabledFlag; };
+
+#if IL_SL_SIGNALLING_N0371
+  Void setFlatScalingList  ( UInt m_layerId );
+#else
   Void setFlatScalingList  ();
+#endif
+
   Void xsetFlatScalingList ( UInt list, UInt size, UInt qp);
   Void xSetScalingListEnc  ( TComScalingList *scalingList, UInt list, UInt size, UInt qp);
Index: /trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 442)
@@ -151,17 +151,12 @@
   Pel* piDstV;
 
-#if SIMPLIFIED_MV_POS_SCALING
   Int scaleX = g_posScalingFactor[refLayerIdc][0];
   Int scaleY = g_posScalingFactor[refLayerIdc][1];
-#else
-  Int   scaleX     = ( ( widthBL << shiftX ) + ( widthEL >> 1 ) ) / widthEL;
-  Int   scaleY     = ( ( heightBL << shiftY ) + ( heightEL >> 1 ) ) / heightEL;
-#endif
 
   if( scaleX == 65536 && scaleY == 65536 ) // ratio 1x
   {
-    piSrcY = piSrcBufY - scalEL.getWindowLeftOffset() - scalEL.getWindowTopOffset() * strideEL;
-    piDstY = piDstBufY;
-    for( i = 0; i < heightEL; i++ )
+    piSrcY = piSrcBufY;
+    piDstY = piDstBufY + scalEL.getWindowLeftOffset() + scalEL.getWindowTopOffset() * strideEL;
+    for( i = 0; i < heightBL; i++ )
     {
       memcpy( piDstY, piSrcY, sizeof(Pel) * widthBL );
@@ -179,11 +174,11 @@
     strideEL  = pcUsPic->getCStride();
 
-    piSrcU = piSrcBufU - ( scalEL.getWindowLeftOffset() >> 1 ) - ( scalEL.getWindowTopOffset() >> 1 ) * strideEL;
-    piSrcV = piSrcBufV - ( scalEL.getWindowLeftOffset() >> 1 ) - ( scalEL.getWindowTopOffset() >> 1 ) * strideEL;
-
-    piDstU = piDstBufU;
-    piDstV = piDstBufV;
-
-    for( i = 0; i < heightEL; i++ )
+    piSrcU = piSrcBufU;
+    piSrcV = piSrcBufV;
+
+    piDstU = piDstBufU + ( scalEL.getWindowLeftOffset() >> 1 ) + ( scalEL.getWindowTopOffset() >> 1 ) * strideEL;
+    piDstV = piDstBufV + ( scalEL.getWindowLeftOffset() >> 1 ) + ( scalEL.getWindowTopOffset() >> 1 ) * strideEL;
+
+    for( i = 0; i < heightBL; i++ )
     {
       memcpy( piDstU, piSrcU, sizeof(Pel) * widthBL );
@@ -238,5 +233,4 @@
     Int shiftYM4 = shiftY - 4;
 
-#if ILP_DECODED_PICTURE
     widthEL   = pcUsPic->getWidth ();
     heightEL  = pcUsPic->getHeight();
@@ -244,5 +238,4 @@
     widthBL   = pcBasePic->getWidth ();
     heightBL  = min<Int>( pcBasePic->getHeight(), heightEL );
-#endif
 #if SCALED_REF_LAYER_OFFSETS
     Int leftStartL = scalEL.getWindowLeftOffset();
@@ -395,5 +388,4 @@
     }
 
-#if ILP_DECODED_PICTURE
 #if SCALED_REF_LAYER_OFFSETS
     widthBL   = pcBasePic->getWidth ();
@@ -408,5 +400,4 @@
     widthEL   = pcUsPic->getWidth () - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
     heightEL  = pcUsPic->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-#endif
 #endif
 
@@ -451,10 +442,4 @@
     shiftYM4 = shiftY - 4;
 
-#if !SIMPLIFIED_MV_POS_SCALING
-    scaleX     = ( ( widthBL << shiftX ) + ( widthEL >> 1 ) ) / widthEL;
-    scaleY     = ( ( heightBL << shiftY ) + ( heightEL >> 1 ) ) / heightEL;
-#endif
-
-#if ILP_DECODED_PICTURE
     widthEL   = pcUsPic->getWidth () >> 1;
     heightEL  = pcUsPic->getHeight() >> 1;
@@ -462,5 +447,4 @@
     widthBL   = pcBasePic->getWidth () >> 1;
     heightBL  = min<Int>( pcBasePic->getHeight() >> 1, heightEL );
-#endif
 
 #if  N0214_INTERMEDIATE_BUFFER_16BITS
@@ -639,5 +623,5 @@
 #endif
     }
-
+  }
     pcUsPic->setBorderExtension(false);
     pcUsPic->extendPicBorder   (); // extend the border.
@@ -647,5 +631,4 @@
     pcTempPic->setBorderExtension(false);
     pcBasePic->setBorderExtension(false);
-  }
 }
 #endif //SVC_EXTENSION
Index: /trunk/source/Lib/TLibCommon/TComWeightPrediction.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComWeightPrediction.h	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TComWeightPrediction.h	(revision 442)
@@ -53,6 +53,4 @@
 class TComWeightPrediction
 {
-  wpScalingParam  m_wp0[3], m_wp1[3];
-
 public:
   TComWeightPrediction();
Index: /trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TypeDef.h	(revision 441)
+++ /trunk/source/Lib/TLibCommon/TypeDef.h	(revision 442)
@@ -41,17 +41,27 @@
 #define SVC_EXTENSION                    1
 
-#define N0139_POSITION_ROUNDING_OFFSET   1
-
 #define SYNTAX_BYTES                     10      ///< number of bytes taken by syntaxes per 4x4 block [RefIdxL0(1byte), RefIdxL1(1byte), MVxL0(2bytes), MVyL0(2bytes), MVxL1(2bytes), MVyL1(2bytes)]
 
+#define RANDOM_ACCESS_SEI_FIX            1
 #if SVC_EXTENSION
+#define VPS_NUH_LAYER_ID                 1      ///< JCTVC-N0085: Assert that the nuh_layer_id of VPS NAL unit should be 0
 #define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
-#define RPL_INIT_N0316_N0082             1      ///< N0316, N0082: initial reference picture list construction 
-#define FINAL_RPL_CHANGE_N0082           1      ///< N0082: final ref picture list change (encoder)
-#define M0464_TILE_BOUNDARY_ALIGNED_FLAG 1      ///< VUI flag to indicate tile boundary alignment
-#define M0463_VUI_EXT_ILP_REF            1      ///< VUI extension inter-layer dependency offset signalling
+#define POC_RESET_FLAG                   1      ///< JCTVC-N0244: POC reset flag for  layer pictures.
+#define ALIGN_TSA_STSA_PICS              1      ///< JCTVC-N0084: Alignment of TSA and STSA pictures across AU.
+#define REPN_FORMAT_IN_VPS               1      ///< JCTVC-N0092: Signal represenation format (spatial resolution, bit depth, colour format) in the VPS
+#define TIMING_INFO_NONZERO_LAYERID_SPS  1      ///< JCTVC-N0085: Semantics of vui_timing_info_present_flag to always set that flag to zero for non-zero layer ID SPS 
+#define RPL_INIT_N0316_N0082             1      ///< JCTVC-N0316, JCTVC-N0082: initial reference picture list construction 
+#define FINAL_RPL_CHANGE_N0082           1      ///< JCTVC-N0082: final ref picture list change (encoder)
+#if FINAL_RPL_CHANGE_N0082
+#define EXTERNAL_USEDBYCURR_N0082        1      ///< JCTVC-N0082: final ref picture list change (encoder) //dev ver.
+#define TEMP_SCALABILITY_FIX             1      ///< fix for temporal scalability
+#endif
+#define IL_SL_SIGNALLING_N0371           0      ///< JCTVC-N0371: inter-layer scaling list
+#define M0464_TILE_BOUNDARY_ALIGNED_FLAG 0      ///< JCTVC-M0464: VUI flag to indicate tile boundary alignment
+#define M0463_VUI_EXT_ILP_REF            0      ///< JCTVC-M0463: VUI extension inter-layer dependency offset signalling
 #define SPS_EXTENSION                    1      ///< Define sps_extension() syntax structure
-#define SCALED_REF_LAYER_OFFSET_FLAG     0      ///< M0309: Signal scaled reference layer offsets in SPS
-#define SCALED_REF_LAYER_OFFSETS         1      ///< M0309: Signal scaled reference layer offsets in SPS
+#define SCALED_REF_LAYER_OFFSETS         1      ///< JCTVC-M0309: Signal scaled reference layer offsets in SPS
+#define VERT_MV_CONSTRAINT               1      ///< Vertical MV component constraint flag
+#define SCALABILITY_MASK_E0104           1      ///< JCT3V-E0104: scalability mask for depth
 
 #define ILP_SSH_SIG                      1      ///< JCTVC-N0195 proposal 2, JCTVC-N0118: add presence flag in VPS ext to condition inter-layer prediction signaling in slice segment header
@@ -66,34 +76,39 @@
 #define VPS_EXTN_PROFILE_INFO            1      ///< Include profile information for layer sets in VPS extension
 #define VPS_EXTN_DIRECT_REF_LAYERS       1      ///< Include indication of direct dependency of layers in VPS extension
-#define VPS_OUTPUT_LAYER_SET_IDX         1      ///< M0268: Signal output_layer_set_idx[i] as output_layer_set_idx_minus1[i]
-#define VPS_MOVE_DIR_DEPENDENCY_FLAG     1      ///< M0268: Move the syntax element direct_dependency_flag to follow the syntax element dimension_id
-#define VPS_PROFILE_OUTPUT_LAYERS        1      ///< M0268: Signal profile information and output layer information as in Sec. 3 of M0268v2
-#define SPS_SUB_LAYER_INFO               1      ///< M0268: Do not signal sps_max_sub_layers_minus1 and sps_temporal_id_nesting_flag for nuh_layer_id greater than 0
-#define VPS_SPLIT_FLAG                   1      ///< M0163: Do not signal dimension_id and the last dimension_id_len_minus1, when splitting_flag is equal to 1. 
+#define VPS_OUTPUT_LAYER_SET_IDX         1      ///< JCTVC-M0268: Signal output_layer_set_idx[i] as output_layer_set_idx_minus1[i]
+#define VPS_MOVE_DIR_DEPENDENCY_FLAG     1      ///< JCTVC-M0268: Move the syntax element direct_dependency_flag to follow the syntax element dimension_id
+#define VPS_PROFILE_OUTPUT_LAYERS        1      ///< JCTVC-M0268: Signal profile information and output layer information as in Sec. 3 of M0268v2
+#define SPS_SUB_LAYER_INFO               1      ///< JCTVC-M0268: Do not signal sps_max_sub_layers_minus1 and sps_temporal_id_nesting_flag for nuh_layer_id greater than 0
+#define VPS_SPLIT_FLAG                   1      ///< JCTVC-M0163: Do not signal dimension_id and the last dimension_id_len_minus1, when splitting_flag is equal to 1. 
 #define M0457_PREDICTION_INDICATIONS     1
 #define M0040_ADAPTIVE_RESOLUTION_CHANGE 1
-#endif
-
-#define SH_DISCARDABLE_FLAG              1      ///< M0152: Use one reserved flag in the slice header for discardable flag
+#define VPS_VUI                          1      ///< Include function structure for VPS VUI
+
+#if VPS_VUI
+#define TILE_BOUNDARY_ALIGNED_FLAG       1      ///< JCTVC-N0160/JCTVC-N0199 proposal 2 variant 2: VPS VUI flag to indicate tile boundary alignment
+#define N0160_VUI_EXT_ILP_REF            1      ///< VUI extension inter-layer dependency offset signalling
+#define VPS_VUI_BITRATE_PICRATE          1      ///< JCTVC-N0085: Signal bit rate and picture in VPS VUI
+#else
+#define M0464_TILE_BOUNDARY_ALIGNED_FLAG 0      ///< VUI flag to indicate tile boundary alignment
+#endif //VPS_VUI
+
+#endif
+
+#define VPS_EXTN_OFFSET                  1      ///< implementation of vps_extension_offset syntax element
+#define SPS_PTL_FIX                      1      ///< remove profile_tier_level from enhancement layer SPS
+#define SH_DISCARDABLE_FLAG              1      ///< JCTVC-M0152: Use one reserved flag in the slice header for discardable flag
 
 #define DERIVE_LAYER_ID_LIST_VARIABLES   1      ///< Derived variables based on the variables in VPS - for use in syntax table parsing
 
-#define SVC_COL_BLK                      1      ///< get co-located block
 #define SVC_UPSAMPLING                   1      ///< upsampling filters
 #define ROUNDING_OFFSET                  1      ///< JCTVC-N0111: upsampling rounding offset using scalling factors
-#define N0214_INTERMEDIATE_BUFFER_16BITS 1      ///< JCTVC-N0214 support base layer input more than 8 bits
+#define N0214_INTERMEDIATE_BUFFER_16BITS 1      ///< JCTVC-N0214: support base layer input more than 8 bits
 #define ARBITRARY_SPATIAL_RATIO          0      ///< JCTVC-N0219, JCTVC-N0273: Support arbitrary spatial ratio
 #define BUGFIX_RESAMPLE                  1      ///< JCTVC-N0055: resampling bug fix for positive left scalled offset
 
-#define SIMPLIFIED_MV_POS_SCALING        1      ///< M0133/M0449: inter-layer MV scaling and pixel mapping position calculation
-#define ILP_DECODED_PICTURE              1      ///< M0274: use decoded picture for inter-layer prediction
 #define JCTVC_M0259_LAMBDAREFINEMENT     1      ///< JCTVC-M0259: lambda refinement (encoder only optimization)
 #define RESTR_CHK                        1      ///< JCTVC-M0208 proposal 1
 #define ILP_RAP                          1      ///< JCTVC-M0208 proposal 3
 
-#define REF_IDX_FRAMEWORK                1      ///< inter-layer reference framework
-
-#define IDR_ALIGNMENT                    1      ///< align IDR picures across layers 
-
 #define AVC_BASE                         1      ///< YUV BL reading for AVC base SVC
 #if AVC_BASE
@@ -101,20 +116,24 @@
 #endif
 
-#if REF_IDX_FRAMEWORK
-#define REF_IDX_ME_ZEROMV                1      ///< L0051: use zero motion for inter-layer reference picture (without fractional ME)
-#define ENCODER_FAST_MODE                1      ///< L0174: enable encoder fast mode. TestMethod 1 is enabled by setting to 1 and TestMethod 2 is enable by setting to 2. By default it is set to 1.
-#define REF_IDX_MFM                      1      ///< L0336: motion vector mapping of inter-layer reference picture
+#define REF_IDX_ME_ZEROMV                1      ///< JCTVC-L0051: use zero motion for inter-layer reference picture (without fractional ME)
+#define ENCODER_FAST_MODE                1      ///< JCTVC-L0174: enable encoder fast mode. TestMethod 1 is enabled by setting to 1 and TestMethod 2 is enable by setting to 2. By default it is set to 1.
+#define REF_IDX_MFM                      1      ///< JCTVC-L0336: motion vector mapping of inter-layer reference picture
 #define JCTVC_M0458_INTERLAYER_RPS_SIG   1      ///< implementation of JCTVC-L0178
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
 #define MAX_ONE_RESAMPLING_DIRECT_LAYERS 1      ///< Allow maximum of one resampling process for direct reference layers
-#endif
-#define JCTVC_M0203_INTERLAYER_PRED_IDC  1      ///< implementation of JCTVC-M0203 Inter-layer Prediction Indication
+#define MOTION_RESAMPLING_CONSTRAINT     1      ///< JCTVC-N0108: Allow maximum of one motion resampling process for direct reference layers, and use motion inter-layer prediction from the same layer as texture inter-layer prediction.
+#endif
+#define JCTVC_M0203_INTERLAYER_PRED_IDC  1      ///< JCTVC-M0203: implementation of Inter-layer Prediction Indication
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
-#define ILR_RESTR                        1      ///< JCTVC-M0209 Inter-layer RPS and RPL
-#define N0120_MAX_TID_REF_PRESENT_FLAG   1      ///< JCTVC-N0120 max_tid_ref_pics_plus1_present_flag
+#define ILR_RESTR                        1      ///< JCTVC-M0209: Inter-layer RPS and RPL
+#define ILR_RESTR_FIX                    1      ///< Fix encoder crash when temporal layers are used with scalable coding
+#define EARLY_REF_PIC_MARKING            1      ///< Decoded picture marking of sub-layer non-reference pictures
+#define N0120_MAX_TID_REF_PRESENT_FLAG   1      ///< JCTVC-N0120: max_tid_ref_pics_plus1_present_flag
+#define N0120_MAX_TID_REF_CFG            1      ///< set max_tid_il_ref_pics_plus1 and max_tid_ref_present_flag in the config. file (configuration setting)
 #endif
 #if REF_IDX_MFM
-#define REMOVE_COL_PICTURE_SIGNALING     1      ///< JCTVC-N0107 remove alternative collocated picture signalling
+#define REMOVE_COL_PICTURE_SIGNALING     1      ///< JCTVC-N0107: remove alternative collocated picture signalling
 #define M0457_COL_PICTURE_SIGNALING      1
+#define N0139_POSITION_ROUNDING_OFFSET   1      ///< JCTVC-N0139: offset for collocated block in motion mapping
 #endif
 
@@ -124,15 +143,21 @@
 #define M0457_IL_SAMPLE_PRED_ONLY_FLAG   0      ///< shall be 0, JCTVC-N0107
 #endif
-#endif
-
-#define FAST_INTRA_SHVC                  1      ///< M0115: reduction number of intra modes in the EL (encoder only)
+
+#define N0147_IRAP_ALIGN_FLAG            1      ///< a flag to indicatate whether IRAPs are aligned across layers
+#if !N0147_IRAP_ALIGN_FLAG
+#define IDR_ALIGNMENT                    1      ///< align IDR picures across layers : As per JCTVC-N0373, IDR are not required to be aligned.
+#endif
+#define FAST_INTRA_SHVC                  1      ///< JCTVC-M0115: reduction number of intra modes in the EL (encoder only)
 #if FAST_INTRA_SHVC
-#define NB_REMAIN_MODES                  2      ///< nb of remaining modes (M0115)
-#endif
-
-#define RC_SHVC_HARMONIZATION            1      ///< JCTVC-M0037, rate control for SHVC
-
-#else
-#define ILP_DECODED_PICTURE              0
+#define NB_REMAIN_MODES                  2      ///< JCTVC-M0115: nb of remaining modes
+#endif
+
+#define RC_SHVC_HARMONIZATION            1      ///< JCTVC-M0037: rate control for SHVC
+
+#define VIEW_ID_RELATED_SIGNALING        1      ///< Introduce syntax elements view_id_len_minus1 and view_id_val
+#define M0043_LAYERS_PRESENT_SEI         0      ///< JCTVC-M0043: add layers present SEI. Macro shall be equal to 0 according to the JCTVC-N0174 discussion. The code is to be removed.
+#define N0383_IL_CONSTRAINED_TILE_SETS_SEI  1
+#define N0065_LAYER_POC_ALIGNMENT        1
+#else
 #define SYNTAX_OUTPUT                    0
 #endif // SVC_EXTENSION
@@ -143,5 +168,4 @@
 
 #define FIX1071 1 ///< fix for issue #1071
-#define M0043_LAYERS_PRESENT_SEI         0 ///< M0043: add layers present SEI
 
 #define MAX_NUM_PICS_IN_SOP           1024
@@ -606,4 +630,12 @@
   };
 }
+#if VIEW_ID_RELATED_SIGNALING
+/// scalability types
+  enum ScalabilityType
+  {
+    VIEW_ORDER_INDEX  = 1,
+    SCALABILITY_ID = 2,
+  };
+#endif
 //! \}
 
Index: /trunk/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 441)
+++ /trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 442)
@@ -101,4 +101,9 @@
     fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
     break;
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
+    fprintf( g_hTrace, "=========== Inter Layer Constrained Tile Sets SEI message ===========\n");
+    break;
+#endif
   case SEI::SCALABLE_NESTING:
     fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
@@ -266,4 +271,10 @@
       xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize);
       break;
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+    case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
+      sei = new SEIInterLayerConstrainedTileSets;
+      xParseSEIInterLayerConstrainedTileSets((SEIInterLayerConstrainedTileSets&) *sei, payloadSize);
+      break;
+#endif
     case SEI::SCALABLE_NESTING:
       sei = new SEIScalableNesting;
@@ -349,4 +360,5 @@
 
   /* restore primary bitstream for sei_message */
+  getBitstream()->deleteFifo();
   delete getBitstream();
   setBitstream(bs);
@@ -774,4 +786,48 @@
 }
 
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+Void SEIReader::xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets &sei, UInt payloadSize)
+{
+  UInt uiCode;
+
+  READ_FLAG( uiCode, "il_all_tiles_exact_sample_value_match_flag"   ); sei.m_ilAllTilesExactSampleValueMatchFlag = uiCode;
+  READ_FLAG( uiCode, "il_one_tile_per_tile_set_flag"                ); sei.m_ilOneTilePerTileSetFlag = uiCode;
+  if( !sei.m_ilOneTilePerTileSetFlag )
+  {
+    READ_UVLC( uiCode, "il_num_sets_in_message_minus1"                ); sei.m_ilNumSetsInMessageMinus1 = uiCode;
+    if( sei.m_ilNumSetsInMessageMinus1 )
+    {
+      READ_FLAG( uiCode, "skipped_tile_set_present_flag"                ); sei.m_skippedTileSetPresentFlag = uiCode;
+    }
+    else
+    {
+      sei.m_skippedTileSetPresentFlag = false;
+    }
+    UInt numSignificantSets = sei.m_ilNumSetsInMessageMinus1 - (sei.m_skippedTileSetPresentFlag ? 1 : 0) + 1;
+    for( UInt i = 0; i < numSignificantSets; i++ )
+    {
+      READ_UVLC( uiCode, "ilcts_id"                                     ); sei.m_ilctsId[i] = uiCode;
+      READ_UVLC( uiCode, "il_num_tile_rects_in_set_minus1"              ) ;sei.m_ilNumTileRectsInSetMinus1[i] = uiCode;
+      for( UInt j = 0; j <= sei.m_ilNumTileRectsInSetMinus1[i]; j++ )
+      {
+        READ_UVLC( uiCode, "il_top_left_tile_index"                       ); sei.m_ilTopLeftTileIndex[i][j] = uiCode;
+        READ_UVLC( uiCode, "il_bottom_right_tile_index"                   ); sei.m_ilBottomRightTileIndex[i][j] = uiCode;
+      }
+      READ_CODE( 2, uiCode, "ilc_idc"                                   ); sei.m_ilcIdc[i] = uiCode;
+      if( sei.m_ilAllTilesExactSampleValueMatchFlag )
+      {
+        READ_FLAG( uiCode, "il_exact_sample_value_match_flag"             ); sei.m_ilExactSampleValueMatchFlag[i] = uiCode;
+      }
+    }
+  }
+  else
+  {
+    READ_CODE( 2, uiCode, "all_tiles_ilc_idc"                         ); sei.m_allTilesIlcIdc = uiCode;
+  }
+
+  xParseByteAlign();
+}
+#endif
+
 #if M0043_LAYERS_PRESENT_SEI
 Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComVPS *vps, TComSPS *sps)
Index: /trunk/source/Lib/TLibDecoder/SEIread.h
===================================================================
--- /trunk/source/Lib/TLibDecoder/SEIread.h	(revision 441)
+++ /trunk/source/Lib/TLibDecoder/SEIread.h	(revision 442)
@@ -80,4 +80,7 @@
   Void xParseSEIToneMappingInfo       (SEIToneMappingInfo& sei, UInt payloadSize);
   Void xParseSEISOPDescription        (SEISOPDescription &sei, UInt payloadSize);
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Void xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets &sei, UInt payloadSize);
+#endif
 #if M0043_LAYERS_PRESENT_SEI
   Void xParseSEILayersPresent         (SEILayersPresent &sei, UInt payloadSize, TComVPS *vps);
Index: /trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp	(revision 441)
+++ /trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp	(revision 442)
@@ -52,9 +52,9 @@
   if (length < 10)
   {
-    fprintf( g_hTrace, "%-50s u(%d)  : %d\n", pSymbolName, length, rValue ); 
+    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue ); 
   }
   else
   {
-    fprintf( g_hTrace, "%-50s u(%d) : %d\n", pSymbolName, length, rValue ); 
+    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue ); 
   }
   fflush ( g_hTrace );
@@ -65,5 +65,5 @@
   xReadUvlc (rValue);
   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
-  fprintf( g_hTrace, "%-50s ue(v) : %d\n", pSymbolName, rValue ); 
+  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue ); 
   fflush ( g_hTrace );
 }
Index: /trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 441)
+++ /trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 442)
@@ -291,7 +291,55 @@
   }
   READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
+
+#if IL_SL_SIGNALLING_N0371
+  pcPPS->setPPS( pcPPS->getLayerId(), pcPPS );  
+#endif
+
   if(pcPPS->getScalingListPresentFlag ())
   {
+#if IL_SL_SIGNALLING_N0371
+    pcPPS->getScalingList()->setLayerId( pcPPS->getLayerId() );
+
+    if( pcPPS->getLayerId() > 0 ) 
+    {
+      READ_FLAG( uiCode, "pps_pred_scaling_list_flag" );           pcPPS->setPredScalingListFlag( uiCode ? true : false );
+      pcPPS->getScalingList()->setPredScalingListFlag( pcPPS->getPredScalingListFlag() );
+      
+      if( pcPPS->getPredScalingListFlag() )
+      {
+        READ_UVLC ( uiCode, "scaling_list_pps_ref_layer_id" );   pcPPS->setScalingListRefLayerId( uiCode );
+
+        // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
+        assert( /*pcPPS->getScalingListRefLayerId() >= 0 &&*/ pcPPS->getScalingListRefLayerId() <= 62 );
+
+        // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of pps_scaling_list_ref_layer_id shall be greater than 0
+        if( pcPPS->getSPS()->getVPS()->getAvcBaseLayerFlag() )
+        {
+          assert( pcPPS->getScalingListRefLayerId() > 0 );
+        }
+
+        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and 
+        // pps_infer_scaling_list_flag in the PPS is equal to 1, pps_infer_scaling_list_flag shall be equal to 0 for the PPS that is active for the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id
+        assert( pcPPS->getPPS( pcPPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
+
+        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB, 
+        // the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
+        assert( pcPPS->getSPS()->getVPS()->getScalingListLayerDependency( pcPPS->getLayerId(), pcPPS->getScalingListRefLayerId() ) == true );
+
+        pcPPS->getScalingList()->setScalingListRefLayerId( pcPPS->getScalingListRefLayerId() );
+        parseScalingList( pcPPS->getScalingList() );
+      }
+      else
+      {
+        parseScalingList( pcPPS->getScalingList() );
+      }
+    }
+    else
+    {
+      parseScalingList( pcPPS->getScalingList() );
+    }
+#else
     parseScalingList( pcPPS->getScalingList() );
+#endif
   }
 
@@ -377,4 +425,10 @@
   TimingInfo *timingInfo = pcVUI->getTimingInfo();
   READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
+#if TIMING_INFO_NONZERO_LAYERID_SPS
+  if( pcSPS->getLayerId() > 0 )
+  {
+    assert( timingInfo->getTimingInfoPresentFlag() == false );
+  }
+#endif
   if(timingInfo->getTimingInfoPresentFlag())
   {
@@ -516,4 +570,8 @@
   }
 #endif 
+#if IL_SL_SIGNALLING_N0371
+  pcSPS->setVPS( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId()) );
+  pcSPS->setSPS( pcSPS->getLayerId(), pcSPS );
+#endif
   if ( pcSPS->getMaxTLayers() == 1 )
   {
@@ -525,40 +583,75 @@
 #endif
   }
-
+#ifdef SPS_PTL_FIX
+  if ( pcSPS->getLayerId() == 0)
+  {
+    parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
+  }
+#else
   parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
+#endif
+
   READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
   assert(uiCode <= 15);
-  
-  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
-  assert(uiCode <= 3);
-  // in the first version we only support chroma_format_idc equal to 1 (4:2:0), so separate_colour_plane_flag cannot appear in the bitstream
-  assert (uiCode == 1);
-  if( uiCode == 3 )
-  {
-    READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
-  }
-
-  READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
-  READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
+
+#if REPN_FORMAT_IN_VPS
+  if( pcSPS->getLayerId() > 0 )
+  {
+    READ_FLAG( uiCode, "update_rep_format_flag" );                 
+    pcSPS->setUpdateRepFormatFlag( uiCode ? true : false );
+  }
+  else
+  {
+    pcSPS->setUpdateRepFormatFlag( true );
+  }
+  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) 
+  {
+#endif
+    READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
+    assert(uiCode <= 3);
+    // in the first version we only support chroma_format_idc equal to 1 (4:2:0), so separate_colour_plane_flag cannot appear in the bitstream
+    assert (uiCode == 1);
+    if( uiCode == 3 )
+    {
+      READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
+    }
+
+    READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
+    READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
+#if REPN_FORMAT_IN_VPS
+  }
+#endif
   READ_FLAG(     uiCode, "conformance_window_flag");
   if (uiCode != 0)
   {
     Window &conf = pcSPS->getConformanceWindow();
+#if REPN_FORMAT_IN_VPS
+    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() ) );
-  }
-
-  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
-  assert(uiCode <= 6);
-  pcSPS->setBitDepthY( uiCode + 8 );
-  pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
-
-  READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
-  assert(uiCode <= 6);
-  pcSPS->setBitDepthC( uiCode + 8 );
-  pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
-
+#endif
+  }
+#if REPN_FORMAT_IN_VPS
+  if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) 
+  {
+#endif
+    READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
+    assert(uiCode <= 6);
+    pcSPS->setBitDepthY( uiCode + 8 );
+    pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
+
+    READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
+    assert(uiCode <= 6);
+    pcSPS->setBitDepthC( uiCode + 8 );
+    pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
+#if REPN_FORMAT_IN_VPS
+  }
+#endif
   READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
   assert(uiCode <= 12);
@@ -606,6 +699,6 @@
   Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
   pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth );
-
   READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
+
   if(pcSPS->getScalingListFlag())
   {
@@ -613,5 +706,50 @@
     if(pcSPS->getScalingListPresentFlag ())
     {
+
+#if IL_SL_SIGNALLING_N0371
+      pcSPS->getScalingList()->setLayerId( pcSPS->getLayerId() );
+
+      if( pcSPS->getLayerId() > 0 )
+      {
+        READ_FLAG( uiCode, "sps_pred_scaling_list_flag" );  pcSPS->setPredScalingListFlag ( uiCode );
+        pcSPS->getScalingList()->setPredScalingListFlag( pcSPS->getPredScalingListFlag() );
+
+        if( pcSPS->getPredScalingListFlag() )
+        {
+          READ_UVLC( uiCode, "scaling_list_sps_ref_layer_id" );    pcSPS->setScalingListRefLayerId( uiCode );
+
+          // The value of sps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
+          assert( /*pcSPS->getScalingListRefLayerId() >= 0 &&*/ pcSPS->getScalingListRefLayerId() <= 62 );
+
+          // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
+          if( pcSPS->getVPS()->getAvcBaseLayerFlag() )
+          {
+            assert( pcSPS->getScalingListRefLayerId() > 0 );
+          }
+
+          // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and 
+          // sps_infer_scaling_list_flag in the SPS is equal to 1, sps_infer_scaling_list_flag shall be equal to 0 for the SPS that is active for the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id
+          assert( pcSPS->getSPS( pcSPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
+
+          // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB, 
+          // the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
+          assert( pcSPS->getVPS()->getScalingListLayerDependency( pcSPS->getLayerId(), pcSPS->getScalingListRefLayerId() ) == true );
+
+          pcSPS->getScalingList()->setScalingListRefLayerId( pcSPS->getScalingListRefLayerId() );
+          parseScalingList( pcSPS->getScalingList() );
+        }
+        else
+        {
+          parseScalingList( pcSPS->getScalingList() );
+        }
+      }
+      else
+      {
+        parseScalingList( pcSPS->getScalingList() );
+      }
+#else
       parseScalingList( pcSPS->getScalingList() );
+#endif
+
     }
   }
@@ -697,11 +835,12 @@
   UInt uiCode;
   // more syntax elements to be parsed here
+
+#if VERT_MV_CONSTRAINT
+  READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );
+  // Vertical MV component restriction is not used in SHVC CTC
+  assert( uiCode == 0 );
+#endif
 #if SCALED_REF_LAYER_OFFSETS
-#if SCALED_REF_LAYER_OFFSET_FLAG
-  READ_FLAG( uiCode, "scaled_ref_layer_offset_present_flag" );
-  if( uiCode )
-#else
   if( pcSPS->getLayerId() > 0 )
-#endif
   {
     Int iCode; 
@@ -754,5 +893,9 @@
   READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
   assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
+#if VPS_EXTN_OFFSET
+  READ_CODE( 16, uiCode,  "vps_extension_offset" );               pcVPS->setExtensionOffset( uiCode );
+#else
   READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
+#endif
   parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
   UInt subLayerOrderingInfoPresentFlag;
@@ -833,4 +976,8 @@
   {
 #if VPS_EXTNS
+    while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
+    {
+      READ_FLAG( uiCode, "vps_extension_alignment_bit_equal_to_one"); assert(uiCode == 1);
+    }
     parseVPSExtension(pcVPS);
     READ_FLAG( uiCode, "vps_entension2_flag" );
@@ -927,4 +1074,16 @@
       assert( uiCode <= vps->getMaxLayerId() );
     }
+  }
+#endif
+#if VIEW_ID_RELATED_SIGNALING 
+  // 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" ); vps->setViewIdLenMinus1( uiCode );
+  }
+
+  for(  i = 0; i < vps->getNumViews(); i++ )
+  {
+    READ_CODE( vps->getViewIdLenMinus1( ) + 1, uiCode, "view_id_val[i]" ); vps->setViewIdVal( i, uiCode );
   }
 #endif
@@ -952,11 +1111,15 @@
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
 #if N0120_MAX_TID_REF_PRESENT_FLAG
-  READ_FLAG( uiCode, "max_tid_il_ref_pics_plus1_present_flag"); vps->setMaxTidIlRefPicsPlus1PresentFlag(uiCode ? true : false);
-  if (vps->getMaxTidIlRefPicsPlus1PresentFlag())
+  READ_FLAG( uiCode, "max_tid_ref_present_flag"); vps->setMaxTidRefPresentFlag(uiCode ? true : false);
+  if (vps->getMaxTidRefPresentFlag())
   {
     for(i = 0; i < vps->getMaxLayers() - 1; i++)
     {
-      READ_CODE( 3, uiCode, "max_sublayer_for_ilp_plus1[i]" ); vps->setMaxSublayerForIlpPlus1(i, uiCode);
-      assert( uiCode <= vps->getMaxTLayers() );
+      READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); vps->setMaxTidIlRefPicsPlus1(i, uiCode);
+#if N0120_MAX_TID_REF_CFG
+      assert( uiCode <= vps->getMaxTLayers());
+#else 
+      assert( uiCode <= vps->getMaxTLayers()+ 1 );
+#endif 
     }
   }
@@ -965,5 +1128,5 @@
     for(i = 0; i < vps->getMaxLayers() - 1; i++)
     {
-      vps->setMaxSublayerForIlpPlus1(i, 7);
+      vps->setMaxTidIlRefPicsPlus1(i, 7);
     }
   }
@@ -971,5 +1134,5 @@
   for(i = 0; i < vps->getMaxLayers() - 1; i++)
   {
-    READ_CODE( 3, uiCode, "max_sublayer_for_ilp_plus1[i]" ); vps->setMaxSublayerForIlpPlus1(i, uiCode);
+    READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); vps->setMaxTidIlRefPicsPlus1(i, uiCode);
     assert( uiCode <= vps->getMaxTLayers() );
   }
@@ -1090,8 +1253,61 @@
 #endif
 #endif
+#if REPN_FORMAT_IN_VPS
+  READ_FLAG( uiCode, "rep_format_idx_present_flag"); 
+  vps->setRepFormatIdxPresentFlag( uiCode ? true : false );
+
+  if( vps->getRepFormatIdxPresentFlag() )
+  {
+    READ_CODE( 4, uiCode, "vps_num_rep_formats_minus1" );
+    vps->setVpsNumRepFormats( uiCode + 1 );
+  }
+  else
+  {
+    // default assignment
+    assert (vps->getMaxLayers() <= 16);       // If max_layers_is more than 15, num_rep_formats has to be signaled
+    vps->setVpsNumRepFormats( vps->getMaxLayers() );
+  }
+  for(i = 0; i < vps->getVpsNumRepFormats(); i++)
+  {
+    // Read rep_format_structures
+    parseRepFormat( vps->getVpsRepFormat(i) );
+  }
+  
+  // Default assignment for layer 0
+  vps->setVpsRepFormatIdx( 0, 0 );
+  if( vps->getRepFormatIdxPresentFlag() )
+  {
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      if( vps->getVpsNumRepFormats() > 1 )
+      {
+        READ_CODE( 4, uiCode, "vps_rep_format_idx[i]" );
+        vps->setVpsRepFormatIdx( i, uiCode );
+      }
+      else
+      {
+        // default assignment - only one rep_format() structure
+        vps->setVpsRepFormatIdx( i, 0 );
+      }
+    }
+  }
+  else
+  {
+    // default assignment - each layer assigned each rep_format() structure in the order signaled
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      vps->setVpsRepFormatIdx( i, i );
+    }
+  }
+#endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
-   READ_FLAG(uiCode, "max_one_active_ref_layer_flag" );
-   vps->setMaxOneActiveRefLayerFlag(uiCode);
-#endif
+  READ_FLAG(uiCode, "max_one_active_ref_layer_flag" );
+  vps->setMaxOneActiveRefLayerFlag(uiCode);
+#endif
+
+#if N0147_IRAP_ALIGN_FLAG
+  READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
+  vps->setCrossLayerIrapAlignFlag(uiCode);
+#endif 
 
 #if !VPS_MOVE_DIR_DEPENDENCY_FLAG
@@ -1128,11 +1344,140 @@
     }
   }
-#endif
+
+#endif
+
+#if IL_SL_SIGNALLING_N0371
+  for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      for(j = 0; j < i; j++)
+        {      
+          vps->setScalingListLayerDependency( i, j, vps->checkLayerDependency( i,j ) );
+        }
+    }
+#endif
+
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   READ_FLAG(uiCode, "single_layer_for_non_irap_flag" ); vps->setSingleLayerForNonIrapFlag(uiCode == 1 ? true : false);
 #endif
-}
-#endif
-
+
+  READ_FLAG( uiCode,  "vps_vui_present_flag" );
+  if (uiCode)
+  {
+#if VPS_VUI
+    while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
+    {
+      READ_FLAG( uiCode, "vps_vui_alignment_bit_equal_to_one"); assert(uiCode == 1);
+    }
+    parseVPSVUI(vps);
+#endif 
+  }
+}
+#endif
+#if REPN_FORMAT_IN_VPS
+Void  TDecCavlc::parseRepFormat      ( RepFormat *repFormat )
+{
+  UInt uiCode;
+  READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( uiCode );
+  
+  if( repFormat->getChromaFormatVpsIdc() == 3 )
+  {
+    READ_FLAG( uiCode, "separate_colour_plane_flag");        repFormat->setSeparateColourPlaneVpsFlag(uiCode ? true : false);
+  }
+
+  READ_CODE ( 16, uiCode, "pic_width_in_luma_samples" );     repFormat->setPicWidthVpsInLumaSamples ( uiCode );
+  READ_CODE ( 16, uiCode, "pic_height_in_luma_samples" );    repFormat->setPicHeightVpsInLumaSamples( uiCode );
+  
+  READ_CODE( 4, uiCode, "bit_depth_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
+  READ_CODE( 4, uiCode, "bit_depth_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
+
+}
+#endif
+#if VPS_VUI
+Void TDecCavlc::parseVPSVUI(TComVPS *vps)
+{
+  UInt i,j;
+  UInt uiCode;
+#if VPS_VUI_BITRATE_PICRATE
+  READ_FLAG( uiCode,        "bit_rate_present_vps_flag" );  vps->setBitRatePresentVpsFlag( uiCode ? true : false );
+  READ_FLAG( uiCode,        "pic_rate_present_vps_flag" );  vps->setPicRatePresentVpsFlag( uiCode ? true : false );
+
+  Bool parseFlag = vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag();
+  {
+    for( i = 0; i < vps->getNumLayerSets(); i++ )
+    {
+      for( j = 0; j < vps->getMaxTLayers(); j++ )
+      {
+        if( parseFlag && vps->getBitRatePresentVpsFlag() )
+        {
+          READ_FLAG( uiCode,        "bit_rate_present_vps_flag[i][j]" );  vps->setBitRatePresentFlag( i, j, uiCode ? true : false );
+        }
+        else
+        {
+          vps->setBitRatePresentFlag( i, j, false );
+        }
+        if( parseFlag && vps->getPicRatePresentVpsFlag() )
+        {
+          READ_FLAG( uiCode,        "pic_rate_present_vps_flag[i][j]" );  vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
+        }
+        else
+        {
+          vps->setPicRatePresentFlag( i, j, false );
+        }
+        if( parseFlag && vps->getBitRatePresentFlag(i, j) )
+        {
+          READ_CODE( 16, uiCode,    "avg_bit_rate[i][j]" ); vps->setAvgBitRate( i, j, uiCode );
+          READ_CODE( 16, uiCode,    "max_bit_rate[i][j]" ); vps->setMaxBitRate( i, j, uiCode );
+        }
+        else
+        {
+          vps->setAvgBitRate( i, j, 0 );
+          vps->setMaxBitRate( i, j, 0 );
+        }
+        if( parseFlag && vps->getPicRatePresentFlag(i, j) )
+        {
+          READ_CODE( 2 , uiCode,    "constant_pic_rate_idc[i][j]" ); vps->setConstPicRateIdc( i, j, uiCode );
+          READ_CODE( 16, uiCode,    "avg_pic_rate[i][j]"          ); vps->setAvgPicRate( i, j, uiCode );
+        }
+        else
+        {
+          vps->setConstPicRateIdc( i, j, 0 );
+          vps->setAvgPicRate     ( i, j, 0 );
+        }
+      }
+    }
+  }
+#endif
+#if TILE_BOUNDARY_ALIGNED_FLAG
+  for(i = 1; i < vps->getMaxLayers(); i++)
+  {
+    for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
+    {
+      READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));      
+    }
+  }  
+#endif 
+#if N0160_VUI_EXT_ILP_REF
+    READ_FLAG( uiCode, "num_ilp_restricted_ref_layers" ); vps->setNumIlpRestrictedRefLayers( uiCode == 1 ); 
+  if( vps->getNumIlpRestrictedRefLayers())
+  {
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
+      {
+        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1[i][j]" ); vps->setMinSpatialSegmentOffsetPlus1( i, j, uiCode ); 
+        if( vps->getMinSpatialSegmentOffsetPlus1(i,j ) > 0 ) 
+        {  
+          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[i][j]"); vps->setCtuBasedOffsetEnabledFlag(i, j, uiCode == 1 ); 
+          if(vps->getCtuBasedOffsetEnabledFlag(i,j))  
+          {
+            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[i][j]"); vps->setMinHorizontalCtuOffsetPlus1( i,j, uiCode ); 
+          }
+        }  
+      }  
+    }
+  }
+#endif 
+}
+#endif 
 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
 {
@@ -1169,5 +1514,9 @@
     rpcSlice->setDependentSliceSegmentFlag(false);
   }
+#if REPN_FORMAT_IN_VPS
+  Int numCTUs = ((rpcSlice->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((rpcSlice->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
+#else
   Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
+#endif
   Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
   UInt sliceSegmentAddress = 0;
@@ -1203,5 +1552,21 @@
   if(!rpcSlice->getDependentSliceSegmentFlag())
   {
-
+#if POC_RESET_FLAG
+    Int iBits = 0; 
+    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
+    {
+      READ_FLAG(uiCode, "poc_reset_flag");      rpcSlice->setPocResetFlag( uiCode ? true : false );
+      iBits++;
+    }
+    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
+    {
+      READ_FLAG(uiCode, "discardable_flag"); // ignored
+      iBits++;
+    }
+    for (; iBits < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
+    {
+      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
+    }
+#else
 #if SH_DISCARDABLE_FLAG
     if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
@@ -1218,4 +1583,5 @@
       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
     }
+#endif
 #endif
 
@@ -1244,11 +1610,15 @@
       rpcSlice->setRPS(rps);
     }
+#if N0065_LAYER_POC_ALIGNMENT
+    if( rpcSlice->getLayerId() > 0 || !rpcSlice->getIdrPicFlag() )
+#else
     else
+#endif
     {
       READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");
       Int iPOClsb = uiCode;
-      Int iPrevPOC = rpcSlice->getPrevPOC();
+      Int iPrevPOC = rpcSlice->getPrevTid0POC();
       Int iMaxPOClsb = 1<< sps->getBitsForPOC();
-      Int iPrevPOClsb = iPrevPOC%iMaxPOClsb;
+      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
       Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
       Int iPOCmsb;
@@ -1274,4 +1644,8 @@
       rpcSlice->setPOC              (iPOCmsb+iPOClsb);
 
+#if N0065_LAYER_POC_ALIGNMENT
+      if( !rpcSlice->getIdrPicFlag() )
+      {
+#endif
       TComReferencePictureSet* rps;
       rps = rpcSlice->getLocalRPS();
@@ -1372,4 +1746,10 @@
             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
             rps->setCheckLTMSBPresent(j,false);
+            
+            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
+            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
+            {
+              deltaPocMSBCycleLT = 0;
+            }
           }
           prevDeltaMSB = deltaPocMSBCycleLT;
@@ -1399,7 +1779,10 @@
         rpcSlice->setEnableTMVPFlag(false);
       }
-    }
-
-#if REF_IDX_FRAMEWORK
+#if N0065_LAYER_POC_ALIGNMENT
+    }
+#endif
+    }
+
+#if SVC_EXTENSION
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
     rpcSlice->setActiveNumILRRefIdx(0);
@@ -1624,5 +2007,5 @@
     if ( rpcSlice->getEnableTMVPFlag() )
     {
-#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
+#if M0457_COL_PICTURE_SIGNALING
 #if REMOVE_COL_PICTURE_SIGNALING
       rpcSlice->setMFMEnabledFlag( rpcSlice->getNumMotionPredRefLayers() > 0 ? true : false );
@@ -1667,5 +2050,5 @@
         rpcSlice->setColRefIdx(0);
       }
-#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
+#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
       }
 #endif
@@ -1685,5 +2068,9 @@
     rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
 
+#if REPN_FORMAT_IN_VPS
+    assert( rpcSlice->getSliceQp() >= -rpcSlice->getQpBDOffsetY() );
+#else
     assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
+#endif
     assert( rpcSlice->getSliceQp() <=  51 );
 
@@ -2016,5 +2403,9 @@
   xReadSvlc( iDQp );
 
+#if REPN_FORMAT_IN_VPS
+  Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY();
+#else
   Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
+#endif
   qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
 
@@ -2186,4 +2577,5 @@
   UInt  code, sizeId, listId;
   Bool scalingListPredModeFlag;
+
   //for each size
   for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
@@ -2191,4 +2583,46 @@
     for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
     {
+#if IL_SL_SIGNALLING_N0371
+      if ( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
+      { 
+        READ_FLAG( code, "scaling_list_pred_mode_flag");
+        scalingListPredModeFlag = (code) ? true : false;
+        if(!scalingListPredModeFlag) //Copy Mode
+        {
+          READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
+          scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
+          if( sizeId > SCALING_LIST_8x8 )
+          {
+            scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
+          }
+          scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
+
+        }
+        else //DPCM Mode
+        {
+          xDecodeScalingList(scalingList, sizeId, listId);
+        }
+      }
+      else
+      {
+        READ_FLAG( code, "scaling_list_pred_mode_flag");
+        scalingListPredModeFlag = (code) ? true : false;
+        if(!scalingListPredModeFlag) //Copy Mode
+        {
+          READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
+          scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
+          if( sizeId > SCALING_LIST_8x8 )
+          {
+            scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
+          }
+          scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
+
+        }
+        else //DPCM Mode
+        {
+          xDecodeScalingList(scalingList, sizeId, listId);
+        }
+      }
+#else
       READ_FLAG( code, "scaling_list_pred_mode_flag");
       scalingListPredModeFlag = (code) ? true : false;
@@ -2208,4 +2642,5 @@
         xDecodeScalingList(scalingList, sizeId, listId);
       }
+#endif
     }
   }
@@ -2229,14 +2664,44 @@
   if( sizeId > SCALING_LIST_8x8 )
   {
+#if IL_SL_SIGNALLING_N0371
+    if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
+    {
+      ref_scalingListDC[scalingList->getLayerId()][sizeId][listId] = scalingList->getScalingListDC(sizeId,listId);
+      scalingList->setScalingListDC(sizeId,listId,ref_scalingListDC[scalingList->getScalingListRefLayerId()][sizeId][listId]);
+    }
+    else
+    {
+      READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
+      scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
+      nextCoef = scalingList->getScalingListDC(sizeId,listId);
+      ref_scalingListDC[scalingList->getLayerId()][sizeId][listId] = scalingList->getScalingListDC(sizeId,listId);
+    }
+#else
     READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
     scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
     nextCoef = scalingList->getScalingListDC(sizeId,listId);
+#endif
   }
 
   for(i = 0; i < coefNum; i++)
   {
+#if IL_SL_SIGNALLING_N0371
+    if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
+    {
+      ref_scalingListCoef[scalingList->getLayerId()][sizeId][listId][i] = dst[scan[i]];
+      dst[scan[i]] = ref_scalingListCoef[scalingList->getScalingListRefLayerId()][sizeId][listId][i];
+    }
+    else
+    {
+      READ_SVLC( data, "scaling_list_delta_coef");
+      nextCoef = (nextCoef + data + 256 ) % 256;
+      dst[scan[i]] = nextCoef;
+      ref_scalingListCoef[scalingList->getLayerId()][sizeId][listId][i] = dst[scan[i]];
+    }
+#else
     READ_SVLC( data, "scaling_list_delta_coef");
     nextCoef = (nextCoef + data + 256 ) % 256;
     dst[scan[i]] = nextCoef;
+#endif
   }
 }
Index: /trunk/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 441)
+++ /trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 442)
@@ -75,4 +75,11 @@
   Void  parseVPSExtension   ( TComVPS* pcVPS );
 #endif
+
+#if VPS_VUI
+  Void  parseVPSVUI   ( TComVPS* pcVPS );
+#endif 
+#if REPN_FORMAT_IN_VPS
+  Void  parseRepFormat      ( RepFormat *repFormat );
+#endif
 #if SPS_SUB_LAYER_INFO
   Void  parseSPS            ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager );
Index: /trunk/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 441)
+++ /trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 442)
@@ -177,6 +177,11 @@
   TComSlice * pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
   UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
+#if REPN_FORMAT_IN_VPS
+  UInt uiWidth  = pcSlice->getPicWidthInLumaSamples();
+  UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
+#else
   UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
   UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
+#endif
   UInt uiGranularityWidth = g_uiMaxCUWidth;
   UInt uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
@@ -230,5 +235,9 @@
   TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
   Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
+#if REPN_FORMAT_IN_VPS
+  if((!bStartInCU) && ( uiRPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
   if((!bStartInCU) && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
   {
     m_pcEntropyDecoder->decodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
@@ -256,5 +265,9 @@
       if ( bSubInSlice )
       {
+#if REPN_FORMAT_IN_VPS
+        if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getPicWidthInLumaSamples()           ) && ( uiTPelY < pcCU->getSlice()->getPicHeightInLumaSamples()           ) )
+#else
         if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
         {
           xDecodeCU( pcCU, uiIdx, uiDepth+1, ruiIsLast );
@@ -385,5 +398,9 @@
   TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
   Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
+#if REPN_FORMAT_IN_VPS
+  if(bStartInCU||( uiRPelX >= pcSlice->getPicWidthInLumaSamples()           ) || ( uiBPelY >= pcSlice->getPicHeightInLumaSamples()           ) )
+#else
   if(bStartInCU||( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
   {
     bBoundary = true;
@@ -401,5 +418,9 @@
       
       Bool binSlice = (pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr())&&(pcCU->getSCUAddr()+uiIdx<pcSlice->getSliceSegmentCurEndCUAddr());
+#if REPN_FORMAT_IN_VPS
+      if(binSlice&&( uiLPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
       if(binSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
       {
         xDecompressCU(pcCU, uiIdx, uiNextDepth );
@@ -494,5 +515,9 @@
   
   //===== inverse transform =====
+#if REPN_FORMAT_IN_VPS
+  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
+#else
   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
   Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
@@ -733,5 +758,9 @@
   pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
 
+#if REPN_FORMAT_IN_VPS
+  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
+#else
   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
   m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
Index: /trunk/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 441)
+++ /trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 442)
@@ -247,12 +247,24 @@
     for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
     {
-#if REF_IDX_FRAMEWORK && VPS_EXTN_DIRECT_REF_LAYERS
+#if SVC_EXTENSION
+#if VPS_EXTN_DIRECT_REF_LAYERS
       if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR( m_layerId ) )
       {
-        printf( "%d(%d) ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
+        printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
       }
       else
-#endif
+      {
+        printf ("%d", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
+      }
+#endif
+      if( pcSlice->getEnableTMVPFlag() && iRefList == 1 - pcSlice->getColFromL0Flag() && iRefIndex == pcSlice->getColRefIdx() )
+      {
+        printf( "c" );
+      }
+
+      printf( " " );
+#else
       printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
+#endif
     }
     printf ("] ");
Index: /trunk/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 441)
+++ /trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 442)
@@ -860,5 +860,9 @@
   {
     UInt uiSign;
+#if REPN_FORMAT_IN_VPS
+    Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY();
+#else
     Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
+#endif
     m_pcTDecBinIf->decodeBinEP(uiSign);
     iDQp = uiDQp;
Index: /trunk/source/Lib/TLibDecoder/TDecSlice.h
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecSlice.h	(revision 441)
+++ /trunk/source/Lib/TLibDecoder/TDecSlice.h	(revision 442)
@@ -65,5 +65,4 @@
   TDecEntropy*    m_pcEntropyDecoder;
   TDecCu*         m_pcCuDecoder;
-  UInt            m_uiCurrSliceIdx;
 
   TDecSbac*       m_pcBufferSbacDecoders;   ///< line to store temporary contexts, one per column of tiles.
Index: /trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 441)
+++ /trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 442)
@@ -57,6 +57,6 @@
   g_nSymbolCounter = 0;
 #endif
+  m_associatedIRAPType = NAL_UNIT_INVALID;
   m_pocCRA = 0;
-  m_prevRAPisBLA = false;
   m_pocRandomAccess = MAX_INT;          
 #if !SVC_EXTENSION
@@ -72,6 +72,4 @@
   m_pBLReconFile = NULL;
 #endif
-#endif
-#if REF_IDX_FRAMEWORK
   memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
 #endif
@@ -79,5 +77,6 @@
   m_pBLSyntaxFile = NULL;
 #endif
-
+  m_prevSliceSkipped = false;
+  m_skippedPOC = 0;
 }
 
@@ -108,5 +107,5 @@
   
   m_cSliceDecoder.destroy();
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   for(Int i=0; i<MAX_NUM_REF; i++)
   {
@@ -137,11 +136,27 @@
 }
 
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
+#if !REPN_FORMAT_IN_VPS
 Void TDecTop::xInitILRP(TComSPS *pcSPS)
-{
+#else
+Void TDecTop::xInitILRP(TComSlice *slice)
+#endif
+{
+#if REPN_FORMAT_IN_VPS
+  TComSPS* pcSPS = slice->getSPS();
+  Int bitDepthY   = slice->getBitDepthY();
+  Int bitDepthC   = slice->getBitDepthC();
+  Int picWidth    = slice->getPicWidthInLumaSamples();
+  Int picHeight   = slice->getPicHeightInLumaSamples();
+#endif
   if(m_layerId>0)
   {
+#if REPN_FORMAT_IN_VPS
+    g_bitDepthY     = bitDepthY;
+    g_bitDepthC     = bitDepthC;
+#else
     g_bitDepthY     = pcSPS->getBitDepthY();
     g_bitDepthC     = pcSPS->getBitDepthC();
+#endif
     g_uiMaxCUWidth  = pcSPS->getMaxCUWidth();
     g_uiMaxCUHeight = pcSPS->getMaxCUHeight();
@@ -164,8 +179,16 @@
 
         m_cIlpPic[j] = new  TComPic;
+#if REPN_FORMAT_IN_VPS
+#if SVC_UPSAMPLING
+        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
+#else
+        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
 #if SVC_UPSAMPLING
         m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
 #else
         m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
 #endif
         for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
@@ -177,4 +200,6 @@
   }
 }
+
+
 
 Void TDecTop::setILRPic(TComPic *pcPic)
@@ -191,4 +216,8 @@
       m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false);
       m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
+      for (Int j=0; j<m_cIlpPic[refLayerIdc]->getPicSym()->getNumberOfCUsInFrame(); j++)  // set reference CU layerId
+      {
+        m_cIlpPic[refLayerIdc]->getPicSym()->getCU(j)->setLayerId(m_cIlpPic[refLayerIdc]->getLayerId());
+      }
     }
   }
@@ -266,13 +295,25 @@
         //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin()); 
         TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
+#if REPN_FORMAT_IN_VPS
+        if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets )
+#else
         if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() || !zeroOffsets )
+#endif
         {
           rpcPic->setSpatialEnhLayerFlag( i, true );
 
           //only for scalable extension
+#if SCALABILITY_MASK_E0104
+          assert( pcSlice->getVPS()->getScalabilityMask(2) == true );
+#else
           assert( pcSlice->getVPS()->getScalabilityMask(1) == true );
+#endif
         }
 #if MAX_ONE_RESAMPLING_DIRECT_LAYERS
+#if SCALABILITY_MASK_E0104
+        if(pcSlice->getVPS()->getScalabilityMask(2))
+#else
         if(pcSlice->getVPS()->getScalabilityMask(1))
+#endif
         {
           pcSlice->setPic(rpcPic);
@@ -283,4 +324,13 @@
 #endif
     
+#if REPN_FORMAT_IN_VPS
+#if SVC_UPSAMPLING
+    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+#else
+    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
 #if SVC_UPSAMPLING
     rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
@@ -290,4 +340,6 @@
                      conformanceWindow, defaultDisplayWindow, numReorderPics, true);
 #endif
+#endif
+
     rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
     m_cListPic.pushBack( rpcPic );
@@ -329,4 +381,14 @@
   rpcPic->destroy();
 
+#if REPN_FORMAT_IN_VPS
+#if SVC_UPSAMPLING
+  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+
+#else
+  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
 #if SVC_UPSAMPLING
   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
@@ -336,4 +398,5 @@
   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
 #endif
   rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
@@ -366,4 +429,69 @@
 }
 
+#if EARLY_REF_PIC_MARKING
+Void TDecTop::earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdSet)
+{
+  UInt currTid = m_pcPic->getTLayer();
+  UInt highestTid = (maxTemporalLayer >= 0) ? maxTemporalLayer : (m_pcPic->getSlice(0)->getSPS()->getMaxTLayers() - 1);
+  UInt latestDecLayerId = m_layerId;
+  UInt numTargetDecLayers = 0;
+  Int targetDecLayerIdList[MAX_LAYERS];
+  UInt latestDecIdx = 0;
+  TComSlice* pcSlice = m_pcPic->getSlice(0);
+
+  if ( currTid != highestTid )  // Marking  process is only applicaple for highest decoded TLayer
+  {
+    return;
+  }
+
+  // currPic must be marked as "used for reference" and must be a sub-layer non-reference picture
+  if ( !((pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N  ||
+          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N    ||
+          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N   ||
+          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N   ||
+          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N   ||
+          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N10     ||
+          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N12     ||
+          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N14) && pcSlice->isReferenced()))
+  {
+    return;
+  }
+
+  if ( targetDecLayerIdSet.size() == 0 ) // Cannot mark if we don't know the number of scalable layers
+  {
+    return;
+  }
+
+  for (std::vector<Int>::iterator it = targetDecLayerIdSet.begin(); it != targetDecLayerIdSet.end(); it++)
+  {
+    if ( latestDecLayerId == (*it) )
+    {
+      latestDecIdx = numTargetDecLayers;
+    }
+    targetDecLayerIdList[numTargetDecLayers++] = (*it);
+  }
+
+  Int remainingInterLayerReferencesFlag = 0;
+  if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId) - 1 )
+  {
+    for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
+    {
+      for ( Int k = 0; k < m_ppcTDecTop[targetDecLayerIdList[j]]->getNumDirectRefLayers(); k++ )
+      {
+        if ( latestDecIdx == m_ppcTDecTop[targetDecLayerIdList[j]]->getRefLayerId(k) )
+        {
+          remainingInterLayerReferencesFlag = 1;
+        }
+      }
+    }
+  }
+
+  if ( remainingInterLayerReferencesFlag == 0 )
+  {
+    pcSlice->setReferenced(false);
+  }
+}
+#endif
+
 Void TDecTop::xCreateLostPicture(Int iLostPoc) 
 {
@@ -478,9 +606,18 @@
   m_apcSlicePilot->setSPS(sps);
   pps->setSPS(sps);
+#if REPN_FORMAT_IN_VPS
   pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
+#else
+  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
+#endif
   pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
 
+#if REPN_FORMAT_IN_VPS
+  g_bitDepthY     = m_apcSlicePilot->getBitDepthY();
+  g_bitDepthC     = m_apcSlicePilot->getBitDepthC();
+#else
   g_bitDepthY     = sps->getBitDepthY();
   g_bitDepthC     = sps->getBitDepthC();
+#endif
   g_uiMaxCUWidth  = sps->getMaxCUWidth();
   g_uiMaxCUHeight = sps->getMaxCUHeight();
@@ -499,10 +636,18 @@
 
   m_cSAO.destroy();
+#if REPN_FORMAT_IN_VPS
+  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
+#else
   m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
+#endif
   m_cLoopFilter.create( sps->getMaxCUDepth() );
 }
 
 #if SVC_EXTENSION
+#if POC_RESET_FLAG
+Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int &iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
+#else
 Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
+#endif
 #else
 Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
@@ -538,12 +683,11 @@
   m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
 
+#if SVC_EXTENSION
 #if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
   setRefLayerParams(m_apcSlicePilot->getVPS());
 #endif
-#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
+#if M0457_COL_PICTURE_SIGNALING
   m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers);
 #endif
-
-#if SVC_EXTENSION
 #if M0457_IL_SAMPLE_PRED_ONLY_FLAG
   m_apcSlicePilot->setNumSamplePredRefLayers( getNumSamplePredRefLayers() );
@@ -554,7 +698,18 @@
 #endif
 
+  // set POC for dependent slices in skipped pictures
+  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
+  {
+    m_apcSlicePilot->setPOC(m_skippedPOC);
+  }
+
+  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
+  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
+
   // Skip pictures due to random access
   if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
   {
+    m_prevSliceSkipped = true;
+    m_skippedPOC = m_apcSlicePilot->getPOC();
     return false;
   }
@@ -562,6 +717,11 @@
   if (isSkipPictureForBLA(iPOCLastDisplay))
   {
+    m_prevSliceSkipped = true;
+    m_skippedPOC = m_apcSlicePilot->getPOC();
     return false;
   }
+
+  // clear previous slice skipped flag
+  m_prevSliceSkipped = false;
 
   // exit when a new picture is found
@@ -594,5 +754,23 @@
   // actual decoding starts here
   xActivateParameterSets();
-
+#if 0 // N0147_IRAP_ALIGN_FLAG Disabled for now!
+  //When cross_layer_irap_aligned_flag is equal to 0, num_extra_slice_header_bits >=1 
+  if(!m_apcSlicePilot->getVPS()->getCrossLayerIrapAlignFlag() )
+  {
+    assert( m_apcSlicePilot->getPPS()->getNumExtraSliceHeaderBits() > 0);
+  }
+  //When cross_layer_irap_aligned_flag is equal to 1, the value of poc_reset_flag shall be equal to 0  
+  if( m_apcSlicePilot->getVPS()->getCrossLayerIrapAlignFlag() )
+  {
+    assert( m_apcSlicePilot->getPocResetFlag() == 0);
+  }
+#endif 
+
+#if REPN_FORMAT_IN_VPS
+  // Initialize ILRP if needed, only for the current layer  
+  // ILRP intialization should go along with activation of parameters sets, 
+  // although activation of parameter sets itself need not be done for each and every slice!!!
+  xInitILRP(m_apcSlicePilot);
+#endif
   if (m_apcSlicePilot->isNextSlice()) 
   {
@@ -604,4 +782,102 @@
   }
   m_bFirstSliceInSequence = false;
+#if POC_RESET_FLAG
+  // This operation would do the following:
+  // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
+  // 2. Update the value of m_pocCRA.
+  // 3. Reset the POC values at the decoder for the current picture to be zero.
+  // 4. update value of POCLastDisplay
+  if( m_apcSlicePilot->getPocResetFlag() )
+  {
+    if( m_apcSlicePilot->getSliceIdx() == 0 )
+    {
+      Int pocAdjustValue = m_apcSlicePilot->getPOC();
+
+      // If poc reset flag is set to 1, reset all POC for DPB -> basically do it for each slice in the picutre
+      TComList<TComPic*>::iterator  iterPic = m_cListPic.begin();  
+
+      // Iterate through all picture in DPB
+      while( iterPic != m_cListPic.end() )
+      {
+        TComPic *dpbPic = *iterPic;
+        // Check if the picture pointed to by iterPic is either used for reference or
+        // needed for output, are in the same layer, and not the current picture.
+        if( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
+            &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
+              && ( dpbPic->getReconMark() ) 
+          )
+        {
+          for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
+          {
+
+            TComSlice *slice = dpbPic->getSlice(i);
+            TComReferencePictureSet *rps = slice->getRPS();
+            slice->setPOC( slice->getPOC() - pocAdjustValue );
+
+            // Also adjust the POC value stored in the RPS of each such slice
+            for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
+            {
+              rps->setPOC( j, rps->getPOC(j) - pocAdjustValue );
+            }
+            // Also adjust the value of refPOC
+            for(Int k = 0; k < 2; k++)  // For List 0 and List 1
+            {
+              RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
+              for(Int j = 0; j < slice->getNumRefIdx(list); j++)
+              {
+                slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j);
+              }
+            }
+          }
+        }
+        iterPic++;
+      }
+      // Update the value of pocCRA
+      m_pocCRA -= pocAdjustValue;
+      // Update value of POCLastDisplay
+      iPOCLastDisplay -= pocAdjustValue;
+    }
+    // Reset current poc for current slice and RPS
+    m_apcSlicePilot->setPOC( 0 );
+  }
+#endif
+#if ALIGN_TSA_STSA_PICS
+  if( m_apcSlicePilot->getLayerId() > 0 )
+  {
+    // Check for TSA alignment
+    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
+        m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R 
+         )
+    {
+      for(Int dependentLayerIdx = 0; dependentLayerIdx < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
+      {
+        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
+        TComPic* refpicLayer = m_apcSlicePilot->getRefPic(*cListPic, m_apcSlicePilot->getPOC() );
+        if( refpicLayer )
+        {
+          assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
+                    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R );    // TSA pictures should be aligned among depenedent layers
+        } 
+      }
+    }
+    // Check for STSA alignment
+    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ||
+         m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R 
+         )
+    {
+      for(Int dependentLayerIdx = 0; dependentLayerIdx < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
+      {
+        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
+        TComPic* refpicLayer = m_apcSlicePilot->getRefPic(*cListPic, m_apcSlicePilot->getPOC() ); // STSA pictures should be aligned among dependent layers
+        if( refpicLayer )
+
+        {
+          assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ||
+                    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R );
+        }
+      }
+    }
+  }
+#endif
   //detect lost reference picture and insert copy of earlier frame.
   Int lostPoc;
@@ -617,12 +893,6 @@
       TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
       fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
-#if ILP_DECODED_PICTURE
       UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth();
       UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight();
-#else
-      const Window &conf = pBLPic->getConformanceWindow();
-      UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth() - conf.getWindowLeftOffset() - conf.getWindowRightOffset();
-      UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight() - conf.getWindowTopOffset() - conf.getWindowBottomOffset();
-#endif
 
       if( pFile->good() )
@@ -674,4 +944,23 @@
     xGetNewPicBuffer (m_apcSlicePilot, pcPic);
 
+    Bool isField = false;
+    Bool isTff = false;
+    
+    if(!m_SEIs.empty())
+    {
+      // Check if any new Picture Timing SEI has arrived
+      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
+      if (pictureTimingSEIs.size()>0)
+      {
+        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
+        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
+        isTff =  (pictureTiming->m_picStruct == 1);
+      }
+    }
+    
+    //Set Field/Frame coding mode
+    m_pcPic->setField(isField);
+    m_pcPic->setTopField(isTff);
+
     // transfer any SEI messages that have been received to the picture
     pcPic->setSEIs(m_SEIs);
@@ -813,7 +1102,7 @@
   if (bNextSlice)
   {
-    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
+    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
     // Set reference list
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
     if (m_layerId == 0)
 #endif
@@ -867,5 +1156,4 @@
 #endif
 
-#if SIMPLIFIED_MV_POS_SCALING
 #if SCALED_REF_LAYER_OFFSETS
         const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
@@ -891,5 +1179,4 @@
         g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
         g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
-#endif
 
 #if SVC_UPSAMPLING
@@ -911,5 +1198,4 @@
     }
 
-#if REF_IDX_FRAMEWORK
     if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
     {
@@ -927,5 +1213,4 @@
 #endif
       }
-#endif
       pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
     }
@@ -940,4 +1225,19 @@
 #endif //SVC_EXTENSION
 
+#if N0147_IRAP_ALIGN_FLAG
+    if(  m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag())
+    {
+      for(Int dependentLayerIdx = 0; dependentLayerIdx < pcSlice->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
+      {
+        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
+        TComPic* refpicLayer = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
+        if(refpicLayer && pcSlice->isIRAP())
+        {                 
+          assert(pcSlice->getNalUnitType() == refpicLayer->getSlice(0)->getNalUnitType());
+        }
+      }
+    }
+#endif 
+    
     // For generalized B
     // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
@@ -986,13 +1286,25 @@
   if(pcSlice->getSPS()->getScalingListFlag())
   {
+#if IL_SL_SIGNALLING_N0371
+    pcSlice->getSPS()->getScalingList()->setLayerId( m_layerId );
+#endif
+
     pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
+
     if(pcSlice->getPPS()->getScalingListPresentFlag())
     {
+#if IL_SL_SIGNALLING_N0371
+      pcSlice->getPPS()->getScalingList()->setLayerId( m_layerId );
+#endif
+
       pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
     }
-    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
     if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
     {
+#if IL_SL_SIGNALLING_N0371
+      pcSlice->setDefaultScalingList( m_layerId );
+#else
       pcSlice->setDefaultScalingList();
+#endif
     }
     m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
@@ -1001,5 +1313,9 @@
   else
   {
+#if IL_SL_SIGNALLING_N0371
+    m_cTrQuant.setFlatScalingList( m_layerId );
+#else
     m_cTrQuant.setFlatScalingList();
+#endif
     m_cTrQuant.setUseScalingList(false);
   }
@@ -1032,4 +1348,5 @@
   sps->setLayerId(m_layerId);
 #endif
+
 #if SPS_SUB_LAYER_INFO
   m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder[0] );
@@ -1042,5 +1359,6 @@
   m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
 #endif
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
+#if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation  
   if(m_numLayer>0)
   {
@@ -1048,4 +1366,5 @@
   }
 #endif
+#endif
 }
 
@@ -1053,4 +1372,9 @@
 {
   TComPPS* pps = new TComPPS();
+
+#if IL_SL_SIGNALLING_N0371
+  pps->setLayerId(m_layerId);
+#endif
+
   m_cEntropyDecoder.decodePPS( pps );
 #if SVC_EXTENSION
@@ -1079,4 +1403,10 @@
   if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
   {
+#if RANDOM_ACCESS_SEI_FIX
+    if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
+    {
+      return;
+    }
+#endif
 #if M0043_LAYERS_PRESENT_SEI
     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveVPS(), m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
@@ -1148,4 +1478,7 @@
   {
     case NAL_UNIT_VPS:
+#if VPS_NUH_LAYER_ID
+      assert( nalu.m_layerId == 0 ); // Non-conforming bitstream. The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
+#endif
       xDecodeVPS();
 #if AVC_BASE
@@ -1247,5 +1580,6 @@
 Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
 {
-  if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
+  if ((m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_N_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_RADL) && 
+       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
   {
     iPOCLastDisplay++;
Index: /trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 441)
+++ /trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 442)
@@ -67,6 +67,6 @@
   Int                     m_iMaxRefPicNum;
   
+  NalUnitType             m_associatedIRAPType; ///< NAL unit type of the associated IRAP picture
   Int                     m_pocCRA;            ///< POC number of the latest CRA picture
-  Bool                    m_prevRAPisBLA;      ///< true if the previous RAP (CRA/CRANT/BLA/BLANT/IDR) picture is a BLA/BLANT picture
   Int                     m_pocRandomAccess;   ///< POC number of the random access point (the first IDR or CRA picture)
 
@@ -79,5 +79,5 @@
 
   TComSlice*              m_apcSlicePilot;
-  
+
   SEIMessages             m_SEIs; ///< List of SEI messages that have been received before the first slice and between slices
 
@@ -107,4 +107,6 @@
   Bool                    m_bFirstSliceInSequence;
 #endif
+  Bool                    m_prevSliceSkipped;
+  Int                     m_skippedPOC;
 
 #if SVC_EXTENSION
@@ -118,5 +120,5 @@
   fstream*                m_pBLReconFile;
   Int                     m_iBLSourceWidth;
-  Int                     m_iBLSourceHeight;
+  Int                     m_iBLSourceHeight;  
 #endif
 #if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
@@ -130,10 +132,8 @@
   Bool                    m_motionPredEnabledFlag[MAX_VPS_LAYER_ID_PLUS1];
 #endif
+  TComPic*                m_cIlpPic[MAX_NUM_REF];                    ///<  Inter layer Prediction picture =  upsampled picture
 #endif 
 #if AVC_SYNTAX || SYNTAX_OUTPUT
   fstream*               m_pBLSyntaxFile;
-#endif
-#if REF_IDX_FRAMEWORK
-  TComPic*                m_cIlpPic[MAX_NUM_REF];                    ///<  Inter layer Prediction picture =  upsampled picture 
 #endif
 
@@ -157,6 +157,8 @@
 
   Void executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic);
-
-#if SVC_EXTENSION
+#if SVC_EXTENSION
+#if EARLY_REF_PIC_MARKING
+  Void earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdList);
+#endif
   UInt      getLayerId            () { return m_layerId;              }
   Void      setLayerId            (UInt layer) { m_layerId = layer; }
@@ -206,4 +208,10 @@
   Int       getBLHeight() { return  m_iBLSourceHeight; }
 #endif
+#if REPN_FORMAT_IN_VPS
+  Void      xInitILRP(TComSlice *slice);
+#else
+  Void      xInitILRP(TComSPS *pcSPS);
+#endif
+  Void      setILRPic(TComPic *pcPic);
 #endif
 #if AVC_SYNTAX || SYNTAX_OUTPUT
@@ -211,8 +219,4 @@
   fstream* getBLSyntaxFile() { return m_pBLSyntaxFile; }
 #endif
-#if REF_IDX_FRAMEWORK
-  Void      xInitILRP(TComSPS *pcSPS);
-  Void      setILRPic(TComPic *pcPic);
-#endif
 
 protected:
@@ -222,5 +226,9 @@
   Void      xActivateParameterSets();
 #if SVC_EXTENSION
+#if POC_RESET_FLAG
+  Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int &iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC);
+#else
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC);
+#endif
 #else
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay);
Index: /trunk/source/Lib/TLibEncoder/SEIwrite.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 442)
@@ -95,4 +95,9 @@
     fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
     break;
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
+    fprintf( g_hTrace, "=========== Inter Layer Constrained Tile Sets SEI message ===========\n");
+    break;
+#endif
   case SEI::SCALABLE_NESTING:
     fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
@@ -153,4 +158,9 @@
     xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
     break;
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
+    xWriteSEIInterLayerConstrainedTileSets(*static_cast<const SEIInterLayerConstrainedTileSets*>(&sei));
+    break;
+#endif
   case SEI::SCALABLE_NESTING:
     xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
@@ -559,4 +569,42 @@
 }
 
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+Void SEIWriter::xWriteSEIInterLayerConstrainedTileSets(const SEIInterLayerConstrainedTileSets& sei)
+{
+  WRITE_FLAG( sei.m_ilAllTilesExactSampleValueMatchFlag,  "il_all_tiles_exact_sample_value_match_flag"   );
+  WRITE_FLAG( sei.m_ilOneTilePerTileSetFlag,              "il_one_tile_per_tile_set_flag"                );
+  if( !sei.m_ilOneTilePerTileSetFlag )
+  {
+    WRITE_UVLC( sei.m_ilNumSetsInMessageMinus1,             "il_num_sets_in_message_minus1"                );
+    if( sei.m_ilNumSetsInMessageMinus1 )
+    {
+      WRITE_FLAG( sei.m_skippedTileSetPresentFlag,            "skipped_tile_set_present_flag"                );
+    }
+    UInt numSignificantSets = sei.m_ilNumSetsInMessageMinus1 - (sei.m_skippedTileSetPresentFlag ? 1 : 0) + 1;
+    for( UInt i = 0; i < numSignificantSets; i++ )
+    {
+      WRITE_UVLC( sei.m_ilctsId[i],                           "ilcts_id"                                     );
+      WRITE_UVLC( sei.m_ilNumTileRectsInSetMinus1[i],         "il_num_tile_rects_in_set_minus1"              );
+      for( UInt j = 0; j <= sei.m_ilNumTileRectsInSetMinus1[i]; j++ )
+      {
+        WRITE_UVLC( sei.m_ilTopLeftTileIndex[i][j],             "il_top_left_tile_index"                       );
+        WRITE_UVLC( sei.m_ilBottomRightTileIndex[i][j],         "il_bottom_right_tile_index"                   );
+      }
+      WRITE_CODE( sei.m_ilcIdc[i], 2,                         "ilc_idc"                                      );
+      if( sei.m_ilAllTilesExactSampleValueMatchFlag )
+      {
+        WRITE_FLAG( sei.m_ilExactSampleValueMatchFlag[i],        "il_exact_sample_value_match_flag"            );
+      }
+    }
+  }
+  else
+  {
+    WRITE_CODE( sei.m_allTilesIlcIdc, 2,                    "all_tiles_ilc_idc"                          );
+  }
+
+  xWriteByteAlign();
+}
+#endif
+
 Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps)
 {
Index: /trunk/source/Lib/TLibEncoder/SEIwrite.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/SEIwrite.h	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/SEIwrite.h	(revision 442)
@@ -68,4 +68,7 @@
 #endif
   Void xWriteSEISOPDescription(const SEISOPDescription& sei);
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Void xWriteSEIInterLayerConstrainedTileSets(const SEIInterLayerConstrainedTileSets& sei);
+#endif
   Void xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps);
   Void xWriteByteAlign();
Index: /trunk/source/Lib/TLibEncoder/TEncAnalyze.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncAnalyze.cpp	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncAnalyze.cpp	(revision 442)
@@ -57,3 +57,4 @@
 #endif
 
+TEncAnalyze             m_gcAnalyzeAll_in;
 //! \}
Index: /trunk/source/Lib/TLibEncoder/TEncAnalyze.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncAnalyze.h	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncAnalyze.h	(revision 442)
@@ -131,4 +131,32 @@
     fclose(pFile);
   }
+
+  Void    printOutInterlaced ( Char cDelim, Double bits )
+  {
+    Double dFps     =   m_dFrmRate; //--CFG_KDY
+    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
+    
+    printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
+    //printf( "\t------------ "  " ----------"   " -------- "  " -------- "  " --------\n" );
+    printf( "\t %8d    %c"          "%12.4lf  "    "%8.4lf  "   "%8.4lf  "    "%8.4lf\n",
+           getNumPic(), cDelim,
+           bits * dScale,
+           getPsnrY() / (Double)getNumPic(),
+           getPsnrU() / (Double)getNumPic(),
+           getPsnrV() / (Double)getNumPic() );
+  }
+  
+  Void    printSummaryOutInterlaced (Int bits)
+  {
+    FILE* pFile = fopen ("summaryTotal.txt", "at");
+    Double dFps     =   m_dFrmRate; //--CFG_KDY
+    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
+    
+    fprintf(pFile, "%f\t %f\t %f\t %f\n", bits * dScale,
+            getPsnrY() / (Double)getNumPic(),
+            getPsnrU() / (Double)getNumPic(),
+            getPsnrV() / (Double)getNumPic() );
+    fclose(pFile);
+  }
   
   Void    printSummary(Char ch)
@@ -178,4 +206,5 @@
 #endif
 
+extern TEncAnalyze             m_gcAnalyzeAll_in;
 //! \}
 
Index: /trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 442)
@@ -221,4 +221,9 @@
   }
   WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0,                          "pps_scaling_list_data_present_flag" ); 
+
+#if IL_SL_SIGNALLING_N0371
+  pcPPS->setPPS( pcPPS->getLayerId(), pcPPS );  
+#endif
+
   if( pcPPS->getScalingListPresentFlag() )
   {
@@ -226,5 +231,49 @@
     printf("PPS\n");
 #endif
+
+#if IL_SL_SIGNALLING_N0371
+    m_pcSlice->getScalingList()->setLayerId( pcPPS->getLayerId() );
+
+    if( pcPPS->getLayerId() > 0 )
+    {
+      WRITE_FLAG( pcPPS->getPredScalingListFlag() ? 1 : 0,                          "pps_pred_scaling_list_flag" );
+      m_pcSlice->getScalingList()->setPredScalingListFlag( pcPPS->getPredScalingListFlag() );
+
+      if( pcPPS->getPredScalingListFlag() )
+      {
+        // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
+        assert( /*pcPPS->getScalingListRefLayerId() >= 0 &&*/ pcPPS->getScalingListRefLayerId() <= 62 );
+
+        // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of pps_scaling_list_ref_layer_id shall be greater than 0
+        if( pcPPS->getSPS()->getVPS()->getAvcBaseLayerFlag() )
+        {
+          assert( pcPPS->getScalingListRefLayerId() > 0 );
+        }
+
+        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and 
+        // pps_infer_scaling_list_flag in the PPS is equal to 1, pps_infer_scaling_list_flag shall be equal to 0 for the PPS that is active for the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id
+        assert( pcPPS->getPPS( pcPPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
+
+        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB, 
+        // the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
+        assert( pcPPS->getSPS()->getVPS()->getScalingListLayerDependency( pcPPS->getLayerId(), pcPPS->getScalingListRefLayerId() ) == true );
+        
+        WRITE_UVLC( pcPPS->getScalingListRefLayerId(),                            "scaling_list_pps_ref_layer_id" );
+        m_pcSlice->getScalingList()->setScalingListRefLayerId( pcPPS->getScalingListRefLayerId() );
+        codeScalingList( m_pcSlice->getScalingList() );
+      }
+      else
+      {
+        codeScalingList( m_pcSlice->getScalingList() );
+      }
+    }
+    else
+    {
+      codeScalingList( m_pcSlice->getScalingList() );
+    }
+#else
     codeScalingList( m_pcSlice->getScalingList() );
+#endif
+
   }
   WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag");
@@ -414,16 +463,34 @@
   }
 #endif
+#ifdef SPS_PTL_FIX
+  if (pcSPS->getLayerId() == 0)
+  {
+    codePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
+  }
+#else
   codePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
+#endif
   WRITE_UVLC( pcSPS->getSPSId (),                   "sps_seq_parameter_set_id" );
-  WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
-  assert(pcSPS->getChromaFormatIdc () == 1);
-  // in the first version chroma_format_idc can only be equal to 1 (4:2:0)
-  if( pcSPS->getChromaFormatIdc () == 3 )
-  {
-    WRITE_FLAG( 0,                                  "separate_colour_plane_flag");
-  }
-
-  WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
-  WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
+#if REPN_FORMAT_IN_VPS
+  if( pcSPS->getLayerId() > 0 )
+  {
+    WRITE_FLAG( pcSPS->getUpdateRepFormatFlag(), "update_rep_format_flag" );
+  }
+  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) 
+  {
+#endif
+    WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
+    assert(pcSPS->getChromaFormatIdc () == 1);
+    // in the first version chroma_format_idc can only be equal to 1 (4:2:0)
+    if( pcSPS->getChromaFormatIdc () == 3 )
+    {
+      WRITE_FLAG( 0,                                  "separate_colour_plane_flag");
+    }
+
+    WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
+    WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
+#if REPN_FORMAT_IN_VPS
+  }
+#endif
   Window conf = pcSPS->getConformanceWindow();
 
@@ -437,7 +504,15 @@
   }
 
-  WRITE_UVLC( pcSPS->getBitDepthY() - 8,             "bit_depth_luma_minus8" );
-  WRITE_UVLC( pcSPS->getBitDepthC() - 8,             "bit_depth_chroma_minus8" );
-
+#if REPN_FORMAT_IN_VPS
+  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) 
+  {
+    assert( pcSPS->getBitDepthY() >= 8 );
+    assert( pcSPS->getBitDepthC() >= 8 );
+#endif
+    WRITE_UVLC( pcSPS->getBitDepthY() - 8,             "bit_depth_luma_minus8" );
+    WRITE_UVLC( pcSPS->getBitDepthC() - 8,             "bit_depth_chroma_minus8" );
+#if REPN_FORMAT_IN_VPS
+  }
+#endif
   WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
 
@@ -463,4 +538,9 @@
   WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthIntra() - 1,                               "max_transform_hierarchy_depth_intra" );
   WRITE_FLAG( pcSPS->getScalingListFlag() ? 1 : 0,                                   "scaling_list_enabled_flag" ); 
+
+#if IL_SL_SIGNALLING_N0371
+  pcSPS->setSPS( pcSPS->getLayerId(), pcSPS );
+#endif
+
   if(pcSPS->getScalingListFlag())
   {
@@ -471,5 +551,50 @@
     printf("SPS\n");
 #endif
+
+#if IL_SL_SIGNALLING_N0371
+    m_pcSlice->getScalingList()->setLayerId( pcSPS->getLayerId() );
+
+    if( pcSPS->getLayerId() > 0 )
+    {
+      WRITE_FLAG( pcSPS->getPredScalingListFlag() ? 1 : 0,                          "sps_pred_scaling_list_flag" );
+      m_pcSlice->getScalingList()->setPredScalingListFlag( pcSPS->getPredScalingListFlag() );
+
+      if( pcSPS->getPredScalingListFlag() )
+      {
+
+        // The value of sps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
+        assert( /*pcSPS->getScalingListRefLayerId() >= 0 &&*/ pcSPS->getScalingListRefLayerId() <= 62 );
+        
+        // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
+        if( pcSPS->getVPS()->getAvcBaseLayerFlag() )
+        {
+          assert( pcSPS->getScalingListRefLayerId() > 0 );
+        }
+
+        // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and 
+        // sps_infer_scaling_list_flag in the SPS is equal to 1, sps_infer_scaling_list_flag shall be equal to 0 for the SPS that is active for the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id
+        assert( pcSPS->getSPS( pcSPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
+
+        // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB, 
+        // the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
+        assert( pcSPS->getVPS()->getScalingListLayerDependency( pcSPS->getLayerId(), pcSPS->getScalingListRefLayerId() ) == true );
+
+        WRITE_UVLC( pcSPS->getScalingListRefLayerId(),                            "scaling_list_sps_ref_layer_id" );
+        m_pcSlice->getScalingList()->setScalingListRefLayerId( pcSPS->getScalingListRefLayerId() );
+        codeScalingList( m_pcSlice->getScalingList() );
+      }
+      else
+      {
+        codeScalingList( m_pcSlice->getScalingList() );
+      }
+    }
+    else
+    {
       codeScalingList( m_pcSlice->getScalingList() );
+    }
+#else
+      codeScalingList( m_pcSlice->getScalingList() );
+#endif
+
     }
   }
@@ -491,5 +616,5 @@
   TComRPSList* rpsList = pcSPS->getRPSList();
   TComReferencePictureSet*      rps;
-
+  
   WRITE_UVLC(rpsList->getNumberOfReferencePictureSets(), "num_short_term_ref_pic_sets" );
   for(Int i=0; i < rpsList->getNumberOfReferencePictureSets(); i++)
@@ -540,11 +665,11 @@
 {
   // more syntax elements to be written here
+
+#if VERT_MV_CONSTRAINT
+  // Vertical MV component restriction is not used in SHVC CTC
+  WRITE_FLAG( 0, "inter_view_mv_vert_constraint_flag" );
+#endif
 #if SCALED_REF_LAYER_OFFSETS
-#if SCALED_REF_LAYER_OFFSET_FLAG
-  WRITE_FLAG( pcSPS->getLayerId() > 0, "scaled_ref_layer_offset_present_flag" );
   if( pcSPS->getLayerId() > 0 )
-#else
-  if( pcSPS->getLayerId() > 0 )
-#endif
   {
     WRITE_UVLC( pcSPS->getNumScaledRefLayerOffsets(),      "num_scaled_ref_layer_offsets" );
@@ -593,5 +718,9 @@
   WRITE_FLAG( pcVPS->getTemporalNestingFlag(),                "vps_temporal_id_nesting_flag" );
   assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
+#if VPS_EXTN_OFFSET
+  WRITE_CODE( pcVPS->getExtensionOffset(),         16,        "vps_extension_offset" );
+#else
   WRITE_CODE( 0xffff,                              16,        "vps_reserved_ffff_16bits" );
+#endif
   codePTL( pcVPS->getPTL(), true, pcVPS->getMaxTLayers() - 1 );
   const Bool subLayerOrderingInfoPresentFlag = 1;
@@ -676,6 +805,13 @@
 #else
   WRITE_FLAG( 1,                     "vps_extension_flag" );
-  codeVPSExtension(pcVPS);
-  WRITE_FLAG( 0,                     "vps_extension2_flag" );   // Flag value of 1 reserved
+  if(1) // Should be conditioned on the value of vps_extension_flag
+  {
+    while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
+    {
+      WRITE_FLAG(1,                  "vps_extension_alignment_bit_equal_to_one");
+    }
+    codeVPSExtension(pcVPS);
+    WRITE_FLAG( 0,                     "vps_extension2_flag" );   // Flag value of 1 reserved
+  }
 #endif  
   //future extensions here..
@@ -737,4 +873,16 @@
   }
 #endif
+#if VIEW_ID_RELATED_SIGNALING
+  // 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( vps->getViewIdLenMinus1( ), 4, "view_id_len_minus1" );
+  }
+
+  for(  i = 0; i < vps->getNumViews(); i++ )
+  {
+    WRITE_CODE( vps->getViewIdVal( i ), vps->getViewIdLenMinus1( ) + 1, "view_id_val[i]" );
+  }
+#endif
 #if VPS_MOVE_DIR_DEPENDENCY_FLAG
 #if VPS_EXTN_DIRECT_REF_LAYERS
@@ -750,10 +898,10 @@
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
 #if N0120_MAX_TID_REF_PRESENT_FLAG
-   WRITE_FLAG( vps->getMaxTidIlRefPicsPlus1PresentFlag(), "max_tid_il_ref_pics_plus1_present_flag");
-   if (vps->getMaxTidIlRefPicsPlus1PresentFlag())
+   WRITE_FLAG( vps->getMaxTidRefPresentFlag(), "max_tid_ref_present_flag");
+   if (vps->getMaxTidRefPresentFlag())
    {
      for( i = 0; i < vps->getMaxLayers() - 1; i++)
      {
-       WRITE_CODE(vps->getMaxSublayerForIlpPlus1(i), 3, "max_sublayer_for_ilp_plus1[i]" );
+       WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i), 3, "max_tid_il_ref_pics_plus1[i]" );
      }
    }
@@ -761,5 +909,5 @@
   for( i = 0; i < vps->getMaxLayers() - 1; i++)
   {
-    WRITE_CODE(vps->getMaxSublayerForIlpPlus1(i), 3, "max_sublayer_for_ilp_plus1[i]" );
+    WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i), 3, "max_tid_il_ref_pics_plus1[i]" );
   }
 #endif
@@ -849,6 +997,35 @@
 #endif
 #endif
+
+#if REPN_FORMAT_IN_VPS
+  WRITE_FLAG( vps->getRepFormatIdxPresentFlag(), "rep_format_idx_present_flag"); 
+
+  if( vps->getRepFormatIdxPresentFlag() )
+  {
+    WRITE_CODE( vps->getVpsNumRepFormats() - 1, 4, "vps_num_rep_formats_minus1" );
+  }
+  for(i = 0; i < vps->getVpsNumRepFormats(); i++)
+  {
+    // Read rep_format_structures
+    codeRepFormat( vps->getVpsRepFormat(i) );
+  }
+  
+  if( vps->getRepFormatIdxPresentFlag() )
+  {
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      if( vps->getVpsNumRepFormats() > 1 )
+      {
+        WRITE_CODE( vps->getVpsRepFormatIdx(i), 4, "vps_rep_format_idx[i]" );
+      }
+    }
+  }
+#endif
+
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
       WRITE_FLAG(vps->getMaxOneActiveRefLayerFlag(), "max_one_active_ref_layer_flag");
+#endif 
+#if N0147_IRAP_ALIGN_FLAG
+      WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
 #endif 
 #if !VPS_MOVE_DIR_DEPENDENCY_FLAG
@@ -875,8 +1052,123 @@
     }
   }
+
+#if IL_SL_SIGNALLING_N0371
+  for(i = 1; i < vps->getMaxLayers(); i++)
+  {
+    for(j = 0; j < i; j++)
+    {
+      vps->setScalingListLayerDependency( i, j, vps->checkLayerDependency( i,j ) );
+    }
+  }
+#endif
+
 #endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   WRITE_FLAG(vps->getSingleLayerForNonIrapFlag(), "single_layer_for_non_irap_flag" );
 #endif
+
+#if !VPS_VUI
+  WRITE_FLAG( 0,                     "vps_vui_present_flag" );
+#else
+  WRITE_FLAG( 1,                     "vps_vui_present_flag" );
+  if(1)   // Should be conditioned on the value of vps_vui_present_flag
+  {
+    while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
+    {
+      WRITE_FLAG(1,                  "vps_vui_alignment_bit_equal_to_one");
+    }
+    codeVPSVUI(vps);  
+  }
+#endif 
+}
+#endif
+#if REPN_FORMAT_IN_VPS
+Void  TEncCavlc::codeRepFormat      ( RepFormat *repFormat )
+{
+  WRITE_CODE( repFormat->getChromaFormatVpsIdc(), 2, "chroma_format_idc" );    
+  
+  if( repFormat->getChromaFormatVpsIdc() == 3 )
+  {
+    WRITE_FLAG( repFormat->getSeparateColourPlaneVpsFlag(), "separate_colour_plane_flag");      
+  }
+
+  WRITE_CODE ( repFormat->getPicWidthVpsInLumaSamples (), 16, "pic_width_in_luma_samples" );    
+  WRITE_CODE ( repFormat->getPicHeightVpsInLumaSamples(), 16, "pic_height_in_luma_samples" );    
+  
+  assert( repFormat->getBitDepthVpsLuma() >= 8 );
+  assert( repFormat->getBitDepthVpsChroma() >= 8 );
+  WRITE_CODE( repFormat->getBitDepthVpsLuma() - 8,   4, "bit_depth_luma_minus8" );           
+  WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" );         
+
+}
+#endif
+#if VPS_VUI
+Void TEncCavlc::codeVPSVUI (TComVPS *vps)
+{
+  Int i,j;
+#if VPS_VUI_BITRATE_PICRATE
+  WRITE_FLAG( vps->getBitRatePresentVpsFlag(),        "bit_rate_present_vps_flag" );
+  WRITE_FLAG( vps->getPicRatePresentVpsFlag(),        "pic_rate_present_vps_flag" );
+
+  if( vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag() )
+  {
+    for( i = 0; i < vps->getNumLayerSets(); i++ )
+    {
+      for( j = 0; j < vps->getMaxTLayers(); j++ )
+      {
+        if( vps->getBitRatePresentVpsFlag() )
+        {
+          WRITE_FLAG( vps->getBitRatePresentFlag( i, j),        "bit_rate_present_vps_flag[i][j]" );
+        }
+        if( vps->getPicRatePresentVpsFlag() )
+        {
+          WRITE_FLAG( vps->getPicRatePresentFlag( i, j),        "pic_rate_present_vps_flag[i][j]" );
+        }
+        if( vps->getBitRatePresentFlag(i, j) )
+        {
+          WRITE_CODE( vps->getAvgBitRate( i, j ), 16, "avg_bit_rate[i][j]" );
+          WRITE_CODE( vps->getAvgBitRate( i, j ), 16, "max_bit_rate[i][j]" );
+        }
+        if( vps->getPicRatePresentFlag(i, j) )
+        {
+          WRITE_CODE( vps->getConstPicRateIdc( i, j), 2 , "constant_pic_rate_idc[i][j]" ); 
+          WRITE_CODE( vps->getConstPicRateIdc( i, j), 16, "avg_pic_rate[i][j]"          ); 
+        }
+      }
+    }
+  }
+#endif
+#if TILE_BOUNDARY_ALIGNED_FLAG
+  for(i = 1; i < vps->getMaxLayers(); i++)
+  {
+    for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
+    {
+      WRITE_FLAG( vps->getTileBoundariesAlignedFlag(i,j) ? 1 : 0 , "tile_boundaries_aligned_flag[i][j]" );
+    }
+  }  
+#endif 
+#if N0160_VUI_EXT_ILP_REF
+  WRITE_FLAG( vps->getNumIlpRestrictedRefLayers() ? 1 : 0 , "num_ilp_restricted_ref_layers" );    
+  if( vps->getNumIlpRestrictedRefLayers())
+  {
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
+      {        
+        WRITE_UVLC(vps->getMinSpatialSegmentOffsetPlus1( i, j),    "min_spatial_segment_offset_plus1[i][j]");
+       
+        if( vps->getMinSpatialSegmentOffsetPlus1(i,j ) > 0 ) 
+        {  
+          WRITE_FLAG( vps->getCtuBasedOffsetEnabledFlag( i, j) ? 1 : 0 , "ctu_based_offset_enabled_flag[i][j]" );    
+          
+          if(vps->getCtuBasedOffsetEnabledFlag(i,j))  
+          {
+            WRITE_UVLC(vps->getMinHorizontalCtuOffsetPlus1( i, j),    "min_horizontal_ctu_offset_plus1[i][j]");            
+          }
+        }  
+      }  
+    }
+  }
+#endif 
 }
 #endif
@@ -927,4 +1219,23 @@
   {
 
+#if POC_RESET_FLAG
+    Int iBits = 0;
+    if( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits )
+    {
+      WRITE_FLAG( pcSlice->getPocResetFlag(), "poc_reset_flag" );
+      iBits++;
+    }
+    if( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits )
+    {
+      assert(!!"discardable_flag");
+      WRITE_FLAG(pcSlice->getDiscardableFlag(), "discardable_flag");
+      iBits++;
+    }
+    for ( ; iBits < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
+    {
+      assert(!!"slice_reserved_undetermined_flag[]");
+      WRITE_FLAG(0, "slice_reserved_undetermined_flag[]");
+    }
+#else
 #if SH_DISCARDABLE_FLAG
     if (pcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
@@ -945,4 +1256,5 @@
     }
 #endif
+#endif
 
     WRITE_UVLC( pcSlice->getSliceType(),       "slice_type" );
@@ -953,13 +1265,39 @@
     }
 
+#if REPN_FORMAT_IN_VPS
+    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
+    assert( pcSlice->getChromaFormatIdc() == 1 );
+#else
     // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
     assert (pcSlice->getSPS()->getChromaFormatIdc() == 1 );
+#endif
     // if( separate_colour_plane_flag  ==  1 )
     //   colour_plane_id                                      u(2)
 
+#if N0065_LAYER_POC_ALIGNMENT
+    if( pcSlice->getLayerId() > 0 || !pcSlice->getIdrPicFlag() )
+#else
     if( !pcSlice->getIdrPicFlag() )
-    {
-      Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
+#endif
+    {
+#if POC_RESET_FLAG
+      Int picOrderCntLSB;
+      if( !pcSlice->getPocResetFlag() )
+      {
+        picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
+      }
+      else
+      {
+        picOrderCntLSB = (pcSlice->getPocValueBeforeReset()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
+      }
+#else
+      Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
+#endif
       WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
+
+#if N0065_LAYER_POC_ALIGNMENT
+      if( !pcSlice->getIdrPicFlag() )
+      {
+#endif
       TComReferencePictureSet* rps = pcSlice->getRPS();
       
@@ -1076,4 +1414,7 @@
         WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enable_flag" );
       }
+#if N0065_LAYER_POC_ALIGNMENT
+      }
+#endif
     }
 
@@ -1224,5 +1565,5 @@
     if ( pcSlice->getEnableTMVPFlag() )
     {
-#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
+#if SVC_EXTENSION && M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
       if ( !pcSlice->getIdrPicFlag() && pcSlice->getLayerId() > 0 && pcSlice->getActiveNumILRRefIdx() > 0 && pcSlice->getNumMotionPredRefLayers() > 0 )
       {
@@ -1247,5 +1588,5 @@
         WRITE_UVLC( pcSlice->getColRefIdx(), "collocated_ref_idx" );
       }
-#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
+#if SVC_EXTENSION && M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
       }
 #endif
@@ -1554,5 +1895,9 @@
   Int iDQp  = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx );
 
+#if REPN_FORMAT_IN_VPS
+  Int qpBdOffsetY =  pcCU->getSlice()->getQpBDOffsetY();
+#else
   Int qpBdOffsetY =  pcCU->getSlice()->getSPS()->getQpBDOffsetY();
+#endif
   iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2);
 
@@ -1682,4 +2027,33 @@
         startBit = m_pcBitIf->getNumberOfWrittenBits();
 #endif
+
+#if IL_SL_SIGNALLING_N0371
+        if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
+        {
+          scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
+          WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
+          if(!scalingListPredModeFlag)// Copy Mode
+          {
+            WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId), "scaling_list_pred_matrix_id_delta");
+          }
+          else// DPCM Mode
+          {
+            xCodeScalingList(scalingList, sizeId, listId);
+          }
+        }
+        else
+        {
+          scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
+          WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
+          if(!scalingListPredModeFlag)// Copy Mode
+          {
+            WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId), "scaling_list_pred_matrix_id_delta");
+          }
+          else// DPCM Mode
+          {
+            xCodeScalingList(scalingList, sizeId, listId);
+          }
+        }
+#else
         scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
         WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
@@ -1692,7 +2066,10 @@
           xCodeScalingList(scalingList, sizeId, listId);
         }
+#endif
+
 #if SCALING_LIST_OUTPUT_RESULT
         printf("Matrix [%d][%d] Bit %d\n",sizeId,listId,m_pcBitIf->getNumberOfWrittenBits() - startBit);
 #endif
+
       }
     }
@@ -1714,11 +2091,49 @@
   Int data;
   Int *src = scalingList->getScalingListAddress(sizeId, listId);
+
     if( sizeId > SCALING_LIST_8x8 )
     {
+#if IL_SL_SIGNALLING_N0371
+      if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
+      {
+        ref_scalingListDC[scalingList->getLayerId()][sizeId][listId] = scalingList->getScalingListDC(sizeId,listId);
+        scalingList->setScalingListDC(sizeId,listId,ref_scalingListDC[scalingList->getScalingListRefLayerId()][sizeId][listId]);
+      }
+      else
+      {
+        WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8");
+        nextCoef = scalingList->getScalingListDC(sizeId,listId);
+        ref_scalingListDC[scalingList->getLayerId()][sizeId][listId] = scalingList->getScalingListDC(sizeId,listId);
+      }
+#else
       WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8");
       nextCoef = scalingList->getScalingListDC(sizeId,listId);
+#endif
     }
     for(Int i=0;i<coefNum;i++)
     {
+#if IL_SL_SIGNALLING_N0371
+      if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
+      {
+        ref_scalingListCoef[scalingList->getLayerId()][sizeId][listId][i] = src[scan[i]];
+        src[scan[i]] = ref_scalingListCoef[scalingList->getScalingListRefLayerId()][sizeId][listId][i];
+      }
+      else
+      {
+        data = src[scan[i]] - nextCoef;
+        ref_scalingListCoef[scalingList->getLayerId()][sizeId][listId][i] = src[scan[i]];
+        nextCoef = src[scan[i]];
+        if(data > 127)
+        {
+          data = data - 256;
+        }
+        if(data < -128)
+        {
+          data = data + 256;
+        }
+
+        WRITE_SVLC( data,  "scaling_list_delta_coef");
+      }
+#else
       data = src[scan[i]] - nextCoef;
       nextCoef = src[scan[i]];
@@ -1733,4 +2148,5 @@
 
       WRITE_SVLC( data,  "scaling_list_delta_coef");
+#endif
     }
 }
@@ -1738,5 +2154,5 @@
 {
   // Bool state = true, state2 = false;
-  Int lsb = ltrpPOC % (1<<pcSlice->getSPS()->getBitsForPOC());
+  Int lsb = ltrpPOC & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
   for (Int k = 0; k < pcSlice->getSPS()->getNumLongTermRefPicSPS(); k++)
   {
Index: /trunk/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 442)
@@ -87,4 +87,11 @@
   Void  codeVPSExtension        ( TComVPS* pcVPS );
 #endif
+
+#if VPS_VUI
+  Void codeVPSVUI               (TComVPS *vps);
+#endif
+#if REPN_FORMAT_IN_VPS
+  Void  codeRepFormat           ( RepFormat *repFormat );
+#endif
   Void  codeVUI                 ( TComVUI *pcVUI, TComSPS* pcSPS );
   Void  codeSPS                 ( TComSPS* pcSPS );
Index: /trunk/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 442)
@@ -69,4 +69,8 @@
   Int m_numRefIdc;
   Int m_refIdc[MAX_NUM_REF_PICS+1];
+#if EXTERNAL_USEDBYCURR_N0082
+  Int m_UseExtusedByCurrPic;
+  Int m_ExtusedByCurrPic[MAX_NUM_REF_PICS];
+#endif
   GOPEntry()
   : m_POC(-1)
@@ -83,12 +87,40 @@
   , m_deltaRPS(0)
   , m_numRefIdc(0)
+#if EXTERNAL_USEDBYCURR_N0082
+  , m_UseExtusedByCurrPic(0)
+#endif
   {
     ::memset( m_referencePics, 0, sizeof(m_referencePics) );
     ::memset( m_usedByCurrPic, 0, sizeof(m_usedByCurrPic) );
     ::memset( m_refIdc,        0, sizeof(m_refIdc) );
+#if EXTERNAL_USEDBYCURR_N0082
+    ::memset( m_usedByCurrPic, 0, sizeof(m_ExtusedByCurrPic) );
+#endif
   }
 };
 
 std::istringstream &operator>>(std::istringstream &in, GOPEntry &entry);     //input
+
+#if REPN_FORMAT_IN_VPS
+struct RepFormatCfg
+{
+  Int   m_chromaFormatIdc;
+  Bool  m_separateColourPlaneFlag;
+  Int   m_picWidthInLumaSamples;
+  Int   m_picHeightInLumaSamples;
+  Int   m_bitDepthLuma;
+  Int   m_bitDepthChroma;
+  RepFormatCfg()
+    : m_chromaFormatIdc         (CHROMA_420)
+    , m_separateColourPlaneFlag (0)
+    , m_picWidthInLumaSamples   (352)
+    , m_picHeightInLumaSamples  (288)
+    , m_bitDepthLuma            (8)
+    , m_bitDepthChroma          (8)
+  {}
+};
+std::istringstream &operator>>(std::istringstream &in, RepFormatCfg &repFormatCfg);
+#endif
+
 //! \ingroup TLibEncoder
 //! \{
@@ -155,4 +187,7 @@
 #endif
 #endif
+#if N0120_MAX_TID_REF_CFG
+  Int       m_maxTidIlRefPicsPlus1;
+#endif 
   //======= Transform =============
   UInt      m_uiQuadtreeTULog2MaxSize;
@@ -283,4 +318,12 @@
   Int       m_SOPDescriptionSEIEnabled;
   Int       m_scalableNestingSEIEnabled;
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Bool      m_interLayerConstrainedTileSetsSEIEnabled;
+  UInt      m_ilNumSetsInMessage;
+  Bool      m_skippedTileSetPresentFlag;
+  UInt      m_topLeftTileIndex[1024];
+  UInt      m_bottomRightTileIndex[1024];
+  UInt      m_ilcIdc[1024];
+#endif
   //====== Weighted Prediction ========
   Bool      m_useWeightedPred;       //< Use of Weighting Prediction (P_SLICE)
@@ -353,10 +396,8 @@
   UInt      m_layerId;   
   UInt      m_numLayer;
-#endif 
-#if REF_IDX_FRAMEWORK
-  Int      m_elRapSliceBEnabled;
-#endif
+  Int       m_elRapSliceBEnabled;
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
-  Int      m_adaptiveResolutionChange;
+  Int       m_adaptiveResolutionChange;
+#endif
 #endif
 
@@ -438,4 +479,8 @@
 #endif
 #endif
+#if N0120_MAX_TID_REF_CFG
+  Int       getMaxTidIlRefPicsPlus1         ()                              { return m_maxTidIlRefPicsPlus1; }
+  Void      setMaxTidIlRefPicsPlus1         (Int num)                       { m_maxTidIlRefPicsPlus1 = num;  }
+#endif 
   //======== Transform =============
   Void      setQuadtreeTULog2MaxSize        ( UInt  u )      { m_uiQuadtreeTULog2MaxSize = u; }
@@ -720,4 +765,36 @@
   Void  setScalableNestingSEIEnabled(Int b)                { m_scalableNestingSEIEnabled = b; }
   Int   getScalableNestingSEIEnabled()                     { return m_scalableNestingSEIEnabled; }
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Void  setInterLayerConstrainedTileSetsSEIEnabled(Bool b) { m_interLayerConstrainedTileSetsSEIEnabled = b; }
+  Bool  getInterLayerConstrainedTileSetsSEIEnabled()       { return m_interLayerConstrainedTileSetsSEIEnabled; }
+  Void  setIlNumSetsInMessage(UInt b)                      { m_ilNumSetsInMessage = b; }
+  Int   getIlNumSetsInMessage()                            { return m_ilNumSetsInMessage; }
+  Void  setSkippedTileSetPresentFlag(Bool b)               { m_skippedTileSetPresentFlag = b; }
+  Bool  getSkippedTileSetPresentFlag()                     { return m_skippedTileSetPresentFlag; }
+  Void  setTopLeftTileIndex(UInt *b)
+  {
+    for (UInt i = 0; i < m_ilNumSetsInMessage; i++)
+    {
+      m_topLeftTileIndex[i] = b[i];
+    }
+  }
+  UInt  getTopLeftTileIndex(UInt b)                        { return m_topLeftTileIndex[b]; }
+  Void  setBottomRightTileIndex(UInt *b)
+  {
+    for (UInt i = 0; i < m_ilNumSetsInMessage; i++)
+    {
+      m_bottomRightTileIndex[i] = b[i];
+    }
+  }
+  UInt  getBottomRightTileIndex(UInt b)                    { return m_bottomRightTileIndex[b]; }
+  Void  setIlcIdc(UInt *b)
+  {
+    for (UInt i = 0; i < m_ilNumSetsInMessage; i++)
+    {
+      m_ilcIdc[i] = b[i];
+    }
+  }
+  UInt  getIlcIdc(UInt b)                                  { return m_ilcIdc[b]; }
+#endif
   Void      setUseWP               ( Bool b )    { m_useWeightedPred   = b;    }
   Void      setWPBiPred            ( Bool b )    { m_useWeightedBiPred = b;    }
@@ -858,13 +935,11 @@
   Void      setConformanceMode    (Int mode)     { m_conformanceMode = mode; }
   Void      setConformanceWindow(Window& conformanceWindow ) { m_conformanceWindow = conformanceWindow; }
-#endif
-#if REF_IDX_FRAMEWORK
   Void      setElRapSliceTypeB(Int bEnabled) {m_elRapSliceBEnabled = bEnabled;}
   Int       getElRapSliceTypeB()              {return m_elRapSliceBEnabled;}
-#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   Void      setAdaptiveResolutionChange(Int x) { m_adaptiveResolutionChange = x;    }
   Int       getAdaptiveResolutionChange()      { return m_adaptiveResolutionChange; }
 #endif
+#endif
 };
 
Index: /trunk/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 442)
@@ -379,9 +379,4 @@
   m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() );
 
-  // variables for fast encoder decision
-  Bool    bEarlySkip  = false;
-  Bool    bTrySplit    = true;
-  Double  fRD_Skip    = MAX_DOUBLE;
-
   // variable for Early CU determination
   Bool    bSubBranch = true;
@@ -390,15 +385,4 @@
   Bool    doNotBlockPu = true;
   Bool earlyDetectionSkipMode = false;
-
-  Bool    bTrySplitDQP  = true;
-
-  static  Double  afCost[ MAX_CU_DEPTH ];
-  static  Int      aiNum [ MAX_CU_DEPTH ];
-
-  if ( rpcBestCU->getAddr() == 0 )
-  {
-    ::memset( afCost, 0, sizeof( afCost ) );
-    ::memset( aiNum,  0, sizeof( aiNum  ) );
-  }
 
   Bool bBoundary = false;
@@ -412,11 +396,20 @@
   Int iMaxQP;
   Bool isAddLowestQP = false;
+#if REPN_FORMAT_IN_VPS
+  Int lowestQP = -rpcTempCU->getSlice()->getQpBDOffsetY();
+#else
   Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY();
+#endif
 
   if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
   {
     Int idQP = m_pcEncCfg->getMaxDeltaQP();
+#if REPN_FORMAT_IN_VPS
     iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
     iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
+#else
+    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
+    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
+#endif
     if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
     {
@@ -450,5 +443,9 @@
   Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart();
   Bool bSliceEnd = (pcSlice->getSliceSegmentCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart());
+#if REPN_FORMAT_IN_VPS
+  Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getPicWidthInLumaSamples()           ) && ( uiBPelY < rpcBestCU->getSlice()->getPicHeightInLumaSamples()           );
+#else
   Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
+#endif
   // We need to split, so don't try these modes.
   if(!bSliceEnd && !bSliceStart && bInsidePicture )
@@ -458,11 +455,17 @@
     if (rpcBestCU->getLayerId() > 0)
     {
-        if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx()) 
-            testInter = false; 
-        if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx()) 
-            testInter = false;
+      if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx())
+      {
+        testInter = false;
+      }
+      if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx()) 
+      {
+        testInter = false;
+      }
 #if M0457_IL_SAMPLE_PRED_ONLY_FLAG
-        if( pcSlice->getInterLayerSamplePredOnlyFlag() ) 
-            testInter = false; 
+      if( pcSlice->getInterLayerSamplePredOnlyFlag() )
+      {
+        testInter = false;
+      }
 #endif
     }
@@ -474,8 +477,4 @@
         iQP = lowestQP;
       }
-      // variables for fast encoder decision
-      bEarlySkip  = false;
-      bTrySplit    = true;
-      fRD_Skip    = MAX_DOUBLE;
 
       rpcTempCU->initEstData( uiDepth, iQP );
@@ -496,49 +495,23 @@
         xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
         rpcTempCU->initEstData( uiDepth, iQP );
-
-        // fast encoder decision for early skip
-        if ( m_pcEncCfg->getUseFastEnc() )
-        {
-          Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
-          if ( aiNum [ iIdx ] > 5 && fRD_Skip < EARLY_SKIP_THRES*afCost[ iIdx ]/aiNum[ iIdx ] )
-          {
-            bEarlySkip = true;
-            bTrySplit  = false;
-          }
-        }
+        
 #if (ENCODER_FAST_MODE == 2)
         if (testInter)
         {
 #endif
-
         if(!m_pcEncCfg->getUseEarlySkipDetection())
         {
           // 2Nx2N, NxN
-          if ( !bEarlySkip )
+          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
+          if(m_pcEncCfg->getUseCbfFastMode())
           {
-            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
-            if(m_pcEncCfg->getUseCbfFastMode())
-            {
-              doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
-            }
+            doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
           }
         }
 #if (ENCODER_FAST_MODE == 2)
-    }
-#endif
-
-      }
-
-      if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
-      {
-        if(iQP == iBaseQP)
-        {
-          bTrySplitDQP = bTrySplit;
-        }
-      }
-      else
-      {
-        bTrySplitDQP = bTrySplit;
-      }
+        }
+#endif
+      }
+
       if (isAddLowestQP && (iQP == lowestQP))
       {
@@ -567,5 +540,5 @@
         // do inter modes, NxN, 2NxN, and Nx2N
 #if (ENCODER_FAST_MODE)
-      if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter )
+        if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter )
 #else
         if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
@@ -573,13 +546,10 @@
         {
           // 2Nx2N, NxN
-          if ( !bEarlySkip )
+          if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
           {
-            if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
+            if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu)
             {
-              if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu)
-              {
-                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
-                rpcTempCU->initEstData( uiDepth, iQP );
-              }
+              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
+              rpcTempCU->initEstData( uiDepth, iQP );
             }
           }
@@ -721,6 +691,4 @@
 
         // do normal intra modes
-        if ( !bEarlySkip )
-        {
           // speedup for inter frames
 #if (ENCODER_FAST_MODE)
@@ -748,5 +716,4 @@
             }
           }
-        }
 
         // test PCM
@@ -790,15 +757,4 @@
     rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
 
-    // accumulate statistics for early skip
-    if ( m_pcEncCfg->getUseFastEnc() )
-    {
-      if ( rpcBestCU->isSkipped(0) )
-      {
-        Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
-        afCost[ iIdx ] += rpcBestCU->getTotalCost();
-        aiNum [ iIdx ] ++;
-      }
-    }
-
     // Early CU determination
     if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) )
@@ -827,6 +783,11 @@
   {
     Int idQP = m_pcEncCfg->getMaxDeltaQP();
+#if REPN_FORMAT_IN_VPS
+    iMinQP = Clip3( -rpcTempCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
+    iMaxQP = Clip3( -rpcTempCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
+#else
     iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
     iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
+#endif
     if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
     {
@@ -878,5 +839,5 @@
 
     // further split
-    if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
+    if( bSubBranch && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
     {
       UChar       uhNextDepth         = uiDepth+1;
@@ -890,5 +851,9 @@
 
         Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getSliceSegmentCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getSliceSegmentCurEndCUAddr();
+#if REPN_FORMAT_IN_VPS
+        if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getPicWidthInLumaSamples()           ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
         if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
         {
           if( m_bUseSBACRD )
@@ -1038,6 +1003,11 @@
   UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
   UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
+#if REPN_FORMAT_IN_VPS
+  UInt uiWidth =  pcSlice->getPicWidthInLumaSamples();
+  UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
+#else
   UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
   UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
+#endif
   while(uiPosX>=uiWidth||uiPosY>=uiHeight)
   {
@@ -1136,5 +1106,9 @@
     iQpOffset = Int(floor( dQpOffset + 0.49999 ));
   }
+#if REPN_FORMAT_IN_VPS
+  return Clip3(-pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset );
+#else
   return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset );
+#endif
 }
 
@@ -1160,5 +1134,9 @@
     pcSlice->getSliceSegmentCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) );
   // We need to split, so don't try these modes.
+#if REPN_FORMAT_IN_VPS
+  if(!bSliceStart&&( uiRPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
   if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
   {
     m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
@@ -1181,5 +1159,9 @@
       uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
       Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurEndCUAddr();
+#if REPN_FORMAT_IN_VPS
+      if(bInSlice&&( uiLPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
       if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
       {
         xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 );
@@ -1706,5 +1688,9 @@
   Bool bSliceEnd   = pcSlice->getSliceSegmentCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && 
     pcSlice->getSliceSegmentCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) );
+#if REPN_FORMAT_IN_VPS
+  if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
   if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
   {
     UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx];
@@ -1727,5 +1713,9 @@
       Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getSliceSegmentCurStartCUAddr() && 
         rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getSliceSegmentCurEndCUAddr();
+#if REPN_FORMAT_IN_VPS
+      if(bInSlice&&( uiSubCULPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiSubCUTPelY < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
       if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
       {
         xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY );   // Copy Yuv data to picture Yuv
Index: /trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 442)
@@ -307,4 +307,43 @@
 }
 
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+SEIInterLayerConstrainedTileSets* TEncGOP::xCreateSEIInterLayerConstrainedTileSets()
+{
+  SEIInterLayerConstrainedTileSets *seiInterLayerConstrainedTileSets = new SEIInterLayerConstrainedTileSets();
+  seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag = false;
+  seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag = false;
+  if (!seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag)
+  {
+    seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 = m_pcCfg->getIlNumSetsInMessage() - 1;
+    if (seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1)
+    {
+      seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = m_pcCfg->getSkippedTileSetPresentFlag();
+    }
+    else
+    {
+      seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = false;
+    }
+    seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 += seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag ? 1 : 0;
+    for (UInt i = 0; i < m_pcCfg->getIlNumSetsInMessage(); i++)
+    {
+      seiInterLayerConstrainedTileSets->m_ilctsId[i] = i;
+      seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i] = 0;
+      for( UInt j = 0; j <= seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i]; j++)
+      {
+        seiInterLayerConstrainedTileSets->m_ilTopLeftTileIndex[i][j]     = m_pcCfg->getTopLeftTileIndex(i);
+        seiInterLayerConstrainedTileSets->m_ilBottomRightTileIndex[i][j] = m_pcCfg->getBottomRightTileIndex(i);
+      }
+      seiInterLayerConstrainedTileSets->m_ilcIdc[i] = m_pcCfg->getIlcIdc(i);
+      if (seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag)
+      {
+        seiInterLayerConstrainedTileSets->m_ilExactSampleValueMatchFlag[i] = false;
+      }
+    }
+  }
+
+  return seiInterLayerConstrainedTileSets;
+}
+#endif
+
 Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps)
 {
@@ -369,4 +408,17 @@
     delete sei;
   }
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  if(m_pcCfg->getInterLayerConstrainedTileSetsSEIEnabled())
+  {
+    SEIInterLayerConstrainedTileSets *sei = xCreateSEIInterLayerConstrainedTileSets ();
+
+    nalu = NALUnit(NAL_UNIT_PREFIX_SEI, 0, m_pcCfg->getNumLayer()-1); // For highest layer
+    m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); 
+    writeRBSPTrailingBits(nalu.m_Bitstream);
+    accessUnit.push_back(new NALUnitEBSP(nalu));
+    delete sei;
+  }
+#endif
 }
 
@@ -375,7 +427,7 @@
 // ====================================================================================================================
 #if SVC_EXTENSION
-Void TEncGOP::compressGOP( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
-#else
-Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
+Void TEncGOP::compressGOP( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff)
+#else
+Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff)
 #endif
 {
@@ -390,5 +442,5 @@
   TComOutputBitstream* pcSubstreamsOut = NULL;
 
-  xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut );
+  xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut, isField );
 
   m_iNumPicCoded = 0;
@@ -463,11 +515,23 @@
 
     /////////////////////////////////////////////////////////////////////////////////////////////////// Initial to start encoding
-    Int pocCurr = iPOCLast -iNumPicRcvd+ m_pcCfg->getGOPEntry(iGOPid).m_POC;
-    Int iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC;
-    if(iPOCLast == 0)
+    Int iTimeOffset;
+    Int pocCurr;
+    
+    if(iPOCLast == 0) //case first frame or first top field
     {
       pocCurr=0;
       iTimeOffset = 1;
     }
+    else if(iPOCLast == 1 && isField) //case first bottom field, just like the first frame, the poc computation is not right anymore, we set the right value
+    {
+      pocCurr = 1;
+      iTimeOffset = 1;
+    }
+    else
+    {
+      pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - isField;
+      iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC;
+    }
+
     if(pocCurr>=m_pcCfg->getFramesToBeEncoded())
     {
@@ -490,5 +554,5 @@
     accessUnitsInGOP.push_back(AccessUnit());
     AccessUnit& accessUnit = accessUnitsInGOP.back();
-    xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr );
+    xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr, isField );
 
     //  Slice data initialization
@@ -499,9 +563,76 @@
 #if SVC_EXTENSION
     pcPic->setLayerId( m_layerId );
-    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getVPS() );
-#else
-    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
-#endif
-
+    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getVPS(), isField );
+#else
+    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), isField );
+#endif
+
+    //Set Frame/Field coding
+    pcSlice->getPic()->setField(isField);
+
+#if POC_RESET_FLAG
+    if( !pcSlice->getPocResetFlag() ) // For picture that are not reset, we should adjust the value of POC calculated from the configuration files.
+    {
+      // Subtract POC adjustment value until now.
+      pcSlice->setPOC( pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue() );
+    }
+    else
+    {
+      // Check if this is the first slice in the picture
+      // In the encoder, the POC values are copied along with copySliceInfo, so we only need
+      // to do this for the first slice.
+      Int pocAdjustValue = pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue();
+      if( pcSlice->getSliceIdx() == 0 )
+      {
+        TComList<TComPic*>::iterator  iterPic = rcListPic.begin();  
+
+        // Iterate through all picture in DPB
+        while( iterPic != rcListPic.end() )
+        {              
+          TComPic *dpbPic = *iterPic;
+          if( dpbPic->getPOC() == pocCurr )
+          {
+            if( dpbPic->getReconMark() )
+            {
+              assert( !( dpbPic->getSlice(0)->isReferenced() ) && !( dpbPic->getOutputMark() ) );
+            }
+          }
+          // Check if the picture pointed to by iterPic is either used for reference or
+          // needed for output, are in the same layer, and not the current picture.
+          if( /* ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
+              && */ ( dpbPic->getLayerId() == pcSlice->getLayerId() )
+              && ( dpbPic->getReconMark() ) 
+            )
+          {
+            for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
+            {
+              TComSlice *slice = dpbPic->getSlice(i);
+              TComReferencePictureSet *rps = slice->getRPS();
+              slice->setPOC( dpbPic->getSlice(i)->getPOC() - pocAdjustValue );
+
+              // Also adjust the POC value stored in the RPS of each such slice
+              for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
+              {
+                rps->setPOC( j, rps->getPOC(j) - pocAdjustValue );
+              }
+              // Also adjust the value of refPOC
+              for(Int k = 0; k < 2; k++)  // For List 0 and List 1
+              {
+                RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
+                for(Int j = 0; j < slice->getNumRefIdx(list); j++)
+                {
+                  slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j);
+                }
+              }
+            }
+          }
+          iterPic++;
+        }
+        m_pcEncTop->setPocAdjustmentValue( m_pcEncTop->getPocAdjustmentValue() + pocAdjustValue );
+      }
+      pcSlice->setPocValueBeforeReset( pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue() + pocAdjustValue );
+      pcSlice->setPOC( 0 );
+    }
+#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
     if (m_pcEncTop->getAdaptiveResolutionChange() > 0 && m_layerId == 1 && pocCurr > m_pcEncTop->getAdaptiveResolutionChange())
@@ -530,4 +661,8 @@
 #endif
 
+#if IL_SL_SIGNALLING_N0371
+    m_pcEncTop->getScalingList()->setLayerId( m_layerId );
+#endif
+
     pcSlice->setLastIDR(m_iLastIDR);
     pcSlice->setSliceIdx(0);
@@ -535,8 +670,11 @@
     pcSlice->setLFCrossSliceBoundaryFlag(  pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()  );
     pcSlice->setScalingList ( m_pcEncTop->getScalingList()  );
-    pcSlice->getScalingList()->setUseTransformSkip(m_pcEncTop->getPPS()->getUseTransformSkip());
     if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF)
     {
+#if IL_SL_SIGNALLING_N0371
+      m_pcEncTop->getTrQuant()->setFlatScalingList( m_layerId );
+#else
       m_pcEncTop->getTrQuant()->setFlatScalingList();
+#endif
       m_pcEncTop->getTrQuant()->setUseScalingList(false);
       m_pcEncTop->getSPS()->setScalingListPresentFlag(false);
@@ -545,5 +683,14 @@
     else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_DEFAULT)
     {
+#if IL_SL_SIGNALLING_N0371
+      pcSlice->getScalingList()->setLayerId( m_layerId );
+#endif
+
+#if IL_SL_SIGNALLING_N0371
+      pcSlice->setDefaultScalingList ( m_layerId );
+#else
       pcSlice->setDefaultScalingList ();
+#endif
+
       m_pcEncTop->getSPS()->setScalingListPresentFlag(false);
       m_pcEncTop->getPPS()->setScalingListPresentFlag(false);
@@ -553,11 +700,41 @@
     else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_FILE_READ)
     {
+#if IL_SL_SIGNALLING_N0371
+      pcSlice->getScalingList()->setLayerId( m_layerId );
+#endif
+
       if(pcSlice->getScalingList()->xParseScalingList(m_pcCfg->getScalingListFile()))
       {
+#if IL_SL_SIGNALLING_N0371
+        pcSlice->setDefaultScalingList ( m_layerId );
+#else
         pcSlice->setDefaultScalingList ();
-      }
+#endif
+      }
+#if IL_SL_SIGNALLING_N0371
+      pcSlice->getScalingList()->checkDcOfMatrix( m_layerId );
+#else
       pcSlice->getScalingList()->checkDcOfMatrix();
+#endif
       m_pcEncTop->getSPS()->setScalingListPresentFlag(pcSlice->checkDefaultScalingList());
+
+#if IL_SL_SIGNALLING_N0371
+      if( m_layerId > 0 )
+      {
+        m_pcEncTop->getSPS()->setPredScalingListFlag  (true); 
+        m_pcEncTop->getSPS()->setScalingListRefLayerId( 0 ); 
+      }
+#endif
+
       m_pcEncTop->getPPS()->setScalingListPresentFlag(false);
+
+#if IL_SL_SIGNALLING_N0371
+      if( m_layerId > 0 )
+      {
+        m_pcEncTop->getPPS()->setPredScalingListFlag  (false); 
+        m_pcEncTop->getPPS()->setScalingListRefLayerId( 0   ); 
+      }
+#endif
+
       m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList());
       m_pcEncTop->getTrQuant()->setUseScalingList(true);
@@ -576,4 +753,8 @@
     pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
 #if SVC_EXTENSION
+#if ILR_RESTR && ILR_RESTR_FIX
+    Int interLayerPredLayerIdcTmp[MAX_VPS_LAYER_ID_PLUS1];
+    Int activeNumILRRefIdxTmp = 0;
+#endif
     if (m_layerId > 0)
     {
@@ -588,5 +769,17 @@
         pcSlice->setBaseColPic( *cListPic, refLayerIdc );
 
-#if SIMPLIFIED_MV_POS_SCALING
+#if ILR_RESTR && ILR_RESTR_FIX
+        // Apply temporal layer restriction to inter-layer prediction
+        Int maxTidIlRefPicsPlus1 = m_pcEncTop->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getLayerId());
+        if( ((Int)(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getRapPicFlag()) )
+        {
+          interLayerPredLayerIdcTmp[activeNumILRRefIdxTmp++] = refLayerIdc; // add picture to the list of valid inter-layer pictures
+        }
+        else
+        {
+          continue; // ILP is not valid due to temporal layer restriction
+        }
+#endif
+
 #if SCALED_REF_LAYER_OFFSETS
         const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow(refLayerIdc);
@@ -612,9 +805,8 @@
         g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
         g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
-#endif
 
 #if SVC_UPSAMPLING
         if( pcPic->isSpatialEnhLayer(refLayerIdc))
-        { 
+        {
 #if SCALED_REF_LAYER_OFFSETS
           m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
@@ -630,39 +822,73 @@
 #endif
       }
-    }
-#endif
-
-#if REF_IDX_FRAMEWORK
-    if( m_layerId > 0 && (pocCurr % m_pcCfg->getIntraPeriod() == 0) )
-    {
+
+#if ILR_RESTR && ILR_RESTR_FIX
+      // Update the list of active inter-layer pictures
+      for ( Int i = 0; i < activeNumILRRefIdxTmp; i++)
+      {
+        pcSlice->setInterLayerPredLayerIdc( interLayerPredLayerIdcTmp[i], i );
+      }
+      pcSlice->setActiveNumILRRefIdx( activeNumILRRefIdxTmp );
+      if ( pcSlice->getActiveNumILRRefIdx() == 0 )
+      {
+        // No valid inter-layer pictures -> disable inter-layer prediction
+        pcSlice->setInterLayerPredEnabledFlag(false);
+      }
+#endif
+      
+      if( pocCurr % m_pcCfg->getIntraPeriod() == 0 )
+      {
+#if N0147_IRAP_ALIGN_FLAG
+        if(pcSlice->getVPS()->getCrossLayerIrapAlignFlag())
+        {
+          TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic();
+          TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
+          if(picLayer0)
+          {
+            pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType());
+          }
+          else
+          {
+            pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
+          }
+        }
+        else
+#endif 
+        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
+
 #if IDR_ALIGNMENT
-      TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic();
-      TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
-      if( picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
-      {
-        pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType());
-      }
-      else
-#endif
-      pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
-    }
-
-    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
-    {
-      pcSlice->setSliceType(I_SLICE);
-    }
-    else if( m_layerId > 0 && !m_pcEncTop->getElRapSliceTypeB() )
-    {
-      if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
-          (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) &&
+        TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic();
+        TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
+        if( picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
+        {
+          pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType());
+        }
+        else
+        {
+          pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
+        }
+#endif 
+      }
+      
+      if( pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
+      {
+        pcSlice->setSliceType(I_SLICE);
+      }
+      else if( !m_pcEncTop->getElRapSliceTypeB() )
+      {
+        if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
+           (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) &&
            pcSlice->getSliceType() == B_SLICE )
-      {
-        pcSlice->setSliceType(P_SLICE);
-      }
-    }
-#endif
+        {
+          pcSlice->setSliceType(P_SLICE);
+        }
+      }
+    }
+#endif //#if SVC_EXTENSION
     if(pcSlice->getTemporalLayerNonReferenceFlag())
     {
-      if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
+      if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_R &&
+          !(m_iGopSize == 1 && pcSlice->getSliceType() == I_SLICE))
+        // Add this condition to avoid POC issues with encoder_intra_main.cfg configuration (see #1127 in bug tracker)
       {
         pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N);
@@ -700,4 +926,61 @@
       if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic) || pcSlice->getSPS()->getTemporalIdNestingFlag())
       {
+#if ALIGN_TSA_STSA_PICS
+        if( pcSlice->getLayerId() > 0 )
+        {
+          Bool oneRefLayerTSA = false, oneRefLayerNotTSA = false;
+          for( Int i = 0; i < pcSlice->getLayerId(); i++)
+          {
+            TComList<TComPic *> *cListPic = m_ppcTEncTop[i]->getListPic();
+            TComPic *lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC());
+            if( lowerLayerPic && pcSlice->getVPS()->getDirectDependencyFlag(pcSlice->getLayerId(), i) )
+            {
+              if( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ) ||
+                  ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R ) 
+                )
+              {
+                if(pcSlice->getTemporalLayerNonReferenceFlag() )
+                {
+                  pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_N);
+                }
+                else
+                {
+                  pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R );
+                }
+                oneRefLayerTSA = true;
+              }
+              else
+              {
+                oneRefLayerNotTSA = true;
+              }
+            }
+          }
+          assert( !( oneRefLayerNotTSA && oneRefLayerTSA ) ); // Only one variable should be true - failure of this assert means
+                                                                // that two independent reference layers that are not dependent on
+                                                                // each other, but are reference for current layer have inconsistency
+          if( oneRefLayerNotTSA /*&& !oneRefLayerTSA*/ )          // No reference layer is TSA - set current as TRAIL
+          {
+            if(pcSlice->getTemporalLayerNonReferenceFlag() )
+            {
+              pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_N );
+            }
+            else
+            {
+              pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_R );
+            }
+          }
+          else  // This means there is no reference layer picture for current picture in this AU
+          {
+            if(pcSlice->getTemporalLayerNonReferenceFlag() )
+            {
+              pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_N);
+            }
+            else
+            {
+              pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R );
+            }
+          }
+        }
+#else
         if(pcSlice->getTemporalLayerNonReferenceFlag())
         {
@@ -708,4 +991,5 @@
           pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R);
         }
+#endif
       }
       else if(pcSlice->isStepwiseTemporalLayerSwitchingPointCandidate(rcListPic))
@@ -741,4 +1025,61 @@
         if(isSTSA==true)
         {    
+#if ALIGN_TSA_STSA_PICS
+          if( pcSlice->getLayerId() > 0 )
+          {
+            Bool oneRefLayerSTSA = false, oneRefLayerNotSTSA = false;
+            for( Int i = 0; i < pcSlice->getLayerId(); i++)
+            {
+              TComList<TComPic *> *cListPic = m_ppcTEncTop[i]->getListPic();
+              TComPic *lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC());
+              if( lowerLayerPic && pcSlice->getVPS()->getDirectDependencyFlag(pcSlice->getLayerId(), i) )
+              {
+                if( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ) ||
+                    ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R ) 
+                  )
+                {
+                  if(pcSlice->getTemporalLayerNonReferenceFlag() )
+                  {
+                    pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N);
+                  }
+                  else
+                  {
+                    pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R );
+                  }
+                  oneRefLayerSTSA = true;
+                }
+                else
+                {
+                  oneRefLayerNotSTSA = true;
+                }
+              }
+            }
+            assert( !( oneRefLayerNotSTSA && oneRefLayerSTSA ) ); // Only one variable should be true - failure of this assert means
+                                                                  // that two independent reference layers that are not dependent on
+                                                                  // each other, but are reference for current layer have inconsistency
+            if( oneRefLayerNotSTSA /*&& !oneRefLayerSTSA*/ )          // No reference layer is STSA - set current as TRAIL
+            {
+              if(pcSlice->getTemporalLayerNonReferenceFlag() )
+              {
+                pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_N );
+              }
+              else
+              {
+                pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_R );
+              }
+            }
+            else  // This means there is no reference layer picture for current picture in this AU
+            {
+              if(pcSlice->getTemporalLayerNonReferenceFlag() )
+              {
+                pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N);
+              }
+              else
+              {
+                pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R );
+              }
+            }
+          }
+#else
           if(pcSlice->getTemporalLayerNonReferenceFlag())
           {
@@ -749,4 +1090,5 @@
             pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R);
           }
+#endif
         }
       }
@@ -759,9 +1101,13 @@
     pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
 
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
     if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
     {
 #if RESTR_CHK
-      if (pcSlice->getPOC()>0  && pcSlice->isRADL()&& pcPic->getSlice(0)->isRASL())
+#if POC_RESET_FLAG
+      if ( pocCurr > 0          && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
+#else
+      if (pcSlice->getPOC()>0  && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
+#endif
       {
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
@@ -797,5 +1143,5 @@
 #endif
     }
-#endif
+#endif //SVC_EXTENSION
 
 #if ADAPTIVE_QP_SELECTION
@@ -803,5 +1149,5 @@
 #endif      
 
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
 #if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
     if ( pcSlice->getSliceType() == B_SLICE && !(pcSlice->getActiveNumILRRefIdx() > 0 && m_pcEncTop->getNumMotionPredRefLayers() > 0) )
@@ -812,20 +1158,14 @@
       pcSlice->setColFromL0Flag(1-uiColDir);
     }
-#endif
 
     //  Set reference list
-#if REF_IDX_FRAMEWORK
     if(m_layerId ==  0 || ( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() == 0 ) )
     {
       pcSlice->setRefPicList( rcListPic);
     }
-#else
-    pcSlice->setRefPicList ( rcListPic );
-#endif
-#if REF_IDX_FRAMEWORK
+
     if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
     {
       m_pcEncTop->setILRPic(pcPic);
-
 #if REF_IDX_MFM
 #if M0457_COL_PICTURE_SIGNALING
@@ -840,5 +1180,8 @@
 #endif
       }
-#endif
+#else
+      //  Set reference list
+      pcSlice->setRefPicList ( rcListPic );
+#endif //SVC_EXTENSION
       pcSlice->setRefPicListModificationSvc();
       pcSlice->setRefPicList( rcListPic, false, m_pcEncTop->getIlpList());
@@ -890,5 +1233,8 @@
 #endif
     }
-#endif
+#else //SVC_EXTENSION
+    //  Set reference list
+    pcSlice->setRefPicList ( rcListPic );
+#endif //#if SVC_EXTENSION
 
     //  Slice info. refinement
@@ -904,5 +1250,5 @@
 #endif
     {
-#if !REF_IDX_FRAMEWORK
+#if !SVC_EXTENSION
       pcSlice->setColFromL0Flag(1-uiColDir);
 #endif
@@ -1021,5 +1367,9 @@
 
       Int sliceQP = m_pcCfg->getInitialQP();
+#if POC_RESET_FLAG
+      if ( ( pocCurr == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified
+#else
       if ( ( pcSlice->getPOC() == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified
+#endif
       {
         Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
@@ -1071,5 +1421,9 @@
       }
 
+#if REPN_FORMAT_IN_VPS
+      sliceQP = Clip3( -pcSlice->getQpBDOffsetY(), MAX_QP, sliceQP );
+#else
       sliceQP = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, sliceQP );
+#endif
       m_pcRateCtrl->getRCPic()->setPicEstQP( sliceQP );
 
@@ -1084,6 +1438,11 @@
     UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
     UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
+#if REPN_FORMAT_IN_VPS
+    UInt uiWidth = pcSlice->getPicWidthInLumaSamples();
+    UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
+#else
     UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
     UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
+#endif
     while(uiPosX>=uiWidth||uiPosY>=uiHeight) 
     {
@@ -1164,4 +1523,11 @@
     //intialize each tile of the current picture
     pcPic->getPicSym()->xInitTiles();
+
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+    if (m_pcCfg->getInterLayerConstrainedTileSetsSEIEnabled())
+    {
+      xBuildTileSetsMap(pcPic->getPicSym());
+    }
+#endif
 
     // Allocate some coders, now we know how many tiles there are.
@@ -1310,5 +1676,9 @@
     {
 #if SVC_EXTENSION
+#if VPS_NUH_LAYER_ID
+      OutputNALUnit nalu(NAL_UNIT_VPS, 0, 0        ); // The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
+#else
       OutputNALUnit nalu(NAL_UNIT_VPS, 0, m_layerId);
+#endif
 #if AVC_BASE
       if( ( m_layerId == 1 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) || ( m_layerId == 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) )
@@ -1333,4 +1703,7 @@
 #if SVC_EXTENSION
       nalu = NALUnit(NAL_UNIT_SPS, 0, m_layerId);
+#if IL_SL_SIGNALLING_N0371
+      pcSlice->getSPS()->setVPS( pcSlice->getVPS() );
+#endif
 #else
       nalu = NALUnit(NAL_UNIT_SPS);
@@ -1452,6 +1825,10 @@
         }
       }
-      pictureTimingSEI.m_auCpbRemovalDelay = std::max<Int>(1, m_totalCoded - m_lastBPSEI); // Syntax element signalled as minus, hence the .
+      pictureTimingSEI.m_auCpbRemovalDelay = std::min<Int>(std::max<Int>(1, m_totalCoded - m_lastBPSEI), static_cast<Int>(pow(2, static_cast<double>(pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getCpbRemovalDelayLengthMinus1()+1)))); // Syntax element signalled as minus, hence the .
+#if POC_RESET_FLAG
+      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pocCurr - m_totalCoded;
+#else
       pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded;
+#endif
       Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2;
       pictureTimingSEI.m_picDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay;
@@ -1558,5 +1935,9 @@
       SEIRecoveryPoint sei_recovery_point;
       sei_recovery_point.m_recoveryPocCnt    = 0;
+#if POC_RESET_FLAG
+      sei_recovery_point.m_exactMatchingFlag = ( pocCurr == 0 ) ? (true) : (false);
+#else
       sei_recovery_point.m_exactMatchingFlag = ( pcSlice->getPOC() == 0 ) ? (true) : (false);
+#endif
       sei_recovery_point.m_brokenLinkFlag    = false;
 
@@ -1619,5 +2000,5 @@
             startCUAddrSliceSegmentIdx++;
           }
-#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
+#if SVC_EXTENSION && M0457_COL_PICTURE_SIGNALING
           pcSlice->setNumMotionPredRefLayers(m_pcEncTop->getNumMotionPredRefLayers());
 #endif
@@ -1632,6 +2013,12 @@
           uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
           uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
+
+#if REPN_FORMAT_IN_VPS
+          uiWidth = pcSlice->getPicWidthInLumaSamples();
+          uiHeight = pcSlice->getPicHeightInLumaSamples();
+#else
           uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
           uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
+#endif
           while(uiPosX>=uiWidth||uiPosY>=uiHeight)
           {
@@ -1688,5 +2075,7 @@
           tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits();
 #endif
+
           m_pcEntropyCoder->encodeSliceHeader(pcSlice);
+
 #if RATE_CONTROL_LAMBDA_DOMAIN
           actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting );
@@ -1975,4 +2364,18 @@
       xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime );
 
+      //In case of field coding, compute the interlaced PSNR for both fields
+      if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)))
+      {
+        //get complementary top field
+        TComPic* pcPicTop;
+        TComList<TComPic*>::iterator   iterPic = rcListPic.begin();
+        while ((*iterPic)->getPOC() != pcPic->getPOC()-1)
+        {
+          iterPic ++;
+        }
+        pcPicTop = *(iterPic);
+        xCalculateInterlacedAddPSNR(pcPicTop, pcPic, pcPicTop->getPicYuvRec(), pcPic->getPicYuvRec(), accessUnit, dEncTime );
+      }
+
       if (digestStr)
       {
@@ -2107,4 +2510,5 @@
             OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
           m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
+          pictureTimingSEI.m_picStruct = (isField && pcSlice->getPic()->isTopField())? 1 : isField? 2 : 0;
           m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS());
           writeRBSPTrailingBits(nalu.m_Bitstream);
@@ -2225,12 +2629,12 @@
 
 #if SVC_EXTENSION
-  assert ( m_iNumPicCoded <= 1 );
-#else
-  assert ( m_iNumPicCoded == iNumPicRcvd );
+  assert ( m_iNumPicCoded <= 1 || (isField && iPOCLast == 1) );
+#else
+  assert ( (m_iNumPicCoded == iNumPicRcvd) || (isField && iPOCLast == 1) );
 #endif
 }
 
 #if !SVC_EXTENSION
-Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded)
+Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded, Bool isField)
 {
   assert (uiNumAllPicCoded == m_gcAnalyzeAll.getNumPic());
@@ -2238,8 +2642,18 @@
     
   //--CFG_KDY
-  m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() );
-  m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() );
-  m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() );
-  m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() );
+  if(isField)
+  {
+    m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() * 2);
+    m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() * 2);
+    m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() * 2);
+    m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() * 2);
+  }
+   else
+  {
+    m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() );
+    m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() );
+    m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() );
+    m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() );
+  }
   
   //-- all
@@ -2264,4 +2678,16 @@
   m_gcAnalyzeB.printSummary('B');
 #endif
+
+  if(isField)
+  {
+    //-- interlaced summary
+    m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate());
+    printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" );
+    m_gcAnalyzeAll_in.printOutInterlaced('a',  m_gcAnalyzeAll.getBits());
+    
+#if _SUMMARY_OUT_
+    m_gcAnalyzeAll_in.printSummaryOutInterlaced();
+#endif
+  }
 
   printf("\nRVM: %.3lf\n" , xCalculateRVM());
@@ -2305,4 +2731,22 @@
 // ====================================================================================================================
 
+
+Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Bool isField )
+{
+  assert( iNumPicRcvd > 0 );
+  //  Exception for the first frames
+  if ( ( isField && (iPOCLast == 0 || iPOCLast == 1) ) || (!isField  && (iPOCLast == 0))  )
+  {
+    m_iGopSize    = 1;
+  }
+  else
+  {
+    m_iGopSize    = m_pcCfg->getGOPSize();
+  }
+  assert (m_iGopSize > 0);
+  
+  return;
+}
+
 Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut )
 {
@@ -2327,14 +2771,33 @@
                          TComPic*&                 rpcPic,
                          TComPicYuv*&              rpcPicYuvRecOut,
-                         Int                       pocCurr )
+                         Int                       pocCurr,
+                         Bool                      isField)
 {
   Int i;
   //  Rec. output
   TComList<TComPicYuv*>::iterator     iterPicYuvRec = rcListPicYuvRecOut.end();
-  for ( i = 0; i < iNumPicRcvd - iTimeOffset + 1; i++ )
-  {
-    iterPicYuvRec--;
-  }
-  
+
+  if (isField)
+  {
+    for ( i = 0; i < ( (pocCurr == 0 ) || (pocCurr == 1 ) ? (iNumPicRcvd - iTimeOffset + 1) : (iNumPicRcvd - iTimeOffset + 2) ); i++ )
+    {
+      iterPicYuvRec--;
+    }
+  }
+  else
+  {
+    for ( i = 0; i < (iNumPicRcvd - iTimeOffset + 1); i++ )
+    {
+      iterPicYuvRec--;
+    }
+  }
+  
+  if (isField)
+  {
+    if(pocCurr == 1)
+    {
+      iterPicYuvRec++;
+    }
+  }
   rpcPicYuvRecOut = *(iterPicYuvRec);
   
@@ -2421,28 +2884,28 @@
   switch (type)
   {
-    case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R";
-    case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N";
+    case NAL_UNIT_CODED_SLICE_TRAIL_R:    return "TRAIL_R";
+    case NAL_UNIT_CODED_SLICE_TRAIL_N:    return "TRAIL_N";
     case NAL_UNIT_CODED_SLICE_TLA_R:      return "TLA_R";
-    case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N";
-    case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R";
-    case NAL_UNIT_CODED_SLICE_STSA_N: return "STSA_N";
+    case NAL_UNIT_CODED_SLICE_TSA_N:      return "TSA_N";
+    case NAL_UNIT_CODED_SLICE_STSA_R:     return "STSA_R";
+    case NAL_UNIT_CODED_SLICE_STSA_N:     return "STSA_N";
     case NAL_UNIT_CODED_SLICE_BLA_W_LP:   return "BLA_W_LP";
     case NAL_UNIT_CODED_SLICE_BLA_W_RADL: return "BLA_W_RADL";
-    case NAL_UNIT_CODED_SLICE_BLA_N_LP: return "BLA_N_LP";
+    case NAL_UNIT_CODED_SLICE_BLA_N_LP:   return "BLA_N_LP";
     case NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL";
-    case NAL_UNIT_CODED_SLICE_IDR_N_LP: return "IDR_N_LP";
-    case NAL_UNIT_CODED_SLICE_CRA: return "CRA";
+    case NAL_UNIT_CODED_SLICE_IDR_N_LP:   return "IDR_N_LP";
+    case NAL_UNIT_CODED_SLICE_CRA:        return "CRA";
     case NAL_UNIT_CODED_SLICE_RADL_R:     return "RADL_R";
     case NAL_UNIT_CODED_SLICE_RASL_R:     return "RASL_R";
-    case NAL_UNIT_VPS: return "VPS";
-    case NAL_UNIT_SPS: return "SPS";
-    case NAL_UNIT_PPS: return "PPS";
-    case NAL_UNIT_ACCESS_UNIT_DELIMITER: return "AUD";
-    case NAL_UNIT_EOS: return "EOS";
-    case NAL_UNIT_EOB: return "EOB";
-    case NAL_UNIT_FILLER_DATA: return "FILLER";
+    case NAL_UNIT_VPS:                    return "VPS";
+    case NAL_UNIT_SPS:                    return "SPS";
+    case NAL_UNIT_PPS:                    return "PPS";
+    case NAL_UNIT_ACCESS_UNIT_DELIMITER:  return "AUD";
+    case NAL_UNIT_EOS:                    return "EOS";
+    case NAL_UNIT_EOB:                    return "EOB";
+    case NAL_UNIT_FILLER_DATA:            return "FILLER";
     case NAL_UNIT_PREFIX_SEI:             return "SEI";
     case NAL_UNIT_SUFFIX_SEI:             return "SEI";
-    default: return "UNK";
+    default:                              return "UNK";
   }
 }
@@ -2625,15 +3088,186 @@
     for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
     {
-#if REF_IDX_FRAMEWORK && VPS_EXTN_DIRECT_REF_LAYERS
+#if SVC_EXTENSION
+#if VPS_EXTN_DIRECT_REF_LAYERS
       if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR(m_layerId) )
       {
-        printf( "%d(%d) ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR(), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
+        printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR(), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
       }
       else
-#endif
+      {
+        printf ("%d", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR());
+      }
+#endif
+      if( pcSlice->getEnableTMVPFlag() && iRefList == 1 - pcSlice->getColFromL0Flag() && iRefIndex == pcSlice->getColRefIdx() )
+      {
+        printf( "c" );
+      }
+
+      printf( " " );
+#else
       printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR());
+#endif
     }
     printf("]");
   }
+}
+
+
+Void reinterlace(Pel* top, Pel* bottom, Pel* dst, UInt stride, UInt width, UInt height, Bool isTff)
+{
+  
+  for (Int y = 0; y < height; y++)
+  {
+    for (Int x = 0; x < width; x++)
+    {
+      dst[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
+      dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
+    }
+    top += stride;
+    bottom += stride;
+    dst += stride*2;
+  }
+}
+
+Void TEncGOP::xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime )
+{
+  Int     x, y;
+  
+  UInt64 uiSSDY_in  = 0;
+  UInt64 uiSSDU_in  = 0;
+  UInt64 uiSSDV_in  = 0;
+  
+  Double  dYPSNR_in  = 0.0;
+  Double  dUPSNR_in  = 0.0;
+  Double  dVPSNR_in  = 0.0;
+  
+  /*------ INTERLACED PSNR -----------*/
+  
+  /* Luma */
+  
+  Pel*  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getLumaAddr();
+  Pel*  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getLumaAddr();
+  Pel*  pRecTop = pcPicRecTop->getLumaAddr();
+  Pel*  pRecBottom = pcPicRecBottom->getLumaAddr();
+  
+  Int   iWidth;
+  Int   iHeight;
+  Int iStride;
+  
+  iWidth  = pcPicOrgTop->getPicYuvOrg()->getWidth () - m_pcEncTop->getPad(0);
+  iHeight = pcPicOrgTop->getPicYuvOrg()->getHeight() - m_pcEncTop->getPad(1);
+  iStride = pcPicOrgTop->getPicYuvOrg()->getStride();
+  Int   iSize   = iWidth*iHeight;
+  bool isTff = pcPicOrgTop->isTopField();
+  
+  TComPicYuv* pcOrgInterlaced = new TComPicYuv;
+  pcOrgInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+  
+  TComPicYuv* pcRecInterlaced = new TComPicYuv;
+  pcRecInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+  
+  Pel* pOrgInterlaced = pcOrgInterlaced->getLumaAddr();
+  Pel* pRecInterlaced = pcRecInterlaced->getLumaAddr();
+  
+  //=== Interlace fields ====
+  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
+  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
+  
+  //===== calculate PSNR =====
+  for( y = 0; y < iHeight << 1; y++ )
+  {
+    for( x = 0; x < iWidth; x++ )
+    {
+      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
+      uiSSDY_in   += iDiff * iDiff;
+    }
+    pOrgInterlaced += iStride;
+    pRecInterlaced += iStride;
+  }
+  
+  /*Chroma*/
+  
+  iHeight >>= 1;
+  iWidth  >>= 1;
+  iStride >>= 1;
+  
+  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCbAddr();
+  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCbAddr();
+  pRecTop = pcPicRecTop->getCbAddr();
+  pRecBottom = pcPicRecBottom->getCbAddr();
+  pOrgInterlaced = pcOrgInterlaced->getCbAddr();
+  pRecInterlaced = pcRecInterlaced->getCbAddr();
+  
+  //=== Interlace fields ====
+  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
+  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
+  
+  //===== calculate PSNR =====
+  for( y = 0; y < iHeight << 1; y++ )
+  {
+    for( x = 0; x < iWidth; x++ )
+    {
+      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
+      uiSSDU_in   += iDiff * iDiff;
+    }
+    pOrgInterlaced += iStride;
+    pRecInterlaced += iStride;
+  }
+  
+  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCrAddr();
+  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCrAddr();
+  pRecTop = pcPicRecTop->getCrAddr();
+  pRecBottom = pcPicRecBottom->getCrAddr();
+  pOrgInterlaced = pcOrgInterlaced->getCrAddr();
+  pRecInterlaced = pcRecInterlaced->getCrAddr();
+  
+  //=== Interlace fields ====
+  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
+  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
+  
+  //===== calculate PSNR =====
+  for( y = 0; y < iHeight << 1; y++ )
+  {
+    for( x = 0; x < iWidth; x++ )
+    {
+      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
+      uiSSDV_in   += iDiff * iDiff;
+    }
+    pOrgInterlaced += iStride;
+    pRecInterlaced += iStride;
+  }
+  
+  Int maxvalY = 255 << (g_bitDepthY-8);
+  Int maxvalC = 255 << (g_bitDepthC-8);
+  Double fRefValueY = (Double) maxvalY * maxvalY * iSize*2;
+  Double fRefValueC = (Double) maxvalC * maxvalC * iSize*2 / 4.0;
+  dYPSNR_in            = ( uiSSDY_in ? 10.0 * log10( fRefValueY / (Double)uiSSDY_in ) : 99.99 );
+  dUPSNR_in            = ( uiSSDU_in ? 10.0 * log10( fRefValueC / (Double)uiSSDU_in ) : 99.99 );
+  dVPSNR_in            = ( uiSSDV_in ? 10.0 * log10( fRefValueC / (Double)uiSSDV_in ) : 99.99 );
+  
+  /* calculate the size of the access unit, excluding:
+   *  - any AnnexB contributions (start_code_prefix, zero_byte, etc.,)
+   *  - SEI NAL units
+   */
+  UInt numRBSPBytes = 0;
+  for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++)
+  {
+    UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size());
+    
+    if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
+      numRBSPBytes += numRBSPBytes_nal;
+  }
+  
+  UInt uibits = numRBSPBytes * 8 ;
+  
+  //===== add PSNR =====
+  m_gcAnalyzeAll_in.addResult (dYPSNR_in, dUPSNR_in, dVPSNR_in, (Double)uibits);
+  
+  printf("\n                                      Interlaced frame %d: [Y %6.4lf dB    U %6.4lf dB    V %6.4lf dB]", pcPicOrgBottom->getPOC()/2 , dYPSNR_in, dUPSNR_in, dVPSNR_in );
+  
+  pcOrgInterlaced->destroy();
+  delete pcOrgInterlaced;
+  pcRecInterlaced->destroy();
+  delete pcRecInterlaced;
 }
 
@@ -2872,4 +3506,46 @@
   return seiStartPos;
 }
+
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+Void TEncGOP::xBuildTileSetsMap(TComPicSym* picSym)
+{
+  Int numCUs = picSym->getFrameWidthInCU() * picSym->getFrameHeightInCU();
+
+  for (Int i = 0; i < numCUs; i++)
+  {
+    picSym->setTileSetIdxMap(i, -1, 0, false);
+  }
+
+  for (Int i = 0; i < m_pcCfg->getIlNumSetsInMessage(); i++)
+  {
+    TComTile* topLeftTile     = picSym->getTComTile(m_pcCfg->getTopLeftTileIndex(i));
+    TComTile* bottomRightTile = picSym->getTComTile(m_pcCfg->getBottomRightTileIndex(i));
+    Int tileSetLeftEdgePosInCU = topLeftTile->getRightEdgePosInCU() - topLeftTile->getTileWidth() + 1;
+    Int tileSetRightEdgePosInCU = bottomRightTile->getRightEdgePosInCU();
+    Int tileSetTopEdgePosInCU = topLeftTile->getBottomEdgePosInCU() - topLeftTile->getTileHeight() + 1;
+    Int tileSetBottomEdgePosInCU = bottomRightTile->getBottomEdgePosInCU();
+    assert(tileSetLeftEdgePosInCU < tileSetRightEdgePosInCU && tileSetTopEdgePosInCU < tileSetBottomEdgePosInCU);
+    for (Int j = tileSetTopEdgePosInCU; j <= tileSetBottomEdgePosInCU; j++)
+    {
+      for (Int k = tileSetLeftEdgePosInCU; k <= tileSetRightEdgePosInCU; k++)
+      {
+        picSym->setTileSetIdxMap(j * picSym->getFrameWidthInCU() + k, i, m_pcCfg->getIlcIdc(i), false);
+      }
+    }
+  }
+  
+  if (m_pcCfg->getSkippedTileSetPresentFlag())
+  {
+    Int skippedTileSetIdx = m_pcCfg->getIlNumSetsInMessage();
+    for (Int i = 0; i < numCUs; i++)
+    {
+      if (picSym->getTileSetIdxMap(i) < 0)
+      {
+        picSym->setTileSetIdxMap(i, skippedTileSetIdx, 0, true);
+      }
+    }
+  }
+}
+#endif
 
 Void TEncGOP::dblMetric( TComPic* pcPic, UInt uiNumSlices )
Index: /trunk/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 442)
@@ -145,7 +145,7 @@
   Void  init        ( TEncTop* pcTEncTop );
 #if SVC_EXTENSION
-  Void  compressGOP ( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP );
+  Void  compressGOP ( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff );
 #else
-  Void  compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP );
+  Void  compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff );
 #endif
   Void  xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect);
@@ -156,5 +156,7 @@
   TComList<TComPic*>*   getListPic()      { return m_pcListPic; }
   
-  Void  printOutSummary      ( UInt uiNumAllPicCoded );
+#if !SVC_EXTENSION
+  Void  printOutSummary      ( UInt uiNumAllPicCoded, Bool isField);
+#endif
   Void  preLoopFilterPicAll  ( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits );
   
@@ -166,8 +168,11 @@
 
 protected:
+  
+  Void xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Bool isField );
   Void  xInitGOP          ( Int iPOC, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut );
-  Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr );
+  Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField );
   
   Void  xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime );
+  Void  xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime );
   
   UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1);
@@ -183,4 +188,8 @@
 
   SEIToneMappingInfo*     xCreateSEIToneMappingInfo();
+
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  SEIInterLayerConstrainedTileSets* xCreateSEIInterLayerConstrainedTileSets();
+#endif
 
   Void xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps);
@@ -197,4 +206,7 @@
     m_nestedPictureTimingSEIPresentInAU      = false;
   }
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Void xBuildTileSetsMap(TComPicSym* picSym);
+#endif
   Void dblMetric( TComPic* pcPic, UInt uiNumSlices );
 #if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
Index: /trunk/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 442)
@@ -804,5 +804,9 @@
   Int iDQp  = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx );
   
+#if REPN_FORMAT_IN_VPS
+  Int qpBdOffsetY =  pcCU->getSlice()->getQpBDOffsetY();
+#else
   Int qpBdOffsetY =  pcCU->getSlice()->getSPS()->getQpBDOffsetY();
+#endif
   iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2);
 
Index: /trunk/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 442)
@@ -1104,5 +1104,9 @@
   pcCU       ->setTrIdxSubParts ( uiTrDepth, uiAbsPartIdx, uiFullDepth );
 
+#if REPN_FORMAT_IN_VPS
+  m_pcTrQuant->setQPforQuant    ( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
+#else
   m_pcTrQuant->setQPforQuant    ( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
 #if RDOQ_CHROMA_LAMBDA 
@@ -3217,4 +3221,38 @@
   Int numValidMergeCand = 0 ;
 
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Bool disableILP = false;
+  if (pcCU->getPic()->getLayerId() == (m_pcEncCfg->getNumLayer() - 1)  && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && pcCU->getPic()->getPicSym()->getTileSetIdxMap(pcCU->getAddr()) >= 0)
+  {
+    if (pcCU->getPic()->getPicSym()->getTileSetType(pcCU->getAddr()) == 2)
+    {
+      disableILP = true;
+    }
+    if (pcCU->getPic()->getPicSym()->getTileSetType(pcCU->getAddr()) == 1)
+    {
+      Int currCUaddr = pcCU->getAddr();
+      Int frameWitdhInCU  = pcCU->getPic()->getPicSym()->getFrameWidthInCU();
+      Int frameHeightInCU = pcCU->getPic()->getPicSym()->getFrameHeightInCU();
+      Bool leftCUExists   = (currCUaddr % frameWitdhInCU) > 0;
+      Bool aboveCUExists  = (currCUaddr / frameWitdhInCU) > 0;
+      Bool rightCUExists  = (currCUaddr % frameWitdhInCU) < (frameWitdhInCU - 1);
+      Bool belowCUExists  = (currCUaddr / frameWitdhInCU) < (frameHeightInCU - 1);
+      Int currTileSetIdx  = pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr);
+      // Check if CU is at tile set boundary
+      if ( (leftCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-1) != currTileSetIdx) ||
+           (leftCUExists && aboveCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-frameWitdhInCU-1) != currTileSetIdx) ||
+           (aboveCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-frameWitdhInCU) != currTileSetIdx) ||
+           (aboveCUExists && rightCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-frameWitdhInCU+1) != currTileSetIdx) ||
+           (rightCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+1) != currTileSetIdx) ||
+           (rightCUExists && belowCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+frameWitdhInCU+1) != currTileSetIdx) ||
+           (belowCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+frameWitdhInCU) != currTileSetIdx) ||
+           (belowCUExists && leftCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+frameWitdhInCU-1) != currTileSetIdx) )
+      {
+        disableILP = true;  // Disable ILP in tile set boundary CU
+      }
+    }
+  }
+#endif
+
   for ( Int iPartIdx = 0; iPartIdx < iNumPart; iPartIdx++ )
   {
@@ -3266,4 +3304,10 @@
       for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ )
       {
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+        if (pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp )->isILR(pcCU->getLayerId()) && disableILP)
+        {
+          continue;
+        }
+#endif
 #if (ENCODER_FAST_MODE)
         TComPic* pcPic    = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp );
@@ -3484,4 +3528,10 @@
           testIter = false;  //the fixed part is ILR, skip this iteration       
         }
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+        if (pcPic->isILR(pcCU->getLayerId()) && disableILP)
+        {
+          testIter = false;
+        }
+#endif
         if(testIter)
         {
@@ -3499,4 +3549,10 @@
             testRefIdx = false;  //the refined part is ILR, skip this reference pic           
           }
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+          if (pcPic->isILR(pcCU->getLayerId()) && disableILP)
+          {
+            testRefIdx = false;
+          }
+#endif
           if(testRefIdx)
           {
@@ -4610,6 +4666,11 @@
   while((uiWidth>>uiMaxTrMode) < (g_uiMaxCUWidth>>g_uiMaxCUDepth)) uiMaxTrMode--;
   
+#if REPN_FORMAT_IN_VPS
+  qpMin =  bHighPass ? Clip3( -pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) - m_iMaxDeltaQP ) : pcCU->getQP( 0 );
+  qpMax =  bHighPass ? Clip3( -pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) + m_iMaxDeltaQP ) : pcCU->getQP( 0 );
+#else
   qpMin =  bHighPass ? Clip3( -pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) - m_iMaxDeltaQP ) : pcCU->getQP( 0 );
   qpMax =  bHighPass ? Clip3( -pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) + m_iMaxDeltaQP ) : pcCU->getQP( 0 );
+#endif
 
   rpcYuvResi->subtract( pcYuvOrg, pcYuvPred, 0, uiWidth );
@@ -4860,5 +4921,9 @@
     }
 
+#if REPN_FORMAT_IN_VPS
+    m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
+#else
     m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
 #if RDOQ_CHROMA_LAMBDA 
@@ -4946,5 +5011,9 @@
       Pel *pcResiCurrY = m_pcQTTempTComYuv[ uiQTTempAccessLayer ].getLumaAddr( absTUPartIdx );
 
+#if REPN_FORMAT_IN_VPS
       m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#else
+      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
       Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA];
@@ -5195,5 +5264,9 @@
       }
 
+#if REPN_FORMAT_IN_VPS
+      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
+#else
       m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
 #if RDOQ_CHROMA_LAMBDA 
@@ -5214,5 +5287,9 @@
         const UInt uiTsSingleBitsY = m_pcEntropyCoder->getNumberOfWrittenBits();
 
+#if REPN_FORMAT_IN_VPS
+        m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
+#else
         m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
         Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA];
Index: /trunk/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 442)
@@ -180,7 +180,7 @@
 #if SVC_EXTENSION
 //\param vps          VPS associated with the slice
-Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, TComVPS *vps )
-#else
-Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
+Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, TComVPS *vps, Bool isField )
+#else
+Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, Bool isField )
 #endif
 {
@@ -260,5 +260,9 @@
   if(eSliceType!=I_SLICE)
   {
+#if REPN_FORMAT_IN_VPS
+    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless()))) 
+#else
     if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless()))) 
+#endif
     {
       dQP += m_pcCfg->getGOPEntry(iGOPid).m_QPOffset;
@@ -294,5 +298,7 @@
     Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
     Int    SHIFT_QP = 12;
-    Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
+
+    Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)(isField ? NumberBFrames/2 : NumberBFrames) );
+
 #if FULL_NBIT
     Int    bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);
@@ -327,5 +333,9 @@
     }
     
+#if REPN_FORMAT_IN_VPS
+    iQP = max( -rpcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
+#else
     iQP = max( -pSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
+#endif
 
     m_pdRdPicLambda[iDQpIdx] = dLambda;
@@ -400,5 +410,5 @@
   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
   
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   if(m_pcCfg->getLayerId() > 0)
   {
@@ -412,5 +422,9 @@
   {
     dQP = xGetQPValueAccordingToLambda( dLambda );
+#if REPN_FORMAT_IN_VPS
+    iQP = max( -rpcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );    
+#else
     iQP = max( -pSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );    
+#endif
   }
 
@@ -467,5 +481,9 @@
   
   pcPic->setTLayer( m_pcCfg->getGOPEntry(iGOPid).m_temporalId );
+#if TEMP_SCALABILITY_FIX
+  if((eSliceType==I_SLICE) || (rpcSlice->getPOC() == 0))
+#else
   if(eSliceType==I_SLICE)
+#endif
   {
     pcPic->setTLayer(0);
@@ -485,5 +503,5 @@
   xStoreWPparam( pPPS->getUseWP(), pPPS->getWPBiPred() );
 
-#if SVC_EXTENSION && REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   if( layerId > 0 )
   {
@@ -606,5 +624,9 @@
     }
 
+#if REPN_FORMAT_IN_VPS
+    qp = max( -pcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );
+#else
     qp = max( -pcSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );
+#endif
 
     m_pdRdPicLambda[deltqQpIdx] = lambda;
@@ -849,6 +871,11 @@
     pcCU->initCU( rpcPic, uiCUAddr );
 
+#if REPN_FORMAT_IN_VPS
+    Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
+    Int width   = min( pcSlice->getSPS()->getMaxCUWidth(), pcSlice->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+#else
     Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
     Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+#endif
 
     iSumHad = m_pcCuEncoder->updateLCUDataISlice(pcCU, uiCUAddr, width, height);
@@ -1148,5 +1175,9 @@
 #endif
 
+#if REPN_FORMAT_IN_VPS
+          estQP     = Clip3( -pcSlice->getQpBDOffsetY(), MAX_QP, estQP );
+#else
           estQP     = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, estQP );
+#endif
 
           m_pcRdCost->setLambda(estLambda);
@@ -1176,6 +1207,11 @@
 #if !M0036_RC_IMPROVEMENT
         UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
+#if REPN_FORMAT_IN_VPS
+        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
+        Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->>getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+#else
         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+#endif
         Double MAD = (Double)SAD / (Double)(height * width);
         MAD = MAD * MAD;
@@ -1253,6 +1289,11 @@
 #if !M0036_RC_IMPROVEMENT
         UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
+#if REPN_FORMAT_IN_VPS
+        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
+        Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+#else
         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+#endif
         Double MAD = (Double)SAD / (Double)(height * width);
         MAD = MAD * MAD;
@@ -1919,6 +1960,11 @@
   UInt uiPosX = ( uiExternalAddress % rpcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
   UInt uiPosY = ( uiExternalAddress / rpcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
+#if REPN_FORMAT_IN_VPS
+  UInt uiWidth = pcSlice->getPicWidthInLumaSamples();
+  UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
+#else
   UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
   UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
+#endif
   while((uiPosX>=uiWidth||uiPosY>=uiHeight)&&!(uiPosX>=uiWidth&&uiPosY>=uiHeight))
   {
@@ -1942,6 +1988,11 @@
   uiPosX = ( uiExternalAddress % rpcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
   uiPosY = ( uiExternalAddress / rpcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
+#if REPN_FORMAT_IN_VPS
+  uiWidth = pcSlice->getPicWidthInLumaSamples();
+  uiHeight = pcSlice->getPicHeightInLumaSamples();
+#else
   uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
   uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
+#endif
   while((uiPosX>=uiWidth||uiPosY>=uiHeight)&&!(uiPosX>=uiWidth&&uiPosY>=uiHeight))
   {
Index: /trunk/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncSlice.h	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncSlice.h	(revision 442)
@@ -118,8 +118,8 @@
 #if SVC_EXTENSION
   Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
-                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, TComVPS *vps );
+                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, TComVPS *vps, Bool isField );
 #else
   Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
-                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
+                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, Bool isField );
 #endif
 
Index: /trunk/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 442)
@@ -83,7 +83,6 @@
   m_pcBitCounters          = NULL;
   m_pcRdCosts              = NULL;
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
-#endif
 #if REF_IDX_MFM
   m_bMFMEnabledFlag = false;
@@ -91,4 +90,8 @@
 #if SCALED_REF_LAYER_OFFSETS
   m_numScaledRefLayerOffsets = 0;
+#endif
+#endif
+#if POC_RESET_FLAG
+  m_pocAdjustmentValue     = 0;
 #endif
 }
@@ -107,5 +110,5 @@
   initROM();
 #endif
-  
+
   // create processing unit classes
 #if SVC_EXTENSION
@@ -288,9 +291,5 @@
   delete[] m_pcRdCosts;
   
-#if !SVC_EXTENSION
-  // destroy ROM
-  destroyROM();
-#endif
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   for(Int i=0; i<MAX_NUM_REF; i++)
   {
@@ -301,10 +300,13 @@
       m_cIlpPic[i] = NULL;
     }
-  }    
+  }
+#else
+  // destroy ROM
+  destroyROM();
 #endif
   return;
 }
 
-Void TEncTop::init()
+Void TEncTop::init(Bool isFieldCoding)
 {
   // initialize SPS
@@ -317,5 +319,5 @@
   m_cPPS.setSPS(&m_cSPS);
   xInitPPS();
-  xInitRPS();
+  xInitRPS(isFieldCoding);
 
   xInitPPSforTiles();
@@ -346,6 +348,4 @@
   m_iSPSIdCnt ++;
   m_iPPSIdCnt ++;
-#endif
-#if REF_IDX_FRAMEWORK
   xInitILRP();
 #endif
@@ -396,5 +396,5 @@
 
   // compress GOP
-  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
+  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
 
 #if RATE_CONTROL_LAMBDA_DOMAIN
@@ -456,5 +456,6 @@
 
   // compress GOP
-  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
+
+  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
 
 #if RATE_CONTROL_LAMBDA_DOMAIN
@@ -467,4 +468,271 @@
   iNumEncoded         = m_iNumPicRcvd;
   m_iNumPicRcvd       = 0;
+  m_uiNumAllPicCoded += iNumEncoded;
+}
+#endif
+
+/**------------------------------------------------
+ Separate interlaced frame into two fields
+ -------------------------------------------------**/
+void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop)
+{
+  if (!isTop)
+  {
+    org += stride;
+  }
+  for (Int y = 0; y < height>>1; y++)
+  {
+    for (Int x = 0; x < width; x++)
+    {
+      dstField[x] = org[x];
+    }
+    
+    dstField += stride;
+    org += stride*2;
+  }
+  
+}
+
+#if SVC_EXTENSION
+Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, Bool isTff )
+{
+  if (pcPicYuvOrg)
+  {
+    /* -- TOP FIELD -- */
+    /* -- Top field initialization -- */
+    
+    TComPic *pcTopField;
+    xGetNewPicBuffer( pcTopField );
+    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
+    pcTopField->setReconMark (false);
+    
+    pcTopField->getSlice(0)->setPOC( m_iPOCLast );
+    pcTopField->getPicYuvRec()->setBorderExtension(false);
+    pcTopField->setTopField(isTff);
+    
+    Int nHeight = pcPicYuvOrg->getHeight();
+    Int nWidth = pcPicYuvOrg->getWidth();
+    Int nStride = pcPicYuvOrg->getStride();
+    Int nPadLuma = pcPicYuvOrg->getLumaMargin();
+    Int nPadChroma = pcPicYuvOrg->getChromaMargin();
+    
+    // Get pointers
+    Pel * PicBufY = pcPicYuvOrg->getBufY();
+    Pel * PicBufU = pcPicYuvOrg->getBufU();
+    Pel * PicBufV = pcPicYuvOrg->getBufV();
+    
+    Pel * pcTopFieldY =  pcTopField->getPicYuvOrg()->getLumaAddr();
+    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
+    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
+    
+    // compute image characteristics
+    if ( getUseAdaptiveQP() )
+    {
+      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
+    }
+    
+    /* -- Defield -- */
+    
+    Bool isTop = isTff;
+    
+    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop);
+    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
+    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
+
+    /* -- BOTTOM FIELD -- */
+    /* -- Bottom field initialization -- */
+    
+    TComPic* pcBottomField;
+    xGetNewPicBuffer( pcBottomField );
+    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
+    pcBottomField->setReconMark (false);
+   
+    pcBottomField->getSlice(0)->setPOC( m_iPOCLast);
+    pcBottomField->getPicYuvRec()->setBorderExtension(false);
+    pcBottomField->setTopField(!isTff);
+    
+    nHeight = pcPicYuvOrg->getHeight();
+    nWidth = pcPicYuvOrg->getWidth();
+    nStride = pcPicYuvOrg->getStride();
+    nPadLuma = pcPicYuvOrg->getLumaMargin();
+    nPadChroma = pcPicYuvOrg->getChromaMargin();
+    
+    // Get pointers
+    PicBufY = pcPicYuvOrg->getBufY();
+    PicBufU = pcPicYuvOrg->getBufU();
+    PicBufV = pcPicYuvOrg->getBufV();
+    
+    Pel * pcBottomFieldY =  pcBottomField->getPicYuvOrg()->getLumaAddr();
+    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
+    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
+    
+    // Compute image characteristics
+    if ( getUseAdaptiveQP() )
+    {
+      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
+    }
+    
+    /* -- Defield -- */
+    
+    isTop = !isTff;
+    
+    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop);
+    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
+    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
+    
+  }
+}
+
+Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff )
+{
+  // compress GOP
+  if (m_iPOCLast == 0) // compress field 0
+  {
+    m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
+  }
+
+  if (pcPicYuvOrg)
+  {
+    TComPicYuv* rpcPicYuvRec = new TComPicYuv;
+    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
+    {
+      rpcPicYuvRec = rcListPicYuvRecOut.popFront();
+    }
+    else
+    {
+      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+    }
+    rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
+  }
+  
+  // compress GOP
+  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
+
+  m_uiNumAllPicCoded ++;
+}
+#else
+Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff)
+{
+  /* -- TOP FIELD -- */
+  
+  if (pcPicYuvOrg)
+  {
+    
+    /* -- Top field initialization -- */
+    
+    TComPic *pcTopField;
+    xGetNewPicBuffer( pcTopField );
+    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
+    pcTopField->setReconMark (false);
+    
+    pcTopField->getSlice(0)->setPOC( m_iPOCLast );
+    pcTopField->getPicYuvRec()->setBorderExtension(false);
+    pcTopField->setTopField(isTff);
+    
+    Int nHeight = pcPicYuvOrg->getHeight();
+    Int nWidth = pcPicYuvOrg->getWidth();
+    Int nStride = pcPicYuvOrg->getStride();
+    Int nPadLuma = pcPicYuvOrg->getLumaMargin();
+    Int nPadChroma = pcPicYuvOrg->getChromaMargin();
+    
+    // Get pointers
+    Pel * PicBufY = pcPicYuvOrg->getBufY();
+    Pel * PicBufU = pcPicYuvOrg->getBufU();
+    Pel * PicBufV = pcPicYuvOrg->getBufV();
+    
+    Pel * pcTopFieldY =  pcTopField->getPicYuvOrg()->getLumaAddr();
+    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
+    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
+    
+    // compute image characteristics
+    if ( getUseAdaptiveQP() )
+    {
+      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
+    }
+    
+    /* -- Defield -- */
+    
+    Bool isTop = isTff;
+    
+    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop);
+    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
+    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
+    
+  }
+  
+  if (m_iPOCLast == 0) // compress field 0
+  {
+    m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
+  }
+  
+  /* -- BOTTOM FIELD -- */
+  
+  if (pcPicYuvOrg)
+  {
+    
+    /* -- Bottom field initialization -- */
+    
+    TComPic* pcBottomField;
+    xGetNewPicBuffer( pcBottomField );
+    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
+    pcBottomField->setReconMark (false);
+    
+    TComPicYuv* rpcPicYuvRec = new TComPicYuv;
+    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
+    {
+      rpcPicYuvRec = rcListPicYuvRecOut.popFront();
+    }
+    else
+    {
+      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+    }
+    rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
+    
+    pcBottomField->getSlice(0)->setPOC( m_iPOCLast);
+    pcBottomField->getPicYuvRec()->setBorderExtension(false);
+    pcBottomField->setTopField(!isTff);
+    
+    int nHeight = pcPicYuvOrg->getHeight();
+    int nWidth = pcPicYuvOrg->getWidth();
+    int nStride = pcPicYuvOrg->getStride();
+    int nPadLuma = pcPicYuvOrg->getLumaMargin();
+    int nPadChroma = pcPicYuvOrg->getChromaMargin();
+    
+    // Get pointers
+    Pel * PicBufY = pcPicYuvOrg->getBufY();
+    Pel * PicBufU = pcPicYuvOrg->getBufU();
+    Pel * PicBufV = pcPicYuvOrg->getBufV();
+    
+    Pel * pcBottomFieldY =  pcBottomField->getPicYuvOrg()->getLumaAddr();
+    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
+    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
+    
+    // Compute image characteristics
+    if ( getUseAdaptiveQP() )
+    {
+      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
+    }
+    
+    /* -- Defield -- */
+    
+    Bool isTop = !isTff;
+    
+    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop);
+    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
+    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
+    
+  }
+  
+  if ( ( !(m_iNumPicRcvd) || (!flush && m_iPOCLast != 1 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) )
+  {
+    iNumEncoded = 0;
+    return;
+  }
+  
+  // compress GOP
+  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
+  
+  iNumEncoded = m_iNumPicRcvd;
+  m_iNumPicRcvd = 0;
   m_uiNumAllPicCoded += iNumEncoded;
 }
@@ -523,5 +791,9 @@
 
             //only for scalable extension
+#if SCALABILITY_MASK_E0104
+            assert( m_cVPS.getScalabilityMask(2) == true );
+#else
             assert( m_cVPS.getScalabilityMask(1) == true );
+#endif
           }
         }
@@ -560,5 +832,9 @@
 
             //only for scalable extension
+#if SCALABILITY_MASK_E0104
+            assert( m_cVPS.getScalabilityMask(2) == true );
+#else
             assert( m_cVPS.getScalabilityMask(1) == true );
+#endif
           }
         }
@@ -682,4 +958,11 @@
   }
 
+#if REPN_FORMAT_IN_VPS
+  m_cSPS.setBitDepthY( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() );
+  m_cSPS.setBitDepthC( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma()  );
+
+  m_cSPS.setQpBDOffsetY ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma()  - 8) );
+  m_cSPS.setQpBDOffsetC ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma()  - 8) );
+#else
   m_cSPS.setBitDepthY( g_bitDepthY );
   m_cSPS.setBitDepthC( g_bitDepthC );
@@ -687,4 +970,5 @@
   m_cSPS.setQpBDOffsetY ( 6*(g_bitDepthY - 8) );
   m_cSPS.setQpBDOffsetC ( 6*(g_bitDepthC - 8) );
+#endif
 
   m_cSPS.setUseSAO( m_bUseSAO );
@@ -745,8 +1029,24 @@
 Void TEncTop::xInitPPS()
 {
+#if IL_SL_SIGNALLING_N0371
+  m_cPPS.setLayerId(m_layerId);
+#endif
+
   m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
   Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
 
+#if REPN_FORMAT_IN_VPS
+  Int lowestQP;
+  if( m_layerId == 0 || m_cSPS.getUpdateRepFormatFlag() )
+  {
+    lowestQP = - m_cSPS.getQpBDOffsetY();
+  }
+  else
+  {
+    lowestQP = - (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() - 8) * 6;
+  }
+#else
   Int lowestQP = - m_cSPS.getQpBDOffsetY();
+#endif
 
   if(getUseLossless())
@@ -860,5 +1160,5 @@
     }
   }
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
   if (!m_layerId)
   {
@@ -869,17 +1169,19 @@
     m_cPPS.setListsModificationPresentFlag(true);
   }
-#endif
-#if SVC_EXTENSION
+
   m_cPPS.setPPSId         ( m_iPPSIdCnt         );
   m_cPPS.setSPSId         ( m_iSPSIdCnt         );
 #endif
+#if POC_RESET_FLAG
+  m_cPPS.setNumExtraSliceHeaderBits( 2 );
+#endif
 }
 
 //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
-Void TEncTop::xInitRPS()
+Void TEncTop::xInitRPS(Bool isFieldCoding)
 {
   TComReferencePictureSet*      rps;
   
-  m_cSPS.createRPSList(getGOPSize()+m_extraRPSs);
+  m_cSPS.createRPSList(getGOPSize()+m_extraRPSs+1);
   TComRPSList* rpsList = m_cSPS.getRPSList();
 
@@ -982,5 +1284,5 @@
         printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
         rps->setNumberOfNegativePictures(numNeg);
-        rps->setNumberOfPositivePictures(numNeg+numPos);
+        rps->setNumberOfPictures(numNeg+numPos);
       }
       if (numPos != rps->getNumberOfPositivePictures())
@@ -988,5 +1290,5 @@
         printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
         rps->setNumberOfPositivePictures(numPos);
-        rps->setNumberOfPositivePictures(numNeg+numPos);
+        rps->setNumberOfPictures(numNeg+numPos);
       }
       RPSTemp.setNumberOfPictures(numNeg+numPos);
@@ -1052,5 +1354,21 @@
 #endif //INTER_RPS_AUTO
   }
-  
+  //In case of field coding, we need to set special parameters for the first bottom field of the sequence, since it is not specified in the cfg file. 
+  //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS. 
+  if (isFieldCoding) 
+  {
+    rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs);
+    rps->setNumberOfPictures(1);
+    rps->setNumberOfNegativePictures(1);
+    rps->setNumberOfPositivePictures(0);
+    rps->setNumberOfLongtermPictures(0);
+    rps->setDeltaPOC(0,-1);
+    rps->setPOC(0,0);
+    rps->setUsed(0,true);
+    rps->setInterRPSPrediction(false);
+    rps->setDeltaRIdxMinus1(0);
+    rps->setDeltaRPS(0);
+    rps->setNumRefIdc(0);
+}
 }
 
@@ -1061,5 +1379,4 @@
 {
   slice->setRPSidx(GOPid);
-
   for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
   {    
@@ -1085,7 +1402,11 @@
   }
 
+  if(POCCurr == 1 && slice->getPic()->isField())
+  {
+    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
+  }
+
   slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
   slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
-
 }
 
@@ -1215,5 +1536,6 @@
 #endif
 
-#if REF_IDX_FRAMEWORK
+#if SVC_EXTENSION
+#if !REPN_FORMAT_IN_VPS
 Void TEncTop::xInitILRP()
 {
@@ -1249,5 +1571,57 @@
   }
 }
-
+#else
+Void TEncTop::xInitILRP()
+{
+  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) );
+  Int bitDepthY,bitDepthC,picWidth,picHeight;
+
+  if( m_cSPS.getUpdateRepFormatFlag() )
+  {
+    bitDepthY   = m_cSPS.getBitDepthY();
+    bitDepthC   = m_cSPS.getBitDepthC();
+    picWidth    = m_cSPS.getPicWidthInLumaSamples();
+    picHeight   = m_cSPS.getPicHeightInLumaSamples();
+  }
+  else
+  {
+    bitDepthY   = repFormat->getBitDepthVpsLuma();
+    bitDepthC   = repFormat->getBitDepthVpsChroma();
+    picWidth    = repFormat->getPicWidthVpsInLumaSamples();
+    picHeight   = repFormat->getPicHeightVpsInLumaSamples();
+  }
+  
+  if(m_layerId > 0)
+  {
+    g_bitDepthY     = bitDepthY;
+    g_bitDepthC     = bitDepthC;
+    g_uiMaxCUWidth  = m_cSPS.getMaxCUWidth();
+    g_uiMaxCUHeight = m_cSPS.getMaxCUHeight();
+    g_uiMaxCUDepth  = m_cSPS.getMaxCUDepth();
+    g_uiAddCUDepth  = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() );
+
+    Int  numReorderPics[MAX_TLAYER];
+    Window &conformanceWindow = m_cSPS.getConformanceWindow();
+    Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window();
+
+    if (m_cIlpPic[0] == NULL)
+    {
+      for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++) // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
+      {
+        m_cIlpPic[j] = new  TComPic;
+#if SVC_UPSAMPLING
+        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
+#else
+        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
+        {
+          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
+        }
+      }
+    }
+  }
+}
+#endif
 Void TEncTop::setILRPic(TComPic *pcPic)
 {
@@ -1263,4 +1637,8 @@
       m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false);
       m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
+      for (Int j=0; j<m_cIlpPic[refLayerIdc]->getPicSym()->getNumberOfCUsInFrame(); j++)    // set reference CU layerId
+      {
+        m_cIlpPic[refLayerIdc]->getPicSym()->getCU(j)->setLayerId(m_cIlpPic[refLayerIdc]->getLayerId());
+      }
     }
   }
Index: /trunk/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 441)
+++ /trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 442)
@@ -130,10 +130,8 @@
   
 #if SVC_EXTENSION
+
   TEncTop**               m_ppcTEncTop;
   TEncTop*                getLayerEnc(UInt layer)   { return m_ppcTEncTop[layer]; }
-#endif
-#if REF_IDX_FRAMEWORK
   TComPic*                m_cIlpPic[MAX_NUM_REF];                    ///<  Inter layer Prediction picture =  upsampled picture 
-#endif
 #if REF_IDX_MFM
   Bool                    m_bMFMEnabledFlag;
@@ -145,4 +143,8 @@
   UInt                    m_numScaledRefLayerOffsets;
   Window                  m_scaledRefLayerWindow[MAX_LAYERS];
+#endif
+#if POC_RESET_FLAG
+  Int                     m_pocAdjustmentValue;
+#endif
 #endif
 protected:
@@ -152,6 +154,6 @@
   
   Void  xInitPPSforTiles  ();
-  Void  xInitRPS          ();                             ///< initialize PPS from encoder options
-#if REF_IDX_FRAMEWORK
+  Void  xInitRPS          (Bool isFieldCoding);           ///< initialize PPS from encoder options
+#if SVC_EXTENSION
   Void xInitILRP();
 #endif
@@ -162,5 +164,5 @@
   Void      create          ();
   Void      destroy         ();
-  Void      init            ();
+  Void      init            (Bool isFieldCoding);
   Void      deletePicBuffer ();
 
@@ -207,5 +209,4 @@
   Int                     getNumPicRcvd         () { return m_iNumPicRcvd;            }
   Void                    setNumPicRcvd         ( Int num ) { m_iNumPicRcvd = num;      }
-#endif
 #if SCALED_REF_LAYER_OFFSETS
   Void                    setNumScaledRefLayerOffsets(Int x) { m_numScaledRefLayerOffsets = x; }
@@ -213,4 +214,5 @@
   Window&  getScaledRefLayerWindow(Int x)            { return m_scaledRefLayerWindow[x]; }
 #endif
+#endif
 
   // -------------------------------------------------------------------------------------------------------------------
@@ -220,8 +222,6 @@
   /// encode several number of pictures until end-of-sequence
 #if SVC_EXTENSION
-#if REF_IDX_FRAMEWORK
   TComPic** getIlpList() { return m_cIlpPic; }
   Void      setILRPic(TComPic *pcPic);
-#endif
 #if REF_IDX_MFM
   Void      setMFMEnabledFlag       (Bool flag)   {m_bMFMEnabledFlag = flag;}
@@ -236,15 +236,25 @@
   fstream*  getBLSyntaxFile() { return m_pBLSyntaxFile; }
 #endif
-  Void      encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP  );
+  Void      encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP );
   Void      encodePrep( TComPicYuv* pcPicYuvOrg );
+  Void      encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff );
+  Void      encodePrep( TComPicYuv* pcPicYuvOrg, Bool isTff );
 #if VPS_EXTN_DIRECT_REF_LAYERS
   TEncTop*  getRefLayerEnc(UInt refLayerIdc);
 #endif
-#else
+#if POC_RESET_FLAG
+  Int  getPocAdjustmentValue()      { return m_pocAdjustmentValue;}
+  Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x;   }
+#endif
+#else //SVC_EXTENSION
   Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
-              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded );  
-#endif
-
-  void printSummary() { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded); }
+              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded );
+
+  /// encode several number of pictures until end-of-sequence
+  Void encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
+              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff);
+
+  Void printSummary(Bool isField) { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded, isField); }
+#endif //#if SVC_EXTENSION
 };
 
Index: /trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp
===================================================================
--- /trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp	(revision 441)
+++ /trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp	(revision 442)
@@ -339,4 +339,44 @@
 }
 
+static Bool writeField(ostream& fd, Pel* top, Pel* bottom, Bool is16bit,
+                       UInt stride,
+                       UInt width, UInt height, bool isTff)
+{
+  Int write_len = width * (is16bit ? 2 : 1)*2;
+  UChar *buf = new UChar[write_len];
+  for (Int y = 0; y < height; y++)
+  {
+    if (!is16bit)
+    {
+      for (Int x = 0; x < width; x++)
+      {
+        buf[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
+        buf[width+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
+      }
+    }
+    else
+    {
+      for (Int x = 0; x < width; x++)
+      {
+        buf[2*x] = isTff ? top[x] & 0xff : bottom[x] & 0xff;
+        buf[2*x+1] = isTff ? (top[x] >> 8) & 0xff : (bottom[x] >> 8) & 0xff;
+        
+        buf[width+2*x] = isTff ? bottom[x] & 0xff : top[x] & 0xff;
+        buf[width+2*x+1] = isTff ? (bottom[x] >> 8) & 0xff : (top[x] >> 8) & 0xff;
+      }
+    }
+    
+    fd.write(reinterpret_cast<Char*>(buf), write_len);
+    if (fd.eof() || fd.fail() )
+    {
+      delete[] buf;
+      return false;
+    }
+    top += stride;
+    bottom += stride;
+  }
+  delete[] buf;
+  return true;
+}
 /**
  * Read one Y'CbCr frame, performing any required input scaling to change
@@ -501,2 +541,108 @@
 }
 
+
+/**
+ * Write one Y'CbCr frame. No bit-depth conversion is performed, pcPicYuv is
+ * assumed to be at TVideoIO::m_fileBitdepth depth.
+ *
+ * @param pPicTop     input top field YUV buffer class pointer
+ * @param pPicBottom  input bottom field YUV buffer class pointer
+ * @param aiPad       source padding size, aiPad[0] = horizontal, aiPad[1] = vertical
+ * @return true for success, false in case of error
+ */
+Bool TVideoIOYuv::write( TComPicYuv* pPicTop, TComPicYuv* pPicBottom, Int cropLeft, Int cropRight, Int cropTop, Int cropBottom , bool isTff)
+{
+  // compute actual YUV frame size excluding padding size
+  Int   iStride = pPicTop->getStride();
+  UInt  width  = pPicTop->getWidth()  - cropLeft - cropRight;
+  UInt  height = pPicTop->getHeight() - cropTop  - cropBottom;
+  Bool is16bit = m_fileBitDepthY > 8 || m_fileBitDepthC > 8;
+  
+  TComPicYuv *dstPicTop = NULL;
+  TComPicYuv *dstPicBottom = NULL;
+  
+  Bool retval = true;
+  
+  if (m_bitDepthShiftY != 0 || m_bitDepthShiftC != 0)
+  {
+    dstPicTop = new TComPicYuv;
+    dstPicTop->create( pPicTop->getWidth(), pPicTop->getHeight(), 1, 1, 0 );
+    pPicTop->copyToPic(dstPicTop);
+    
+    dstPicBottom = new TComPicYuv;
+    dstPicBottom->create( pPicBottom->getWidth(), pPicBottom->getHeight(), 1, 1, 0 );
+    pPicBottom->copyToPic(dstPicBottom);
+    
+    Pel minvalY = 0;
+    Pel minvalC = 0;
+    Pel maxvalY = (1 << m_fileBitDepthY) - 1;
+    Pel maxvalC = (1 << m_fileBitDepthC) - 1;
+#if CLIP_TO_709_RANGE
+    if (-m_bitDepthShiftY < 0 && m_fileBitDepthY >= 8)
+    {
+      /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
+      minvalY = 1 << (m_fileBitDepthY - 8);
+      maxvalY = (0xff << (m_fileBitDepthY - 8)) -1;
+    }
+    if (-m_bitDepthShiftC < 0 && m_fileBitDepthC >= 8)
+    {
+      /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
+      minvalC = 1 << (m_fileBitDepthC - 8);
+      maxvalC = (0xff << (m_fileBitDepthC - 8)) -1;
+    }
+#endif
+    scalePlane(dstPicTop->getLumaAddr(), dstPicTop->getStride(), dstPicTop->getWidth(), dstPicTop->getHeight(), -m_bitDepthShiftY, minvalY, maxvalY);
+    scalePlane(dstPicTop->getCbAddr(), dstPicTop->getCStride(), dstPicTop->getWidth()>>1, dstPicTop->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
+    scalePlane(dstPicTop->getCrAddr(), dstPicTop->getCStride(), dstPicTop->getWidth()>>1, dstPicTop->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
+    
+    scalePlane(dstPicBottom->getLumaAddr(), dstPicBottom->getStride(), dstPicBottom->getWidth(), dstPicBottom->getHeight(), -m_bitDepthShiftY, minvalY, maxvalY);
+    scalePlane(dstPicBottom->getCbAddr(), dstPicBottom->getCStride(), dstPicBottom->getWidth()>>1, dstPicBottom->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
+    scalePlane(dstPicBottom->getCrAddr(), dstPicBottom->getCStride(), dstPicBottom->getWidth()>>1, dstPicBottom->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
+  }
+  else
+  {
+    dstPicTop = pPicTop;
+    dstPicBottom = pPicBottom;
+  }
+  // location of upper left pel in a plane
+  Int planeOffset = 0; //cropLeft + cropTop * iStride;
+  //Write luma
+  if (! writeField(m_cHandle, dstPicTop->getLumaAddr() + planeOffset,  dstPicBottom->getLumaAddr() + planeOffset, is16bit, iStride, width, height, isTff))
+  {
+    retval=false;
+    goto exit;
+  }
+  
+  width >>= 1;
+  height >>= 1;
+  iStride >>= 1;
+  cropLeft >>= 1;
+  cropRight >>= 1;
+  
+  planeOffset = 0; // cropLeft + cropTop * iStride;
+  
+  //Write chroma U
+  if (! writeField(m_cHandle, dstPicTop->getCbAddr() + planeOffset, dstPicBottom->getCbAddr() + planeOffset, is16bit, iStride, width, height, isTff))
+  {
+    retval=false;
+    goto exit;
+  }
+  
+  //Write chroma V
+  if (! writeField(m_cHandle, dstPicTop->getCrAddr() + planeOffset, dstPicBottom->getCrAddr() + planeOffset, is16bit, iStride, width, height, isTff))
+    
+  {
+    retval=false;
+    goto exit;
+  }
+  
+exit:
+  if (m_bitDepthShiftY != 0 || m_bitDepthShiftC != 0)
+  {
+    dstPicTop->destroy();
+    delete dstPicTop;
+    dstPicBottom->destroy();
+    delete dstPicBottom;
+  }  
+  return retval;
+}
Index: /trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h
===================================================================
--- /trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h	(revision 441)
+++ /trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h	(revision 442)
@@ -72,4 +72,5 @@
   Bool  read  ( TComPicYuv*   pPicYuv, Int aiPad[2] );     ///< read  one YUV frame with padding parameter
   Bool  write( TComPicYuv*    pPicYuv, Int confLeft=0, Int confRight=0, Int confTop=0, Int confBottom=0 );
+  Bool  write( TComPicYuv*    pPicYuv, TComPicYuv*    pPicYuv2, Int confLeft=0, Int confRight=0, Int confTop=0, Int confBottom=0, Bool isTff = false ); 
   
   Bool  isEof ();                                           ///< check for end-of-file
