<div dir="ltr">Pushed to master branch, Thanks</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Nov 2, 2022 at 6:53 PM Snehaa Giridharan <<a href="mailto:snehaa@multicorewareinc.com">snehaa@multicorewareinc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><div>From 6b8db060a7ee5850758b05c9ff0119a8269bf6f8 Mon Sep 17 00:00:00 2001</div><div>From: Snehaa Giridharan <<a href="mailto:snehaa@multicorewareinc.com" target="_blank">snehaa@multicorewareinc.com</a>></div><div>Date: Tue, 1 Nov 2022 16:50:45 +0530</div><div>Subject: [PATCH] Fix memory leak in SBRC</div><div><br></div><div>---</div><div> source/common/frame.cpp      |  2 +-</div><div> source/encoder/slicetype.cpp | 73 +++++++++++++++++++-----------------</div><div> source/encoder/slicetype.h   |  1 +</div><div> source/x265.h                |  1 -</div><div> 4 files changed, 40 insertions(+), 37 deletions(-)</div><div><br></div><div>diff --git a/source/common/frame.cpp b/source/common/frame.cpp</div><div>index d7f8ce2a8..019a5cb76 100644</div><div>--- a/source/common/frame.cpp</div><div>+++ b/source/common/frame.cpp</div><div>@@ -63,7 +63,7 @@ Frame::Frame()</div><div>     m_thetaPic = NULL;</div><div>     m_edgeBitPlane = NULL;</div><div>     m_edgeBitPic = NULL;</div><div>-    m_frameSegment = X265_AQ_NONE;</div><div>+    m_frameSegment = 0;</div><div>     m_isInsideWindow = 0;</div><div> </div><div>     // mcstf</div><div>diff --git a/source/encoder/slicetype.cpp b/source/encoder/slicetype.cpp</div><div>index 79541e5cb..5a1500716 100644</div><div>--- a/source/encoder/slicetype.cpp</div><div>+++ b/source/encoder/slicetype.cpp</div><div>@@ -481,9 +481,9 @@ void LookaheadTLD::calcAdaptiveQuantFrame(Frame *curFrame, x265_param* param)</div><div>     if (!(param->rc.bStatRead && param->rc.cuTree && IS_REFERENCED(curFrame)))</div><div>     {</div><div>         /* Calculate Qp offset for each 16x16 or 8x8 block in the frame */</div><div>-        if (curFrame->m_frameSegment == X265_AQ_NONE || param->rc.aqStrength == 0)</div><div>+        if (param->rc.aqMode == X265_AQ_NONE || param->rc.aqStrength == 0)</div><div>         {</div><div>-            if (curFrame->m_frameSegment && param->rc.aqStrength == 0)</div><div>+            if (param->rc.aqMode && param->rc.aqStrength == 0)</div><div>             {</div><div>                 if (quantOffsets)</div><div>                 {</div><div>@@ -524,17 +524,17 @@ void LookaheadTLD::calcAdaptiveQuantFrame(Frame *curFrame, x265_param* param)</div><div>                 double bias_strength = 0.f;</div><div>                 double strength = 0.f;</div><div> </div><div>-                if (curFrame->m_frameSegment == X265_AQ_EDGE )</div><div>+                if (param->rc.aqMode == X265_AQ_EDGE)</div><div>                     edgeFilter(curFrame, param);</div><div> </div><div>-                if (curFrame->m_frameSegment == X265_AQ_EDGE && param->recursionSkipMode == EDGE_BASED_RSKIP)</div><div>+                if (param->rc.aqMode == X265_AQ_EDGE && param->recursionSkipMode == EDGE_BASED_RSKIP)</div><div>                 {</div><div>                     pixel* src = curFrame->m_edgePic + curFrame->m_fencPic->m_lumaMarginY * curFrame->m_fencPic->m_stride + curFrame->m_fencPic->m_lumaMarginX;</div><div>                     primitives.planecopy_pp_shr(src, curFrame->m_fencPic->m_stride, curFrame->m_edgeBitPic,</div><div>                         curFrame->m_fencPic->m_stride, curFrame->m_fencPic->m_picWidth, curFrame->m_fencPic->m_picHeight, SHIFT_TO_BITPLANE);</div><div>                 }</div><div> </div><div>-                if (curFrame->m_frameSegment == X265_AQ_AUTO_VARIANCE || curFrame->m_frameSegment == X265_AQ_AUTO_VARIANCE_BIASED || curFrame->m_frameSegment == X265_AQ_EDGE)</div><div>+                if (param->rc.aqMode == X265_AQ_AUTO_VARIANCE || param->rc.aqMode == X265_AQ_AUTO_VARIANCE_BIASED || param->rc.aqMode == X265_AQ_EDGE)</div><div>                 {</div><div>                     double bit_depth_correction = 1.f / (1 << (2 * (X265_DEPTH - 8)));</div><div>                     for (int blockY = 0; blockY < maxRow; blockY += loopIncr)</div><div>@@ -543,7 +543,7 @@ void LookaheadTLD::calcAdaptiveQuantFrame(Frame *curFrame, x265_param* param)</div><div>                         {</div><div>                             uint32_t energy, edgeDensity, avgAngle;</div><div>                             energy = acEnergyCu(curFrame, blockX, blockY, param->internalCsp, param->rc.qgSize);</div><div>-                            if (curFrame->m_frameSegment == X265_AQ_EDGE)</div><div>+                            if (param->rc.aqMode == X265_AQ_EDGE)</div><div>                             {</div><div>                                 edgeDensity = edgeDensityCu(curFrame, avgAngle, blockX, blockY, param->rc.qgSize);</div><div>                                 if (edgeDensity)</div><div>@@ -583,17 +583,17 @@ void LookaheadTLD::calcAdaptiveQuantFrame(Frame *curFrame, x265_param* param)</div><div>                 {</div><div>                     for (int blockX = 0; blockX < maxCol; blockX += loopIncr)</div><div>                     {</div><div>-                        if (curFrame->m_frameSegment == X265_AQ_AUTO_VARIANCE_BIASED)</div><div>+                        if (param->rc.aqMode == X265_AQ_AUTO_VARIANCE_BIASED)</div><div>                         {</div><div>                             qp_adj = curFrame->m_lowres.qpCuTreeOffset[blockXY];</div><div>                             qp_adj = strength * (qp_adj - avg_adj) + bias_strength * (1.f - modeTwoConst / (qp_adj * qp_adj));</div><div>                         }</div><div>-                        else if (curFrame->m_frameSegment == X265_AQ_AUTO_VARIANCE)</div><div>+                        else if (param->rc.aqMode == X265_AQ_AUTO_VARIANCE)</div><div>                         {</div><div>                             qp_adj = curFrame->m_lowres.qpCuTreeOffset[blockXY];</div><div>                             qp_adj = strength * (qp_adj - avg_adj);</div><div>                         }</div><div>-                        else if (curFrame->m_frameSegment == X265_AQ_EDGE)</div><div>+                        else if (param->rc.aqMode == X265_AQ_EDGE)</div><div>                         {</div><div>                             inclinedEdge = curFrame->m_lowres.edgeInclined[blockXY];</div><div>                             qp_adj = curFrame->m_lowres.qpCuTreeOffset[blockXY];</div><div>@@ -1732,6 +1732,34 @@ void LookaheadTLD::collectPictureStatistics(Frame *curFrame)</div><div>     curFrame->m_lowres.bHistScenecutAnalyzed = false;</div><div> }</div><div> </div><div>+void LookaheadTLD::calcFrameSegment(Frame *preFrame)</div><div>+{</div><div>+    int heightL = preFrame->m_lowres.lines;</div><div>+    int widthL = preFrame->m_lowres.width;</div><div>+    pixel *lumaPlane = preFrame->m_lowres.fpelPlane[0];</div><div>+    intptr_t stride = preFrame->m_lowres.lumaStride;</div><div>+    double brightnessIntensity = 0, edgeIntensity = 0;</div><div>+</div><div>+    /* Edge plane computation */</div><div>+    memset(preFrame->m_lowres.lowresEdgePlane, 0, stride * (heightL + (preFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));</div><div>+    pixel* lowresEdgePic = preFrame->m_lowres.lowresEdgePlane + preFrame->m_fencPic->m_lumaMarginY * stride + preFrame->m_fencPic->m_lumaMarginX;</div><div>+    computeEdge(lowresEdgePic, lumaPlane, NULL, stride, heightL, widthL, false);</div><div>+</div><div>+    /*Frame edge percentage computation */</div><div>+    edgeIntensity = computeEdgeIntensity(lowresEdgePic, widthL, heightL, stride);</div><div>+</div><div>+    /* Frame Brightness percentage computation */</div><div>+    brightnessIntensity = computeBrightnessIntensity(lumaPlane, widthL, heightL, stride);</div><div>+</div><div>+    /* AQ mode switch */</div><div>+    if (edgeIntensity < FRAME_EDGE_THRESHOLD)</div><div>+        preFrame->m_frameSegment = brightnessIntensity > FRAME_BRIGHTNESS_THRESHOLD ? X265_AQ_AUTO_VARIANCE : X265_AQ_AUTO_VARIANCE_BIASED;</div><div>+    else</div><div>+        preFrame->m_frameSegment = brightnessIntensity > FRAME_BRIGHTNESS_THRESHOLD ? X265_AQ_EDGE : X265_AQ_VARIANCE;</div><div>+</div><div>+    preFrame->m_param->rc.aqMode = preFrame->m_frameSegment;</div><div>+}</div><div>+</div><div> void PreLookaheadGroup::processTasks(int workerThreadID)</div><div> {</div><div>     if (workerThreadID < 0)</div><div>@@ -1749,32 +1777,7 @@ void PreLookaheadGroup::processTasks(int workerThreadID)</div><div> </div><div>         /* SBRC */</div><div>         if (preFrame->m_param->rc.frameSegment)</div><div>-        {</div><div>-            int heightL = preFrame->m_lowres.lines;</div><div>-            int widthL = preFrame->m_lowres.width;</div><div>-            pixel *lumaPlane = preFrame->m_lowres.fpelPlane[0];</div><div>-            intptr_t stride = preFrame->m_lowres.lumaStride;</div><div>-            double brightnessIntensity = 0, edgeIntensity = 0;</div><div>-</div><div>-            /* Edge plane computation */</div><div>-            memset(preFrame->m_lowres.lowresEdgePlane, 0, stride * (heightL + (preFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));</div><div>-            pixel* lowresEdgePic = preFrame->m_lowres.lowresEdgePlane + preFrame->m_fencPic->m_lumaMarginY * stride + preFrame->m_fencPic->m_lumaMarginX;</div><div>-            computeEdge(lowresEdgePic, lumaPlane, NULL, stride, heightL, widthL, false);</div><div>-</div><div>-            /*Frame edge percentage computation */</div><div>-            edgeIntensity = computeEdgeIntensity(lowresEdgePic, widthL, heightL, stride);</div><div>-</div><div>-            /* Frame Brightness percentage computation */</div><div>-            brightnessIntensity = computeBrightnessIntensity(lumaPlane, widthL, heightL, stride);</div><div>-</div><div>-            /* AQ mode switch */</div><div>-            if (edgeIntensity < FRAME_EDGE_THRESHOLD)</div><div>-                preFrame->m_frameSegment = brightnessIntensity > FRAME_BRIGHTNESS_THRESHOLD? X265_AQ_AUTO_VARIANCE : X265_AQ_AUTO_VARIANCE_BIASED;</div><div>-            else</div><div>-                preFrame->m_frameSegment = brightnessIntensity > FRAME_BRIGHTNESS_THRESHOLD? X265_AQ_EDGE : X265_AQ_EDGE_BIASED;</div><div>-        }</div><div>-        else</div><div>-            preFrame->m_frameSegment = preFrame->m_param->rc.aqMode;</div><div>+            tld.calcFrameSegment(preFrame);</div><div> </div><div>         if (m_lookahead.m_bAdaptiveQuant)</div><div>             tld.calcAdaptiveQuantFrame(preFrame, m_lookahead.m_param);</div><div>diff --git a/source/encoder/slicetype.h b/source/encoder/slicetype.h</div><div>index d0a39506a..05cef800b 100644</div><div>--- a/source/encoder/slicetype.h</div><div>+++ b/source/encoder/slicetype.h</div><div>@@ -133,6 +133,7 @@ struct LookaheadTLD</div><div>     uint32_t calcVariance(pixel* src, intptr_t stride, intptr_t blockOffset, uint32_t plane);</div><div> </div><div>     void calcAdaptiveQuantFrame(Frame *curFrame, x265_param* param);</div><div>+    void calcFrameSegment(Frame *curFrame);</div><div>     void lowresIntraEstimate(Lowres& fenc, uint32_t qgSize);</div><div> </div><div>     void weightsAnalyse(Lowres& fenc, Lowres& ref);</div><div>diff --git a/source/x265.h b/source/x265.h</div><div>index 4f1c52d56..e77d4e019 100644</div><div>--- a/source/x265.h</div><div>+++ b/source/x265.h</div><div>@@ -581,7 +581,6 @@ typedef enum</div><div> #define X265_AQ_AUTO_VARIANCE        2</div><div> #define X265_AQ_AUTO_VARIANCE_BIASED 3</div><div> #define X265_AQ_EDGE                 4</div><div>-#define X265_AQ_EDGE_BIASED          1</div><div> #define x265_ADAPT_RD_STRENGTH   4</div><div> #define X265_REFINE_INTER_LEVELS 3</div><div> /* NOTE! For this release only X265_CSP_I420 and X265_CSP_I444 are supported */</div><div>-- </div><div>2.37.2.windows.2</div><div><br></div></div></div></div></div>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org" target="_blank">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</blockquote></div>