Index: branches/HTM-8.2-dev0-KWU/cfg/3D-HEVC/baseCfg_3view+depth.cfg
===================================================================
--- branches/HTM-8.2-dev0-KWU/cfg/3D-HEVC/baseCfg_3view+depth.cfg	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/cfg/3D-HEVC/baseCfg_3view+depth.cfg	(revision 635)
@@ -224,4 +224,16 @@
 RCForceIntraQP                      : 0                # Rate control: force intra QP to be equal to initial QP
 
+DepthMADPred			    : 0		       # 0: Disable Depth based MAD prediction for extended view 1: Enable Depth based MAD prediction for extended view
+TargetBitAssign  		    : 0			# Manual assignment of target bit-rate
+ViewWiseTargetBits		    : 950000 315000 358000 		# View-wise target bit-rate setting
+
+#============ Rate Control URQ ======================
+#RateControl                         : 0                # 0: Disable rate control 1: Enable rate control with total target
+#DepthMADPred			    : 0		       # 0: Disable Depth based MAD prediction for extended view 1: Enable Depth based MAD prediction for extended view
+#TargetBitAssign  		    : 0			# Manual assignment of target bit-rate
+#ViewWiseTargetBits		    : 952 315 360 	# View-wise target bit-rate setting
+#TargetBitrate                       : 1500             # input target bitrate when RateCtrl is enable
+#NumLCUInUnit                        : 1                # Number of LCU in an Unit. Fraction is not allowed
+
 #========== multiview coding tools ==========
 IvMvPred                            : 1                # Inter-view motion prediction
Index: branches/HTM-8.2-dev0-KWU/cfg/3D-HEVC/fullCfg.cfg
===================================================================
--- branches/HTM-8.2-dev0-KWU/cfg/3D-HEVC/fullCfg.cfg	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/cfg/3D-HEVC/fullCfg.cfg	(revision 635)
@@ -230,4 +230,16 @@
 RCForceIntraQP                      : 0                # Rate control: force intra QP to be equal to initial QP
 
+DepthMADPred			    : 0		       # 0: Disable Depth based MAD prediction for extended view 1: Enable Depth based MAD prediction for extended view
+TargetBitAssign  		    : 0			# Manual assignment of target bit-rate
+ViewWiseTargetBits		    : 950000 315000 358000 		# View-wise target bit-rate setting
+
+#============ Rate Control URQ ======================
+#RateControl                         : 0                # 0: Disable rate control 1: Enable rate control with total target
+#DepthMADPred			    : 0		       # 0: Disable Depth based MAD prediction for extended view 1: Enable Depth based MAD prediction for extended view
+#TargetBitAssign  		    : 0			# Manual assignment of target bit-rate
+#ViewWiseTargetBits		    : 952 315 360 	# View-wise target bit-rate setting
+#TargetBitrate                       : 1500             # input target bitrate when RateCtrl is enable
+#NumLCUInUnit                        : 1                # Number of LCU in an Unit. Fraction is not allowed
+
 #========== multiview coding tools ==========
 IvMvPred                            : 1                # Inter-view motion prediction
Index: branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 635)
@@ -82,4 +82,8 @@
   m_codedPivotValue = NULL;
   m_targetPivotValue = NULL;
+
+#if KWU_RC_MADPRED_E0227
+  m_uiDepthMADPred = 0;
+#endif
 }
 
@@ -594,8 +598,24 @@
   ( "InitialQP",           m_RCInitialQP,               0, "Rate control: initial QP" )
   ( "RCForceIntraQP",      m_RCForceIntraQP,        false, "Rate control: force intra QP to be equal to initial QP" )
-#else
-  ("RateCtrl,-rc", m_enableRateCtrl, false, "Rate control on/off")
+
+#if KWU_RC_VIEWRC_E0227
+  ("ViewWiseTargetBits, -vtbr" ,  m_pchViewTargetBits,  std::vector<Int>(1, 32), "View-wise target bit-rate setting")
+  ("TargetBitAssign, -ta", m_bViewWiseRateCtrl, false, "View-wise rate control on/off")
+#endif
+#if KWU_RC_MADPRED_E0227
+  ("DepthMADPred, -dm", m_uiDepthMADPred, (UInt)0, "Depth based MAD prediction on/off")
+#endif
+#else
+  ("RateControl,-rc", m_enableRateCtrl, false, "Rate control on/off")
   ("TargetBitrate,-tbr", m_targetBitrate, 0, "Input target bitrate")
   ("NumLCUInUnit,-nu", m_numLCUInUnit, 0, "Number of LCUs in an Unit")
+
+#if KWU_RC_VIEWRC_E0227
+  ("ViewWiseTargetBits, -vtbr" ,  m_pchViewTargetBits,  std::vector<Int>(1, 32), "View-wise target bit-rate setting")
+  ("TargetBitAssign, -ta", m_bViewWiseRateCtrl, false, "View-wise rate control on/off")
+#endif
+#if KWU_RC_MADPRED_E0227
+  ("DepthMADPred, -dm", m_uiDepthMADPred, (UInt)0, "Depth based MAD prediction on/off")
+#endif
 #endif
 
@@ -2159,5 +2179,5 @@
     xConfirmPara( (numLCUInPic % m_numLCUInUnit) != 0, "total number of LCUs in a frame should be completely divided by NumLCUInUnit" );
 
-    m_iMaxDeltaQP       = MAX_DELTA_QP;
+    //m_iMaxDeltaQP       = MAX_DELTA_QP;
     m_iMaxCuDQPDepth    = MAX_CUDQP_DEPTH;
   }
@@ -2301,4 +2321,23 @@
     printf("InitialQP                    : %d\n", m_RCInitialQP );
     printf("ForceIntraQP                 : %d\n", m_RCForceIntraQP );
+
+#if KWU_RC_MADPRED_E0227
+    printf("Depth based MAD prediction   : %d\n", m_uiDepthMADPred);
+#endif
+#if KWU_RC_VIEWRC_E0227
+    printf("View-wise Rate control       : %d\n", m_bViewWiseRateCtrl);
+    if(m_bViewWiseRateCtrl)
+    {
+
+      printf("ViewWiseTargetBits           : ");
+      for (int i = 0 ; i < m_iNumberOfViews ; i++)
+        printf("%d ", m_pchViewTargetBits[i]);
+      printf("\n");
+    }
+    else
+    {
+      printf("TargetBitrate                : %d\n", m_RCTargetBitrate );
+    }
+#endif
   }
 #else
@@ -2308,4 +2347,23 @@
     printf("TargetBitrate                : %d\n", m_targetBitrate);
     printf("NumLCUInUnit                 : %d\n", m_numLCUInUnit);
+
+#if KWU_RC_MADPRED_E0227
+    printf("Depth based MAD prediction   : %d\n", m_uiDepthMADPred);
+#endif
+#if KWU_RC_VIEWRC_E0227
+    printf("View-wise Rate control       : %d\n", m_bViewWiseRateCtrl);
+    if(m_bViewWiseRateCtrl)
+    {
+
+      printf("ViewWiseTargetBits           : ");
+      for (int i = 0 ; i < m_iNumberOfViews ; i++)
+        printf("%d ", m_pchViewTargetBits[i]);
+      printf("\n");
+    }
+    else
+    {
+      printf("TargetBitrate                : %d\n", m_targetBitrate );
+    }
+#endif
   }
 #endif
