<div dir="ltr">From 69560b753aadfc06f1b315aea2354f3c01536028 Mon Sep 17 00:00:00 2001<br>From: AnusuyaKumarasamy <<a href="mailto:anusuya.kumarasamy@multicorewareinc.com">anusuya.kumarasamy@multicorewareinc.com</a>><br>Date: Mon, 28 Oct 2024 11:30:49 +0530<br>Subject: [PATCH 09/10] Remove frameencoder instance for mcstf and fix memory<br> leak<br><br>---<br> source/common/frame.cpp         |  1 +<br> source/common/lowres.cpp        |  2 +-<br> source/encoder/frameencoder.cpp | 40 +++++++++------------------------<br> source/encoder/frameencoder.h   |  4 ----<br> 4 files changed, 12 insertions(+), 35 deletions(-)<br><br>diff --git a/source/common/frame.cpp b/source/common/frame.cpp<br>index e5f5b0327..fbecfb4e9 100644<br>--- a/source/common/frame.cpp<br>+++ b/source/common/frame.cpp<br>@@ -316,6 +316,7 @@ void Frame::destroy()<br>             m_fencPicSubsampled4 = NULL;<br>         }<br> <br>+        delete m_mcstf->m_metld;<br>         for (int i = 0; i < (m_mcstf->m_range << 1); i++)<br>             m_mcstf->destroyRefPicInfo(&m_mcstfRefList[i]);<br> <br>diff --git a/source/common/lowres.cpp b/source/common/lowres.cpp<br>index 14d1e03f4..17c071c2c 100644<br>--- a/source/common/lowres.cpp<br>+++ b/source/common/lowres.cpp<br>@@ -253,7 +253,7 @@ fail:<br> void Lowres::destroy(x265_param* param)<br> {<br>     X265_FREE(buffer[0]);<br>-    if(bEnableHME)<br>+    if(bEnableHME || param->bEnableTemporalFilter)<br>         X265_FREE(lowerResBuffer[0]);<br>     X265_FREE(intraCost);<br>     X265_FREE(intraMode);<br>diff --git a/source/encoder/frameencoder.cpp b/source/encoder/frameencoder.cpp<br>index 772810f3d..f0ced45e1 100644<br>--- a/source/encoder/frameencoder.cpp<br>+++ b/source/encoder/frameencoder.cpp<br>@@ -106,16 +106,6 @@ void FrameEncoder::destroy()<br>         delete m_rce.picTimingSEI;<br>         delete m_rce.hrdTiming;<br>     }<br>-<br>-    if (m_param->bEnableTemporalFilter)<br>-    {<br>-        delete m_frameEncTF->m_metld;<br>-<br>-        for (int i = 0; i < (m_frameEncTF->m_range << 1); i++)<br>-            m_frameEncTF->destroyRefPicInfo(&m_mcstfRefList[i]);<br>-<br>-        delete m_frameEncTF;<br>-    }<br> }<br> <br> bool FrameEncoder::init(Encoder *top, int numRows, int numCols)<br>@@ -210,16 +200,6 @@ bool FrameEncoder::init(Encoder *top, int numRows, int numCols)<br>         m_sliceAddrBits = (uint16_t)(tmp + 1);<br>     }<br> <br>-    if (m_param->bEnableTemporalFilter)<br>-    {<br>-        m_frameEncTF = new TemporalFilter();<br>-        if (m_frameEncTF)<br>-            m_frameEncTF->init(m_param);<br>-<br>-        for (int i = 0; i < (m_frameEncTF->m_range << 1); i++)<br>-            ok &= !!m_frameEncTF->createRefPicInfo(&m_mcstfRefList[i], m_param);<br>-    }<br>-<br>     m_retFrameBuffer = X265_MALLOC(Frame*, m_param->numLayers);<br>     for (int layer = 0; layer < m_param->numLayers; layer++)<br>         m_retFrameBuffer[layer] = NULL;<br>@@ -676,8 +656,8 @@ void FrameEncoder::compressFrame(int layer)<br>     }<br>     if (m_param->bEnableTemporalFilter)<br>     {<br>-        m_frameEncTF->m_QP = qp;<br>-        m_frameEncTF->bilateralFilter(m_frame[layer], m_frame[layer]->m_mcstfRefList, m_param->temporalFilterStrength);<br>+        m_frame[layer]->m_mcstf->m_QP = qp;<br>+        m_frame[layer]->m_mcstf->bilateralFilter(m_frame[layer], m_frame[layer]->m_mcstfRefList, m_param->temporalFilterStrength);<br>     }<br> <br>     if (m_nr)<br>@@ -1071,14 +1051,14 @@ void FrameEncoder::compressFrame(int layer)<br>     if (m_param->bEnableTemporalFilter && m_top->isFilterThisframe(m_frame[layer]->m_mcstf->m_sliceTypeConfig, m_frame[layer]->m_lowres.sliceType))<br>     {<br>         //Reset the MCSTF context in Frame Encoder and Frame<br>-        for (int i = 0; i < (m_frameEncTF->m_range << 1); i++)<br>-        {<br>-            memset(m_mcstfRefList[i].mvs0, 0, sizeof(MV) * ((m_param->sourceWidth / 16) * (m_param->sourceHeight / 16)));<br>-            memset(m_mcstfRefList[i].mvs1, 0, sizeof(MV) * ((m_param->sourceWidth / 16) * (m_param->sourceHeight / 16)));<br>-            memset(m_mcstfRefList[i].mvs2, 0, sizeof(MV) * ((m_param->sourceWidth / 16) * (m_param->sourceHeight / 16)));<br>-            memset(m_mcstfRefList[i].mvs,  0, sizeof(MV) * ((m_param->sourceWidth / 4) * (m_param->sourceHeight / 4)));<br>-            memset(m_mcstfRefList[i].noise, 0, sizeof(int) * ((m_param->sourceWidth / 4) * (m_param->sourceHeight / 4)));<br>-            memset(m_mcstfRefList[i].error, 0, sizeof(int) * ((m_param->sourceWidth / 4) * (m_param->sourceHeight / 4)));<br>+        for (int i = 0; i < (m_frame[layer]->m_mcstf->m_range << 1); i++)<br>+        {<br>+            memset(m_frame[layer]->m_mcstfRefList[i].mvs0, 0, sizeof(MV) * ((m_param->sourceWidth / 16) * (m_param->sourceHeight / 16)));<br>+            memset(m_frame[layer]->m_mcstfRefList[i].mvs1, 0, sizeof(MV) * ((m_param->sourceWidth / 16) * (m_param->sourceHeight / 16)));<br>+            memset(m_frame[layer]->m_mcstfRefList[i].mvs2, 0, sizeof(MV) * ((m_param->sourceWidth / 16) * (m_param->sourceHeight / 16)));<br>+            memset(m_frame[layer]->m_mcstfRefList[i].mvs,  0, sizeof(MV) * ((m_param->sourceWidth / 4) * (m_param->sourceHeight / 4)));<br>+            memset(m_frame[layer]->m_mcstfRefList[i].noise, 0, sizeof(int) * ((m_param->sourceWidth / 4) * (m_param->sourceHeight / 4)));<br>+            memset(m_frame[layer]->m_mcstfRefList[i].error, 0, sizeof(int) * ((m_param->sourceWidth / 4) * (m_param->sourceHeight / 4)));<br> <br>             m_frame[layer]->m_mcstf->m_numRef = 0;<br>         }<br>diff --git a/source/encoder/frameencoder.h b/source/encoder/frameencoder.h<br>index 21d05c2f2..c31762402 100644<br>--- a/source/encoder/frameencoder.h<br>+++ b/source/encoder/frameencoder.h<br>@@ -265,10 +265,6 @@ public:<br>     FrameFilter              m_frameFilter;<br>     NALList                  m_nalList;<br> <br>-    // initialization for mcstf<br>-    TemporalFilter*          m_frameEncTF;<br>-    TemporalFilterRefPicInfo m_mcstfRefList[MAX_MCSTF_TEMPORAL_WINDOW_LENGTH];<br>-<br>     int                      m_sLayerId;<br> <br>     class WeightAnalysis : public BondedTaskGroup<br>-- <br>2.36.0.windows.1<br><br></div>