Index: trunk/source/App/TAppDownConvert/TAppDownConvert.cpp
===================================================================
--- trunk/source/App/TAppDownConvert/TAppDownConvert.cpp	(revision 345)
+++ trunk/source/App/TAppDownConvert/TAppDownConvert.cpp	(revision 345)
@@ -0,0 +1,472 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.  
+ *
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** \file     TAppDownConvert.cpp
+    \brief    Down convert application main
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+//! \ingroup TAppDecoder
+//! \{
+
+#define pi 3.1415926
+
+int get_mem2DPelWithPad(unsigned char ***array2D, int dim0, int dim1, int iPadY, int iPadX)
+{
+  int i;
+  unsigned char *curr = NULL;
+  int iHeight, iWidth;
+
+  iHeight = dim0+2*iPadY;
+  iWidth = dim1+2*iPadX;
+  (*array2D) = (unsigned char**)malloc(iHeight*sizeof(unsigned char*));
+  *(*array2D) = (unsigned char* )calloc(iHeight * iWidth, sizeof(unsigned char ));
+
+  (*array2D)[0] += iPadX;
+  curr = (*array2D)[0];
+  for(i = 1 ; i < iHeight; i++)
+  {
+    curr += iWidth;
+    (*array2D)[i] = curr;
+  }
+  (*array2D) = &((*array2D)[iPadY]);
+
+  return 0;
+}
+
+int get_mem2DintWithPad(int ***array2D, int dim0, int dim1, int iPadY, int iPadX)
+{
+  int i;
+  int *curr = NULL;
+  int iHeight, iWidth;
+
+  iHeight = dim0+2*iPadY;
+  iWidth = dim1+2*iPadX;
+  (*array2D) = (int**)malloc(iHeight*sizeof(int*));
+  *(*array2D) = (int* )calloc(iHeight * iWidth, sizeof(int ));
+
+  (*array2D)[0] += iPadX;
+  curr = (*array2D)[0];
+  for(i = 1 ; i < iHeight; i++)
+  {
+    curr += iWidth;
+    (*array2D)[i] = curr;
+  }
+  (*array2D) = &((*array2D)[iPadY]);
+
+  return 0;
+}
+
+void free_mem2DPelWithPad(unsigned char **array2D, int iPadY, int iPadX)
+{
+  if (array2D)
+  {
+    if (*array2D)
+    {
+      free (array2D[-iPadY]-iPadX);
+    }
+    else 
+    {
+      printf("free_mem2DintWithPad: trying to free unused memory\r\nPress Any Key\r\n");
+    }
+
+    free (&array2D[-iPadY]);
+  } 
+  else
+  {
+    printf("free_mem2DintWithPad: trying to free unused memory\r\nPress Any Key\r\n");
+  }
+}
+
+void free_mem2DintWithPad(int **array2D, int iPadY, int iPadX)
+{
+  if (array2D)
+  {
+    if (*array2D)
+    {
+      free (array2D[-iPadY]-iPadX);
+    }
+    else 
+    {
+      printf("free_mem2DintWithPad: trying to free unused memory\r\nPress Any Key\r\n");
+    }
+
+    free (&array2D[-iPadY]);
+  } 
+  else
+  {
+    printf("free_mem2DintWithPad: trying to free unused memory\r\nPress Any Key\r\n");
+  }
+}
+
+void PadImgHorizontal(unsigned char **src, unsigned char **dst, int height, int width, int pad_h)
+{
+  int i, j;
+  unsigned char *BufSrc, *BufDst;
+
+  for (j=0;j<height;j++)
+  {    
+    BufDst = &(dst[j][-pad_h] );
+    BufSrc = src[j];
+    for (i=0;i<pad_h;i++)
+    {
+      *(BufDst++) = BufSrc[0];
+    }
+    memcpy(BufDst, BufSrc, width*sizeof(unsigned char));
+    BufDst += width;
+    for (i=0;i<pad_h;i++)
+    {
+      *(BufDst++) = BufSrc[width-1];
+    }
+  }
+}
+
+void FilterImg( unsigned char **src,
+                int           **temp,
+                unsigned char **dst,
+                int           height1,  
+                int           width1,  
+                int           M, 
+                int           N, 
+                int           **phase_filter,
+                int           length,
+                int           shift,
+                int           plane)
+{
+  int height2,width2;
+  int k,iSum;
+  int i0, div_i0, i1;
+  int j0, div_j0, j1;
+  int *p_filter;
+  unsigned char *p_src, *p_dst;
+  int **p_temp, *p_tmp;
+  int shift2 = (2*shift);
+  int shift_round = (1 << (2 * shift - 1));
+
+  height2 = (height1 * M) / N;
+  width2  = (width1  * M) / N;
+
+  // horizontal filtering
+  for(j1 = 0; j1 < height1; j1++)
+  {
+    i0=-N;
+    p_tmp = temp[j1];
+    for(i1 = 0; i1 < width2; i1++)
+    {
+      i0      += N;
+      div_i0   = (i0 / M);
+      p_src    = &src[j1][ div_i0 - (length >> 1)];
+      p_filter = phase_filter[i0 - div_i0 * M];
+      iSum     = 0;
+      for(k = 0; k < length; k++)
+      {
+        iSum += (*p_src++) * (*p_filter++);
+      }
+      *p_tmp++ = iSum;
+    }
+  }
+
+  // pad temp (vertical)
+  for (k=-(length>>1);k<0;k++)
+    memcpy(temp[k], temp[0], width2*sizeof(int));
+  for (k=height1;k<(height1+(length>>1));k++)
+    memcpy(temp[k], temp[k-1], (width2)* sizeof(int));
+
+  // vertical filtering
+  j0 = (plane == 0) ? -N : -(N-1);
+  
+  for(j1 = 0; j1 < height2; j1++)
+  {
+    j0      += N;
+    div_j0   = (j0 / M);
+    p_dst    = dst[j1];
+    p_temp   = &temp[div_j0 - (length>>1)];
+    p_filter = phase_filter[j0 - div_j0 * M];
+    for(i1 = 0; i1 < width2;i1++)
+    {
+      iSum=0;
+      for(k = 0; k < length; k++)
+      {
+        iSum += p_temp[k][i1] * p_filter[k];
+      }
+      iSum=((iSum + shift_round) >> shift2);
+      *p_dst++ = (unsigned char)(iSum > 255 ? 255 : iSum < 0 ? 0 : iSum);
+    }
+  }
+}
+
+// ====================================================================================================================
+// Main function
+// ====================================================================================================================
+
+int main(int argc, char *argv[])
+{
+  const int phase_filter_0[4][13]={
+    {0,  2,  -3,  -9,   6,  39,  58,  39,   6,  -9,  -3,  2,  0},  
+    {0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0},  
+    {0,  1,   0,  -7,  -5,  22,  53,  53,  22,  -5,  -7,  0,  1},  
+    {0,  0,   1,  -5,  -7,  13,  47,  57,  31,  -1,  -8,-1,  1}  
+  };
+
+  const int phase_filter_1[8][13]={
+    {0,   0,  5,  -6,  -10,  37,  76,  37,-10,   -6, 5,  0,   0},    
+    {0,  -1,  5,  -3,  -12,  29,  75,  45,  -7,   -8, 5,  0,   0},    
+    {0,  -1,  4,  -1,  -13,  22,  73,  52,  -3,  -10, 4,  1,   0},    
+    {0,  -1,  4,   1,  -13,  14,  70,  59,   2,  -12, 3,  2,  -1},  
+    {0,  -1,  3,   2,  -13,   8,  65,  65,   8,  -13, 2,  3,  -1},    
+    {0,  -1,  2,   3,  -12,   2,  59,  70,  14,  -13, 1,  4,  -1},    
+    {0,   0,  1,   4,  -10,  -3,  52,  73,  22,  -13,-1,  4,  -1},    
+    {0,   0,  0,   5,   -8,  -7,  45,  75,  29,  -12,-3,  5,  -1}    
+  };
+
+  int i,j;
+
+  int width_org,  width_org_c,  width_sampled,  width_sampled_c;
+  int height_org, height_org_c, height_sampled, height_sampled_c;
+  int size_org,   size_org_c,   size_sampled,   size_sampled_c;
+
+  unsigned char **Y1,    **U1,    **V1;
+  unsigned char **Y2,    **U2,    **V2;
+  unsigned char **temp_luma,    **temp_chroma;
+  int           **tempY, **tempU, **tempV;
+
+  int **phase_filter;
+  int log2_scaling_factor=7;
+
+  FILE * infile;
+  FILE * outfile;
+
+  int M,N;
+  int ratio;
+  int Frames=0;
+  int totalFrames=0;
+  int StartFrame=0;
+  int Tap=13;
+
+  if (argc < 6)
+  {
+    printf("\nIncorrect number of arguments!!!\n\n");
+    printf("Syntax: \n");
+    printf("%s <input width> <input height> <input file> <output file> <downsampling method> [frames_to_process] [start_frame]\n\n", argv[0]);
+    printf("<downsampling method> 0: 2x downsampling, 1: 1.5x downsampling. \n");
+    printf("Examples: \n");
+    printf("%s 1920 1080 input_1920x1080_24p.yuv output_960x540_24p.yuv 0 \n", argv[0]);
+    printf("%s 1920 1080 input_1920x1080_24p.yuv output_1280x720_24p.yuv 1 \n", argv[0]);
+    return -1;
+  }
+
+  width_org  = atoi  (argv[1]);
+  height_org = atoi  (argv[2]);
+  infile     = fopen (argv[3], "rb");
+  outfile    = fopen (argv[4], "wb");
+  ratio      = atoi  (argv[5]); 
+
+  for(i=7; i<= argc; i++)
+  {
+    switch(i)
+    {
+    case 7:
+      Frames = atoi(argv[6]);
+      break;
+    case 8:
+      StartFrame = atoi(argv[7]);
+      break;
+    default:
+      printf("Too many input arguments");
+      break;
+    }
+  }
+
+  if( width_org < 4 || height_org < 4 )
+  {
+    printf("\ninput resolution is too small, exit\n");
+    return -1;
+  }
+  if ( infile == NULL || outfile == NULL )
+  {
+    printf("\ninput or output file is invalid, exit\n");
+    return -1;
+  }
+  if ((argc > 6) && (Frames < 1 || StartFrame < 0))
+  {
+    printf("input frame parameter error\n");
+    return -1;
+  }
+  if ( ratio > 1 || ratio < 0)
+  {
+    printf("\ndown sampling parameter %d is not supported (0: 2x downsampling, 1: 1.5x downsampling)\n", ratio);
+    return -1;
+  }
+
+  if (ratio==0)
+  {
+    M=4;
+    N=8;
+  }
+  else if (ratio==1)
+  {
+    M=8;
+    N=12;
+  }
+
+  width_org_c      = width_org  >> 1;
+  height_org_c     = height_org >> 1;
+  width_sampled    = (width_org  * M) / N;
+  height_sampled   = (height_org * M) / N;
+  width_sampled_c  = width_sampled  >> 1;
+  height_sampled_c = height_sampled >> 1;
+  size_org         = height_org * width_org;
+  size_org_c       = height_org_c * width_org_c;
+  size_sampled     = height_sampled * width_sampled;
+  size_sampled_c   = height_sampled_c * width_sampled_c;
+
+  printf("\n=============================================================\n");
+  printf("\n Input  = %s", argv[3]);
+  printf("\n Output = %s", argv[4]);
+  printf("\n Rescaling input from (%d,%d) to (%d,%d) resolution\n", width_org, height_org, width_sampled, height_sampled);
+  printf("\n=============================================================\n\n");  
+
+  // construct phase filters
+  get_mem2DintWithPad (&phase_filter, M, Tap, 0, 0);
+
+  for (j=0;j<M;j++)
+    for (i=0;i<Tap;i++)
+      phase_filter[j][i]= ratio==0 ? phase_filter_0[j][i] :  phase_filter_1[j][i];
+
+  get_mem2DPelWithPad (&Y1, height_org,   width_org,   0, Tap>>1);
+  get_mem2DPelWithPad (&U1, height_org_c, width_org_c, 0, Tap>>1);
+  get_mem2DPelWithPad (&V1, height_org_c, width_org_c, 0, Tap>>1);
+
+  get_mem2DintWithPad (&tempY, height_org,   width_sampled,   Tap>>1, 0);
+  get_mem2DintWithPad (&tempU, height_org_c, width_sampled_c, Tap>>1, 0);
+  get_mem2DintWithPad (&tempV, height_org_c, width_sampled_c, Tap>>1, 0);
+
+  get_mem2DPelWithPad (&Y2, height_sampled,   width_sampled,  0,0);
+  get_mem2DPelWithPad (&U2, height_sampled_c, width_sampled_c,0,0);
+  get_mem2DPelWithPad (&V2, height_sampled_c, width_sampled_c,0,0);
+
+  get_mem2DPelWithPad (&temp_luma,   height_org,   width_org,  0,0);
+  get_mem2DPelWithPad (&temp_chroma, height_org_c, width_org_c,0,0);
+
+  if(StartFrame!=0)
+  {
+    for (i = 0; i < StartFrame; i ++)
+    {
+      fread(temp_luma[0], sizeof(unsigned char), size_org,     infile);
+      fread(temp_chroma[0], sizeof(unsigned char), size_org_c, infile);
+      fread(temp_chroma[0], sizeof(unsigned char), size_org_c, infile);
+      if (feof(infile))
+      {
+        printf("\nThe start frame number exceeds the file size\n");
+        return -1;
+      }
+    }
+    //fseek64(infile, (size_org * StartFrame * 3) >> 1,SEEK_SET);
+  }
+
+  if (Frames)
+  {
+    totalFrames = Frames;
+  }
+  else
+  {
+    totalFrames = 0x7FFF;
+  }
+
+  i = 0;
+  while(totalFrames)
+  {
+    
+    // read and pad Y
+    fread(temp_luma[0], sizeof(unsigned char), size_org,     infile);
+    PadImgHorizontal(temp_luma, Y1, height_org, width_org, Tap>>1);
+
+    // read and pad U
+    fread(temp_chroma[0], sizeof(unsigned char), size_org_c, infile);
+    PadImgHorizontal(temp_chroma, U1, height_org_c, width_org_c, Tap>>1);
+
+    // read and pad V
+    fread(temp_chroma[0], sizeof(unsigned char), size_org_c, infile);
+    PadImgHorizontal(temp_chroma, V1, height_org_c, width_org_c, Tap>>1);
+
+    if (feof(infile))
+    {
+      break;
+    }
+
+    fprintf(stdout,"Rescaling %dth frame\r", i);
+    fflush(stdout);
+
+    i ++;
+    totalFrames --;
+
+    FilterImg(Y1,tempY,Y2,height_org,  width_org,  M, N, phase_filter,Tap,log2_scaling_factor,0);
+    FilterImg(U1,tempU,U2,height_org_c,width_org_c,M, N, phase_filter,Tap,log2_scaling_factor,1);
+    FilterImg(V1,tempV,V2,height_org_c,width_org_c,M, N, phase_filter,Tap,log2_scaling_factor,2);
+
+    // write a sampled frame
+    fwrite(Y2[0], sizeof(unsigned char), size_sampled,     outfile);
+    fwrite(U2[0], sizeof(unsigned char), size_sampled_c, outfile);
+    fwrite(V2[0], sizeof(unsigned char), size_sampled_c, outfile);
+
+  }
+
+  printf("\nEnd of rescaling process.\n");
+
+  free_mem2DintWithPad (phase_filter, 0, 0);
+
+  free_mem2DPelWithPad (Y1, 0, Tap>>1);
+  free_mem2DPelWithPad (U1, 0, Tap>>1);
+  free_mem2DPelWithPad (V1, 0, Tap>>1);
+
+  free_mem2DintWithPad (tempY, Tap>>1, 0);
+  free_mem2DintWithPad (tempU, Tap>>1, 0);
+  free_mem2DintWithPad (tempV, Tap>>1, 0);
+
+  free_mem2DPelWithPad (Y2,0,0);
+  free_mem2DPelWithPad (U2,0,0);
+  free_mem2DPelWithPad (V2,0,0);
+
+  free_mem2DPelWithPad (temp_luma,  0,0);
+  free_mem2DPelWithPad (temp_chroma,0,0);
+
+  fclose(infile);
+  fclose(outfile);
+
+  return 0;
+}
+
+//! \}
Index: trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 313)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 345)
@@ -817,4 +817,11 @@
     opts.addOptions()(cOSS.str(), m_GOPList[i-1], GOPEntry());
   }