Index: branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.h	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.h	(revision 635)
@@ -367,8 +367,24 @@
   Int       m_RCInitialQP;                        ///< inital QP for rate control
   Bool      m_RCForceIntraQP;                     ///< force all intra picture to use initial QP or not
+
+#if KWU_RC_VIEWRC_E0227
+  vector<Int>     m_pchViewTargetBits;
+  bool      m_bViewWiseRateCtrl;                              ///< Flag for using view-wise rate control
+#endif
+#if KWU_RC_MADPRED_E0227
+  UInt       m_uiDepthMADPred;
+#endif
 #else
   Bool      m_enableRateCtrl;                                   ///< Flag for using rate control algorithm
   Int       m_targetBitrate;                                 ///< target bitrate
   Int       m_numLCUInUnit;                                  ///< Total number of LCUs in a frame should be completely divided by the NumLCUInUnit
+
+#if KWU_RC_VIEWRC_E0227
+  vector<Int>     m_pchViewTargetBits;
+  bool      m_bViewWiseRateCtrl;                              ///< Flag for using view-wise rate control
+#endif
+#if KWU_RC_MADPRED_E0227
+  UInt       m_uiDepthMADPred;
+#endif
 #endif
   Int       m_useScalingListId;                               ///< using quantization matrix
Index: branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncTop.cpp	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncTop.cpp	(revision 635)
@@ -512,6 +512,11 @@
   m_cTEncTop.setSignHideFlag(m_signHideFlag);
 #if RATE_CONTROL_LAMBDA_DOMAIN
-  m_cTEncTop.setUseRateCtrl         ( m_RCEnableRateControl );
+  if(!m_cTEncTop.getIsDepth())    //only for texture
+    m_cTEncTop.setUseRateCtrl         ( m_RCEnableRateControl );
+  else
+    m_cTEncTop.setUseRateCtrl         ( 0 );
+#if !KWU_RC_VIEWRC_E0227
   m_cTEncTop.setTargetBitrate       ( m_RCTargetBitrate );
+#endif
   m_cTEncTop.setKeepHierBit         ( m_RCKeepHierarchicalBit );
   m_cTEncTop.setLCULevelRC          ( m_RCLCULevelRC );
@@ -519,8 +524,123 @@
   m_cTEncTop.setInitialQP           ( m_RCInitialQP );
   m_cTEncTop.setForceIntraQP        ( m_RCForceIntraQP );
-#else
-  m_cTEncTop.setUseRateCtrl     ( m_enableRateCtrl);
-  m_cTEncTop.setTargetBitrate   ( m_targetBitrate);
-  m_cTEncTop.setNumLCUInUnit    ( m_numLCUInUnit);
+
+#if KWU_RC_MADPRED_E0227
+  if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
+  {
+    m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_uiDepthMADPred       : 0);
+
+    if(m_cTEncTop.getUseDepthMADPred())
+      m_cTEncTop.setCamParam(&m_cCameraData);
+  }
+#endif
+#if KWU_RC_VIEWRC_E0227
+  if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
+  {
+    m_cTEncTop.setUseViewWiseRateCtrl(m_bViewWiseRateCtrl);
+
+    if(m_iNumberOfViews == 1)
+    {
+      if(m_bViewWiseRateCtrl)
+      {
+        m_cTEncTop.setTargetBitrate(m_pchViewTargetBits[layerIdInVps>>1]);
+      }
+      else
+        m_cTEncTop.setTargetBitrate       ( m_RCTargetBitrate );
+    }
+    else
+    {
+      if(m_bViewWiseRateCtrl)
+      {
+        m_cTEncTop.setTargetBitrate(m_pchViewTargetBits[layerIdInVps>>1]);
+      }
+      else
+      {
+        if(m_iNumberOfViews == 2)
+        {
+          if(m_cTEncTop.getViewId() == 0)
+            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*80)/100 );
+          else if(m_cTEncTop.getViewId() == 1)
+            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*20)/100 );
+        }
+        else if(m_iNumberOfViews == 3)
+        {
+          if(m_cTEncTop.getViewId() == 0)
+            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*66)/100 );
+          else if(m_cTEncTop.getViewId() == 1)
+            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*17)/100 );
+          else if(m_cTEncTop.getViewId() == 2)
+            m_cTEncTop.setTargetBitrate              ( (m_RCTargetBitrate*17)/100 );
+        }
+        else
+          m_cTEncTop.setTargetBitrate              ( m_RCTargetBitrate );
+      }
+    }
+  }
+#endif
+#else
+  if(!m_cTEncTop.getIsDepth())    //only for texture
+  {
+    m_cTEncTop.setUseRateCtrl         ( m_enableRateCtrl );
+#if !KWU_RC_VIEWRC_E0227
+    m_cTEncTop.setTargetBitrate       ( m_targetBitrate );
+#endif
+    m_cTEncTop.setNumLCUInUnit        ( m_numLCUInUnit);
+  }
+  else
+    m_cTEncTop.setUseRateCtrl         ( 0 );
+  
+#if KWU_RC_MADPRED_E0227
+  if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
+  {
+    m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_uiDepthMADPred       : 0);
+
+    if(m_cTEncTop.getUseDepthMADPred())
+      m_cTEncTop.setCamParam(&m_cCameraData);
+  }
+#endif
+
+#if KWU_RC_VIEWRC_E0227
+  if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
+  {
+    m_cTEncTop.setUseViewWiseRateCtrl(m_bViewWiseRateCtrl);
+    if(m_iNumberOfViews == 1)
+    {
+      if(m_bViewWiseRateCtrl)
+      {
+        m_cTEncTop.setTargetBitrate(m_pchViewTargetBits[layerIdInVps>>1]);
+      }
+      else
+        m_cTEncTop.setTargetBitrate       ( m_targetBitrate );
+    }
+    else
+    {
+      if(m_bViewWiseRateCtrl)
+      {
+        m_cTEncTop.setTargetBitrate(m_pchViewTargetBits[layerIdInVps>>1]);
+      }
+      else
+      {
+        if(m_iNumberOfViews == 2)
+        {
+          if(m_cTEncTop.getViewId() == 0)
+            m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*80)/100 );
+          else if(m_cTEncTop.getViewId() == 1)
+            m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*20)/100 );
+        }
+        else if(m_iNumberOfViews == 3)
+        {
+          if(m_cTEncTop.getViewId() == 0)
+            m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*66)/100 );
+          else if(m_cTEncTop.getViewId() == 1)
+            m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*17)/100 );
+          else if(m_cTEncTop.getViewId() == 2)
+            m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*17)/100 );
+        }
+        else
+          m_cTEncTop.setTargetBitrate              ( m_targetBitrate );
+      }
+    }
+  }
+#endif
 #endif
   m_cTEncTop.setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
@@ -669,5 +789,9 @@
   for(Int layer=0; layer<m_numberOfLayers; layer++)
   {
+#if KWU_RC_MADPRED_E0227
+    m_acTEncTopList[layer]->init( this );
+#else
     m_acTEncTopList[layer]->init( );
+#endif
   }
 #else
@@ -789,4 +913,15 @@
       }
     }
+
+#if !RATE_CONTROL_LAMBDA_DOMAIN
+    for(Int layer=0; layer < m_numberOfLayers; layer++ )
+    {
+      if(m_acTEncTopList[layer]->getUseRateCtrl()  && !m_acTEncTopList[layer]->getIsDepth())
+      {
+        m_acTEncTopList[layer]->getRateCtrl()->updateRCGOPStatus();
+      }
+    }
+#endif
+
     gopSize = maxGopSize;
   }
