Index: /branches/0.3-nokia/CommonTestConditionsCfgs/baseCfg_2view+depth.cfg
===================================================================
--- /branches/0.3-nokia/CommonTestConditionsCfgs/baseCfg_2view+depth.cfg	(revision 33)
+++ /branches/0.3-nokia/CommonTestConditionsCfgs/baseCfg_2view+depth.cfg	(revision 34)
@@ -15,4 +15,7 @@
 
 BitstreamFile             : stream.bit                             # bitstream file
+
+3DVFlexOrder 		:	0
+3DVCodingOrder 		:	T0D0D1D2T1T2
 
 
Index: /branches/0.3-nokia/CommonTestConditionsCfgs/baseCfg_3view+depth.cfg
===================================================================
--- /branches/0.3-nokia/CommonTestConditionsCfgs/baseCfg_3view+depth.cfg	(revision 33)
+++ /branches/0.3-nokia/CommonTestConditionsCfgs/baseCfg_3view+depth.cfg	(revision 34)
@@ -1,3 +1,2 @@
-
 
 #========== file i/o ==========
@@ -20,4 +19,6 @@
 BitstreamFile             : stream.bit                             # bitstream file
 
+3DVFlexOrder 		:	0
+3DVCodingOrder 		:	T0D0D1D2T1T2
 
 #========== general coding parameters ==========
Index: /branches/0.3-nokia/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- /branches/0.3-nokia/source/App/TAppDecoder/TAppDecTop.cpp	(revision 33)
+++ /branches/0.3-nokia/source/App/TAppDecoder/TAppDecTop.cpp	(revision 34)
@@ -126,4 +126,10 @@
   NalUnitType eNalUnitType;
 
+#if FLEX_CODING_ORDER
+  Int iDepthViewIdx = 0;
+  Bool bCountDepthViewIdx = false;		// a flag which avoid repeating assign a value to iDepthViewIdx   
+  Bool bNewPictureType =true;
+  Bool bFirstDepth = false;
+#endif
   
   while ( !bEos )
@@ -136,11 +142,21 @@
       if( bIsDepth )
       {
+#if FLEX_CODING_ORDER
+		  if (!bFirstSliceDecoded) m_acTDecDepthTopList[iDepthViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iDepthViewIdx] ,bNewPictureType);
+		  m_acTDecDepthTopList[iDepthViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iDepthViewIdx]);
+
+#else
         if (!bFirstSliceDecoded) m_acTDecDepthTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iViewIdx] );
         m_acTDecDepthTopList[iViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iViewIdx]);
+#endif
       }
       else
       {
+#if FLEX_CODING_ORDER
+		  if (!bFirstSliceDecoded) m_acTDecTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx], bNewPictureType);
+#else
         if (!bFirstSliceDecoded) m_acTDecTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx] );
-        m_acTDecTopList[iViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx]);
+#endif
+		m_acTDecTopList[iViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx]);
       }
       if( pcListPic )
@@ -156,8 +172,53 @@
     Bool bNewPicture;
     if( bIsDepth )
+#if FLEX_CODING_ORDER
+		  bNewPicture = m_acTDecDepthTopList[iDepthViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iDepthViewIdx], bNewPictureType);
+#else
       bNewPicture = m_acTDecDepthTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iViewIdx] );
+#endif
     else
+#if FLEX_CODING_ORDER
+		bNewPicture = m_acTDecTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx], bNewPictureType );
+#else
       bNewPicture = m_acTDecTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx] );
+#endif
     bFirstSliceDecoded   = true;
