Index: trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 773)
+++ trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 872)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2013, ITU/ISO/IEC
+* Copyright (c) 2010-2014, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -140,5 +140,7 @@
     AOF( m_pScaleOffsetFile ); 
   }
+#if !FIX_CAM_PARS_COLLECTOR
   m_cCamParsCollector.init( m_pScaleOffsetFile );
+#endif
 #endif
   InputByteStream bytestream(bitstreamFile);
@@ -165,5 +167,6 @@
   Bool firstSlice        = true; 
 #endif
- 
+  Bool loopFiltered      = false;
+
   while (!!bitstreamFile)
   {
@@ -206,5 +209,16 @@
       read(nalu, nalUnit);
 #if H_MV      
+#if H_MV_FIX_VPS_LAYER_ID_NOT_EQUAL_ZERO
+      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) 
+          || !isNaluWithinTargetDecLayerIdSet(&nalu)
+          || nalu.m_layerId > MAX_NUM_LAYER_IDS-1
+          || (nalu.m_nalUnitType == NAL_UNIT_VPS && nalu.m_layerId > 0)           
+#if H_MV_HLS_7_MISC_P0130_EOS
+          || (nalu.m_nalUnitType == NAL_UNIT_EOB && nalu.m_layerId > 0)           
+#endif
+         ) 
+#else
       if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) || nalu.m_layerId > MAX_NUM_LAYER_IDS-1 ) 
+#endif
       {
         bNewPicture = false;
@@ -234,6 +248,23 @@
           }
 
+#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
+          if ( m_targetOptLayerSetIdx < 0 || m_targetOptLayerSetIdx >= vps->getNumOutputLayerSets() )
+          {
+            fprintf(stderr, "\ntarget output layer set index must be in the range of 0 to %d, inclusive \n", vps->getNumOutputLayerSets() - 1 );            
+            exit(EXIT_FAILURE);
+          }
+#endif
           m_targetDecLayerIdSet = vps->getTargetDecLayerIdList( m_targetOptLayerSetIdx ); 
         }
+
+#if FIX_CAM_PARS_COLLECTOR
+#if H_3D
+        if (nalu.m_nalUnitType == NAL_UNIT_VPS )
+        {        
+          
+          m_cCamParsCollector.init( m_pScaleOffsetFile, m_tDecTop[decIdx]->getPrefetchedVPS() );
+        }       
+#endif
+#endif
         bNewPicture       = ( newSliceDiffLayer || newSliceDiffPoc ) && !sliceSkippedFlag; 
         if ( nalu.isSlice() && firstSlice && !sliceSkippedFlag )        
@@ -278,6 +309,6 @@
           bitstreamFile.seekg(location-streamoff(3));
           bytestream.reset();
+#if H_MV_ENC_DEC_TRAC
 #if ENC_DEC_TRACE
-#if H_MV_ENC_DEC_TRAC
           const Bool resetCounter = false; 
           if ( resetCounter )
@@ -287,21 +318,23 @@
           else
           {
-            g_disableHLSTrace = true;     // Trancing of second parsing of SH is not carried out
-          }          
-#else
-          g_nSymbolCounter = symCount;
-#endif
-#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
+            g_disableHLSTrace = true;     // Tracing of second parsing of SH is not carried out
+          }      
+#endif
+#endif
+        }
+      }
+    }
+    if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS )
+    {
+      if (!loopFiltered || bitstreamFile)
+      {
+#if H_MV
+        assert( decIdxLastPic != -1 ); 
+        m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet );
+#else
+        m_cTDecTop.executeLoopFilters(poc, pcListPic);
+#endif
+      }
+      loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS);
     }
 #if H_3D
@@ -351,4 +384,12 @@
 #endif
       }
+      if (nalu.m_nalUnitType == NAL_UNIT_EOS)
+      {
+#if H_MV
+        xFlushOutput( pcListPic, decIdxLastPic );
+#else
+        xFlushOutput( pcListPic );
+#endif
+      }
       // write reconstruction to file
       if(bNewPicture)
@@ -462,4 +503,10 @@
 #endif
 {
+
+  if (pcListPic->empty())
+  {
+    return;
+  }
+
   TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
   Int numPicsNotYetDisplayed = 0;
@@ -647,5 +694,5 @@
 #endif
 {
-  if(!pcListPic)
+  if(!pcListPic || pcListPic->empty())
   {
     return;
