Index: trunk/source/App/TAppDecoder/TAppDecCfg.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 443)
+++ trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 608)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -42,4 +42,7 @@
 #include "TAppCommon/program_options_lite.h"
 
+#if H_MV
+#include <cassert>
+#endif
 #ifdef WIN32
 #define strdup _strdup
@@ -61,8 +64,11 @@
 Bool TAppDecCfg::parseCfg( Int argc, Char* argv[] )
 {
-  bool do_help = false;
+  Bool do_help = false;
   string cfg_BitstreamFile;
   string cfg_ReconFile;
+  string cfg_TargetDecLayerIdSetFile;
+#if H_3D
   string cfg_ScaleOffsetFile;
+#endif
 
   po::Options opts;
@@ -72,17 +78,25 @@
   ("ReconFile,o",     cfg_ReconFile,     string(""), "reconstructed YUV output file name\n"
                                                      "YUV writing is skipped if omitted")
+#if H_3D
   ("ScaleOffsetFile,p", cfg_ScaleOffsetFile, string(""), "file with coded scales and offsets")
+#endif
   ("SkipFrames,s", m_iSkipFrame, 0, "number of frames to skip before random access")
-  ("OutputBitDepth,d", m_outputBitDepth, 0u, "bit depth of YUV output file (use 0 for native depth)")
+  ("OutputBitDepth,d", m_outputBitDepthY, 0, "bit depth of YUV output luma component (default: use 0 for native depth)")
+  ("OutputBitDepthC,d", m_outputBitDepthC, 0, "bit depth of YUV output chroma component (default: use 0 for native depth)")
+#if H_MV
+  ("MaxLayerId,-ls", m_maxLayerId, MAX_NUM_LAYER_IDS-1, "Maximum LayerId to be decoded.")
+#endif
   ("MaxTemporalLayer,t", m_iMaxTemporalLayer, -1, "Maximum Temporal Layer to be decoded. -1 to decode all layers")
-  ("SEIpictureDigest", m_pictureDigestEnabled, true, "Control handling of picture_digest SEI messages\n"
-                                              "\t1: check\n"
-                                              "\t0: ignore")
+  ("SEIDecodedPictureHash", m_decodedPictureHashSEIEnabled, 1, "Control handling of decoded picture hash SEI messages\n"
+                                              "\t1: check hash in SEI messages if available in the bitstream\n"
+                                              "\t0: ignore SEI message")
+  ("SEIpictureDigest", m_decodedPictureHashSEIEnabled, 1, "deprecated alias for SEIDecodedPictureHash")
+  ("TarDecLayerIdSetFile,l", cfg_TargetDecLayerIdSetFile, string(""), "targetDecLayerIdSet file name. The file should include white space separated LayerId values to be decoded. Omitting the option or a value of -1 in the file decodes all layers.")
+  ("RespectDefDispWindow,w", m_respectDefDispWindow, 0, "Only output content inside the default display window\n")
   ;
+  po::setDefaults(opts);
+  const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
 
-  po::setDefaults(opts);
-  const list<const char*>& argv_unhandled = po::scanArgv(opts, argc, (const char**) argv);
-
-  for (list<const char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
+  for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
   {
     fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
@@ -98,16 +112,72 @@
   m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
   m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
+
+#if H_3D
   m_pchScaleOffsetFile = cfg_ScaleOffsetFile.empty() ? NULL : strdup(cfg_ScaleOffsetFile.c_str());
-
-
+#endif
   if (!m_pchBitstreamFile)
   {
-    fprintf(stderr, "No input file specified, aborting\n");
+    fprintf(stderr, "No input file specifed, aborting\n");
     return false;
   }
+
+  if ( !cfg_TargetDecLayerIdSetFile.empty() )
+  {
+    FILE* targetDecLayerIdSetFile = fopen ( cfg_TargetDecLayerIdSetFile.c_str(), "r" );
+    if ( targetDecLayerIdSetFile )
+    {
+      Bool isLayerIdZeroIncluded = false;
+      while ( !feof(targetDecLayerIdSetFile) )
+      {
+        Int layerIdParsed = 0;
+        if ( fscanf( targetDecLayerIdSetFile, "%d ", &layerIdParsed ) != 1 )
+        {
+          if ( m_targetDecLayerIdSet.size() == 0 )
+          {
+            fprintf(stderr, "No LayerId could be parsed in file %s. Decoding all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
+          }
+          break;
+        }
+        if ( layerIdParsed  == -1 ) // The file includes a -1, which means all LayerIds are to be decoded.
+        {
+          m_targetDecLayerIdSet.clear(); // Empty set means decoding all layers.
+          break;
+        }
+        if ( layerIdParsed < 0 || layerIdParsed >= MAX_NUM_LAYER_IDS )
+        {
+          fprintf(stderr, "Warning! Parsed LayerId %d is not withing allowed range [0,%d]. Ignoring this value.\n", layerIdParsed, MAX_NUM_LAYER_IDS-1 );
+        }
+        else
+        {
+          isLayerIdZeroIncluded = layerIdParsed == 0 ? true : isLayerIdZeroIncluded;
+          m_targetDecLayerIdSet.push_back ( layerIdParsed );
+        }
+      }
+      fclose (targetDecLayerIdSetFile);
+      if ( m_targetDecLayerIdSet.size() > 0 && !isLayerIdZeroIncluded )
+      {
+        fprintf(stderr, "TargetDecLayerIdSet must contain LayerId=0, aborting" );
+        return false;
+      }
+    }
+    else
+    {
+      fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
+    }
+  }
+#if H_MV
+  else
+  {
+    for ( Int curLayerId = 0; curLayerId <= m_maxLayerId; curLayerId++ )
+    {
+      m_targetDecLayerIdSet.push_back( curLayerId );
+    }
+  }
+#endif
 
   return true;
 }
 
+#if H_MV
 Void TAppDecCfg::xAppendToFileNameEnd( Char* pchInputFileName, const Char* pchStringToAppend, Char*& rpchOutputFileName)
 {
@@ -125,4 +195,4 @@
   rpchOutputFileName[iInLength+iAppendLength] = '\0';          
 }
-
+#endif
 //! \}
Index: trunk/source/App/TAppDecoder/TAppDecCfg.h
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecCfg.h	(revision 443)
+++ trunk/source/App/TAppDecoder/TAppDecCfg.h	(revision 608)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -44,4 +44,5 @@
 
 #include "TLibCommon/CommonDef.h"
+#include <vector>
 
 //! \ingroup TAppDecoder
@@ -56,16 +57,40 @@
 {
 protected:
-  char*         m_pchBitstreamFile;                   ///< input bitstream file name
-  char*         m_pchReconFile;                       ///< output reconstruction file name
-  char*         m_pchScaleOffsetFile;                 ///< output coded scale and offset parameters
+  Char*         m_pchBitstreamFile;                   ///< input bitstream file name
+#if H_MV
+  Int           m_maxLayerId;                         ///< maximum nuh_layer_id decoded
+  std::vector<Char*> m_pchReconFiles;                 ///< array of output reconstruction file name create from output reconstruction file name
+#endif
+  Char*         m_pchReconFile;                       ///< output reconstruction file name
+#if H_3D
+  Char*         m_pchScaleOffsetFile;                 ///< output coded scale and offset parameters
+#endif
   Int           m_iSkipFrame;                         ///< counter for frames prior to the random access point to skip
-  UInt          m_outputBitDepth;                     ///< bit depth used for writing output
+  Int           m_outputBitDepthY;                    ///< bit depth used for writing output (luma)
+  Int           m_outputBitDepthC;                    ///< bit depth used for writing output (chroma)t
 
   Int           m_iMaxTemporalLayer;                  ///< maximum temporal layer to be decoded
-  bool m_pictureDigestEnabled; ///< enable(1)/disable(0) acting on SEI picture_digest message
+  Int           m_decodedPictureHashSEIEnabled;       ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message
+
+  std::vector<Int> m_targetDecLayerIdSet;             ///< set of LayerIds to be included in the sub-bitstream extraction process.
+  Int           m_respectDefDispWindow;               ///< Only output content inside the default display window 
+
+#if H_MV
   Void xAppendToFileNameEnd( Char* pchInputFileName, const Char* pchStringToAppend, Char*& rpchOutputFileName); ///< create filenames
-
+#endif
 public:
-  TAppDecCfg()          {}
+  TAppDecCfg()
+  : m_pchBitstreamFile(NULL)
+#if H_MV
+  , m_maxLayerId(0)
+#endif
+  , m_pchReconFile(NULL)
+  , m_iSkipFrame(0)
+  , m_outputBitDepthY(0)
+  , m_outputBitDepthC(0)
+  , m_iMaxTemporalLayer(-1)
+  , m_decodedPictureHashSEIEnabled(0)
+  , m_respectDefDispWindow(0)
+  {}
   virtual ~TAppDecCfg() {}
   
Index: trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 443)
+++ trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 608)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -54,8 +54,17 @@
 
 TAppDecTop::TAppDecTop()
+#if !H_MV
+: m_iPOCLastDisplay(-MAX_INT)
+#else
+: m_numDecoders( 0 )
+#endif
 {
   ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag));
-  m_useDepth = false;
-  m_pScaleOffsetFile  = 0;
+#if H_MV
+  for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++) m_layerIdToDecIdx[i] = -1; 
+#endif
+#if H_3D
+    m_pScaleOffsetFile  = 0;
+#endif
 }
 
