Index: /branches/HTM-4.0-Nokia/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- /branches/HTM-4.0-Nokia/source/App/TAppDecoder/TAppDecTop.cpp	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/App/TAppDecoder/TAppDecTop.cpp	(revision 139)
@@ -87,8 +87,16 @@
   increaseNumberOfViews( 1 );
 #endif
-  
+#if FLEX_CODING_ORDER
+  Int iDepthViewIdx = 0;
+  Int iTextureViewIdx=0;
+  Bool first_frame=1;
+  Bool viewid_zero=true;
+  Int FCO_index=0;  //when the current frame is not first frame,use FCO_index stand for viewDepth. 
+#endif
+
 #if SONY_COLPIC_AVAILABILITY
   m_tDecTop[0]->setViewOrderIdx(0);
 #endif
+
   Int                 viewDepthId = 0;
   Int                 previousViewDepthId  = 0;
@@ -102,4 +110,7 @@
     pcListPic[i] = NULL;
     newPicture[i] = false;
+#if FLEX_CODING_ORDER
+    FCO_Order[i]=NULL;
+#endif
   }
 
@@ -156,9 +167,111 @@
         depth = getVPSAccess()->getActiveVPS()->getDepthFlag(nalu.m_layerId);
       }
-      viewDepthId = nalu.m_layerId;   // coding order T0D0T1D1T2D2
+#if FLEX_CODING_ORDER
+      if (viewId>0)
+      {
+        viewid_zero=false;
+      }
+      if (viewid_zero==false&&viewId==0)
+      {
+        first_frame=0; //if viewId has been more than zero and now it set to zero again, we can see that it is not the first view
+      }
+      if (first_frame)
+      { // if the current view is first frame, we set the viewDepthId as texture plus depth and get the FCO order 
+        viewDepthId = iDepthViewIdx+iTextureViewIdx;
+        FCO_viewDepthId=viewDepthId;
+      }
+      else
+      {//if current view is not first frame, we set the viewDepthId depended on the FCO order
+        viewDepthId=0;
+        if (depth)
+        {
+          for (FCO_index=0;FCO_index<2*MAX_VIEW_NUM;FCO_index++ )
+          {
+            if (FCO_Order[FCO_index]=='D')
+            {
+              if (viewId==viewDepthId)
+                break;
+              else
+                viewDepthId++;
+            }
+          }
+        }
+        else
+        {
+          for (FCO_index=0;FCO_index<2*MAX_VIEW_NUM;FCO_index++ )
+          {
+            if (FCO_Order[FCO_index]=='T')
+            {
+              if (viewId==viewDepthId)
+                break;
+              else
+                viewDepthId++;
+            }
+          }
+        }
+
+        viewDepthId=FCO_index;
+
+      }
+
+
+#else
+       viewDepthId = nalu.m_layerId;   // coding order T0D0T1D1T2D2
+#endif
+    
 #else
       Int viewId = nalu.m_viewId;
       Int depth = nalu.m_isDepth ? 1 : 0;
-      viewDepthId = viewId * 2 + depth;   // coding order T0D0T1D1T2D2
+#if FLEX_CODING_ORDER
+      if (viewId>0)
+      {
+        viewid_zero=false;
+      }
+      if (viewid_zero==false&&viewId==0)
+      {
+        first_frame=0;
+      }
+      if (first_frame)
+      {
+        viewDepthId = iDepthViewIdx+iTextureViewIdx;
+        FCO_viewDepthId=viewDepthId;
+      }
+      else
+      {
+        viewDepthId=0;
+        if (depth)
+        {
+          for (FCO_index=0;FCO_index<2*MAX_VIEW_NUM;FCO_index++ )
+          {
+            if (FCO_Order[FCO_index]=='D')
+            {
+              if (viewId==viewDepthId)
+                break;
+              else
+                viewDepthId++;
+            }
+          }
+        }
+        else
+        {
+          for (FCO_index=0;FCO_index<2*MAX_VIEW_NUM;FCO_index++ )
+          {
+            if (FCO_Order[FCO_index]=='T')
+            {
+              if (viewId==viewDepthId)
+                break;
+              else
+                viewDepthId++;
+            }
+          }
+        }
+
+        viewDepthId=FCO_index;
+
+      }
+#else
+  viewDepthId = viewId * 2 + depth;   // coding order T0D0T1D1T2D2
+#endif
+     
 #endif
       
