Index: trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 189)
+++ trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 210)
@@ -82,5 +82,5 @@
 Void TAppDecTop::decode()
 {
-#if VIDYO_VPS_INTEGRATION
+#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
   increaseNumberOfViews( 0, 0, 0 );
 #else
@@ -88,4 +88,12 @@
 #endif
   
+#if FLEX_CODING_ORDER_M23723
+  Int iDepthViewIdx = 0;
+  Int iTextureViewIdx=0;
+  Bool firstFrame=1;
+  Bool viewIdZero=true;
+  Int fcoIndex=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);
@@ -102,4 +110,12 @@
     pcListPic[i] = NULL;
     newPicture[i] = false;
+#if FLEX_CODING_ORDER_M23723
+#if  FIX_FCO_COMP_WARNING
+    m_fcoOrder[i] = ' ';
+#else
+    m_fcoOrder[i]=NULL;
+#endif
+#endif
+
   }
 
@@ -145,4 +161,9 @@
     {
       read(nalu, nalUnit);
+#if QC_MVHEVC_B0046
+    viewDepthId = nalu.m_layerId;
+    Int depth = 0;
+    Int viewId = viewDepthId;
+#else
 #if VIDYO_VPS_INTEGRATION
       Int viewId = 0;
@@ -156,15 +177,114 @@
         depth = getVPSAccess()->getActiveVPS()->getDepthFlag(nalu.m_layerId);
       }
+#if FLEX_CODING_ORDER_M23723
+      if (viewId>0)
+      {
+        viewIdZero=false;
+      }
+      if (viewIdZero==false&&viewId==0)
+      {
+        firstFrame=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 (firstFrame)
+      { // if the current view is first frame, we set the viewDepthId as texture plus depth and get the FCO order 
+        viewDepthId = iDepthViewIdx+iTextureViewIdx;
+        m_fcoViewDepthId=viewDepthId;
+      }
+      else
+      {//if current view is not first frame, we set the viewDepthId depended on the FCO order
+        viewDepthId=0;
+        if (depth)
+        {
+          for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ )
+          {
+            if (m_fcoOrder[fcoIndex]=='D')
+            {
+              if (viewId==viewDepthId)
+                break;
+              else
+                viewDepthId++;
+            }
+          }
+        }
+        else
+        {
+          for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ )
+          {
+            if (m_fcoOrder[fcoIndex]=='T')
+            {
+              if (viewId==viewDepthId)
+                break;
+              else
+                viewDepthId++;
+            }
+          }
+        }
+
+        viewDepthId=fcoIndex;
+
+      }
+
+
+#else
       viewDepthId = nalu.m_layerId;   // coding order T0D0T1D1T2D2
+#endif
+    
 #else
       Int viewId = nalu.m_viewId;
       Int depth = nalu.m_isDepth ? 1 : 0;
+#if FLEX_CODING_ORDER_M23723
+      if (viewId>0)
+      {
+        viewIdZero=false;
+      }
+      if (viewIdZero==false&&viewId==0)
+      {
+        firstFrame=0;
+      }
+      if (firstFrame)
+      {
+        viewDepthId = iDepthViewIdx+iTextureViewIdx;
+        m_fcoViewDepthId=viewDepthId;
+      }
+      else
+      {
+        viewDepthId=0;
+        if (depth)
+        {
+          for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ )
+          {
+            if (m_fcoOrder[fcoIndex]=='D')
+            {
+              if (viewId==viewDepthId)
+                break;
+              else
+                viewDepthId++;
+            }
+          }
+        }
+        else
+        {
+          for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ )
+          {
+            if (m_fcoOrder[fcoIndex]=='T')
+            {
+              if (viewId==viewDepthId)
+                break;
+              else
+                viewDepthId++;
+            }
+          }
+        }
+        viewDepthId=fcoIndex;
+      }
+#else
       viewDepthId = viewId * 2 + depth;   // coding order T0D0T1D1T2D2
 #endif
-      
+#endif
+#endif     
       newPicture[viewDepthId] = false;
       if( viewDepthId >= m_tDecTop.size() )      
       {
-#if VIDYO_VPS_INTEGRATION
+#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
         increaseNumberOfViews( viewDepthId, viewId, depth );
 #else
@@ -195,4 +315,14 @@
       if( !(m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) )
       {
+#if QC_MVHEVC_B0046
+        if(viewDepthId && m_tDecTop[viewDepthId]->m_bFirstNal== false)
+        {
+          m_tDecTop[viewDepthId]->m_bFirstNal = true;
+          ParameterSetManagerDecoder* pDecV0 = m_tDecTop[0]->xGetParaSetDec();
+          m_tDecTop[viewDepthId]->xCopyVPS(pDecV0->getPrefetchedVPS(0));
+          m_tDecTop[viewDepthId]->xCopySPS(pDecV0->getPrefetchedSPS(0));
+          m_tDecTop[viewDepthId]->xCopyPPS(pDecV0->getPrefetchedPPS(0));
+        }
+#endif
         newPicture[viewDepthId] = m_tDecTop[viewDepthId]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[viewDepthId]);
         if (newPicture[viewDepthId])
@@ -209,4 +339,20 @@
         {
           previousPictureDecoded = true;
+#if FLEX_CODING_ORDER_M23723
+        if (firstFrame)
+        {
+            if (depth)
+            {
+                iDepthViewIdx++;
+                m_fcoOrder[viewDepthId]='D';
+            }
+            else
+           {
+                iTextureViewIdx++;
+                m_fcoOrder[viewDepthId]='T';
+           }
+          }
+
+#endif
         }
       }