@@ -66,4 +75,31 @@
 Void TAppDecTop::destroy()
 {
+  if (m_pchBitstreamFile)
+  {
+    free (m_pchBitstreamFile);
+    m_pchBitstreamFile = NULL;
+  }
+#if H_MV
+  for (Int decIdx = 0; decIdx < m_numDecoders; decIdx++)
+  {
+    if (m_pchReconFiles[decIdx])
+    {
+      free (m_pchReconFiles[decIdx]);
+      m_pchReconFiles[decIdx] = NULL;
+    }
+  }
+#endif
+  if (m_pchReconFile)
+  {
+    free (m_pchReconFile);
+    m_pchReconFile = NULL;
+  }
+#if H_3D
+  if (m_pchScaleOffsetFile)
+  {
+    free (m_pchScaleOffsetFile);
+    m_pchScaleOffsetFile = NULL; 
+  }
+#endif
 }
 
@@ -82,34 +118,9 @@
 Void TAppDecTop::decode()
 {
-#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
-  increaseNumberOfViews( 0, 0, 0 );
-#else
-  increaseNumberOfViews( 1 );
-#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
-
-  Int                 viewDepthId = 0;
-  Int                 previousViewDepthId  = 0;
-  UInt                uiPOC[MAX_VIEW_NUM*2];
-  TComList<TComPic*>* pcListPic[MAX_VIEW_NUM*2];
-  Bool                newPicture[MAX_VIEW_NUM*2];
-  Bool                previousPictureDecoded = false;
-  for( Int i = 0; i < MAX_VIEW_NUM*2; i++ )
-  {
-    uiPOC[i] = 0;
-    pcListPic[i] = NULL;
-    newPicture[i] = false;
-#if FLEX_CODING_ORDER_M23723
-    m_fcoOrder[i] = ' ';
-#endif
-
-  }
+  Int                 poc;
+#if H_MV
+  poc = -1; 
+#endif
+  TComList<TComPic*>* pcListPic = NULL;
 
   ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary);
