From fed490418714a8be4a7df1410a00484f5fb28c0a Mon Sep 17 00:00:00 2001
From: Wei Jia <wei.jia@bytedance.com>
Date: Fri, 18 Aug 2023 15:37:17 +0000
Subject: [PATCH] JVET-AE0135 item2: On NNPF picture rate upsampling constraint

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

diff --git a/source/Lib/CommonLib/SEINeuralNetworkPostFiltering.cpp b/source/Lib/CommonLib/SEINeuralNetworkPostFiltering.cpp
index 1af50c12a..2bcbb11a8 100644
--- a/source/Lib/CommonLib/SEINeuralNetworkPostFiltering.cpp
+++ b/source/Lib/CommonLib/SEINeuralNetworkPostFiltering.cpp
@@ -238,11 +238,17 @@ void SEINeuralNetworkPostFiltering::checkInputPics(
 
   if (nnpfa != nullptr)
   {
+#if JVET_AE0135_NNPF_PIC_RATE_UPSAMPLING_CONSTRAINT
+    int numPicsCurrLayer = 0;
+#endif
     Picture *lastPic = nullptr;
     for (auto pic : m_picList)
     {
       if (pic->layerId == currCodedPic->layerId)
       {
+#if JVET_AE0135_NNPF_PIC_RATE_UPSAMPLING_CONSTRAINT
+        ++numPicsCurrLayer;
+#endif
         if (lastPic == nullptr || (pic->getPOC() > lastPic->getPOC()))
         {
           lastPic = pic;
@@ -265,6 +271,9 @@ void SEINeuralNetworkPostFiltering::checkInputPics(
           numPostRoll = i;
         }
       }
+#if JVET_AE0135_NNPF_PIC_RATE_UPSAMPLING_CONSTRAINT
+      CHECK( numPicsCurrLayer > numInputPics && greaterThan0count > 1, "Disallow generating NNPF output pictures between any particular pair of consecutive input pictures more than once." );
+#endif
     }
 
     int numInferences;
diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 19fb632d2..e879dd349 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -65,6 +65,8 @@
 
 #define JVET_AE0141_NNPFC_BUGFIX_COLOURIZATION            1  // JVET-AE0141: Fix a bug in NNPFC SEI message for colourization
 
+#define JVET_AE0135_NNPF_PIC_RATE_UPSAMPLING_CONSTRAINT   1  // JVET_AE0135 item2: On NNPF picture rate upsampling constraint
+
 //########### place macros to be be kept below this line ###############
 
 #define GDR_ENABLED   1
-- 
GitLab