[x265] [PATCH 06/10] Remove the redundant code for mcstf in encoder

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


>From 9350b78dc247df80673b93d0f076ef0c4e00a2af Mon Sep 17 00:00:00 2001
From: AnusuyaKumarasamy <anusuya.kumarasamy at multicorewareinc.com>
Date: Fri, 25 Oct 2024 16:37:08 +0530
Subject: [PATCH 06/10] Remove the redundant code for mcstf in encoder

---
 source/common/frame.cpp    | 11 +++++
 source/encoder/encoder.cpp | 97 ++------------------------------------
 source/encoder/encoder.h   |  1 -
 3 files changed, 16 insertions(+), 93 deletions(-)

diff --git a/source/common/frame.cpp b/source/common/frame.cpp
index 63e9b829b..e5f5b0327 100644
--- a/source/common/frame.cpp
+++ b/source/common/frame.cpp
@@ -315,6 +315,17 @@ void Frame::destroy()
             delete m_fencPicSubsampled4;
             m_fencPicSubsampled4 = NULL;
         }
+
+        for (int i = 0; i < (m_mcstf->m_range << 1); i++)
+            m_mcstf->destroyRefPicInfo(&m_mcstfRefList[i]);
+
+        if (m_mcstffencPic)
+        {
+            m_mcstffencPic->destroy();
+            delete m_mcstffencPic;
+            m_mcstffencPic = NULL;
+        }
+
         delete m_mcstf;
         X265_FREE(m_isSubSampled);
     }
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
index 7745a7196..09f58c62a 100644
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -171,7 +171,6 @@ Encoder::Encoder()
     m_startPoint = 0;
     m_saveCTUSize = 0;
     m_zoneIndex = 0;
-    m_origPicBuffer = 0;
 }

 inline char *strcatFilename(const char *input, const char *suffix)
@@ -362,9 +361,6 @@ void Encoder::create()
     m_lookahead->m_numPools = pools;
     m_dpb = new DPB(m_param);

-    if (m_param->bEnableTemporalFilter)
-        m_origPicBuffer = new OrigPicBuffer();
-
     m_rateControl = new RateControl(*m_param, this);
     if (!m_param->bResetZoneConfig)
     {
@@ -938,9 +934,6 @@ void Encoder::destroy()
         delete[] zoneWriteCount;
     }

-    if (m_param->bEnableTemporalFilter)
-        delete m_origPicBuffer;
-
     if (m_rateControl)
     {
         m_rateControl->destroy();
@@ -1405,82 +1398,6 @@ bool Encoder::isFilterThisframe(uint8_t
sliceTypeConfig, int curSliceType)
     return ((sliceTypeConfig & newSliceType) != 0);
 }