@@ -218,5 +364,10 @@
     if( pcListPic[viewDepthId] )
     {
+#if QC_REM_IDV_B0046
+      Int iviewId = m_tDecTop[viewDepthId]->getViewId();
+      if( newPicture[viewDepthId] && (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR || ((nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR && iviewId) && m_tDecTop[viewDepthId]->getNalUnitTypeBaseView() == NAL_UNIT_CODED_SLICE_IDR)) )
+#else
       if( newPicture[viewDepthId] && (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR || (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDV && m_tDecTop[viewDepthId]->getNalUnitTypeBaseView() == NAL_UNIT_CODED_SLICE_IDR)) )
+#endif
       {
         xFlushOutput( pcListPic[viewDepthId], viewDepthId );
@@ -275,4 +426,13 @@
         m_tDecTop[viewDepthIdx]->destroy() ;
       }
+#if QC_MVHEVC_B0046
+      if(viewDepthIdx)
+      {
+         //Call clear function to remove the record, which has been freed during viewDepthIdx = 0 case.
+        m_tDecTop[viewDepthIdx]->xGetParaSetDec()->clearSPS();
+        m_tDecTop[viewDepthIdx]->xGetParaSetDec()->clearVPS();
+        m_tDecTop[viewDepthIdx]->xGetParaSetDec()->clearPPS();
+      }
+#endif
       delete m_tDecTop[viewDepthIdx] ; 
       m_tDecTop[viewDepthIdx] = NULL ;
@@ -416,5 +576,5 @@
   m_pocLastDisplay[viewDepthId] = -MAX_INT;
 }
-#if VIDYO_VPS_INTEGRATION
+#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
 Void  TAppDecTop::increaseNumberOfViews  ( UInt layerId, UInt viewId, UInt isDepth )
 #else
@@ -422,5 +582,5 @@
 #endif
 {
-#if VIDYO_VPS_INTEGRATION
+#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
   Int newNumberOfViewDepth = layerId + 1;
 #endif
@@ -429,5 +589,5 @@
     m_outputBitDepth = g_uiBitDepth + g_uiBitIncrement;
   }
-#if !VIDYO_VPS_INTEGRATION
+#if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046
   Int viewId = (newNumberOfViewDepth-1)>>1;   // coding order T0D0T1D1T2D2
   Bool isDepth = ((newNumberOfViewDepth % 2) == 0);  // coding order T0D0T1D1T2D2
@@ -442,5 +602,5 @@
       m_tVideoIOYuvReconFile.push_back(new TVideoIOYuv);
       Char buffer[4];
-#if VIDYO_VPS_INTEGRATION
+#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
       sprintf(buffer,"_%i", viewId );
 #else
@@ -448,5 +608,5 @@
 #endif
       Char* nextFilename = NULL;
-#if VIDYO_VPS_INTEGRATION
+#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
       if( isDepth)
 #else
@@ -463,5 +623,5 @@
         xAppendToFileNameEnd( m_pchReconFile, buffer, nextFilename);
       }
-#if !VIDYO_VPS_INTEGRATION
+#if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046
       if( isDepth || ( !isDepth && (m_tVideoIOYuvReconFile.size() % 2) == 1 ) )
 #endif
@@ -480,5 +640,5 @@
   {
     m_tDecTop.push_back(new TDecTop);
-#if !VIDYO_VPS_INTEGRATION
+#if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046
     if( isDepth || ( !isDepth && (m_tVideoIOYuvReconFile.size() % 2) == 1 ) )
     {
@@ -490,5 +650,5 @@
       m_tDecTop.back()->setPictureDigestEnabled(m_pictureDigestEnabled);
       m_tDecTop.back()->setCamParsCollector( &m_cCamParsCollector );
-#if !VIDYO_VPS_INTEGRATION
+#if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046
     }
 #endif
@@ -498,5 +658,60 @@
 TDecTop* TAppDecTop::getTDecTop( Int viewId, Bool isDepth )
 { 
+#if FLEX_CODING_ORDER_M23723
+  Int viewnumber=0;
+  Int i=0;
+  Bool fcoFlag=0;
+  if (viewId>m_fcoViewDepthId)
+  {
+    return NULL;
+  }
+  else
+  {
+    if (isDepth)
+   {
+      for ( i=0; i<=m_fcoViewDepthId;i++)
+      {
+         if (m_fcoOrder[i]=='D')
+         {
+           if (viewnumber==viewId)
+           {
+             fcoFlag=1;
+             break;
+           }
+           else
+             viewnumber++;
+         }
+      }
+    }
+    else
+    {
+      for ( i=0; i<=m_fcoViewDepthId;i++)
+      {
+        if (m_fcoOrder[i]=='T')
+        {
+          if (viewnumber==viewId)
+          {
+            fcoFlag=1;
+            break;
+          }
+          else
+            viewnumber++;
+        }
+      }
+    }
+    if (fcoFlag)
+    {
+      return m_tDecTop[i];
+    }
+    else
+      return NULL;
+    
+  }
+
+    // coding order T0D0T1D1T2D2
+#else
   return m_tDecTop[(isDepth ? 1 : 0) + viewId * 2];  // coding order T0D0T1D1T2D2
+#endif
+ 
 } 
 
@@ -517,4 +732,7 @@
   assert( ( viewId >= 0 ) );
 
+#if FLEX_CODING_ORDER_M23723
+if (getTDecTop(viewId,isDepth))
+{
   TComList<TComPic*>* apcListPic = getTDecTop( viewId, isDepth )->getListPic();
   TComPic* pcPic = NULL;
@@ -529,3 +747,20 @@
   return pcPic;
 }
+else
+  return NULL;
+#else
+
+  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;
+#endif
+}
 //! \}
