[x265] [PATCH 09/10] Remove frameencoder instance for mcstf and fix memory leak

Anusuya Kumarasamy anusuya.kumarasamy at multicorewareinc.com
Mon Nov 11 14:24:00 UTC 2024


>From 69560b753aadfc06f1b315aea2354f3c01536028 Mon Sep 17 00:00:00 2001
From: AnusuyaKumarasamy <anusuya.kumarasamy at multicorewareinc.com>
Date: Mon, 28 Oct 2024 11:30:49 +0530
Subject: [PATCH 09/10] Remove frameencoder instance for mcstf and fix memory
 leak

---
 source/common/frame.cpp         |  1 +
 source/common/lowres.cpp        |  2 +-
 source/encoder/frameencoder.cpp | 40 +++++++++------------------------
 source/encoder/frameencoder.h   |  4 ----
 4 files changed, 12 insertions(+), 35 deletions(-)

diff --git a/source/common/frame.cpp b/source/common/frame.cpp
index e5f5b0327..fbecfb4e9 100644
--- a/source/common/frame.cpp
+++ b/source/common/frame.cpp
@@ -316,6 +316,7 @@ void Frame::destroy()
             m_fencPicSubsampled4 = NULL;
         }

+        delete m_mcstf->m_metld;
         for (int i = 0; i < (m_mcstf->m_range << 1); i++)
             m_mcstf->destroyRefPicInfo(&m_mcstfRefList[i]);

diff --git a/source/common/lowres.cpp b/source/common/lowres.cpp
index 14d1e03f4..17c071c2c 100644
--- a/source/common/lowres.cpp
+++ b/source/common/lowres.cpp
@@ -253,7 +253,7 @@ fail:
 void Lowres::destroy(x265_param* param)
 {
     X265_FREE(buffer[0]);
-    if(bEnableHME)
+    if(bEnableHME || param->bEnableTemporalFilter)
         X265_FREE(lowerResBuffer[0]);
     X265_FREE(intraCost);
     X265_FREE(intraMode);
diff --git a/source/encoder/frameencoder.cpp
b/source/encoder/frameencoder.cpp
index 772810f3d..f0ced45e1 100644
--- a/source/encoder/frameencoder.cpp
+++ b/source/encoder/frameencoder.cpp
@@ -106,16 +106,6 @@ void FrameEncoder::destroy()
         delete m_rce.picTimingSEI;
         delete m_rce.hrdTiming;
     }
-
-    if (m_param->bEnableTemporalFilter)
-    {
-        delete m_frameEncTF->m_metld;
-
-        for (int i = 0; i < (m_frameEncTF->m_range << 1); i++)
-            m_frameEncTF->destroyRefPicInfo(&m_mcstfRefList[i]);
-
-        delete m_frameEncTF;
-    }
 }

 bool FrameEncoder::init(Encoder *top, int numRows, int numCols)
@@ -210,16 +200,6 @@ bool FrameEncoder::init(Encoder *top, int numRows, int
numCols)
         m_sliceAddrBits = (uint16_t)(tmp + 1);
     }

-    if (m_param->bEnableTemporalFilter)
-    {
-        m_frameEncTF = new TemporalFilter();
-        if (m_frameEncTF)
-            m_frameEncTF->init(m_param);
-
-        for (int i = 0; i < (m_frameEncTF->m_range << 1); i++)
-            ok &= !!m_frameEncTF->createRefPicInfo(&m_mcstfRefList[i],
m_param);
-    }
-
     m_retFrameBuffer = X265_MALLOC(Frame*, m_param->numLayers);
     for (int layer = 0; layer < m_param->numLayers; layer++)
         m_retFrameBuffer[layer] = NULL;
@@ -676,8 +656,8 @@ void FrameEncoder::compressFrame(int layer)
     }
     if (m_param->bEnableTemporalFilter)
     {
-        m_frameEncTF->m_QP = qp;
-        m_frameEncTF->bilateralFilter(m_frame[layer],
m_frame[layer]->m_mcstfRefList, m_param->temporalFilterStrength);
+        m_frame[layer]->m_mcstf->m_QP = qp;
+        m_frame[layer]->m_mcstf->bilateralFilter(m_frame[layer],
m_frame[layer]->m_mcstfRefList, m_param->temporalFilterStrength);
     }

     if (m_nr)
