From 00d2c12759b7947d227013807c4b9251777c8d37 Mon Sep 17 00:00:00 2001
From: Fabrice URBAN <fabrice.urban@interdigital.com>
Date: Tue, 23 Jul 2024 16:27:39 +0000
Subject: [PATCH] fix decoder mismatch when IBC OFF

---
 source/Lib/CommonLib/IntraPrediction.cpp |  2 +-
 source/Lib/DecoderLib/CABACReader.cpp    |  4 +++-
 source/Lib/DecoderLib/VLCReader.cpp      | 14 ++++++++------
 source/Lib/EncoderLib/CABACWriter.cpp    |  9 ++++++++-
 source/Lib/EncoderLib/VLCWriter.cpp      |  8 ++++----
 5 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/source/Lib/CommonLib/IntraPrediction.cpp b/source/Lib/CommonLib/IntraPrediction.cpp
index afef96be8..e717263c4 100644
--- a/source/Lib/CommonLib/IntraPrediction.cpp
+++ b/source/Lib/CommonLib/IntraPrediction.cpp
@@ -14679,7 +14679,7 @@ void IntraPrediction::searchCandidateFromOnePicIntra( CodingUnit* pcCU, Pel** ta
   static_vector<TempLibFast, MTMP_NUM_SPARSE> sparseMtmpCandList[3];
   static_vector<uint64_t, MTMP_NUM_SPARSE>    sparseMtmpCostList[3];
 #if JVET_AG0136_INTRA_TMP_LIC
-  static const int TMP_SAMPLING = pcCU->slice->getSPS()->getItmpLicMode() ? TMP_SAMPLING_LIC_MODE_1 : TMP_SAMPLING_LIC_MODE_0;
+  const int TMP_SAMPLING = pcCU->slice->getSPS()->getItmpLicMode() ? TMP_SAMPLING_LIC_MODE_1 : TMP_SAMPLING_LIC_MODE_0;
   static_vector<TempLibFast, MTMP_NUM_SPARSE> sparseMtmpCandListSupp[3];
   static_vector<uint64_t, MTMP_NUM_SPARSE> sparseMtmpCostListSupp[3];
   int mtmpNumSparse[3];
diff --git a/source/Lib/DecoderLib/CABACReader.cpp b/source/Lib/DecoderLib/CABACReader.cpp
index 0a5d92644..82dc26815 100644
--- a/source/Lib/DecoderLib/CABACReader.cpp
+++ b/source/Lib/DecoderLib/CABACReader.cpp
@@ -9670,6 +9670,7 @@ void CABACReader::tmp_flag(CodingUnit& cu)
       cu.tmpLicFlag = m_BinDecoder.decodeBin(Ctx::TmpLic(0));
       cu.ibcLicFlag = cu.tmpLicFlag;
       cu.ibcLicIdx = 0;
+      DTRACE(g_trace_ctx, D_SYNTAX, "tmpLicFlag pos=(%d,%d) value=%d\n", cu.lumaPos().x, cu.lumaPos().y, cu.tmpLicFlag);
 #endif
     }
     else
@@ -9754,6 +9755,7 @@ void CABACReader::tmp_flag(CodingUnit& cu)
         }
         cu.tmpIsSubPel  = 0;
         cu.tmpSubPelIdx = -1;
+        DTRACE(g_trace_ctx, D_SYNTAX, "tmpFracIdx pos=(%d,%d) value=%d\n", cu.lumaPos().x, cu.lumaPos().y, cu.tmpFracIdx);
 #else
         cu.tmpIsSubPel = m_BinDecoder.decodeBin(Ctx::TmpFlag(4));
         if (cu.tmpIsSubPel)
@@ -9765,8 +9767,8 @@ void CABACReader::tmp_flag(CodingUnit& cu)
           }
           cu.tmpSubPelIdx = m_BinDecoder.decodeBinsEP(3);
         }
-#endif
         DTRACE(g_trace_ctx, D_SYNTAX, "tmp_is_subpel() pos=(%d,%d) mode=%d\n", cu.lumaPos().x, cu.lumaPos().y, cu.tmpIsSubPel);