Index: branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncTop.h	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncTop.h	(revision 635)
@@ -50,4 +50,7 @@
 #endif
 
+#if KWU_RC_MADPRED_E0227
+class TEncTop;
+#endif
 //! \ingroup TAppEncoder
 //! \{
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TAppCommon/TAppComCamPara.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TAppCommon/TAppComCamPara.cpp	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TAppCommon/TAppComCamPara.cpp	(revision 635)
@@ -1526,2 +1526,63 @@
 }
 #endif
+
+
+#if KWU_RC_MADPRED_E0227
+Void
+  TAppComCamPara::RCGetZNearZFar( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar )
+{
+  UInt uiFoundLine = -1;
+  if( !xGetCameraDataRow( m_aiBaseViews[iView], uiFrame, uiFoundLine ) || !( m_aadCameraParameters[ uiFoundLine ].size() < 8 ) )
+  {
+    rdZNear = m_aadCameraParameters[ uiFoundLine ][ 6 ];
+    rdZFar  = m_aadCameraParameters[ uiFoundLine ][ 7 ];
+  }
+  else
+  {
+    std::cerr << "No ZNear or no ZFar for View " << (Double)iView / m_dViewNumPrec << " and Frame " << uiFrame << " given in CameraParameterFile" << std::endl;
+    exit( EXIT_FAILURE );
+  }
+}
+
+
+Void
+  TAppComCamPara::RCGetGeometryData( Int iView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated )
+{
+  UInt uiFoundLine = -1;
+  if ( !xGetCameraDataRow( m_aiBaseViews[iView], uiFrame, uiFoundLine ) )
+  {
+    AOT( m_aadCameraParameters[ uiFoundLine ].size() < 6 );
+    rbInterpolated = false;
+    rdFocalLength =  m_aadCameraParameters[ uiFoundLine ][ 3 ];
+    rdPosition    =  m_aadCameraParameters[ uiFoundLine ][ 4 ];
+    rdCameraShift =  m_aadCameraParameters[ uiFoundLine ][ 5 ];
+  }
+  else
+  {
+    UInt uiLeftViewLine;
+    UInt uiRightViewLine;
+    Int  iLeftView;
+    Int  iRightView;
+    Int  iDummy;
+
+    if( !xGetLeftRightView( iView, m_aiViewsInCfgFile, iLeftView, iRightView, iDummy, iDummy ) ||
+      xGetCameraDataRow( iLeftView,  uiFrame, uiLeftViewLine  )                             ||
+      xGetCameraDataRow( iRightView, uiFrame, uiRightViewLine )
+      )
+    {
+      std::cerr << "No Left or no Right View next to View " << (Double)iView / m_dViewNumPrec << " for Frame " << uiFrame << " given in CameraParameterFile" << std::endl;
+      AOT(true);
+      exit( EXIT_FAILURE );
+    }
+    AOT( m_aadCameraParameters[ uiLeftViewLine  ].size() < 6 );
+    AOT( m_aadCameraParameters[ uiRightViewLine ].size() < 6 );
+
+    // Linear Interpolation
+    Double dFactor = ( (Double)( iView - iLeftView ) ) / ( (Double)( iRightView - iLeftView ) );
+    rdFocalLength  = m_aadCameraParameters[ uiLeftViewLine ][ 3 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 3 ] - m_aadCameraParameters[ uiLeftViewLine ][ 3 ] );
+    rdPosition     = m_aadCameraParameters[ uiLeftViewLine ][ 4 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 4 ] - m_aadCameraParameters[ uiLeftViewLine ][ 4 ] );
+    rdCameraShift  = m_aadCameraParameters[ uiLeftViewLine ][ 5 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 5 ] - m_aadCameraParameters[ uiLeftViewLine ][ 5 ] );
+    rbInterpolated = true;
+  }
+}
+#endif
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TAppCommon/TAppComCamPara.h
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TAppCommon/TAppComCamPara.h	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TAppCommon/TAppComCamPara.h	(revision 635)
@@ -220,4 +220,9 @@
   Int**               getCodedScale             ()  { return m_aaiCodedScale;           }
   Int**               getCodedOffset            ()  { return m_aaiCodedOffset;          }