+#if FINAL_RPL_CHANGE_N0082
+  for(Int i=1; i<MAX_GOP+1; i++) {
+    std::ostringstream cOSS;
+    cOSS<<"FrameEL"<<i;
+    opts.addOptions()(cOSS.str(), m_acLayerCfg[1].m_GOPListLayer[i-1], GOPEntry());
+  }
+#endif
   po::setDefaults(opts);
   const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
@@ -1460,8 +1467,12 @@
 #endif
   
+#if !FINAL_RPL_CHANGE_N0082
   Bool verifiedGOP=false;
+#endif
   Bool errorGOP=false;
+#if !FINAL_RPL_CHANGE_N0082
   Int checkGOP=1;
   Int numRefs = 1;
+#endif
   Int refList[MAX_NUM_REF_PICS+1];
   refList[0]=0;
@@ -1471,5 +1482,7 @@
     isOK[i]=false;
   }
+#if !FINAL_RPL_CHANGE_N0082
   Int numOK=0;
+#endif
 #if !SVC_EXTENSION
   xConfirmPara( m_iIntraPeriod >=0&&(m_iIntraPeriod%m_iGOPSize!=0), "Intra period must be a multiple of GOPSize, or -1" );
@@ -1514,5 +1527,23 @@
   }
 #endif