+
+#if FLEX_CODING_ORDER
+	  if (eNalUnitType == NAL_UNIT_SPS)
+	  {
+		  if( cComSPS.isDepth() && (m_bUsingDepth==false) )  // expected not using depth, but bitstream are using depth
+		  {                                                     // know from sps
+			  assert( cComSPS.getViewId() == 0 && iDepthViewIdx == 0 && !bIsDepth );
+			  startUsingDepth() ;
+		  }
+		  if (cComSPS.isDepth())
+		  {
+			  if (cComSPS.getViewId() >= m_acTVideoIOYuvDepthReconFileList.size())
+			  {
+				  assert( cComSPS.getViewId() == m_acTVideoIOYuvReconFileList.size() );
+				  increaseNumberOfViews(cComSPS.getViewId()+1);
+			  }
+  			
+			  m_acTDecDepthTopList[cComSPS.getViewId()]->setSPS(cComSPS);
+		  }
+		  else 
+		  {
+			  if (cComSPS.getViewId() >= m_acTVideoIOYuvReconFileList.size())
+			  {
+				  assert( cComSPS.getViewId() == m_acTVideoIOYuvReconFileList.size() );
+				  increaseNumberOfViews(cComSPS.getViewId()+1);
+			  }
+			  m_acTDecTopList[cComSPS.getViewId()]->setSPS(cComSPS);
+		  }
+		  bEos = m_cTVideoIOBitstreamFile.readBits( pcBitstream );
+		  assert( !bEos);
+		  if( cComSPS.isDepth() )
+			  m_acTDecDepthTopList[cComSPS.getViewId()]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[cComSPS.getViewId()], bNewPictureType); // decode PPS
+		  else
+			  m_acTDecTopList[cComSPS.getViewId()]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[cComSPS.getViewId()], bNewPictureType); // decode PPS
+		  assert( eNalUnitType == NAL_UNIT_PPS );
+	  }
+#else
 
     if( eNalUnitType == NAL_UNIT_SPS )
@@ -188,9 +249,15 @@
       assert( eNalUnitType == NAL_UNIT_PPS );
     }
+
+#endif
     assert( eNalUnitType != NAL_UNIT_SEI ); // not yet supported for MVC
     if (bNewPicture)
     {
       if( bIsDepth )
+#if FLEX_CODING_ORDER
+        m_acTDecDepthTopList[iDepthViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iDepthViewIdx]);
+#else
         m_acTDecDepthTopList[iViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iViewIdx]);
+#endif
       else
         m_acTDecTopList[iViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx]);
@@ -199,19 +266,42 @@
       bFirstSliceDecoded = false;
 
-      if( m_bUsingDepth && !bIsDepth )
-      {
-        bIsDepth = true;
+#if FLEX_CODING_ORDER
+      if (m_bUsingDepth)
+      {
+        bIsDepth = bNewPictureType;	  
+
+      }
+      if (bCountDepthViewIdx == false )
+      {
+        bCountDepthViewIdx = true;
+        if (bIsDepth == true)
+        {
+          bFirstDepth = true;
+          bCountDepthViewIdx = true;
+        }
+        if (!bFirstDepth && !bIsDepth)
+        {
+          iViewIdx++;
+          bCountDepthViewIdx = false;
+        }
+
       }
       else
       {
-        bIsDepth = false;
-        if( iViewIdx<m_acTDecTopList.size()-1)
-        {
-          iViewIdx++ ;
+        if (bIsDepth)
+        {
+          iDepthViewIdx++;
         }
         else
         {
+          iViewIdx ++;
+        }
+
+        if (iViewIdx >= m_acTDecTopList.size() || iDepthViewIdx >= m_acTDecDepthTopList.size())
+        {
+          bFirstDepth = false;
           iViewIdx = 0;
-
+          iDepthViewIdx = 0;
+          bCountDepthViewIdx = false;
           // end of access unit: delete extra pic buffers
           Int iNumViews = (Int)m_acTVideoIOYuvReconFileList.size();
@@ -244,4 +334,53 @@
         }
       }
+	  
+#else
+
+      if( m_bUsingDepth && !bIsDepth )
+      {
+        bIsDepth = true;
+      }
+      else
+      {
+        bIsDepth = false;
+        if( iViewIdx<m_acTDecTopList.size()-1)
+        {
+          iViewIdx++ ;
+        }
+        else
+        {
+          iViewIdx = 0;
+
+          // end of access unit: delete extra pic buffers
+          Int iNumViews = (Int)m_acTVideoIOYuvReconFileList.size();
+          for( Int iVId = 0; iVId < iNumViews; iVId++ )
+          {
+            if( iVId < (Int)m_acTDecTopList.size() &&  m_acTDecTopList[iVId] )
+            {
+              m_acTDecTopList[iVId]->deleteExtraPicBuffers( (Int)uiPOC );
+            }
+            if( iVId < (Int)m_acTDecDepthTopList.size() && m_acTDecDepthTopList[iVId] )
+            {
+              m_acTDecDepthTopList[iVId]->deleteExtraPicBuffers( (Int)uiPOC );
+            }
+          }
+
+#if AMVP_BUFFERCOMPRESS
+          // compress motion for entire access unit
+          for( Int iVId = 0; iVId < iNumViews; iVId++ )
+          {
+            if( iVId < (Int)m_acTDecTopList.size() &&  m_acTDecTopList[iVId] )
+            {
+              m_acTDecTopList[iVId]->compressMotion( (Int)uiPOC );
+            }
+            if( iVId < (Int)m_acTDecDepthTopList.size() && m_acTDecDepthTopList[iVId] )
+            {
+              m_acTDecDepthTopList[iVId]->compressMotion( (Int)uiPOC );
+            }
+          }
+#endif
+        }
+	  }
+#endif
     }
 #else
@@ -506,5 +645,11 @@
       m_acTDecDepthTopList.back()->create() ;
       m_acTDecDepthTopList.back()->init( this, false );
-      m_acTDecDepthTopList.back()->setViewIdx((Int)m_acTDecTopList.size()-1);
+#if FLEX_CODING_ORDER
+      Int iNumofgen = (Int)m_acTDecDepthTopList.size();
+      m_acTDecDepthTopList.back()->setViewIdx(iNumofgen-1);
+#else
+	  m_acTDecDepthTopList.back()->setViewIdx((Int)m_acTDecTopList.size()-1);
+#endif
+
       m_acTDecDepthTopList.back()->setPictureDigestEnabled(m_pictureDigestEnabled);
       m_acTDecDepthTopList.back()->setToDepth( true );
Index: /branches/0.3-nokia/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/0.3-nokia/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 33)
+++ /branches/0.3-nokia/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 34)
@@ -110,4 +110,10 @@
     free (m_pchBitstreamFile) ;
 