@@ -120,4 +131,5 @@
   }
 
+#if H_3D
   if( m_pchScaleOffsetFile ) 
   { 
@@ -126,7 +138,29 @@
   }
   m_cCamParsCollector.init( m_pScaleOffsetFile );
-
+#endif
   InputByteStream bytestream(bitstreamFile);
 
+  // create & initialize internal classes
+  xCreateDecLib();
+  xInitDecLib  ();
+#if !H_MV
+  m_iPOCLastDisplay += m_iSkipFrame;      // set the last displayed POC correctly for skip forward.
+
+  // main decoder loop
+  Bool recon_opened = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
+#else
+#if H_3D
+  Int  pocCurrPic        = -MAX_INT;     
+  Int  pocLastPic        = -MAX_INT;   
+#endif
+
+  Int  layerIdCurrPic    = 0; 
+
+  Int  decIdxLastPic     = 0; 
+  Int  decIdxCurrPic     = 0; 
+
+  Bool firstSlice        = true; 
+#endif
+ 
   while (!!bitstreamFile)
   {
@@ -136,5 +170,14 @@
      * nal unit. */
     streampos location = bitstreamFile.tellg();
+#if H_MV
+#if ENC_DEC_TRACE
+    Int64 symCount = g_nSymbolCounter;
+#endif
+#endif
     AnnexBStats stats = AnnexBStats();
+#if !H_MV
+    Bool bPreviousPictureDecoded = false;
+#endif
+
     vector<uint8_t> nalUnit;
     InputNALUnit nalu;
@@ -142,4 +185,12 @@
 
     // call actual decoding function
+    Bool bNewPicture = false;
+#if H_MV
+    Bool newSliceDiffPoc   = false;
+    Bool newSliceDiffLayer = false;
+#if H_3D
+    Bool allLayersDecoded  = false;     
+#endif
+#endif
     if (nalUnit.empty())
     {
@@ -154,170 +205,65 @@
     {
       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;
-      Int depth = 0;
+#if H_MV      
+      Int decIdx     = xGetDecoderIdx( nalu.m_layerId , true );
       
-      if(nalu.m_nalUnitType != NAL_UNIT_VPS || nalu.m_layerId)
-      {
-        // code assumes that the first nal unit is VPS
-        // currently, this is a hack that requires non-first VPSs have non-zero layer_id
-        viewId = getVPSAccess()->getActiveVPS()->getViewId(nalu.m_layerId);
-        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;
+      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) )
+      {
+        bNewPicture = false;
       }
       else
-      {//if current view is not first frame, we set the viewDepthId depended on the FCO order
-        viewDepthId=0;
-        if (depth)
+      { 
+        newSliceDiffLayer = nalu.isSlice() && ( nalu.m_layerId != layerIdCurrPic ) && !firstSlice;
+        newSliceDiffPoc   = m_tDecTop[decIdx]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[decIdx], newSliceDiffLayer );
+        // decode function only returns true when all of the following conditions are true
+        // - poc in particular layer changes
+        // - nalu does not belong to first slice in layer
+        // - nalu.isSlice() == true      
+
+        bNewPicture       = newSliceDiffLayer || newSliceDiffPoc; 
+
+        if ( nalu.isSlice() && firstSlice )
         {
-          for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ )
-          {
-            if (m_fcoOrder[fcoIndex]=='D')
-            {
-              if (viewId==viewDepthId)
-                break;
-              else
-                viewDepthId++;
-            }
-          }
+          layerIdCurrPic = nalu.m_layerId; 
+#if H_3D
+          pocCurrPic     = m_tDecTop[decIdx]->getCurrPoc(); 
+#endif
+          decIdxCurrPic  = decIdx; 
+          firstSlice     = false; 
+        }
+
+        if ( bNewPicture || !bitstreamFile )
+        { 
+          layerIdCurrPic    = nalu.m_layerId; 
+#if H_3D          
+          pocLastPic        = pocCurrPic; 
+          pocCurrPic        = m_tDecTop[decIdx]->getCurrPoc(); 
+#endif          
+          decIdxLastPic     = decIdxCurrPic; 
+          decIdxCurrPic     = decIdx; 
+#if H_3D
+          allLayersDecoded = ( pocCurrPic != pocLastPic );
+#endif
+        }
+
+        
+#else
+      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  )
+      {
+        if(bPreviousPictureDecoded)
+        {
+          bNewPicture = true;
+          bPreviousPictureDecoded = false;
         }
         else
         {
-          for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ )
-          {
-            if (m_fcoOrder[fcoIndex]=='T')
-            {
-              if (viewId==viewDepthId)
-                break;
-              else
-                viewDepthId++;
-            }
-          }
+          bNewPicture = false;
         }
-
-        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|QC_MVHEVC_B0046
-        increaseNumberOfViews( viewDepthId, viewId, depth );
-#else
-        increaseNumberOfViews( viewDepthId +1 );
-#endif   
-      }
-      if(m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer)
-      {
-        previousPictureDecoded = false; 
-      }
-      if(m_tDecTop.size() > 1 && (viewDepthId != previousViewDepthId) && previousPictureDecoded )
-      {
-        m_tDecTop[previousViewDepthId]->executeDeblockAndAlf(uiPOC[previousViewDepthId], pcListPic[previousViewDepthId], m_iSkipFrame, m_pocLastDisplay[previousViewDepthId]);
-      } 
-      if( ( viewDepthId == 0 && (viewDepthId != previousViewDepthId) ) || m_tDecTop.size() == 1 )
-      {
-#if H3D_IVRP
-        for( Int i = 0; i < m_tDecTop.size(); i++ )
-        {
-          m_tDecTop[i]->deleteExtraPicBuffers( uiPOC[i] );
-        }
-#endif
-        for( Int i = 0; i < m_tDecTop.size(); i++ )
-        {
-          m_tDecTop[i]->compressMotion( uiPOC[i] );
-        }
-      }   
-      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])
+        bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay);
+#endif
+        if (bNewPicture)
         {
           bitstreamFile.clear();
@@ -328,59 +274,115 @@
           bitstreamFile.seekg(location-streamoff(3));
           bytestream.reset();
+#if ENC_DEC_TRACE
+#if H_MV_ENC_DEC_TRAC
+          const Bool resetCounter = false; 
+          if ( resetCounter )
+          {
+            g_nSymbolCounter  = symCount; // Only reset counter SH becomes traced twice
+          }
+          else
+          {
+            g_disableHLSTrace = true;     // Trancing of second parsing of SH is not carried out
+          }          
+#else
+          g_nSymbolCounter = symCount;
+#endif
+#endif
         }
