<div dir="ltr">From 7cacb15e7992677942cacf858c80698a2af8d5b3 Mon Sep 17 00:00:00 2001<br>From: AnusuyaKumarasamy <<a href="mailto:anusuya.kumarasamy@multicorewareinc.com">anusuya.kumarasamy@multicorewareinc.com</a>><br>Date: Wed, 18 Sep 2024 16:29:29 +0530<br>Subject: [PATCH 1/5] Fix seg fault while enabling sea<br><br>---<br> source/encoder/encoder.cpp     | 28 ++++++++++++++++------------<br> source/encoder/framefilter.cpp |  6 +++---<br> source/encoder/framefilter.h   |  2 +-<br> 3 files changed, 20 insertions(+), 16 deletions(-)<br><br>diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp<br>index 65c247aba..82123606c 100644<br>--- a/source/encoder/encoder.cpp<br>+++ b/source/encoder/encoder.cpp<br>@@ -2332,22 +2332,26 @@ int Encoder::encode(const x265_picture* pic_in, x265_picture** pic_out)<br>                     }<br>                 }<br>             }<br>-            if (m_param->searchMethod == X265_SEA && frameEnc[0]->m_lowres.sliceType != X265_TYPE_B)<br>+<br>+            for (int layer = 0; layer < m_param->numLayers; layer++)<br>             {<br>-                int padX = m_param->maxCUSize + 32;<br>-                int padY = m_param->maxCUSize + 16;<br>-                uint32_t numCuInHeight = (frameEnc[0]->m_encData->m_reconPic[0]->m_picHeight + m_param->maxCUSize - 1) / m_param->maxCUSize;<br>-                int maxHeight = numCuInHeight * m_param->maxCUSize;<br>-                for (int i = 0; i < INTEGRAL_PLANE_NUM; i++)<br>+                if (m_param->searchMethod == X265_SEA && (frameEnc[layer]->m_lowres.sliceType != X265_TYPE_B || !layer))<br>                 {<br>-                    frameEnc[0]->m_encData->m_meBuffer[i] = X265_MALLOC(uint32_t, frameEnc[0]->m_reconPic[0]->m_stride * (maxHeight + (2 * padY)));<br>-                    if (frameEnc[0]->m_encData->m_meBuffer[i])<br>+                    int padX = m_param->maxCUSize + 32;<br>+                    int padY = m_param->maxCUSize + 16;<br>+                    uint32_t numCuInHeight = (frameEnc[layer]->m_encData->m_reconPic[0]->m_picHeight + m_param->maxCUSize - 1) / m_param->maxCUSize;<br>+                    int maxHeight = numCuInHeight * m_param->maxCUSize;<br>+                    for (int i = 0; i < INTEGRAL_PLANE_NUM; i++)<br>                     {<br>-                        memset(frameEnc[0]->m_encData->m_meBuffer[i], 0, sizeof(uint32_t)* frameEnc[0]->m_reconPic[0]->m_stride * (maxHeight + (2 * padY)));<br>-                        frameEnc[0]->m_encData->m_meIntegral[i] = frameEnc[0]->m_encData->m_meBuffer[i] + frameEnc[0]->m_encData->m_reconPic[0]->m_stride * padY + padX;<br>+                        frameEnc[layer]->m_encData->m_meBuffer[i] = X265_MALLOC(uint32_t, frameEnc[layer]->m_reconPic[0]->m_stride * (maxHeight + (2 * padY)));<br>+                        if (frameEnc[layer]->m_encData->m_meBuffer[i])<br>+                        {<br>+                            memset(frameEnc[layer]->m_encData->m_meBuffer[i], 0, sizeof(uint32_t) * frameEnc[layer]->m_reconPic[0]->m_stride * (maxHeight + (2 * padY)));<br>+                            frameEnc[layer]->m_encData->m_meIntegral[i] = frameEnc[layer]->m_encData->m_meBuffer[i] + frameEnc[layer]->m_encData->m_reconPic[0]->m_stride * padY + padX;<br>+                        }<br>+                        else<br>+                            x265_log(m_param, X265_LOG_ERROR, "SEA motion search: POC %d Integral buffer[%d] unallocated\n", frameEnc[0]->m_poc, i);<br>                     }<br>-                    else<br>-                        x265_log(m_param, X265_LOG_ERROR, "SEA motion search: POC %d Integral buffer[%d] unallocated\n", frameEnc[0]->m_poc, i);<br>                 }<br>             }<br> <br>diff --git a/source/encoder/framefilter.cpp b/source/encoder/framefilter.cpp<br>index 344ac738d..71dc42b2c 100644<br>--- a/source/encoder/framefilter.cpp<br>+++ b/source/encoder/framefilter.cpp<br>@@ -659,7 +659,7 @@ void FrameFilter::processPostRow(int row, int layer)<br> <br>     /* Generate integral planes for SEA motion search */<br>     if(m_param->searchMethod == X265_SEA)<br>-        computeMEIntegral(row);<br>+        computeMEIntegral(row, layer);<br>     // Notify other FrameEncoders that this row of reconstructed pixels is available<br>     m_frame->m_reconRowFlag[row].set(1);<br> <br>@@ -722,10 +722,10 @@ void FrameFilter::processPostRow(int row, int layer)<br>     }<br> }<br> <br>-void FrameFilter::computeMEIntegral(int row)<br>+void FrameFilter::computeMEIntegral(int row, int layer)<br> {<br>     int lastRow = row == (int)m_frame->m_encData->m_slice->m_sps->numCuInHeight - 1;<br>-    if (m_frame->m_lowres.sliceType != X265_TYPE_B)<br>+    if (m_frame->m_lowres.sliceType != X265_TYPE_B || !layer)<br>     {<br>         /* If WPP, other than first row, integral calculation for current row needs to wait till the<br>         * integral for the previous row is computed */<br>diff --git a/source/encoder/framefilter.h b/source/encoder/framefilter.h<br>index b84b7094c..8bea1a0e9 100644<br>--- a/source/encoder/framefilter.h<br>+++ b/source/encoder/framefilter.h<br>@@ -130,7 +130,7 @@ public:<br> <br>     void processRow(int row, int layer);<br>     void processPostRow(int row, int layer);<br>-    void computeMEIntegral(int row);<br>+    void computeMEIntegral(int row, int layer);<br> };<br> }<br> <br>-- <br>2.36.0.windows.1<br><br></div>