+#if FLEX_CODING_ORDER
+  if (m_pchMVCJointCodingOrder != NULL)
+  {
+	  free(m_pchMVCJointCodingOrder) ;
+  }
+#endif
   for(Int i = 0; i< m_pchDepthReconFileList.size(); i++ )
   {
@@ -153,4 +159,9 @@
   string cfg_ReconFile;
   string cfg_dQPFile;
+
+#if FLEX_CODING_ORDER
+  string cfg_JointCodingOrdering;
+#endif
+
   po::Options opts;
   opts.addOptions()
@@ -191,5 +202,9 @@
   ("NumberOfViews",         m_iNumberOfViews,    0, "Number of views")
 
-
+#if FLEX_CODING_ORDER
+  ("3DVFlexOrder",          m_b3DVFlexOrder,   false, "flexible coding order flag" )
+  ("3DVCodingOrder",		cfg_JointCodingOrdering,  string(""), "The coding order for joint texture-depth coding")
+
+#endif
   /* Unit definition parameters */
   ("MaxCUWidth",          m_uiMaxCUWidth,  64u)
@@ -379,4 +394,36 @@
   m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
 
+#if FLEX_CODING_ORDER && HHI_VSO
+  m_pchMVCJointCodingOrder	= cfg_JointCodingOrdering.empty()?NULL:strdup(cfg_JointCodingOrdering.c_str());
+  // If flexible order is enabled and if depth comes before the texture for a view, disable VSO
+  Bool depthComesFirst = false;
+  if ( m_b3DVFlexOrder )
+  {
+    for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
+    {
+      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
+          {
+            depthComesFirst = true;
+            break;
+          }
+          else
+          {
+            assert(m_pchMVCJointCodingOrder[ii-1]=='T');
+          }
+        }
+      }
+    }
+  }
+  if (depthComesFirst)
+  {
+    m_bUseVSO = false;		
+  }
+#endif
+
 
 // GT FIX
Index: /branches/0.3-nokia/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- /branches/0.3-nokia/source/App/TAppEncoder/TAppEncCfg.h	(revision 33)
+++ /branches/0.3-nokia/source/App/TAppEncoder/TAppEncCfg.h	(revision 34)
@@ -81,4 +81,9 @@
   Bool      m_bUsingDepthMaps ;
 
+#if FLEX_CODING_ORDER
+  char*		m_pchMVCJointCodingOrder;		///<  texture-depth coding order
+  Bool		m_b3DVFlexOrder;		///<  flexible coding order flag
+#endif
+
 
   // coding structure
Index: /branches/0.3-nokia/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/0.3-nokia/source/App/TAppEncoder/TAppEncTop.cpp	(revision 33)
+++ /branches/0.3-nokia/source/App/TAppEncoder/TAppEncTop.cpp	(revision 34)
@@ -235,4 +235,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_iDepthFrameRcvdVector.push_back(0) ;
       m_acTEncDepthTopList.push_back(new TEncTop);
@@ -354,4 +377,7 @@
       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 CONSTRAINED_INTRA_PRED
       m_acTEncDepthTopList[iViewIdx]->setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
