From 8c4798d45c824843dfae5037dcd9ca418b31ec35 Mon Sep 17 00:00:00 2001
From: Hendry <hendry197@gmail.com>
Date: Tue, 8 Mar 2022 11:22:01 -0800
Subject: [PATCH] Fix the application of NoOutputOfPriorPicsFlag so that it is
 invoked only once per AU

---
 source/Lib/CommonLib/TypeDef.h   | 2 ++
 source/Lib/DecoderLib/DecLib.cpp | 9 ++++++++-
 source/Lib/DecoderLib/DecLib.h   | 2 +-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index e75bdb48fd..775b9ebd3f 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -72,6 +72,8 @@
 #define GDR_DEC_TRACE  0
 #endif
 
+#define JVET_S0078_NOOUTPUT_PRIOR_PICS_FLAG               1 // Apply no output of prior pics only once per AU for all layers or once per picture in AU for each layer.
+
 #define JVET_S0257_DUMP_360SEI_MESSAGE                    1 // Software support of 360 SEI messages
 
 #define JVET_R0351_HIGH_BIT_DEPTH_ENABLED                 0 // JVET-R0351: high bit depth coding enabled (increases accuracies of some calculations, e.g. transforms)
diff --git a/source/Lib/DecoderLib/DecLib.cpp b/source/Lib/DecoderLib/DecLib.cpp
index 9f58119d67..2bdae4e742 100644
--- a/source/Lib/DecoderLib/DecLib.cpp
+++ b/source/Lib/DecoderLib/DecLib.cpp
@@ -943,7 +943,7 @@ void DecLib::finishPicture(int &poc, PicList *&rpcListPic, MsgLevel msgl, bool a
   m_puCounter++;
 }
 
-void DecLib::checkNoOutputPriorPics (PicList* pcListPic)
+void DecLib::checkNoOutputPriorPics(PicList *pcListPic)
 {
   if (!pcListPic || !m_isNoOutputPriorPics)
   {
@@ -2580,10 +2580,17 @@ bool DecLib::xDecodeSlice(InputNALUnit &nalu, int &iSkipFrame, int iPOCLastDispl
 
   DTRACE_UPDATE( g_trace_ctx, std::make_pair( "poc", m_apcSlicePilot->getPOC() ) );
 
+#if JVET_S0078_NOOUTPUT_PRIOR_PICS_FLAG
+  if (m_bFirstSliceInPicture && m_apcSlicePilot->getPOC() != m_prevPOC &&
+       (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
+       || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_GDR) &&
+      getNoOutputPriorPicsFlag())
+#else
   if ((m_bFirstSliceInPicture ||
         m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ||
         m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_GDR) &&
       getNoOutputPriorPicsFlag())
+#endif
     {
       checkNoOutputPriorPics(&m_cListPic);
       setNoOutputPriorPicsFlag (false);
diff --git a/source/Lib/DecoderLib/DecLib.h b/source/Lib/DecoderLib/DecLib.h
index e4cca9605e..d0aef7731b 100644
--- a/source/Lib/DecoderLib/DecLib.h
+++ b/source/Lib/DecoderLib/DecLib.h
@@ -244,7 +244,7 @@ public:
   void  executeLoopFilters();
   void finishPicture(int &poc, PicList *&rpcListPic, MsgLevel msgl = INFO, bool associatedWithNewClvs = false);
   void  finishPictureLight(int& poc, PicList*& rpcListPic );
-  void  checkNoOutputPriorPics (PicList* rpcListPic);
+  void checkNoOutputPriorPics(PicList *rpcListPic);
   void  checkNalUnitConstraints( uint32_t naluType );
   void  checkPicTypeAfterEos();
   void  updateAssociatedIRAP();
-- 
GitLab