-        if( nalu.isSlice() )
-        {
-          previousPictureDecoded = true;
-#if FLEX_CODING_ORDER_M23723
-        if (firstFrame)
-        {
-            if (depth)
-            {
-                iDepthViewIdx++;
-                m_fcoOrder[viewDepthId]='D';
-            }
-            else
-           {
-                iTextureViewIdx++;
-                m_fcoOrder[viewDepthId]='T';
-           }
-          }
-
-#endif
-        }
-      }
-    }
-    if( ( (newPicture[viewDepthId] || !bitstreamFile) && m_tDecTop.size() == 1) || (!bitstreamFile && previousPictureDecoded == true) )  
-    {
-      m_tDecTop[viewDepthId]->executeDeblockAndAlf(uiPOC[viewDepthId], pcListPic[viewDepthId], m_iSkipFrame, m_pocLastDisplay[viewDepthId]);
-    }
-    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 );
+#if !H_MV
+        bPreviousPictureDecoded = true; 
+#endif
+      }
+    }
+    if (bNewPicture || !bitstreamFile)
+    {
+#if H_MV
+      assert( decIdxLastPic != -1 ); 
+      m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet );
+#else
+      m_cTDecTop.executeLoopFilters(poc, pcListPic);
+#endif
+    }
+#if H_3D
+    if ( allLayersDecoded || !bitstreamFile )
+    {
+      for( Int dI = 0; dI < m_numDecoders; dI++ )
+      {
+        TComPic* picLastCoded = m_ivPicLists.getPic( m_tDecTop[dI]->getLayerId(), pocLastPic );
+        assert( picLastCoded != NULL );        
+#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
+        picLastCoded->compressMotion(1);
+#else
+        picLastCoded->compressMotion();         
+#endif
+      }
+    }
+#endif
+
+    if( pcListPic )
+    {
+#if H_MV
+      if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] )
+#else
+      if ( m_pchReconFile && !recon_opened )
+#endif
+      {
+        if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; }
+        if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; }
+
+#if H_MV
+        m_tVideoIOYuvReconFile[decIdxLastPic]->open( m_pchReconFiles[decIdxLastPic], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
+        m_reconOpen[decIdxLastPic] = true;
+      }
+      if ( bNewPicture && newSliceDiffPoc && 
+#else
+        m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
+        recon_opened = true;
+      }
+      if ( bNewPicture && 
+#endif
+           (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
+            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
+            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP
+            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) )
+      {
+#if H_MV
+        xFlushOutput( pcListPic, decIdxLastPic );
+#else
+        xFlushOutput( pcListPic );
+#endif
       }
       // write reconstruction to file
-      if(newPicture[viewDepthId])
-      {
-        xWriteOutput( pcListPic[viewDepthId], viewDepthId, nalu.m_temporalId );
-      }
-    }
-    previousViewDepthId = viewDepthId;
-  } 
+      if(bNewPicture)
+      {
+#if H_MV
+        xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId );
+      }
+    }
+  }
+
+#if H_3D
   if( m_cCamParsCollector.isInitialized() )
   {
     m_cCamParsCollector.setSlice( 0 );
   }
-  // last frame
-  for( Int viewDepthIdx = 0; viewDepthIdx < m_tDecTop.size(); viewDepthIdx++ )
-  {
-    xFlushOutput( pcListPic[viewDepthIdx], viewDepthIdx );
-  }  
+#endif
+  for(UInt decIdx = 0; decIdx < m_numDecoders; decIdx++)
+  {
+    xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx );
+  }
+#else
+        xWriteOutput( pcListPic, nalu.m_temporalId );
+      }
+    }
+  }
+  
+  xFlushOutput( pcListPic );
+  // delete buffers
+  m_cTDecTop.deletePicBuffer();
+#endif
+     
+  // destroy internal classes
   xDestroyDecLib();
 }