@@ -190,4 +303,7 @@
         for( Int i = 0; i < m_tDecTop.size(); i++ )
         {
+//#if FLEX_CODING_ORDER
+//        FCO_Order[i]=NULL;
+//#endif
           m_tDecTop[i]->compressMotion( uiPOC[i] );
         }
@@ -209,4 +325,22 @@
         {
           previousPictureDecoded = true;
+#if FLEX_CODING_ORDER
+if (first_frame)
+{
+  if (depth)
+  {
+    iDepthViewIdx++;
+    FCO_Order[viewDepthId]='D';
+  }
+  else
+  {
+    iTextureViewIdx++;
+    FCO_Order[viewDepthId]='T';
+  }
+}
+
+
+
+#endif
         }
       }
@@ -215,4 +349,5 @@
     {
       m_tDecTop[viewDepthId]->executeDeblockAndAlf(uiPOC[viewDepthId], pcListPic[viewDepthId], m_iSkipFrame, m_pocLastDisplay[viewDepthId]);
+
     }
     if( pcListPic[viewDepthId] )
@@ -234,4 +369,9 @@
     previousViewDepthId = viewDepthId;
   } 
+
+
+
+
+
   if( m_cCamParsCollector.isInitialized() )
   {
@@ -502,5 +642,63 @@
 TDecTop* TAppDecTop::getTDecTop( Int viewId, Bool isDepth )
 { 
+#if FLEX_CODING_ORDER
+  Int viewnumber=0;
+  Int i=0;
+  Bool FCO_flag=0;
+  if (viewId>FCO_viewDepthId)
+  {
+    return NULL;
+  }
+  else
+  {
+    if (isDepth)
+   {
+      for ( i=0; i<=FCO_viewDepthId;i++)
+      {
+         if (FCO_Order[i]=='D')
+         {
+           if (viewnumber==viewId)
+           {
+             FCO_flag=1;
+             break;
+           }
+           else
+             viewnumber++;
+         }
+      }
+    }
+    else
+    {
+      for ( i=0; i<=FCO_viewDepthId;i++)
+      {
+        if (FCO_Order[i]=='T')
+        {
+          if (viewnumber==viewId)
+          {
+            FCO_flag=1;
+            break;
+          }
+          else
+            viewnumber++;
+        }
+      }
+    }
+    if (FCO_flag)
+    {
+      return m_tDecTop[i];
+    }
+    else
+      return NULL;
+    
+  }
+
+    // coding order T0D0T1D1T2D2
+#else
   return m_tDecTop[(isDepth ? 1 : 0) + viewId * 2];  // coding order T0D0T1D1T2D2
+#endif
+  /*
+  //original code
+  return m_tDecTop[(isDepth ? 1 : 0) + viewId * 2];  // coding order T0D0T1D1T2D2
+  */
 } 
 
@@ -520,5 +718,22 @@
 {
   assert( ( viewId >= 0 ) );
-
+#if FLEX_CODING_ORDER
+if (getTDecTop(viewId,isDepth))
+{
+   TComList<TComPic*>* apcListPic = getTDecTop( viewId, isDepth )->getListPic();
+   TComPic* pcPic = NULL;
+   for( TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++ )
+   {
+     if( (*it)->getPOC() == poc )
+     {
+       pcPic = *it;
+       break;
+     }
+   }
+   return pcPic;
+}
+else
+  return NULL;
+#else
   TComList<TComPic*>* apcListPic = getTDecTop( viewId, isDepth )->getListPic();
   TComPic* pcPic = NULL;
@@ -532,4 +747,7 @@
   }
   return pcPic;
+#endif
+
+
 }
 //! \}
Index: /branches/HTM-4.0-Nokia/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- /branches/HTM-4.0-Nokia/source/App/TAppDecoder/TAppDecTop.h	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/App/TAppDecoder/TAppDecTop.h	(revision 139)
@@ -70,5 +70,8 @@
   std::vector<Int>                m_pocLastDisplay;               ///< last POC in display order
   Bool                            m_useDepth;