+
+#if KWU_RC_MADPRED_E0227
+  Void  RCGetZNearZFar             ( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar );
+  Void  RCGetGeometryData          ( Int dView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated );
+#endif
 };
 
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TComRdCost.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TComRdCost.cpp	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TComRdCost.cpp	(revision 635)
@@ -614,5 +614,5 @@
 #endif
 
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
 UInt TComRdCost::getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height )
 {
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TComRdCost.h
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TComRdCost.h	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TComRdCost.h	(revision 635)
@@ -343,5 +343,5 @@
 #endif
 
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
   UInt   getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height );
 #endif
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TComSlice.cpp	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TComSlice.cpp	(revision 635)
@@ -472,6 +472,6 @@
   {
     // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
-    //  If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-    //  Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    // ?If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
+    // ?Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     if (getRapPicFlag())
     {
@@ -827,10 +827,10 @@
     // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
 #if H_MV
-    // â If nuh_layer_id is equal to 0 and the current picture is a BLA picture or a CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-    // â Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    // ??If nuh_layer_id is equal to 0 and the current picture is a BLA picture or a CRA picture, the value of NumPocTotalCurr shall be equal to 0.
+    // ??Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     if ( getRapPicFlag() && m_layerId == 0 )
 #else
-    // â If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-    // â Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    // ??If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
+    // ??Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     if (getRapPicFlag())
 #endif
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TypeDef.h	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TypeDef.h	(revision 635)
@@ -306,6 +306,10 @@
 #define TICKET_1090_FIX                             1
 
+#if RATE_CONTROL_LAMBDA_DOMAIN
 #define RC_FIX                                      1  /// suggested fix for M0036
 #define RATE_CONTROL_INTRA                          1  ///< JCTVC-M0257, rate control for intra 
+#endif
+#define KWU_RC_VIEWRC_E0227                         0  ///< JCT3V-E0227, view-wise target bitrate allocation
+#define KWU_RC_MADPRED_E0227                        0  ///< JCT3V-E0227, inter-view MAD prediction
 
 #define MAX_CPB_CNT                     32  ///< Upper bound of (cpb_cnt_minus1 + 1)
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCfg.h	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCfg.h	(revision 635)
@@ -310,8 +310,22 @@
   Int       m_RCInitialQP;
   Bool      m_RCForceIntraQP;
+
+#if KWU_RC_MADPRED_E0227
+  UInt       m_uiDepthMADPred;
+#endif
+#if KWU_RC_VIEWRC_E0227
+  Bool      m_bViewWiseRateCtrl;
+#endif
 #else
   Bool      m_enableRateCtrl;                                ///< Flag for using rate control algorithm
   Int       m_targetBitrate;                                 ///< target bitrate
   Int       m_numLCUInUnit;                                  ///< Total number of LCUs in a frame should be divided by the NumLCUInUnit
+
+#if KWU_RC_MADPRED_E0227
+  UInt       m_uiDepthMADPred;
+#endif
+#if KWU_RC_VIEWRC_E0227
+  Bool      m_bViewWiseRateCtrl;
+#endif
 #endif
   Bool      m_TransquantBypassEnableFlag;                     ///< transquant_bypass_enable_flag setting in PPS.
@@ -826,4 +840,13 @@
   Bool      getForceIntraQP        ()              { return m_RCForceIntraQP;        }
   Void      setForceIntraQP        ( Bool b )      { m_RCForceIntraQP = b;           }
+
+#if KWU_RC_MADPRED_E0227
+  UInt      getUseDepthMADPred    ()                { return m_uiDepthMADPred;        }
+  Void      setUseDepthMADPred    (UInt b)          { m_uiDepthMADPred    = b;        }
+#endif
+#if KWU_RC_VIEWRC_E0227
+  Bool      getUseViewWiseRateCtrl    ()                { return m_bViewWiseRateCtrl;        }
+  Void      setUseViewWiseRateCtrl    (Bool b)          { m_bViewWiseRateCtrl    = b;        }
+#endif
 #else
   Bool      getUseRateCtrl    ()                { return m_enableRateCtrl;    }
@@ -833,4 +856,13 @@
   Int       getNumLCUInUnit   ()                { return m_numLCUInUnit;      }
   Void      setNumLCUInUnit   (Int numLCUs)     { m_numLCUInUnit   = numLCUs; }
+
+#if KWU_RC_MADPRED_E0227
+  UInt      getUseDepthMADPred    ()                { return m_uiDepthMADPred;        }
+  Void      setUseDepthMADPred    (UInt b)          { m_uiDepthMADPred    = b;        }
+#endif
+#if KWU_RC_VIEWRC_E0227
+  Bool      getUseViewWiseRateCtrl    ()                { return m_bViewWiseRateCtrl;        }
+  Void      setUseViewWiseRateCtrl    (Bool b)          { m_bViewWiseRateCtrl    = b;        }
+#endif
 #endif
   Bool      getTransquantBypassEnableFlag()           { return m_TransquantBypassEnableFlag; }
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.cpp	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.cpp	(revision 635)
@@ -103,8 +103,9 @@
   
   m_bEncodeDQP = false;
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
   m_LCUPredictionSAD = 0;
   m_addSADDepth      = 0;
   m_temporalSAD      = 0;
+  m_spatialSAD       = 0;
 #endif
 
@@ -241,5 +242,10 @@
   
   m_bUseSBACRD        = pcEncTop->getUseSBACRD();
-  m_pcRateCtrl        = pcEncTop->getRateCtrl();
+  if(!pcEncTop->getIsDepth())
+    m_pcRateCtrl        = pcEncTop->getRateCtrl();
+  else
+  {
+    m_pcRateCtrl = NULL;
+  }
 }
 
@@ -256,8 +262,9 @@
   m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
 
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
   m_addSADDepth      = 0;
   m_LCUPredictionSAD = 0;
   m_temporalSAD      = 0;
+  m_spatialSAD       = 0;
 #endif
 
@@ -464,5 +471,5 @@
 
 #if RATE_CONTROL_LAMBDA_DOMAIN
-  if ( m_pcEncCfg->getUseRateCtrl() )
+  if ( m_pcEncCfg->getUseRateCtrl() && !m_pcEncCfg->getIsDepth() )
   {
     iMinQP = m_pcRateCtrl->getRCQP();
@@ -470,5 +477,5 @@
   }
 #else
-  if(m_pcEncCfg->getUseRateCtrl())
+  if(m_pcEncCfg->getUseRateCtrl() && !m_pcEncCfg->getIsDepth())
   {
     Int qp = m_pcRateCtrl->getUnitQP();
@@ -671,9 +678,17 @@
     }
 
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
     if ( uiDepth <= m_addSADDepth )
     {
       m_LCUPredictionSAD += m_temporalSAD;
       m_addSADDepth = uiDepth;
+    }
+#endif
+#if !RATE_CONTROL_LAMBDA_DOMAIN
+    if(m_pcEncCfg->getUseRateCtrl())
+    {
+      Int qp = m_pcRateCtrl->getUnitQP();
+      iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
+      iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
     }
 #endif
@@ -1012,4 +1027,11 @@
           {
             xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
+#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
+            if ( uiDepth <= m_addSADDepth )
+            {
+              m_LCUPredictionSAD += m_spatialSAD;
+              m_addSADDepth = uiDepth;
+            }
+#endif
             rpcTempCU->initEstData( uiDepth, iQP );
             if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
@@ -1146,5 +1168,5 @@
   }
 #if RATE_CONTROL_LAMBDA_DOMAIN
-  if ( m_pcEncCfg->getUseRateCtrl() )
+  if ( m_pcEncCfg->getUseRateCtrl() && !m_pcEncCfg->getIsDepth() )
   {
     iMinQP = m_pcRateCtrl->getRCQP();
@@ -1152,5 +1174,5 @@
   }
 #else
-  if(m_pcEncCfg->getUseRateCtrl())
+  if(m_pcEncCfg->getUseRateCtrl() && !m_pcEncCfg->getIsDepth())
   {
     Int qp = m_pcRateCtrl->getUnitQP();
@@ -2102,6 +2124,17 @@
 #endif
 
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if RATE_CONTROL_LAMBDA_DOMAIN  && !M0036_RC_IMPROVEMENT
+#if KWU_RC_MADPRED_E0227
   if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
+  {
+    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
+      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
+      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
+    m_temporalSAD = (Int)SAD;
+  }
+#endif
+#endif
+#if !RATE_CONTROL_LAMBDA_DOMAIN  && KWU_RC_MADPRED_E0227
+  if ( m_pcEncCfg->getUseRateCtrl() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
   {
     UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
@@ -2235,4 +2268,26 @@
   rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
   
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if KWU_RC_MADPRED_E0227
+  UChar uhDepth = rpcTempCU->getDepth( 0 );
+  if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
+  {
+    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
+      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
+      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
+    m_spatialSAD = (Int)SAD;
+  }
+#endif
+#endif
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
+  UChar uhDepth = rpcTempCU->getDepth( 0 );
+  if ( m_pcEncCfg->getUseRateCtrl() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
+  {
+    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
+      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
+      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
+    m_spatialSAD = (Int)SAD;
+  }
+#endif
   xCheckDQP( rpcTempCU );
   xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth);
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.h	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.h	(revision 635)
@@ -102,8 +102,9 @@
   Bool                    m_bUseSBACRD;
   TEncRateCtrl*           m_pcRateCtrl;
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
   UInt                    m_LCUPredictionSAD;
   Int                     m_addSADDepth;
   Int                     m_temporalSAD;
+  Int                     m_spatialSAD;
 #endif
 public:
@@ -124,5 +125,5 @@
   
   Void setBitCounter        ( TComBitCounter* pcBitCounter ) { m_pcBitCounter = pcBitCounter; }
-#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
   UInt getLCUPredictionSAD() { return m_LCUPredictionSAD; }
 #endif
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 635)
@@ -153,4 +153,8 @@
 #endif
 #endif
+
+#if !RATE_CONTROL_LAMBDA_DOMAIN
+  m_pcRateCtrl           = pcTEncTop->getRateCtrl();
+#endif
 }
 
@@ -977,4 +981,11 @@
       }
       m_pcRateCtrl->initRCPic( frameLevel );
+
+#if KWU_RC_MADPRED_E0227
+      if(m_pcCfg->getLayerId() != 0)
+        m_pcRateCtrl->getRCPic()->setIVPic( m_pcEncTop->getEncTop()->getTEncTop(0)->getRateCtrl()->getRCPic() );
+      //getEncTop()->getEncTop();//->getTEncTop(0);//->getUseRateCtrl()->getRCPic();
+#endif
+
       estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits();
 
@@ -1021,4 +1032,15 @@
       else    // normal case
       {
+#if KWU_RC_MADPRED_E0227
+        if(m_pcRateCtrl->getLayerID() != 0)
+        {
+          list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
+          lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambdaIV( listPreviousPicture, pcSlice->getPOC() );
+          //printf("lambda : %lf\n", lambda);
+          sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
+        }
+        else
+        {
+#endif
         list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
 #if RATE_CONTROL_INTRA
@@ -1028,4 +1050,7 @@
 #endif
         sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
+#if KWU_RC_MADPRED_E0227
+        }
+#endif
       }
 
@@ -2191,10 +2216,5 @@
       delete[] pcSubstreamsOut;
   }
