<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif">From 691bee81e212d752bd4bbe471a4cf737159268b1 Mon Sep 17 00:00:00 2001<br>From: AnusuyaKumarasamy <<a href="mailto:anusuya.kumarasamy@multicorewareinc.com">anusuya.kumarasamy@multicorewareinc.com</a>><br>Date: Tue, 19 Nov 2024 16:07:25 +0530<br>Subject: [PATCH] Fix decoder crash in alpha,scc,mv-hevc<br><br>---<br> source/abrEncApp.cpp                |  6 +++---<br> source/common/param.cpp             |  4 ++--<br> source/common/slice.h               |  1 +<br> source/encoder/encoder.cpp          |  1 +<br> source/encoder/entropy.cpp          | 32 +++++++++++++----------------<br> source/encoder/sei.h                | 16 +++++++--------<br> source/encoder/weightPrediction.cpp |  4 ----<br> source/x265.h                       |  1 +<br> 8 files changed, 30 insertions(+), 35 deletions(-)<br><br>diff --git a/source/abrEncApp.cpp b/source/abrEncApp.cpp<br>index 66787ff11..c83c00e90 100644<br>--- a/source/abrEncApp.cpp<br>+++ b/source/abrEncApp.cpp<br>@@ -63,7 +63,7 @@ namespace X265_NS {<br>             m_passEnc[i]->init(ret);<br>         }<br> <br>-        m_numInputViews = m_passEnc[0]->m_param->numViews - !!m_passEnc[0]->m_param->format;<br>+        m_numInputViews = (m_passEnc[0]->m_param->numViews > 1) ? m_passEnc[0]->m_param->numViews - !!m_passEnc[0]->m_param->format : 0;<br>         if (!allocBuffers())<br>         {<br>             x265_log(NULL, X265_LOG_ERROR, "Unable to allocate memory for buffers\n");<br>@@ -146,7 +146,7 @@ namespace X265_NS {<br>     {<br>         x265_cleanup(); /* Free library singletons */<br> #if ENABLE_MULTIVIEW<br>-        if(m_numInputViews > 1)<br>+        if(m_numInputViews != 0)<br>         {<br>             for (uint8_t pass = 0; pass < m_numInputViews; pass++)<br>             {<br>@@ -252,7 +252,7 @@ namespace X265_NS {<br>                 }<br>             }<br>         }<br>-<br>+        m_param->isAbrLadderEnable = m_parent->m_numEncodes > 1;<br>         if (m_cliopt.zoneFile)<br>         {<br>             if (!m_cliopt.parseZoneFile())<br>diff --git a/source/common/param.cpp b/source/common/param.cpp<br>index dd8a12ef4..b8ec5b3d0 100755<br>--- a/source/common/param.cpp<br>+++ b/source/common/param.cpp<br>@@ -1515,8 +1515,6 @@ int x265_param_parse(x265_param* p, const char* name, const char* value)<br>         OPT("scc")<br>         {<br>             p->bEnableSCC = atoi(value);<br>-            if (p->bEnableSCC)<br>-                p->bEnableWeightedPred = false;<br>         }<br> #endif<br>         OPT("frame-rc") p->bConfigRCFrame = atobool(value);<br>@@ -2007,6 +2005,7 @@ int x265_check_params(x265_param* param)<br>         CHECK(param->internalBitDepth != 8, "BitDepthConstraint must be 8 for Multiview main profile");<br>         CHECK(param->analysisMultiPassDistortion || param->analysisMultiPassRefine, "Multiview encode doesnot support multipass feature");<br>         CHECK(strlen(param->analysisSave) || strlen(param->analysisLoad), "Multiview encode doesnot support analysis save and load feature");<br>+        CHECK(param->isAbrLadderEnable, "Multiview encode and Abr-Ladder feature can't be enabled together");<br>     }<br> #endif<br> #if ENABLE_SCC_EXT<br>@@ -3025,6 +3024,7 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>         dst->aomFilmGrain = src->aomFilmGrain;<br>     dst->bEnableSBRC = src->bEnableSBRC;<br>     dst->bConfigRCFrame = src->bConfigRCFrame;<br>+    dst->isAbrLadderEnable = src->isAbrLadderEnable;<br> }<br> <br> #ifdef SVT_HEVC<br>diff --git a/source/common/slice.h b/source/common/slice.h<br>index 08e2577c7..df6f540f8 100644<br>--- a/source/common/slice.h<br>+++ b/source/common/slice.h<br>@@ -281,6 +281,7 @@ struct SPS<br> <br> #if ENABLE_MULTIVIEW<br>     int      setSpsExtOrMaxSubLayersMinus1;<br>+    int      spsInferScalingListFlag;<br>     int      maxViews;<br>     bool     vui_parameters_present_flag;<br> #endif<br>diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp<br>index e85e09d82..ee39c3280 100644<br>--- a/source/encoder/encoder.cpp<br>+++ b/source/encoder/encoder.cpp<br>@@ -3602,6 +3602,7 @@ void Encoder::initSPS(SPS *sps)<br> #if ENABLE_MULTIVIEW<br>     sps->setSpsExtOrMaxSubLayersMinus1 = sps->maxTempSubLayers - 1;<br>     sps->maxViews = m_param->numViews;<br>+    sps->spsInferScalingListFlag = 0;<br>     if (m_param->numViews > 1)<br>     {<br>         sps->sps_extension_flag = true;<br>diff --git a/source/encoder/entropy.cpp b/source/encoder/entropy.cpp<br>index 86a1d0c7d..ece8d6bc9 100644<br>--- a/source/encoder/entropy.cpp<br>+++ b/source/encoder/entropy.cpp<br>@@ -581,12 +581,10 @@ void Entropy::codeSPS(const SPS& sps, const ScalingList& scalingList, const Prof<br>     if (scalingList.m_bEnabled)<br>     {<br> #if ENABLE_MULTIVIEW<br>-        if (sps.maxViews > 1)<br>-        {<br>-            if ((layer != 0 && sps.setSpsExtOrMaxSubLayersMinus1 == 7))<br>-                WRITE_FLAG(1, "sps_infer_scaling_list_flag");<br>+        if ((layer != 0 && sps.setSpsExtOrMaxSubLayersMinus1 == 7))<br>+            WRITE_FLAG(sps.spsInferScalingListFlag, "sps_infer_scaling_list_flag");<br>+        if(sps.spsInferScalingListFlag)<br>             WRITE_CODE(0, 6, "sps_scaling_list_ref_layer_id");<br>-        }<br>         else<br> #endif<br>         {<br>@@ -667,7 +665,7 @@ void Entropy::codePPS( const PPS& pps, bool filerAcross, int iPPSInitQpMinus26,<br>     WRITE_FLAG(pps.pps_slice_chroma_qp_offsets_present_flag, "pps_slice_chroma_qp_offsets_present_flag");<br> <br>     WRITE_FLAG(layer ? 0 : pps.bUseWeightPred,            "weighted_pred_flag");<br>-    WRITE_FLAG(pps.bUseWeightedBiPred,        "weighted_bipred_flag");<br>+    WRITE_FLAG(layer ? 0 : pps.bUseWeightedBiPred,        "weighted_bipred_flag");<br>     WRITE_FLAG(pps.bTransquantBypassEnabled,  "transquant_bypass_enable_flag");<br>     WRITE_FLAG(0,                             "tiles_enabled_flag");<br>     WRITE_FLAG(pps.bEntropyCodingSyncEnabled, "entropy_coding_sync_enabled_flag");<br>@@ -1766,10 +1764,6 @@ void Entropy::codePredWeightTable(const Slice& slice)<br>         {<br>             for (int ref = 0; ref < slice.m_numRefIdx[list]; ref++)<br>             {<br>-#if ENABLE_SCC_EXT<br>-                if (slice.m_poc == slice.m_refPOCList[list][ref])<br>-                    continue;<br>-#endif<br>                 wp = slice.m_weightPredTable[list][ref];<br>                 if (!bDenomCoded)<br>                 {<br>@@ -1782,7 +1776,12 @@ void Entropy::codePredWeightTable(const Slice& slice)<br>                     }<br>                     bDenomCoded = true;<br>                 }<br>-                WRITE_FLAG(!!wp[0].wtPresent, "luma_weight_lX_flag");<br>+#if ENABLE_SCC_EXT<br>+                if (slice.m_poc == slice.m_refPOCList[list][ref])<br>+                    assert(!wp[0].wtPresent);<br>+                else<br>+#endif<br>+                    WRITE_FLAG(!!wp[0].wtPresent, "luma_weight_lX_flag");<br>                 totalSignalledWeightFlags += wp[0].wtPresent;<br>             }<br> <br>@@ -1790,22 +1789,19 @@ void Entropy::codePredWeightTable(const Slice& slice)<br>             {<br>                 for (int ref = 0; ref < slice.m_numRefIdx[list]; ref++)<br>                 {<br>+                    wp = slice.m_weightPredTable[list][ref];<br> #if ENABLE_SCC_EXT<br>                     if (slice.m_poc == slice.m_refPOCList[list][ref])<br>-                        continue;<br>+                        assert(!wp[1].wtPresent);<br>+                    else<br> #endif<br>-                    wp = slice.m_weightPredTable[list][ref];<br>-                    WRITE_FLAG(!!wp[1].wtPresent, "chroma_weight_lX_flag");<br>+                        WRITE_FLAG(!!wp[1].wtPresent, "chroma_weight_lX_flag");<br>                     totalSignalledWeightFlags += 2 * wp[1].wtPresent;<br>                 }<br>             }<br> <br>             for (int ref = 0; ref < slice.m_numRefIdx[list]; ref++)<br>             {<br>-#if ENABLE_SCC_EXT<br>-                if (slice.m_poc == slice.m_refPOCList[list][ref])<br>-                    continue;<br>-#endif<br>                 wp = slice.m_weightPredTable[list][ref];<br>                 if (wp[0].wtPresent)<br>                 {<br>diff --git a/source/encoder/sei.h b/source/encoder/sei.h<br>index f02e0c50d..3ed957058 100644<br>--- a/source/encoder/sei.h<br>+++ b/source/encoder/sei.h<br>@@ -469,15 +469,15 @@ public:<br>             {<br>                 for (int k = 0; k <= 2; k++)  /* column */<br>                 {<br>-                    temp_sign_r[j][k] = sign_r[j][k];<br>-                    temp_exponent_r[j][k] = exponent_r[j][k];<br>-                    temp_mantissa_r[j][k] = mantissa_r[j][k];<br>-                    temp_length_mantissa_r[j][k] = length_mantissa_r[j][k];<br>+                    sign_r[j][k] = temp_sign_r[j][k];<br>+                    exponent_r[j][k] = temp_exponent_r[j][k];<br>+                    mantissa_r[j][k] = temp_mantissa_r[j][k];<br>+                    length_mantissa_r[j][k] = temp_length_mantissa_r[j][k];<br>                 }<br>-                temp_sign_t[i][j] = sign_t[i][j];<br>-                temp_exponent_t[i][j] = exponent_t[i][j];<br>-                temp_mantissa_t[i][j] = mantissa_t[i][j];<br>-                temp_length_mantissa_t[i][j] = length_mantissa_t[i][j];<br>+                sign_t[i][j] = temp_sign_t[i][j];<br>+                exponent_t[i][j] = temp_exponent_t[i][j];<br>+                mantissa_t[i][j] = temp_mantissa_t[i][j];<br>+                length_mantissa_t[i][j] = temp_length_mantissa_t[i][j];<br>             }<br>         }<br>     }<br>diff --git a/source/encoder/weightPrediction.cpp b/source/encoder/weightPrediction.cpp<br>index 718d88284..a3136d056 100644<br>--- a/source/encoder/weightPrediction.cpp<br>+++ b/source/encoder/weightPrediction.cpp<br>@@ -492,10 +492,6 @@ void weightAnalyse(Slice& slice, Frame& frame, x265_param& param)<br>         chromaDenom = weights[1].log2WeightDenom;<br> <br>         int numIdx = slice.m_numRefIdx[list];<br>-#if ENABLE_SCC_EXT<br>-        if (!list && param.bEnableSCC)<br>-            numIdx--;<br>-#endif<br> <br>         /* reset weight states */<br>         for (int ref = 1; ref < numIdx; ref++)<br>diff --git a/source/x265.h b/source/x265.h<br>index c4fb1a54d..58e7ff11b 100644<br>--- a/source/x265.h<br>+++ b/source/x265.h<br>@@ -2343,6 +2343,7 @@ typedef struct x265_param<br> <br>     /*Frame level RateControl Configuration*/<br>     int     bConfigRCFrame;<br>+    int    isAbrLadderEnable;<br> } x265_param;<br> <br> /* x265_param_alloc:<br>-- <br>2.36.0.windows.1<br><br></div></div>