-
+#if FLEX_CODING_ORDER
+  Int  FCO_viewDepthId;
+  Char FCO_Order[MAX_VIEW_NUM*2];
+#endif
   FILE*                           m_pScaleOffsetFile;
   CamParsCollector                m_cCamParsCollector;
Index: /branches/HTM-4.0-Nokia/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- /branches/HTM-4.0-Nokia/source/App/TAppEncoder/TAppEncCfg.h	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/App/TAppEncoder/TAppEncCfg.h	(revision 139)
@@ -88,4 +88,13 @@
   Int       m_iNumberOfViews;                                 ///< number Views to Encode
   Bool      m_bUsingDepthMaps;
+
+#if FLEX_CODING_ORDER
+  char*  m_pchMVCJointCodingOrder;      ///<  texture-depth coding order
+  Bool    m_b3DVFlexOrder;    ///<  flexible coding order flag
+#endif
+
+
+
+
   // coding structure
   Int       m_iIntraPeriod;                                   ///< period of I-slice (random access period)
Index: /branches/HTM-4.0-Nokia/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/HTM-4.0-Nokia/source/App/TAppEncoder/TAppEncTop.cpp	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/App/TAppEncoder/TAppEncTop.cpp	(revision 139)
@@ -369,4 +369,27 @@
     for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
     {
+#if FLEX_CODING_ORDER
+      // Detect whether depth comes before than texture for this view
+      Bool isDepthFirst = false;
+      if ( m_b3DVFlexOrder )
+      {
+        for ( Int ii=1; ii<12; ii+=2 )
+        {
+          Int iViewIdxCfg = (Int)(m_pchMVCJointCodingOrder[ii]-'0');
+          if ( iViewIdxCfg == iViewIdx )
+          {
+            if ( m_pchMVCJointCodingOrder[ii-1]=='D' ) // depth comes first for this view
+            {
+              isDepthFirst = true;
+            }
+            else
+            {
+              assert(m_pchMVCJointCodingOrder[ii-1]=='T');
+            }
+            break;
+          }
+        }
+      }
+#endif
       m_depthFrameRcvd.push_back(0);
       m_acTEncDepthTopList.push_back(new TEncTop); 
@@ -634,6 +657,17 @@
     m_acTEncDepthTopList[iViewIdx]->setUseDMM                     ( m_bUseDMM );
 #endif
+
+#if FLEX_CODING_ORDER && HHI_DMM_PRED_TEX
+    m_acTEncDepthTopList[iViewIdx]->setUseDMM34( (m_b3DVFlexOrder && isDepthFirst) ? false : m_bUseDMM );
+#endif
+
+
 #if HHI_MPI
-     m_acTEncDepthTopList[iViewIdx]->setUseMVI( m_bUseMVI );
+#if FLEX_CODING_ORDER
+    m_acTEncDepthTopList[iViewIdx]->setUseMVI( (m_b3DVFlexOrder && isDepthFirst) ? false : m_bUseMVI );
+#else
+    m_acTEncDepthTopList[iViewIdx]->setUseMVI( m_bUseMVI );
+#endif
+    // m_acTEncDepthTopList[iViewIdx]->setUseMVI( m_bUseMVI );
 #endif
     }
@@ -920,4 +954,59 @@
       m_cCameraData.update( iNextPoc );
       }
