[x265] [PATCH] Fix decoder crash in alpha,scc,mv-hevc

Pavan Tarun Chakka Venkata pavan.tarun at multicorewareinc.com
Thu Nov 21 10:15:32 UTC 2024


>From 691bee81e212d752bd4bbe471a4cf737159268b1 Mon Sep 17 00:00:00 2001
From: AnusuyaKumarasamy <anusuya.kumarasamy at multicorewareinc.com>
Date: Tue, 19 Nov 2024 16:07:25 +0530
Subject: [PATCH] Fix decoder crash in alpha,scc,mv-hevc

---
 source/abrEncApp.cpp                |  6 +++---
 source/common/param.cpp             |  4 ++--
 source/common/slice.h               |  1 +
 source/encoder/encoder.cpp          |  1 +
 source/encoder/entropy.cpp          | 32 +++++++++++++----------------
 source/encoder/sei.h                | 16 +++++++--------
 source/encoder/weightPrediction.cpp |  4 ----
 source/x265.h                       |  1 +
 8 files changed, 30 insertions(+), 35 deletions(-)

diff --git a/source/abrEncApp.cpp b/source/abrEncApp.cpp
index 66787ff11..c83c00e90 100644
--- a/source/abrEncApp.cpp
+++ b/source/abrEncApp.cpp
@@ -63,7 +63,7 @@ namespace X265_NS {
             m_passEnc[i]->init(ret);
         }

