<div dir="ltr">From 03db2eab9c3d38d3d9c2f5305a2d42ee2ca2035f Mon Sep 17 00:00:00 2001<br>From: AnusuyaKumarasamy <<a href="mailto:anusuya.kumarasamy@multicorewareinc.com">anusuya.kumarasamy@multicorewareinc.com</a>><br>Date: Fri, 20 Sep 2024 16:31:31 +0530<br>Subject: [PATCH 2/5] Fix segmentation fault in scc<br><br>---<br> source/common/cudata.cpp    | 6 +++---<br> source/encoder/analysis.cpp | 2 +-<br> source/encoder/encoder.cpp  | 6 ++++++<br> source/encoder/search.cpp   | 8 ++++----<br> 4 files changed, 14 insertions(+), 8 deletions(-)<br><br>diff --git a/source/common/cudata.cpp b/source/common/cudata.cpp<br>index 23ceeaeaf..ae1fb4694 100644<br>--- a/source/common/cudata.cpp<br>+++ b/source/common/cudata.cpp<br>@@ -2378,9 +2378,9 @@ void CUData::getIntraBCMVPsEncOnly(uint32_t absPartIdx, MV* MvPred, int& nbPred,<br>     uint32_t            m_numPartitionsInCtu = s_numPartInCUSize * s_numPartInCUSize;<br>     uint32_t            m_frameWidthInCtus = (m_slice->m_sps->picWidthInLumaSamples % m_slice->m_param->maxCUSize) ? m_slice->m_sps->picWidthInLumaSamples / m_slice->m_param->maxCUSize + 1 : m_slice->m_sps->picWidthInLumaSamples / m_slice->m_param->maxCUSize;<br> <br>-    uint32_t            partIdxLT = m_absIdxInCTU + absPartIdx;<br>-    uint32_t            partIdxLB = g_rasterToZscan[g_zscanToRaster[partIdxLT] + (height / 4 - 1) * numPartInCUWidth];<br>-    uint32_t            partIdxRT = g_rasterToZscan[g_zscanToRaster[partIdxLT] + width / 4 - 1];<br>+    uint32_t            partIdxLT = m_absIdxInCTU;<br>+    uint32_t            partIdxLB = g_rasterToZscan[g_zscanToRaster[m_absIdxInCTU] + (((1 << (m_log2CUSize[0] - LOG2_UNIT_SIZE - 1)) - 1) << LOG2_RASTER_SIZE)];<br>+    uint32_t            partIdxRT = g_rasterToZscan[g_zscanToRaster[partIdxLT] + (1 << (m_log2CUSize[0] - LOG2_UNIT_SIZE)) - 1];<br> <br>     left = above = 0;<br> <br>diff --git a/source/encoder/analysis.cpp b/source/encoder/analysis.cpp<br>index 53a19b29f..d60747cc0 100644<br>--- a/source/encoder/analysis.cpp<br>+++ b/source/encoder/analysis.cpp<br>@@ -3623,7 +3623,7 @@ void Analysis::checkBidir2Nx2N(Mode& inter2Nx2N, Mode& bidir2Nx2N, const CUGeom&<br>     CUData& cu = bidir2Nx2N.cu;<br> <br> #if ENABLE_SCC_EXT<br>-    if ((cu.is8x8BipredRestriction(inter2Nx2N.bestME[0][0].mv, inter2Nx2N.bestME[0][1].mv, inter2Nx2N.bestME[0][0].ref, inter2Nx2N.bestME[0][1].ref) ? (cu.m_cuDepth[0] == 3) : cu.isBipredRestriction()) || inter2Nx2N.bestME[0][0].cost == MAX_UINT || inter2Nx2N.bestME[0][1].cost == MAX_UINT)<br>+    if ((cu.is8x8BipredRestriction(inter2Nx2N.bestME[0][0].mv, inter2Nx2N.bestME[0][1].mv, inter2Nx2N.bestME[0][0].ref, inter2Nx2N.bestME[0][1].ref) ? (1 << cu.m_log2CUSize[0] == 8) : cu.isBipredRestriction()) || inter2Nx2N.bestME[0][0].cost == MAX_UINT || inter2Nx2N.bestME[0][1].cost == MAX_UINT)<br> #else<br>     if (cu.isBipredRestriction() || inter2Nx2N.bestME[0][0].cost == MAX_UINT || inter2Nx2N.bestME[0][1].cost == MAX_UINT)<br> #endif<br>diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp<br>index 82123606c..f4a998fa9 100644<br>--- a/source/encoder/encoder.cpp<br>+++ b/source/encoder/encoder.cpp<br>@@ -4715,6 +4715,12 @@ void Encoder::configure(x265_param *p)<br>             p->keyframeMin = p->keyframeMax;<br>         }<br>     }<br>+<br>+    if (!!p->bEnableSCC && p->maxNumReferences == 1)<br>+    {<br>+        x265_log(p, X265_LOG_WARNING, "Screen Content Coding requies maximum number of references should be atleast greater than 1.Increamenting by one.\n");<br>+        p->maxNumReferences++;<br>+    }<br> }<br> <br> void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x265_picture* picIn, int paramBytes)<br>diff --git a/source/encoder/search.cpp b/source/encoder/search.cpp<br>index 0df11b431..ebd85dd52 100644<br>--- a/source/encoder/search.cpp<br>+++ b/source/encoder/search.cpp<br>@@ -3503,7 +3503,7 @@ void Search::setIntraSearchRange(Mode& intraBCMode, MV& pred, int puIdx, int roi<br>     const uint32_t picWidth = m_slice->m_sps->picWidthInLumaSamples;<br>     const uint32_t picHeight = m_slice->m_sps->picHeightInLumaSamples;<br>     bool  isFullFrameSearchrangeEnabled = false; // disabled by default<br>-    if (cu.m_cuDepth[0] == 2 && cu.m_partSize[0] == SIZE_2Nx2N && isFullFrameSearchrangeEnabled)// full frame search<br>+    if (1 << cu.m_log2CUSize[0] == 16 && cu.m_partSize[0] == SIZE_2Nx2N && isFullFrameSearchrangeEnabled)// full frame search<br>     {<br>         srLeft = -1 * cuPelX;<br>         srTop = -1 * cuPelY;<br>@@ -3513,7 +3513,7 @@ void Search::setIntraSearchRange(Mode& intraBCMode, MV& pred, int puIdx, int roi<br>     }<br>     else<br>     {<br>-        const uint32_t searchWidthInCTUs = cu.m_cuDepth[0] == 3 ? 1 : (isFullFrameSearchrangeEnabled) ? -1 : 1;<br>+        const uint32_t searchWidthInCTUs = 1 << cu.m_log2CUSize[0] == 8 ? 1 : (isFullFrameSearchrangeEnabled) ? -1 : 1;<br>         uint32_t width = 0, maxWidth = searchWidthInCTUs * lcuWidth;<br>         for (const CUData* pTestCU = cu.m_cuLeft;<br>             width < maxWidth && pTestCU != NULL && pTestCU->m_slice != NULL;<br>@@ -3718,7 +3718,7 @@ bool Search::predIntraBCSearch(Mode& intraBCMode, const CUGeom& cuGeom, bool bCh<br> <br>         if (ePartSize != SIZE_2Nx2N)<br>         {<br>-            if (log2ParallelMergeLevelMinus2 && ePartSize != SIZE_2Nx2N && cu.m_cuDepth[0] >= 3)<br>+            if (log2ParallelMergeLevelMinus2 && ePartSize != SIZE_2Nx2N && 1 << cu.m_log2CUSize[0] >= 8)<br>             {<br>                 cu.setPartSizeSubParts(SIZE_2Nx2N);<br>                 if (puIdx == 0)<br>@@ -4010,7 +4010,7 @@ bool Search::predMixedIntraBCInterSearch(Mode& intraBCMixedMode, const CUGeom& c<br> <br>                 if (ePartSize != SIZE_2Nx2N)<br>                 {<br>-                    if (log2ParallelMergeLevelMinus2 && ePartSize != SIZE_2Nx2N && cu.m_cuDepth[0] >= 3)<br>+                    if (log2ParallelMergeLevelMinus2 && ePartSize != SIZE_2Nx2N && 1 << cu.m_log2CUSize[0] >= 8)<br>                     {<br>                         cu.setPartSizeSubParts(SIZE_2Nx2N);<br>                         if (partIdx == 0)<br>-- <br>2.36.0.windows.1<br><br></div>