+
+
+
+#if FLEX_CODING_ORDER
+      if (m_b3DVFlexOrder)
+      {
+        Int  iNumDepthEncoded = 0;
+        iNumEncoded = 0;
+        Int i=0;
+        Int iViewIdx=0;
+        Int iNumberofDepthViews = m_bUsingDepthMaps?m_iNumberOfViews:0;
+        for (Int j=0; j < (m_iNumberOfViews+ iNumberofDepthViews); j++ )
+        {
+          if (m_pchMVCJointCodingOrder[i]=='T')
+          {
+
+            i++;
+            assert(isdigit(m_pchMVCJointCodingOrder[i]));
+            iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
+
+            m_acTEncTopList[iViewIdx]->encode( eos[iViewIdx], pcPicYuvOrg, *m_picYuvRec[iViewIdx], outputAccessUnits, iNumEncoded, gopId );
+            xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits, iViewIdx, false);
+            outputAccessUnits.clear();
+            i++;
+          }
+          else if ( m_pchMVCJointCodingOrder[i] == 'D')
+          {
+
+            i++;
+            if( m_bUsingDepthMaps )
+            {
+              assert(isdigit(m_pchMVCJointCodingOrder[i]));
+              iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
+#if SAIT_VSO_EST_A0033
+              if( m_bUseVSO && iNextPoc < m_iFrameToBeEncoded )
+              {
+                m_cCameraData.xSetDispCoeff( iNextPoc, iViewIdx );
+                m_acTEncDepthTopList[iViewIdx]->setDispCoeff( m_cCameraData.getDispCoeff() );
+              }
+#endif
+              m_acTEncDepthTopList[iViewIdx]->encode( depthEos[iViewIdx], pcDepthPicYuvOrg, *m_picYuvDepthRec[iViewIdx], outputAccessUnits, iNumDepthEncoded, gopId );
+              xWriteOutput(bitstreamFile, iNumDepthEncoded, outputAccessUnits, iViewIdx, true);
+              outputAccessUnits.clear();
+              i++;
+            }
+          }
+        }
+      }
+      else
+      {
+
+#endif
+
+//original code
+
       for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
       {
@@ -943,4 +1032,12 @@
         }
       }
+
+#if FLEX_CODING_ORDER
+      }
+#endif
+
+
+
+
 #if HHI_INTERVIEW_SKIP || HHI_INTER_VIEW_MOTION_PRED || HHI_INTER_VIEW_RESIDUAL_PRED
       for( Int iViewIdx = 0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
Index: /branches/HTM-4.0-Nokia/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/HTM-4.0-Nokia/source/Lib/TLibCommon/TComSlice.cpp	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/Lib/TLibCommon/TComSlice.cpp	(revision 139)
@@ -1441,4 +1441,9 @@
 , m_bUseDMM                   (false)
 #endif
+
+#if FLEX_CODING_ORDER && HHI_DMM_PRED_TEX
+, m_bUseDMM34                   (false)
+#endif
+
 {
   // AMVP parameter
Index: /branches/HTM-4.0-Nokia/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/HTM-4.0-Nokia/source/Lib/TLibCommon/TComSlice.h	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/Lib/TLibCommon/TComSlice.h	(revision 139)
@@ -354,4 +354,8 @@
 #endif
 
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  Bool  m_bUseDMM34;
+#endif
+
 #if DEPTH_MAP_GENERATION
   UInt  m_uiPredDepthMapGeneration;
@@ -382,5 +386,6 @@
   Void setVPSId       (Int i)    { m_VPSId = i;             }
 #endif
-  Int  getSPSId       ()         { return m_SPSId;          }
+  Int  getSPSId       ()         
+  { return m_SPSId;          }
   Void setSPSId       (Int i)    { m_SPSId = i;             }
   Int  getProfileIdc  ()         { return m_ProfileIdc;     }
@@ -619,4 +624,9 @@
 #endif
 
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  Bool getUseDMM34()         { return m_bUseDMM34; }
+  Void setUseDMM34( Bool b ) { m_bUseDMM34 = b;    }
+#endif
+
   Void initMultiviewSPS      ( UInt uiViewId, Int iViewOrderIdx = 0, UInt uiCamParPrecision = 0, Bool bCamParSlice = false, Int** aaiScale = 0, Int** aaiOffset = 0 );
   Void initMultiviewSPSDepth ( UInt uiViewId, Int iViewOrderIdx );
Index: /branches/HTM-4.0-Nokia/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/HTM-4.0-Nokia/source/Lib/TLibCommon/TypeDef.h	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/Lib/TLibCommon/TypeDef.h	(revision 139)
@@ -46,5 +46,17 @@
 #define FIX_DECODING_WO_WRITING           1
 #define FIX_INIT_ROM                      1
+
 #define FIX_VIRT_DESTRUCTOR               1
+
+
+
+
+#define FLEX_CODING_ORDER               1
+#if FLEX_CODING_ORDER
+  #define DISABLE_FCO_FOR_VSO             1
+#else
+  #define DISABLE_FCO_FOR_VSO             0
+#endif
+
 
 
Index: /branches/HTM-4.0-Nokia/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/HTM-4.0-Nokia/source/Lib/TLibDecoder/TDecTop.cpp	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/Lib/TLibDecoder/TDecTop.cpp	(revision 139)
@@ -614,7 +614,9 @@
 
 #if SKIPFRAME_BUGFIX
-Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
-#else
-Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int iSkipFrame, Int iPOCLastDisplay )
+Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay
+)
+#else
+Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int iSkipFrame, Int iPOCLastDisplay
+                           )
 #endif
 {
@@ -969,6 +971,22 @@
     assert( m_tAppDecTop != NULL );
     TComPic * const pcTexturePic = m_isDepth ? m_tAppDecTop->getPicFromView(  m_viewId, pcSlice->getPOC(), false ) : NULL;
+
+#if FLEX_CODING_ORDER
+    if (pcTexturePic != NULL)
+    {
+      assert( !m_isDepth || pcTexturePic != NULL );
+      pcSlice->setTexturePic( pcTexturePic );
+    }
+#else
     assert( !m_isDepth || pcTexturePic != NULL );
     pcSlice->setTexturePic( pcTexturePic );
+#endif
+    
+
+//     //original code 
+//     assert( !m_isDepth || pcTexturePic != NULL );
+//     pcSlice->setTexturePic( pcTexturePic );
+
+
 
     std::vector<TComPic*> apcInterViewRefPics = m_tAppDecTop->getInterViewRefPics( m_viewId, pcSlice->getPOC(), m_isDepth, pcSlice->getSPS() );
@@ -1082,4 +1100,8 @@
 }
 