-
+#if FINAL_RPL_CHANGE_N0082
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    if (m_acLayerCfg[layer].m_GOPListLayer[0].m_POC<0){
+      memcpy( m_acLayerCfg[layer].m_GOPListLayer, m_GOPList, sizeof(GOPEntry)*MAX_GOP );
+    }
+    errorGOP = xconfirmExtraGOP( m_acLayerCfg[layer].m_GOPListLayer );
+    xConfirmPara(errorGOP,"Invalid GOP structure given");
+  }
+  //tentative for encoder
+  if( m_acLayerCfg[1].m_GOPListLayer[5].m_POC == 6  && m_acLayerCfg[1].m_GOPListLayer[7].m_POC == 7 ){
+    //RA, POC5
+    m_acLayerCfg[1].m_GOPListLayer[5].m_usedByCurrPic[2] = 0;
+    m_acLayerCfg[1].m_GOPListLayer[5].m_refIdc[2] = 0;
+    //RA, POC7
+    m_acLayerCfg[1].m_GOPListLayer[7].m_usedByCurrPic[2] = 0;
+    m_acLayerCfg[1].m_GOPListLayer[7].m_refIdc[2] = 0;
+  }
+#else
   m_extraRPSs=0;
   //start looping through frames in coding order until we can verify that the GOP structure is correct.