-#if !RATE_CONTROL_LAMBDA_DOMAIN
-  if(m_pcCfg->getUseRateCtrl())
-  {
-    m_pcRateCtrl->updateRCGOPStatus();
-  }
-#endif
+
   delete pcBitstreamRedirect;
 
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncGOP.h	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncGOP.h	(revision 635)
@@ -57,4 +57,7 @@
 #include "TEncAnalyze.h"
 #include "TEncRateCtrl.h"
+#if KWU_RC_MADPRED_E0227
+#include "../App/TAppEncoder/TAppEncTop.h"
+#endif
 #include <vector>
 
@@ -176,5 +179,9 @@
   Void  preLoopFilterPicAll  ( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits );
 #endif
-  
+
+#if KWU_RC_MADPRED_E0227
+  TEncTop* getEncTop() { return m_pcEncTop; }
+#endif
+
   TEncSlice*  getSliceEncoder()   { return m_pcSliceEncoder; }
   NalUnitType getNalUnitType( Int pocCurr, Int lastIdr );
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.cpp	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.cpp	(revision 635)
@@ -537,4 +537,9 @@
   m_lastPicture  = NULL;
 #endif
+
+#if KWU_RC_MADPRED_E0227
+  m_lastIVPicture = NULL;
+#endif
+
   m_picActualHeaderBits = 0;
 #if !M0036_RC_IMPROVEMENT
@@ -544,4 +549,8 @@
   m_picQP               = 0;
   m_picLambda           = 0.0;
+
+#if KWU_RC_MADPRED_E0227
+  m_IVtotalMAD            = 0.0;
+#endif
 }
 
@@ -621,5 +630,22 @@
 }
 
+#if KWU_RC_MADPRED_E0227
+Void TEncRCPic::addToPictureLsitIV( list<TEncRCPic*>& listPreviousPictures )
+{
+  m_lastIVPicture = NULL;
+  m_lastIVPicture = this;
+}
+
+Void TEncRCPic::setIVPic( TEncRCPic* BaseRCPic )
+{
+  m_lastIVPicture = BaseRCPic;
+}
+#endif
+
+#if KWU_RC_MADPRED_E0227
+Void TEncRCPic::create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures, Int LayerID )
+#else
 Void TEncRCPic::create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures )
+#endif
 {
   destroy();
@@ -673,4 +699,10 @@
       Int currHeight = ( (j == picHeightInLCU-1) ? picHeight - LCUHeight*(picHeightInLCU-1) : LCUHeight );
       m_LCUs[LCUIdx].m_numberOfPixel = currWidth * currHeight;
+
+#if KWU_RC_MADPRED_E0227
+      m_LCUs[LCUIdx].m_CUWidth = currWidth;
+      m_LCUs[LCUIdx].m_CUHeight = currHeight;
+      m_LCUs[LCUIdx].m_IVMAD = -1.0;
+#endif
     }
   }
@@ -683,7 +715,41 @@
   m_picLambda           = 0.0;
 
+
+#if KWU_RC_MADPRED_E0227
+  m_LayerID = LayerID;
+  m_lastIVPicture = NULL;
+  m_IVtotalMAD            = 0.0;
+#endif
+
+
 #if !M0036_RC_IMPROVEMENT
   m_lastPicture = NULL;
   list<TEncRCPic*>::reverse_iterator it;
+  for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
+  {
+    if ( (*it)->getFrameLevel() == m_frameLevel )
+    {
+      m_lastPicture = (*it);
+      break;
+    }
+  }
+#endif
+
+#if KWU_RC_MADPRED_E0227
+  list<TEncRCPic*>::reverse_iterator it;
+  if( m_LayerID != 0)
+  {
+    m_lastIVPicture = NULL;
+    for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
+    {
+      if ( (*it)->getLayerID() == 0 )
+      {
+        m_lastIVPicture = (*it);
+        break;
+      }
+    }
+  }
+
+  m_lastPicture = NULL;
   for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
   {
@@ -856,4 +922,71 @@
 }
 
+
+#if KWU_RC_MADPRED_E0227
+Double TEncRCPic::estimatePicLambdaIV( list<TEncRCPic*>& listPreviousPictures, Int CurPOC )
+{
+  Double alpha         = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
+  Double beta          = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
+  Double bpp       = (Double)m_targetBits/(Double)m_numberOfPixel;
+  Double estLambda = alpha * pow( bpp, beta );
+  Double lastLevelLambda = -1.0;
+  Double lastPicLambda   = -1.0;
+  Double lastValidLambda = -1.0;
+  list<TEncRCPic*>::iterator it;
+
+  if(listPreviousPictures.size() == 0 || CurPOC%8 == 0)
+  {
+    lastLevelLambda = m_lastIVPicture->getPicActualLambda();
+    lastPicLambda     = m_lastIVPicture->getPicActualLambda();
+  }
+  else
+  {
+    for ( it = listPreviousPictures.begin(); it != listPreviousPictures.end(); it++ )
+    {
+      if ( (*it)->getFrameLevel() == m_frameLevel )
+      {
+        lastLevelLambda = (*it)->getPicActualLambda();
+      }
+      lastPicLambda     = (*it)->getPicActualLambda();
+
+      if ( lastPicLambda > 0.0 )
+      {
+        lastValidLambda = lastPicLambda;
+      }
+    }
+  }
+
+  if ( lastLevelLambda > 0.0 )
+  {
+    lastLevelLambda = Clip3( 0.1, 10000.0, lastLevelLambda );
+    estLambda = Clip3( lastLevelLambda * pow( 2.0, -3.0/3.0 ), lastLevelLambda * pow( 2.0, 3.0/3.0 ), estLambda );
+  }
+
+  if ( lastPicLambda > 0.0 )
+  {
+    lastPicLambda = Clip3( 0.1, 2000.0, lastPicLambda );
+    estLambda = Clip3( lastPicLambda * pow( 2.0, -10.0/3.0 ), lastPicLambda * pow( 2.0, 10.0/3.0 ), estLambda );
+  }
+  else if ( lastValidLambda > 0.0 )
+  {
+    lastValidLambda = Clip3( 0.1, 2000.0, lastValidLambda );
+    estLambda = Clip3( lastValidLambda * pow(2.0, -10.0/3.0), lastValidLambda * pow(2.0, 10.0/3.0), estLambda );
+  }
+  else
+  {
+    estLambda = Clip3( 0.1, 10000.0, estLambda );
+  }
+
+  if ( estLambda < 0.1 )
+  {
+    estLambda = 0.1;
+  }
+
+  m_estPicLambda = estLambda;
+  return estLambda;
+}
+#endif
+
+
 #if RATE_CONTROL_INTRA
 Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType)  