@@ -1071,14 +1051,14 @@ void FrameEncoder::compressFrame(int layer)
     if (m_param->bEnableTemporalFilter &&
m_top->isFilterThisframe(m_frame[layer]->m_mcstf->m_sliceTypeConfig,
m_frame[layer]->m_lowres.sliceType))
     {
         //Reset the MCSTF context in Frame Encoder and Frame
-        for (int i = 0; i < (m_frameEncTF->m_range << 1); i++)
-        {
-            memset(m_mcstfRefList[i].mvs0, 0, sizeof(MV) *
((m_param->sourceWidth / 16) * (m_param->sourceHeight / 16)));
-            memset(m_mcstfRefList[i].mvs1, 0, sizeof(MV) *
((m_param->sourceWidth / 16) * (m_param->sourceHeight / 16)));
-            memset(m_mcstfRefList[i].mvs2, 0, sizeof(MV) *
((m_param->sourceWidth / 16) * (m_param->sourceHeight / 16)));
-            memset(m_mcstfRefList[i].mvs,  0, sizeof(MV) *
((m_param->sourceWidth / 4) * (m_param->sourceHeight / 4)));
-            memset(m_mcstfRefList[i].noise, 0, sizeof(int) *
((m_param->sourceWidth / 4) * (m_param->sourceHeight / 4)));
-            memset(m_mcstfRefList[i].error, 0, sizeof(int) *
((m_param->sourceWidth / 4) * (m_param->sourceHeight / 4)));
+        for (int i = 0; i < (m_frame[layer]->m_mcstf->m_range << 1); i++)
+        {
+            memset(m_frame[layer]->m_mcstfRefList[i].mvs0, 0, sizeof(MV) *
((m_param->sourceWidth / 16) * (m_param->sourceHeight / 16)));
+            memset(m_frame[layer]->m_mcstfRefList[i].mvs1, 0, sizeof(MV) *
((m_param->sourceWidth / 16) * (m_param->sourceHeight / 16)));
+            memset(m_frame[layer]->m_mcstfRefList[i].mvs2, 0, sizeof(MV) *
((m_param->sourceWidth / 16) * (m_param->sourceHeight / 16)));
+            memset(m_frame[layer]->m_mcstfRefList[i].mvs,  0, sizeof(MV) *
((m_param->sourceWidth / 4) * (m_param->sourceHeight / 4)));
+            memset(m_frame[layer]->m_mcstfRefList[i].noise, 0, sizeof(int)
* ((m_param->sourceWidth / 4) * (m_param->sourceHeight / 4)));
+            memset(m_frame[layer]->m_mcstfRefList[i].error, 0, sizeof(int)
* ((m_param->sourceWidth / 4) * (m_param->sourceHeight / 4)));

             m_frame[layer]->m_mcstf->m_numRef = 0;
         }
diff --git a/source/encoder/frameencoder.h b/source/encoder/frameencoder.h
index 21d05c2f2..c31762402 100644
--- a/source/encoder/frameencoder.h
+++ b/source/encoder/frameencoder.h
@@ -265,10 +265,6 @@ public:
     FrameFilter              m_frameFilter;
     NALList                  m_nalList;

-    // initialization for mcstf
-    TemporalFilter*          m_frameEncTF;
-    TemporalFilterRefPicInfo
m_mcstfRefList[MAX_MCSTF_TEMPORAL_WINDOW_LENGTH];
-
     int                      m_sLayerId;

     class WeightAnalysis : public BondedTaskGroup
-- 
2.36.0.windows.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241111/286e16dc/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0009-Remove-frameencoder-instance-for-mcstf-and-fix-memor.patch
Type: application/octet-stream
Size: 5749 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241111/286e16dc/attachment.obj>


More information about the x265-devel mailing list