-inline int enqueueRefFrame(FrameEncoder* curframeEncoder, Frame*
iterFrame, Frame* curFrame, bool isPreFiltered, int16_t i)
-{
-    TemporalFilterRefPicInfo* dest =
&curframeEncoder->m_mcstfRefList[curFrame->m_mcstf->m_numRef];
-    dest->poc = iterFrame->m_poc;
-    dest->picBuffer = iterFrame->m_mcstffencPic;
-    dest->picBufferSubSampled2 = iterFrame->m_fencPicSubsampled2;
-    dest->picBufferSubSampled4 = iterFrame->m_fencPicSubsampled4;
-    dest->isFilteredFrame = isPreFiltered;
-    dest->isSubsampled = iterFrame->m_isSubSampled;
-    dest->origOffset = i;
-
-    TemporalFilterRefPicInfo* temp =
&curFrame->m_mcstfRefList[curFrame->m_mcstf->m_numRef];
-    temp->poc = iterFrame->m_poc;
-    temp->picBuffer = iterFrame->m_mcstffencPic;
-    temp->lowres = iterFrame->m_lowres.lowresPlane[0];
-    temp->lowerRes = iterFrame->m_lowres.lowerResPlane[0];
-    temp->isFilteredFrame = isPreFiltered;
-    temp->origOffset = i;
-
-    curFrame->m_mcstf->m_numRef++;
-
-    return 1;
-}
-
-bool Encoder::generateMcstfRef(Frame* frameEnc, FrameEncoder* currEncoder)
-{
-    frameEnc->m_mcstf->m_numRef = 0;
-
-    for (int iterPOC = (frameEnc->m_poc - frameEnc->m_mcstf->m_range);
-        iterPOC <= (frameEnc->m_poc + frameEnc->m_mcstf->m_range);
iterPOC++)
-    {
-        bool isFound = false;
-        if (iterPOC != frameEnc->m_poc)
-        {
-            //search for the reference frame in the Original Picture Buffer
-            if (!isFound)
-            {
-                for (int j = 0; j < (2 * frameEnc->m_mcstf->m_range); j++)
-                {
-                    if (iterPOC < 0)
-                        continue;
-                    if (iterPOC >= m_pocLast)
-                    {
-
-                        TemporalFilter* mcstf = frameEnc->m_mcstf;
-                        while (mcstf->m_numRef)
-                        {
-
 memset(frameEnc->m_mcstfRefList[mcstf->m_numRef].mvs0, 0, sizeof(MV) *
((mcstf->m_sourceWidth / 16) * (mcstf->m_sourceHeight / 16)));
-
 memset(frameEnc->m_mcstfRefList[mcstf->m_numRef].mvs1, 0, sizeof(MV) *
((mcstf->m_sourceWidth / 16) * (mcstf->m_sourceHeight / 16)));
-
 memset(frameEnc->m_mcstfRefList[mcstf->m_numRef].mvs2, 0, sizeof(MV) *
((mcstf->m_sourceWidth / 16) * (mcstf->m_sourceHeight / 16)));
-
 memset(frameEnc->m_mcstfRefList[mcstf->m_numRef].mvs, 0, sizeof(MV) *
((mcstf->m_sourceWidth / 4) * (mcstf->m_sourceHeight / 4)));
-
 memset(frameEnc->m_mcstfRefList[mcstf->m_numRef].noise, 0, sizeof(int) *
((mcstf->m_sourceWidth / 4) * (mcstf->m_sourceHeight / 4)));
-
 memset(frameEnc->m_mcstfRefList[mcstf->m_numRef].error, 0, sizeof(int) *
((mcstf->m_sourceWidth / 4) * (mcstf->m_sourceHeight / 4)));
-
-                            mcstf->m_numRef--;
-                        }
-
-                        break;
-                    }
-                    Frame* iterFrame =
frameEnc->m_encData->m_slice->m_mcstfRefFrameList[1][j];
-                    if (iterFrame->m_poc == iterPOC)
-                    {
-                        if (!enqueueRefFrame(currEncoder, iterFrame,
frameEnc, false, (int16_t)(iterPOC - frameEnc->m_poc)))
-                        {
-                            return false;
-                        };
-                        break;
-                    }
-                }
-            }
-        }
-    }
-
-    return true;
-}
-
 /**
  * Feed one new input frame into the encoder, get one frame out. If pic_in
is
  * NULL, a flush condition is implied and pic_in must be NULL for all
subsequent
@@ -2510,18 +2427,14 @@ int Encoder::encode(const x265_picture* pic_in,
x265_picture* pic_out)
             // Generate MCSTF References and perform HME
             if (m_param->bEnableTemporalFilter &&
isFilterThisframe(frameEnc[0]->m_mcstf->m_sliceTypeConfig,
frameEnc[0]->m_lowres.sliceType))
             {
-
-                if (!generateMcstfRef(frameEnc[0], curEncoder))
-                {
-                    m_aborted = true;
-                    x265_log(m_param, X265_LOG_ERROR, "Failed to
initialize MCSTFReferencePicInfo at POC %d\n", frameEnc[0]->m_poc);
-                    fflush(stderr);
-                    return -1;
-                }
-
                 for (int i = 0; i < frameEnc[0]->m_mcstf->m_numRef; i++)
                 {
                     TemporalFilterRefPicInfo* ref =
&frameEnc[0]->m_mcstfRefList[i];
+
+                    //Resetting the reference picture buffer from
mcstfpiclist
+                    Frame* iterFrame =
frameEnc[0]->m_encData->m_slice->m_mcstfRefFrameList[1][i];
+                    ref->picBuffer = iterFrame->m_mcstffencPic;
+
                     ref->slicetype =
m_lookahead->findSliceType(frameEnc[0]->m_poc + ref->origOffset);
                     Frame* dpbframePtr =
m_dpb->m_picList.getPOC(frameEnc[0]->m_poc + ref->origOffset, 0);
                     if (dpbframePtr != NULL)
diff --git a/source/encoder/encoder.h b/source/encoder/encoder.h
index f50f783d0..af216942b 100644
--- a/source/encoder/encoder.h
+++ b/source/encoder/encoder.h
@@ -287,7 +287,6 @@ public:
     FILE* m_filmGrainIn;
     /* Aom film grain model file*/
     FILE* m_aomFilmGrainIn;
-    OrigPicBuffer*          m_origPicBuffer;

     Encoder();
     ~Encoder()
-- 
2.36.0.windows.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241111/66ac2b0f/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0006-Remove-the-redundant-code-for-mcstf-in-encoder.patch
Type: application/octet-stream
Size: 7562 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241111/66ac2b0f/attachment-0001.obj>


More information about the x265-devel mailing list