@@ -390,43 +392,51 @@
 // ====================================================================================================================
 
+Void TAppDecTop::xCreateDecLib()
+{
+#if H_MV
+  // initialize global variables
+  initROM();  
+#if H_3D_DIM_DMM
+  initWedgeLists();
+#endif
+#else
+  // create decoder class
+  m_cTDecTop.create();
+#endif
+}
+
 Void TAppDecTop::xDestroyDecLib()
 {
-
-  for(Int viewDepthIdx=0; viewDepthIdx<m_tVideoIOYuvReconFile.size() ; viewDepthIdx++)
-  {
-    if( m_tVideoIOYuvReconFile[viewDepthIdx] )
-    {
-      m_tVideoIOYuvReconFile[viewDepthIdx]->close();
-      delete m_tVideoIOYuvReconFile[viewDepthIdx]; 
-      m_tVideoIOYuvReconFile[viewDepthIdx] = NULL ;
-    }
-  }
-
-  for(Int viewDepthIdx=0; viewDepthIdx<m_tDecTop.size() ; viewDepthIdx++)
-  {
-    if( m_tDecTop[viewDepthIdx] )
-    {
-      if( !m_useDepth && (viewDepthIdx % 2 == 1) )
-      {
-      }
-      else
-      {
-        m_tDecTop[viewDepthIdx]->deletePicBuffer();
-        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 ;
-    }
-  }
-
+#if H_MV
+  // destroy ROM
+  destroyROM();
+
+  for(Int decIdx = 0; decIdx < m_numDecoders ; decIdx++)
+  {
+    if( m_tVideoIOYuvReconFile[decIdx] )
+    {
+      m_tVideoIOYuvReconFile[decIdx]->close();
+      delete m_tVideoIOYuvReconFile[decIdx]; 
+      m_tVideoIOYuvReconFile[decIdx] = NULL ;
+    }
+
+    if( m_tDecTop[decIdx] )
+    {
+      m_tDecTop[decIdx]->deletePicBuffer();
+      m_tDecTop[decIdx]->destroy() ;
+    }
+    delete m_tDecTop[decIdx] ; 
+    m_tDecTop[decIdx] = NULL ;
+  }
+#else
+  if ( m_pchReconFile )
+  {
+    m_cTVideoIOYuvReconFile. close();
+  }
+  
+  // destroy decoder class
+  m_cTDecTop.destroy();
+#endif
+#if H_3D
   m_cCamParsCollector.uninit();
   if( m_pScaleOffsetFile ) 
@@ -434,7 +444,24 @@
     ::fclose( m_pScaleOffsetFile ); 
   }
-}
-
-Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int viewDepthId, UInt tId )
+#endif
+}
+
+Void TAppDecTop::xInitDecLib()
+{
+#if !H_MV
+  // initialize decoder class
+  m_cTDecTop.init();
+  m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
+#endif
+}
+
+/** \param pcListPic list of pictures to be written to file
+    \todo            DYN_REF_FREE should be revised
+ */
+#if H_MV
+Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int decIdx, Int tId )
+#else
+Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId )
+#endif
 {
   TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
@@ -444,5 +471,9 @@
   {
     TComPic* pcPic = *(iterPic);
-    if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[viewDepthId])
+#if H_MV
+    if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx])
+#else
+    if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay)
+#endif
     {
        not_displayed++;
@@ -455,17 +486,38 @@
   {
     TComPic* pcPic = *(iterPic);
-    TComSPS *sps = pcPic->getSlice(0)->getSPS();
     
-    if ( pcPic->getOutputMark() && (not_displayed >  pcPic->getSlice(0)->getSPS()->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[viewDepthId]))
+#if H_MV
+    if ( pcPic->getOutputMark() && (not_displayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[decIdx]))
+#else
+    if ( pcPic->getOutputMark() && (not_displayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
+#endif
     {
       // write to file
        not_displayed--;
+#if H_MV
+      if ( m_pchReconFiles[decIdx] )
+#else
       if ( m_pchReconFile )
-      {
-        m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), sps->getPicCropLeftOffset(), sps->getPicCropRightOffset(), sps->getPicCropTopOffset(), sps->getPicCropBottomOffset() );
+#endif
+      {
+        const Window &conf = pcPic->getConformanceWindow();
+        const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+#if H_MV
+        m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
+#else
+        m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
+#endif
+                                       conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+                                       conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+                                       conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+                                       conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
       }
       
       // update POC of display order
-      m_pocLastDisplay[viewDepthId] = pcPic->getPOC();
+#if H_MV
+      m_pocLastDisplay[decIdx] = pcPic->getPOC();
+#else
+      m_iPOCLastDisplay = pcPic->getPOC();
+#endif
       
       // erase non-referenced picture in the reference picture list after display
@@ -495,5 +547,9 @@
     \todo            DYN_REF_FREE should be revised
  */
-Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int viewDepthId )
+#if H_MV
+Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int decIdx )
+#else
+Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic )
+#endif
 {
   if(!pcListPic)
@@ -508,16 +564,33 @@
   {
     TComPic* pcPic = *(iterPic);
-    TComSPS *sps = pcPic->getSlice(0)->getSPS();
 
     if ( pcPic->getOutputMark() )
     {
       // write to file
+#if H_MV
+      if ( m_pchReconFiles[decIdx] )
+#else
       if ( m_pchReconFile )
-      {
-        m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), sps->getPicCropLeftOffset(), sps->getPicCropRightOffset(), sps->getPicCropTopOffset(), sps->getPicCropBottomOffset() );
+#endif
+      {
+        const Window &conf = pcPic->getConformanceWindow();
+        const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+#if H_MV
+        m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
+#else
+        m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
+#endif
+                                       conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
+                                       conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
+                                       conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
+                                       conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
       }
       
       // update POC of display order
-      m_pocLastDisplay[viewDepthId] = pcPic->getPOC();
+#if H_MV
+      m_pocLastDisplay[decIdx] = pcPic->getPOC();
+#else
+      m_iPOCLastDisplay = pcPic->getPOC();
+#endif
       
       // erase non-referenced picture in the reference picture list after display
@@ -539,224 +612,100 @@
       pcPic->setOutputMark(false);
     }
-    
+#if !H_MV
+#if !DYN_REF_FREE
+    if(pcPic)
+    {
+      pcPic->destroy();
+      delete pcPic;
+      pcPic = NULL;
+    }
+#endif 
+#endif
     iterPic++;
   }
+#if H_MV
+  m_pocLastDisplay[decIdx] = -MAX_INT;
+#else
   pcListPic->clear();
-  m_pocLastDisplay[viewDepthId] = -MAX_INT;
-}
-#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
-Void  TAppDecTop::increaseNumberOfViews  ( UInt layerId, UInt viewId, UInt isDepth )
-#else
-Void  TAppDecTop::increaseNumberOfViews  ( Int newNumberOfViewDepth )
-#endif
-{
-#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
-  Int newNumberOfViewDepth = layerId + 1;
-#endif
-  if ( m_outputBitDepth == 0 )
-  {
-    m_outputBitDepth = g_uiBitDepth + g_uiBitIncrement;
-  }
-#if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046
-  Int viewId = (newNumberOfViewDepth-1)>>1;   // coding order T0D0T1D1T2D2
-  Bool isDepth = ((newNumberOfViewDepth % 2) == 0);  // coding order T0D0T1D1T2D2
-#endif
-  if( isDepth )
-    m_useDepth = true;
-
-  if ( m_pchReconFile )
-  { 
-    while( m_tVideoIOYuvReconFile.size() < newNumberOfViewDepth)
-    {
-      m_tVideoIOYuvReconFile.push_back(new TVideoIOYuv);
-      Char buffer[4];
-#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
-      sprintf(buffer,"_%i", viewId );
-#else
-      sprintf(buffer,"_%i", (Int)(m_tVideoIOYuvReconFile.size()-1) / 2 );
-#endif
-      Char* nextFilename = NULL;
-#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
-      if( isDepth)
-#else
-      if( (m_tVideoIOYuvReconFile.size() % 2) == 0 )
-#endif
-      {
-        Char* pchTempFilename = NULL;
-        xAppendToFileNameEnd( m_pchReconFile, "_depth", pchTempFilename);
-        xAppendToFileNameEnd( pchTempFilename, buffer, nextFilename);
-        free ( pchTempFilename );
-      }
-      else
-      {
-        xAppendToFileNameEnd( m_pchReconFile, buffer, nextFilename);
-      }
-#if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046
-      if( isDepth || ( !isDepth && (m_tVideoIOYuvReconFile.size() % 2) == 1 ) )
-#endif
-      {
-        m_tVideoIOYuvReconFile.back()->open( nextFilename, true, m_outputBitDepth, g_uiBitDepth + g_uiBitIncrement );
-      }
-      free ( nextFilename );
-    }
-  }
-
-  while( m_pocLastDisplay.size() < newNumberOfViewDepth )
-  {
-    m_pocLastDisplay.push_back(-MAX_INT+m_iSkipFrame);
-  }
-  while( m_tDecTop.size() < newNumberOfViewDepth)
-  {
-    m_tDecTop.push_back(new TDecTop);
-#if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046
-    if( isDepth || ( !isDepth && (m_tVideoIOYuvReconFile.size() % 2) == 1 ) )
-    {
-#endif
-      m_tDecTop.back()->create();
-      m_tDecTop.back()->init( this, newNumberOfViewDepth == 1);
-      m_tDecTop.back()->setViewId( viewId );
-      m_tDecTop.back()->setIsDepth( isDepth );
-      m_tDecTop.back()->setPictureDigestEnabled(m_pictureDigestEnabled);
-      m_tDecTop.back()->setCamParsCollector( &m_cCamParsCollector );
-#if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046
-    }
-#endif
-  }
-}
-
-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;
+  m_iPOCLastDisplay = -MAX_INT;
+#endif
+}
+
+/** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet
+ */
+Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu )
+{
+  if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed
+  {
+    return true;
+  }
+  for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++)
+  {
+#if H_MV
+    if ( nalu->m_layerId == (*it) )
+#else
+    if ( nalu->m_reservedZero6Bits == (*it) )
+#endif
+    {
+      return true;
+    }
+  }
+  return false;
+}
+
+#if H_MV
+Int TAppDecTop::xGetDecoderIdx( Int layerId, Bool createFlag /*= false */ )
+{
+  Int decIdx = -1; 
+  if ( m_layerIdToDecIdx[ layerId ] != -1 ) 
+  {      
+    decIdx = m_layerIdToDecIdx[ layerId ]; 
   }
   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
- 
-} 
-
-std::vector<TComPic*> TAppDecTop::getInterViewRefPics( Int viewId, Int poc, Bool isDepth, TComSPS* sps )
-{
-  std::vector<TComPic*> apcRefPics( sps->getNumberOfUsableInterViewRefs(), (TComPic*)NULL );
-  for( Int k = 0; k < sps->getNumberOfUsableInterViewRefs(); k++ )
-  {
-    TComPic* pcRefPic = xGetPicFromView( sps->getUsableInterViewRef( k ) + viewId, poc, isDepth );
-    assert( pcRefPic != NULL );
-    apcRefPics[k] = pcRefPic;
-  }
-  return apcRefPics;
-}
-
-TComPic* TAppDecTop::xGetPicFromView( Int viewId, Int poc, Bool isDepth )
-{
-  assert( ( viewId >= 0 ) );
-
-#if FLEX_CODING_ORDER_M23723
-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;
-  for( TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++ )
-  {
-    if( (*it)->getPOC() == poc )
-    {
-      pcPic = *it;
-      break;
-    }
-  }
-  return pcPic;
-#endif
-}
-
-#if MERL_VSP_C0152
-Void TAppDecTop::setBWVSPLUT(
-#if MERL_VSP_NBDV_RefVId_Fix_D0166
-    Int iNeighborViewId,
-#endif
-    TComSlice* pcSlice,  Int iCodedViewIdx,  Int iCurPoc)
-
-{
-  //first view does not have VSP 
-  if((iCodedViewIdx == 0)) return;
-
-  AOT( iCodedViewIdx <= 0);
-  //AOT( iCodedViewIdx >= m_iNumberOfViews );
-#if !MERL_VSP_NBDV_RefVId_Fix_D0166
-  Int iNeighborViewId = 0;
-#endif
-  //  Int* piShiftLUT = bRenderFromLeft ? m_cCamParsCollector.getBaseViewShiftLUTI()[iCodedViewIdx][iNeighborViewId][0] : m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0];
-  Int* piShiftLUT = m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0];
-#if MERL_VSP_NBDV_RefVId_Fix_D0166
-  pcSlice->setBWVSPLUTParam(piShiftLUT, 2-LOG2_DISP_PREC_LUT, iNeighborViewId );
-#else
-  pcSlice->setBWVSPLUTParam(piShiftLUT, 2-LOG2_DISP_PREC_LUT );
-#endif
-}
-#endif
-
+  {      
+    assert ( createFlag ); 
+    assert( m_numDecoders < MAX_NUM_LAYERS ); 
+
+    decIdx = m_numDecoders; 
+
+    // Init decoder
+    m_tDecTop[ decIdx ] =  new TDecTop;
+    m_tDecTop[ decIdx ]->create();
+    m_tDecTop[ decIdx ]->init( );
+    m_tDecTop[ decIdx ]->setLayerId( layerId );
+    m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
+    m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists ); 
+#if H_3D
+   m_tDecTop[ decIdx ]->setCamParsCollector( &m_cCamParsCollector );
+#endif
+
+    // append pic list of new decoder to PicLists 
+    assert( m_ivPicLists.size() == m_numDecoders );
+    m_ivPicLists.push_back( m_tDecTop[ decIdx ]->getListPic() );
+
+    // create recon file related stuff      
+    Char* pchTempFilename = NULL;
+    if ( m_pchReconFile )
+    {      
+      Char buffer[4];      
+      sprintf(buffer,"_%i", layerId );
+      assert ( m_pchReconFile ); 
+      xAppendToFileNameEnd( m_pchReconFile , buffer, pchTempFilename );
+      assert( m_pchReconFiles.size() == m_numDecoders );
+    }
+
+    m_pchReconFiles.push_back( pchTempFilename );   
+
+    m_tVideoIOYuvReconFile[ decIdx ] = new TVideoIOYuv;
+    m_reconOpen           [ decIdx ] = false;
+
+    // set others 
+    m_pocLastDisplay      [ decIdx ] = -MAX_INT;
+    m_layerIdToDecIdx     [ layerId ] = decIdx; 
+
+    m_numDecoders++; 
+  };
+  return decIdx;
+}
+#endif
 //! \}