+#endif
       }
       else
       {
diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp
index 4deeda96f..15dbd4a68 100644
--- a/source/Lib/DecoderLib/VLCReader.cpp
+++ b/source/Lib/DecoderLib/VLCReader.cpp
@@ -2490,7 +2490,7 @@ void HLSyntaxReader::parseSPS(SPS* pcSPS)
   pcSPS->setUseAffMergeOppositeLic(false);
   if (pcSPS->getUseAffine())
   {
-    READ_FLAG(uiCode, "sps_affine_oppolic_merge_enabled_flag");            pcSPS->setUseAffMergeOppositeLic(uiCode != 0);
+    READ_FLAG(uiCode, "sps_affine_oppositelic_merge_enabled_flag");            pcSPS->setUseAffMergeOppositeLic(uiCode != 0);
   }
 #endif
   if ( pcSPS->getUseAffine() )
@@ -2514,7 +2514,7 @@ void HLSyntaxReader::parseSPS(SPS* pcSPS)
 #if JVET_AG0276_LIC_FLAG_SIGNALING
     if (pcSPS->getUseAffMergeOppositeLic())
     {
-      READ_UVLC(uiCode, "eight_minus_max_num_aff_oppolic_merge_cand");
+      READ_UVLC(uiCode, "eight_minus_max_num_aff_oppositelic_merge_cand");
       pcSPS->setMaxNumAffineOppositeLicMergeCand(AFF_MRG_MAX_NUM_CANDS_OPPOSITELIC - uiCode);
     }
 #endif
@@ -2895,14 +2895,16 @@ void HLSyntaxReader::parseSPS(SPS* pcSPS)
 #endif
 #if JVET_AE0094_IBC_NONADJACENT_SPATIAL_CANDIDATES
     READ_FLAG( uiCode, "sps_ibc_non_adjacent_spatial_candidates_enabled_flag");    pcSPS->setUseIbcNonAdjCand(uiCode != 0);
-#endif
-#if JVET_AG0136_INTRA_TMP_LIC
-    READ_FLAG( uiCode, "sps_itmp_lic_extension_flag" );                    pcSPS->setItmpLicExtension ( uiCode != 0 );
-    READ_FLAG( uiCode, "sps_itmp_lic_mode_flag" );                              pcSPS->setItmpLicMode ( uiCode != 0 );
 #endif
   }
   else
+  {
     pcSPS->setMaxNumIBCMergeCand(0);
+  }
+#if JVET_AG0136_INTRA_TMP_LIC
+  READ_FLAG( uiCode, "sps_itmp_lic_extension_flag" );                    pcSPS->setItmpLicExtension ( uiCode != 0 );
+  READ_FLAG( uiCode, "sps_itmp_lic_mode_flag" );                              pcSPS->setItmpLicMode ( uiCode != 0 );
+#endif
 
 #if !JVET_S0074_SPS_REORDER
   READ_FLAG(uiCode, "sps_lmcs_enable_flag");                   pcSPS->setUseLmcs(uiCode == 1);
diff --git a/source/Lib/EncoderLib/CABACWriter.cpp b/source/Lib/EncoderLib/CABACWriter.cpp
index 8bed966b1..084b4c091 100644
--- a/source/Lib/EncoderLib/CABACWriter.cpp
+++ b/source/Lib/EncoderLib/CABACWriter.cpp
@@ -2652,8 +2652,13 @@ void CABACWriter::intra_chroma_pred_mode(const PredictionUnit& pu)
         m_BinEncoder.encodeBin(isFusion ? 1 : 0, Ctx::ChromaFusionMode());
 #endif
       }
+#if JVET_AH0136_CHROMA_REORDERING
+      DTRACE(g_trace_ctx, D_SYNTAX, "intra_chroma_pred_modes() pos=(%d,%d) dir=%d\n", pu.blocks[CHANNEL_TYPE_CHROMA].x,
+             pu.blocks[CHANNEL_TYPE_CHROMA].y, isDbvChromaMode ? DBV_CHROMA_IDX : pu.intraDir[CHANNEL_TYPE_CHROMA]);
+#else
       DTRACE(g_trace_ctx, D_SYNTAX, "intra_chroma_pred_modes() pos=(%d,%d) dir=%d\n",
         pu.blocks[CHANNEL_TYPE_CHROMA].x, pu.blocks[CHANNEL_TYPE_CHROMA].y, pu.intraDir[CHANNEL_TYPE_CHROMA]);