@@ -1710,4 +1741,5 @@
   }
   xConfirmPara(errorGOP,"Invalid GOP structure given");
+#endif
   m_maxTempLayer = 1;
   for(Int i=0; i<m_iGOPSize; i++) 
@@ -1730,8 +1762,4 @@
       m_maxDecPicBuffering[m_GOPList[i].m_temporalId] = m_GOPList[i].m_numRefPics + 1;
     }
-
-#if SVC_EXTENSION
-    m_maxDecPicBuffering[m_GOPList[i].m_temporalId] += 1; // it should be updated if more than 1 resampling picture is used
-#endif
 
     Int highestDecodingNumberWithLowerPOC = 0; 
@@ -2187,10 +2215,4 @@
   printf("ENCODER_FAST_MODE: %d ", ENCODER_FAST_MODE);
   printf("REF_IDX_MFM: %d ", REF_IDX_MFM);
-#elif INTRA_BL
-  printf("INTRA_BL:%d ", INTRA_BL);
-#if !AVC_BASE
-  printf("SVC_MVP:%d ", SVC_MVP );
-  printf("SVC_BL_CAND_INTRA:%d", SVC_BL_CAND_INTRA );
-#endif
 #endif
 #else
@@ -2245,3 +2267,218 @@
 }
 #endif