+
+
+
+
 #if VIDYO_VPS_INTEGRATION
 Void TDecTop::xDecodeVPS()
@@ -1147,5 +1169,7 @@
 }
 
-Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
+Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay
+
+ )
 {
   // Initialize entropy decoder
@@ -1184,5 +1208,6 @@
     case NAL_UNIT_CODED_SLICE_CDR:
 #endif
-      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
+      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay
+        );
       break;
     default:
Index: /branches/HTM-4.0-Nokia/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /branches/HTM-4.0-Nokia/source/Lib/TLibDecoder/TDecTop.h	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/Lib/TLibDecoder/TDecTop.h	(revision 139)
@@ -111,7 +111,9 @@
   TComList<TComPic*>      m_cListPic;         //  Dynamic buffer
   ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets 
+
+
   TComRPSList             m_RPSList;
   TComSlice*              m_apcSlicePilot;
-  
+
   SEImessages *m_SEIs; ///< "all" SEI messages.  If not NULL, we own the object.
 
@@ -165,5 +167,6 @@
   
   Void  init( TAppDecTop* pcTAppDecTop, Bool bFirstInstance );
-  Bool  decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay);
+  Bool  decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay
+  );
   
   Void  deletePicBuffer();
@@ -204,7 +207,9 @@
   Void      xActivateParameterSets();
 #if SKIPFRAME_BUGFIX
-  Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay);
+  Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay
+    );
 #else
-  Bool      xDecodeSlice(InputNALUnit &nalu, Int iSkipFrame, Int iPOCLastDisplay);
+  Bool      xDecodeSlice(InputNALUnit &nalu, Int iSkipFrame, Int iPOCLastDisplay,
+    );
 #endif
 #if VIDYO_VPS_INTEGRATION
Index: /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncCfg.h	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncCfg.h	(revision 139)
@@ -312,4 +312,8 @@
 #endif
 
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  Bool m_bUseDMM34;
+#endif
+
   Int      m_iViewOrderIdx;
 
@@ -799,4 +803,9 @@
 #endif
 
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  Void setUseDMM34( Bool b) { m_bUseDMM34 = b;    }
+  Bool getUseDMM34()        { return m_bUseDMM34; }
+#endif
+
   Void      setViewOrderIdx       ( Int   i )      { m_iViewOrderIdx          = i; }
   Void      setCamParPrecision              ( UInt  u )      { m_uiCamParPrecision      = u; }
Index: /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 139)
@@ -167,4 +167,5 @@
   TEncSbac* pcSbacCoders = NULL;
   TComOutputBitstream* pcSubstreamsOut = NULL;