@@ -380,7 +406,11 @@
 #endif
 #if HHI_MPI
+#if FLEX_CODING_ORDER
+      m_acTEncDepthTopList[iViewIdx]->setUseMVI( (m_b3DVFlexOrder && isDepthFirst) ? false : m_bUseMVI );
+#else
       m_acTEncDepthTopList[iViewIdx]->setUseMVI( m_bUseMVI );
 #endif
-
+#endif
+      
       m_acTEncDepthTopList[iViewIdx]->setPictureDigestEnabled(m_pictureDigestEnabled);
 
@@ -591,5 +621,4 @@
   std::vector<Bool>  bDepthEos ;
   std::vector<Bool>  bContinueReadingDepthPics ;
-
   for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
   {
@@ -689,4 +718,62 @@
 #endif
 
+#if FLEX_CODING_ORDER
+    if (m_b3DVFlexOrder)
+    {
+      Int i=0;
+      Int iViewIdx = 0;
+      bool bThisViewContinueReadingPics = false;
+      bool bThisViewContinueReadingDepthPics = false;
+      Int iNumberofDepthViews = m_bUsingDepthMaps?m_iNumberOfViews:0;
+      for(Int j=0; j < (m_iNumberOfViews+ iNumberofDepthViews); j++ )     // Start encoding
+      {
+        if (m_pchMVCJointCodingOrder[i]=='T')
+        {
+          i++;
+          assert(isdigit(m_pchMVCJointCodingOrder[i]));
+          iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
+          bThisViewContinueReadingPics = bContinueReadingPics[iViewIdx];
+          m_acTEncTopList[iViewIdx]->encode( bEos[iViewIdx], m_cListPicYuvRecMap[iViewIdx], pcBitstream, bThisViewContinueReadingPics );
+          bContinueReadingPics[iViewIdx]=bThisViewContinueReadingPics;
+          bAllContinueReadingPics = bAllContinueReadingPics||bContinueReadingPics[iViewIdx];
+
+          if(pcBitstream->getNumberOfWrittenBits()!=0)
+          {
+            m_cTVideoIOBitsFile.writeBits( pcBitstream );
+          }
+          pcBitstream->resetBits(); //GT: also done later in ....
+          pcBitstream->rewindStreamPacket( );
+          // write bistream to file if necessary
+          xWriteOutput( iViewIdx ); //GT: Write Reconfiles (when gop is complete?)
+          i++;
+        }
+        else if ( m_pchMVCJointCodingOrder[i] == 'D')
+        {
+          i++;
+          if( m_bUsingDepthMaps )
+          {
+            assert(isdigit(m_pchMVCJointCodingOrder[i]));
+            iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
+            bThisViewContinueReadingDepthPics = bContinueReadingDepthPics[iViewIdx];
+            m_acTEncDepthTopList[iViewIdx]->encode( bDepthEos[iViewIdx], m_cListPicYuvDepthRecMap[iViewIdx], pcBitstream, bThisViewContinueReadingDepthPics );
+            bContinueReadingDepthPics[iViewIdx]=bThisViewContinueReadingDepthPics;
+
+            bAllContinueReadingDepthPics = bAllContinueReadingDepthPics||bContinueReadingDepthPics[iViewIdx];
+            if(pcBitstream->getNumberOfWrittenBits()!=0)
+            {
+              m_cTVideoIOBitsFile.writeBits( pcBitstream );
+            }
+            pcBitstream->resetBits();
+            pcBitstream->rewindStreamPacket( );
+            // write bistream to file if necessary
+            xWriteOutput( iViewIdx, true );
+            i++;
+          }
+        }
+      }
+    }
+    else
+    {
+#endif
     //GT: Encode
     for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )     // Start encoding
@@ -723,5 +810,7 @@
       }
     }
-
+#if FLEX_CODING_ORDER
+	}
+#endif
     // delete extra picture buffers
     if( bCurrPocCoded )
Index: /branches/0.3-nokia/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/0.3-nokia/source/Lib/TLibCommon/TComSlice.cpp	(revision 33)
+++ /branches/0.3-nokia/source/Lib/TLibCommon/TComSlice.cpp	(revision 34)
@@ -687,4 +687,7 @@
   m_bUseDMM = false;
 #endif
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+   m_bUseDMM34 = false;
+#endif
 }
 