Index: trunk/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 443)
+++ trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 608)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -46,5 +46,4 @@
 #include "TLibCommon/TComList.h"
 #include "TLibCommon/TComPicYuv.h"
-#include "TLibCommon/TComDepthMapGenerator.h"
 #include "TLibDecoder/TDecTop.h"
 #include "TAppDecCfg.h"
@@ -62,28 +61,26 @@
 private:
   // class interface
-  std::vector<TDecTop*>           m_tDecTop;                      ///< decoder classes
-
-  std::vector<TVideoIOYuv*>       m_tVideoIOYuvReconFile;         ///< reconstruction YUV class
-
-  // for output control
+#if H_MV
+  TDecTop*                        m_tDecTop             [ MAX_NUM_LAYERS ];    ///< decoder classes
+  TVideoIOYuv*                    m_tVideoIOYuvReconFile[ MAX_NUM_LAYERS ];    ///< reconstruction YUV class
+  Int                             m_layerIdToDecIdx     [ MAX_NUM_LAYER_IDS ]; ///< maping from layer id to decoder index
+  Int                             m_numDecoders;                               ///< number of decoder instances
+  TComPicLists                    m_ivPicLists;                                ///< picture buffers of decoder instances
+#else
+  TDecTop                         m_cTDecTop;                     ///< decoder class
+  TVideoIOYuv                     m_cTVideoIOYuvReconFile;        ///< reconstruction YUV class
+#endif
+    // for output control
   Bool                            m_abDecFlag[ MAX_GOP ];         ///< decoded flag in one GOP