+  int is_Depth;
 
   {
@@ -255,5 +256,5 @@
       pcSlice->setViewId( m_pcEncTop->getViewId() );
       pcSlice->setIsDepth( m_pcEncTop->getIsDepth() ); 
-
+      is_Depth = m_pcEncTop->getIsDepth();
       m_pcEncTop->getSPS()->setDisInter4x4(m_pcEncTop->getDisInter4x4());
       pcSlice->setScalingList ( m_pcEncTop->getScalingList()  );
@@ -461,9 +462,13 @@
 
 #if SAIT_VSO_EST_A0033
-    m_pcRdCost->setVideoRecPicYuv( m_pcEncTop->getEncTop()->getPicYuvFromView( pcSlice->getViewId(), pcSlice->getPOC(), false, true ) );
+    
+{
+Bool flag_rec;
+
+    flag_rec =  ((m_pcEncTop->getEncTop()->getPicYuvFromView( pcSlice->getViewId(), pcSlice->getPOC(), false, true) == NULL) ? false: true);
+    m_pcRdCost->setVideoRecPicYuv( m_pcEncTop->getEncTop()->getPicYuvFromView( pcSlice->getViewId(), pcSlice->getPOC(), false, flag_rec ) );
     m_pcRdCost->setDepthPicYuv   ( m_pcEncTop->getEncTop()->getPicYuvFromView( pcSlice->getViewId(), pcSlice->getPOC(), true, false ) );
-#endif
-
-
+}
+#endif
   }
 #endif
Index: /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 139)
@@ -964,4 +964,13 @@
 #endif
 #if HHI_DMM_PRED_TEX
+
+#if FLEX_CODING_ORDER
+    if ( !pcCU->getSlice()->getSPS()->getUseDMM34() )
+    {
+      assert( uiDir != DMM_WEDGE_PREDTEX_D_IDX );
+      assert( uiDir != DMM_CONTOUR_PREDTEX_D_IDX );
+    }
+#endif
+
     if( uiDir == DMM_WEDGE_PREDTEX_D_IDX )     { xCodeWedgePredTexDeltaInfo  ( pcCU, uiAbsPartIdx ); }
     if( uiDir == DMM_CONTOUR_PREDTEX_D_IDX )   { xCodeContourPredTexDeltaInfo( pcCU, uiAbsPartIdx ); }
Index: /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 139)
@@ -2025,4 +2025,9 @@
 #endif
 #if HHI_DMM_PRED_TEX
+
+#if FLEX_CODING_ORDER
+      if ( pcCU->getSlice()->getSPS()->getUseDMM34() )
+      {
+#endif
       UInt uiTexTabIdx  = 0;
       Int  iTexDeltaDC1 = 0;
@@ -2048,4 +2053,7 @@
         uiRdModeList[ numModesForFullRD++ ] = DMM_CONTOUR_PREDTEX_D_IDX;
       }
+#if FLEX_CODING_ORDER
+      }
+#endif
 #endif
     }
@@ -2083,4 +2091,13 @@
 
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+      if( m_pcEncCfg->getIsDepth() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight, pcCU->getSlice()->getSPS()->getUseDMM34() ) 
+#if LGE_EDGE_INTRA
+        && uiOrgMode < EDGE_INTRA_IDX
+#endif
+        )
+
+#else
+
       if( m_pcEncCfg->getIsDepth() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight ) 
 #if LGE_EDGE_INTRA
@@ -2088,4 +2105,5 @@
 #endif
         )
+#endif
       {
         continue;
@@ -6014,6 +6032,9 @@
 }
 
-#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
+#if ((HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX)&&FLEX_CODING_ORDER)
+Bool TEncSearch::predIntraLumaDMMAvailable( UInt uiMode, UInt uiWidth, UInt uiHeight, Bool bDMMAvailable34 )
+#else
 Bool TEncSearch::predIntraLumaDMMAvailable( UInt uiMode, UInt uiWidth, UInt uiHeight )