+
+#if FINAL_RPL_CHANGE_N0082
+Bool  TAppEncCfg::xconfirmExtraGOP (GOPEntry * ge)
+{
+  Bool verifiedGOP=false;
+  Bool errorGOP=false;
+  Int checkGOP=1;
+  Int numRefs = 1;
+  Int refList[MAX_NUM_REF_PICS+1];
+  refList[0]=0;
+  Bool isOK[MAX_GOP];
+  for(Int i=0; i<MAX_GOP; i++) 
+  {
+    isOK[i]=false;
+  }
+  Int numOK=0;
+
+  m_extraRPSs=0;
+  //start looping through frames in coding order until we can verify that the GOP structure is correct.
+  while(!verifiedGOP&&!errorGOP) 
+  {
+    Int curGOP = (checkGOP-1)%m_iGOPSize;
+    Int curPOC = ((checkGOP-1)/m_iGOPSize)*m_iGOPSize + ge[curGOP].m_POC;    
+    if(ge[curGOP].m_POC<0) 
+    {
+      printf("\nError: found fewer Reference Picture Sets than GOPSize\n");
+      errorGOP=true;
+    }
+    else 
+    {
+      //check that all reference pictures are available, or have a POC < 0 meaning they might be available in the next GOP.
+      Bool beforeI = false;
+      for(Int i = 0; i< ge[curGOP].m_numRefPics; i++) 
+      {
+        Int absPOC = curPOC+ge[curGOP].m_referencePics[i];
+        if(absPOC < 0)
+        {
+          beforeI=true;
+        }
+        else 
+        {
+          Bool found=false;
+          for(Int j=0; j<numRefs; j++) 
+          {
+            if(refList[j]==absPOC) 
+            {
+              found=true;
+              for(Int k=0; k<m_iGOPSize; k++)
+              {
+                if(absPOC%m_iGOPSize == ge[k].m_POC%m_iGOPSize)
+                {
+                  if(ge[k].m_temporalId==ge[curGOP].m_temporalId)
+                  {
+                    ge[k].m_refPic = true;
+                  }
+                  ge[curGOP].m_usedByCurrPic[i]=ge[k].m_temporalId<=ge[curGOP].m_temporalId;
+                }
+              }
+            }
+          }
+          if(!found)
+          {
+            printf("\nError: ref pic %d is not available for GOP frame %d\n",ge[curGOP].m_referencePics[i],curGOP+1);
+            errorGOP=true;
+          }
+        }
+      }
+      if(!beforeI&&!errorGOP)
+      {
+        //all ref frames were present
+        if(!isOK[curGOP]) 
+        {
+          numOK++;
+          isOK[curGOP]=true;
+          if(numOK==m_iGOPSize)
+          {
+            verifiedGOP=true;
+          }
+        }
+      }
+      else 
+      {
+        //create a new GOPEntry for this frame containing all the reference pictures that were available (POC > 0)
+        ge[m_iGOPSize+m_extraRPSs]=ge[curGOP];
+        Int newRefs=0;
+        for(Int i = 0; i< ge[curGOP].m_numRefPics; i++) 
+        {
+          Int absPOC = curPOC+ge[curGOP].m_referencePics[i];
+          if(absPOC>=0)
+          {
+            ge[m_iGOPSize+m_extraRPSs].m_referencePics[newRefs]=ge[curGOP].m_referencePics[i];
+            ge[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[newRefs]=ge[curGOP].m_usedByCurrPic[i];
+            newRefs++;
+          }
+        }
+        Int numPrefRefs = ge[curGOP].m_numRefPicsActive;
+        
+        for(Int offset = -1; offset>-checkGOP; offset--)
+        {
+          //step backwards in coding order and include any extra available pictures we might find useful to replace the ones with POC < 0.
+          Int offGOP = (checkGOP-1+offset)%m_iGOPSize;
+          Int offPOC = ((checkGOP-1+offset)/m_iGOPSize)*m_iGOPSize + ge[offGOP].m_POC;
+          if(offPOC>=0&&ge[offGOP].m_temporalId<=ge[curGOP].m_temporalId)
+          {
+            Bool newRef=false;
+            for(Int i=0; i<numRefs; i++)
+            {
+              if(refList[i]==offPOC)
+              {
+                newRef=true;
+              }
+            }
+            for(Int i=0; i<newRefs; i++) 
+            {
+              if(ge[m_iGOPSize+m_extraRPSs].m_referencePics[i]==offPOC-curPOC)
+              {
+                newRef=false;
+              }
+            }
+            if(newRef) 
+            {
+              Int insertPoint=newRefs;
+              //this picture can be added, find appropriate place in list and insert it.
+              if(ge[offGOP].m_temporalId==ge[curGOP].m_temporalId)
+              {
+                ge[offGOP].m_refPic = true;
+              }
+              for(Int j=0; j<newRefs; j++)
+              {
+                if(ge[m_iGOPSize+m_extraRPSs].m_referencePics[j]<offPOC-curPOC||ge[m_iGOPSize+m_extraRPSs].m_referencePics[j]>0)
+                {
+                  insertPoint = j;
+                  break;
+                }
+              }
+              Int prev = offPOC-curPOC;
+              Int prevUsed = ge[offGOP].m_temporalId<=ge[curGOP].m_temporalId;
+              for(Int j=insertPoint; j<newRefs+1; j++)
+              {
+                Int newPrev = ge[m_iGOPSize+m_extraRPSs].m_referencePics[j];
+                Int newUsed = ge[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j];
+                ge[m_iGOPSize+m_extraRPSs].m_referencePics[j]=prev;
+                ge[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j]=prevUsed;
+                prevUsed=newUsed;
+                prev=newPrev;
+              }
+              newRefs++;
+            }
+          }
+          if(newRefs>=numPrefRefs)
+          {
+            break;
+          }
+        }
+        ge[m_iGOPSize+m_extraRPSs].m_numRefPics=newRefs;
+        ge[m_iGOPSize+m_extraRPSs].m_POC = curPOC;
+        if (m_extraRPSs == 0)
+        {
+          ge[m_iGOPSize+m_extraRPSs].m_interRPSPrediction = 0;
+          ge[m_iGOPSize+m_extraRPSs].m_numRefIdc = 0;
+        }
+        else
+        {
+          Int rIdx =  m_iGOPSize + m_extraRPSs - 1;
+          Int refPOC = ge[rIdx].m_POC;
+          Int refPics = ge[rIdx].m_numRefPics;
+          Int newIdc=0;
+          for(Int i = 0; i<= refPics; i++) 
+          {
+            Int deltaPOC = ((i != refPics)? ge[rIdx].m_referencePics[i] : 0);  // check if the reference abs POC is >= 0
+            Int absPOCref = refPOC+deltaPOC;
+            Int refIdc = 0;
+            for (Int j = 0; j < ge[m_iGOPSize+m_extraRPSs].m_numRefPics; j++)
+            {
+              if ( (absPOCref - curPOC) == ge[m_iGOPSize+m_extraRPSs].m_referencePics[j])
+              {
+                if (ge[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j])
+                {
+                  refIdc = 1;
+                }
+                else
+                {
+                  refIdc = 2;
+                }
+              }
+            }
+            ge[m_iGOPSize+m_extraRPSs].m_refIdc[newIdc]=refIdc;
+            newIdc++;
+          }
+          ge[m_iGOPSize+m_extraRPSs].m_interRPSPrediction = 1;  
+          ge[m_iGOPSize+m_extraRPSs].m_numRefIdc = newIdc;
+          ge[m_iGOPSize+m_extraRPSs].m_deltaRPS = refPOC - ge[m_iGOPSize+m_extraRPSs].m_POC; 
+        }
+        curGOP=m_iGOPSize+m_extraRPSs;
+        m_extraRPSs++;
+      }
+      numRefs=0;
+      for(Int i = 0; i< ge[curGOP].m_numRefPics; i++) 
+      {
+        Int absPOC = curPOC+ge[curGOP].m_referencePics[i];
+        if(absPOC >= 0) 
+        {
+          refList[numRefs]=absPOC;
+          numRefs++;
+        }
+      }
+      refList[numRefs]=curPOC;
+      numRefs++;
+    }
+    checkGOP++;
+  }
+
+  return errorGOP; //update
+}
+#endif
 //! \}
Index: trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 313)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 345)
@@ -348,4 +348,7 @@
   Void  xPrintParameter ();                                   ///< print configuration values
   Void  xPrintUsage     ();                                   ///< print usage