-        m_numInputViews = m_passEnc[0]->m_param->numViews -
!!m_passEnc[0]->m_param->format;
+        m_numInputViews = (m_passEnc[0]->m_param->numViews > 1) ?
m_passEnc[0]->m_param->numViews - !!m_passEnc[0]->m_param->format : 0;
         if (!allocBuffers())
         {
             x265_log(NULL, X265_LOG_ERROR, "Unable to allocate memory for
buffers\n");
@@ -146,7 +146,7 @@ namespace X265_NS {
     {
         x265_cleanup(); /* Free library singletons */
 #if ENABLE_MULTIVIEW
-        if(m_numInputViews > 1)
+        if(m_numInputViews != 0)
         {
             for (uint8_t pass = 0; pass < m_numInputViews; pass++)
             {
@@ -252,7 +252,7 @@ namespace X265_NS {
                 }
             }
         }
-
+        m_param->isAbrLadderEnable = m_parent->m_numEncodes > 1;
         if (m_cliopt.zoneFile)
         {
             if (!m_cliopt.parseZoneFile())
diff --git a/source/common/param.cpp b/source/common/param.cpp
index dd8a12ef4..b8ec5b3d0 100755
--- a/source/common/param.cpp
+++ b/source/common/param.cpp
@@ -1515,8 +1515,6 @@ int x265_param_parse(x265_param* p, const char* name,
const char* value)
         OPT("scc")
         {
             p->bEnableSCC = atoi(value);
-            if (p->bEnableSCC)
-                p->bEnableWeightedPred = false;
         }
 #endif
         OPT("frame-rc") p->bConfigRCFrame = atobool(value);
@@ -2007,6 +2005,7 @@ int x265_check_params(x265_param* param)
         CHECK(param->internalBitDepth != 8, "BitDepthConstraint must be 8
for Multiview main profile");
         CHECK(param->analysisMultiPassDistortion ||
param->analysisMultiPassRefine, "Multiview encode doesnot support multipass
feature");
         CHECK(strlen(param->analysisSave) || strlen(param->analysisLoad),
"Multiview encode doesnot support analysis save and load feature");
+        CHECK(param->isAbrLadderEnable, "Multiview encode and Abr-Ladder
feature can't be enabled together");
     }
 #endif
 #if ENABLE_SCC_EXT
@@ -3025,6 +3024,7 @@ void x265_copy_params(x265_param* dst, x265_param*
src)
         dst->aomFilmGrain = src->aomFilmGrain;
     dst->bEnableSBRC = src->bEnableSBRC;
     dst->bConfigRCFrame = src->bConfigRCFrame;
+    dst->isAbrLadderEnable = src->isAbrLadderEnable;
 }

 #ifdef SVT_HEVC
diff --git a/source/common/slice.h b/source/common/slice.h
index 08e2577c7..df6f540f8 100644
--- a/source/common/slice.h
+++ b/source/common/slice.h
@@ -281,6 +281,7 @@ struct SPS

 #if ENABLE_MULTIVIEW
     int      setSpsExtOrMaxSubLayersMinus1;
+    int      spsInferScalingListFlag;
     int      maxViews;
     bool     vui_parameters_present_flag;
 #endif
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
index e85e09d82..ee39c3280 100644
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -3602,6 +3602,7 @@ void Encoder::initSPS(SPS *sps)
 #if ENABLE_MULTIVIEW
     sps->setSpsExtOrMaxSubLayersMinus1 = sps->maxTempSubLayers - 1;
     sps->maxViews = m_param->numViews;
+    sps->spsInferScalingListFlag = 0;
     if (m_param->numViews > 1)
     {
         sps->sps_extension_flag = true;
diff --git a/source/encoder/entropy.cpp b/source/encoder/entropy.cpp
index 86a1d0c7d..ece8d6bc9 100644
--- a/source/encoder/entropy.cpp
+++ b/source/encoder/entropy.cpp
@@ -581,12 +581,10 @@ void Entropy::codeSPS(const SPS& sps, const
ScalingList& scalingList, const Prof
     if (scalingList.m_bEnabled)
     {
 #if ENABLE_MULTIVIEW
-        if (sps.maxViews > 1)
-        {
-            if ((layer != 0 && sps.setSpsExtOrMaxSubLayersMinus1 == 7))
-                WRITE_FLAG(1, "sps_infer_scaling_list_flag");
+        if ((layer != 0 && sps.setSpsExtOrMaxSubLayersMinus1 == 7))
+            WRITE_FLAG(sps.spsInferScalingListFlag,
"sps_infer_scaling_list_flag");
+        if(sps.spsInferScalingListFlag)
             WRITE_CODE(0, 6, "sps_scaling_list_ref_layer_id");
-        }
         else
 #endif
         {
@@ -667,7 +665,7 @@ void Entropy::codePPS( const PPS& pps, bool
filerAcross, int iPPSInitQpMinus26,
     WRITE_FLAG(pps.pps_slice_chroma_qp_offsets_present_flag,
"pps_slice_chroma_qp_offsets_present_flag");

     WRITE_FLAG(layer ? 0 : pps.bUseWeightPred,
 "weighted_pred_flag");
-    WRITE_FLAG(pps.bUseWeightedBiPred,        "weighted_bipred_flag");
+    WRITE_FLAG(layer ? 0 : pps.bUseWeightedBiPred,
 "weighted_bipred_flag");
     WRITE_FLAG(pps.bTransquantBypassEnabled,
 "transquant_bypass_enable_flag");
     WRITE_FLAG(0,                             "tiles_enabled_flag");
     WRITE_FLAG(pps.bEntropyCodingSyncEnabled,
"entropy_coding_sync_enabled_flag");
@@ -1766,10 +1764,6 @@ void Entropy::codePredWeightTable(const Slice& slice)
         {
             for (int ref = 0; ref < slice.m_numRefIdx[list]; ref++)
             {
-#if ENABLE_SCC_EXT
-                if (slice.m_poc == slice.m_refPOCList[list][ref])
-                    continue;
-#endif
                 wp = slice.m_weightPredTable[list][ref];
                 if (!bDenomCoded)
                 {
@@ -1782,7 +1776,12 @@ void Entropy::codePredWeightTable(const Slice& slice)
                     }
                     bDenomCoded = true;
                 }
-                WRITE_FLAG(!!wp[0].wtPresent, "luma_weight_lX_flag");
+#if ENABLE_SCC_EXT
+                if (slice.m_poc == slice.m_refPOCList[list][ref])
+                    assert(!wp[0].wtPresent);
+                else
+#endif
+                    WRITE_FLAG(!!wp[0].wtPresent, "luma_weight_lX_flag");
                 totalSignalledWeightFlags += wp[0].wtPresent;
             }

@@ -1790,22 +1789,19 @@ void Entropy::codePredWeightTable(const Slice&
slice)
             {
                 for (int ref = 0; ref < slice.m_numRefIdx[list]; ref++)
                 {
+                    wp = slice.m_weightPredTable[list][ref];
 #if ENABLE_SCC_EXT
                     if (slice.m_poc == slice.m_refPOCList[list][ref])
-                        continue;
+                        assert(!wp[1].wtPresent);
+                    else
 #endif
-                    wp = slice.m_weightPredTable[list][ref];
-                    WRITE_FLAG(!!wp[1].wtPresent, "chroma_weight_lX_flag");
+                        WRITE_FLAG(!!wp[1].wtPresent,
"chroma_weight_lX_flag");
                     totalSignalledWeightFlags += 2 * wp[1].wtPresent;
                 }
             }

             for (int ref = 0; ref < slice.m_numRefIdx[list]; ref++)
             {
-#if ENABLE_SCC_EXT
-                if (slice.m_poc == slice.m_refPOCList[list][ref])
-                    continue;
-#endif
                 wp = slice.m_weightPredTable[list][ref];
                 if (wp[0].wtPresent)
                 {
diff --git a/source/encoder/sei.h b/source/encoder/sei.h
index f02e0c50d..3ed957058 100644
--- a/source/encoder/sei.h
+++ b/source/encoder/sei.h
@@ -469,15 +469,15 @@ public:
             {
                 for (int k = 0; k <= 2; k++)  /* column */
                 {
-                    temp_sign_r[j][k] = sign_r[j][k];
-                    temp_exponent_r[j][k] = exponent_r[j][k];
-                    temp_mantissa_r[j][k] = mantissa_r[j][k];
-                    temp_length_mantissa_r[j][k] = length_mantissa_r[j][k];
+                    sign_r[j][k] = temp_sign_r[j][k];
+                    exponent_r[j][k] = temp_exponent_r[j][k];
+                    mantissa_r[j][k] = temp_mantissa_r[j][k];
+                    length_mantissa_r[j][k] = temp_length_mantissa_r[j][k];
                 }
-                temp_sign_t[i][j] = sign_t[i][j];
-                temp_exponent_t[i][j] = exponent_t[i][j];
-                temp_mantissa_t[i][j] = mantissa_t[i][j];
-                temp_length_mantissa_t[i][j] = length_mantissa_t[i][j];
+                sign_t[i][j] = temp_sign_t[i][j];
+                exponent_t[i][j] = temp_exponent_t[i][j];
+                mantissa_t[i][j] = temp_mantissa_t[i][j];
+                length_mantissa_t[i][j] = temp_length_mantissa_t[i][j];
             }
         }
     }
diff --git a/source/encoder/weightPrediction.cpp
b/source/encoder/weightPrediction.cpp
index 718d88284..a3136d056 100644
--- a/source/encoder/weightPrediction.cpp
+++ b/source/encoder/weightPrediction.cpp
@@ -492,10 +492,6 @@ void weightAnalyse(Slice& slice, Frame& frame,
x265_param& param)
         chromaDenom = weights[1].log2WeightDenom;

         int numIdx = slice.m_numRefIdx[list];
-#if ENABLE_SCC_EXT
-        if (!list && param.bEnableSCC)
-            numIdx--;
-#endif

         /* reset weight states */
         for (int ref = 1; ref < numIdx; ref++)
diff --git a/source/x265.h b/source/x265.h
index c4fb1a54d..58e7ff11b 100644
--- a/source/x265.h
+++ b/source/x265.h
@@ -2343,6 +2343,7 @@ typedef struct x265_param

     /*Frame level RateControl Configuration*/
     int     bConfigRCFrame;
+    int    isAbrLadderEnable;
 } x265_param;

 /* x265_param_alloc:
-- 
2.36.0.windows.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241121/5bde1643/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0009-Fix-decoder-crash-in-alpha-scc-mv-hevc.patch
Type: application/octet-stream
Size: 9816 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241121/5bde1643/attachment-0001.obj>


More information about the x265-devel mailing list