Index: branches/HTM-4.0-Nokia/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- branches/HTM-4.0-Nokia/source/App/TAppDecoder/TAppDecTop.cpp	(revision 137)
+++ 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 137)
+++ 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;