+#if FINAL_RPL_CHANGE_N0082
+  Bool  xconfirmExtraGOP (GOPEntry * ge);
+#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   Int       m_adaptiveResolutionChange;                       ///< Indicate adaptive resolution change frame
Index: trunk/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 313)
+++ trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 345)
@@ -81,4 +81,7 @@
   Int       m_scaledRefLayerBottomOffset[MAX_LAYERS];
 #endif  
+#if FINAL_RPL_CHANGE_N0082
+  GOPEntry  m_GOPListLayer[MAX_GOP];                            ///< for layer
+#endif
 public:
   TAppEncLayerCfg();
@@ -141,4 +144,7 @@
   Bool    getRCForceIntraQP()         {return m_RCForceIntraQP;        }
 #endif
+#if FINAL_RPL_CHANGE_N0082
+  GOPEntry getGOPEntry(Int i )        {return m_GOPListLayer[i];  }
+#endif
 }; // END CLASS DEFINITION TAppEncLayerCfg
 
Index: trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 313)
+++ trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 345)
@@ -136,5 +136,9 @@
     m_acTEncTop[layer].setDecodingRefreshType          ( m_iDecodingRefreshType );
     m_acTEncTop[layer].setGOPSize                      ( m_iGOPSize );
+#if FINAL_RPL_CHANGE_N0082
+    m_acTEncTop[layer].setGopList                      ( m_acLayerCfg[layer].m_GOPListLayer );
+#else
     m_acTEncTop[layer].setGopList                      ( m_GOPList );
+#endif
     m_acTEncTop[layer].setExtraRPSs                    ( m_extraRPSs );
     for(Int i = 0; i < MAX_TLAYER; i++)
@@ -884,4 +888,24 @@
   }
 #endif
+#if N0120_MAX_TID_REF_PRESENT_FLAG
+  vps->setMaxTidIlRefPicsPlus1PresentFlag(true);
+  if (vps->getMaxTidIlRefPicsPlus1PresentFlag())
+  {
+    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
+    {
+      vps->setMaxSublayerForIlpPlus1(i, vps->getMaxTLayers()+1);
+    }
+  }
+  else
+  {
+    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
+    {
+      vps->setMaxSublayerForIlpPlus1(i, 7);
+    }
+  }
+#endif 
+#if ILP_SSH_SIG
+    vps->setIlpSshSignalingEnabledFlag(true);
+#endif
 #if VPS_EXTN_PROFILE_INFO
   vps->getPTLForExtnPtr()->resize(vps->getNumLayerSets());