@@ -937,4 +1070,119 @@
 }
 
+
+#if KWU_RC_MADPRED_E0227
+Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double BasePos, Double CurPos, Double FocalLen, Double Znear, Double Zfar, Int Direction, Int* iDisparity )
+{
+  Int   LCUIdx    = getLCUCoded();
+  Double bpp      = -1.0;
+  Int avgBits     = 0;
+#if !M0036_RC_IMPROVEMENT
+  Double totalMAD = -1.0;
+  Double MAD      = -1.0;
+#endif
+
+  Double totalMAD = -1.0;
+  Double MAD      = -1.0;
+
+  Double IVMAD      = -1.0;
+  Double SAD = 0.0;
+  Int     x, y;
+  Int Sum = 0;
+
+  {
+    Pel*  pOrg    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
+    Pel*  pRec    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvPred()->getLumaAddr(pcCU->getAddr(), 0);
+    Pel*  pDep    = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
+    Int   iStride = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getStride();
+
+    Int   iWidth  = m_LCUs[ LCUIdx ].m_CUWidth;
+    Int   iHeight = m_LCUs[ LCUIdx ].m_CUHeight;
+
+    for( y = 0 ; y < pcCU->getSlice()->getSPS()->getMaxCUHeight() ; y+=8)
+    {
+      for( x = 0 ; x < pcCU->getSlice()->getSPS()->getMaxCUWidth() ; x+=8)
+      {
+        Sum += pDep[x];
+      }
+      pDep += iStride;
+    }
+
+    Double AvgDepth = (Double)Sum/((pcCU->getSlice()->getSPS()->getMaxCUHeight()/8)*(pcCU->getSlice()->getSPS()->getMaxCUWidth()/8));
+
+    //Int iDisparity = pDepthGen->RCGetDisparityFromVirtDepth(0, (Int)AvgDepth);
+
+    Double dFL = FocalLen * abs( BasePos - CurPos );
+    Double dZ  = abs( 1.0 / Znear - 1.0 / Zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / Zfar);
+    *iDisparity = (Int)(Direction*dFL * dZ);
+    Int shift = DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8);
+
+    Int Disp = *iDisparity;
+    Int PosX, PosY;
+    pcCU->getPosInPic(0, PosX, PosY);
+    if((PosX + *iDisparity) < 0 || (PosX + *iDisparity + iWidth) >= pcCU->getSlice()->getSPS()->getMaxCUWidth())
+      Disp = 0;
+
+    for( y = 0; y < iHeight; y++ )
+    {
+      for( x = 0; x < iWidth; x++ )
+      {
+        SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + Disp)]
+                  - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + Disp)] )>>shift;
+      }
+      pOrg += iStride;
+      pRec += iStride;
+    }
+    IVMAD = SAD / (Double)(iHeight * iWidth);
+    IVMAD = IVMAD * IVMAD;
+
+    m_LCUs[ LCUIdx ].m_IVMAD = IVMAD;
+    if(m_lastPicture)
+      m_LCUs[ LCUIdx ].m_MAD = m_lastPicture->getLCU(LCUIdx).m_MAD;
+
+    MAD = m_LCUs[ LCUIdx ].m_IVMAD;
+
+    if(m_lastPicture)
+    {
+      totalMAD = m_lastPicture->getTotalMAD();      // get total MAD of temporal frame
+      for ( Int i=0; i<LCUIdx; i++ )
+      {
+        totalMAD -= m_lastPicture->getLCU(i).m_MAD;
+      }
+    }
+    else
+    {
+      totalMAD = m_lastIVPicture->getTotalMAD();      // get total MAD of inter-view frame
+      for ( Int i=0; i<LCUIdx; i++ )
+      {
+        totalMAD -= m_lastIVPicture->getLCU(i).m_MAD;
+      }
+    }
+
+
+    if ( totalMAD > 0.1 )
+    {
+      avgBits = Int( (m_bitsLeft * MAD) / totalMAD );
+    }
+    else
+    {
+      avgBits = Int( (m_bitsLeft) / m_LCULeft );
+    }
+  }
+
+  if ( avgBits < 5 )
+  {
+    avgBits = 5;
+  }
+
+  bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel;
+  m_LCUs[ LCUIdx ].m_targetBits = avgBits;
+
+  return bpp;
+}
+#endif
+
+
+
+
 Double TEncRCPic::getLCUEstLambda( Double bpp )
 {
@@ -1185,5 +1433,6 @@
   }
   m_picLambda           = averageLambda;
-#if !M0036_RC_IMPROVEMENT
+#if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227
+  m_totalMAD = 0;
   for ( Int i=0; i<m_numberOfLCU; i++ )
   {
@@ -1393,5 +1642,9 @@
 
 #if M0036_RC_IMPROVEMENT
+#if KWU_RC_MADPRED_E0227
+Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP], Int LayerID )
+#else
 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
+#endif
 #else
 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
@@ -1607,4 +1860,8 @@
   }
 
+#if KWU_RC_MADPRED_E0227
+  setLayerID(LayerID);
+#endif
+
   delete[] bitsRatio;
   delete[] GOPID2Level;
@@ -1614,5 +1871,9 @@
 {
   m_encRCPic = new TEncRCPic;
+#if KWU_RC_MADPRED_E0227
+  m_encRCPic->create( m_encRCSeq, m_encRCGOP, frameLevel, m_listRCPictures, m_LayerID );
+#else
   m_encRCPic->create( m_encRCSeq, m_encRCGOP, frameLevel, m_listRCPictures );
+#endif
 }
 
@@ -1815,6 +2076,6 @@
   m_sourceHeightInLCU        = (sourceHeight / maxCUHeight) + (( sourceHeight %  maxCUHeight) ? 1 : 0);  
   m_isLowdelay               = (sizeIntraPeriod == -1) ? true : false;
-  m_prevBitrate              = ( targetKbps << 10 );  // in units of 1,024 bps
-  m_currBitrate              = ( targetKbps << 10 );
+  m_prevBitrate              = ( targetKbps * 1000 );  // in units of 1,024 bps
+  m_currBitrate              = ( targetKbps * 1000 );
   m_frameRate                = frameRate;
   m_refFrameNum              = m_isLowdelay ? (sizeGOP) : (sizeGOP>>1);
@@ -2192,5 +2453,5 @@
 
   Pel*  pOrg   = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
-  Pel*  pRec   = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);
+  Pel*  pRec   = pcCU->getPic()->getPicYuvPred()->getLumaAddr(pcCU->getAddr(), 0);
   Int   stride = pcCU->getPic()->getStride();
 
@@ -2212,4 +2473,57 @@
 }
 