-  std::vector<Int>                m_pocLastDisplay;               ///< last POC in display order
-  Bool                            m_useDepth;
-
-#if FLEX_CODING_ORDER_M23723
-  Int  m_fcoViewDepthId;
-  Char m_fcoOrder[MAX_VIEW_NUM*2];
+#if H_MV
+  Int                             m_pocLastDisplay      [ MAX_NUM_LAYERS ]; ///< last POC in display order
+  Bool                            m_reconOpen           [ MAX_NUM_LAYERS ]; ///< reconstruction file opened
+#else
+  Int                             m_iPOCLastDisplay;              ///< last POC in display order
 #endif
-
+#if H_3D
   FILE*                           m_pScaleOffsetFile;
   CamParsCollector                m_cCamParsCollector;
-#if DEPTH_MAP_GENERATION
-#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
-  TComVPSAccess                   m_cVPSAccess;
 #endif
-  TComSPSAccess                   m_cSPSAccess;
-  TComAUPicAccess                 m_cAUPicAccess;
-#endif
-
 public:
   TAppDecTop();
@@ -93,43 +90,23 @@
   Void  destroy           (); ///< destroy internal members
   Void  decode            (); ///< main decoding function
-#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
-  Void  increaseNumberOfViews  (UInt layerId, UInt viewId, UInt isDepth);
-#else
-  Void  increaseNumberOfViews  (Int newNumberOfViewDepth);
-#endif
-  TDecTop* getTDecTop     ( Int viewId, Bool isDepth );
-
-  std::vector<TComPic*> getInterViewRefPics( Int viewId, Int poc, Bool isDepth, TComSPS* sps );
-  TComPic*              getPicFromView     ( Int viewId, Int poc, bool isDepth ) { return xGetPicFromView( viewId, poc, isDepth ); }
-
-#if DEPTH_MAP_GENERATION
-#if VIDYO_VPS_INTEGRATION
-  TComVPSAccess*    getVPSAccess  () { return &m_cVPSAccess;   }
-#endif
-  TComSPSAccess*    getSPSAccess  () { return &m_cSPSAccess;   }
-  TComAUPicAccess*  getAUPicAccess() { return &m_cAUPicAccess; }
-  TDecTop*          getDecTop0    () { return m_tDecTop[0]; }
-#endif
-
-#if MERL_VSP_C0152
-#if MERL_VSP_NBDV_RefVId_Fix_D0166
-  Void  setBWVSPLUT( Int iNeighborViewId, TComSlice* pcSlice, Int iCodedViewIdx, Int iCurPoc );
-#else
-  Void  setBWVSPLUT( TComSlice* pcSlice, Int iCodedViewIdx, Int iCurPoc   );
-#endif
-#endif
 
 protected:
-//  Void  xCreateDecLib     (); ///< create internal classes
+  Void  xCreateDecLib     (); ///< create internal classes
   Void  xDestroyDecLib    (); ///< destroy internal classes
-//  Void  xInitDecLib       (); ///< initialize decoder class
-  
-  Void  xWriteOutput      ( TComList<TComPic*>* pcListPic, Int viewDepthId, UInt tId); ///< write YUV to file
-  Void  xFlushOutput      ( TComList<TComPic*>* pcListPic, Int viewDepthId ); ///< flush all remaining decoded pictures to file
+  Void  xInitDecLib       (); ///< initialize decoder class
 
-  TComPic* xGetPicFromView( Int viewId, Int poc, Bool isDepth );
+#if H_MV
+  Void  xWriteOutput      ( TComList<TComPic*>* pcListPic, Int layerId, Int tId ); ///< write YUV to file
+  Void  xFlushOutput      ( TComList<TComPic*>* pcListPic, Int layerId ); ///< flush all remaining decoded pictures to file
+  Int   xGetDecoderIdx    ( Int layerId, Bool createFlag = false );
+#else
+  Void  xWriteOutput      ( TComList<TComPic*>* pcListPic , UInt tId); ///< write YUV to file
+  Void  xFlushOutput      ( TComList<TComPic*>* pcListPic ); ///< flush all remaining decoded pictures to file
+#endif
+  Bool  isNaluWithinTargetDecLayerIdSet ( InputNALUnit* nalu ); ///< check whether given Nalu is within targetDecLayerIdSet
 };
 
 //! \}
+
 #endif
 
Index: trunk/source/App/TAppDecoder/decmain.cpp
===================================================================
--- trunk/source/App/TAppDecoder/decmain.cpp	(revision 443)
+++ trunk/source/App/TAppDecoder/decmain.cpp	(revision 608)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -56,5 +56,9 @@
   // print information
   fprintf( stdout, "\n" );
-  fprintf( stdout, "3D-HTM Software: Decoder Version [%s] based on HM Version [%s]", NV_VERSION, HM_VERSION );
+#if H_MV
+  fprintf( stdout, "3D-HTM Software: Decoder Version [%s] based on HM Version [%s]", NV_VERSION, HM_VERSION );  
+#else
+  fprintf( stdout, "HM software: Decoder Version [%s]", NV_VERSION );
+#endif
   fprintf( stdout, NVM_ONOS );
   fprintf( stdout, NVM_COMPILEDBY );