Index: /branches/0.3-nokia/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/0.3-nokia/source/Lib/TLibCommon/TComSlice.h	(revision 33)
+++ /branches/0.3-nokia/source/Lib/TLibCommon/TComSlice.h	(revision 34)
@@ -134,4 +134,7 @@
   Bool  m_bUseDMM;
 #endif
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  Bool  m_bUseDMM34;
+#endif
 
 #if DEPTH_MAP_GENERATION
@@ -230,5 +233,8 @@
   Void setUseDMM( Bool b ) { m_bUseDMM = b;    }
 #endif
-
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  Bool getUseDMM34()         { return m_bUseDMM34; }
+  Void setUseDMM34( Bool b ) { m_bUseDMM34 = b;    }
+#endif
 
 #if DCM_COMB_LIST
Index: /branches/0.3-nokia/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/0.3-nokia/source/Lib/TLibCommon/TypeDef.h	(revision 33)
+++ /branches/0.3-nokia/source/Lib/TLibCommon/TypeDef.h	(revision 34)
@@ -40,4 +40,5 @@
 
 
+#define FLEX_CODING_ORDER				        1
 
 #define SONY_COLPIC_AVAILABILITY  		  1
@@ -329,4 +330,6 @@
 #endif
 
+
+
 // ====================================================================================================================
 // Basic type redefinition
Index: /branches/0.3-nokia/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/0.3-nokia/source/Lib/TLibDecoder/TDecTop.cpp	(revision 33)
+++ /branches/0.3-nokia/source/Lib/TLibDecoder/TDecTop.cpp	(revision 34)
@@ -513,5 +513,10 @@
 
 #if DCM_SKIP_DECODING_FRAMES
+#if FLEX_CODING_ORDER
+Bool TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame,  Int& iPOCLastDisplay, Bool& bNewPictureType)
+#else
 Bool TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame,  Int& iPOCLastDisplay)
+
+#endif
 #else
 Void TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS )
@@ -541,4 +546,7 @@
       TComSPS cTempSPS;
       m_cEntropyDecoder.decodeSPS( &cTempSPS );
+#if FLEX_CODING_ORDER
+      m_cNewSPS = cTempSPS;
+#endif
 
       if( (m_iViewIdx == cTempSPS.getViewId()) && ( m_bIsDepth == cTempSPS.isDepth() ) )
@@ -615,4 +623,7 @@
       {
         m_uiPrevPOC = m_apcSlicePilot->getPOC();
+#if FLEX_CODING_ORDER
+        bNewPictureType = m_cNewSPS.isDepth();
+#endif
         return true;
       }
@@ -697,7 +708,16 @@
         std::vector<TComPic*> apcSpatRefPics = getDecTop()->getSpatialRefPics( pcPic->getViewIdx(), pcSlice->getPOC(), m_cSPS.isDepth() );
         TComPic * const pcTexturePic = m_cSPS.isDepth() ? getDecTop()->getPicFromView( pcPic->getViewIdx(), pcSlice->getPOC(), false ) : NULL;
+
+#if FLEX_CODING_ORDER
+        if (pcTexturePic != NULL)
+        {
+          assert( ! m_cSPS.isDepth() || pcTexturePic != NULL );
+          pcSlice->setTexturePic( pcTexturePic );
+        }
+#else
         assert( ! m_cSPS.isDepth() || pcTexturePic != NULL );
         pcSlice->setTexturePic( pcTexturePic );
         pcSlice->setViewIdx( pcPic->getViewIdx() );
+#endif
 #if SONY_COLPIC_AVAILABILITY
         pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
Index: /branches/0.3-nokia/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /branches/0.3-nokia/source/Lib/TLibDecoder/TDecTop.h	(revision 33)
+++ /branches/0.3-nokia/source/Lib/TLibDecoder/TDecTop.h	(revision 34)
@@ -111,4 +111,7 @@
   TComList<TComPic*>      m_cListPic;         //  Dynamic buffer
   TComSPS                 m_cSPS;
+#if FLEX_CODING_ORDER
+  TComSPS                 m_cNewSPS;
+#endif
   TComPPS                 m_cPPS;
   TComSlice*              m_apcSlicePilot;
@@ -167,5 +170,10 @@
   Void  init( TAppDecTop* pcTAppDecTop, Bool bFirstInstance = true );
 #if DCM_SKIP_DECODING_FRAMES
+#if FLEX_CODING_ORDER
+  Bool  decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame, Int& iPOCLastDisplay, Bool& bNewPictureType);
+#else
   Bool  decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame, Int& iPOCLastDisplay);
+
+#endif
 #else
   Void  decode ( Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS );
Index: /branches/0.3-nokia/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /branches/0.3-nokia/source/Lib/TLibEncoder/TEncCfg.h	(revision 33)
+++ /branches/0.3-nokia/source/Lib/TLibEncoder/TEncCfg.h	(revision 34)
@@ -159,4 +159,7 @@
   Bool m_bUseDMM;
 #endif
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  Bool m_bUseDMM34;
+#endif
 #if HHI_MPI
   Bool m_bUseMVI;
@@ -424,5 +427,8 @@
   Bool getUseDMM()        { return m_bUseDMM; }
 #endif
-
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  Void setUseDMM34( Bool b) { m_bUseDMM34 = b;    }
+  Bool getUseDMM34()        { return m_bUseDMM34; }
+#endif
 #if LM_CHROMA
   Bool getUseLMChroma                       ()      { return m_bUseLMChroma;        }
Index: /branches/0.3-nokia/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- /branches/0.3-nokia/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 33)
+++ /branches/0.3-nokia/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 34)
@@ -1126,4 +1126,11 @@
 #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/0.3-nokia/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/0.3-nokia/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 33)
+++ /branches/0.3-nokia/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 34)
@@ -1926,4 +1926,8 @@
 #endif
 #if HHI_DMM_PRED_TEX
+#if FLEX_CODING_ORDER
+      if ( pcCU->getSlice()->getSPS()->getUseDMM34() )
+      {
+#endif
       TComYuv cTempYuv; cTempYuv.create( uiWidth, uiHeight ); cTempYuv.clear();
       Pel* piTempY      = cTempYuv.getLumaAddr();
@@ -1958,6 +1962,8 @@
         uiRdModeList[ uiNewMaxMode++ ] = DMM_CONTOUR_PREDTEX_D_IDX;
       }
-
       cTempYuv.destroy();
+#if FLEX_CODING_ORDER
+      }
+#endif
 #endif
     }
@@ -1988,5 +1994,9 @@
 #else
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+      if( m_pcEncCfg->isDepthCoder() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight, pcCU->getSlice()->getSPS()->getUseDMM34() ) )
+#else
       if( m_pcEncCfg->isDepthCoder() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight ) )
+#endif
         continue;
 #endif
@@ -2076,5 +2086,9 @@
 #else
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+      if( m_pcEncCfg->isDepthCoder() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight, pcCU->getSlice()->getSPS()->getUseDMM34() ) )
+#else
       if( m_pcEncCfg->isDepthCoder() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight ) )
+#endif
         continue;
 #endif
@@ -2719,5 +2733,9 @@
 }
 
+#if 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 <= MAX_MODE_ID_INTRA_DIR ) return true;
@@ -2747,4 +2765,10 @@
       bDMMAvailable = false;
     }
+#if FLEX_CODING_ORDER
+    if ( !bDMMAvailable34 )
+    {
+      bDMMAvailable = false;
+    }
+#endif
   }
 
Index: /branches/0.3-nokia/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- /branches/0.3-nokia/source/Lib/TLibEncoder/TEncSearch.h	(revision 33)
+++ /branches/0.3-nokia/source/Lib/TLibEncoder/TEncSearch.h	(revision 34)
@@ -207,5 +207,10 @@
   Bool predIntraLumaDMMAvailable( UInt         uiMode, 
                                   UInt         uiWidth, 
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+                                  UInt         uiHeight, 
+                                  Bool         bDMMAvailable34 );
+#else
                                   UInt         uiHeight );
+#endif
 #endif
 #if HHI_DMM_WEDGE_INTRA
Index: /branches/0.3-nokia/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /branches/0.3-nokia/source/Lib/TLibEncoder/TEncTop.cpp	(revision 33)
+++ /branches/0.3-nokia/source/Lib/TLibEncoder/TEncTop.cpp	(revision 34)
@@ -287,6 +287,9 @@
 
   bool bSomethingCoded = false ;
-
+#if FLEX_CODING_ORDER  
+  if (TEncTop::m_bPicWaitingForCoding )
+#else
   if (m_bPicWaitingForCoding )
+#endif
   {
     std::map<Int, TComPic*>::iterator cIter = m_acInputPicMap.find( (Int)m_cSeqIter.getPoc() );
@@ -615,4 +618,7 @@
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
   m_cSPS.setUseDMM( m_bUseDMM );
+#endif
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  m_cSPS.setUseDMM34( m_bUseDMM34 );
 #endif
 #if HHI_MPI