+#endif
 {
   if( uiMode < NUM_INTRA_MODE ) return true;
@@ -6023,7 +6044,7 @@
 #if HHI_DMM_WEDGE_INTRA
   if( uiMode == DMM_WEDGE_FULL_IDX        ||
-      uiMode == DMM_WEDGE_FULL_D_IDX      ||
-      uiMode == DMM_WEDGE_PREDDIR_IDX     ||
-      uiMode == DMM_WEDGE_PREDDIR_D_IDX )
+    uiMode == DMM_WEDGE_FULL_D_IDX      ||
+    uiMode == DMM_WEDGE_PREDDIR_IDX     ||
+    uiMode == DMM_WEDGE_PREDDIR_D_IDX )
   {
     if( (uiWidth != uiHeight) || (uiWidth < DMM_WEDGEMODEL_MIN_SIZE) || (uiWidth > DMM_WEDGEMODEL_MAX_SIZE) || ( ( uiMode == DMM_WEDGE_PREDDIR_IDX || uiMode == DMM_WEDGE_PREDDIR_D_IDX ) && uiWidth == 4 ) )
@@ -6035,7 +6056,7 @@
 #if HHI_DMM_PRED_TEX
   if( uiMode == DMM_WEDGE_PREDTEX_IDX     ||
-      uiMode == DMM_WEDGE_PREDTEX_D_IDX   ||
-      uiMode == DMM_CONTOUR_PREDTEX_IDX   ||
-      uiMode == DMM_CONTOUR_PREDTEX_D_IDX )
+    uiMode == DMM_WEDGE_PREDTEX_D_IDX   ||
+    uiMode == DMM_CONTOUR_PREDTEX_IDX   ||
+    uiMode == DMM_CONTOUR_PREDTEX_D_IDX )
   {
     if( (uiWidth != uiHeight) || (uiWidth < DMM_WEDGEMODEL_MIN_SIZE) || (uiWidth > DMM_WEDGEMODEL_MAX_SIZE) || ( ( uiMode == DMM_CONTOUR_PREDTEX_IDX || uiMode == DMM_CONTOUR_PREDTEX_D_IDX ) && uiWidth == 4 ) )
@@ -6043,4 +6064,12 @@
       bDMMAvailable = false;
     }
+
+#if FLEX_CODING_ORDER
+    if ( !bDMMAvailable34 )
+    {
+      bDMMAvailable = false;
+    }
+#endif
+
   }
 #endif
@@ -6148,6 +6177,6 @@
   xDeltaDCQuantScaleDown( pcCU, riDeltaDC2 );
 }
-#endif
-#if HHI_DMM_WEDGE_INTRA
+//#endif
+#if HHI_DMM_WEDGE_INTRA  
 Void TEncSearch::findWedgeFullMinDist( TComDataCU*  pcCU,
                                        UInt         uiAbsPtIdx,
Index: /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncSearch.h	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncSearch.h	(revision 139)
@@ -315,5 +315,11 @@
   Bool predIntraLumaDMMAvailable  ( UInt           uiMode, 
                                     UInt           uiWidth, 
-                                    UInt           uiHeight );
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+                                    UInt         uiHeight, 
+                                    Bool         bDMMAvailable34 );
+#else
+                                    UInt         uiHeight );
+#endif
+
   Void xGetWedgeDeltaDCsMinDist   ( TComWedgelet*  pcWedgelet, 
                                     TComDataCU*    pcCU, 
Index: /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 139)
@@ -729,5 +729,7 @@
  {
 
-   Int frameWidth = m_pcCfg->getSourceWidth();
+ 
+#if 0
+  Int frameWidth = m_pcCfg->getSourceWidth();
    Pel* pVideoRec = m_pcRdCost->getVideoRecPicYuv()->getLumaAddr();
    Int iVideoRecStride = m_pcRdCost->getVideoRecPicYuv()->getStride();
@@ -746,4 +748,5 @@
      pDepthOrg += iDepthOrgStride;
    }
+#endif
  }
 #endif
Index: /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncTop.cpp	(revision 138)
+++ /branches/HTM-4.0-Nokia/source/Lib/TLibEncoder/TEncTop.cpp	(revision 139)
@@ -768,4 +768,10 @@
   m_cSPS.setUseDMM( m_bUseDMM );
 #endif
+
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  m_cSPS.setUseDMM34( m_bUseDMM34 );
+#endif
+
+
 #if HHI_MPI
   m_cSPS.setUseMVI( m_bUseMVI );