+
+#if KWU_RC_MADPRED_E0227
+Void  TEncRateCtrl::updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int iQP, Double BasePos, Double CurPos, Double FocalLen, Double Znear, Double Zfar, Int Direction)
+{
+  Int     x, y;
+  double dMAD = 0.0;
+  Int Sum = 0;
+  Double SAD = 0.0;
+
+  Pel*  pOrg    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
+  Pel*  pRec    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvPred()->getLumaAddr(pcCU->getAddr(), 0);
+  Pel*  pDep    = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
+  Int   iStride = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getStride();
+
+  Int   iWidth  = m_pcLCUData[m_indexLCU].m_widthInPixel;
+  Int   iHeight = m_pcLCUData[m_indexLCU].m_heightInPixel;
+
+  for( y = 0 ; y < pcCU->getSlice()->getSPS()->getMaxCUHeight() ; y+=8)
+  {
+    for( x = 0 ; x < pcCU->getSlice()->getSPS()->getMaxCUWidth() ; x+=8)
+    {
+      Sum += pDep[x];
+    }
+    pDep += iStride;
+  }
+
+  Double AvgDepth = (Double)Sum/((pcCU->getSlice()->getSPS()->getMaxCUHeight()/8)*(pcCU->getSlice()->getSPS()->getMaxCUWidth()/8));
+
+  //Int iDisparity = pDepthGen->RCGetDisparityFromVirtDepth(0, (Int)AvgDepth);
+
+  Double dFL = FocalLen * abs( BasePos - CurPos );
+  Double dZ  = abs( 1.0 / Znear - 1.0 / Zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / Zfar);
+  Int   iDisparity = (Int)(Direction*dFL * dZ);
+  Int shift = DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8);
+  Int Disp = iDisparity;
+
+  for( y = 0; y < iHeight; y++ )
+  {
+    for( x = 0; x < iWidth; x++ )
+    {
+      SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + Disp)]
+      - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + Disp)] )>>shift;
+    }
+    pOrg += iStride;
+    pRec += iStride;
+  }
+  m_pcLCUData[m_indexLCU].m_qp   = iQP;
+  m_pcLCUData[m_indexLCU].m_costMAD  = (SAD /(Double)(iWidth*iHeight));
+  m_pcLCUData[m_indexLCU].m_bits = (Int)uiBits;
+}
+#endif
+
+
 Double TEncRateCtrl::xAdjustmentBits(Int& reductionBits, Int& compensationBits)
 {
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.h
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.h	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.h	(revision 635)
@@ -98,4 +98,12 @@
   Int m_targetBitsLeft;
 #endif
+
+#if KWU_RC_MADPRED_E0227
+  Double m_MAD;
+
+  Int m_CUWidth;
+  Int m_CUHeight;
+  Double m_IVMAD;
+#endif
 };
 
@@ -248,7 +256,14 @@
 
 public:
+#if KWU_RC_MADPRED_E0227
+  Void create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures, Int LayerID );
+#else
   Void create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures );
+#endif
   Void destroy();
 
+#if KWU_RC_MADPRED_E0227
+  Double estimatePicLambdaIV( list<TEncRCPic*>& listPreviousPictures, Int CurPOC );
+#endif
 #if !RATE_CONTROL_INTRA
   Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures );
@@ -267,4 +282,9 @@
   Double getLCUTargetBpp();
 #endif
+
+#if KWU_RC_MADPRED_E0227
+  Double getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double BasePos, Double CurPos, Double FocalLen, Double Znear, Double Zfar, Int Direction, Int* iDisparity );
+#endif
+
   Double getLCUEstLambda( Double bpp );
   Int    getLCUEstQP( Double lambda, Int clipPicQP );
@@ -282,4 +302,10 @@
 
   Void addToPictureLsit( list<TEncRCPic*>& listPreviousPictures );
+
+#if KWU_RC_MADPRED_E0227
+  Void addToPictureLsitIV( list<TEncRCPic*>& listPreviousPictures );
+  Void setIVPic( TEncRCPic* BaseRCPic );
+#endif
+
 #if !M0036_RC_IMPROVEMENT
   Double getEffectivePercentage();
@@ -322,4 +348,12 @@
 #endif
 
+#if KWU_RC_MADPRED_E0227
+  Double getTotalMAD()                                    { return m_totalMAD; }
+  Void   setTotalMAD( Double MAD )                        { m_totalMAD = MAD; }
+
+  Double getIVTotalMAD()                                    { return m_IVtotalMAD; }
+  Void   setIVTotalMAD( Double MAD )                        { m_IVtotalMAD = MAD; }
+#endif
+
   Int  getPicActualBits()                                 { return m_picActualBits; }
   Int  getPicActualQP()                                   { return m_picQP; }
@@ -330,4 +364,9 @@
   Void setPicEstLambda( Double lambda )                   { m_picLambda = lambda; }
 
+#if KWU_RC_MADPRED_E0227
+  Int getLayerID()                                         { return m_LayerID; }
+  Void setLayerID(Int layerid)                              { m_LayerID = layerid; }
+#endif
+
 private:
   TEncRCSeq* m_encRCSeq;
@@ -361,4 +400,12 @@
   TEncRCPic* m_lastPicture;
 #endif
+
+#if KWU_RC_MADPRED_E0227
+  Double m_totalMAD;
+  TEncRCPic* m_lastPicture;
+  Int m_LayerID;
+  TEncRCPic* m_lastIVPicture;
+  Double m_IVtotalMAD;
+#endif
 };
 
@@ -371,5 +418,9 @@
 public:
 #if M0036_RC_IMPROVEMENT
+#if KWU_RC_MADPRED_E0227
+  Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP], Int LayerID );
+#else
   Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
+#endif
 #else
   Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
@@ -388,4 +439,9 @@
   list<TEncRCPic*>& getPicList() { return m_listRCPictures; }
 
+#if KWU_RC_MADPRED_E0227
+  Int getLayerID()                { return m_LayerID; }
+  Void setLayerID(Int layerid)     { m_LayerID = layerid; }
+#endif
+
 private:
   TEncRCSeq* m_encRCSeq;
@@ -394,4 +450,8 @@
   list<TEncRCPic*> m_listRCPictures;
   Int        m_RCQP;
+
+#if KWU_RC_MADPRED_E0227
+  Int m_LayerID;
+#endif
 };
 
@@ -518,4 +578,7 @@
   Void          updataRCUnitStatus    ();
   Void          updateLCUData         (TComDataCU* pcCU, UInt64 actualLCUBits, Int qp);
+#if KWU_RC_MADPRED_E0227
+  Void          updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int iQP, Double BasePos, Double CurPos, Double FocalLen, Double Znear, Double Zfar, Int Direction);
+#endif
   Void          updateFrameData       (UInt64 actualFrameBits);
   Double        xAdjustmentBits       (Int& reductionBits, Int& compensationBits);
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 635)
@@ -157,5 +157,8 @@
   m_pdRdPicQp         = (Double*)xMalloc( Double, m_pcCfg->getDeltaQpRD() * 2 + 1 );
   m_piRdPicQp         = (Int*   )xMalloc( Int,    m_pcCfg->getDeltaQpRD() * 2 + 1 );
-  m_pcRateCtrl        = pcEncTop->getRateCtrl();
+  if(m_pcCfg->getUseRateCtrl())
+    m_pcRateCtrl        = pcEncTop->getRateCtrl();
+  else
+    m_pcRateCtrl        = NULL;
 }
 
@@ -321,5 +324,5 @@
   }
 #if !RATE_CONTROL_LAMBDA_DOMAIN