+#endif
       return;
     }
   }
@@ -9498,10 +9503,11 @@ void CABACWriter::tmp_flag(const CodingUnit& cu)
       {
         m_BinEncoder.encodeBinEP(tmpFusionIdx > 1 ? 1 : 0);
       }
+      DTRACE(g_trace_ctx, D_SYNTAX, "tmp_fusion_idx() pos=(%d,%d) mode=%d\n", cu.lumaPos().x, cu.lumaPos().y, cu.tmpIdx);
 #if JVET_AG0136_INTRA_TMP_LIC
       m_BinEncoder.encodeBin(cu.tmpLicFlag, Ctx::TmpLic(0));
+      DTRACE(g_trace_ctx, D_SYNTAX, "tmpLicFlag pos=(%d,%d) value=%d\n", cu.lumaPos().x, cu.lumaPos().y, cu.tmpLicFlag);
 #endif
-      DTRACE(g_trace_ctx, D_SYNTAX, "tmp_fusion_idx() pos=(%d,%d) mode=%d\n", cu.lumaPos().x, cu.lumaPos().y, cu.tmpIdx);
     }
     else
     {
@@ -9570,6 +9576,7 @@ void CABACWriter::tmp_flag(const CodingUnit& cu)
             m_BinEncoder.encodeBin(0, Ctx::TmpFlag(7));
           }
         }
+        DTRACE(g_trace_ctx, D_SYNTAX, "tmpFracIdx pos=(%d,%d) value=%d\n", cu.lumaPos().x, cu.lumaPos().y, cu.tmpFracIdx);
 #else
         m_BinEncoder.encodeBin(cu.tmpIsSubPel != 0 ? 1 : 0, Ctx::TmpFlag(4));
         if (cu.tmpIsSubPel)
diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp
index de1983de0..32afe5300 100644
--- a/source/Lib/EncoderLib/VLCWriter.cpp
+++ b/source/Lib/EncoderLib/VLCWriter.cpp
@@ -1577,7 +1577,7 @@ void HLSWriter::codeSPS( const SPS* pcSPS )
 #if JVET_AG0276_LIC_FLAG_SIGNALING
     if (pcSPS->getUseAffMergeOppositeLic())
     {
-      WRITE_UVLC(AFF_MRG_MAX_NUM_CANDS_OPPOSITELIC - pcSPS->getMaxNumAffineOppositeLicMergeCand(), "eight_minus_max_num_oppositelic_subblock_merge_cand");
+      WRITE_UVLC(AFF_MRG_MAX_NUM_CANDS_OPPOSITELIC - pcSPS->getMaxNumAffineOppositeLicMergeCand(), "eight_minus_max_num_aff_oppositelic_merge_cand");
     }
 #endif
     if (pcSPS->getAMVREnabledFlag())
@@ -1895,11 +1895,11 @@ void HLSWriter::codeSPS( const SPS* pcSPS )
 #if JVET_AE0094_IBC_NONADJACENT_SPATIAL_CANDIDATES
     WRITE_FLAG(pcSPS->getUseIbcNonAdjCand() ? 1 : 0, "sps_ibc_non_adjacent_spatial_candidates_enabled_flag");
 #endif
+  }
 #if JVET_AG0136_INTRA_TMP_LIC
-    WRITE_FLAG( pcSPS->getItmpLicExtension ( ) ? 1 : 0 , "sps_itmp_lic_extension_flag" );
-    WRITE_FLAG( pcSPS->getItmpLicMode ( ) ? 1 : 0 , "sps_itmp_lic_mode_flag" );
+  WRITE_FLAG( pcSPS->getItmpLicExtension ( ) ? 1 : 0 , "sps_itmp_lic_extension_flag" );
+  WRITE_FLAG( pcSPS->getItmpLicMode ( ) ? 1 : 0 , "sps_itmp_lic_mode_flag" );
 #endif
-  }
 #if !JVET_S0074_SPS_REORDER
   WRITE_FLAG(pcSPS->getUseLmcs() ? 1 : 0, "sps_lmcs_enable_flag");
 #if JVET_AH0103_LOW_DELAY_LFNST_NSPT
-- 
GitLab