-  if ( m_pcCfg->getUseRateCtrl())
+  if ( m_pcCfg->getUseRateCtrl() && !m_pcCfg->getIsDepth())
   {
     dQP = m_pcRateCtrl->getFrameQP(rpcSlice->isReferenced(), rpcSlice->getPOC());
@@ -1123,6 +1126,21 @@
 #endif
 #if !RATE_CONTROL_LAMBDA_DOMAIN
-    if(m_pcCfg->getUseRateCtrl())
-    {
+    if(m_pcCfg->getUseRateCtrl() && !m_pcCfg->getIsDepth())
+    {
+#if KWU_RC_MADPRED_E0227
+      if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())
+      {
+        double Zn, Zf, FocalLength, Position, CamShift;
+        double BasePos;
+        bool bInterpolated;
+        Int Direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
+
+        pcEncTop->getCamParam()->RCGetZNearZFar(pcSlice->getViewId(), pcSlice->getPOC(), Zn, Zf);
+        pcEncTop->getCamParam()->RCGetGeometryData(0, pcSlice->getPOC(), FocalLength, BasePos, CamShift, bInterpolated);
+        pcEncTop->getCamParam()->RCGetGeometryData(pcSlice->getViewId(), pcSlice->getPOC(), FocalLength, Position, CamShift, bInterpolated);
+
+        m_pcRateCtrl->updateLCUDataEnhancedView(pcCU, pcCU->getTotalBits(), pcCU->getQP(0), BasePos, Position, FocalLength, Zn, Zf, (Direction > 0 ? 1 : -1));
+      }
+#endif
       if(m_pcRateCtrl->calculateUnitQP())
       {
@@ -1223,4 +1241,22 @@
         else
         {
+#if KWU_RC_MADPRED_E0227
+          if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())
+          {
+            double Zn, Zf, FocalLength, Position, CamShift;
+            double BasePos;
+            bool bInterpolated;
+            Int Direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
+            Int iDisparity;
+
+            pcEncTop->getCamParam()->RCGetZNearZFar(pcSlice->getViewId(), pcSlice->getPOC(), Zn, Zf);
+            pcEncTop->getCamParam()->RCGetGeometryData(0, pcSlice->getPOC(), FocalLength, BasePos, CamShift, bInterpolated);
+            pcEncTop->getCamParam()->RCGetGeometryData(pcSlice->getViewId(), pcSlice->getPOC(), FocalLength, Position, CamShift, bInterpolated);
+            bpp       = m_pcRateCtrl->getRCPic()->getLCUTargetBppforInterView( m_pcRateCtrl->getPicList(), pcCU,
+                            BasePos, Position, FocalLength, Zn, Zf, (Direction > 0 ? 1 : -1), &iDisparity );
+          }
+          else
+          {
+#endif
 #if RATE_CONTROL_INTRA
           bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType());
@@ -1239,5 +1275,11 @@
           estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
 #endif
-
+#if KWU_RC_MADPRED_E0227
+          }
+#endif
+#if KWU_RC_MADPRED_E0227
+          estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
+          estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
+#endif
           estQP     = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, estQP );
 
@@ -1341,7 +1383,7 @@
 #if TICKET_1090_FIX
 #if RATE_CONTROL_LAMBDA_DOMAIN
-      if ( m_pcCfg->getUseRateCtrl() )
-      {
-#if !M0036_RC_IMPROVEMENT
+      if ( m_pcCfg->getUseRateCtrl() && !m_pcCfg->getIsDepth() )
+      {
+#if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227
         UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
@@ -1406,5 +1448,5 @@
     m_uiPicDist      += pcCU->getTotalDistortion();
 #if !RATE_CONTROL_LAMBDA_DOMAIN
-    if(m_pcCfg->getUseRateCtrl())
+    if(m_pcCfg->getUseRateCtrl() && !m_pcCfg->getIsDepth())
     {
       m_pcRateCtrl->updateLCUData(pcCU, pcCU->getTotalBits(), pcCU->getQP(0));
@@ -1427,5 +1469,5 @@
   xRestoreWPparam( pcSlice );
 #if !RATE_CONTROL_LAMBDA_DOMAIN
-  if(m_pcCfg->getUseRateCtrl())
+  if(m_pcCfg->getUseRateCtrl() && !m_pcCfg->getIsDepth())
   {
     m_pcRateCtrl->updateFrameData(m_uiPicTotalBits);
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncTop.cpp	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncTop.cpp	(revision 635)
@@ -123,9 +123,15 @@
   if ( m_RCEnableRateControl )
   {
+#if KWU_RC_MADPRED_E0227
+    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
+      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList, getLayerId() );
+#else
     m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
                       g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
-  }
-#else
-  m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);
+#endif
+  }
+#else
+  if(m_enableRateCtrl)
+    m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);
 #endif
   // if SBAC-based RD optimization is used
@@ -224,5 +230,4 @@
   }
   m_cLoopFilter.        destroy();
-  m_cRateCtrl.          destroy();
   // SBAC RD
   if( m_bUseSBACRD )
@@ -284,5 +289,9 @@
 }
 
+#if KWU_RC_MADPRED_E0227
+Void TEncTop::init(TAppEncTop* pcTAppEncTop)
+#else
 Void TEncTop::init()
+#endif
 {
   // initialize SPS
@@ -310,4 +319,7 @@
   m_cCuEncoder.   init( this );
   
+#if KWU_RC_MADPRED_E0227
+  m_pcTAppEncTop = pcTAppEncTop;
+#endif
   // initialize transform & quantization class
   m_pcCavlcCoder = getCavlcCoder();
@@ -739,4 +751,11 @@
     m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
   } 
+#else
+  if ( m_enableRateCtrl )
+  {
+    m_cPPS.setUseDQP(true);
+    m_cPPS.setMaxCuDQPDepth( 0 );
+    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
+  } 
 #endif
 
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncTop.h	(revision 633)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncTop.h	(revision 635)
@@ -64,4 +64,7 @@
 // ====================================================================================================================
 
+#if KWU_RC_MADPRED_E0227
+class TAppEncTop;
+#endif
 /// encoder class
 class TEncTop : public TEncCfg
@@ -124,4 +127,9 @@
   TComScalingList         m_scalingList;                 ///< quantization matrix information
   TEncRateCtrl            m_cRateCtrl;                    ///< Rate control class
+
+#if KWU_RC_MADPRED_E0227
+  TAppEncTop*             m_pcTAppEncTop;
+  TAppComCamPara*         m_cCamParam;
+#endif
   
 #if H_MV
@@ -145,5 +153,10 @@
   Void      create          ();
   Void      destroy         ();
+#if KWU_RC_MADPRED_E0227
+  Void      init            ( TAppEncTop* pcTAppEncTop );
+#else
   Void      init            ();
+#endif
+
 #if H_MV  
   TComPicLists* getIvPicLists() { return m_ivPicLists; }
@@ -185,4 +198,9 @@
   TEncSbac*               getRDGoOnSbacCoders   () { return  m_pcRDGoOnSbacCoders;   }
   TEncRateCtrl*           getRateCtrl           () { return &m_cRateCtrl;             }
+#if KWU_RC_MADPRED_E0227
+  TAppEncTop*             getEncTop             () { return m_pcTAppEncTop; }
+  TAppComCamPara*         getCamParam()                 { return m_cCamParam;}
+  Void                    setCamParam(TAppComCamPara * pCamparam)                 { m_cCamParam = pCamparam;}
+#endif
   TComSPS*                getSPS                () { return  &m_cSPS;                 }
   TComPPS*                getPPS                () { return  &m_cPPS;                 }
